Skip to content

Latest commit

 

History

History
 
 

aws-iam-scp-permissions-boundary

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

SCP, Permissions Boundary, and IAM policy

Overview

We’re going to be creating and configuring an IAM user, and then limiting their access via IAM Policies, Permissions Boundary’s, and Service Control Policies (SCPs).

We’re going to create a user in an organisation sub-account, then test out creating S3 buckets and IAM users, using that newly created user.

We will then use an SCP to prevent deleting buckets at the account level, and Permission Boundary’s to limit the user to performing everything in S3, all while having full AdministratorAccess at the Identity-based policy level.

The following diagram from the Cantrill Solutions Architect Professional course explains how these three permission tools work together.

Untitled

Note: You will need to have an AWS Organisation set up to use Service Control Policies. They’re relatively easy to set up as long as you have 2+ AWS accounts, see the following tutorial for instructions: https://docs.aws.amazon.com/organizations/latest/userguide/orgs_tutorials_basic.html

Instructions

Stage 1 - Create the IAM user

Account: Sub-account

User: Your default user

Head to the IAM dashboard: https://us-east-1.console.aws.amazon.com/iamv2/home

Go the Users page click Add Users

Enter the User Name, ensure “Enable console access” is selected, leave “Autogenerated password” selected, and leave “Users must create a new password at next sign-in (recommended)” selected. Then click Next.

On the next page, select “Attach policies directly” and check “AdministratorAccess”

Untitled

Click Next

On the next page, click Create user.

Make sure you copy down the autogenerated password as you’ll need that for the next step.

This user now has unrestricted access to perform any tasks / API calls in this AWS account, because they have the “AdministratorAccess” identity-based policy assigned.

Stage 2 - Login as your new user and test access

Account: Sub-account

User: Newly created user

Let’s test out some actions, first we’ll create an S3 bucket.

Head to the S3 console: https://s3.console.aws.amazon.com/s3/buckets

Click on Create bucket

Choose any name and any region, and leave all other settings as default.

Click Create bucket

It should have created without any issues.

Untitled

Let’s try and delete that bucket. Select it, and click Delete

Untitled

Enter the bucket name in the confirmation window, and click Delete bucket

As expected, it worked.

Now, head to the IAM console: https://us-east-1.console.aws.amazon.com/iamv2/home

Go to Users and click Add users

Untitled

Set the User name to anything you like.

Click Next

Under Permissions, select “Attach policies directly”, and select the “AdministratorAccess” policy

Untitled

Click Next

Click Create user

As expected, it worked, and now the organisation has a user that was created with administrator privileges, that isn’t tracked / necessarily known by the owners or administrators of the organisation, which isn’t definitely isn’t ideal

Select the user you just created, and click Delete

Untitled

In the confirmation box, enter the username and click Delete

Stage 3 - Creating an SCP to prevent bucket deletion

Account: Management account

User: Your default user

Head to the AWS Organizations console: https://us-east-1.console.aws.amazon.com/organizations/v2/home/

Go to Policies then Service control policies

Untitled

Click on Create policy

Set the Policy Name to “NoDeleteBucket”

Then in the statement box, enter

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "s3:DeleteBucket"
            ],
            "Resource": "*",
            "Effect": "Deny"
        }
    ]
}

Untitled

Click Create policy

Now go to the AWS accounts page, and click on the sub-account you’re using for this demo (and where you have created your IAM user)

Untitled

Go to the Policies tab and click Attach

Untitled

Select the NoDeleteBucket policy and click Attach policy

Untitled

Stage 4 - Create a permissions boundary

Account: Sub-account

User: Your default user

Head to the IAM console: https://us-east-1.console.aws.amazon.com/iamv2/home

Go to Users and click on the user you created earlier

Untitled

Expand “Permissions boundary” and click Set permissions boundary

Untitled

Search for “AmazonS3FullAccess” and select that policy

Untitled

Click Set boundary

Stage 5 - Login as your new user and test access

Account: Sub-account

User: Newly created user

Login to your sub-account, as your newly created user.

First, like we did before, we’ll create a new S3 bucket.

Head to the S3 console: https://s3.console.aws.amazon.com/s3/buckets

Click on Create bucket

Choose any name and any region, and leave all other settings as default.

Click Create bucket

As expected, it worked.

Now we’ll try and delete our newly created bucket. Select the bucket and click Delete

Untitled

Enter the name of the bucket and click Delete bucket

You should receive an error:

Untitled

Remember, our SCP, applied at the account level, is preventing anyone from deleting S3 buckets.

Now let’s try creating a new user like we did earlier.

Head to the IAM console: https://us-east-1.console.aws.amazon.com/iamv2/home

Immediately you will start seeing permission errors.

Untitled

Even if you do go to the Users page, nothing will load, including the Create user button.

In production, this would be a lot more fine tuned, you would need to give your user access to change their password, MFA, etc, rather than just denying iam:*

Effectively, our user has three permission sets acting upon them:

IAM policy - Administrator access to everything

SCP - They can’t delete S3 buckets

Permissions boundary - The user can do anything in S3

This results in our user only being allowed to perform S3 actions, except for DeleteBucket

Stage 6 - Clean up

Account: Management account

Login to your management account

Head to the AWS Organizations console: https://us-east-1.console.aws.amazon.com/organizations/v2/home/

Go to the AWS accounts page, and click on the sub-account you’re using for this demo

Untitled

Go to the Policies tab, select our “NoDeleteBucket” policy, and click Detach

Untitled

In the confirmation box, click Detach policy

Go to Policies then Service control policies

Untitled

Select the “NoDeleteBucket” policy, and click Actions then Delete policy

Untitled

Enter the policy name in the confirmation box and click Delete

Account: Sub-account

Login to your sub-account, as the original user you used, to create the sub-account user.

Head to the IAM console: https://us-east-1.console.aws.amazon.com/

Go to Users, select the sub-account user you have been testing with, and click Delete

Untitled

Enter their username in the confirmation box, and click Delete

Head to the S3 console: https://s3.console.aws.amazon.com/s3/buckets

Select the bucket you created earlier, and click Delete

Untitled

Enter the bucket name in the confirmation window and click Delete bucket