DEV Community

Cover image for Advanced Azure Storage Security: Managed Identities, Key Vaults, and Immutability
Louis Oodo
Louis Oodo

Posted on

Advanced Azure Storage Security: Managed Identities, Key Vaults, and Immutability

Advanced Azure Storage Security: Managed Identities, Key Vaults, and Immutability

Introduction

Security is a multi-layered responsibility in the cloud. Beyond simple access keys, enterprise-grade storage requires robust identity management and data protection. In this guide, we will walk through the advanced configuration of an Azure Storage account. We will cover the implementation of User-Assigned Managed Identities, securing data with Customer-Managed Keys (CMK) via Azure Key Vault, and enforcing data integrity using time-based retention policies and infrastructure encryption scopes.


Create the storage account and managed identity

Provide a storage account for the web app.

  1. In the portal, search for and select Storage accounts.
    Storage accounts

  2. Select + Create.
    Create

  3. For Resource group select Create new. Give your resource group a name and select OK to save your changes.
    Resource group

  4. Provide a Storage account name. Ensure the name is unique and meets the naming requirements.
    Storage account name

  5. Move to the Encryption tab.
    Encryption

  6. Check the box for Enable infrastructure encryption.
    Enable infrastructure encryption

  7. Notice the warning, This option cannot be changed after this storage account is created.
    Notice the warning

  8. Select Review + Create.
    Review + Create
    Create

  9. Wait for the resource to deploy.
    resource to deploy

Provide a managed identity for the web app to use. Learn more about managed identities.

  1. Search for and select Managed identities.
    Managed identities

  2. Select Create.
    Create

  3. Select your resource group.
    resource group

  4. Give your managed identity a name.
    managed identity a name

  5. Select Review and create, and then Create.
    Review and create
    Create

Assign the correct permissions to the managed identity. The identity only needs to read and list containers and blobs. Learn more about how to assign Azure roles.

  1. Search for and select your storage account.
    storage account

  2. Select the Access Control (IAM) blade.
    Access Control (IAM)

  3. Select Add role assignment (center of the page).
    Add role assignment

  4. On the Job functions roles page, search for and select the Storage Blob Data Reader role.
    Storage Blob Data Reader

  5. On the Members page, select Managed identity.
    Managed identity

  6. Select Select members, in the Managed identity drop-down select User-assigned managed identity.
    User-assigned managed identity

  7. Select the managed identity you created in the previous step.
    managed identity

  8. Click Select and then Review + assign the role.
    Review + assign

  9. Select Review + assign a second time to add the role assignment.

  10. Your storage account can now be accessed by a managed identity with the Storage Data Blob Reader permissions.


Secure access to the storage account with a key vault and key

To create the key vault and key needed for this part of the lab, your user account must have Key Vault Administrator permissions. Learn more about how to provide access to Key Vault keys, certificates, and secrets with an Azure role-based access control

  1. In the portal, search for and select Resource groups.
    Resource groups

  2. Select your resource group, and then the Access Control (IAM) blade.
    resource group
    Access Control (IAM)

  3. Select Add role assignment (center of the page).
    Add role assignment

  4. On the Job functions roles page, search for and select the Key Vault Administrator role.
    Key Vault Administrator

  5. On the Members page, select User, group, or service principal.
    User, group, or service principal

  6. Select Select members.
    Select members

  7. Search for and select your user account. Your user account is shown in the top right of the portal.
    select your user account

  8. Click Select and then Review + assign.
    Select
    Review + assign

  9. Select Review + assign a second time to add the role assignment.
    Review + assign

  10. You are now ready to continue with the lab.

Create a key vault to store the access keys.

  1. In the portal, search for and select Key vaults.
    Key vaults

  2. Select Create.
    Create

  3. Select your resource group.
    resource group

  4. Provide the name for the key vault. The name must be unique.
    key vault name

  5. Ensure on the Access configuration tab that Azure role-based access control (recommended) is selected.
    Azure role-based access control

  6. Select Review + create.
    Review + create

  7. Wait for the validation checks to complete and then select Create.
    Create

  8. After the deployment, select Go to resource.
    Go to resource

  9. On the Overview blade ensure both Soft-delete and Purge protection are enabled.
    Soft-delete and Purge protection
    Create a customer-managed key in the key vault.

  10. In your key vault, in the Objects section, select the Keys blade.
    Objects

  11. Select Generate/Import and Name the key.
    Generate/Import
    Name

  12. Take the defaults for the rest of the parameters, and Create the key.
    Create


Configure the storage account to use the customer managed key in the key vault

Before you can complete the next steps, you must assign the Key Vault Crypto Service Encryption User role to the managed identity. Learn more about how to use a system-assigned managed identity to authorize access

  1. In the portal, search for and select Resource groups.
    Resource groups

  2. Select your resource group, and then the Access Control (IAM) blade.
    resource group, and then the Access Control (IAM)

  3. Select Add role assignment (center of the page).
    Add role assignment

  4. On the Job functions roles page, search for and select the Key Vault Crypto Service Encryption User role.
    Key Vault Crypto Service Encryption User
    Next

  5. On the Members page, select Managed identity.
    Managed identity

  6. Select Select members, in the Managed identity drop-down select User-assigned managed identity.
    User-assigned managed identity

  7. Select your managed identity.
    managed identity

  8. Click Select and then Review + assign.
    Review + assign

  9. Select Review + assign a second time to add the role assignment.
    Review + assign

Configure the storage account to use the customer managed key in your key vault. Learn more about customer managed keys on an existing storage account.

  1. Return to your the storage account.
    storage account

  2. In the Security + networking section, select the Encryption blade.
    Security + networking

  3. Select Customer-managed keys.
    Customer-managed keys

  4. Select a key vault and key. Select your key vault and key.
    key vault and key

  5. Select to confirm your choices.
    Select

  6. Ensure the Identity type is User-assigned.
    User-assigned

  7. Select an identity.
    identity

  8. Select your managed identity then select Add.
    Add

  9. Save your changes.
    Save

  10. If you receive an error that your identity does not have the correct permissions, wait a minute and try again.


Configure an time-based retention policy and an encryption scope.

The developers require a storage container where files can’t be modified, even by the administrator. Learn more about blob immutable storage.

  1. Navigate to your storage account.
    storage account

  2. In the Data storage section, select the Containers blade.
    Data storage

  3. Create a container called hold. Take the defaults. Be sure to Create the container.
    hold

  4. Upload a file to the container.
    Upload

  5. In the Settings section, select the Access policy blade.
    Setting

  6. In the Immutable blob storage section, select + Add policy.
    Immutable blob storage

  7. For the Policy type, select time-based retention.
    Policy type

  8. Set the Retention period to 5 days.
    Retention period

  9. Be sure to Save your changes.
    Save

  10. Try to delete the file in the container.
    delete

  11. Verify you are notified failed to delete blobs due to policy.
    failed to delete blobs

The developers require an encryption scope that enables infrastructure encryption. Learn more about infrastructure encryption.

  1. Navigate back to your storage account.
    storage account

  2. In the Security + networking blade, select Encryption.
    Security + networking

  3. In the Encryption scopes tab, select Add.
    Encryption scopes

  4. Give your encryption scope a name.
    name

  5. The Encryption type is Microsoft-managed key.
    Microsoft-managed key

  6. Set Infrastructure encryption to Enable.
    Infrastructure encryption

  7. Create the encryption scope.
    Create

  8. Return to your storage account and create a new container.
    new container

  9. Notice on the New container page, there is the Name and Public access level.
    New container

  10. Notice in the Advanced section you can select the Encryption scope you created and apply it to all blobs in the container.
    Advanced


Conclusion

By implementing these configurations, you have successfully established a highly secure and compliant storage environment. Using User-Assigned Managed Identities removes the risk associated with hard-coded credentials, while Customer-Managed Keys ensure you maintain full control over your data encryption. Furthermore, the use of immutable storage and specialized encryption scopes provides the data integrity required for modern development workflows. This architecture not only protects against external threats but also safeguards your data from accidental modification or deletion.

Top comments (0)