Skip to content

Commit c8532a9

Browse files
authored
feat: OIDC support for Cloudformation deployment (#184)
* chore: OIDC support for Cloudformation deployment
1 parent 9e19fcf commit c8532a9

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

.github/workflows/deploy_cloudformation.yaml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ on:
77
description: AWS IAM role ARN
88
required: false
99
type: string
10+
useOIDC:
11+
description: Whether to use OIDC for assume role
12+
required: false
13+
type: boolean
14+
default: false
15+
githubOIDCRoleArn:
16+
description: Github OIDC role ARN
17+
required: false
18+
type: string
19+
default: "arn:aws:iam::031263542130:role/GithubOIDCRole"
1020
awsRegion:
1121
description: AWS region
1222
required: false
@@ -57,7 +67,7 @@ on:
5767
description: Additional parameters of aws cloudformation deploy
5868
required: false
5969
type: string
60-
70+
6171
outputs:
6272
stackOutputs:
6373
description: Stringified json containing outputs of cloudformation stack
@@ -66,10 +76,10 @@ on:
6676
secrets:
6777
awsAccessKeyId:
6878
description: AWS access key ID
69-
required: true
79+
required: false
7080
awsSecretAccessKey:
7181
description: AWS secret access key
72-
required: true
82+
required: false
7383
slackToken:
7484
description: Slack API token
7585
required: false
@@ -124,6 +134,7 @@ jobs:
124134
uses: actions/checkout@v4
125135

126136
- name: assume IAM role
137+
if: inputs.useOIDC == false
127138
uses: aws-actions/configure-aws-credentials@v4
128139
with:
129140
aws-access-key-id: ${{ secrets.awsAccessKeyId }}
@@ -136,6 +147,30 @@ jobs:
136147
# which does not work for cross-account assume
137148
role-skip-session-tagging: true
138149

150+
# First assume GithubOIDCRole role, the trust relationship between GitHub and AWS is defined in IAM GithubOIDCRole in the organization account. This role has permissions to assume Deployer roles only.
151+
- name: assume GithubOIDCRole
152+
if: inputs.useOIDC == true
153+
uses: aws-actions/configure-aws-credentials@v4
154+
with:
155+
aws-region: ${{ inputs.awsRegion }}
156+
role-to-assume: ${{ inputs.githubOIDCRoleArn }}
157+
role-duration-seconds: ${{ inputs.awsSessionDuration }}
158+
159+
# This parameter is needed otherwise this action is trying to tag session
160+
# which does not work for cross-account assume
161+
role-skip-session-tagging: true
162+
163+
# Then assume Deployer role, which can be assumed by GithubOIDCRole and has all the permissions needed to deploy cloudformation stacks.
164+
- name: assume Deployer role
165+
if: inputs.useOIDC == true
166+
uses: aws-actions/configure-aws-credentials@v4
167+
with:
168+
aws-region: ${{ inputs.awsRegion }}
169+
role-to-assume: ${{ inputs.awsRoleArn }}
170+
role-duration-seconds: ${{ inputs.awsSessionDuration }}
171+
role-chaining: true
172+
role-skip-session-tagging: true
173+
139174
# Since the official cloudformation deploy action is archived for some reason, let's script this!
140175
- name: deploy
141176
id: deploy
@@ -209,7 +244,7 @@ jobs:
209244
echo "color=#ff0000" >> $GITHUB_OUTPUT
210245
echo "emoji=red_circle" >> $GITHUB_OUTPUT
211246
fi
212-
247+
213248
- name: send result to slack
214249
if: always() && inputs.slackChannelId != ''
215250
uses: slackapi/[email protected]

0 commit comments

Comments
 (0)