|
1 | 1 | --- |
2 | 2 | title: "Managed Identity" |
3 | | -description: API coverage for Microsoft.ManagedIdentity in LocalStack for Azure. |
| 3 | +description: Get started with Azure Managed Identity on LocalStack |
4 | 4 | template: doc |
5 | 5 | --- |
6 | 6 |
|
7 | 7 | import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage"; |
8 | 8 |
|
| 9 | +## Introduction |
| 10 | + |
| 11 | +Azure Managed Identity provides identities for Azure resources so applications can authenticate without storing credentials in code. The Azure platform supports two types of identities: |
| 12 | + |
| 13 | +- **System-assigned**: Tied directly to the lifecycle of a specific resource; when the resource is deleted, Azure automatically cleans up the identity. |
| 14 | +- **User-assigned**: Created as a standalone Azure resource that can be assigned to one or more instances, making it ideal for shared workloads and scale sets. |
| 15 | + |
| 16 | +Managed identities are commonly used to access Azure services securely from apps and automation workflows. For more information, see [What are managed identities for Azure resources?](https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview). |
| 17 | + |
| 18 | +LocalStack for Azure allows you to build and emulate applications that make use of system-assigned or user-assigned Managed Identities directly in your local environment. This enables you to validate your secret-less authentication logic with high fidelity, ensuring your code is production-ready without needing to provision live cloud resources. |
| 19 | +The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Managed Identity's integration with LocalStack. |
| 20 | + |
| 21 | +## Getting started |
| 22 | + |
| 23 | +This guide is designed for users new to Managed Identity and assumes basic knowledge of the Azure CLI and our `azlocal` wrapper script. |
| 24 | + |
| 25 | +Launch LocalStack using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/). Once the container is running, enable Azure CLI interception by running: |
| 26 | + |
| 27 | + |
| 28 | +### Create a resource group |
| 29 | + |
| 30 | +Create a resource group for the identity resources: |
| 31 | + |
| 32 | +```bash |
| 33 | +az group create \ |
| 34 | + --name rg-managedidentity-demo \ |
| 35 | + --location westeurope |
| 36 | +``` |
| 37 | + |
| 38 | +```bash title="Output" |
| 39 | +{ |
| 40 | + "name": "rg-managedidentity-demo", |
| 41 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-managedidentity-demo", |
| 42 | + "location": "westeurope", |
| 43 | + "properties": { |
| 44 | + "provisioningState": "Succeeded" |
| 45 | + }, |
| 46 | + ... |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +### User-assigned managed identity |
| 51 | + |
| 52 | +Create a user-assigned managed identity: |
| 53 | + |
| 54 | +```bash |
| 55 | +az identity create \ |
| 56 | + --name mi-doc77 \ |
| 57 | + --resource-group rg-managedidentity-demo \ |
| 58 | + --location westeurope \ |
| 59 | + --tags environment=test |
| 60 | +``` |
| 61 | + |
| 62 | +```bash title="Output" |
| 63 | +{ |
| 64 | + "name": "mi-doc77", |
| 65 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-managedidentity-demo/providers/Microsoft.ManagedIdentity/userAssignedIdentities/mi-doc77", |
| 66 | + "location": "westeurope", |
| 67 | + "principalId": "a55f8986-0187-48fd-ac82-e87db6b80376", |
| 68 | + "clientId": "216de8da-baf0-4403-925d-ac69c6ad67e3", |
| 69 | + "tenantId": "00000000-0000-0000-0000-000000000000", |
| 70 | + "tags": { |
| 71 | + "environment": "test" |
| 72 | + }, |
| 73 | + ... |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +Get the new user-assigned managed identity: |
| 78 | + |
| 79 | +```bash |
| 80 | +az identity show \ |
| 81 | + --name mi-doc77 \ |
| 82 | + --resource-group rg-managedidentity-demo |
| 83 | +``` |
| 84 | + |
| 85 | +```bash title="Output" |
| 86 | +{ |
| 87 | + "name": "mi-doc77", |
| 88 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-managedidentity-demo/providers/Microsoft.ManagedIdentity/userAssignedIdentities/mi-doc77", |
| 89 | + "principalId": "a55f8986-0187-48fd-ac82-e87db6b80376", |
| 90 | + "clientId": "216de8da-baf0-4403-925d-ac69c6ad67e3", |
| 91 | + "tags": { |
| 92 | + "environment": "test" |
| 93 | + }, |
| 94 | + ... |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +List user-assigned managed identities by resource group: |
| 99 | + |
| 100 | +```bash |
| 101 | +az identity list --resource-group rg-managedidentity-demo |
| 102 | +``` |
| 103 | + |
| 104 | +```bash title="Output" |
| 105 | +[ |
| 106 | + { |
| 107 | + "name": "mi-doc77", |
| 108 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-managedidentity-demo/providers/Microsoft.ManagedIdentity/userAssignedIdentities/mi-doc77", |
| 109 | + "resourceGroup": "rg-managedidentity-demo", |
| 110 | + "tags": {"environment": "test"}, |
| 111 | + ... |
| 112 | + } |
| 113 | +] |
| 114 | +``` |
| 115 | + |
| 116 | +List identities by subscription: |
| 117 | + |
| 118 | +```bash |
| 119 | +az identity list |
| 120 | +``` |
| 121 | + |
| 122 | +```bash title="Output" |
| 123 | +[ |
| 124 | + { |
| 125 | + "name": "mi-doc77", |
| 126 | + "type": "Microsoft.ManagedIdentity/userAssignedIdentities", |
| 127 | + "resourceGroup": "rg-managedidentity-demo", |
| 128 | + ... |
| 129 | + } |
| 130 | +] |
| 131 | +``` |
| 132 | + |
| 133 | +Update identity tags: |
| 134 | + |
| 135 | +```bash |
| 136 | +az identity update \ |
| 137 | + --name mi-doc77 \ |
| 138 | + --resource-group rg-managedidentity-demo \ |
| 139 | + --tags environment=dev |
| 140 | +``` |
| 141 | + |
| 142 | +```bash title="Output" |
| 143 | +{ |
| 144 | + "name": "mi-doc77", |
| 145 | + "tags": { |
| 146 | + "environment": "dev" |
| 147 | + }, |
| 148 | + ... |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +Delete the identity and verify it no longer appears in the resource group: |
| 153 | + |
| 154 | +```bash |
| 155 | +az identity delete --name mi-doc77 --resource-group rg-managedidentity-demo |
| 156 | +az identity list --resource-group rg-managedidentity-demo |
| 157 | +``` |
| 158 | + |
| 159 | +```bash title="Output" |
| 160 | +[] |
| 161 | +``` |
| 162 | + |
| 163 | +### System-assigned managed identity |
| 164 | + |
| 165 | +Create an app service plan and a web app: |
| 166 | + |
| 167 | +```bash |
| 168 | +az appservice plan create \ |
| 169 | + --name asp-doc77 \ |
| 170 | + --resource-group rg-managedidentity-demo \ |
| 171 | + --location westeurope \ |
| 172 | + --sku F1 |
| 173 | + |
| 174 | +az webapp create \ |
| 175 | + --name ls-app-doc77 \ |
| 176 | + --resource-group rg-managedidentity-demo \ |
| 177 | + --plan asp-doc77 \ |
| 178 | + --runtime "PYTHON:3.11" |
| 179 | +``` |
| 180 | + |
| 181 | +```bash title="Output" |
| 182 | +{ |
| 183 | + "name": "asp-doc77", |
| 184 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-managedidentity-demo/providers/Microsoft.Web/serverfarms/asp-doc77", |
| 185 | + "location": "westeurope", |
| 186 | + "provisioningState": "Succeeded", |
| 187 | + ... |
| 188 | +} |
| 189 | +{ |
| 190 | + "name": "ls-app-doc77", |
| 191 | + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-managedidentity-demo/providers/Microsoft.Web/sites/ls-app-doc77", |
| 192 | + "type": "Microsoft.Web/sites", |
| 193 | + "location": "westeurope", |
| 194 | + ... |
| 195 | +} |
| 196 | +``` |
| 197 | + |
| 198 | +Enable the system-assigned managed identity on the web app |
| 199 | + |
| 200 | +```bash |
| 201 | +az webapp identity assign \ |
| 202 | + --name ls-app-doc77 \ |
| 203 | + --resource-group rg-managedidentity-demo |
| 204 | +``` |
| 205 | + |
| 206 | +```bash title="Output" |
| 207 | +{ |
| 208 | + "type": "SystemAssigned", |
| 209 | + "principalId": "78b44418-f917-4f3a-ac29-a9821d3d8e7c", |
| 210 | + "tenantId": "00000000-0000-0000-0000-000000000000", |
| 211 | + ... |
| 212 | +} |
| 213 | +``` |
| 214 | + |
| 215 | +Retrieve the system-assigned managed identity by scope: |
| 216 | + |
| 217 | + |
9 | 218 | ## API Coverage |
10 | 219 |
|
11 | 220 | <AzureFeatureCoverage service="Microsoft.ManagedIdentity" client:load /> |
0 commit comments