Sub topic 12
Data perimeter patterns with RCPs and SCPs
This chapter assumes you can read IAM policy JSON and know that SCPs limit principals while RCPs limit resources. It also assumes you know how both are attached and inherited in an organization.
What a data perimeter is
A data perimeter is a set of preventive guardrails that keep your data inside boundaries you trust. The guardrails are set once at the organization level and apply whatever individual teams put in their own policies.
Three boundaries are common:
| Boundary | Question it answers | Typical control |
|---|---|---|
| Identity | Who may touch my resources? | RCP on resources |
| Resource | Which resources may my principals touch? | SCP on principals |
| Network | From where may requests arrive? | RCP and SCP with network conditions |
The split follows from what each policy type controls. An RCP sits on the resource side of a request, so it can restrict who reaches your buckets, even if a bucket policy is too open. An SCP sits on the principal side, so it can restrict what your own roles reach, such as a bucket in an unknown account.
Identity perimeter with an RCP
This RCP denies S3 access to any principal outside your organization, unless the caller is an AWS service.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyNonOrgPrincipalsOnS3",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringNotEqualsIfExists": {
"aws:PrincipalOrgID": "o-exampleorgid"
},
"BoolIfExists": {
"aws:PrincipalIsAWSService": "false"
}
}
}
]
}Read the two conditions together. Both must be true for the deny to apply, so the request is denied only when the principal is not in your organization and is not an AWS service.
The IfExists suffix matters. If a key is missing from the request, the condition still matches, so the request is denied. Anonymous requests have no aws:PrincipalOrgID, so this policy blocks them too.
Resource perimeter with an SCP
The mirror image is an SCP that stops your principals from reading or writing resources owned outside the organization. You build it with the aws:ResourceOrgID condition key. Two cautions apply:
- Some actions, such as listing all buckets, have no resource organization to compare. Scope the deny to specific actions, or use an
IfExistsoperator with care. - AWS services sometimes read AWS-owned resources on your behalf, such as buckets that hold agent software or public datasets. Exempt those, or your workloads will break.
Handling approved exceptions
Real environments have partners, vendors, and shared services. Add exceptions to the deny conditions instead of removing the perimeter. Common patterns are:
- Allow a known external account by adding a
StringNotEqualsIfExistscheck onaws:PrincipalAccount. - Allow a trusted role ARN by adding a check on
aws:PrincipalArn. - Tag principals that need an exception and test the tag in the condition.
Keep the exception list short and record why each entry exists.
Check your work
Before attaching a perimeter broadly, review these points:
- Confirm S3 is a supported service for RCPs, and check the list for each service you add.
- Search CloudTrail for cross-account and service-principal calls to find legitimate traffic you would block.
- Remember that RCPs do not affect service-linked roles or principals in the management account's own resources in the same way as member accounts. Check the exemptions list before you rely on a control.
Exercise
Your RCP uses StringNotEqualsIfExists on aws:PrincipalOrgID with no other conditions. A CloudFront or Lambda service call to a bucket suddenly fails. What condition did the RCP in this chapter use to avoid that, and why does it work?
Show answer
It added BoolIfExists with aws:PrincipalIsAWSService set to "false". Both conditions must match for the deny to apply. When an AWS service principal makes the call, aws:PrincipalIsAWSService is true, so the second condition fails and the deny does not apply.