Sub topic 10
Writing RCPs and checking supported services
This chapter assumes you can read IAM policy JSON, have enabled the RCP policy type on your root, and know how SCPs inherit down the organization tree. Here you will write RCPs, create and attach them with the CLI, and check which services they cover.
What an RCP statement looks like
An RCP is an IAM-style JSON document, but with tighter rules than an SCP:
- Use
"Effect": "Deny"for the controls you write. The only Allow statement is the defaultRCPFullAWSAccesspolicy, which AWS attaches when you enable RCPs. Leave it attached, because removing it blocks all access to supported resources. - Set
"Principal": "*". An RCP restricts who can reach a resource, and you narrow the scope with conditions, not by naming principals. - Put the restriction in
Condition. Condition keys such asaws:SecureTransport,aws:PrincipalOrgID, andaws:PrincipalIsAWSServicedo most of the work.
An RCP never grants access. A request still needs an Allow from an identity-based or resource-based policy.
Example 1: require TLS on S3
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceTLSOnS3",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"BoolIfExists": {
"aws:SecureTransport": "false"
}
}
}
]
}BoolIfExists makes the deny apply when the key is false and also when the key is missing from the request context. The statement therefore fails closed. No bucket policy in any member account can override this deny.
Example 2: an identity perimeter for S3
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyNonOrgPrincipalsOnS3",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringNotEqualsIfExists": {
"aws:PrincipalOrgID": "o-exampleorgid"
},
"BoolIfExists": {
"aws:PrincipalIsAWSService": "false"
}
}
}
]
}A Deny applies only when every condition in the statement is true. This request is denied when the principal is not in your organization and the caller is not an AWS service. Anonymous requests have no aws:PrincipalOrgID, so IfExists makes the first condition true and they are denied too.
Create and attach an RCP
The workflow matches SCPs. Only the policy type differs.
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-ple12345Attach to a test OU first. RCPs inherit down the tree like SCPs and apply to resources in the target's accounts.
Check supported services before you rely on an RCP
RCPs only take effect for a fixed list of services. Examples include Amazon S3, AWS STS, AWS KMS, Amazon SQS, and AWS Secrets Manager, and AWS has added services over time. For any other service, an RCP is silently ignored, which can leave a false sense of coverage.
Before you write a control:
- Open "Resource control policies" in the AWS Organizations user guide and find the supported-services list.
- Confirm the service and the actions you deny are on that list.
- If they are not, use another control, such as a resource-based policy, an SCP, or a permission boundary.
Remember also that RCPs do not apply to resources in the management account. They do not apply to calls made by service-linked roles.
Exercise
You attach an RCP that denies dynamodb:* unless aws:SecureTransport is true, but the service you chose is not on the RCP supported list. Does the control work, and what should you do?
Show answer
No. RCPs are ignored for unsupported services, so the request is not denied. Check the supported-services list first, then enforce the control another way, for example with a resource-based policy on each resource, or with an SCP if the goal is to restrict your own principals.