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

[QUERY] How do I programmatically set-up storage account access keys for auto rotation in key vault? #20941

Closed
aniruddhagore1984 opened this issue May 10, 2021 · 4 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. KeyVault Mgmt This issue is related to a management-plane library. needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)

Comments

@aniruddhagore1984
Copy link

Query/Question
I intend to accomplish the following:

  1. create a storage account
  2. create a key vault
  3. add the storage account to the key vault aka add access keys to vault
  4. set-up storage access keys for auto rotation

I am developing in C# and have managed to accomplish (1) and (2) but not getting any help in docs for (3) and (4). Could you please point me in the right direction?

Environment:

  • Hosting platform or OS and .NET runtime version (dotnet --info output for .NET Core projects): Windows 10 .NET Framework
  • IDE and version : Visual Studio
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels May 10, 2021
@blueww
Copy link
Member

blueww commented May 10, 2021

@aniruddhagore1984

This need both storage SDK and key vault SDK.

For storage SDK side:

first you will need assign an identity to the storage account, and get the account identity ID, like following.

                var updateParameters = new StorageAccountUpdateParameters()
                {
                    Identity = new Identity() { Type = IdentityType.SystemAssigned }
                };
                account = storageMgmtClient.StorageAccounts.Update(rgname, accountName, updateParameters);
                string accountId = account.Identity.PrincipalId;

Then you need give the accountId wrapkey,unwrapkey,get access to the keyvault, and you also need create a key with Destination as Software in the keyvault. This part depends on Keyvault SDK, need keyvault SDK owner to answer.

Finally, you can update the keyvault key information to the storage account. As you need enabled key auto rotation, just skip set key version.

               updateParameters = new StorageAccountUpdateParameters
                {
                    Encryption = new Encryption
                    {
                        Services = new EncryptionServices { Blob = new EncryptionService { Enabled = true }, File = new EncryptionService { Enabled = true } },
                        KeySource = "Microsoft.Keyvault",
                        KeyVaultProperties =
                            new KeyVaultProperties
                            {
                                KeyName = keyVaultKey.KeyIdentifier.Name,
                                KeyVaultUri = keyVault.Properties.VaultUri
                            }
                    }
                };

                account = storageMgmtClient.StorageAccounts.Update(rgname, accountName, updateParameters);

For you reference, this is a sample to enable CMK in Powershell: https://docs.microsoft.com/en-us/azure/storage/common/customer-managed-keys-configure-key-vault?tabs=powershell

@jsquire jsquire added the Storage Storage Service (Queues, Blobs, Files) label May 10, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label May 10, 2021
@jsquire jsquire added Mgmt This issue is related to a management-plane library. needs-author-feedback Workflow: More information is needed from author to address the issue. labels May 10, 2021
@markcowl markcowl added KeyVault Service Attention Workflow: This issue is responsible by Azure service team. labels May 10, 2021
@ghost
Copy link

ghost commented May 10, 2021

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @RandalliLama, @schaabs, @jlichwa.

Issue Details

Query/Question
I intend to accomplish the following:

  1. create a storage account
  2. create a key vault
  3. add the storage account to the key vault aka add access keys to vault
  4. set-up storage access keys for auto rotation

I am developing in C# and have managed to accomplish (1) and (2) but not getting any help in docs for (3) and (4). Could you please point me in the right direction?

Environment:

  • Hosting platform or OS and .NET runtime version (dotnet --info output for .NET Core projects): Windows 10 .NET Framework
  • IDE and version : Visual Studio
Author: aniruddhagore1984
Assignees: blueww
Labels:

KeyVault, Mgmt, Service Attention, Storage, customer-reported, needs-author-feedback, question

Milestone: -

@markcowl markcowl removed the needs-author-feedback Workflow: More information is needed from author to address the issue. label May 10, 2021
@jlichwa
Copy link

jlichwa commented May 10, 2021

@aniruddhagore1984 if you are looking for managed storage account keys feature, here is the sample in .NET https://docs.microsoft.com/en-us/samples/azure/azure-sdk-for-net/share-link/

This feature does not add storage account key to key vault, just use Key Vault to manage access by generating storage account keys SAS tokens, more can be find here:
https://docs.microsoft.com/en-us/azure/key-vault/secrets/overview-storage-keys

Other than that when direct access to keys is required, key vault does not provide any built in way to rotate access keys in key vault besides using function like here:
https://docs.microsoft.com/en-us/azure/key-vault/secrets/tutorial-rotation-dual?tabs=azure-cli

@heaths heaths added the needs-author-feedback Workflow: More information is needed from author to address the issue. label May 17, 2021
@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label May 25, 2021
@ghost
Copy link

ghost commented May 25, 2021

Hi, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@ghost ghost closed this as completed Jun 8, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. KeyVault Mgmt This issue is related to a management-plane library. needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

No branches or pull requests

6 participants