Opscraft
AWS IAM & multi-account security · Lesson 2 of 7 · 5 min read

Policies: types and structure

Policy document anatomy

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadOrdersBucket",
      "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:ListBucket"],
      "Resource": [
        "arn:aws:s3:::acme-orders-prod",
        "arn:aws:s3:::acme-orders-prod/*"
      ],
      "Condition": {
        "StringEquals": { "aws:PrincipalTag/team": "orders" },
        "Bool": { "aws:SecureTransport": "true" }
      }
    }
  ]
}
Enlarge diagramEffect"Allow"Action"s3:GetObject"Resource"arn:aws:s3:::orders-data/*"Conditionaws:SourceVpce = vpce-0abcListBucket applies to the bucket ARN; GetObject to object ARNs (/*). Mixing them up is a classic AccessDenied.
Figure 1. The parts of a policy statement, read as a sentence: Allow this Action on this Resource, if this Condition is true.
Swipe sideways to see all of it, or tap to open it full screen.
  • Effect Allow/Deny; Action (supports wildcards; NotAction inverts); Resource ARNs (NotResource); Principal only in resource-based and trust policies; Condition with operators (StringEquals, StringLike, ArnLike, IpAddress, Bool, NumericLessThan, DateGreaterThan, ...IfExists, ForAnyValue:/ForAllValues:).
  • Note s3:ListBucket applies to the bucket ARN and GetObject to object ARNs (/*) — a classic mistake.
  • Version "2012-10-17" is required for policy variables like ${aws:username} and ${aws:PrincipalTag/team}.

Policy types

Type Attached to Purpose
Identity-based (managed or inline) Users, groups, roles What the identity can do
Resource-based Resources (S3 bucket policy, KMS key policy, SQS, SNS, Lambda, ECR, Secrets Manager) Who can access this resource; enables cross-account without role assumption
Trust policy Roles (a resource policy on the role) Who can assume the role
Permissions boundary Users/roles Maximum permissions the identity can ever have — used to safely delegate role creation
SCPs (Service Control Policies) Organization root, OUs, accounts Maximum permissions for all principals in member accounts (not the management account) — guardrails
RCPs (Resource Control Policies) Organization, OUs, accounts Maximum permissions on resources in member accounts (e.g. no external access to S3)
Session policies Passed when assuming a role/federating Further restrict a single session
ACLs Legacy S3/other Avoid

Managed policies: AWS managed (convenient, often too broad — AdministratorAccess, ReadOnlyAccess), customer managed (yours, versioned, reusable). Inline policies are embedded in one identity — use for strict one-to-one cases.

Enlarge diagramGRANT PERMISSIONSONLY LIMIT (NEVER GRANT)Identity-basedattached to a user, group or roleResource-basedon the bucket, key or queueTrust policywho may assume a roleSCPs and RCPsorganisation guardrailsPermissions boundarycap on a role or userSession policycap for one session
Figure 2. Some policies grant permissions; others only set the maximum. Access is allowed only where the granting policies and every limit overlap.
Swipe sideways to see all of it, or tap to open it full screen.

Policy evaluation logic

For a request within one account:

  1. Explicit Deny anywhere (SCP, RCP, boundary, session, identity, resource) → denied. Deny always wins.
  2. Organizations SCPs/RCPs must allow it (if in a member account).
  3. Resource-based policy — if it allows the principal, it can grant access (within the same account) even without an identity policy (with caveats for roles/boundaries).
  4. Permissions boundary must allow it (if set).
  5. Session policy must allow it (if used).
  6. Identity-based policy must allow it.
  7. Otherwise implicit deny (default).

Effective permission = intersection of all the "maximum" policies (SCP ∩ RCP ∩ boundary ∩ session) with what identity/resource policies grant.

Enlarge diagramExplicit Deny anywhere?yes → DENIEDSCPs / RCPs allow?no → deniedResource policy allows?can grant within an accountPermissions boundaryallows?no → deniedSession policy allows?no → deniedIdentity policy allows?yes → ALLOWED, else implicitdeny123456
Figure 3. How AWS decides a request. Any explicit deny wins; otherwise every limiting policy must allow it and some policy must grant it.
Swipe sideways to see all of it, or tap to open it full screen.

Cross-account: the caller's identity policy must allow the action and the resource policy in the other account (or the trust policy of the role being assumed) must allow the caller. Both sides must say yes.

Enlarge diagramACCOUNT A (TOOLING)ACCOUNT B (PROD)CI roleidentity policy: Allow sts:AssumeRole onarn:…:222233334444:role/deploydeploy roletrust policy: Allow account A's CI role toassume meEither side missing → AccessDenied
Figure 4. Cross-account access needs both sides to agree: the caller's account must allow the call, and the other account must allow the caller.
Swipe sideways to see all of it, or tap to open it full screen.