Skip to content

Fix OIDC token cut #1792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix OIDC token cut #1792

wants to merge 1 commit into from

Conversation

acouvreur
Copy link

Closes #1791

The OIDC token is now properly extracted from the 4th quote instead of the 6th.

Verified

This commit was signed with the committer’s verified signature.
acouvreur Alexis Couvreur
closes codecov#1791
Copy link

@matheuscscp matheuscscp left a comment

Choose a reason for hiding this comment

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

LGTM

Can somebody pls merge this? 🙏

@inomdzhon
Copy link

LGTM

Can somebody pls merge this? 🙏

+1

@@ -210,7 +210,7 @@ runs:
then
# {"count":1984,"value":"***"}
echo -e "\033[0;32m==>\033[0m Requesting OIDC token from '$ACTIONS_ID_TOKEN_REQUEST_URL'"
CC_TOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$CC_OIDC_AUDIENCE" | cut -d\" -f6)
CC_TOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$CC_OIDC_AUDIENCE" | cut -d\" -f4)
Copy link

@rix0rrr rix0rrr Apr 11, 2025

Choose a reason for hiding this comment

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

This is expecting the JSON to be returned in a particular order if it has multiple fields. It will fail again if the format or order changes again, and in fact the order doesn't even seem to be stable currently. I ran a test on my own repo and had the following result (only one field, and the token would have been in position 4, not 6):

$ curl -H 'Authorization: bearer ***' 'https://run-actions-2-azure-eastus.actions.githubusercontent.com/49//idtoken/91debbd1-626a-42e4-8946-dcda602180fb/fad0b7ef-e9f6-5f42-8ca8-86dea076a55d?api-version=2.0&audience=someone'
{"value":"***"}

How about using a tool on disk to return the JSON field by name (.value) instead of by serialization order?

node is going to be on every GitHub image, so we can probably use that:

Suggested change
CC_TOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$CC_OIDC_AUDIENCE" | cut -d\" -f4)
CC_TOKEN=$(node -p 'JSON.parse(process.argv[1]).value' "$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$CC_OIDC_AUDIENCE")")

Choose a reason for hiding this comment

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

Regarding the tool on disk idea there is also wide support for the 'jq' tool which works with the curl pipe style already here

Suggested change
CC_TOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$CC_OIDC_AUDIENCE" | cut -d\" -f4)
CC_TOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$CC_OIDC_AUDIENCE" | jq -r '.value')

Also it may help to actually request json responses with curl like so:

Suggested change
CC_TOKEN=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$CC_OIDC_AUDIENCE" | cut -d\" -f4)
CC_TOKEN=$(curl -H "Accept: application/json" -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$CC_OIDC_AUDIENCE" | jq -r '.value')

🙇 Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Upload failed: {"message":"Token required because branch is protected"}
5 participants