Skip to content
1 change: 1 addition & 0 deletions .azuredevops/modulePipelines/ms.batch.batchaccounts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ stages:
parameters:
removeDeployment: '${{ parameters.removeDeployment }}'
deploymentBlocks:
- path: $(modulePath)/.test/encr.parameters.json
- path: $(modulePath)/.test/min.parameters.json
- path: $(modulePath)/.test/parameters.json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@
"name": {
"value": "<<namePrefix>>-az-aut-encr-001"
},
"encryptionKeySource": {
"value": "Microsoft.Keyvault"
},
"encryptionUserAssignedIdentity": {
"value": "/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001" // this identity needs to be one of the identities defined in userAssignedIdentities section
},
"keyName": {
"value": "keyEncryptionKey"
},
"keyvaultUri": {
"value": "https://adp-<<namePrefix>>-az-kv-nopr-002.vault.azure.net/"
},
"keyVersion": {
"value": "9917c14be51d4d93b37218de7d326f60"
},
"userAssignedIdentities": {
"value": {
"/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001": {}
}
},
"cMKUserAssignedIdentityResourceId": {
"value": "/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001"
},
"cMKKeyName": {
"value": "keyEncryptionKey"
},
"cMKKeyVaultResourceId": {
"value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.KeyVault/vaults/adp-<<namePrefix>>-az-kv-nopr-002"
}
}
}
55 changes: 29 additions & 26 deletions modules/Microsoft.Automation/automationAccounts/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,17 @@ param location string = resourceGroup().location
])
param skuName string = 'Basic'

@description('Optional. User identity used for CMK. If you set encryptionKeySource as Microsoft.Keyvault encryptionUserAssignedIdentity is required.')
param encryptionUserAssignedIdentity string = ''
@description('Optional. The resource ID of a key vault to reference a customer managed key for encryption from.')
param cMKKeyVaultResourceId string = ''

@description('Optional. Encryption Key Source. For security reasons it is recommended to use Microsoft.Keyvault if custom keys are available.')
@allowed([
'Microsoft.Automation'
'Microsoft.Keyvault'
])
param encryptionKeySource string = 'Microsoft.Automation'
@description('Optional. The name of the customer managed key to use for encryption.')
param cMKKeyName string = ''

@description('Optional. The name of key used to encrypt data. This parameter is needed only if you enable Microsoft.Keyvault as encryptionKeySource.')
param keyName string = ''
@description('Optional. User assigned identity to use when fetching the customer managed key. If not provided, a system-assigned identity can be used - but must be given access to the referenced key vault first.')
param cMKUserAssignedIdentityResourceId string = ''

@description('Optional. The URI of the key vault key used to encrypt data. This parameter is needed only if you enable Microsoft.Keyvault as encryptionKeySource.')
param keyvaultUri string = ''

@description('Optional. The key version of the key used to encrypt data. This parameter is needed only if you enable Microsoft.Keyvault as encryptionKeySource.')
param keyVersion string = ''
@description('Optional. The version of the customer managed key to reference for encryption. If not provided, the latest key version is used.')
param cMKKeyVersion string = ''

@description('Optional. List of modules to be created in the automation account.')
param modules array = []
Expand Down Expand Up @@ -160,6 +153,16 @@ resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (ena
}
}

resource cMKKeyVault 'Microsoft.KeyVault/vaults@2021-10-01' existing = if (!empty(cMKKeyVaultResourceId)) {
name: last(split(cMKKeyVaultResourceId, '/'))
scope: resourceGroup(split(cMKKeyVaultResourceId, '/')[2], split(cMKKeyVaultResourceId, '/')[4])
}

resource cMKKeyVaultKey 'Microsoft.KeyVault/vaults/keys@2021-10-01' existing = if (!empty(cMKKeyVaultResourceId) && !empty(cMKKeyName)) {
name: '${last(split(cMKKeyVaultResourceId, '/'))}/${cMKKeyName}'
scope: resourceGroup(split(cMKKeyVaultResourceId, '/')[2], split(cMKKeyVaultResourceId, '/')[4])
}

resource automationAccount 'Microsoft.Automation/automationAccounts@2020-01-13-preview' = {
name: name
location: location
Expand All @@ -169,17 +172,17 @@ resource automationAccount 'Microsoft.Automation/automationAccounts@2020-01-13-p
sku: {
name: skuName
}
encryption: {
identity: encryptionKeySource == 'Microsoft.Keyvault' ? {
userAssignedIdentity: any(encryptionUserAssignedIdentity)
} : null
keySource: encryptionKeySource
keyVaultProperties: encryptionKeySource == 'Microsoft.Keyvault' ? {
keyName: keyName
keyvaultUri: keyvaultUri
keyVersion: keyVersion
} : null
}
encryption: !empty(cMKKeyName) ? {
keySource: 'Microsoft.KeyVault'
identity: {
userAssignedIdentity: cMKUserAssignedIdentityResourceId
}
keyVaultProperties: {
keyName: cMKKeyName
keyVaultUri: cMKKeyVault.properties.vaultUri
keyVersion: !empty(cMKKeyVersion) ? cMKKeyVersion : last(split(cMKKeyVaultKey.properties.keyUriWithVersion, '/'))
}
} : null
}
}

Expand Down
41 changes: 16 additions & 25 deletions modules/Microsoft.Automation/automationAccounts/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ This module deploys an Azure Automation Account.
**Optional parameters**
| Parameter Name | Type | Default Value | Allowed Values | Description |
| :-- | :-- | :-- | :-- | :-- |
| `cMKKeyName` | string | `''` | | The name of the customer managed key to use for encryption. |
| `cMKKeyVaultResourceId` | string | `''` | | The resource ID of a key vault to reference a customer managed key for encryption from. |
| `cMKKeyVersion` | string | `''` | | The version of the customer managed key to reference for encryption. If not provided, the latest key version is used. |
| `cMKUserAssignedIdentityResourceId` | string | `''` | | User assigned identity to use when fetching the customer managed key. If not provided, a system-assigned identity can be used - but must be given access to the referenced key vault first. |
| `diagnosticEventHubAuthorizationRuleId` | string | `''` | | Resource ID of the diagnostic event hub authorization rule for the Event Hubs namespace in which the event hub should be created or streamed to. |
| `diagnosticEventHubName` | string | `''` | | Name of the diagnostic event hub within the namespace to which logs are streamed. Without this, an event hub is created for each log category. |
| `diagnosticLogCategoriesToEnable` | array | `[JobLogs, JobStreams, DscNodeStatus]` | `[JobLogs, JobStreams, DscNodeStatus]` | The name of logs that will be streamed. |
Expand All @@ -47,13 +51,8 @@ This module deploys an Azure Automation Account.
| `diagnosticStorageAccountId` | string | `''` | | Resource ID of the diagnostic storage account. |
| `diagnosticWorkspaceId` | string | `''` | | Resource ID of the diagnostic log analytics workspace. |
| `enableDefaultTelemetry` | bool | `True` | | Enable telemetry via the Customer Usage Attribution ID (GUID). |
| `encryptionKeySource` | string | `'Microsoft.Automation'` | `[Microsoft.Automation, Microsoft.Keyvault]` | Encryption Key Source. For security reasons it is recommended to use Microsoft.Keyvault if custom keys are available. |
| `encryptionUserAssignedIdentity` | string | `''` | | User identity used for CMK. If you set encryptionKeySource as Microsoft.Keyvault encryptionUserAssignedIdentity is required. |
| `gallerySolutions` | array | `[]` | | List of gallerySolutions to be created in the linked log analytics workspace. |
| `jobSchedules` | _[jobSchedules](jobSchedules/readme.md)_ array | `[]` | | List of jobSchedules to be created in the automation account. |
| `keyName` | string | `''` | | The name of key used to encrypt data. This parameter is needed only if you enable Microsoft.Keyvault as encryptionKeySource. |
| `keyvaultUri` | string | `''` | | The URI of the key vault key used to encrypt data. This parameter is needed only if you enable Microsoft.Keyvault as encryptionKeySource. |
| `keyVersion` | string | `''` | | The key version of the key used to encrypt data. This parameter is needed only if you enable Microsoft.Keyvault as encryptionKeySource. |
| `linkedWorkspaceResourceId` | string | `''` | | ID of the log analytics workspace to be linked to the deployed automation account. |
| `location` | string | `[resourceGroup().location]` | | Location for all resources. |
| `lock` | string | `''` | `[, CanNotDelete, ReadOnly]` | Specify the type of lock. |
Expand Down Expand Up @@ -359,25 +358,19 @@ userAssignedIdentities: {
"name": {
"value": "<<namePrefix>>-az-aut-encr-001"
},
"encryptionKeySource": {
"value": "Microsoft.Keyvault"
},
"encryptionUserAssignedIdentity": {
"value": "/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001" // this identity needs to be one of the identities defined in userAssignedIdentities section
},
"keyName": {
"value": "keyEncryptionKey"
},
"keyvaultUri": {
"value": "https://adp-<<namePrefix>>-az-kv-nopr-002.vault.azure.net/"
},
"keyVersion": {
"value": "9917c14be51d4d93b37218de7d326f60"
},
"userAssignedIdentities": {
"value": {
"/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001": {}
}
},
"cMKUserAssignedIdentityResourceId": {
"value": "/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001"
},
"cMKKeyName": {
"value": "keyEncryptionKey"
},
"cMKKeyVaultResourceId": {
"value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.KeyVault/vaults/adp-<<namePrefix>>-az-kv-nopr-002"
}
}
}
Expand All @@ -394,14 +387,12 @@ module automationAccounts './Microsoft.Automation/automationAccounts/deploy.bice
name: '${uniqueString(deployment().name)}-automationAccounts'
params: {
name: '<<namePrefix>>-az-aut-encr-001'
encryptionKeySource: 'Microsoft.Keyvault'
encryptionUserAssignedIdentity: '/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001'
keyName: 'keyEncryptionKey'
keyvaultUri: 'https://adp-<<namePrefix>>-az-kv-nopr-002.vault.azure.net/'
keyVersion: '9917c14be51d4d93b37218de7d326f60'
userAssignedIdentities: {
'/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001': {}
}
cMKUserAssignedIdentityResourceId: '/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001'
cMKKeyName: 'keyEncryptionKey'
cMKKeyVaultResourceId: '/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.KeyVault/vaults/adp-<<namePrefix>>-az-kv-nopr-002'
}
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"value": "<<namePrefix>>azbaweuencr001"
},
"poolAllocationMode": {
"value": "BatchService"
},
"storageAccountId": {
"value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<<namePrefix>>azsax001"
},
"storageAuthenticationMode": {
"value": "BatchAccountManagedIdentity"
},
"userAssignedIdentities": {
"value": {
"/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001": {}
}
},
"storageAccessIdentity": {
"value": "/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<<namePrefix>>-az-msi-x-001"
},
"cMKKeyName": {
"value": "keyEncryptionKey"
},
"cMKKeyVaultResourceId": {
"value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.KeyVault/vaults/adp-<<namePrefix>>-az-kv-nopr-002"
}
}
}
50 changes: 28 additions & 22 deletions modules/Microsoft.Batch/batchAccounts/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ param storageAccessIdentity string = ''
@description('Optional. The allocation mode for creating pools in the Batch account. Determines which quota will be used.')
param poolAllocationMode string = 'BatchService'

@description('Conditional. The key vault to associate with the Batch account. Required if the \'poolAllocationMode\' is set to \'UserSubscription\' and requires the service principal \'Microsoft Azure Batch\' to be granted contributor permissions on this key vault.')
param keyVaultReferenceResourceId string = ''

@allowed([
'Disabled'
'Enabled'
Expand Down Expand Up @@ -73,21 +76,14 @@ param tags object = {}
@description('Optional. List of allowed authentication modes for the Batch account that can be used to authenticate with the data plane.')
param allowedAuthenticationModes array = []

@allowed([
'Microsoft.Batch'
'Microsoft.KeyVault'
])
@description('Optional. Type of the key source.')
param encryptionKeySource string = 'Microsoft.Batch'
@description('Optional. The resource ID of a key vault to reference a customer managed key for encryption from.')
param cMKKeyVaultResourceId string = ''

@description('Conditional. Full path to the versioned secret. Required if `encryptionKeySource` is set to `Microsoft.KeyVault` or `poolAllocationMode` is set to `UserSubscription`.')
param encryptionKeyIdentifier string = ''
@description('Optional. The name of the customer managed key to use for encryption.')
param cMKKeyName string = ''

@description('Conditional. The resource ID of the Azure key vault associated with the Batch account. Required if `encryptionKeySource` is set to `Microsoft.KeyVault` or `poolAllocationMode` is set to `UserSubscription`.')
param keyVaultResourceId string = ''

@description('Conditional. The URL of the Azure key vault associated with the Batch account. Required if `encryptionKeySource` is set to `Microsoft.KeyVault` or `poolAllocationMode` is set to `UserSubscription`.')
param keyVaultUri string = ''
@description('Optional. The version of the customer managed key to reference for encryption. If not provided, the latest key version is used.')
param cMKKeyVersion string = ''

@description('Optional. Enable telemetry via the Customer Usage Attribution ID (GUID).')
param enableDefaultTelemetry bool = true
Expand Down Expand Up @@ -159,6 +155,16 @@ resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (ena
}
}

resource keyVaultReferenceKeyVault 'Microsoft.KeyVault/vaults@2021-10-01' existing = if (!empty(keyVaultReferenceResourceId)) {
name: last(split(keyVaultReferenceResourceId, '/'))
scope: resourceGroup(split(keyVaultReferenceResourceId, '/')[2], split(keyVaultReferenceResourceId, '/')[4])
}

resource cMKKeyVaultKey 'Microsoft.KeyVault/vaults/keys@2021-10-01' existing = if (!empty(cMKKeyVaultResourceId) && !empty(cMKKeyName)) {
name: '${last(split(cMKKeyVaultResourceId, '/'))}/${cMKKeyName}'
scope: resourceGroup(split(cMKKeyVaultResourceId, '/')[2], split(cMKKeyVaultResourceId, '/')[4])
}

resource batchAccount 'Microsoft.Batch/batchAccounts@2022-01-01' = {
name: name
location: location
Expand All @@ -167,15 +173,15 @@ resource batchAccount 'Microsoft.Batch/batchAccounts@2022-01-01' = {
properties: {
allowedAuthenticationModes: allowedAuthenticationModes
autoStorage: autoStorageConfig
encryption: {
keySource: encryptionKeySource
keyVaultProperties: encryptionKeySource == 'Microsoft.KeyVault' && systemAssignedIdentity == true || poolAllocationMode == 'UserSubscription' ? {
keyIdentifier: encryptionKeyIdentifier
} : null
}
keyVaultReference: encryptionKeySource == 'Microsoft.KeyVault' && systemAssignedIdentity == true || poolAllocationMode == 'UserSubscription' ? {
id: keyVaultResourceId
url: keyVaultUri
encryption: !empty(cMKKeyName) ? {
keySource: 'Microsoft.KeyVault'
keyVaultProperties: {
keyIdentifier: !empty(cMKKeyVersion) ? '${cMKKeyVaultKey.properties.keyUri}/${cMKKeyVersion}' : cMKKeyVaultKey.properties.keyUriWithVersion
}
} : null
keyVaultReference: poolAllocationMode == 'UserSubscription' ? {
id: keyVaultReferenceResourceId
url: keyVaultReferenceKeyVault.properties.vaultUri
} : null
poolAllocationMode: poolAllocationMode
publicNetworkAccess: publicNetworkAccess
Expand Down
Loading