-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.template
72 lines (71 loc) · 2.27 KB
/
setup.template
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
Description: >
Template to create GitHub OIDC provider and associated roles for CDK deployment.
If you don't specify an OIDC provider this will create one for you.
If you don't specify a repository name it will just create the OIDC provider.
Parameters:
GitHubOrg:
Description: GitHub org name or username
Type: String
RepositoryName:
Description: Optional repository name. If not provided only OIDC will be created.
Default: ""
Type: String
EnvironmentName:
Description: Optional GitHub environment name. If not provided allows all environments.
Default: ""
Type: String
OIDCProviderArn:
Description: Arn for the GitHub OIDC Provider.
Default: ""
Type: String
Conditions:
CreateOIDCProvider: !Equals
- !Ref OIDCProviderArn
- ""
UseEnvironment: !Not [!Equals [!Ref EnvironmentName, ""]]
CreateRole: !Not [!Equals [!Ref RepositoryName, ""]]
Resources:
Role:
Type: "AWS::IAM::Role"
Condition: CreateRole
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action: "sts:AssumeRoleWithWebIdentity"
Principal:
Federated: !If
- CreateOIDCProvider
- !Ref GithubOidc
- !Ref OIDCProviderArn
Condition:
StringLike:
"token.actions.githubusercontent.com:sub": !If
- UseEnvironment
- !Sub >-
repo:${GitHubOrg}/${RepositoryName}:environment:${EnvironmentName}
- !Sub "repo:${GitHubOrg}/${RepositoryName}:*"
Policies:
- PolicyName: CDKAssumeRole
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: sts:AssumeRole
Resource: !Sub arn:aws:iam::${AWS::AccountId}:role/cdk-*
GithubOidc:
Type: "AWS::IAM::OIDCProvider"
Condition: CreateOIDCProvider
Properties:
Url: "https://token.actions.githubusercontent.com"
ClientIdList:
- sts.amazonaws.com
ThumbprintList:
- 6938fd4d98bab03faadb97b34396831e3780aea1
Outputs:
Role:
Value: !GetAtt Role.Arn
Condition: CreateRole
GithubOidc:
Value: !GetAtt GithubOidc.Arn
Condition: CreateOIDCProvider