Skip to content

Cheatsheet · Cloud

Read-only Azure and Entra ID review with the Azure CLI

Read-only Azure and Entra ID review with the Azure CLI: subscriptions, RBAC roles, identities, key vaults, storage and network security groups.

By Steven Carrier Published

Official website: Azure CLI

This cheatsheet collects Azure CLI read commands for reviewing an Entra ID tenant and its Azure subscriptions: who holds which permissions, which identities exist and which resources are exposed. Every command lists configuration metadata, without reading any secret or changing any resource. They assume access provided by the client, ideally the Reader and Security Reader roles on the subscriptions and a directory read role (Global Reader or Directory Readers), within a scope agreed in the penetration test scoping checklist. Example names (alice, rg-example, target.example) are fictitious. For the same approach on AWS, see the AWS IAM audit cheatsheet.

Sign in and set the scope

# Interactive sign-in (browser or device code)
az login
az login --use-device-code

# Signed-in account, tenant and current subscription
az account show

# Subscriptions this account can access
az account list --output table

# Set the subscription under review
az account set --subscription "00000000-0000-0000-0000-000000000000"

Check the tenant and subscription identifiers before any other command: they must match the agreement. A guest (B2B) account often sees several tenants. Remember az logout at the end of a session on a shared workstation.

Role assignments (RBAC)

# All assignments in the current subscription, inheritance included
az role assignment list --all --include-inherited --output table

# Useful columns in a readable table
az role assignment list --all \
  --query "[].{principal:principalName, type:principalType, role:roleDefinitionName, scope:scope}" \
  --output table

# Assignments for a specific identity
az role assignment list --assignee alice@target.example --all --output table

# Broad assignments: Owner and Contributor
az role assignment list --all \
  --query "[?roleDefinitionName=='Owner' || roleDefinitionName=='Contributor'].{principal:principalName, role:roleDefinitionName, scope:scope}" \
  --output table

Look for Owner and Contributor at subscription or management-group scope, assignments made to users rather than groups, guest accounts with elevated roles, and deleted principals (empty principalName: orphaned assignment).

Custom roles

# Custom roles in the subscription
az role definition list --custom-role-only true --output table

# Actions of a custom role
az role definition list --name "CustomRoleName" \
  --query "[].{actions:permissions[0].actions, dataActions:permissions[0].dataActions, scopes:assignableScopes}"

Look for "*" in actions, write permissions on Microsoft.Authorization/* (which allows self-assigning roles) and overly broad assignable scopes.

Entra ID: users, groups, service principals

# Users (name, type, account state)
az ad user list --query "[].{name:displayName, upn:userPrincipalName, enabled:accountEnabled}" --output table

# Guest accounts
az ad user list --filter "userType eq 'Guest'" --query "[].userPrincipalName" --output tsv

# Groups and a group's members
az ad group list --query "[].displayName" --output tsv
az ad group member list --group "Administrators" --query "[].userPrincipalName" --output tsv

# Service principals and application registrations in the tenant
az ad sp list --all --query "[].{name:displayName, appId:appId, type:servicePrincipalType}" --output table
az ad app list --all --query "[].{name:displayName, appId:appId}" --output table

On a large tenant --all is slow: prefer --display-name or --filter when targeting one object. An app registration’s permissions and credentials (expiry dates) can be viewed with az ad app show and az ad app credential list --id <appId>: the latter returns metadata only (key identifier, dates), not values.

Key vaults: access metadata only

# Vaults in the subscription
az keyvault list --query "[].{name:name, group:resourceGroup}" --output table

# Authorisation model, access policies and network rules of a vault
az keyvault show --name kv-example \
  --query "{rbac:properties.enableRbacAuthorization, purge:properties.enablePurgeProtection, softDelete:properties.enableSoftDelete, network:properties.networkAcls.defaultAction, policies:properties.accessPolicies}"

Do not list or read secrets: az keyvault secret show returns the value. The review covers configuration: RBAC model or access policies, get and list rights granted widely, purge protection enabled, network access open to the whole internet. Calls are logged by the vault: warn the client.

Storage accounts: public access and encryption in transit

az storage account list \
  --query "[].{name:name, publicBlob:allowBlobPublicAccess, https:enableHttpsTrafficOnly, tlsMin:minimumTlsVersion, network:networkRuleSet.defaultAction, sharedKey:allowSharedKeyAccess}" \
  --output table

Points to watch: publicBlob set to true (containers may be public), default network rule set to Allow, minimum TLS version below TLS1_2, shared-key access enabled. Establishing whether a container is actually public means checking its access level: do so only on in-scope accounts, without reading or downloading any content.

Network security groups

# Network security groups in the subscription
az network nsg list --query "[].{name:name, group:resourceGroup}" --output table

# Rules of one group: allowed inbound traffic
az network nsg rule list --nsg-name nsg-example --resource-group rg-example \
  --query "[?direction=='Inbound' && access=='Allow'].{rule:name, source:sourceAddressPrefix, port:destinationPortRange, proto:protocol, priority:priority}" \
  --output table

A source of *, Internet or 0.0.0.0/0 combined with administration ports (22, 3389) or database ports is a priority finding. Note that rules can also use port and prefix lists (destinationPortRanges, sourceAddressPrefixes) that this projection does not show.

Going further: Microsoft Graph, Prowler, ScoutSuite

The az ad commands rely on Microsoft Graph. For what they do not cover (directory roles, conditional access), query Graph read-only:

# Directory roles activated in the tenant (needs directory read permission)
az rest --method get --url "https://graph.microsoft.com/v1.0/directoryRoles"

For a broader configuration audit, tools automate hundreds of checks:

# Prowler: Azure audit using the Azure CLI session
prowler azure --az-cli-auth

ScoutSuite (scout azure --cli) plays a comparable role. Options change between versions: see each tool’s help and documentation. Every automated finding still needs manual verification before it goes into the report.

Engagement precautions

  • Use a dedicated read-only account with multi-factor authentication, and sign out at the end of the session.
  • Calls are logged in the Azure activity log and in Entra ID audit logs: warn the client’s security team.
  • Stay within the in-scope subscriptions and tenants; a guest account may see others.
  • Read no secret value, key or storage content: reference resources by identifier.

Sources

Related resources

  • AI prompt · Infrastructure and AD pentesting · OSINT · Cloud

    Attack surface prompt

    Prompt that analyses an asset inventory from the authorised scope (domains, IPs, services, cloud) to prioritise testing: exposure, criticality, checks.

    Published

  • Cheatsheet · Cloud

    AWS IAM audit (CLI)

    Read-only AWS IAM review with the AWS CLI: identity, users, roles, policies, access key age, MFA, credential report and Prowler pointers.

    Published

  • AI prompt · Cloud

    Cloud test plan prompt

    Prompt that builds a cloud security assessment plan (AWS, Azure, GCP): identity, network, data, logging and workloads, read-only first.

    Published

BEAROPS

Need a penetration test?

BEAROPS experts test your applications, infrastructure and cloud, black box or grey box, following OWASP, NIST and ANSSI guidance.