Guardrails with SCPs and RCPs: deny by exception, and test before you attach
Design a small catalogue of organisation guardrails (Region limits, protecting audit and security services, a root-user deny, sandbox limits, a data perimeter), prove them offline with a tested evaluator and linter, and roll them out without locking yourself out.
Assumes: .NET 10 LTS · xUnit v3 4.0.3 · AWS CLI v2 · Terraform AWS provider v6 · Region us-east-1. Verified against official sources on 2026-11-18.
Learning objectives
By the end of this lesson you can:
- Choose between a deny list and an allow list SCP strategy and explain why most banks use deny lists on top of
FullAWSAccess. - Write the five guardrails every bank organisation needs: Region restriction, protect audit logging, protect detection services, deny the root user, and block long-lived IAM user keys; plus sandbox limits and a Suspended-OU deny-all.
- Write a Region restriction that does not break IAM, Organizations, billing or CloudFront, and explain why
NotActionis required. - Describe what RCPs add (a perimeter around resources, including requests from outside the organisation) and what they cannot do.
- Test guardrails offline with the lab's evaluator and linter, and in AWS with a staging account, before attaching them to anything that matters.
- Roll out in stages with a rollback plan, and read an SCP denial in CloudTrail.
Prerequisites
- Boundaries, SCPs, RCPs and resource policies: the mechanics and the baseline Harbourline SCP. This lesson is the guardrail engineering that builds on it.
- Policy evaluation logic
- AWS Organizations structure
- Tools: .NET 10 SDK or Docker for the tests; the lab folder
labs/m15-org-guardrails.
Why this matters in banking
SCPs are the only control that holds even when an administrator in the account wants to break the rule. That makes them the right tool for the handful of things a bank must never lose: the audit trail, the detection services, the organisation membership, and the Regions where its data may live.
But an SCP is also the control that can take a whole business unit offline in one AttachPolicy call, and it fails silently in ways an engineer will blame on their own IAM policy for an hour before suspecting it. The skill is not writing SCP JSON. It is writing few, narrow, tested guardrails and rolling them out like a production change.
The idea in plain language
An SCP is a ceiling on what the IAM users and roles in a member account can do. It grants nothing. If the ceiling says "no", no IAM policy in the account can raise it. An RCP is a ceiling on what can be done to resources in member accounts, whoever is asking, including principals from outside your organisation. Use SCPs to say what your people cannot do. Use RCPs to say who may touch your resources.
Analogy: a bank's rulebook versus a vault door. An SCP is a head-office rule: "no branch may open an account outside the UK and Ireland, whatever the manager says". An RCP is the vault door: "only staff of this bank may enter, whatever a branch manager signed". The rulebook limits staff. The door limits visitors.
Deny list or allow list?
| Strategy | How it works | Pros | Cons |
|---|---|---|---|
| Deny list (most common) | Keep FullAWSAccess, add Deny statements for what must never happen | Easy to start, new services work automatically, small policies | You must think of everything you want to deny |
| Allow list | Remove FullAWSAccess, attach SCPs that Allow only listed services | Strong default-deny posture | New AWS features are blocked until added; policies grow large (10,240 character limit); every OU on the path needs the Allow |
Banks mostly choose deny lists at the OU level, with an allow list only for narrow OUs where a fixed service set makes sense (a tightly scoped sandbox, a payments production OU later in maturity). Do not mix strategies at random: at every level of the path an Allow must exist, and the lab proves what happens when you forget.
The guardrail catalogue for Harbourline
| # | Guardrail | Attach to | Policy file in the lab | Why |
|---|---|---|---|---|
| G1 | Deny leaving the organisation | All OUs | scp-baseline-protect | A compromised account must not walk out with its data |
| G2 | Deny the root user of member accounts | All OUs | scp-baseline-protect | Root bypasses IAM; deny day-to-day use |
| G3 | Protect the audit trail | All OUs | scp-baseline-protect | Nobody switches off CloudTrail |
| G4 | Protect detection services | All OUs | scp-baseline-protect | Nobody switches off GuardDuty, Security Hub or Config |
| G5 | No long-lived IAM user keys | All OUs | scp-baseline-protect | People use Identity Center and roles |
| G6 | Approved Regions only | All OUs | scp-deny-outside-regions | Data residency and attack surface |
| G7 | Sandbox limits | Sandbox | scp-sandbox-limits | Cost and risk containment |
| G8 | Suspended deny-all | Suspended | scp-suspended-deny-all | Freeze closed accounts and keep the evidence |
| G9 | Resource perimeter (RCP) | Workloads, Security | (inline, below) | Nothing outside the bank reads its buckets or keys |
All the SCPs are in the lab folder, linted and tested. Read them there rather than trusting the excerpts here.
What problem the AWS service solves
Without central guardrails, the only thing stopping an engineer in an account from disabling CloudTrail is that engineer's IAM policy, which an account administrator can edit. An SCP moves that decision to a level the account's own administrators cannot reach.
What SCPs do not do
- They do not restrict the management account.
- They do not restrict service-linked roles.
- They do not grant anything: a Deny is only useful if the action would otherwise be allowed.
- They apply to principals in your member accounts. They do not stop an outsider from using access that one of your resource-based policies grants; that is what RCPs are for.
- They do not see inside a request: they cannot enforce the contents of an object or the shape of a template (use tag policies, Config, CloudFormation Hooks or code for that).
What RCPs add, and their limits
RCPs apply to a supported set of services (S3, STS, KMS, SQS and Secrets Manager first, with more added over time) ⚠ VERIFY the current list before relying on one. Rules that bite:
- Only
Effect: Deny. TheRCPFullAWSAccesspolicy is attached automatically and cannot be removed. Principalmust be"*"; target principals with conditions.NotPrincipalandNotActionare not supported.- You cannot write
"Action": "*"; name the service, for example"s3:*". - 5,120 characters maximum; up to 5 attached per target, counting the built-in one.
- They do not restrict the management account's resources and do not apply to service-linked roles acting on a resource ⚠ VERIFY.
An RCP example, a bank-wide TLS and organisation perimeter for S3 only (adapted from the pattern in Boundaries, SCPs, RCPs; replace the organisation ID):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3OrganisationIdentityPerimeter",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringNotEqualsIfExists": { "aws:PrincipalOrgID": "o-a1b2c3d4e5" },
"BoolIfExists": { "aws:PrincipalIsAWSService": "false" }
}
},
{
"Sid": "S3RequireTls",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": { "BoolIfExists": { "aws:SecureTransport": "false" } }
}
]
}This one is not in the lab's policies/ folder because the lab evaluator models SCPs only. Test RCPs in a staging account with real requests. Public examples of data-perimeter policies exist in aws-samples/data-perimeter-policy-examples (MIT-0 code), which is a good starting point; adapt and test, never paste into production.
Microsoft / Azure comparison
| You know (Microsoft/Azure) | AWS equivalent | What's different |
|---|---|---|
Azure Policy deny effect at management group scope | SCP Deny on an OU | SCPs match API actions and conditions, not resource property values; they cannot "audit" |
| Azure Policy "allowed locations" | Region SCP with aws:RequestedRegion and NotAction for global services | Global services are not tied to a Region; forgetting that is the classic outage |
| Azure Policy "not allowed resource types" | SCP deny on actions (e.g. savingsplans:CreateSavingsPlan) | You deny API actions, not resource types |
| Azure Blueprint resource locks | SCP protecting actions, plus S3 Object Lock | There is no "lock" resource; deny the action that would delete |
| Azure Policy exemption | Condition exemption (ArnNotLike aws:PrincipalArn) for a break-glass role | The exemption is written inside the policy, so reviewing the policy reviews the exceptions |
| Microsoft Entra "block legacy authentication" | SCP: no iam:CreateUser / iam:CreateAccessKey | You block creation of long-lived credentials rather than a protocol |
| Azure private endpoints plus "disable public access" policy | RCP on S3 with aws:PrincipalOrgID | The RCP enforces who may call the resource, even if a bucket policy is wrong |
Architecture
Where guardrails sit in the evaluation of a request:
The rollout path for a new guardrail:
Step-by-step implementation
Write the policy as a file in Git
One concern per policy file, one statement per rule, every statement with a Sid. Small policies are easier to review and stay below the 10,240 character limit with room to spare. Name files after what they protect: scp-baseline-protect, not scp-1.
Define the break-glass role
Create a role named hl-security-breakglass in every account (baseline stack). Protected statements exempt it with ArnNotLike on aws:PrincipalArn. Because it is the only exemption, the policy review is also the exception review. Protect the role itself: only the security team may assume it, with MFA, and every assumption pages the SOC.
Lint
Run hl-org lint on each file. Fix every error. The linter checks the mistakes that actually hurt: Region deny without NotAction, Principal in an SCP, a non-* resource on an Allow, an exemption wildcard that matches every role, a missing Sid, and size.
Evaluate offline
Write tests that state what must be denied, what must still work and what the exemption allows. The lab ships 50 of them. A guardrail with no "must still work" test is a guardrail you have not tested.
Validate with AWS where you can
Run IAM Access Analyzer validate-policy for the SCP policy type ⚠ VERIFY that your CLI version supports SERVICE_CONTROL_POLICY. It catches syntax and some logic errors that your own linter does not.
Attach to a staging OU and watch
Attach to a real test account. Run a script that exercises both the denied and the still-working actions. Watch CloudTrail for AccessDenied that mentions a service control policy. One to two weeks is normal for a production guardrail.
Promote in stages, with a rollback
Sandbox, then NonProd, then Prod in a change window. The rollback is DetachPolicy, which takes effect quickly. Practise it. Record the policy version and the person who approved.
Monitor denials
EventBridge or a CloudWatch Logs metric filter on CloudTrail for errorCode containing AccessDenied and a message about a service control policy. A sudden spike after a deploy means a guardrail is breaking a pipeline.
AWS Console instructions
- Console → AWS Organizations → Policies → Service control policies → Create policy. Paste the JSON, add tags (
Owner,Lab), save. - Open the policy, choose Targets → Attach, and pick the OU (Sandbox first).
- To roll back: the same page, Targets, select the OU, Detach.
- Resource control policies is a sibling entry under Policies; Enable resource control policies first if you have never used them.
- In CloudTrail → Event history (member account), filter Event name or Error code to find the denial.
AWS CLI
# One-off: make sure SCPs are enabled on the root
ROOT_ID=$(aws organizations list-roots --profile learn-management --query "Roots[0].Id" --output text)
aws organizations enable-policy-type --root-id "$ROOT_ID" --policy-type SERVICE_CONTROL_POLICY --profile learn-management
# Validate the SCP with IAM Access Analyzer (⚠ VERIFY policy-type support in your CLI version)
aws accessanalyzer validate-policy --policy-type SERVICE_CONTROL_POLICY \
--policy-document file://policies/scp-baseline-protect.json --profile learn-management
# Create the policy and attach it to the SANDBOX OU only
POLICY_ID=$(aws organizations create-policy --name scp-baseline-protect --type SERVICE_CONTROL_POLICY \
--description "Harbourline baseline guardrails (lab m15)" \
--content file://policies/scp-baseline-protect.json \
--tags Key=Project,Value=cea-lab Key=Lab,Value=m15-l1 \
--profile learn-management --query "Policy.PolicySummary.Id" --output text)
aws organizations attach-policy --policy-id "$POLICY_ID" --target-id ou-xxxx-sandboxid --profile learn-management
# Update in place after a review (creates no new ID; effect is immediate)
aws organizations update-policy --policy-id "$POLICY_ID" --content file://policies/scp-baseline-protect.json --profile learn-management
# Who is it attached to?
aws organizations list-targets-for-policy --policy-id "$POLICY_ID" --profile learn-management
# Roll back
aws organizations detach-policy --policy-id "$POLICY_ID" --target-id ou-xxxx-sandboxid --profile learn-management
# Find denials in CloudTrail (run in the member account; the message wording is ⚠ VERIFY)
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=StopLogging \
--profile learn-sandbox --max-results 5 \
--query "Events[].CloudTrailEvent" --output textInfrastructure as Code
using System.Text.Json;
using Amazon.CDK;
using Amazon.CDK.AWS.Organizations;
using Constructs;
// Creates an SCP from a JSON file in Git and attaches it to one OU.
// Compiled against Amazon.CDK.Lib 2.277.0, not deployed. ⚠ VERIFY: JsonSerializer yields JsonElement values for
// nested objects; if synthesis rejects them, convert to plain dictionaries and lists first.
public class GuardrailStack : Stack
{
public GuardrailStack(Construct scope, string id, string sandboxOuId, string policyJsonPath) : base(scope, id)
{
var content = JsonSerializer.Deserialize<Dictionary<string, object>>(File.ReadAllText(policyJsonPath))!;
_ = new CfnPolicy(this, "BaselineProtect", new CfnPolicyProps
{
Name = "scp-baseline-protect",
Type = "SERVICE_CONTROL_POLICY",
Description = "Harbourline baseline guardrails",
Content = content,
TargetIds = new[] { sandboxOuId } // Sandbox first; widen only after testing
});
}
}Complete code
Everything is in labs/m15-org-guardrails. The core of the evaluator is short enough to read in full, which is the point: you can explain it to an auditor.
public Decision Evaluate(OrgNode account, AuthRequest request)
{
if (account.Kind != NodeKind.Account)
throw new ArgumentException("SCPs are evaluated for an account.", nameof(account));
// SCPs and RCPs never restrict the management account.
if (account.Purpose == "management")
return new Decision(true, "SCPs do not apply to the management account.");
// Service-linked roles are not restricted by SCPs.
if (request.PrincipalArn.Contains(":role/aws-service-role/", StringComparison.Ordinal))
return new Decision(true, "SCPs do not restrict service-linked roles.");
var context = BuildContext(request);
var path = account.PathFromRoot();
// 1. An explicit Deny anywhere wins.
foreach (var node in path)
{
foreach (var (policy, statement) in Statements(node))
{
if (!statement.IsAllow && Matches(statement, request, context))
return new Decision(false,
$"Explicit deny in '{policy.Name}' ({statement.Sid ?? "no Sid"}) attached to {node.Name}.",
policy.Name, statement.Sid);
}
}
// 2. Every level must offer an Allow.
foreach (var node in path)
{
var allowed = Statements(node).Any(x => x.Statement.IsAllow && Matches(x.Statement, request, context));
if (!allowed)
return new Decision(false,
$"No SCP attached to {node.Name} allows {request.Action}: the ceiling is not high enough.",
MissingAllowAt: node.Name);
}
return new Decision(true, "Allowed by an SCP at every level and denied by none.");
}The Region guardrail (policies/scp-deny-outside-regions.json), trimmed:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyOutsideApprovedRegions",
"Effect": "Deny",
"NotAction": [
"account:*", "budgets:*", "ce:*", "cloudfront:*", "cur:*", "iam:*",
"organizations:*", "route53:*", "route53domains:*", "sts:*", "support:*"
],
"Resource": "*",
"Condition": {
"StringNotEquals": { "aws:RequestedRegion": ["eu-west-2", "eu-west-1", "us-east-1"] },
"ArnNotLike": { "aws:PrincipalArn": "arn:aws:iam::*:role/hl-security-breakglass" }
}
}
]
}The shipped file has a longer exemption list. The exemption list of global services is ⚠ VERIFY against AWS's current guidance and the public sample policies before production use, because AWS adds and changes services.
Tests that state intent, from EvaluatorTests.cs:
[Theory]
[InlineData("eu-west-2", true)]
[InlineData("eu-west-1", true)]
[InlineData("us-east-1", true)]
[InlineData("ap-southeast-1", false)]
[InlineData("us-west-2", false)]
public void Region_guardrail_allows_only_approved_regions(string region, bool allowed)
{
var d = Run("payments-dev", "ec2:RunInstances", Fixtures.Developer("888888888888"), region,
"arn:aws:ec2:" + region + ":888888888888:instance/i-1");
Assert.Equal(allowed, d.Allowed);
}
[Fact]
public void Global_services_survive_the_region_guardrail()
{
// IAM is a global service: requests are made against us-east-1, and NotAction exempts it anyway.
var d = Run("payments-prod", "iam:ListRoles", Fixtures.Developer("666666666666"), "ap-southeast-1");
Assert.True(d.Allowed, d.Reason);
}
[Fact]
public void Breakglass_role_still_cannot_leave_the_organisation()
{
var d = Run("payments-prod", "organizations:LeaveOrganization", Fixtures.Breakglass("666666666666"));
Assert.False(d.Allowed);
Assert.Equal("DenyLeavingOrganisation", d.DenyingSid);
}Run all 50:
dotnet test --solution OrgGuardrails.slnxAnd a CI job (GitHub Actions) that validates every pull request touching the policies or the organisation file:
name: guardrails
on:
pull_request:
paths: ["labs/m15-org-guardrails/**"]
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
- name: Unit tests
run: dotnet test --solution OrgGuardrails.slnx
working-directory: labs/m15-org-guardrails
- name: Validate organisation design and policies
run: >
dotnet run --project src/Harbourline.Governance.Tool --
validate org/harbourline-org.json policies
working-directory: labs/m15-org-guardrailsCode explained line by line
The evaluator
- The first two
ifblocks encode the two exemptions from SCPs. Having them as code, with a test each, stops a future reader assuming SCPs are universal. PathFromRoot()gives the root-to-account chain. SCPs inherit down, so all of them matter.- Step 1 loops over every statement on the path. A matching
Denyreturns immediately, naming the policy and theSid. That is the information you want in an incident ("which statement blocked this?"), and why every statement needs aSid. - Step 2 requires an
Allowthat matches the request at every level. With onlyFullAWSAccessit always does. If someone has removed it and attached a narrow allow list, an action outside the list fails here withMissingAllowAt, and the reason names the level. Matcheschecks action (with wildcard, case-insensitive), resource (wildcard, case-sensitive) and all conditions (AND).- Conditions treat a missing key the way IAM does:
...IfExistsmakes it true; a negated operator (StringNotEquals,ArnNotLike) is true; a positive operator is false. A test proves each. - An operator the evaluator does not model throws
NotSupportedException. A test double that silently returns "allowed" for things it does not understand is worse than none.
The Region guardrail
NotActionmeans "deny everything except these", so the list contains the global-service actions that must keep working.StringNotEqualsonaws:RequestedRegiontriggers the deny when the Region is not in the list.ArnNotLikeonaws:PrincipalArnlets the break-glass role through.- The two conditions are AND-ed: deny when the Region is wrong and the caller is not break-glass.
Security considerations
⚠ Learning shortcut — not for production
The lab's evaluator is a small model of SCP behaviour for learning and for catching mistakes early. It does not replace testing in a real staging account, and it does not model RCPs, ForAnyValue/ForAllValues, numeric or date operators, policy variables, or the interaction with IAM policies and resource policies. Production guardrails need both: offline unit tests (fast, in CI) and a staging account (real AWS behaviour).
- Your SCP is only as safe as its exemption. A wide
ArnNotLike(likerole/*) protects nothing; the linter flags it as HL-SCP-006. - Do not lock out the people who fix SCPs. The management account is exempt, so keep one tested path (a management-account role) that can detach any policy, and test it before you attach anything.
- Guardrails are not data protection. An SCP does not encrypt, classify or log. It limits actions. Pair it with KMS, Object Lock, Macie and logging.
- Region limits protect residency only for data you control. Replication and DR design decide where data actually lives. Involve legal and compliance on what "approved Regions" means for UK GDPR transfers; do not state it as a legal conclusion.
- Change control.
CreatePolicy,UpdatePolicy,AttachPolicyandDetachPolicyare among the most sensitive API calls in the organisation. Alert on all of them and allow only a pipeline role. - Do not claim compliance. "We have an SCP that denies disabling GuardDuty" is a design control that can support evidence. It does not by itself satisfy any framework requirement.
Banking use case
A new fraud analytics team asks for an account that may use only a few services and must never leave the UK Regions. Harbourline places the account in a dedicated child OU of NonProd, attaches the standard baseline and Region SCPs (inherited), and adds a narrow allow list for that OU only: S3, Athena, Glue, KMS, CloudWatch and the Identity Center service-linked roles. The platform team then runs the offline tests (Removing_FullAWSAccess_leaves_an_allow_list_that_blocks_everything_else is the pattern), attaches the policy to a staging account, and promotes after two weeks of no unexpected denials. When the team later needs Bedrock for a model experiment, the request is a one-line pull request to the allow list with a data-protection review, not an exception hidden in an account.
Common mistakes
- Region deny on
Action: "*". Blocks global services; the linter's HL-SCP-005 exists for this. - Attaching to the root first. One bug then affects the entire bank.
- Removing
FullAWSAccessand forgetting that a narrow allow list denies everything else, including new services. - Writing
Principalin an SCP. Not supported. Use conditions. - Non-
*resource on an Allow statement. Not allowed for SCP Allows; narrow only in Denies. - Testing with an administrator in the management account. SCPs do not apply there, so the test proves nothing. Test in a member account.
- No
Sid. Then a denial in CloudTrail says nothing about which statement fired. - Assuming an exemption by session name. Match on the role ARN with
aws:PrincipalArn; session names are caller-chosen. - One giant policy. It exceeds the character limit and nobody can review it. Split by concern.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
AccessDenied ... with an explicit deny in a service control policy ⚠ VERIFY wording | An SCP Deny matched | Find which policy and statement: list targets and policies along the path, then read the statements. In the lab, hl-org check names the Sid |
| An action that was allowed yesterday fails after a move | The account's new OU inherits an SCP with an Allow list lacking that action | Compare effective policies of old and new OU; add to the allow list or choose another OU |
| IAM Identity Center or a pipeline breaks after the Region SCP | A global-service action is not in NotAction | Add the action prefix to the exemption list (after review) and re-test |
| Admin in the management account cannot reproduce the denial | SCPs do not apply to the management account | Reproduce from a member account |
ConstraintViolationException when attaching | More than 10 SCPs on the target, or policy too large | Merge or trim; the lab's validator flags both |
PolicyTypeNotEnabledException | SCPs or RCPs not enabled on the root | enable-policy-type |
Lab test throws NotSupportedException | A condition operator the evaluator does not model | Add support or test it in a staging account |
Cost and cleanup
Cost: free. SCPs and RCPs have no charge; the lab tests run locally. Attaching guardrails to the Sandbox OU changes real behaviour, so clean up:
# Detach and delete what you created (policy must be detached from every target before deletion)
aws organizations detach-policy --policy-id "$POLICY_ID" --target-id ou-xxxx-sandboxid --profile learn-management
aws organizations delete-policy --policy-id "$POLICY_ID" --profile learn-management
# Or, if you used Terraform
cd labs/m15-org-guardrails/infra/terraform
terraform destroy -var owner=you -var root_id=r-xxxx
# Local build output
find labs/m15-org-guardrails -type d \( -name bin -o -name obj \) -prune -exec rm -rf {} +Exercises
- 🟢 Guided: Run
hl-org checkforpayments-devandec2:RunInstancesinap-southeast-1, then ineu-west-2. Then runlintonpolicies/bad/bad-region-deny.jsonand fix the file until the linter is quiet. - 🟡 Challenge: Add a guardrail G10 that stops anyone except break-glass from changing S3 Block Public Access settings (bucket level and account level). Write the policy, two tests (denied for developer, allowed for break-glass) and attach it in
harbourline-org.jsonto Workloads. - 🔴 Live problem: "Since Tuesday's SCP rollout, the nightly data load fails at 02:00 in
dataplatform-prodbut works in dev." You have CloudTrail and the policy files. Write the investigation plan and the three most likely causes.
Assignment
Add a guardrails/ folder to your portfolio repository with: the policy JSON files, tests that state what must be denied and what must still work, the CI workflow, and a one-page rollout plan (order of OUs, time in each, rollback command, who approves). Include the output of hl-org validate.
Solutions
ap-southeast-1 returns DENIED: Explicit deny in 'scp-deny-outside-regions' (DenyOutsideApprovedRegions) attached to Workloads. and eu-west-2 returns allowed (exit code 0). For the bad policy, the linter reports HL-SCP-005 (Region deny on every action). The fix is to move to NotAction with the global-service list, as in the shipped scp-deny-outside-regions.json.
A statement like {"Sid":"ProtectPublicAccessBlock","Effect":"Deny","Action":["s3:PutBucketPublicAccessBlock","s3:PutAccountPublicAccessBlock"],"Resource":"*","Condition":{"ArnNotLike":{"aws:PrincipalArn":"arn:aws:iam::*:role/hl-security-breakglass"}}} (deleting a Block Public Access configuration is governed by the same Put permission, but check the exact action names in the S3 documentation ⚠ VERIFY). Tests: developer role denied in payments-prod; break-glass allowed; developer still allowed s3:GetObject (the "still works" test). Run hl-org validate: HL-ORG-010 only checks the five protected actions, so extend OrgValidator.ProtectedActions to include the new actions if you want the probe to cover them.
Plan: (1) find the failing call in CloudTrail in the prod account and read errorCode and errorMessage; (2) list the SCPs on the path root, Workloads, Prod, account and diff against dev's path. Likely causes: a) the job runs in a Region outside the approved list in prod only (dev's OU has no Region SCP, or the job uses a global-endpoint call that is not in NotAction); b) the prod OU has an allow list that lacks a new service the job started using; c) the job uses a role named differently from the break-glass exemption, or assumes a role chain whose session principal does not match aws:PrincipalArn, or an IAM user key is created by the job and now denied by G5. Fix by adding the needed action or Region after review, or changing the job; never by detaching a guardrail without an owner's approval.
Knowledge check
Answer: Only S3 actions can be allowed in accounts below that OU. Everything else is denied because no SCP at that level allows it (an allow list).
Answer: Global services (IAM, Organizations, billing, CloudFront, Route 53 and others) are not served from the approved Regions. Denying * outside approved Regions would block them too. NotAction exempts them.
Answer: No. Custom RCPs contain only Deny statements. RCPFullAWSAccess is the built-in Allow.
Answer: SCPs do not restrict the management account. Test from a member account.
Answer: A role session name is chosen by the caller; the role ARN identifies the role. aws:PrincipalArn resolves an assumed-role session to the role ARN.
Interview questions
- How do you roll out an SCP to a production organisation safely? Lint, unit test, validate with Access Analyzer, attach to a staging account, watch CloudTrail, promote OU by OU with a change window and a rehearsed rollback (
DetachPolicy). Alert on policy changes. - What is the difference between an SCP and a permission boundary? An SCP caps every principal in an account or OU, set centrally by the organisation. A permission boundary caps one IAM user or role, set within an account. Both are ceilings; effective permission is the intersection with the identity policy.
- What does an RCP do that an SCP cannot? It restricts access to resources even from principals outside the organisation, for supported services, for example enforcing an organisation identity perimeter on S3 whatever a bucket policy says.
- What are the limits of SCPs for compliance? They enforce a rule on API actions but do not prove the rule holds in all cases, do not cover the management account or service-linked roles, and do not inspect content. They are one control among several.
Certification practice
A bank must ensure no principal in member accounts can stop CloudTrail logging, except an emergency role. Which implementation is correct?
A) An IAM policy in each account denying cloudtrail:StopLogging.
B) An SCP with a Deny on cloudtrail:StopLogging and an ArnNotLike condition on aws:PrincipalArn for the emergency role, attached to the OUs.
C) An SCP with an Allow for the emergency role only.
D) A resource control policy on CloudTrail.
Answer: B. An SCP Deny with a role exemption applies centrally and cannot be edited by account administrators. A can be changed by an account administrator. C is wrong because SCPs do not grant; an Allow cannot restrict other principals. D is wrong because RCPs control who may access a resource, whereas this requirement restricts what your own principals may do, which is an SCP's job.
A company wants to ensure that data in S3 buckets in all member accounts cannot be accessed by principals outside the organisation, even if a developer mistakenly makes a bucket policy too permissive. Which control best meets this?
A) An SCP on the root denying s3:* for external principals.
B) A resource control policy that denies S3 actions unless aws:PrincipalOrgID matches the organisation (with an exception for AWS service principals).
C) A permission boundary on every role.
D) S3 Block Public Access only.
Answer: B. RCPs cap resource access, including by outsiders, regardless of the bucket policy. A is wrong because SCPs only restrict principals in your own accounts. C only restricts roles in the account. D controls public access but not access by other AWS accounts.
After a new SCP is attached to the Workloads OU, an operations engineer in the management account tests a blocked action and finds it succeeds. What explains this?
A) SCP propagation takes 24 hours. B) SCPs do not apply to the management account. C) The engineer has too many IAM permissions. D) The SCP syntax is invalid.
Answer: B. SCPs never restrict the management account. A is wrong (changes take effect quickly). C is wrong because IAM permissions cannot override an SCP Deny in a member account; the real reason is the management account exemption. D is wrong because invalid syntax would have been rejected when the policy was saved.
Completion checklist
- I can state deny list versus allow list and why banks usually choose deny list
- I can explain why a Region SCP needs
NotAction - I ran
hl-org linton a bad policy and fixed it - I ran the 50 tests and read one test that proves a "must still work" case
- I can describe the rollout path and the rollback command
- I ran the cleanup
Key takeaways
- SCPs are ceilings set where account admins cannot reach: use them for the few things that must never happen.
- Write few, narrow,
Sid-labelled policies; exempt one named break-glass role. - Test offline for speed and in a staging account for truth.
- Roll out OU by OU and practise the rollback. The root is the last place.
- RCPs protect resources from outsiders; SCPs limit your own principals.
Further reading
- aws-samples/service-control-policy-examples (MIT-0): a library of examples to adapt
- aws-samples/data-perimeter-policy-examples: SCP, RCP and endpoint policy examples
- Boundaries, SCPs, RCPs and resource policies
- Next: Centralised logging
Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.
AWS Control Tower and landing zones: build it, buy it or start lighter
Understand what AWS Control Tower creates in your organisation, how its controls and Account Factory work, what it costs, and how to decide between Control Tower, a lite landing zone built as code, or a mix of both.
Lab 15.1: design, test and attach organisation guardrails
Describe Harbourline's organisation as a file, prove with 50 tests that its guardrails block what they should and allow what they must, then attach them to your sandbox OU with Terraform and watch a real explicit deny.