Skip to content

Instantly share code, notes, and snippets.

@jolexa
Last active May 18, 2018 15:07
Show Gist options
  • Save jolexa/dfd444e7e2ead69a9479d5a07a366fee to your computer and use it in GitHub Desktop.
Save jolexa/dfd444e7e2ead69a9479d5a07a366fee to your computer and use it in GitHub Desktop.
AWS IAM Role that both services *and* Humans-with-2fa can assume
AWSTemplateFormatVersion: '2010-09-09'
Resources:
ExampleRole:
Type: AWS::IAM::Role
Properties:
Path: "/cfn/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
Policies:
- PolicyName: DynamoDBGetter
PolicyDocument:
Statement:
- Effect: Allow
Action:
- dynamodb:GetItem
Resource:
- !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/specificTableName"
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Sid: 'LambdaCanReadTable'
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
- Effect: Allow
Sid: 'HumanCanReadTableToo'
Principal:
AWS:
- !Ref AWS::AccountId
Action:
- sts:AssumeRole
Condition:
Bool:
aws:MultiFactorAuthPresent: 'true'
ExampleAdminRole:
Type: AWS::IAM::Role
Properties:
Path: "/cfn/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
Policies:
- PolicyName: DynamoDBAdmin
PolicyDocument:
Statement:
- Effect: Allow
Action:
- dynamodb:*
Resource:
- !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/specificTableName"
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Sid: 'HumanAdmin'
Principal:
AWS:
- !Ref AWS::AccountId
Action:
- sts:AssumeRole
Condition:
Bool:
aws:MultiFactorAuthPresent: 'true'
@jolexa
Copy link
Author

jolexa commented May 18, 2018

This is a contrived example that shows two IAM Roles that allows:

  • Any S3 Read Access
  • A Specific DDB Table access

The first role allows dynamoddb:GetItem access on the table. Both lambda functions (where this role is applied) and Humans-with-2fa can assume this role.
The second role allows for "HumanAdmins" to do ANYTHING to the specific table. Only Humans-with-2fa can use this role.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment