Skip to content

Commit 05e2311

Browse files
committed
Changed the method of AWS Authentication in the 'aws-config-storage.sh' script and now it uses Bitbucket OIDC (OpenID Connect) token.
1 parent 9704e82 commit 05e2311

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

aws/aws-config-storage.sh

+15-5
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,22 @@ if [ "$#" -lt 2 ]; then
120120
about
121121
fi
122122

123-
if [ -n "$AWS_OIDC_ROLE_ARN" ]; then
124-
echo "Assuming role: $AWS_OIDC_ROLE_ARN"
125-
role_session_name="SomeSessionName" # You can customize this session name
126123

127-
# Assume role and get temporary credentials
128-
creds=$(aws sts assume-role --role-arn "$AWS_OIDC_ROLE_ARN" --role-session-name "$role_session_name" --query 'Credentials' --output json)
124+
if [ -n "$AWS_OIDC_ROLE_ARN" ] && [ -n "$BITBUCKET_STEP_OIDC_TOKEN" ]; then
125+
echo "Using Bitbucket OIDC Token for AWS Authentication"
126+
127+
timestamp=$(date +%Y%m%d-%H%M%S)
128+
# Set the OIDC token and AWS Role ARN
129+
oidc_token=$BITBUCKET_STEP_OIDC_TOKEN
130+
aws_role_arn=$AWS_OIDC_ROLE_ARN
131+
132+
# Assume the AWS role using the OIDC token
133+
creds=$(aws sts assume-role-with-web-identity \
134+
--role-arn "$aws_role_arn" \
135+
--role-session-name "BitbucketSession" \
136+
--web-identity-token "$oidc_token" \
137+
--query 'Credentials' \
138+
--output json)
129139

130140
# Set temporary credentials for subsequent AWS CLI commands
131141
AWS_ACCESS_KEY_ID=$(echo "$creds" | jq -r '.AccessKeyId')

0 commit comments

Comments
 (0)