Time: ~2 hours · Difficulty: Intermediate · You need: a terminal; a Rust toolchain for the Cedar half; AWS CLI credentials for any AWS account to run the Access Analyzer checks (no organization needed, and nothing is created)
How this page was checked: a script extracted every code block on this page, including the exercise answers, and ran it as printed on 4 November 2026, each shell block in a fresh interactive zsh on an Apple silicon Mac; every output shown is pasted from that run, and a planted error made the same script fail. The AWS commands ran with AWS CLI 2.39.2 and jq 1.8.2 against an account that is not in an organization. Every policy on the page, with single statements wrapped in a policy document, went through IAM Access Analyzer's validate-policy (the resource control policies with the RCP policy type), and check-no-new-access compared the step 1 policy with a copy granting one more action. simulate-principal-policy, run as printed, was refused because the placeholder ARN in step 4 names another account, so it was also run against a role in the test account. The Cedar half ran with cedar-policy-cli 4.14.1, installed by the cargo install line. No RCP was attached, because that needs an organization: what an attached RCP does, including the services it covers, what it never applies to and which requests it denies, was checked against AWS's Organizations, IAM and Access Analyzer documentation and AWS's published example policies on 4 November 2026.
Slides: download the PDF or make your own editable copy (copying needs a Google account). The slides are licensed CC BY-NC 4.0.
Reading a policy correctly is its own skill
An IAM (Identity and Access Management) policy is a JSON document that says who may do what to which AWS resources: this role may read objects in that bucket, that user may not delete anything. Almost everyone in cloud security reads IAM policies, to review a change, to investigate an incident, or to answer a question such as "can this role read the customer-data bucket?", and most people are worse at it than they believe.
Reading the JSON is the easy part. What trips people up is that the JSON is only half the input. Whether a request succeeds depends on several policy types evaluated together in a fixed order, and a document that plainly says "Effect": "Allow" may grant nothing at all, because other policies can cap or deny it.
Two languages are worth real study, and this page teaches both. The first is the AWS IAM policy grammar: what a policy document may contain, and what each part means. It is unavoidable, it carries fifteen years of accumulated design decisions (IAM reached general availability in May 2011), and it is full of elements that do the opposite of what they appear to. The walk-through also covers resource control policies (RCPs), a newer kind of AWS policy written in the same grammar.
The second is Cedar, AWS's open-source authorization language, released under Apache 2.0 in 2023. Authorization means deciding whether a request is allowed. Cedar is the engine behind Amazon Verified Permissions, an AWS service that makes those decisions for your own applications, and it is increasingly the way application-level authorization gets written: the checks inside an application, such as whether a user may open a given document. It is what IAM might look like designed once, deliberately, with a type checker: a tool that compares a policy with a description of your data and rejects it, before it ever runs, if it names something that is not there.
Learning them together is worth more than learning either alone, because Cedar makes explicit several things IAM leaves implicit, and once you have seen the explicit version the implicit one stops surprising you.
On this page
How to use this guide
This guide is marked intermediate. It assumes you know what IAM users, roles and policies are, have read a JSON policy document before, and have run the AWS CLI (command-line interface) with credentials set up. The resource control policy part also assumes you know that AWS Organizations runs many AWS accounts together under one management account. If any of that is new, the site's IAM and cloud identity guide covers the kinds of identity, and its AWS security guide shows how an organization's accounts are laid out. Cedar is taught from the start.
Read the next section first. It explains how AWS combines the policies that apply to a request, and ends with six questions to ask of any policy statement. The walk-through then comes in three parts. In the AWS IAM part, steps 1 to 3 show short policies to read and explain the pieces that behave differently from how they look, and step 4 runs AWS's own policy-checking tools from the AWS CLI. In the resource control policy part, step 5 compares RCPs with SCPs and checks whether your account is in an organization, and steps 6 and 7 save policies as files and run AWS's validator on them; that works in any account, organization or not, because the validator reads only the policy text you send. In the Cedar part, steps 8 to 10 install Cedar and write, check and test a small policy set. The Cedar part needs no AWS account and does not depend on the AWS parts, so you can do it on its own. The exercises mix both languages, with each answer hidden until you open Show the answer.
Each input block has a label at the top, and every block has a copy button. A block labelled JSON is a policy document, or one statement from one: read it, and save it as a file when the text says to, under the name it gives. A block labelled CEDAR is a Cedar file to save in the ~/cedar-lab folder that step 8 creates; its first line, a comment starting //, gives the file name. A block labelled BASH holds commands to paste into your terminal, from the folder that holds the files they name. An unlabelled block is output: what the command before it should print. Step 10 starts with cat > entities.json <<'EOF', which writes every line down to the one that says only EOF into a file called entities.json; paste that whole block at once, the EOF line included.
Your output should match the page. Every block was run as printed on 4 November 2026, with AWS CLI 2.39.2, jq 1.8.2 and cedar-policy-cli 4.14.1, against an AWS account that is not in an organization, and every output shown is pasted from that run. A few things will differ for you. In step 4, simulate-principal-policy names a placeholder role in another account, so AWS refuses it as printed; put the ARN (Amazon Resource Name) of a role in your own account in its place. Step 4's last command compares two files, old.json and new.json, that you make yourself; the page was checked with the step 1 policy and a copy granting one more action. In step 5, describe-organization prints your management account's ID and feature set instead of an error if your account is in an organization. No RCP was attached for this page, because that needs an organization, so what an attached RCP does comes from AWS's documentation and published examples, not from a run. AWS's list of the services RCPs cover also grows, and exercise 5's error depends on what is on it.
If a result differs from the page, check that you are in the folder that holds the files the command names (~/cedar-lab for the Cedar steps), that you saved each file under the name the page gives, and that your versions match the ones above.
How AWS decides whether a request is allowed
Suppose someone asks whether a role can delete objects in a bucket. You open the role's policy, and it allows s3:*, every action in S3 (Simple Storage Service, AWS's storage for files and data). Many people stop there and answer yes, and the answer can still be no, because other policies also apply to that request. To answer correctly you need to know which policies those are and how AWS combines them.
Access is usually granted in one of two places. An identity policy is attached to a user or role, the principal making the request. A resource policy is attached to the thing being accessed, such as a bucket policy on an S3 bucket. Other kinds only set a ceiling. An organization in AWS Organizations can attach resource control policies (RCPs) and service control policies (SCPs) to its accounts; a user or role can have a permissions boundary, a cap attached to it; and a temporary session can be given a session policy, a cap passed in when the session starts.
AWS does not ask "does a policy allow this". It runs a fixed evaluation across every policy type that applies:
- An explicit
Denyanywhere ends it. In any policy, of any type, at any level. Nothing overrides it. - Every applicable guardrail must allow. AWS checks resource control policies (RCPs) first, then service control policies (SCPs), and checks permissions boundaries and session policies after the grants. Each acts as a ceiling. They do not grant anything; they cap what can be granted.
- Something must grant it. Within one account, an allow in either the identity policy or the resource policy is generally enough. Across accounts, both sides must allow independently.
- Otherwise, implicit deny. Nothing is permitted by default.
Read that as an intersection, not a union. The effective permission is what survives every layer, and adding a policy can only ever remove access or leave it unchanged, never add access past a ceiling above it.
The two organization ceilings face opposite ways. An SCP follows the principal: it caps what users and roles in the member accounts under it can do. An RCP follows the resource: it caps what anyone, inside the organization or outside it, can do to resources in the member accounts under it. On a cross-account request the caller's SCPs and the resource owner's RCPs both apply. The RCP walk-through covers what an RCP can and cannot say.
So "the policy says Allow" is not an answer to "can they do it". An AdministratorAccess policy attached to a role inside an organizational unit whose SCP denies everything outside eu-west-1 grants exactly nothing outside eu-west-1. Reading one document tells you an upper bound on that document's contribution, and nothing about the result.
The six questions
For any statement, answer these in order. It sounds mechanical because it is, and doing it mechanically is how you stop being fooled.
- Effect: Allow or Deny? Deny changes everything that follows.
- Principal: who? Absent means the policy is identity-based and the principal is whoever it is attached to.
- Action: which operations, and is it
ActionorNotAction? (Step 2) - Resource: which objects, and is it
ResourceorNotResource? - Condition: under what circumstances, and what happens when a key is missing? (Step 3)
- What type of policy is this, and therefore is it a grant or a ceiling?
Question six is the one people skip, and it is the one that most often makes the other five irrelevant. Exercise 1 is built around it.
Walk-through: AWS IAM
1. The grammar, and the parts that invert
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadOwnBucketPrefix",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::acme-data/${aws:PrincipalTag/team}/*",
"Condition": {
"Bool": { "aws:SecureTransport": "true" },
"StringEquals": { "aws:PrincipalOrgID": "o-abc123" }
}
}
]
}Three things in that small document are worth naming.
${aws:PrincipalTag/team} is a policy variable, substituted at evaluation time. One statement covering every team is far better than fifty near-identical policies, and it is the standard way to do attribute-based access control on AWS. Note that only single-valued context keys can be used as variables. Context keys are the facts AWS attaches to each request, such as the caller's tags or organization, and they are what a Condition tests.
aws:PrincipalOrgID is the modern answer to the confused-deputy problem: the caller must belong to your organization, whoever they claim to be. Its siblings aws:SourceArn and aws:SourceAccount do the same job for service principals, the identities AWS services use when they act on your behalf, and their absence is exactly what made a long list of cross-tenant vulnerabilities possible.
Wildcards are not regular expressions. Only * (any sequence) and ? (any single character) exist. s3:Get* is fine; s3:Get.* matches nothing, and [a-z] is a literal bracket expression that will never match an action name.
2. NotAction, and why it is almost always wrong
{
"Effect": "Allow",
"NotAction": "iam:*",
"Resource": "*"
}Read that carefully. It does not deny IAM. It allows every action in AWS except IAM, on every resource. That includes services launched after the policy was written, which is the part that makes it unmanageable: the blast radius grows every time AWS ships something.
NotAction has one defensible use, in a Deny statement expressing "deny everything except this narrow set", which is how the standard region-restriction SCP is written:
{
"Effect": "Deny",
"NotAction": ["iam:*", "organizations:*", "sts:*", "cloudfront:*",
"route53:*", "support:*", "waf:*"],
"Resource": "*",
"Condition": {
"StringNotEquals": { "aws:RequestedRegion": ["eu-west-1", "eu-central-1"] }
}
}The exception list exists because those services are global and live in us-east-1; deny them by region and you lock yourself out of IAM. That list is also the thing people copy without updating, so treat any inherited version of this SCP as needing review rather than as settled.
NotPrincipal is worse still and the AWS documentation itself steers you away from it. If you find one, treat it as a finding.
3. Conditions, and the two set operators that fail open
Multi-valued condition keys need a set operator, and the two available behave differently in the case that matters: the key not being present at all.
ForAllValuesis true when every value in the request matches something in the policy. It is also true when there are no values in the request at all.ForAnyValueis true when at least one value matches. It is false when the key is absent.
So ForAllValues in an Allow fails open. The AWS documentation carries an explicit warning on this and prescribes the fix: pair it with a Null check so the statement requires the key to be present.
{
"Effect": "Allow",
"Action": "ec2:DeleteTags",
"Resource": "arn:aws:ec2:us-east-1:111122223333:instance/*",
"Condition": {
"ForAllValues:StringEquals": {
"aws:TagKeys": ["environment", "cost-center"]
},
"Null": { "aws:TagKeys": "false" }
}
}Without that Null block, a request carrying no tag keys satisfies the condition and is allowed. With it, the same request is a no-match. One line, and it is the difference between a working restriction and a decorative one.
The related trap is the ...IfExists suffix: StringEqualsIfExists means "if the key is present it must match, and if it is absent that is fine". Deliberately permissive, occasionally correct, and frequently pasted in to make a policy stop blocking something without anyone noticing what it now permits.
4. Test it rather than reasoning about it
Given how many layers combine, reading is not verification. AWS has three tools that answer different questions, and all three are underused.
The first checks grammar, best practice and security warnings on a single document. It reads only the policy text you send and looks at nothing in your account. Start here: save the step 1 policy as policy.json and run:
aws accessanalyzer validate-policy \ --policy-type IDENTITY_POLICY \ --policy-document file://policy.json
The second asks whether one specific principal may do one specific thing, evaluating the identity policies attached to it, its permissions boundary and the SCPs above its account. It does not evaluate RCPs, so a deny that comes from an RCP will not show up in its answer.
aws iam simulate-principal-policy \ --policy-source-arn arn:aws:iam::111122223333:role/app \ --action-names s3:GetObject \ --resource-arns arn:aws:s3:::acme-data/reports/q3.csv
The third asks whether a new version of a policy grants anything the old one did not, which makes it a CI gate: fail the pipeline if a change broadens access.
aws accessanalyzer check-no-new-access \ --existing-policy-document file://old.json \ --new-policy-document file://new.json \ --policy-type IDENTITY_POLICY
check-no-new-access is the one worth building a habit around. It answers a comparative question that no amount of reading reliably answers, and it turns "this refactor is equivalent, trust me" into something a pipeline can confirm. Its siblings check-access-not-granted and check-no-public-access cover "this policy must never grant these actions" and "this resource policy must not be public". These three are what AWS calls custom policy checks, and they are not free: on 20 November 2026 the IAM Access Analyzer pricing page listed them at $0.002 per check (each API call) with no free allowance, while validate-policy comes at no additional charge.
Walk-through: resource control policies
A resource control policy (RCP) is an AWS Organizations policy type, launched in November 2024, that caps what can be done to resources in the member accounts under it, whoever makes the request, root users included. That reaches principals from other organizations, which an SCP cannot, because an SCP only constrains principals in your own member accounts. Like an SCP, an RCP grants nothing.
An RCP can leave a gap, or break something, without an error. Three cases, each checked for this page:
- It covers only the services on AWS's list, and within them only actions that act on a resource.
validate-policyreportsec2:*as an error but passess3:ListAllMyBuckets, an action with no resource for the RCP to apply to (step 5). - It never applies to resources in the management account, even when it is attached to the organization root (step 5).
- A perimeter that denies callers from outside your organization also denies AWS services that write to your buckets, unless it exempts them.
validate-policyreports the missing exception as a warning, not an error (step 6).
5. What an RCP can say, next to an SCP
The grammar is IAM's, with tighter rules. From AWS's RCP syntax and quota pages:
| Element or limit | SCP | RCP |
|---|---|---|
| Caps | users and roles in member accounts | resources in member accounts, whoever calls |
Effect | Allow or Deny | Deny; Allow appears only in RCPFullAWSAccess |
Principal | not supported | required, and only "*" |
Action | any service; NotAction allowed | listed services only, and never "*" alone in an RCP you write; no NotAction |
Resource, NotResource, Condition | supported | supported |
| Maximum size | 10,240 characters | 5,120 characters |
| Attached per root, organizational unit (OU) or account | up to 10 | up to 5, counting RCPFullAWSAccess |
| Never applies to | users and roles in the management account; service-linked roles | resources in the management account; service-linked roles; AWS managed keys in Key Management Service (KMS) |
Because the principal is always "*", who a statement is about goes in its conditions, with keys such as aws:PrincipalOrgID, aws:PrincipalAccount and aws:PrincipalIsAWSService. And because you can only deny, every RCP you write subtracts from RCPFullAWSAccess, the AWS managed policy that Organizations attaches to the root, every OU and every account when you enable RCPs. You cannot detach it. It grants nothing; it lets every request through RCP evaluation so that your other policies decide:
{
"Version": "2012-10-17",
"Statement": [
{ "Effect": "Allow", "Principal": "*", "Action": "*", "Resource": "*" }
]
}At launch RCPs covered five services: Amazon S3 (Simple Storage Service), AWS Security Token Service (STS), AWS KMS, Amazon Simple Queue Service (SQS) and AWS Secrets Manager. AWS's list named 62 service prefixes on 4 November 2026, including Amazon DynamoDB, Amazon Elastic Container Registry, Amazon CloudWatch Logs and Amazon Cognito. Amazon Simple Notification Service (SNS), AWS Lambda, Amazon API Gateway and Amazon Elastic Compute Cloud (EC2) are not on it, so no RCP protects an SNS topic or a Lambda function; AWS's data-perimeter examples cover SNS topics and API Gateway APIs with resource-based policies instead. The list grows, so check it rather than a copy of it.
Naming a service that is not on the list is an error to validate-policy run with the RCP policy type (exercise 5 shows the output): an ERROR finding, RCP_SYNTAX_ERROR_ACTION, and AWS defines errors as lines that prevent the policy from functioning. Whether Organizations would also refuse to save such a policy was not tested for this page, because that needs an organization, so treat the validator as your gate. The quieter case passes it. s3:ListAllMyBuckets has no resource type in AWS's Service Authorization Reference, and an RCP applies through the resource a request authorizes, so a statement denying it validates with no findings and has nothing to apply to.
Two more exemptions belong in that last row. RCPs do not restrict kms:RetireGrant, and an RCP never reaches resources in accounts outside its organization, even when your own principals are the ones calling. The management account exemption is the one to plan around: an RCP attached to the organization root covers every member account, delegated administrators included, and leaves the management account's buckets, keys and queues to their own policies. To see which account that is:
aws organizations describe-organization \ --query 'Organization.[MasterAccountId,FeatureSet]' --output text
In an organization this prints the management account's ID and the feature set; RCPs are available only when that is ALL. Outside one, as for the account used to check this page, it prints this instead, and no RCP applies to that account at all:
aws: [ERROR]: An error occurred (AWSOrganizationsNotInUseException) when calling the DescribeOrganization operation: Your account is not a member of an organization.
6. A data perimeter on S3
This is the identity-perimeter statement from AWS's data-perimeter examples, cut down to S3 without its exception lists, and given a made-up organization ID. Save it as rcp-perimeter.json:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceOrgIdentities",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringNotEqualsIfExists": { "aws:PrincipalOrgID": "o-exampleorgid" },
"BoolIfExists": { "aws:PrincipalIsAWSService": "false" }
}
}
]
}Run the six questions over it. It denies every principal every S3 action on every resource in the accounts under it, but only when both conditions hold, because separate conditions are joined with a logical AND: the caller is not in your organization, and the caller is not an AWS service principal. Both operators end in IfExists, which makes a missing key count as a match, and here that is deliberate. A principal that belongs to no organization carries no aws:PrincipalOrgID, and an anonymous request carries neither key, so both are denied, and a bucket that serves the public cannot sit under this RCP. Validate it with the RCP policy type:
aws accessanalyzer validate-policy \
--policy-type RESOURCE_CONTROL_POLICY \
--policy-document file://rcp-perimeter.json \
--query 'findings[].{type:findingType,code:issueCode}'[]
No findings. Now remove the exception and validate the result:
jq 'del(.Statement[0].Condition.BoolIfExists)' rcp-perimeter.json > rcp-trimmed.json
aws accessanalyzer validate-policy \
--policy-type RESOURCE_CONTROL_POLICY \
--policy-document file://rcp-trimmed.json \
--query 'findings[].{type:findingType,code:issueCode}'[
{
"type": "WARNING",
"code": "RCP_MISSING_RELATED_PRINCIPAL_CONDITION_KEY"
}
]A warning, on a policy that is otherwise valid. Attached, it denies AWS services that act on your resources with their own service principal, because a service principal does not belong to your organization. AWS's own example of such a call is CloudTrail writing logs to a bucket as cloudtrail.amazonaws.com. Make your pipeline fail on this warning, not only on errors. The same statement also shuts out a partner account you share a bucket with, whatever the bucket policy says; AWS's full example lists such accounts under aws:PrincipalAccount in the same StringNotEqualsIfExists block.
7. Confused-deputy protection with aws:SourceOrgID
The exception in step 6 lets every AWS service principal through, whoever it is working for. A service acting on your bucket on behalf of someone else's resource is the confused-deputy problem from step 1, and AWS's RCP examples include a statement for it. Save it as rcp-deputy.json:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceConfusedDeputyProtection",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringNotEqualsIfExists": { "aws:SourceOrgID": "o-exampleorgid" },
"Null": { "aws:SourceAccount": "false" },
"Bool": { "aws:PrincipalIsAWSService": "true" }
}
}
]
}All three conditions must hold for the deny: the caller is a service principal, the request carries aws:SourceAccount (that is what the Null check tests), and aws:SourceOrgID, the organization of the resource the service is acting for, is not yours or is missing. The Null check limits the deny to requests that carry aws:SourceAccount, so service integrations that do not use the source keys keep working; AWS's notes give Elastic Load Balancing access logs in some Regions, services that use KMS grants, and services that assume your service roles as examples.
aws accessanalyzer validate-policy \
--policy-type RESOURCE_CONTROL_POLICY \
--policy-document file://rcp-deputy.json \
--query 'findings[].{type:findingType,code:issueCode}'[]
Delete the Null block and validate-policy warns RCP_MISSING_SERVICE_CONDITION_KEY_NULL_CHECK; delete the Bool block instead and it warns RCP_MISSING_RELATED_SERVICE_PRINCIPAL_CONDITION_KEY. Both statements fit in one RCP, which matters because a root, OU or account takes at most five RCPs and RCPFullAWSAccess is one of them. AWS's identity_perimeter_rcp.json carries both statements across STS, KMS, SQS, Secrets Manager and more, plus statements for OpenID Connect (OIDC) federation. Before attaching anything, AWS recommends starting on a test account and reading CloudTrail for access-denied errors. The policy simulator cannot help here, because it does not evaluate RCPs.
Walk-through: Cedar
8. Install it and write a policy set
cargo install cedar-policy-cli cedar --version mkdir -p ~/cedar-lab && cd ~/cedar-lab
Cedar's shape will look familiar, and the differences are the interesting part:
// policies.cedar
// Members of the security group may read any bucket, but only with MFA.
permit (
principal in Group::"security",
action == Action::"read",
resource
)
when { context.mfa == true };
// A forbid always wins, whatever any permit says. Same rule as an
// explicit Deny in IAM, and stated in the language rather than in a
// separate document describing how the language is evaluated.
forbid (
principal,
action,
resource
)
when { resource.public == true };Three structural choices to notice. The head is always principal, action, resource, so every policy is scoped the same way and can be indexed. in walks an entity hierarchy, so group membership is a first-class relation rather than something you fake with tags. And forbid beating permit is a property of the language, not of the service evaluating it.
9. The part IAM cannot do: a schema
// store.cedarschema
entity Group;
entity User in [Group];
entity Bucket = {
"public": Bool,
};
action read, write appliesTo {
principal: [User],
resource: [Bucket],
context: { "mfa": Bool }
};cedar validate --schema store.cedarschema --policies policies.cedar
☞ policy set validation passed ╰─▶ no errors or warnings
Now introduce a typo. Change resource.public to resource.publik and validate again:
× policy set validation failed
╰─▶ for policy `policy1`, attribute `publik` on entity type `Bucket` not
found
╭─[18:8]
17 │ )
18 │ when { resource.publik == true };
· ───────────────
╰────
help: did you mean `public`?This is the most important difference between the two languages. The same typo in an IAM condition key produces a perfectly valid policy that simply never matches. No error at write time, no error at evaluation time, no signal of any kind. A Deny statement with a misspelled condition key is a security control that does not exist, and it looks exactly like one that does.
Change resource.publik back to resource.public before step 10, which reads the same policies.cedar, and run the cedar validate line again to see it pass.
10. Evaluate real requests
An entities file describes the world: who exists, what they belong to, and what attributes each resource has. Each request also needs a context, here just whether MFA was used:
cat > entities.json <<'EOF'
[
{"uid": {"type":"Group","id":"security"}, "attrs": {}, "parents": []},
{"uid": {"type":"User","id":"alice"}, "attrs": {},
"parents": [{"type":"Group","id":"security"}]},
{"uid": {"type":"User","id":"bob"}, "attrs": {}, "parents": []},
{"uid": {"type":"Bucket","id":"private-logs"}, "attrs": {"public": false}, "parents": []},
{"uid": {"type":"Bucket","id":"public-site"}, "attrs": {"public": true}, "parents": []}
]
EOF
echo '{"mfa": true}' > ctx_mfa.json
echo '{"mfa": false}' > ctx_nomfa.jsonAlice is a member of Group::"security", has MFA and asks for a private bucket, so this prints ALLOW:
cedar authorize --schema store.cedarschema --policies policies.cedar \ --entities entities.json -c ctx_mfa.json \ -l 'User::"alice"' -a 'Action::"read"' -r 'Bucket::"private-logs"'
Then change one thing at a time. With -c ctx_nomfa.json it prints DENY. With MFA but -r 'Bucket::"public-site"' it prints DENY, because the forbid wins. With -l 'User::"bob"', who is not in the group, it prints DENY.
Run all four. cedar authorize exits 0 on ALLOW and non-zero on DENY, so a shell script can assert an expected decision, which means your authorization rules can have a test suite. Writing those four cases takes two minutes and is the closest thing to a unit test that authorization logic normally gets.
Amazon Verified Permissions is this engine as a managed service; AWS's documentation says it currently uses Cedar 4.12. You do not need the service to use the language: the engine is a library, and running it in-process is a perfectly normal deployment.
Hands-on exercises
A role has this identity policy attached. The account is in an OU whose SCP denies all actions outside eu-west-1. The role also has a permissions boundary allowing only s3:*. What can this role do?
{ "Effect": "Allow", "Action": "*", "Resource": "*" }Show the answer
Every S3 action, in eu-west-1 only. Nothing else.
Work the intersection rather than the documents. The identity policy grants everything, so it constrains nothing. The permissions boundary caps the role at s3:*. The SCP caps the whole account at one region. The result is the overlap: s3:* in eu-west-1.
Two things worth carrying away. An administrator-level identity policy told you nothing useful, which is exactly why "the policy says Allow" is not an answer. And the boundary and the SCP are doing all the real work while being attached somewhere else entirely, so anyone reading only the role's inline policy would get this completely wrong.
One caveat to keep honest: global services such as IAM and CloudFront do not sit in eu-west-1, so a region-restricting SCP written without an exception list breaks them. The SCP in step 2 carries one for that reason.
This statement was written to force MFA. Explain precisely how a request without MFA gets through, and fix it.
{
"Effect": "Deny",
"Action": "*",
"Resource": "*",
"Condition": {
"BoolIfExists": { "aws:MultiFactorAuthPresent": "false" }
}
}Show the answer
This one is subtle, and the naive fix is wrong.
aws:MultiFactorAuthPresent is not present at all for requests made with long-term IAM user access keys. It is only populated for temporary credentials. So with a plain Bool, the condition is a no-match for exactly the credential type you were most worried about, and the deny never fires.
BoolIfExists is therefore correct here, not the bug: it makes the deny apply when the key is absent as well as when it is false. That is the standard AWS-documented pattern for an MFA-enforcement deny.
The real problem is "Action": "*". Denying everything without MFA also denies the calls a user needs to set up and use MFA, locking them out of self-service. The working version carves those out:
{
"Effect": "Deny",
"NotAction": [
"iam:CreateVirtualMFADevice", "iam:EnableMFADevice",
"iam:ResyncMFADevice", "iam:ListMFADevices",
"iam:ListVirtualMFADevices", "iam:GetUser",
"sts:GetSessionToken", "iam:ChangePassword"
],
"Resource": "*",
"Condition": {
"BoolIfExists": { "aws:MultiFactorAuthPresent": "false" }
}
}Note that this is the defensible use of NotAction from step 2: inside a Deny, expressing "everything except this narrow list".
The general lesson is the one worth keeping: a condition key that is absent is not the same as a condition key that is false, and which of those you get depends on how the request was authenticated rather than on anything in the policy.
Add a Cedar policy letting any user read a bucket they own, then extend the schema so it validates. What did the schema force you to decide that IAM would have let you leave vague?
Show the answer
// store.cedarschema - Bucket gains an owner
entity Bucket = {
"public": Bool,
"owner": User,
};
// policies.cedar
permit (principal, action == Action::"read", resource)
when { resource.owner == principal };The schema forced you to declare that owner is of type User, and that every Bucket has one. Both are real decisions with real consequences, and both are the kind of thing an IAM policy leaves implicit until an edge case surfaces them in production.
Make it optional with "owner"?: User and Cedar will then refuse to let you write resource.owner == principal without a presence check first, in the same way CEL demands has(). The type checker is not being fussy; unowned buckets are a case that exists, and it is asking which way you want them to fall.
Do not forget the entities file. Adding a required attribute to the schema means every existing Bucket entity needs an owner, and cedar authorize will tell you so.
You are refactoring a 400-line IAM policy into three smaller ones and want to prove you have not widened access. How do you get evidence rather than an opinion?
Show the answer
aws accessanalyzer check-no-new-access \ --existing-policy-document file://old.json \ --new-policy-document file://new.json \ --policy-type IDENTITY_POLICY
This compares the two documents semantically rather than textually, and reports whether the new one permits anything the old one did not. Wire it into CI and a pull request that broadens access fails, whatever the diff looks like.
Two things to be careful about. It compares documents, so splitting one policy into three means checking the union, not each part. And it answers only "is anything new allowed": a refactor that accidentally removes needed access passes cleanly, which is an outage rather than a breach but is still your problem. Pair it with simulate-principal-policy over the actions that must keep working.
This is the same shape as the deny-direction-only testing trap in the Rego page: a check that can only fail one way is half a check.
A colleague plans to attach this RCP to the organization root to keep principals from outside the organization away from S3, SNS and Lambda. Find three problems before it ships, and say which of them validate-policy catches.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "KeepOutsidersOut",
"Effect": "Deny",
"Principal": "*",
"Action": ["s3:*", "sns:*", "lambda:*"],
"Resource": "*",
"Condition": {
"StringNotEqualsIfExists": { "aws:PrincipalOrgID": "o-exampleorgid" }
}
}
]
}Show the answer
Save it as rcp-exercise.json and validate it as an RCP:
aws accessanalyzer validate-policy \
--policy-type RESOURCE_CONTROL_POLICY \
--policy-document file://rcp-exercise.json \
--query 'findings[].{type:findingType,code:issueCode}'[
{
"type": "ERROR",
"code": "RCP_SYNTAX_ERROR_ACTION"
},
{
"type": "WARNING",
"code": "RCP_MISSING_RELATED_PRINCIPAL_CONDITION_KEY"
}
]The error is the first problem: SNS and Lambda are not on AWS's list of services RCPs apply to, so the policy cannot protect them. Drop those prefixes and protect those resources another way, such as SNS topic policies, for which AWS's data-perimeter examples include a perimeter statement.
The warning is the second: with no aws:PrincipalIsAWSService exception, the deny also catches AWS services writing to your buckets with their service principals, CloudTrail log delivery among them. Add "BoolIfExists": { "aws:PrincipalIsAWSService": "false" } to the condition, as in step 6.
The third problem no validator reports. Attached at the root, the RCP covers every member account and none of the management account's resources, so any bucket kept there stays outside the perimeter. The fix is in how the organization is laid out: keep data you need inside the perimeter out of the management account.
Common mistakes
- Reading one policy and concluding what a principal can do. The answer is the intersection of every applicable layer, minus every explicit deny.
NotActionwithAllow. It grants every future AWS service too. Defensible only inside aDeny.ForAllValuesin anAllowwithout aNullcheck. Documented by AWS as overly permissive, because a request with no values satisfies it.- Assuming a missing condition key evaluates to false. It usually means no-match, and which one you get is often the difference between enforcement and decoration.
- Treating wildcards as regex. Only
*and?. Anything else is a literal that will never match. - Typos in condition keys. Silently never match. This is the failure Cedar's schema exists to eliminate, and the reason to run
validate-policyon anything hand-written. - Forgetting cross-account needs both sides. A resource policy alone is not enough when the principal lives in another account.
- Omitting
aws:SourceArnoraws:SourceAccounton service-principal trust. This is the confused-deputy shape behind a long list of cross-tenant findings. - Expecting an RCP to cover every service it names. It covers only the services on AWS's list, and only actions that act on a resource.
validate-policyreports an unlisted service as an error; an action with no resource, such ass3:ListAllMyBuckets, passes with no findings and is never restricted by the RCP. - Counting on an RCP to protect the management account. RCPs never apply to its resources, even when attached to the organization root.
- A data-perimeter RCP without the
aws:PrincipalIsAWSServiceexception. It denies AWS services acting on your resources, such as CloudTrail delivering logs to a bucket, andvalidate-policyreports it only as a warning. - Testing an RCP with the policy simulator.
simulate-principal-policydoes not evaluate RCPs, so its answer leaves out every deny that comes from one. Try the RCP on a test account and read CloudTrail for access-denied errors. - Shipping a Cedar policy set without a schema. You give up the one advantage the language has over what you were using before.
Where next
- IAM and identity architecture for how these documents fit an account and organization design.
- OPA and Rego for gating policy documents in CI before they reach an account.
- jq and JMESPath, since auditing policies at scale means querying thousands of JSON documents.
- CEL for the Google Cloud equivalent, where IAM conditions are CEL expressions.
- Azure Policy for the Azure side: the rules that decide which resources may exist, with Azure role assignment conditions at the end.
- AWS security and AWS vs Azure vs GCP for how the three providers' models differ, which is more than terminology.
- cedarpolicy.com has a browser playground, and the AWS policy evaluation logic reference is the authoritative version of the ordering above, including the flowcharts.
