Skip to content
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

Fetch OIDC token in the background process to avoid expiration issue #2669

Merged
merged 14 commits into from
Apr 12, 2024
21 changes: 20 additions & 1 deletion .github/workflows/assets-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,26 @@ jobs:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
scripts-setup-dir: ${{ env.scripts_setup_dir }}


- name: Refresh login (background process)
run: |
while true; do
token_request=$ACTIONS_ID_TOKEN_REQUEST_TOKEN
token_uri=$ACTIONS_ID_TOKEN_REQUEST_URL
token=$(curl -H "Authorization: bearer $token_request" "${token_uri}&audience=api://AzureADTokenExchange" | jq .value -r)
elesel marked this conversation as resolved.
Show resolved Hide resolved

expiration_time=$(jq -R 'split(".") | .[1] | @base64d | fromjson | .exp' <<< $token)
expiration_time_formatted=$(date -u -d @$expiration_time +"%Y-%m-%dT%H:%M:%SZ")
current_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "Token expires at: $expiration_time_formatted, Current time: $current_time"

az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -t ${{ secrets.AZURE_TENANT_ID }} --federated-token $token --output none

sleep_timer=$((expiration_time - $(date +%s) - 30))
echo "Sleeping for $sleep_timer seconds"
sleep $sleep_timer
done &

- name: Test asset
run: python -u $scripts_test_dir/test_assets.py -i "${{ matrix.asset_config_path }}" -a $asset_config_filename -p $scripts_test_dir/requirements.txt -r $GITHUB_WORKSPACE/$pytest_reports

Expand Down