Skip to content

Commit 5e28871

Browse files
authored
fix: Full OIDC support for Build workflow (#205)
1 parent f81f36c commit 5e28871

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

.github/workflows/build_docker_image_and_push_to_ecr.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: build docker image and push it to ECR
33
on:
44
workflow_call:
55
inputs:
6+
awsRoleArn:
7+
description: AWS IAM role ARN
8+
required: false
9+
type: string
610
useOIDC:
711
description: Whether to use OIDC for assume role
812
required: false
@@ -169,8 +173,8 @@ jobs:
169173
- name: setup Docker Buildx
170174
uses: docker/setup-buildx-action@v3
171175

172-
# Assume OIDC Role, the trust relationship between GitHub and AWS is defined in IAM in the organization account.
173-
- name: assume OIDC Role
176+
# 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.
177+
- name: assume GithubOIDCRole
174178
if: inputs.useOIDC == true
175179
uses: aws-actions/configure-aws-credentials@v4
176180
with:
@@ -182,6 +186,17 @@ jobs:
182186
# which does not work for cross-account assume
183187
role-skip-session-tagging: true
184188

189+
# Then assume Deployer role, which can be assumed by GithubOIDCRole and has all the permissions needed to deploy cloudformation stacks.
190+
- name: assume Deployer role
191+
if: inputs.useOIDC == true
192+
uses: aws-actions/configure-aws-credentials@v4
193+
with:
194+
aws-region: ${{ inputs.awsRegion }}
195+
role-to-assume: ${{ inputs.awsRoleArn }}
196+
role-duration-seconds: ${{ inputs.awsSessionDuration }}
197+
role-chaining: true
198+
role-skip-session-tagging: true
199+
185200
- name: login to AWS ECR using OIDC
186201
if: inputs.useOIDC == true
187202
id: login-ecr

0 commit comments

Comments
 (0)