Issues
Issues copied to clipboard
Accessing Azure keyvault from Bicep template fails
Severity
Low, workarounds available
Version
All
Latest Version
I could reproduce the problem in the latest build
What happened?
When running a Deploy a Bicep Template with a dependency on an Azure Key Vault secret deployments fail.
Reproduction
Create an Azure Key Vault and secret using Bicep
@description('Specifies the name of the key vault.')
param keyVaultName string
@description('Specifies the Azure location where the key vault should be created.')
param location string = resourceGroup().location
@description('Specifies whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key vault.')
param enabledForDeployment bool = false
@description('Specifies whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys.')
param enabledForDiskEncryption bool = false
@description('Specifies whether Azure Resource Manager is permitted to retrieve secrets from the key vault.')
param enabledForTemplateDeployment bool = false
@description('Specifies the Azure Active Directory tenant ID that should be used for authenticating requests to the key vault. Get it by using Get-AzSubscription cmdlet.')
param tenantId string = subscription().tenantId
@description('Specifies the object ID of a user, service principal or security group in the Azure Active Directory tenant for the vault. The object ID must be unique for the list of access policies. Get it by using Get-AzADUser or Get-AzADServicePrincipal cmdlets.')
param objectId string
@description('Specifies the permissions to keys in the vault. Valid values are: all, encrypt, decrypt, wrapKey, unwrapKey, sign, verify, get, list, create, update, import, delete, backup, restore, recover, and purge.')
param keysPermissions array = [
'list'
]
@description('Specifies the permissions to secrets in the vault. Valid values are: all, get, list, set, delete, backup, restore, recover, and purge.')
param secretsPermissions array = [
'list'
]
@description('Specifies whether the key vault is a standard vault or a premium vault.')
@allowed([
'standard'
'premium'
])
param skuName string = 'standard'
@description('Specifies the name of the secret that you want to create.')
param secretName string
@description('Specifies the value of the secret that you want to create.')
@secure()
param secretValue string
resource kv 'Microsoft.KeyVault/vaults@2021-11-01-preview' = {
name: keyVaultName
location: location
properties: {
enabledForDeployment: enabledForDeployment
enabledForDiskEncryption: enabledForDiskEncryption
enabledForTemplateDeployment: enabledForTemplateDeployment
tenantId: tenantId
enableSoftDelete: true
softDeleteRetentionInDays: 90
accessPolicies: [
{
objectId: objectId
tenantId: tenantId
permissions: {
keys: keysPermissions
secrets: secretsPermissions
}
}
]
sku: {
name: skuName
family: 'A'
}
networkAcls: {
defaultAction: 'Allow'
bypass: 'AzureServices'
}
}
}
resource secret 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
parent: kv
name: secretName
properties: {
value: secretValue
}
}
Error and Stacktrace
15:21:23 Error | - Please run 'az login' to set up account
15:21:23 Error | - Please run 'Connect-AzAccount' to set up account.
More Information
This step is built on a new step execution framework, this framework currently does not currently have built in extensions to handle azure cli authentication with process scoping. As there is a work-around and this requires some additional work (isn't as simple as executing az login) this issue is a low priority.
Workaround
- The Deploy an Arm Template step has an active authentication step
- Use secrets/variables stored within Octopus