Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add key vault to storage account - avm/res/storage/storage-account #1920

Merged
merged 43 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
304081f
Default version is 2 for Hash
Agazoth May 6, 2024
a6637cd
SetAMVModule executed
Agazoth May 7, 2024
fe19f2c
bicep build run directly
Agazoth May 7, 2024
7bac7a6
fix: CDN Profile - Parameter name for originGroups - `avm/res/cdn/pro…
cloudchristoph May 6, 2024
1fde75f
feat: added option to enable image cleaner to container service aks. …
PixelRobots May 6, 2024
a074087
feat: Bing is not available - `avm/res/cognitive-services/account` (#…
Agazoth May 6, 2024
b72e39d
fix: Fixed typo in 'Publish from tag' workflow (#1853)
AlexanderSehr May 6, 2024
f8654ff
feat: Removed enforcement of UDT schemas for pattern modules (#1832)
AlexanderSehr May 6, 2024
59d1d87
fix: Update files after Set-AVMModule run - `avm/res/cognitive-servic…
ilhaan May 6, 2024
57f1695
fix: network watcher missing v2 formatting (#1855)
eriqua May 7, 2024
307656a
fix: app managed environment missing v2 formatting (#1856)
eriqua May 7, 2024
7f4ed46
feat: add requested features to VM module - `avm/res/compute/virtual-…
rahalan May 7, 2024
cb1bb0b
fix: Added missing context switching to deployment target resolution …
AlexanderSehr May 7, 2024
687ed1c
feat: Implemented logic to make `resourceLocation` optional in CI (#1…
AlexanderSehr May 8, 2024
3ec9f47
feat: Added alias case handling for resource ID resolution in removal…
AlexanderSehr May 9, 2024
7fee121
fix: service bus authorization rules default value fix (#1890)
ChrisSidebotham May 9, 2024
6295766
feat: Enabled support for `*` properties in UDTs (#1891)
AlexanderSehr May 9, 2024
9c4234b
feat: Added the option to declare a specific resource type to be remo…
AlexanderSehr May 10, 2024
98467c4
feat: Add new parameters for `avm/res/virtual-machine-images/image-te…
ahmadabdalla May 11, 2024
553b39d
feat: Migrated module App/Jobs from CARML - `avm/res/app/job` (#1823)
AlexanderSehr May 11, 2024
1ff4980
fix: Remove ptn readme (#1916)
eriqua May 12, 2024
e57a04b
Added Key Vault secret management to Storage Account
Agazoth May 13, 2024
b5438c9
Merge branch 'main' into KVToStorageAccount
Agazoth May 13, 2024
c5de070
Revert "Merge branch 'main' into main"
Agazoth May 14, 2024
9cb7df0
Updated description according to documentation
Agazoth May 14, 2024
646acd3
Fixed wrong sku name
Agazoth May 14, 2024
8752900
Ran Set-AVMModule and fixed readme alphabetized sort error
Agazoth May 14, 2024
9fe87d0
Fixed sort order
Agazoth May 14, 2024
f08b1ea
Merge branch 'main' into KVToStorageAccount
Agazoth May 14, 2024
e81078c
Yet another update
Agazoth May 14, 2024
a01fe23
Merged with origin
Agazoth Aug 12, 2024
94746dc
Implemented Secrets Export
Agazoth Aug 13, 2024
b12e253
Ran Set-AVMModule
Agazoth Aug 13, 2024
06871a3
Updated to camelCase
Agazoth Aug 13, 2024
f8b4344
Merge branch 'main' into KVToStorageAccount
Agazoth Aug 13, 2024
5347ba2
Merge branch 'main' into KVToStorageAccount
Agazoth Aug 13, 2024
c54366a
Updated according to requested changes
Agazoth Aug 13, 2024
2c3d342
Set-AVMModule
Agazoth Aug 13, 2024
2aa34ad
Updated description text
Agazoth Aug 14, 2024
398cea6
Added missing bits
Agazoth Aug 14, 2024
11a36f8
Merge branch 'main' into KVToStorageAccount
Agazoth Aug 14, 2024
3bedb3b
Merge branch 'main' into KVToStorageAccount
Agazoth Aug 16, 2024
396e64d
Version bumped
Agazoth Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 136 additions & 12 deletions avm/res/storage/storage-account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This module deploys a Storage Account.
| `Microsoft.Authorization/locks` | [2020-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-05-01/locks) |
| `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) |
| `Microsoft.Insights/diagnosticSettings` | [2021-05-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings) |
| `Microsoft.KeyVault/vaults/secrets` | [2023-07-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.KeyVault/2023-07-01/vaults/secrets) |
| `Microsoft.Network/privateEndpoints` | [2023-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-11-01/privateEndpoints) |
| `Microsoft.Network/privateEndpoints/privateDnsZoneGroups` | [2023-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-11-01/privateEndpoints/privateDnsZoneGroups) |
| `Microsoft.Storage/storageAccounts` | [2022-09-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Storage/2022-09-01/storageAccounts) |
Expand Down Expand Up @@ -46,12 +47,13 @@ The following section provides usage examples for the module, which were used to
- [Deploying as a Block Blob Storage](#example-2-deploying-as-a-block-blob-storage)
- [Using only changefeed configuration](#example-3-using-only-changefeed-configuration)
- [Using only defaults](#example-4-using-only-defaults)
- [Using large parameter set](#example-5-using-large-parameter-set)
- [Deploying with a NFS File Share](#example-6-deploying-with-a-nfs-file-share)
- [Using Customer-Managed-Keys with System-Assigned identity](#example-7-using-customer-managed-keys-with-system-assigned-identity)
- [Using Customer-Managed-Keys with User-Assigned identity](#example-8-using-customer-managed-keys-with-user-assigned-identity)
- [Deploying as Storage Account version 1](#example-9-deploying-as-storage-account-version-1)
- [WAF-aligned](#example-10-waf-aligned)
- [Deploying with a key vault reference to save secrets](#example-5-deploying-with-a-key-vault-reference-to-save-secrets)
- [Using large parameter set](#example-6-using-large-parameter-set)
- [Deploying with a NFS File Share](#example-7-deploying-with-a-nfs-file-share)
- [Using Customer-Managed-Keys with System-Assigned identity](#example-8-using-customer-managed-keys-with-system-assigned-identity)
- [Using Customer-Managed-Keys with User-Assigned identity](#example-9-using-customer-managed-keys-with-user-assigned-identity)
- [Deploying as Storage Account version 1](#example-10-deploying-as-storage-account-version-1)
- [WAF-aligned](#example-11-waf-aligned)

### Example 1: _Deploying as a Blob Storage_

Expand Down Expand Up @@ -287,7 +289,71 @@ module storageAccount 'br/public:avm/res/storage/storage-account:<version>' = {
</details>
<p>

### Example 5: _Using large parameter set_
### Example 5: _Deploying with a key vault reference to save secrets_

This instance deploys the module saving all its secrets in a key vault.


<details>

<summary>via Bicep module</summary>

```bicep
module storageAccount 'br/public:avm/res/storage/storage-account:<version>' = {
name: 'storageAccountDeployment'
params: {
// Required parameters
name: 'kvref'
// Non-required parameters
location: '<location>'
secretsExportConfiguration: {
connectionString1: 'custom-connectionString1-name'
connectionString2: 'custom-connectionString2-name'
key1: 'custom-key1-name'
key2: 'custom-key2-name'
keyVaultResourceId: '<keyVaultResourceId>'
}
}
}
```

</details>
<p>

<details>

<summary>via JSON Parameter file</summary>

```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"name": {
"value": "kvref"
},
// Non-required parameters
"location": {
"value": "<location>"
},
"secretsExportConfiguration": {
"value": {
"connectionString1": "custom-connectionString1-name",
"connectionString2": "custom-connectionString2-name",
"key1": "custom-key1-name",
"key2": "custom-key2-name",
"keyVaultResourceId": "<keyVaultResourceId>"
}
}
}
}
```

</details>
<p>

### Example 6: _Using large parameter set_

This instance deploys the module with most of its features enabled.

Expand Down Expand Up @@ -1161,7 +1227,7 @@ module storageAccount 'br/public:avm/res/storage/storage-account:<version>' = {
</details>
<p>

### Example 6: _Deploying with a NFS File Share_
### Example 7: _Deploying with a NFS File Share_

This instance deploys the module with a NFS File Share.

Expand Down Expand Up @@ -1235,7 +1301,7 @@ module storageAccount 'br/public:avm/res/storage/storage-account:<version>' = {
</details>
<p>

### Example 7: _Using Customer-Managed-Keys with System-Assigned identity_
### Example 8: _Using Customer-Managed-Keys with System-Assigned identity_

This instance deploys the module using Customer-Managed-Keys using a System-Assigned Identity. This required the service to be deployed twice, once as a pre-requisite to create the System-Assigned Identity, and once to use it for accessing the Customer-Managed-Key secret.

Expand Down Expand Up @@ -1339,7 +1405,7 @@ module storageAccount 'br/public:avm/res/storage/storage-account:<version>' = {
</details>
<p>

### Example 8: _Using Customer-Managed-Keys with User-Assigned identity_
### Example 9: _Using Customer-Managed-Keys with User-Assigned identity_

This instance deploys the module using Customer-Managed-Keys using a User-Assigned Identity to access the Customer-Managed-Key secret.

Expand Down Expand Up @@ -1459,7 +1525,7 @@ module storageAccount 'br/public:avm/res/storage/storage-account:<version>' = {
</details>
<p>

### Example 9: _Deploying as Storage Account version 1_
### Example 10: _Deploying as Storage Account version 1_

This instance deploys the module as Storage Account version 1.

Expand Down Expand Up @@ -1511,7 +1577,7 @@ module storageAccount 'br/public:avm/res/storage/storage-account:<version>' = {
</details>
<p>

### Example 10: _WAF-aligned_
### Example 11: _WAF-aligned_

This instance deploys the module in alignment with the best-practices of the Azure Well-Architected Framework.

Expand Down Expand Up @@ -2118,6 +2184,7 @@ module storageAccount 'br/public:avm/res/storage/storage-account:<version>' = {
| [`requireInfrastructureEncryption`](#parameter-requireinfrastructureencryption) | bool | A Boolean indicating whether or not the service applies a secondary layer of encryption with platform managed keys for data at rest. For security reasons, it is recommended to set it to true. |
| [`roleAssignments`](#parameter-roleassignments) | array | Array of role assignments to create. |
| [`sasExpirationPeriod`](#parameter-sasexpirationperiod) | string | The SAS expiration period. DD.HH:MM:SS. |
| [`secretsExportConfiguration`](#parameter-secretsexportconfiguration) | object | Key vault reference and secret settings for the module's secrets export. |
| [`skuName`](#parameter-skuname) | string | Storage Account Sku Name. |
| [`supportsHttpsTrafficOnly`](#parameter-supportshttpstrafficonly) | bool | Allows HTTPS traffic only to storage service if sets to true. |
| [`tableServices`](#parameter-tableservices) | object | Table service and tables to create. |
Expand Down Expand Up @@ -3179,6 +3246,63 @@ The SAS expiration period. DD.HH:MM:SS.
- Type: string
- Default: `''`

### Parameter: `secretsExportConfiguration`

Key vault reference and secret settings for the module's secrets export.

- Required: No
- Type: object

**Required parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`keyVaultResourceId`](#parameter-secretsexportconfigurationkeyvaultresourceid) | string | The key vault name where to store the keys and connection strings generated by the modules. |

**Optional parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`connectionString1`](#parameter-secretsexportconfigurationconnectionstring1) | string | Default to Key1-ConnectionString. The primary connection string secret name to create. |
| [`connectionString2`](#parameter-secretsexportconfigurationconnectionstring2) | string | Default to Key2-ConnectionString. The secondary connection string secret name to create. |
| [`key1`](#parameter-secretsexportconfigurationkey1) | string | Default to Key1Key. The primary key secret name to create. |
| [`key2`](#parameter-secretsexportconfigurationkey2) | string | Default to Key2-Key. The secondary key secret name to create. |

### Parameter: `secretsExportConfiguration.keyVaultResourceId`

The key vault name where to store the keys and connection strings generated by the modules.

- Required: Yes
- Type: string

### Parameter: `secretsExportConfiguration.connectionString1`

Default to Key1-ConnectionString. The primary connection string secret name to create.

- Required: No
- Type: string

### Parameter: `secretsExportConfiguration.connectionString2`

Default to Key2-ConnectionString. The secondary connection string secret name to create.

- Required: No
- Type: string

### Parameter: `secretsExportConfiguration.key1`

Default to Key1Key. The primary key secret name to create.

- Required: No
- Type: string

### Parameter: `secretsExportConfiguration.key2`

Default to Key2-Key. The secondary key secret name to create.

- Required: No
- Type: string

### Parameter: `skuName`

Storage Account Sku Name.
Expand Down
66 changes: 66 additions & 0 deletions avm/res/storage/storage-account/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ param sasExpirationPeriod string = ''
])
param keyType string?

@description('Optional. Key vault reference and secret settings for the module\'s secrets export.')
param secretsExportConfiguration secretsExportConfigurationType?

var supportsBlobService = kind == 'BlockBlobStorage' || kind == 'BlobStorage' || kind == 'StorageV2' || kind == 'Storage'
var supportsFileService = kind == 'FileStorage' || kind == 'StorageV2' || kind == 'Storage'

Expand Down Expand Up @@ -628,6 +631,52 @@ module storageAccount_tableServices 'table-service/main.bicep' = if (!empty(tabl
}
}

module secretsExport 'modules/keyVaultExport.bicep' = if (secretsExportConfiguration != null) {
name: '${uniqueString(deployment().name, location)}-secrets-kv'
scope: resourceGroup(
split((secretsExportConfiguration.?keyVaultResourceId ?? '//'), '/')[2],
split((secretsExportConfiguration.?keyVaultResourceId ?? '////'), '/')[4]
)
params: {
keyVaultName: last(split(secretsExportConfiguration.?keyVaultResourceId ?? '//', '/'))
secretsToSet: union(
[],
contains(secretsExportConfiguration!, 'key1')
Agazoth marked this conversation as resolved.
Show resolved Hide resolved
? [
{
name: secretsExportConfiguration!.key1
value: storageAccount.listKeys().keys[0].value
}
]
: [],
contains(secretsExportConfiguration!, 'connectionString1')
? [
{
name: secretsExportConfiguration!.connectionString1
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};AccountKey=${storageAccount.listKeys().keys[0]};EndpointSuffix=core.windows.net'
}
]
: [],
contains(secretsExportConfiguration!, 'key2')
Agazoth marked this conversation as resolved.
Show resolved Hide resolved
? [
{
name: secretsExportConfiguration!.key2
value: storageAccount.listKeys().keys[1].value
}
]
: [],
contains(secretsExportConfiguration!, 'connectionString2')
? [
{
name: secretsExportConfiguration!.connectionString2
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};AccountKey=${storageAccount.listKeys().keys[1]};EndpointSuffix=core.windows.net'
}
]
: []
)
}
}

@description('The resource ID of the deployed storage account.')
output resourceId string = storageAccount.id

Expand Down Expand Up @@ -851,3 +900,20 @@ type customerManagedKeyType = {
@description('Optional. User assigned identity to use when fetching the customer managed key. If used must also be specified in `managedIdentities.userAssignedResourceIds`. Required if no system assigned identity is available for use.')
userAssignedIdentityResourceId: string?
}?

type secretsExportConfigurationType = {
@description('Required. The key vault name where to store the keys and connection strings generated by the modules.')
keyVaultResourceId: string

@description('Optional. Default to Key1Key. The primary key secret name to create.')
Agazoth marked this conversation as resolved.
Show resolved Hide resolved
key1: string?

@description('Optional. Default to Key1-ConnectionString. The primary connection string secret name to create.')
connectionString1: string?

@description('Optional. Default to Key2-Key. The secondary key secret name to create.')
key2: string?

@description('Optional. Default to Key2-ConnectionString. The secondary connection string secret name to create.')
connectionString2: string?
}
Loading