TExcelTAD
Home › Cloud & Container Security › Permission Boundaries, SCPs and the Full Evaluation Chain

Permission Boundaries, SCPs and the Full Evaluation Chain

A developer team gets AdministratorAccess in its development account "so it isn't blocked". Is that a finding? It depends on what sits above the identity policy. AWS can evaluate several policy types for one request, and two of them exist precisely to cap what an identity policy can grant: service control policies (SCPs) from AWS Organizations, set on the organisation, organisational units or accounts, and permission boundaries, set on a single user or role. An auditor who reads only identity policies will both over- and under-report; an attacker who finds a key wants to know which caps apply before trying anything noisy.

The chain

For a principal in a member account of an organisation, a request is allowed only if:

  1. no applicable policy of any type has an explicit deny;
  2. the SCPs on every level from the organisation root down to the account allow it (SCPs never grant; they only set the maximum). Since 2024 resource control policies (RCPs) do the same for resources in the account;
  3. the resource policy or the identity policy allows it (as in the evaluator);
  4. the permission boundary, if the principal has one, allows it: the effective permissions are the intersection of identity policy and boundary;
  5. the session policy, if the role session was created with one, allows it (another intersection).
explicit denyanywhere? SCPs / RCPsallow? identity orresource allow? boundaryallows? session policyallows? yes: DENYno: DENYno: DENYno: DENYyes: ALLOW every gate must pass (simplified; see the exceptions in the text)

Exceptions worth knowing (from AWS's documentation; check the current text before relying on them): SCPs don't apply to the organisation's management account or to service-linked roles; within one account, a resource policy that grants to a user ARN or a role session ARN directly isn't limited by that principal's boundary. The model below ignores these.

The model

python · try it yourself
from fnmatch import fnmatchcase

def L(x):
    return x if isinstance(x, list) else [x]

def cond_ok(cond, ctx):
    for op, tests in (cond or {}).items():
        for key, expected in tests.items():
            present = key in ctx
            if op == "StringEquals" and not (present and ctx[key] in L(expected)):
                return False
            if op == "StringNotEquals" and present and ctx[key] in L(expected):
                return False
    return True

def applies(st, req):
    a = req["action"].lower()
    act = (any(fnmatchcase(a, p.lower()) for p in L(st["Action"])) if "Action" in st
           else not any(fnmatchcase(a, p.lower()) for p in L(st["NotAction"])))
    return act and any(fnmatchcase(req["resource"], r) for r in L(st["Resource"])) and cond_ok(st.get("Condition"), req["ctx"])

def layer(policies, req):
    """'deny:<sid>' for an explicit deny, 'allow' if some statement allows, None otherwise."""
    allowed = None
    for pol in policies:
        for st in pol:
            if applies(st, req):
                if st["Effect"] == "Deny":
                    return "deny:" + st["Sid"]
                allowed = "allow"
    return allowed

def evaluate(req, scps, identity, boundary=None, session=None):
    layers = [("SCP", scps), ("identity", identity)]
    layers += [("boundary", boundary)] if boundary is not None else []
    layers += [("session", session)] if session is not None else []
    results = {name: layer(pols, req) for name, pols in layers}
    for name, r in results.items():
        if r and r.startswith("deny:"):
            return f"DENY explicit in {name} ({r[5:]})"
    for name, r in results.items():
        if r != "allow":
            return f"DENY: {name} does not allow"
    return "ALLOW"

ACCT = "210987654321"                              # the development account
BOUNDARY_ARN = f"arn:aws:iam::{ACCT}:policy/dev-boundary"
scps = [
    [{"Sid": "FullAWSAccess", "Effect": "Allow", "Action": "*", "Resource": "*"}],       # default, attached at the root
    [{"Sid": "ProtectTrail", "Effect": "Deny", "Action": ["cloudtrail:StopLogging", "cloudtrail:DeleteTrail"], "Resource": "*"},
     {"Sid": "EuOnly", "Effect": "Deny", "NotAction": ["iam:*", "sts:*", "organizations:*", "support:*"], "Resource": "*",
      "Condition": {"StringNotEquals": {"aws:RequestedRegion": ["eu-west-1"]}}}],          # attached to the Dev OU
]
admin = [[{"Sid": "AdministratorAccess", "Effect": "Allow", "Action": "*", "Resource": "*"}]]
boundary = [[
    {"Sid": "Workloads", "Effect": "Allow", "Action": ["ec2:*", "s3:*", "logs:*", "lambda:*"], "Resource": "*"},
    {"Sid": "PassOnlyBoundedRoles", "Effect": "Allow", "Action": ["iam:CreateRole", "iam:PutRolePermissionsBoundary"],
     "Resource": f"arn:aws:iam::{ACCT}:role/app-*", "Condition": {"StringEquals": {"iam:PermissionsBoundary": BOUNDARY_ARN}}},
    {"Sid": "KeepBoundary", "Effect": "Deny", "Action": ["iam:DeleteRolePermissionsBoundary", "iam:CreatePolicyVersion"],
     "Resource": "*"},
]]
read_only_session = [[{"Sid": "ReadOnly", "Effect": "Allow", "Action": ["s3:Get*", "s3:List*", "ec2:Describe*"], "Resource": "*"}]]

def ask(action, resource="*", session=None, **ctx):
    ctx.setdefault("aws:RequestedRegion", "eu-west-1")
    req = {"action": action, "resource": resource, "ctx": ctx}
    label = action + (f" [{ctx['aws:RequestedRegion']}]" if ctx["aws:RequestedRegion"] != "eu-west-1" else "")
    label += " +boundary" if "iam:PermissionsBoundary" in ctx else ""
    print(f"{label:46} {'session' if session else '':8} {evaluate(req, scps, admin, boundary, session)}")

ask("ec2:RunInstances")
ask("ec2:RunInstances", **{"aws:RequestedRegion": "us-east-1"})
ask("cloudtrail:StopLogging")
ask("dynamodb:DeleteTable")
ask("iam:CreateUser", f"arn:aws:iam::{ACCT}:user/backdoor", **{"aws:RequestedRegion": "us-east-1"})
ask("iam:CreateRole", f"arn:aws:iam::{ACCT}:role/app-worker", **{"aws:RequestedRegion": "us-east-1"})
ask("iam:CreateRole", f"arn:aws:iam::{ACCT}:role/app-worker", **{"aws:RequestedRegion": "us-east-1", "iam:PermissionsBoundary": BOUNDARY_ARN})
ask("iam:DeleteRolePermissionsBoundary", f"arn:aws:iam::{ACCT}:role/dev-admin", **{"aws:RequestedRegion": "us-east-1"})
ask("s3:GetObject", "arn:aws:s3:::lab-dev-data/x", session=read_only_session)
ask("s3:PutObject", "arn:aws:s3:::lab-dev-data/x", session=read_only_session)
ec2:RunInstances                                        ALLOW
ec2:RunInstances [us-east-1]                            DENY explicit in SCP (EuOnly)
cloudtrail:StopLogging                                  DENY explicit in SCP (ProtectTrail)
dynamodb:DeleteTable                                    DENY: boundary does not allow
iam:CreateUser [us-east-1]                              DENY: boundary does not allow
iam:CreateRole [us-east-1]                              DENY: boundary does not allow
iam:CreateRole [us-east-1] +boundary                    ALLOW
iam:DeleteRolePermissionsBoundary [us-east-1]           DENY explicit in boundary (KeepBoundary)
s3:GetObject                                   session  ALLOW
s3:PutObject                                   session  DENY: session does not allow

The development admin has Action: *, and yet:

  • The SCP on the Dev OU blocks every region except eu-west-1 and protects CloudTrail for everyone in the account, the account's own administrators included. IAM, STS and Organizations are exempted from the region rule because IAM and Organizations are global services whose requests carry the region us-east-1 (so do STS calls to the global endpoint sts.amazonaws.com); forgetting that exemption locks everyone out of IAM.
  • The boundary limits the role to EC2, S3, CloudWatch Logs and Lambda: DynamoDB and iam:CreateUser are implicitly denied even though the identity policy says *.
  • The PassOnlyBoundedRoles statement is the delegated-administration pattern: the team may create roles, but only named app-* and only with the same boundary attached, so it can't create a role more powerful than itself. Without the boundary parameter the same call is denied. KeepBoundary stops the team from removing its own cap.
  • A session policy (passed when assuming the role) narrowed one session to read-only.

How missing caps are detected

  • List the SCPs per OU and account (organizations list-policies-for-target) and check that every production account inherits the protective ones: CloudTrail and GuardDuty protection, region restriction, deny leaving the organisation, deny root user actions.
  • For every principal with broad identity policies, check whether a boundary is attached (iam get-role shows PermissionsBoundary) and whether it can be removed by the principal itself (iam:DeleteRolePermissionsBoundary, iam:PutRolePermissionsBoundary, iam:CreatePolicyVersion on the boundary policy).
  • In CloudTrail, alert on changes to the caps themselves: organizations:DetachPolicy, UpdatePolicy, iam:DeleteRolePermissionsBoundary (Cloud Detections).

How it is fixed

  • Keep FullAWSAccess at the root and add deny-list SCPs per OU for things nobody may do; allow-list SCPs (replacing FullAWSAccess) suit sandbox OUs with a fixed service list.
  • Attach a boundary to every role a team can create, enforce it with the iam:PermissionsBoundary condition, and deny changes to the boundary policy itself.
  • Test SCP changes in a test OU first: a wrong SCP is an outage for every account under it.

Pitfalls

  • Believing an SCP grants anything: it only removes. A principal with no identity policy has no permissions however generous the SCP.
  • Expecting SCPs to restrict the management account. Keep workloads out of it.
  • A boundary on the role, but the team can still edit the boundary policy (iam:CreatePolicyVersion), so the cap is self-service.

Practice

1. Remove "iam:*" from the EuOnly exemption list and run again. What breaks?

All four IAM requests (iam:CreateUser, both iam:CreateRole calls and iam:DeleteRolePermissionsBoundary) now hit the region deny (their region is us-east-1) and report DENY explicit in SCP (EuOnly), including the bounded CreateRole that was allowed before. In a real organisation, nobody in the Dev OU could manage IAM any more.

2. Change KeepBoundary to an Allow. Which request changes, and what does that mean?

iam:DeleteRolePermissionsBoundary is no longer denied by the boundary and is allowed (SCP allows it, identity is *). The team could remove its own boundary and become a full administrator of the account: the cap is worthless.

3. An auditor finds a role with AdministratorAccess in a production account, no boundary, but the account is under an OU whose SCPs deny IAM changes. Is it still a finding?

Yes, with a lower severity than without the SCP: the role can still read and delete every data store and resource the SCPs don't protect. SCPs cap the blast radius; they don't make broad roles least-privilege.

Test yourself

The identity policy allows *, the permission boundary allows only ec2:* and s3:*. Is dynamodb:DeleteTable allowed?

  1. Yes, identity policies win
  2. No: effective permissions are the intersection of identity policy and boundary
  3. Only in eu-west-1
  4. Only with MFA

Why are iam:* and sts:* exempted from the region-restriction SCP?

  1. They are free
  2. Their requests are made against us-east-1, so a region deny would block them
  3. SCPs can't mention IAM
  4. They are read-only

What does the iam:PermissionsBoundary condition on iam:CreateRole achieve?

  1. Faster role creation
  2. Roles created by the team must carry the same boundary, so the team can't create a more powerful role
  3. It deletes old roles
  4. It enables MFA

Do SCPs grant permissions?

  1. Yes, FullAWSAccess grants everything
  2. No, they only set the maximum; an identity or resource policy must still allow
  3. Only to the management account
  4. Only to roles