Back to Blog

Encrypt and Isolate Storage: CMK, AAD Auth and Private Endpoints

Complete AZ-104 tutorial on Azure Storage Accounts. Learn customer-managed keys, Azure AD auth, network rules, SFTP support.

Encrypt and Isolate Storage: CMK, AAD Auth and Private Endpoints

Encrypt and Isolate Storage: CMK, AAD Auth, and Private Endpoints

Introduction

In today's digital landscape, securing data in the cloud is paramount, especially for organizations that handle sensitive information. Azure Storage Accounts provide robust options for encryption and isolation, crucial topics for the AZ-104 certification. This tutorial covers Customer-Managed Keys (CMK), Azure Active Directory (AAD) Authentication, and Private Endpoints—key features that enhance the security posture of Azure Storage.

Understanding these concepts is vital for Azure Administrators to ensure data protection and compliance with regulatory standards. Key scenarios include utilizing CMK for encryption control, leveraging AAD for secure data access, and implementing private endpoints to isolate storage accounts from public networks. This tutorial will guide you through the practical implementation of these features, ensuring you're prepared for real-world applications and the AZ-104 exam.

Prerequisites

To follow along with this tutorial, ensure you have:

  • An Azure subscription with permissions to create and manage storage accounts.
  • Role-Based Access Control (RBAC) permissions to manage Azure Key Vault and storage accounts.
  • Tools installed:
    • Azure CLI or Azure PowerShell.
    • Azure Portal for GUI-based management.
  • Required services enabled:
    • Azure Key Vault for managing customer-managed keys.
    • Networking capabilities for Private Endpoints.

Core Concepts

Customer-Managed Keys (CMK)

CMK allows users to control their encryption keys for data stored in Azure. This feature offers enhanced security by providing the ability to create, rotate, and revoke keys using Azure Key Vault.

Azure Active Directory (AAD) Authentication

AAD Authentication provides a mechanism for securing access to Azure Storage by integrating Azure Role-Based Access Control (RBAC). It allows administrators to assign permissions at a granular level, enhancing security by minimizing exposure.

Private Endpoints

Private Endpoints enable secure connections to Azure Storage services over a private link, isolating the storage account from the public internet. This ensures that all traffic remains within the Azure backbone network, significantly reducing the attack surface.

Limitations and Pricing Notes

  • CMK has associated costs with Azure Key Vault and may require management overhead for key rotation.
  • AAD Authentication requires proper configuration of roles and permissions, which may complicate setups in hybrid environments.
  • Private Endpoints are not available for general-purpose v1 storage accounts and incur additional costs based on bandwidth usage.

Syntax/Configuration

Azure CLI Commands

Create a Storage Account with CMK

az storage account create \
  --name <storage-account-name> \
  --resource-group <resource-group-name> \
  --location <location> \
  --sku Standard_LRS \
  --encryption-key-source Microsoft.Keyvault \
  --encryption-key-vault <key-vault-id> \
  --encryption-key-name <key-name>

Configure AAD Authentication

az storage account update \
  --name <storage-account-name> \
  --resource-group <resource-group-name> \
  --enable-azure-active-directory-authentication true

Create a Private Endpoint

az network private-endpoint create \
  --name <private-endpoint-name> \
  --resource-group <resource-group-name> \
  --vnet-name <vnet-name> \
  --subnet <subnet-name> \
  --private-connection-resource-id <resource-id> \
  --group-ids blob

Azure Portal Steps

  1. Creating a Storage Account with CMK:

    • Navigate to Storage accounts > Create.
    • Under the Encryption tab, select Customer-managed keys (CMK).
    • Provide the Key Vault details.
  2. Configuring AAD Authentication:

    • Go to your storage account, select Access Control (IAM).
    • Assign necessary roles (e.g., Storage Blob Data Owner).
  3. Creating a Private Endpoint:

    • Navigate to Private endpoints > Create.
    • Specify the target resource as your storage account.

Practical Examples

Example 1: Creating a Storage Account with CMK

Use the Azure CLI to create a storage account that utilizes customer-managed keys for encryption.

Explanation

This account will use a specified key stored in Azure Key Vault, allowing for enhanced control over encryption.

Example 2: Enabling AAD Authentication

Enable Azure Active Directory Authentication for your storage account to leverage RBAC.

Explanation

This allows users to authenticate using their Azure AD credentials, providing a more secure access model.

Example 3: Creating a Private Endpoint

Create a private endpoint for secure access to your storage account within a virtual network.

Explanation

This isolates storage access from the public internet, leveraging Azure's internal network.

Example 4: Accessing Azure Storage with AAD

Use Azure CLI to list blobs in a storage account authenticated via Azure AD.

az storage blob list \
  --account-name <storage-account-name> \
  --account-key <account-key>

Example 5: Key Rotation in Azure Key Vault

Rotate your customer-managed key within Azure Key Vault.

Explanation

Regularly updating keys is essential for maintaining security standards.

Example 6: Configuring Network Rules

Set up network rules to restrict access to the storage account.

az storage account network-rule add \
  --resource-group <resource-group-name> \
  --account-name <storage-account-name> \
  --vnet <vnet-name> \
  --subnet <subnet-name>

Example 7: Testing Private Endpoint Connectivity

Check the connectivity of your private endpoint using a virtual machine in the same virtual network.

nslookup <storage-account-name>.privatelink.blob.core.windows.net

Example 8: Revoking Access to a CMK

Revoke access to a customer-managed key in Azure Key Vault.

Explanation

This action can make data encrypted with this key inaccessible, ensuring compliance with security policies.

Real-World Scenarios

Scenario 1: Compliance with Data Regulations

An organization needs to meet GDPR compliance by encrypting user data stored in Azure. By using CMK and AAD authentication, they can maintain strict control over access and key management.

Scenario 2: Secure Development Environment

A development team uses Azure Storage for temporary file storage. By utilizing private endpoints, they ensure that test data remains isolated from external threats.

Scenario 3: Hybrid Cloud Integration

A company with an on-premises Active Directory wants to use Azure for file sharing. By enabling AAD authentication and configuring private endpoints, they create a secure, integrated environment.

Best Practices

  1. Use CMK for Enhanced Control: Always consider using CMK for sensitive data to maintain control over encryption keys.
  2. Regularly Rotate Keys: Implement a key rotation policy to minimize risks associated with key exposure.
  3. Enable AAD for Authentication: Prefer Azure AD authentication over account keys for better security.
  4. Implement Private Endpoints: Use private endpoints to isolate storage accounts from public access.
  5. Monitor Access Revocation: Regularly audit and revoke access to keys and accounts as necessary to maintain security.

Common Errors

  1. Error Message: "The specified key does not exist."

    • Cause: The key was deleted or not correctly referenced.
    • Fix: Ensure the key exists in the specified Key Vault.
  2. Error Message: "Access denied."

    • Cause: Insufficient permissions to access the storage account or Key Vault.
    • Fix: Verify that the AAD user has the appropriate role assigned.
  3. Error Message: "Private endpoint connection failed."

    • Cause: The endpoint is incorrectly configured or the subnet does not allow the connection.
    • Fix: Check the configuration of the private endpoint and the associated subnet settings.
  4. Error Message: "Key vault access policy doesn't allow this operation."

    • Cause: The managed identity lacks permissions in the Key Vault.
    • Fix: Update the access policy to include necessary permissions (e.g., wrapKey, unwrapKey).

Related Services/Commands

Feature/Service Description Command
Azure Key Vault Manage encryption keys and secrets securely. az keyvault create
Storage Account Main service for storing data in Azure. az storage account create
Private Link Establish a private connection to services. az network private-link
RBAC Manage access control over Azure resources. az role assignment create
Azure Monitor Monitor usage and access to storage resources. az monitor

Automation Script

# Automate the creation of a storage account with CMK and AAD Auth
$resourceGroup = "<resource-group-name>"
$location = "<location>"
$storageAccountName = "<storage-account-name>"
$keyVaultName = "<key-vault-name>"
$keyName = "<key-name>"

# Create Storage Account
az storage account create `
    --name $storageAccountName `
    --resource-group $resourceGroup `
    --location $location `
    --sku Standard_LRS `
    --encryption-key-source Microsoft.Keyvault `
    --encryption-key-vault $keyVaultName `
    --encryption-key-name $keyName

# Enable AAD Authentication
az storage account update `
    --name $storageAccountName `
    --resource-group $resourceGroup `
    --enable-azure-active-directory-authentication true

# Output
Write-Output "Storage account created with CMK and AAD authentication enabled."

Conclusion

In this tutorial, we covered how to encrypt and isolate Azure Storage using Customer-Managed Keys, Azure AD Authentication, and Private Endpoints. These features are essential for enhancing the security of your Azure environment, particularly in scenarios requiring strict compliance and data protection.

Next Steps

  • Explore the Azure documentation for further details on Customer-Managed Keys.
  • Practice configuring these features in a lab environment to solidify your understanding.
  • Consider completing additional training modules on Azure security to enhance your expertise.

References