Skip to content

Commit 974611a

Browse files
authored
feat: support OIDC invalidate cloudfront (#259)
1 parent 69fcbcf commit 974611a

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

.github/workflows/invalidate_cloudfront.yaml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ on:
1616
description: AWS IAM role ARN
1717
required: false
1818
type: string
19+
useOIDC:
20+
description: Whether to use OIDC for assume role
21+
required: false
22+
type: boolean
23+
default: false
24+
githubOIDCRoleArn:
25+
description: Github OIDC role ARN
26+
required: false
27+
type: string
28+
default: ""
1929
awsRegion:
2030
description: AWS region
2131
required: false
@@ -42,10 +52,10 @@ on:
4252
secrets:
4353
awsAccessKeyId:
4454
description: AWS access key ID
45-
required: true
55+
required: false
4656
awsSecretAccessKey:
4757
description: AWS secret access key
48-
required: true
58+
required: false
4959
slackToken:
5060
description: Slack API token
5161
required: false
@@ -55,6 +65,7 @@ jobs:
5565
runs-on: ubuntu-22.04-arm64
5666
steps:
5767
- name: assume IAM role
68+
if: inputs.useOIDC == false
5869
uses: aws-actions/configure-aws-credentials@v4
5970
with:
6071
aws-access-key-id: ${{ secrets.awsAccessKeyId }}
@@ -67,6 +78,30 @@ jobs:
6778
# which does not work for cross-account assume
6879
role-skip-session-tagging: true
6980

81+
# 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.
82+
- name: assume GithubOIDCRole
83+
if: inputs.useOIDC == true
84+
uses: aws-actions/configure-aws-credentials@v4
85+
with:
86+
aws-region: ${{ inputs.awsRegion }}
87+
role-to-assume: ${{ inputs.githubOIDCRoleArn }}
88+
role-duration-seconds: ${{ inputs.awsSessionDuration }}
89+
90+
# This parameter is needed otherwise this action is trying to tag session
91+
# which does not work for cross-account assume
92+
role-skip-session-tagging: true
93+
94+
# Then assume Deployer role, which can be assumed by GithubOIDCRole and has all the permissions needed.
95+
- name: assume Deployer role
96+
if: inputs.useOIDC == true
97+
uses: aws-actions/configure-aws-credentials@v4
98+
with:
99+
aws-region: ${{ inputs.awsRegion }}
100+
role-to-assume: ${{ inputs.awsRoleArn }}
101+
role-duration-seconds: ${{ inputs.awsSessionDuration }}
102+
role-chaining: true
103+
role-skip-session-tagging: true
104+
70105
- name: invalidate
71106
run: |
72107
echo ">>> Invalidating path ${{ inputs.path }} of distribution ${{ inputs.distributionId }}"

0 commit comments

Comments
 (0)