Skip to Content
Asterrr's Handbook
4 · Identity and access management

IAM identities and policy types

Users, groups, roles, the nine policy types, policy JSON elements, condition operators and keys, NotAction, and the IAM size limits the exam quotes.

Exam tasks: 4.2 (Skills 4.2.1 authorization controls and resource policies for cross-account access, 4.2.3 interpret and implement least-privilege policies, 4.2.4 analyze authorization failures)

The decision: which identity, policy type, condition key and operator expresses the restriction the question describes?

IAM is a global service. It authenticates principals and authorizes each request against a set of policies. Everything is denied by default. Permissions come only from an explicit Allow that survives every guardrail.

Grant permissionsLimit permissionsAWS accountgrantsgrantscapscapsIdentity-basedpolicyResource-basedpolicySCP and RCPPermissionsboundaryIAM user or role
Identities receive permissions from identity-based policies. Guardrail policies only shrink what those grants can reach.

Identities

IdentityCredentialsRemember
Root userEmail and password, optional access keysFull access. Cannot be limited by IAM policies. Is limited by SCPs and RCPs in member accounts.
IAM userPassword for console, up to two access keysLong-term credentials. Use only where federation or roles are impossible.
IAM user groupNoneCollection of users for attaching policies. Groups cannot be nested and cannot be a Principal.
IAM roleNone, issues temporary credentialsAssumed by users, services, other accounts and federated identities. Has a trust policy plus permissions policies.

Exam signal

"Avoid long-term credentials" or "no embedded keys" points to roles, IAM Identity Center or federation. Long-term access keys are justified only for workloads that cannot use roles, third-party clients that cannot use Identity Center, and break-glass users protected by MFA.

Policy types

AWS lists nine types. Only the first two grant permissions on their own. The rest set limits.

TypeAttached toGrants?Key point
Identity-basedUser, group, roleYesManaged (AWS or customer) or inline.
Resource-basedResource, such as S3 bucket or role trust policyYes, to the named principalAlways inline. Needs a Principal element.
Permissions boundaryUser or roleNoCaps identity-based grants. Does not cap resource-based grants to a user or role session ARN.
SCPOrg root, OU, accountNoCaps principals in member accounts.
RCPOrg root, OU, accountNoCaps resources in member accounts, even for outside principals.
Session policyPassed at AssumeRole or GetFederationTokenNoCaps one session.
VPC endpoint policyVPC endpointNoExtra boundary for traffic through the endpoint. Default allows all.
ACLResource (S3, WAF, VPC)Yes, cross-account onlyOnly non-JSON type. Cannot grant to the same account. For S3, disable them with Object Ownership.
RAM resource shareShared resourceYesAlternative to per-resource policies for sharing subnets, Transit Gateway and similar.

Inline policies have no ARN of their own and are deleted with the identity. Customer managed policies are reusable and versioned. AWS managed policies cannot be edited.

Policy elements

ElementNotes
VersionUse 2012-10-17. Needed for policy variables.
SidOptional label.
EffectAllow or Deny.
PrincipalRequired in resource-based policies. Not allowed in identity-based policies.
Action and NotActionWildcards allowed, such as ec2:Describe*.
Resource and NotResourceARNs. Some actions need *.
ConditionOptional. Multiple operators in one block are ANDed. Multiple values for one key are ORed.

Multiple statements and multiple policies are combined with a logical OR before denies are applied.

Condition operators that get tested

OperatorBehavior
StringEqualsExact, case-sensitive.
StringEqualsIgnoreCaseExact, ignores case.
StringLikeCase-sensitive, supports * and ?.
ArnLike, ArnEqualsCompare each ARN segment. Behave identically.
IpAddress, NotIpAddressCIDR match on aws:SourceIp. Absent when a VPC endpoint is used.
Boolaws:SecureTransport, aws:MultiFactorAuthPresent.
Null"false" means the key must exist.
...IfExistsMissing key counts as true. Fixes multi-resource actions such as ec2:RunInstances.
ForAllValues, ForAnyValueSet operators for multivalued keys. ForAllValues is true on an empty set, so add a Null check.

A missing key makes a positive operator false. A missing key makes a negated operator such as StringNotLike true.

  • Within a condition key, values are OR. Across keys and across operators, it's AND.
  • Only the Like operators honour * and ?. Bool takes "true" or "false" as strings.

Exam trap

StringLike is not case-insensitive. It is case-sensitive and only adds wildcards. Use StringEqualsIgnoreCase when case must be ignored. Also, aws:SourceIp does not work when a service calls another service on your behalf, because the target sees the calling service address.

Condition keys that decide exam questions

KeyWhat it checksClassic use
aws:PrincipalOrgIDCaller's account is in your organizationBucket or key policy: allow anyone in the org, no account list
aws:PrincipalOrgPathsCaller's OU pathOnly accounts under the prod OU
aws:ResourceOrgIDResource belongs to your orgIdentity or endpoint policy: company buckets only
aws:SourceVpce / aws:SourceVpcRequest came through this endpoint or VPCBucket reachable only from inside the network
aws:SourceIpPublic IP of the callerOffice egress range. Not populated through VPC endpoints; use aws:VpcSourceIp there
aws:MultiFactorAuthPresentSession was created with MFADeny sensitive actions without MFA
aws:MultiFactorAuthAgeSeconds since MFARequire recent MFA for deletes
aws:SecureTransportRequest used TLSDeny HTTP on buckets and queues
aws:RequestedRegionTarget RegionRegion restriction SCPs
aws:PrincipalTag/..., aws:ResourceTag/..., aws:RequestTag/..., aws:TagKeysTags on caller, resource and requestABAC
aws:SourceArn / aws:SourceAccountWhich resource made a service call on your behalfConfused deputy protection in resource policies
aws:PrincipalIsAWSService, aws:ViaAWSService, aws:CalledViaThe call came from, or through, an AWS serviceExempt service calls from network-perimeter denies

The MFA deny done right

Long-term access keys never carry aws:MultiFactorAuthPresent. A deny with Bool false misses them, because the key is absent. BoolIfExists catches both cases:

{
  "Sid": "DenyDeletesWithoutMfa",
  "Effect": "Deny",
  "Action": ["s3:DeleteObject", "s3:DeleteBucket"],
  "Resource": "*",
  "Condition": { "BoolIfExists": { "aws:MultiFactorAuthPresent": "false" } }
}

A network perimeter on a bucket

{
  "Sid": "OnlyFromOurEndpointOrServices",
  "Effect": "Deny",
  "Principal": "*",
  "Action": "s3:*",
  "Resource": ["arn:aws:s3:::lumen-ledger", "arn:aws:s3:::lumen-ledger/*"],
  "Condition": {
    "StringNotEqualsIfExists": { "aws:SourceVpce": "vpce-0a1b2c3d4e5f60718" },
    "BoolIfExists": { "aws:PrincipalIsAWSService": "false" }
  }
}

Both conditions must be true for the deny to apply: the request didn't come through the endpoint and it isn't an AWS service principal (such as CloudTrail delivering logs).

aws:SourceIp behind an endpoint

A bucket policy that allows only aws:SourceIp 203.0.113.0/24 breaks as soon as instances reach S3 through a gateway endpoint, because requests then carry private addresses and no public source IP. Use aws:SourceVpce or aws:SourceVpc for traffic from your VPCs.

NotAction, NotResource and NotPrincipal

  • Allow + NotAction grants every action except those listed, including services launched next year. It's almost never least privilege.
  • Deny + NotAction with a condition is the useful form: "deny everything except IAM and STS unless MFA is present", or "deny everything outside eu-west-1 except global services".
  • NotResource in an allow means "every resource except these". Same risk as above.
  • NotPrincipal with Deny is fragile: you must list the role and the assumed-role session ARN and the account, or you lock out the principal you meant to exempt. Prefer "Principal": "*" with an aws:PrincipalArn condition (ArnNotLike), which matches every session of the role.

Exam signal

If an answer uses NotPrincipal and another uses Principal: * with a StringNotEquals or ArnNotLike condition on aws:PrincipalArn or aws:PrincipalOrgID, pick the condition version.

Limits and defaults

ItemValue
Customer managed policy size6,144 characters (whitespace not counted)
Inline policy total per entityUser 2,048, group 5,120, role 10,240 characters
Role trust policy length2,048 default, adjustable to 8,192
Managed policies per role20 default, up to 25
Managed policies per user10 default, up to 20
Customer managed policies per account1,500 default, up to 10,000
Roles per account1,000 default, up to 10,000
Groups per account300 default, up to 500
Session policy2,048 characters combined with ARNs, max 10 managed ARNs, one JSON document
Session tagsUp to 50
Role session name64 characters

Scenarios

Scenario
A security engineer wants to force MFA for all actions except managing one's own MFA device and calling sts:GetSessionToken. The first draft denies everything with NotAction for those exceptions when aws:MultiFactorAuthPresent is false. Testing shows that CLI calls with a long-term access key and no MFA still succeed. What is the cause?
Scenario
A company wants a KMS key policy that lets any role in any of its 140 accounts use the key for decryption, without listing accounts, and with no access from outside the company. Which condition should the key policy statement use?

Further reading

On this page