This repository has been archived by the owner on Oct 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.yml
77 lines (74 loc) · 2.72 KB
/
example.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Parameters:
TrustedAccountId:
Type: String
TrustedRoleName:
Type: String
Default: GithubActions
Resources:
RoleThatTrustsAnyRepo:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns: [ arn:aws:iam::aws:policy/ReadOnlyAccess ]
Tags:
# this only allows roles specifically intended to be assumed by GHA
# to be assumed. this avoids the scenario where a role might trust
# our account's :root but didn't have GHA in mind.
- Key: ghaoidc
Value: true
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
# the reason why we trust :root here and the specific role
# in a condition block is so that if the lambda's cfn stack
# is destroyed and recreated, it won't require *this* trust
# policy to be recreated. TODO: find a doc that explains this
AWS: !Sub arn:aws:iam::${TrustedAccountId}:root
Condition:
StringEquals:
aws:PrincipalArn: !Sub arn:aws:iam::${TrustedAccountId}:role/${TrustedRoleName}
- Effect: Allow
Action: sts:TagSession
Principal:
AWS: !Sub arn:aws:iam::${TrustedAccountId}:root
Condition:
# this allows GHA to set any tags it pleases as long as they
# begin with gha_
ForAllValues:StringLike:
aws:TagKeys: gha_*
RoleThatOnlyWorksForMainPush:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns: [ arn:aws:iam::aws:policy/ReadOnlyAccess ]
Tags:
# see above
- Key: ghaoidc
Value: true
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: sts:AssumeRole
Principal:
# explanation is as above
AWS: !Sub arn:aws:iam::${TrustedAccountId}:root
Condition:
StringEquals:
aws:PrincipalArn: !Sub arn:aws:iam::${TrustedAccountId}:role/${TrustedRoleName}
# this role can only be assumed for jobs triggered by pushes
# to the "main" branch
aws:RequestTag/gha_event_name: push
aws:RequestTag/gha_ref: refs/heads/main
- Effect: Allow
Action: sts:TagSession
Principal:
AWS: !Sub arn:aws:iam::${TrustedAccountId}:root
Condition:
# as above
ForAllValues:StringLike:
aws:TagKeys: gha_*
Outputs:
RoleThatTrustsAnyRepo:
Value: !GetAtt RoleThatTrustsAnyRepo.Arn
RoleThatOnlyWorksForMainPush:
Value: !GetAtt RoleThatOnlyWorksForMainPush.Arn