You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/azure/sdk/authentication/user-assigned-managed-identity.md
+24-12Lines changed: 24 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ User-assigned identities are created as standalone resources in your Azure subsc
41
41
42
42
Azure CLI commands can be run in the [Azure Cloud Shell](https://shell.azure.com) or on a workstation with the [Azure CLI installed](/cli/azure/install-azure-cli).
43
43
44
-
Use the Azure CLI command `az identity create` to create a managed identity for an Azure resource:
44
+
Use the Azure CLI command [`az identity create`](/cli/azure/identity?view=azure-cli-latest#az-identity-create) to create a managed identity for an Azure resource:
45
45
46
46
```azurecli
47
47
az identity create --resource-group <resource-group-name> --name <identity-name>
@@ -59,7 +59,7 @@ The command output prints the following values:
59
59
60
60
## Assign the managed identity to your app
61
61
62
-
A user-assigned can be associated with one or more Azure resources. All of the resources that use that identity will gain the permissions applied through the identity's roles.
62
+
A user-assigned can be associated with one or more Azure resources. All of the resources that use that identity gain the permissions applied through the identity's roles.
63
63
64
64
### [Azure portal](#tab/azure-portal)
65
65
@@ -87,22 +87,31 @@ az identity show -n cli-identity -g aitesting -o json --query id
87
87
88
88
Once you have the resource ID, use the Azure CLI command `az <resourceType> identity assign` command to associate the user-assigned identity with different resources, such as the following:
89
89
90
-
For Azure App Service, use the Azure CLI command `azd webapp identity assign`:
90
+
For Azure App Service, use the Azure CLI command [`az webapp identity assign`](/cli/azure/webapp/identity?view=azure-cli-latest#az-webapp-identity-assign):
91
91
92
92
```azurecli
93
-
az webapp identity assign --resource-group <resource-group-name> --name <webapp-name> --identities <user-assigned-identity-resource-id>
93
+
az webapp identity assign \
94
+
--resource-group <resource-group-name> \
95
+
--name <webapp-name> \
96
+
--identities <user-assigned-identity-resource-id>
94
97
```
95
98
96
-
For Azure Container Apps, use the Azure CLI command `az containerapp identity assign`:
99
+
For Azure Container Apps, use the Azure CLI command [`az containerapp identity assign`](/cli/azure/containerapp/identity?view=azure-cli-latest#az-containerapp-identity-assign):
97
100
98
101
```azurecli
99
-
az webapp identity assign --resource-group <resource-group-name> --name <webapp-name> --identities <user-assigned-identity-resource-id>
102
+
az webapp identity assign \
103
+
--resource-group <resource-group-name> \
104
+
--name <webapp-name> \
105
+
--identities <user-assigned-identity-resource-id>
100
106
```
101
107
102
-
For Azure Container Apps, use the Azure CLI command `az containerapp identity assign`:
108
+
For Azure Container Apps, use the Azure CLI command [`az vm identity assign`](/cli/azure/vm/identity?view=azure-cli-latest#az-vm-identity-assign):
103
109
104
110
```azurecli
105
-
az vm identity assign --resource-group <resource-group-name> --name <webapp-name> --identities <user-assigned-identity-resource-id>
111
+
az vm identity assign \
112
+
--resource-group <resource-group-name> \
113
+
--name <webapp-name> \
114
+
--identities <user-assigned-identity-resource-id>
106
115
```
107
116
108
117
---
@@ -142,16 +151,19 @@ The following example shows how to assign roles at the resource group scope, sin
142
151
To assign a user-assigned identity to an Azure App Service web app using the Azure CLI, you'll need the principal ID of the identity. Use the `az identity show` command to retrieve the resource ID:
143
152
144
153
```dotnetcli
145
-
az identity show -n cli-identity -g aitesting -o json --query id
154
+
az identity show \
155
+
--resource-group <your-resource-group> \
156
+
--name <your-managed-identity-name> \
157
+
-o json --query principalId
146
158
```
147
159
148
160
Assign a role to a managed identity using the [az role assignment create](/cli/azure/role/assignment#az-role-assignment-create) command:
149
161
150
162
```azurecli
151
163
az role assignment create \
152
-
--assignee "{principalId}" \
153
-
--role "{roleName}" \
154
-
--scope "{scope}"
164
+
--assignee <your-principal-id> \
165
+
--role <role-name> \
166
+
--scope <scope>
155
167
```
156
168
157
169
To get the role names to which a service principal can be assigned, use the [az role definition list](/cli/azure/role/definition#az-role-definition-list) command:
0 commit comments