Sub topic 10
Writing RCPs and checking supported services
This chapter assumes you can read IAM policy JSON, you know how SCPs inherit down the organization tree, and you have enabled the RCP policy type on the root. You will learn the rules that shape an RCP, how to read its two example policies, how to add exceptions, and how to confirm a service is supported before you rely on a policy.
What makes an RCP different to write
An RCP looks like an IAM policy, but it is restricted in ways that follow from what it does. It sets the maximum permissions on resources in member accounts, whoever the caller is. It never grants access.
| Element | Rule in an RCP |
|---|---|
| Effect | Use `Deny` in custom RCPs. AWS attaches the default `RCPFullAWSAccess` policy for you, which is what allows everything until you deny something. |
| Principal | Must be `"*"`. To target particular callers, use condition keys such as `aws:PrincipalOrgID`. |
| Action | Only actions of supported services take effect. Use the service prefix, for example `s3:*`. |
| Resource | `"*"` or specific resource ARNs. |
| Condition | Supported. Most real RCPs depend on it. |
| Size | A limit applies to the document (5,120 characters at the time of writing, whitespace included). Check the current quotas. |
Because Principal is always *, the Condition block decides who is affected. A deny with no condition blocks everyone, including your own administrators.
Create and attach an RCP
The workflow matches SCPs. You create the policy with the type RESOURCE_CONTROL_POLICY, then attach it to the root, an OU, or an account. Start with a test OU.
aws organizations create-policy \
--name EnforceTLSOnS3 \
--description "Deny S3 requests that do not use TLS" \
--type RESOURCE_CONTROL_POLICY \
--content file://enforce-tls-s3.json
aws organizations attach-policy \
--policy-id p-examplepolicyid \
--target-id ou-exam-ple12345Inheritance works as it does for SCPs. A resource in an account is subject to the RCPs attached to the root, to every OU above the account, and to the account itself. A request must be allowed at every level, and any explicit deny at any level wins.
Example 1: require TLS on S3
This is a good first RCP because it is simple and rarely breaks legitimate traffic.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceTLSOnS3",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"BoolIfExists": {
"aws:SecureTransport": "false"
}
}
}
]
}The condition key aws:SecureTransport is false when a request uses plain HTTP. The IfExists suffix means that a request missing the key is also treated as a match for the condition. Without it, a request with no aws:SecureTransport value would skip the condition and the deny would not apply.
The effect is stronger than a bucket policy. A bucket owner can write a bucket policy with the same deny, but they can also delete it. With the RCP attached at the organization level, no one in a member account can remove the guardrail.
Example 2: an identity perimeter for S3
The second policy keeps S3 data from being read by principals outside your organization.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyNonOrgPrincipalsOnS3",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringNotEqualsIfExists": {
"aws:PrincipalOrgID": "o-exampleorgid"
},
"BoolIfExists": {
"aws:PrincipalIsAWSService": "false"
}
}
}
]
}Conditions in one block are combined with AND, so the deny applies only when both are true:
- The caller's
aws:PrincipalOrgIDis noto-exampleorgid, or the key is missing (an anonymous request has no organization). - The caller is not an AWS service.
aws:PrincipalIsAWSServiceistruewhen a service principal such as CloudTrail or S3 log delivery makes the call.
The second condition exists so that AWS services acting on your data, such as log delivery, keep working. Without it, the policy would block them because a service principal has no organization ID.
"RCP does not deny" does not mean "allowed." The request still needs an Allow from an identity-based or resource-based policy.
Add exceptions for approved third parties
Some outside access is legitimate: a vendor role that reads a bucket, or a partner account. The perimeter policy would block it, so add the approved accounts to the condition.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyNonOrgPrincipalsExceptApproved",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringNotEqualsIfExists": {
"aws:PrincipalOrgID": "o-exampleorgid",
"aws:PrincipalAccount": ["111122223333"]
},
"BoolIfExists": {
"aws:PrincipalIsAWSService": "false"
}
}
}
]
}The deny now applies only if the caller is outside the organization, is not account 111122223333, and is not an AWS service. Keep the list of approved accounts small and review it on a schedule. Each entry is a hole in the perimeter.
Check which services an RCP supports
An RCP only restricts actions of services that support RCPs. If you write "Action": "ec2:*" and EC2 is not supported, the policy attaches without error and does nothing. The tooling will not warn you.
At launch, the supported services were Amazon S3, AWS STS, AWS KMS, Amazon SQS, and AWS Secrets Manager. AWS has added more since, so treat that list as a starting point. To check:
- Open the "Resource control policies" page in the AWS Organizations user guide and read the list of services that support RCPs.
- Check that your actions are covered. Support is defined by service and, in some cases, by resource type, so read the notes under each service.
- Record the date you checked and the services you rely on, so you can recheck when the list changes.
What RCPs do not cover
- Resources in the management account. Like SCPs, RCPs do not restrict the management account's own resources. Keep sensitive workloads out of that account.
- Service-linked roles. Calls made by service-linked roles are not restricted by RCPs.
- Unsupported services. See the previous section.
- Principals. An RCP cannot stop an IAM user in your account from calling an API on a resource in another account that the other account's RCPs do not cover. Use an SCP for that direction.
Common mistakes
- Missing
IfExists. A deny based on a key that may be absent can silently fail to match. Check that each key is present in the requests you want to cover. - Forgetting AWS services. Perimeter denies without
aws:PrincipalIsAWSServicebreak log delivery, replication, and similar features. - Writing
Principalas a specific ARN. RCPs require"*". Express the restriction with conditions. - Attaching to the root first. A mistake then affects every member account. Attach to a test OU, watch CloudTrail for
AccessDeniedevents, and then widen.
Exercise
You attach an RCP that denies ec2:* for principals outside your organization. It attaches successfully, but an outside account can still call EC2 APIs against your resources. What is the most likely reason, and how do you confirm it?
Show answer
EC2 is probably not a service that supports RCPs, so the policy has no effect on it. Attachment succeeds regardless. Confirm by checking the list of RCP-supported services in the AWS Organizations documentation. If the service is not listed, use another control, such as an SCP on your own principals or resource-level controls.
Exercise
In the identity perimeter RCP, why does the deny not block CloudTrail from writing logs to a bucket in a member account?
Show answer
CloudTrail is an AWS service principal, so aws:PrincipalIsAWSService is true. The BoolIfExists condition for false does not match, and the deny only applies when both conditions match. The request still needs an Allow in the bucket policy.