Skip to content

Commit b57828b

Browse files
authored
Merge pull request #4 from cookielab/OPS-558
feat(assume-role): Provide script for AssumeRoleWithWebIdentity
2 parents f1b7463 + e011e7e commit b57828b

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ARG AWS_CLI_VERSION
2323
COPY build-scripts/download-aws-cli.sh /tmp/download-aws-cli.sh
2424
RUN /tmp/download-aws-cli.sh
2525

26+
COPY scripts/assume-role.sh /usr/local/bin/assume-role
2627
COPY scripts/deploy-s3-cf.sh /usr/local/bin/deploy-s3-cf
2728

2829
FROM cookielab/container-image-tools:1.4.0-aws AS container-image-tools

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@
88
## Scripts
99

1010
- `deploy-s3-cf` - for deploying static site to S3 and CloudFront
11+
- `assume-role` - Script for AssumeRoleWithWebIdentity
12+
- Requirements:
13+
- `$AWS_ROLE_ARN` = ENV variable for Role ARN
14+
- `$AWS_ROLE_SESSION_NAME` = ENV variable for session name
15+
- `$OIDC_TOKEN` = ENV variable for providing OIDC token

scripts/assume-role.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_SESSION_EXPIRATION
4+
5+
read -r AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_SESSION_EXPIRATION < <(
6+
aws sts assume-role-with-web-identity \
7+
--role-arn "${AWS_ROLE_ARN}" \
8+
--role-session-name "${AWS_ROLE_SESSION_NAME}" \
9+
--web-identity-token "${OIDC_TOKEN}" \
10+
--duration-seconds 900 \
11+
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken,Expiration]' \
12+
--output text
13+
)
14+

0 commit comments

Comments
 (0)