← All cheatsheets

Security

Cloud IAM — roles, policies, and access-denied across AWS, GCP, Azure

Side-by-side model of identities, policies, and workload identity across AWS, GCP, and Azure, plus a repeatable way to debug any AccessDenied: find the principal, find the missing permission, grant least-privilege, verify.

Docs-checkediamrbacleast-privilegepoliciesaccess-denied

Quick reference — reach for these first

Who am I (AWS)aws sts get-caller-identityPrints the Account, UserId, and Arn of the caller — shows the real principal (an IAM user, or assumed-role/SESSION_NAME) behind your current credentials.
Who am I (GCP)gcloud auth listShows the active account (user or service account). Pair with 'gcloud config list' to confirm the active PROJECT_ID that bindings are evaluated against.
Who am I (Azure)az account showShows the signed-in Entra ID identity and the active SUBSCRIPTION_ID — the default RBAC scope for subsequent commands.
Test a permissiongcloud projects test-iam-permissions PROJECT_ID --permissions=PERMISSION # AWS: aws iam simulate-principal-policyAnswers 'can this principal do X?' without performing X. Use before granting to confirm exactly which permission is missing.
Grant least-privilegegcloud projects add-iam-policy-binding PROJECT_ID --member=MEMBER --role=ROLE # az role assignment create / aws iam attach-role-policyBind the narrowest role/policy that covers the one missing permission to the exact principal, at the smallest scope. Changes production access.

How an API request is authorized: principal -> policy evaluation -> allow or deny

API request authorization flowPrincipal is authenticated, then policy evaluation applies explicit-deny-wins, then explicit-allow, else implicit deny; deny paths end Denied, allow path ends Allowed.PrincipalIAM user/role ·member/SA · Entra IDAuthenticate(who is calling)Policy evaluation1 · Explicit DENY?SCP · boundary · deny policy2 · Matching ALLOW?identity / resource policy3 · Defaultimplicit DENYALLOWDENYallowdeny wins

Text equivalent: A left-to-right flow. A Principal (IAM user/role, GCP member/service account, or Entra ID identity) is authenticated, then its request enters policy evaluation. Evaluation runs in order: if any explicit deny matches (SCP, permission boundary, IAM deny policy, or Azure deny assignment) the result is DENY and wins over everything. Otherwise, if a matching allow exists, the result is ALLOW. If neither matches, the default is an implicit DENY. Both deny paths lead to a Denied outcome; the allow path leads to an Allowed outcome.

Common tasks

Concept · AWS / GCP / Azure · How to debug access

ConceptAWS / GCP / AzureHow to debug access
Identify the AWS principal behind current credentialsaws sts get-caller-identityArn is the identity you expect (watch for assumed-role/ROLE/SESSION, not an IAM user).
Identify the active GCP account and projectgcloud auth list && gcloud config listThe active (*) account and the project are the ones you intend to authorize against.
Identify the Azure identity and subscriptionaz account show --query '{user:user.name, sub:id}' -o jsonuser.name and subscription id match the intended principal and scope.
List managed policies attached to an AWS roleaws iam list-attached-role-policies --role-name ROLE_NAMEThe policy you expect to grant the action appears in AttachedPolicies.
Simulate an AWS action against a principalaws iam simulate-principal-policy --policy-source-arn PRINCIPAL_ARN --action-names s3:GetObject --resource-arns RESOURCE_ARNEvalDecision is 'allowed'; if 'explicitDeny' or 'implicitDeny', note MatchedStatements.
Test whether the caller has specific GCP permissionsgcloud projects test-iam-permissions PROJECT_ID --permissions=storage.objects.getThe queried permission appears in the returned 'permissions' list (absent = not granted).
Read the IAM policy (bindings) on a GCP projectgcloud projects get-iam-policy PROJECT_ID --format=jsonA binding ties MEMBER to the role that contains the needed permission.
List Azure role assignments for a principalaz role assignment list --assignee PRINCIPAL_ID --all -o tableAn assignment grants a role whose actions cover the request at the right scope.
[CHANGES PROD] Attach a least-privilege AWS policy to a roleaws iam attach-role-policy --role-name ROLE_NAME --policy-arn POLICY_ARNRe-run simulate-principal-policy and confirm EvalDecision is 'allowed'.
[CHANGES PROD] Add a GCP IAM role binding (predefined, not basic)gcloud projects add-iam-policy-binding PROJECT_ID --member=MEMBER --role=roles/storage.objectViewer --condition=Nonetest-iam-permissions now returns the permission; prefer a predefined role over roles/editor|owner.
[CHANGES PROD] Create an Azure RBAC assignment at the narrowest scopeaz role assignment create --assignee PRINCIPAL_ID --role 'ROLE_NAME' --scope RESOURCE_IDaz role assignment list shows it; scope is the resource/RG, not the whole subscription, unless required.
Check for an overriding guardrail (SCP / permission boundary / Org policy)aws iam get-role --role-name ROLE_NAME --query 'Role.PermissionsBoundary' # GCP: gcloud org-policies list --project=PROJECT_IDNo boundary/SCP/deny-policy explicitly blocks the action you are granting.

Debug an S3 AccessDenied from least-privilege back to a passing call

AWS

1
Read the error and capture the exact action and resource
2
Identify the real principal making the call
aws sts get-caller-identity
# Arn: arn:aws:sts::1234:assumed-role/app-reader/i-0abc  (a role, not your user)
3
Confirm the permission is actually missing for that principal
aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::1234:role/app-reader --action-names s3:GetObject --resource-arns arn:aws:s3:::reports-prod/2026/q3.csv
# EvalDecision: implicitDeny  (no matching allow, and no explicit deny)
4
Rule out a guardrail override before granting
aws iam get-role --role-name app-reader --query 'Role.PermissionsBoundary'
# null  (no permission boundary is capping the role)
5
Grant the narrowest allow — a scoped inline policy for just this prefix (changes prod)
aws iam put-role-policy --role-name app-reader --policy-name read-reports-q3 --policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"s3:GetObject","Resource":"arn:aws:s3:::reports-prod/2026/*"}]}'
# (no output on success)
6
Verify the decision flipped, then confirm with the real call
aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::1234:role/app-reader --action-names s3:GetObject --resource-arns arn:aws:s3:::reports-prod/2026/q3.csv
# EvalDecision: allowed  -> then: aws s3 cp s3://reports-prod/2026/q3.csv - succeeds

Troubleshooting — symptom → first check → next check

SymptomFirst checkEstablishesNext check
AccessDenied even though a policy clearly grants the actionLook for an explicit deny higher up: an AWS SCP or permission boundary, a GCP IAM deny policy or Org Policy constraint, or an Azure deny assignment.Whether an allow is being overridden — in all three clouds an explicit deny beats any allow, and access is deny-by-default without a matching allow.Remove/adjust the deny or request an exception at the org level; do not pile on more allows — they cannot override an explicit deny.
Policy added to your IAM user but calls still failRun sts get-caller-identity / gcloud auth list / az account show — confirm the request runs as that principal, not an assumed role, service account, or managed identity.That you edited the identity actually making the request (assumed roles and workload identities carry their own permissions, not the human's).Attach the policy/binding to the role or service account that the workload assumes, then retry.
Permission boundary, SCP, or Org Policy blocks the grantInspect the boundary/guardrail: get-role PermissionsBoundary, aws organizations list-policies, or gcloud org-policies describe CONSTRAINT.That the ceiling on effective permissions is lower than the role grants — the intersection, not the union, is what applies.Widen the boundary or get the org/SCP exception; granting at the account level alone will not help while the guardrail denies it.
Access works in one account/project but not cross-account/cross-projectConfirm both sides: a resource policy / trust policy that allows the external principal, and an identity policy on the caller permitting the action.That cross-boundary access needs allows on BOTH the resource side and the identity side (plus, in GCP, the resource's own project bindings).Add the trust/resource-based allow for the external principal and verify the caller's identity policy, then re-test.
Intermittent 401/ExpiredToken on previously working callsCheck credential freshness: STS session expiry, 'gcloud auth print-access-token' age, or 'az account get-access-token' expiresOn.That the failure is stale short-lived credentials, not a policy change.Refresh the session (re-assume the role, gcloud auth login / application-default login, az login) and retry.
Granted the role but access only works after a delayRe-test the exact action after a short wait; IAM changes are eventually consistent across all three providers.That the binding/assignment is correct and the lag is propagation, not a missing permission.Wait and retry (seconds to a couple of minutes); if it never resolves, re-inspect for an overriding deny.