DEV Community

Cover image for Providing storage with secure access for an app using managed identity and role-based access control
Stephen Onyewuchi
Stephen Onyewuchi

Posted on • Edited on

Providing storage with secure access for an app using managed identity and role-based access control

Table of contents

Step 1. Create the storage account and managed identity.
Step 2. Secure access to the storage account with a key vault and key.
Step 3. Configure the storage account to use the customer managed key in the key vault
Step 4. Configure a time-based retention policy and an encryption scope.

Step 1. - Create the storage account and managed identity

1. Provide a storage account for the web app.

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

2024-10-30_20h51_02

  • Select + Create.

2024-10-30_20h55_08

  • For Resource group select Create new. Give your resource group a name and select OK to save your changes.
  • Provide a Storage account name. Ensure the name is unique and meets the naming requirements.

2024-10-30_21h07_09

  • Move to the Encryption tab.
  • Check the box for Enable infrastructure encryption.
  • Notice the warning, this option cannot be changed after this storage account is created.
  • Select Review + Create.
  • Wait for the resource to deploy.

2024-10-30_21h10_10

2. Provide a managed identity for the web app to use.

  • Search for and select Managed identities.

2024-10-30_21h19_25

  • Select + Create.

2024-10-30_21h23_23

  • Select your resource group.
  • Give your managed identity a name.

2024-10-30_21h27_45

  • Select Review + create, and then Create.
  • Assign the correct permissions to the managed identity. The identity only needs to read and list containers and blobs.
  • Search for and select your storage account.
  • Select the Access Control (IAM) blade.
  • Select Add role assignment (center of the page).

2024-11-02_13h59_51

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

2024-11-02_14h04_52

  • On the Members page, select Managed identity.
  • Select + Select members, in the Managed identity drop-down select User-assigned managed identity.
  • Select the managed identity you created in the previous step.
  • Click Select and then Review + assign the role.

2024-11-02_14h08_15

  • Select Review + assign a second time to add the role assignment.
  • Your storage account can now be accessed by a managed identity with the Storage Data Blob Reader permissions.

2024-11-02_14h11_41

Step 2. - Secure access to the storage account with a key vault and key

1. To create the key vault and key needed for this part of the lab, your user account must have Key Vault Administrator permissions.

  • In the portal, search for and select Resource groups.
  • Select your resource group, and then the Access Control (IAM) blade.
  • Select Add role assignment (center of the page).

2024-11-02_14h14_14

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

2024-11-02_14h16_49

  • On the Members page, select User, group, or service principal.
  • Select + Select members.
  • Search for and select your user account. Your user account is shown in the top right of the portal.
  • Click Select and then Review + assign.

2024-11-02_14h20_51

  • Select Review + assign a second time to add the role assignment.
  • You are now ready to continue with the lab.

2024-11-02_14h24_48

2. Create a key vault to store the access keys.

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

2024-11-02_14h26_39

  • Select + Create.

2024-11-02_14h29_34

  • Select your Resource group.
  • Provide the name for the key vault. The name must be unique.

2024-11-02_14h42_22

  • Ensure on the Access configuration tab that Azure role-based access control (recommended) is selected.
  • Select Review + create.
  • Wait for the validation checks to complete and then select + Create.

2024-11-02_14h44_54

  • After the deployment, select Go to resource.

2024-11-02_14h49_23

  • On the Overview blade ensure both Soft-delete and Purge protection are enabled.

2024-11-02_14h51_36

3. Create a customer-managed key in the key vault.

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

2024-11-02_14h55_04

  • Select Generate/Import and Name the key.
  • Take the defaults for the rest of the parameters, and Create the key.

2024-11-02_14h57_24

Step 3. - Configure the storage account to use the customer managed key in the key vault

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

  • In the portal, search for and select Resource groups.
  • Select your resource group, and then the Access Control (IAM) blade.
  • Select Add role assignment (center of the page).

2024-11-02_15h08_34

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

2024-11-02_15h12_12

  • On the Members page, select Managed identity.
  • Select + Select members, in the Managed identity drop-down select User-assigned managed identity.
  • Select your managed identity.
  • Click Select and then Review + assign.

2024-11-02_15h18_26

  • Select Review + assign a second time to add the role assignment.
  • Select check access, then View my access to confirm roles

2024-11-02_15h30_36

2. 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.

  • Return to your the storage account.
  • In the Security + networking section, select the Encryption blade.
  • Select Customer-managed keys.

2024-11-02_15h39_52

  • Select Select a key vault and key. Select your key vault and key.
  • Select to confirm your choices.
  • Ensure the Identity type is User-assigned.
  • Select an identity.
  • Select your managed identity then select Add.
  • Save your changes.

2024-11-02_15h44_40

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

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

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

  • Navigate to your storage account.
  • In the Data storage section, select the Containers blade.
  • Create a container called hold. Take the defaults. Be sure to Create the container.

2024-11-02_16h05_20

  • Upload a file to the container.
  • Navigate to the container.

2024-11-02_16h09_03

  • In the Settings section, select the Access policy blade.
  • In the Immutable blob storage section, select + Add policy.
  • For the Policy type, select time-based retention.
  • Set the Retention period to 5 days.
  • Be sure to Save your changes.

2024-11-02_16h13_56

  • Try to delete the file in the container.
  • Verify you are notified failed to delete blobs due to policy.

2024-11-02_16h18_46

2. The developers require an encryption scope that enables infrastructure encryption.
Find our more about infrastructure encryption.

  • Navigate back to your storage account.
  • In the Security + networking blade, select Encryption.
  • In the Encryption scopes tab, select Add.
  • Give your encryption scope a name.
  • The Encryption type is Microsoft-managed key.
  • Set Infrastructure encryption to Enable.
  • Create the encryption scope.

2024-11-02_16h23_03

  • Return to your storage account and create a new container.
  • Notice on the New container page, there is the Name and Public access level.
  • Notice in the Advanced section you can select the Encryption scope you created and apply it to all blobs in the container.

2024-11-02_16h41_24
Back to top

Top comments (0)