Skip to content

Commit ae3dcbb

Browse files
authored
CloudFormation Template for IAM Role & Managed Policies (#16)
* Add CloudFormation Template for IAM Role and Permission Policies.
1 parent aafd8ee commit ae3dcbb

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

cfn/S3EC-GitHub-CF-Template

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Resources:
3+
S3ECGitHubKMSKeyID:
4+
Type: 'AWS::KMS::Key'
5+
Properties:
6+
Description: KMS Key for GitHub Action Workflow
7+
Enabled: true
8+
KeyPolicy:
9+
Version: 2012-10-17
10+
Statement:
11+
- Effect: Allow
12+
Principal:
13+
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
14+
Action: 'kms:*'
15+
Resource: '*'
16+
17+
S3ECGitHubKMSKeyAlias:
18+
Type: 'AWS::KMS::Alias'
19+
Properties:
20+
AliasName: alias/S3EC-Github-KMS-Key
21+
TargetKeyId: !Ref S3ECGitHubKMSKeyID
22+
23+
S3ECGitHubTestS3Bucket:
24+
Type: 'AWS::S3::Bucket'
25+
Properties:
26+
BucketName: s3ec-github-test-bucket
27+
LifecycleConfiguration:
28+
Rules:
29+
- Id: Expire in 14 days
30+
Status: Enabled
31+
ExpirationInDays: 14
32+
PublicAccessBlockConfiguration:
33+
BlockPublicAcls: false
34+
BlockPublicPolicy: false
35+
IgnorePublicAcls: false
36+
RestrictPublicBuckets: false
37+
38+
S3ECGitHubS3BucketPolicy:
39+
Type: 'AWS::IAM::ManagedPolicy'
40+
Properties:
41+
ManagedPolicyName: S3EC-GitHub-S3-Bucket-Policy
42+
PolicyDocument:
43+
Version: 2012-10-17
44+
Statement:
45+
- Effect: Allow
46+
Action:
47+
- 's3:PutObject'
48+
- 's3:GetObject'
49+
Resource:
50+
- !Join [ "", [ !GetAtt S3ECGitHubTestS3Bucket.Arn, '/*'] ]
51+
52+
S3ECGitHubKMSKeyPolicy:
53+
Type: 'AWS::IAM::ManagedPolicy'
54+
Properties:
55+
PolicyDocument: !Sub |
56+
{
57+
"Version": "2012-10-17",
58+
"Statement": [
59+
{
60+
"Effect": "Allow",
61+
"Resource": [
62+
"arn:aws:kms:*:${AWS::AccountId}:key/${S3ECGitHubKMSKeyID}",
63+
"arn:aws:kms:*:${AWS::AccountId}:${S3ECGitHubKMSKeyAlias}"
64+
],
65+
"Action": [
66+
"kms:Encrypt",
67+
"kms:Decrypt",
68+
"kms:GenerateDataKey",
69+
"kms:GenerateDataKeyPair"
70+
]
71+
}
72+
]
73+
}
74+
ManagedPolicyName: S3EC-GitHub-KMS-Key-Policy
75+
76+
S3ECGithubTestRole:
77+
Type: 'AWS::IAM::Role'
78+
Properties:
79+
Path: /service-role/
80+
RoleName: S3EC-GitHub-test-role
81+
AssumeRolePolicyDocument: !Sub |
82+
{
83+
"Version": "2012-10-17",
84+
"Statement": [
85+
{
86+
"Effect": "Allow",
87+
"Principal": { "Federated": "arn:aws:iam::${AWS::AccountId}:oidc-provider/token.actions.githubusercontent.com" },
88+
"Action": "sts:AssumeRoleWithWebIdentity",
89+
"Condition": {
90+
"StringEquals": {
91+
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
92+
},
93+
"StringLike": {
94+
"token.actions.githubusercontent.com:sub": "repo:aws/aws-s3-encryption-client-java:ref:refs/*"
95+
}
96+
}
97+
}
98+
]
99+
}
100+
Description: >-
101+
Grant GitHub S3 put and get and KMS encrypt, decrypt, and generate access
102+
for testing
103+
ManagedPolicyArns:
104+
- !Ref S3ECGitHubKMSKeyPolicy
105+
- !Ref S3ECGitHubS3BucketPolicy

0 commit comments

Comments
 (0)