DEV Community

Cover image for Provide storage for a new company app
Afeez Adeyemo
Afeez Adeyemo

Posted on

Provide storage for a new company app

This is a step by step tutorial on how to provide storage for a new company app.

The company is designing and developing a new app. Developers need to ensure the storage is only accessed using keys and managed identities. The developers would like to use role-based access control. To help with testing, protected immutable storage is needed.

Table of Content

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.

Storage accounts

  • Select + Create.

+ create

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

Resource group

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

Storage account

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

Encryption tab

  • Wait for the resource to deploy

deployment complete

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

  • Search for and select Managed identities.

search for managed identities

  • Select Create.

+ create
- Select your resource group.
- Give your managed identity a name.

  • Select Review and create, and then Create.

IAM

Create

deployment is complete

3. 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).

Add role assignment

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

Storage Blob Data Reader

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

Select members

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

Review + assign

Image description

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

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.

Resource group

  • Select your resource group, and then the Access Control (IAM) blade.
  • Select Add role assignment (center of the page).

IAM blade

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

key vault administrator

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

members

review + assign

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

review + assign

  • You are now ready to continue with the lab.
  1. Create a key vault to store the access keys.
  • In the portal, search for and select Key vaults.

search for key vault

  • Select Create.

create

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

key vault name

  • Ensure on the Access configuration tab that Azure role-based access control (recommended) is selected.
  • Select Review + create.

access configuration

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

create

  • After the deployment, select Go to resource.

go to resource

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

soft delete and purge protection enabled

  1. Create a customer-managed key in the key vault.
  • In your key vault, in the Objects section, select the Keys blade.
  • Select Generate/Import and Name the key.

keys blade

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

create key

key enabled

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.

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

resource group

  • Select your resource group, and then the Access Control (IAM) blade.
  • Select Add role assignment (center of the page).

add role assignment

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

Key Vault Crypto Service Encryption User

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

members

Review + assign

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

Review + assign

  1. Configure the storage account to use the customer managed key in your key vault.
  • Return to your the storage account.

storage account

  • In the Security + networking section, select the Encryption blade.
  • Select Customer-managed keys.
  • Select a key vault and key.

encryption key

  • Select your key vault and key.
  • Select to confirm your choices.

Image description

  • Ensure the Identity type is User-assigned.
  • Select an identity.

select an identity

  • Select your managed identity then select Add.
  • Save your changes.

save changes

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

Step 4: Configure a 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.
  • 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.

create a container

  • Upload a file to the container.

upload a file

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

access policy

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

try to delete

  1. The developers require an encryption scope that enables infrastructure encryption.
  • Navigate back to your storage account.
  • In the Security + networking blade, select Encryption.
  • In the Encryption scopes tab, select Add.

Encryption

  • Give your encryption scope a name.
  • The Encryption type is Microsoft-managed key.
  • Set Infrastructure encryption to Enable.
  • Create the encryption scope.

encryption scope

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

Image description

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

Top comments (0)