In this lab, I explored how to provide secure, controlled, and compliant Azure storage for a new company application. The devs needed full control over how the storage was accessed β only via keys and managed identities, with role-based access control (RBAC), customer-managed encryption, and immutable blob retention policies for compliance and testing.
Letβs get into the details.
π Scenario
The company is developing a new app and wanted the backing storage to be secure and compliant:
- π Access only via keys and user-assigned managed identities
- π Encryption must use a customer-managed key (CMK) stored in Key Vault
- π Test files need to be locked down with time-based retention
- π§± Files should be stored under an encryption scope with infrastructure encryption
π οΈ Skilling Tasks
- β Create a storage account with infrastructure encryption
- β Create a user-assigned managed identity and assign RBAC
- β Secure access with Azure Key Vault and a customer-managed key
- β Enable immutable blob policies for file retention
- β Create an encryption scope with infrastructure encryption
πΉ Step 1: Create the Storage Account and Managed Identity
I started by creating a new resource group: storagerg2
.
Then, I created a Storage Account named az104bobstg2
with:
- Infrastructure encryption enabled (extra layer of encryption)
- Review + Create > β Passed validation > Created successfully
Next, I needed a user-assigned managed identity for the app:
- Searched for Managed identities
- Created one named
managedbob
instoragerg2
π After that, I granted the identity Storage Blob Data Reader permissions:
- Went to the IAM tab of my storage account
- Added the role to
managedbob
- Verified RBAC was assigned correctly
π Step 2: Secure Access with Azure Key Vault and CMK
I needed a Key Vault to store the customer-managed encryption key:
- Created a Key Vault called
keyvaultbob
in the same RG - Ensured Azure RBAC was selected
- Ensured Purge protection was enabled (critical for CMK use)
Got an error initially:
β βOperation not allowed by RBACβ
β
Fixed it by assigning myself the Key Vault Administrator role in IAM.
Then, I generated a key named bobkey
.
π‘ Note: You must enable Soft Delete and Purge Protection on the vault for customer-managed keys to work β I hit this roadblock too!
π Step 3: Configure the Storage Account to Use the Customer-Managed Key
Before assigning the key:
- I assigned the Key Vault Crypto Service Encryption User role to
managedbob
(via IAM in the RG).
Then, back in the Encryption blade of the storage account:
- Selected Customer-managed keys
- Pointed to my Key Vault and selected
bobkey
- Set the identity type to User-assigned, and selected
managedbob
- Saved changes β success!
π Now my storage account uses my Key Vault key to encrypt its contents.
π§· Step 4: Configure Time-Based Retention (Immutable Blob Policy)
To lock files for compliance testing, I enabled time-based immutability:
- Created a new container called
hold
- Uploaded a test file
- Opened the Access policy blade and added a Time-based retention policy for 5 days
- Saved the policy
Then, I tested it by trying to delete the file...
β Result: βFailed to delete blobs due to policyβ β exactly what I wanted!
π§ Step 5: Create an Encryption Scope with Infrastructure Encryption
For more control, I created a scoped encryption option:
- In Encryption > Encryption scopes, I clicked Add
- Named it
encryptionbob
- Set the encryption type to Microsoft-managed key
- Enabled Infrastructure encryption
- Created the scope
When creating a new container, I could now assign encryptionbob
as the encryption scope under the Advanced section.
β This means files in this container get encrypted using a defined scope, while the overall account still uses CMK.
π§Ή Cleanup Tip
If you're doing this in your own subscription, remember to delete the resource group to avoid unwanted costs:
az group delete --name storagerg2
π§ Key Takeaways
This was a super valuable exercise in securing and customizing storage for enterprise-grade apps.
Hereβs what I walked away with:
- RBAC + Managed Identities gives granular, secure access control
- Customer-Managed Keys (CMK) lets me bring my own encryption keys using Key Vault
- Immutable blob policies ensure compliance and protect against tampering or deletion
- Encryption scopes offer scoped, fine-grained encryption with optional infrastructure encryption
π― If you're building apps that need serious compliance, this setup is exactly how you'd secure your storage. The combo of encryption, role-based access, and immutability covers all the bases.
On to the next one! πͺ
Top comments (0)