Controlling access to resources in AWS is done using IAM policies. You attach pre-made or custom policies to users, either directly or using groups, giving the user access to those resources.
All policies have this basic structure:
"Action": [ "s3:ListBucket" ],
"Resource": [ "arn:aws:s3:::test" ],
"Action" is the action you are allowing or denying, such as
kinesis:PutRecord. (You can exclude actions with
"Resource" is the specific resource. For example, you can restrict the
s3:GetItem to anything in a bucket, or a wildcard-matched set of files in a bucket. (You can exclude resources with
"Effect" is whether to
"Deny" access, based on whether the Action and Resource match.
The different statements are evaluated first to last, so for example you could have a statement allowing write access to everything in a bucket, but then follow it with a statement denying access to a specific file. This would give write access to everything except that one file.
Different AWS resources have more or less granularity of control, so you will need to read the documentation for each resource to determine what the least privilege is.
The wrong way to give that access would be with an “allow all” policy:
"Action": [ "s3:*" ],
"Resource": [ "arn:aws:s3:::*" ],
This policy would give Travis CI permission to take any action to any S3 bucket in the AWS account, including creating new buckets. That’s clearly a horrible idea.
Note: If you are attaching the default AWS policies, this is probably what you are doing! To administrate access to your resources correctly, you will almost always need to create your own policies.
A much better policy would be something like:
"Action": [ "s3:PutItem" ],
"Resource": [ "arn:aws:s3:::my-app/asset-folder/*" ],
This will give permission only to the
my-app bucket, and only allow it to write files with the keypath prefix
asset-folder/, for example
Finding out what the available policy rules are for each resource can be difficult.
Here are the steps I usually take:
- Start at the main AWS Documentation page,
- Click in to the resource type you are investigating,
- Go into the “Developer Guide” (sometimes named slightly different) HTML version,
- Look on the left navigation area for something called “Security”, “Access Control”, or similar,
- Look for something labeled IAM or “Identity Access Management”
- Look around in there for some sort of “Reference” page
Here are some links to ones I work with commonly: