Bird
Raised Fist0
Azurecloud~5 mins

Managed identities concept in Azure - Commands & Configuration

Choose your learning style10 modes available
Introduction
Sometimes cloud apps need to access other cloud services securely without using passwords. Managed identities let apps get special IDs automatically to prove who they are, so they can access resources safely without you managing secrets.
When you want an Azure virtual machine to access a storage account without storing keys.
When a web app needs to read from a database securely without embedding credentials.
When automating scripts that call Azure services and you want to avoid manual secret management.
When you want to improve security by removing passwords from your code or configuration.
When you want Azure services to authenticate to each other easily and safely.
Commands
This command enables a managed identity for the virtual machine named example-vm in the example-rg resource group. It creates an identity that the VM can use to access other Azure services securely.
Terminal
az vm identity assign --resource-group example-rg --name example-vm
Expected OutputExpected
{ "principalId": "12345678-1234-1234-1234-123456789abc", "tenantId": "87654321-4321-4321-4321-cba987654321", "type": "SystemAssigned" }
→
--resource-group - Specifies the resource group where the VM exists
→
--name - Specifies the name of the VM to assign the identity
This command gives the VM's managed identity permission to read from the examplestorage storage account by assigning the Reader role at the storage account scope.
Terminal
az role assignment create --assignee 12345678-1234-1234-1234-123456789abc --role Reader --scope /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorage
Expected OutputExpected
{ "canDelegate": null, "id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleAssignments/abcdef12-3456-7890-abcd-ef1234567890", "name": "abcdef12-3456-7890-abcd-ef1234567890", "principalId": "12345678-1234-1234-1234-123456789abc", "roleDefinitionId": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7", "scope": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorage", "type": "Microsoft.Authorization/roleAssignments" }
→
--assignee - Specifies the managed identity's principal ID to assign the role
→
--role - Specifies the permission level to grant
→
--scope - Limits the permission to a specific resource
This command checks the managed identity details of the VM to confirm it is enabled and view its IDs.
Terminal
az vm show --resource-group example-rg --name example-vm --query identity
Expected OutputExpected
{ "principalId": "12345678-1234-1234-1234-123456789abc", "tenantId": "87654321-4321-4321-4321-cba987654321", "type": "SystemAssigned" }
→
--resource-group - Specifies the VM's resource group
→
--name - Specifies the VM name
→
--query - Filters output to show only identity information
Key Concept

If you remember nothing else from this pattern, remember: managed identities let Azure resources prove who they are securely without you handling passwords.

Common Mistakes
Trying to use managed identity without assigning a role to it.
The identity exists but has no permissions, so access to resources is denied.
Always assign the needed role to the managed identity for the target resource.
Using the VM name instead of the principal ID when assigning roles.
Role assignments require the identity's principal ID, not the VM name.
Retrieve the principal ID from the VM's identity details and use it in role assignments.
Not enabling managed identity on the resource before trying to use it.
Without enabling, the resource has no identity and cannot authenticate.
Run the command to assign a managed identity before using it.
Summary
Enable a managed identity on an Azure resource like a virtual machine.
Assign proper roles to the managed identity to grant access to other Azure services.
Verify the managed identity is enabled and has the correct permissions.

Practice

(1/5)
1. What is the main purpose of managed identities in Azure?
easy
A. Allow resources to access other services securely without passwords
B. Store user passwords for Azure services
C. Create virtual machines automatically
D. Manage network traffic between resources

Solution

  1. Step 1: Understand managed identities purpose

    Managed identities provide a way for Azure resources to authenticate to other services without needing passwords.
  2. Step 2: Compare options

    Only Allow resources to access other services securely without passwords correctly describes this purpose. The other options describe unrelated functions.
  3. Final Answer:

    Allow resources to access other services securely without passwords -> Option A
  4. Quick Check:

    Managed identities = secure access without passwords [OK]
Hint: Managed identities remove password use for resource access [OK]
Common Mistakes:
  • Thinking managed identities store passwords
  • Confusing managed identities with VM creation
  • Assuming managed identities manage network traffic
2. Which syntax correctly enables a system-assigned managed identity in an Azure resource configuration?
easy
A. "managedIdentity": "system"
B. "identity": { "enabled": true }
C. "identity": { "type": "SystemAssigned" }
D. "identity": "system-assigned"

Solution

  1. Step 1: Recall correct identity block syntax

    Azure resource config uses an "identity" block with a "type" property set to "SystemAssigned" to enable system-assigned managed identity.
  2. Step 2: Validate options

    "identity": { "type": "SystemAssigned" } matches the correct JSON syntax. The other options do not follow Azure's expected configuration format.
  3. Final Answer:

    "identity": { "type": "SystemAssigned" } -> Option C
  4. Quick Check:

    Correct identity block syntax = "identity": { "type": "SystemAssigned" } [OK]
Hint: Use "identity": { "type": "SystemAssigned" } to enable system identity [OK]
Common Mistakes:
  • Using incorrect property names like "enabled"
  • Omitting the "type" key
  • Using wrong string values like "system" or "system-assigned"
3. Given this Azure resource configuration snippet:
{
  "identity": { "type": "UserAssigned", "userAssignedIdentities": { "/subscriptions/123/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/identity1": {} } }
}

What does this configuration do?
medium
A. Enables a system-assigned managed identity for the resource
B. Assigns a user-assigned managed identity named 'identity1' to the resource
C. Disables all managed identities for the resource
D. Creates a new user-assigned identity named 'identity1'

Solution

  1. Step 1: Analyze the identity type

    The "type" is "UserAssigned", meaning the resource uses an existing user-assigned identity.
  2. Step 2: Check the userAssignedIdentities property

    The resource assigns the existing identity at the given resource ID path, named 'identity1'. It does not create a new identity.
  3. Final Answer:

    Assigns a user-assigned managed identity named 'identity1' to the resource -> Option B
  4. Quick Check:

    UserAssigned with identity path = Assigns a user-assigned managed identity named 'identity1' to the resource [OK]
Hint: UserAssigned type with identity path means assign existing identity [OK]
Common Mistakes:
  • Confusing system-assigned with user-assigned identity
  • Thinking the identity is created, not assigned
  • Ignoring the userAssignedIdentities property
4. You wrote this Azure resource config to enable a system-assigned managed identity:
{
  "identity": { "type": "systemassigned" }
}

Why does this configuration fail to enable the identity?
medium
A. The resource group name is missing
B. The identity block is missing the "enabled" property
C. User-assigned identities require a different syntax
D. The type value is case-sensitive and must be "SystemAssigned"

Solution

  1. Step 1: Check the type value case

    Azure expects "SystemAssigned" with capital S and A. "systemassigned" is invalid due to case sensitivity.
  2. Step 2: Validate other options

    Stating that the identity block is missing the "enabled" property is incorrect because "enabled" is not required. User-assigned identities require a different syntax, but this config is for system-assigned. The resource group name is unrelated to this error.
  3. Final Answer:

    The type value is case-sensitive and must be "SystemAssigned" -> Option D
  4. Quick Check:

    Case-sensitive type value = The type value is case-sensitive and must be "SystemAssigned" [OK]
Hint: Check capitalization of "SystemAssigned" exactly [OK]
Common Mistakes:
  • Ignoring case sensitivity in type value
  • Adding unnecessary properties like "enabled"
  • Confusing system-assigned with user-assigned syntax
5. You want two Azure virtual machines to share the same managed identity to access a database securely. Which approach should you use?
hard
A. Create a user-assigned managed identity and assign it to both VMs
B. Assign a system-assigned managed identity to each VM separately
C. Use a shared password stored in Azure Key Vault
D. Enable managed identity only on one VM and share its credentials manually

Solution

  1. Step 1: Understand identity sharing options

    System-assigned identities are unique per resource and cannot be shared.
  2. Step 2: Identify user-assigned identity use

    User-assigned managed identities can be created once and assigned to multiple resources, allowing sharing.
  3. Step 3: Evaluate other options

    Using shared passwords or manual credential sharing is insecure and against best practices.
  4. Final Answer:

    Create a user-assigned managed identity and assign it to both VMs -> Option A
  5. Quick Check:

    User-assigned identity allows sharing = Create a user-assigned managed identity and assign it to both VMs [OK]
Hint: Use user-assigned identity to share across multiple resources [OK]
Common Mistakes:
  • Trying to share system-assigned identities
  • Using passwords instead of managed identities
  • Manually sharing credentials insecurely
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard