CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Cloud CLIs / aws iam

aws iam

Inspect users, roles and policies, and debug access

Intermediateawssecuritypermissions

aws iam manages who can do what in an AWS account: users, roles, groups, policies and access keys. Most of the time you use it read-only, to answer 'which policies does this role have?', 'what does this policy allow?' and 'why is this call denied?', plus key rotation and policy simulation.

Syntaxaws iam list-users|get-role|list-attached-role-policies|get-policy-version|simulate-principal-policy|list-access-keys|... [OPTIONS]

Watch it run

You've just been given access to an account and want to see your identity and the human and machine users in it.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
aws sts get-caller-identity

Always the first command: it needs no permissions and tells you the account and principal your credentials map to. AIDA... is a user ID; a role session would show AROA... and an assumed-role ARN.

Anatomy of a command

$
commandaws iam

IAM is global: no region, one endpoint (iam.amazonaws.com) for the whole account.

How it works

IAM stores principals (users, roles) and JSON policies, and every AWS API request is checked against them by the service you call. A request starts as an implicit deny. An explicit Deny in any applicable policy wins immediately. Within an AWS Organization, SCPs (and RCPs for resources) must allow the action. Then an Allow must come from an identity-based policy on the principal or, for services that support them, a resource-based policy such as a bucket policy. If the principal has a permissions boundary, or the session was created with a session policy, those must allow it too. Roles are assumed through STS (sts:AssumeRole), which checks the role's trust policy and returns temporary credentials. IAM changes are eventually consistent, so a new permission can take a few seconds to apply. Read-only commands like get-role and list-attached-role-policies show the inputs; simulate-principal-policy evaluates identity policies for you.

Every request starts denied; an explicit Deny anywhere wins, and an Allow must survive every policy layer that applies.

evaluatenoallowsyesallowsyesno AllowAPI requests3:PutObjectrole shop-api-taskExplicit Deny?any policySCP / RCPOrganizationsAllow found?identity/resourceBoundary+ session policyAllowedrequest runsDeniedAccessDenied
1/7
Every request starts as deny

The service gathers every policy that applies: the caller's identity policies, the resource's policy, SCPs and RCPs, boundaries and session policies. With nothing else, the answer is an implicit deny.

← → to step

Options you'll actually use

sts get-caller-identityWhich user or role am I right now?
list-users / list-rolesPrincipals in the account (use --query to trim)
list-attached-role-policiesManaged policies on a role (--role-name); list-role-policies for inline ones
get-policy-versionThe JSON document of a managed policy (--policy-arn, --version-id)
get-role --role-name RRole details, including its trust policy (who may assume it)
simulate-principal-policyTest whether actions would be allowed for a principal
*-access-key(s)list-, create-, update- and delete-access-key: rotate long-lived keys
attach-role-policyAttach a managed policy to a role (detach-role-policy removes it)
decode-authorization-messageaws sts ...: decode the encoded reason in a denial

Common mistakes

Attaching AdministratorAccess to 'fix' an AccessDenied

Turns a missing permission into full account control for that principal, and hides what the app actually needs.

Read the error's action and resource, and grant exactly that (e.g. s3:PutObject on arn:aws:s3:::bucket/invoices/*)
"Resource": "arn:aws:s3:::kunal-artifacts" for s3:GetObject

Object actions apply to object ARNs; the bucket ARN alone matches nothing for GetObject.

arn:aws:s3:::kunal-artifacts/* for objects, the bucket ARN for s3:ListBucket
Long-lived access keys for CI and servers

Keys leak through logs, repos and laptops and stay valid until someone notices.

Roles: instance profiles, ECS task roles, EKS Pod Identity, OIDC federation for CI
A trust policy with "Principal": {"AWS": "*"}

Any AWS account in the world can try to assume the role; only conditions stand in the way.

Name specific accounts, roles or services, and add sts:ExternalId or aws:SourceArn conditions

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Write an IAM policy as ~/app/s3-invoices-policy.json that allows only s3:PutObject and s3:GetObject on objects under the invoices/ prefix of bucket devops-artifacts, then validate it is proper JSON with jq.

  2. 2

    With jq, list the actions allowed by that file, one per line.

  3. 3

    Show who is allowed to assume the role shop-api-task.

  4. 4

    Test whether the role shop-api-task may call ec2:TerminateInstances, without terminating anything.

Related commands

aws configureSet up AWS CLI credentials, region and profilesaws s3Copy, sync and list files in Amazon S3aws eksConnect kubectl to EKS and manage cluster accesssudoRun a command as root or another user
Previousaws ec2Nextaws eks
Linux / Cloud CLIs / aws iam

aws iam

Inspect users, roles and policies, and debug access

Intermediateawssecuritypermissions

aws iam manages who can do what in an AWS account: users, roles, groups, policies and access keys. Most of the time you use it read-only, to answer 'which policies does this role have?', 'what does this policy allow?' and 'why is this call denied?', plus key rotation and policy simulation.

Syntaxaws iam list-users|get-role|list-attached-role-policies|get-policy-version|simulate-principal-policy|list-access-keys|... [OPTIONS]

Watch it run

You've just been given access to an account and want to see your identity and the human and machine users in it.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
aws sts get-caller-identity

Always the first command: it needs no permissions and tells you the account and principal your credentials map to. AIDA... is a user ID; a role session would show AROA... and an assumed-role ARN.

Anatomy of a command

$
commandaws iam

IAM is global: no region, one endpoint (iam.amazonaws.com) for the whole account.

How it works

IAM stores principals (users, roles) and JSON policies, and every AWS API request is checked against them by the service you call. A request starts as an implicit deny. An explicit Deny in any applicable policy wins immediately. Within an AWS Organization, SCPs (and RCPs for resources) must allow the action. Then an Allow must come from an identity-based policy on the principal or, for services that support them, a resource-based policy such as a bucket policy. If the principal has a permissions boundary, or the session was created with a session policy, those must allow it too. Roles are assumed through STS (sts:AssumeRole), which checks the role's trust policy and returns temporary credentials. IAM changes are eventually consistent, so a new permission can take a few seconds to apply. Read-only commands like get-role and list-attached-role-policies show the inputs; simulate-principal-policy evaluates identity policies for you.

Every request starts denied; an explicit Deny anywhere wins, and an Allow must survive every policy layer that applies.

evaluatenoallowsyesallowsyesno AllowAPI requests3:PutObjectrole shop-api-taskExplicit Deny?any policySCP / RCPOrganizationsAllow found?identity/resourceBoundary+ session policyAllowedrequest runsDeniedAccessDenied
1/7
Every request starts as deny

The service gathers every policy that applies: the caller's identity policies, the resource's policy, SCPs and RCPs, boundaries and session policies. With nothing else, the answer is an implicit deny.

← → to step

Options you'll actually use

sts get-caller-identityWhich user or role am I right now?
list-users / list-rolesPrincipals in the account (use --query to trim)
list-attached-role-policiesManaged policies on a role (--role-name); list-role-policies for inline ones
get-policy-versionThe JSON document of a managed policy (--policy-arn, --version-id)
get-role --role-name RRole details, including its trust policy (who may assume it)
simulate-principal-policyTest whether actions would be allowed for a principal
*-access-key(s)list-, create-, update- and delete-access-key: rotate long-lived keys
attach-role-policyAttach a managed policy to a role (detach-role-policy removes it)
decode-authorization-messageaws sts ...: decode the encoded reason in a denial

Common mistakes

Attaching AdministratorAccess to 'fix' an AccessDenied

Turns a missing permission into full account control for that principal, and hides what the app actually needs.

Read the error's action and resource, and grant exactly that (e.g. s3:PutObject on arn:aws:s3:::bucket/invoices/*)
"Resource": "arn:aws:s3:::kunal-artifacts" for s3:GetObject

Object actions apply to object ARNs; the bucket ARN alone matches nothing for GetObject.

arn:aws:s3:::kunal-artifacts/* for objects, the bucket ARN for s3:ListBucket
Long-lived access keys for CI and servers

Keys leak through logs, repos and laptops and stay valid until someone notices.

Roles: instance profiles, ECS task roles, EKS Pod Identity, OIDC federation for CI
A trust policy with "Principal": {"AWS": "*"}

Any AWS account in the world can try to assume the role; only conditions stand in the way.

Name specific accounts, roles or services, and add sts:ExternalId or aws:SourceArn conditions

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Write an IAM policy as ~/app/s3-invoices-policy.json that allows only s3:PutObject and s3:GetObject on objects under the invoices/ prefix of bucket devops-artifacts, then validate it is proper JSON with jq.

  2. 2

    With jq, list the actions allowed by that file, one per line.

  3. 3

    Show who is allowed to assume the role shop-api-task.

  4. 4

    Test whether the role shop-api-task may call ec2:TerminateInstances, without terminating anything.

Related commands

aws configureSet up AWS CLI credentials, region and profilesaws s3Copy, sync and list files in Amazon S3aws eksConnect kubectl to EKS and manage cluster accesssudoRun a command as root or another user
Previousaws ec2Nextaws eks