Authentication in IAM is done with users or roles
Authorization is done by policies
Root user | IAM User | IAM role | |
---|---|---|---|
Can have password | Always | Yes | No |
Can have access key | Yes * | Yes | No |
Can belong to group | No | Yes | No |
Can be associated with an EC2 instance | No | No | Yes |
* not recommended
{
Version: '2012-10-17',
Statement: [{
Sid: '1',
Effect: 'Allow',
Action: ['ec2:*'],
Resource: ['*']
}]
}
every EC2 action
allows
every EC2 action
{
Version: '2012-10-17',
Statement: [
{
Sid: '1',
Effect: 'Allow',
Action: ['ec2:*'],
Resource: ['*']
},
{
Sid: '2',
Effect: 'Deny',
Action: ['ec2:TerminateInstances'],
Resources: ['*']
}
]
}
above policy allows all EC2 actions except terminating instances
{
Version: '2012-10-17',
Statement: [
{
Sid: '1',
Effect: 'Deny',
Action: ['ec2:*'],
Resource: ['*']
},
{
Sid: '2',
Effect: 'Allow',
Action: ['ec2:TerminateInstances'],
Resources: ['*']
}
]
}
above policy denies all actions including ec2:TerminateInstances
arn:aws:ec2:us-east-1:878533158213:instance/i-3dd4f812
Service
Region
AccountID
Resource Type
Resource
If you want to create policies that can be reused in your account. There are 2 types:
A policy that belongs to a certain IAM role, user, or group. The inline policy can't exist without the IAM role, the user, or the group.
{
"Statement": [
"Effect": "allow|deny",
"Principle": "principle",
"Action": "action",
"Resource": "arn",
"Condition": {
"condition": {
"key": "value"
}
}
]
}
you can have multiple statements and each statement is comprised of PARC
Principle Action Resource Condition
PARC + E
<!-- everyone (anonymous users) -->
"Principal":"AWS":"*.*"
<!-- specific account or accounts -->
"Principal": {"AWS":"arn:aws:iam::1234567:root"}
<!-- individual IAM user -->
"Principal": {"AWS":"arn:aws:iam::1234567:user/username"}
<!-- federated user (using web identity federation) -->
"Principal": {"Federated": "www.amazon.com"}
"Principal": {"Federated": "graph.facebook.com"}
<!-- specific role -->
"Principal": {"AWS":"arn:aws:iam::1234567:role/rolename}
<!-- specific service -->
"Principal": {"Service":"ec2.amazonaws.com"}
<!-- EC2 action -->
"Action": "ec2:StartInstances"
<!-- IAM action -->
"Action": "iam:ChangePassword"
<!-- s3 action -->
"Action": "s3:GetObject"
<!-- specify multiple values -->
"Action": ["sqs:SendMessage", "sqs:ReceiveMessage"]
<!-- use wildcards (* or ?) as part of the action name -->
"Action": "iam:*AccessKey"
<!-- this would cover, for e.g, CreateAccessKey, DeleteAccessKey etc -->
<-- S3 Bucket -->
"Resource": "arn:aws:s3:::my_corporate_bucket/*"
<-- SQS queue -->
"Resource": "arn:aws:sqs:us-west-2:12345678:queue1"
<-- Dynamo table -->
"Resource": "arn:aws:dynamodb:us-west-1:12345678:table/books_table"
<-- All EC2 instances for an account in a region -->
"Resource": "arn:aws:ec2:us-east-1:12345678:instance/*"