Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2.1
setup: true
orbs:
orb-tools: circleci/orb-tools@12.2
shellcheck: circleci/shellcheck@3.2
orb-tools: circleci/orb-tools@12.3.1
shellcheck: circleci/shellcheck@3.4

filters: &filters
tags:
Expand All @@ -18,6 +18,7 @@ workflows:
- orb-tools/review:
filters: *filters
- shellcheck/check:
shell: bash
filters: *filters
- orb-tools/continue:
orb_name: aws-cli
Expand Down
2 changes: 1 addition & 1 deletion .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2.1
orbs:
orb-tools: circleci/orb-tools@12.0
orb-tools: circleci/orb-tools@12.3.1
aws-cli: {}
filters: &filters
tags:
Expand Down
16 changes: 14 additions & 2 deletions src/scripts/assume_role_with_web_identity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,20 @@ if [ -z "${AWS_CLI_STR_ROLE_SESSION_NAME}" ]; then
exit 1
fi

if [ -z "${CIRCLE_OIDC_TOKEN_V2}" ]; then
echo "OIDC Token cannot be found."
if [ -z "${CIRCLE_OIDC_TOKEN_V2}" ] || [ -z "${CIRCLE_OIDC_TOKEN}" ]; then
for i in {1..3}; do
echo "Attempt $i: Checking OIDC tokens"
CIRCLE_OIDC_TOKEN=$(circleci run oidc get --claims "{\"aud\":\"${CIRCLE_ORGANIZATION_ID}\"}")
if [ -n "$CIRCLE_OIDC_TOKEN" ] || [ -n "$CIRCLE_OIDC_TOKEN_V2" ]; then
echo "Successfully set CIRCLE_OIDC_TOKEN"
echo 'export CIRCLE_OIDC_TOKEN="'"$CIRCLE_OIDC_TOKEN"'"' >> "$BASH_ENV"
echo 'export CIRCLE_OIDC_TOKEN_V2="'"$CIRCLE_OIDC_TOKEN"'"' >> "$BASH_ENV"
exit 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi I was reviewing the script and was wondering why we would want to exit out of here? Wouldn't we want to exit the for loop and continue the script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ohjinsoo!

In this version of this script, if the exit 0 was not there, even if it were able to get a new token, it would trigger the last echo "failed to set ..." message.
The exit 0 in this case exits the scripts entirely once we confirm that we have a token set.

Copy link
Contributor

@ohjinsoo ohjinsoo Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but the command aws-cli/setup is used to setup AWS creds. By exiting here, you won't be setting AWS creds, and you'd have to run the same command again which doesn't seem ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I've created a new PR for this #224

fi
echo "Waiting 1 second before retry"
sleep 1
done
echo "Failed to set CIRCLE_OIDC_TOKEN_V2 after 3 attempts"
exit 1
fi

Expand Down