Sub topic 12
Data perimeter patterns with RCPs and SCPs
This chapter assumes you can read IAM policy JSON and that you know how SCPs and RCPs are attached, inherited, and evaluated from the earlier chapters. Here you combine them into a data perimeter. A data perimeter is a set of preventive guardrails that keeps your data reachable only by trusted identities, through trusted resources, from expected networks.
The three perimeters
A data perimeter has three parts. Each part answers one question about a request, and one policy type is the natural place to enforce it.
| Perimeter | Question it answers | Enforced with | Typical condition keys |
|---|---|---|---|
| Identity | Is only a trusted identity touching my resources? | RCP | `aws:PrincipalOrgID`, `aws:PrincipalIsAWSService` |
| Resource | Are my identities touching only trusted resources? | SCP | `aws:ResourceOrgID` |
| Network | Does the request come from an expected network? | RCP (resources), SCP (principals) | `aws:SourceIp`, `aws:SourceVpc`, `aws:ViaAWSService` |
The split follows what each policy type constrains. An SCP caps what principals in your accounts can do, so it can stop your identities from reaching resources outside your organization. An RCP caps what can be done to resources in your accounts, so it can stop outside identities from reaching your resources, even when a bucket policy allows them.
Identity perimeter with an RCP
The identity perimeter protects against a common mistake: someone writes a bucket policy that grants access to a wide set of principals, or to an account you do not control. An RCP overrides that, because an explicit deny in an RCP wins over any allow in a resource-based policy.
{
"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 condition as a conjunction. The statement denies a request only when both blocks are true:
- The caller's organization ID is not
o-exampleorgid, or the key is missing from the request. TheIfExistssuffix makes a missing key count as a match, so anonymous requests are denied too. - The caller is not an AWS service principal, or the key is missing.
If either block is false, the deny does not apply. A caller from your organization fails block 1. An AWS service acting with its own service principal fails block 2. Both pass through to normal evaluation. This exemption matters for features such as CloudFront origin access control and log delivery, which use service principals.
Exceptions you will need
A strict identity perimeter breaks legitimate access that you have not listed. Common cases:
- Approved third parties. Add their account IDs to the condition. One way is a third
StringNotEqualsIfExistsentry onaws:PrincipalAccount. Another is to list extra organization IDs inaws:PrincipalOrgID, which accepts an array. - Public content. A bucket that serves public static content to anonymous users will stop working. Keep such buckets in an OU that does not receive this RCP.
- Other services. The RCP above covers only S3. Extend the pattern to other RCP-supported services as you verify each one, rather than listing every service at once.
Resource perimeter with an SCP
The resource perimeter blocks data exfiltration by your own identities, for example copying objects to a personal bucket in an outside account. RCPs cannot do this, because the destination resource is not in your organization. An SCP can, because the request originates from a principal you govern.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyAccessToResourcesOutsideOrg",
"Effect": "Deny",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket"
],
"Resource": "*",
"Condition": {
"StringNotEqualsIfExists": {
"aws:ResourceOrgID": "o-exampleorgid"
}
}
}
]
}Notes on this pattern:
- Scope the action list to services that populate
aws:ResourceOrgID. Using"Action": "*"is risky, because some actions reach resources owned by AWS or by third parties as part of normal operation. - AWS-owned resources, such as buckets that hold public AWS artifacts, are not in your organization. If your workloads depend on them, add an exception for those resource ARNs, or use
NotResourceon the statement. - The SCP does not apply to the management account, so a principal there can still reach outside resources unless you control it another way.
Network perimeter
The network perimeter limits requests to known IP ranges or VPCs. As an RCP it protects resources from requests that arrive from anywhere else.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceExpectedNetworkOnS3",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"NotIpAddressIfExists": {
"aws:SourceIp": ["203.0.113.0/24"]
},
"StringNotEqualsIfExists": {
"aws:SourceVpc": ["vpc-0example1234567"]
},
"BoolIfExists": {
"aws:PrincipalIsAWSService": "false",
"aws:ViaAWSService": "false"
}
}
}
]
}The deny applies only when the request is outside the listed CIDR range, outside the listed VPC, not from an AWS service principal, and not made by a service on a caller's behalf. The last two checks matter. Without them you break services that call S3 for the caller, such as services that use forward access sessions, because those requests do not come from your network.
Combining the perimeters
Attach the policies at the level that matches the intent:
- Attach the identity and network RCPs at the root, with the S3 and other data-bearing services you have verified. Exempt specific OUs only through conditions or by attaching to child OUs instead of the root.
- Attach the resource perimeter SCP at the root or on workload OUs. Keep the management account in mind, since SCPs do not affect it.
- Keep the full-access defaults in place. A data perimeter is a deny layer on top of them. It never grants access, so your IAM policies and resource policies must still allow each request.
A request passes only when four things agree. The SCP does not deny it. The RCP does not deny it. An identity-based or resource-based policy allows it. No permission boundary or session policy blocks it.
Common failure modes
- Missing service principal exemption. Logs stop arriving, or CloudFront cannot read a bucket. Check that
aws:PrincipalIsAWSServiceis handled. - Operator mistakes.
StringNotEqualswithoutIfExistsdoes not match when the key is absent, so anonymous requests may slip past a deny. UseIfExistson deny statements that must catch missing keys. - Too-broad actions. A resource perimeter on
"Action": "*"can block calls to AWS-owned resources. Start with an explicit list. - Hidden dependencies. A forgotten partner role or a legacy bucket in another organization fails after rollout. Review access logs and AWS CloudTrail for cross-organization calls before you enforce.
Rolling out
Roll out in three steps. First, attach the policy to a test OU and run your integration tests. Second, check CloudTrail for access-denied events that name the policy as the cause. Third, widen the attachment one OU at a time. If you need to compare a proposed control against real traffic, search CloudTrail first for requests whose principal or resource organization differs from yours. That list is the set of exceptions you must decide on before you enforce.
Exercise
A team's bucket policy allows an account outside your organization to read objects. You then attach the identity perimeter RCP from this chapter to the root, and the outside account's reads start failing. A colleague says the bucket policy must be broken. What is the real cause, and what are two ways to restore access if the partner is approved?
Show answer
The RCP, not the bucket policy, is denying the request. The caller's aws:PrincipalOrgID is not your organization ID and the caller is not an AWS service, so both condition blocks match and the explicit deny overrides the bucket policy's allow. To restore access for an approved partner, either add the partner's account ID to an exception condition such as aws:PrincipalAccount, or add the partner's organization ID to the aws:PrincipalOrgID list. Attaching the RCP only to OUs that do not hold the shared bucket is a third option, but it removes the guardrail for those accounts.
Exercise
Why can an RCP enforce the identity perimeter but not the resource perimeter, and which policy type enforces the resource perimeter?
Show answer
An RCP applies to resources in your organization, so it can control who reaches them. It cannot control what your principals do with resources in other organizations. The resource perimeter has to restrict your own principals, which is what an SCP does, typically with a condition on aws:ResourceOrgID.