Home

Awesome

AWS IAM Access Analyzer CheckNoNewAccess Sample Reference Policies

This repository contains a collection of sample reference policies that can be used with the Access Analyzer's CheckNoNewAccess API. The CheckNoNewAccess API checks an existing policy against a new policy and returns PASS if no new access is detected in the new policy and FAIL if new access is detected in the new policy.

The reference policies in this repository are meant to be passed to the ExistingPolicyDocument parameter of the CheckNoNewAccess API. You then pass the IAM policy you're attempting to check for new access (referred to as the candidate-policy in this repository) in the NewPolicyDocument parameter. Example:

aws accessanalyzer check-no-new-access --existing-policy-document file://reference-policy.json --new-policy-document file://candidate-policy.json --policy-type IDENTITY_POLICY 

The CheckNoNewAccess API supports both identity policies and resource policies and is built on Zelkova, which translates IAM policies into equivalent logical statements, and runs a suite of general-purpose and specialized logical solvers (satisfiability modulo theories) against the problem. To learn more about satisfiability modulo theories, see Satisfiability Modulo Theories.

What are reference policies?

You use a reference policy to check if a candidate policy allows more access than the reference policy does. Worded differently, the check passes if the candidate policy is a subset of the reference policy.

With properly crafted reference policies, this allows you to make assertions like:

Let's walk through an example. A reference policy typically starts by allowing all access. If you've seen service control policies before, this probably looks familiar to you. You then add a statement or statements that deny the access that you want the reference policy to check for.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "*",
            "Resource": "*"
        },
        {
            "Effect": "Deny",
            "Action": [
                "s3:PutBucketPolicy"
            ],
            "Resource": "arn:aws:s3:::my-sensitive-bucket"
        }
    ]
}

Example 1: Reference policy that checks for s3:PutBucketPolicy access to my-sensitive-bucket

In Example 1 above, we start by allowing all access. We then deny the s3:PutBucketPolicy action against a specific sensitive bucket, my-sensitive-bucket. You could choose to add more than one bucket here.

The CheckNoNewAccess API will return a PASS, meaning no new access, for candidate policies that do not grant s3:PutBucketPolicy access to my-sensitive-bucket. The API will return a FAIL for candidate policies that do grant access to the sensitive bucket. You might use that result to decide that a policy that grants s3:PutBucketPolicy access to a sensitive bucket needs additional review as part of a CI/CD pipeline process.

You can use this same type of pattern with any AWS service and there are a number of reference policies that you can customize in this repository.

What if I just want to check for IAM actions and not deal with reference policies?

You should use the CheckAccessNotGranted API instead. The CheckAccessNotGranted API checks that a candidate policy does not grant access to an IAM action.

What does it mean when the check fails and there is "new access" when checking an IAM policy against a reference policy?

New access means that the candidate policy you're checking against grants additional access that the reference policy does not grant.

This is why we recommend you start your reference policies with a statement that grants access to all actions and resources. You then write statements that deny the particular access that you're checking for. This means that the only way your candidate policy could grant access that is not granted in the reference policy is if it grants the access denied by the reference policy.

In Example 1 above, the only way a candidate policy can grant more access than the reference policy is if it allows access to exactly the s3:PutBucketPolicy action and the my-sensitive-bucket resource.

How should I use the example reference policies in this repository?

The example reference policies in this repository are divided into two top-level folders - resource policies and identity policies.

Identity policies

Resource policies

How do I write my own reference policies?

We recommend sticking to the examples provided in this repository and customizing them as you see fit. If you do want to write your own reference policies, you should follow these general patterns.

For identity policies, start with a statement that allows all actions and resources. Add a deny statement for actions, resources, and conditions that should cause the check to fail if they are granted in a candidate policy.

For resource policies, add statements to allow access to the principals, actions, resources, and conditions as you normally would when writing a resource policy. If you only want to check for specific actions or resources, add a statement with a NotAction or NotResource element at the end that includes the specific actions and resources you're checking for and effectively allows all other actions and resources.

What are some things to keep in mind when writing my own reference policies?

If you go the path of writing your own reference policies, we recommend customizing the reference policies in this repository or following the general patterns described above. There are some things to be aware of when you customize the existing reference policies or write your own.