Skip to content

Commit

Permalink
Fetch OID token every 4 mins to avoid expiration issue (#2669)
Browse files Browse the repository at this point in the history
* acquire access token before expiry

* temp change to trigger test

* add requested url

* print the current time as well

* update when to get token

* Revert "temp change to trigger test"

This reverts commit 7ec78cd.

* prevent logging token

* temp bump version to trigger test

* Revert "prevent logging token"

This reverts commit 1367d1f.

* try switching to resource

* try fetching OID token every 4 mins

* Revert "temp bump version to trigger test"

This reverts commit 3336fe4.
  • Loading branch information
iamrk04 authored Apr 12, 2024
1 parent 272d87f commit 2e961ac
Showing 1 changed file with 20 additions and 1 deletion.
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)
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

0 comments on commit 2e961ac

Please sign in to comment.