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

Azure CLI GitHub Action fails with Azure CLI 2.30.0: Could not retrieve credential from local cache for service principal #20154

Closed
zwolf opened this issue Nov 2, 2021 · 7 comments
Assignees
Labels
Account az login/account customer-reported Issues that are reported by GitHub users external to the Azure organization. MSAL

Comments

@zwolf
Copy link

zwolf commented Nov 2, 2021

Describe the bug
I am using the Azure CLI Github Action to upload files to Azure Blob Storage. This worked until this morning, when latest became CLI 2.30.0 and uploads to Blob Storage began failing with a 404 ResourceNotFound error.

To Reproduce

    - uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    - name: Upload to blob storage
      uses: azure/CLI@v1
      with:
        inlineScript: |
            az storage blob upload \
              --account-name my-account \
              --container-name 'my-container' \
              --name 'path/to/file.html' \
              --file ./file.html

This will default to using azcliversion: latest and the new & unexpected output is:

WARNING: Skip querying account key due to failure: Could not retrieve credential from local cache for service principal asdfasdf-asdf-asdf-asdf-asdfasdfasdf. Run az login for this service principal.
ERROR: Client-Request-ID=asdfasdf-asdf-asdf-asdf-adsfasdfasdf Retry policy did not allow for a retry: Server-Timestamp=Tue, 02 Nov 2021 16:52:14 GMT, Server-Request-ID=asdfadsf-asdf-asdf-asdf-asdfasdfasdfasdf, HTTP status code=404, Exception=The specified resource does not exist. ErrorCode: ResourceNotFound<?xml version="1.0" encoding="utf-8"?><Error><Code>ResourceNotFound</Code><Message>The specified resource does not exist.RequestId:asdfasdfasdf-asdf-adsf-adsf-asdfasdfasdfadsfTime:2021-11-02T16:52:15.3159868Z</Message></Error>.

Running az login for the associated service principal works, but does not solve this problem.

Reverting to previous release by adding

  with:
    azcliversion: 2.29.2

to the above fixes the issue and uploads the file as expected.

Expected behavior
The latest version of the CLI should work the same as the previous version. There are no related changes in the release notes for 2.30.0..

Environment summary
Github's own Action runners using runs-on: ubuntu-latest (20.04.3 LTS) along with the Azure-created actions noted above, specifically 'azure/CLI@v1' (SHA:4b58c946a0f48d82cc2b6e31c0d15a6604859554).

@ghost ghost added needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Nov 2, 2021
@jiasli jiasli self-assigned this Nov 3, 2021
@jiasli jiasli changed the title az storage blob uploads fail from GH Action with CLI 2.30.0 az storage blob uploads fail from GH Action with CLI 2.30.0: Could not retrieve credential from local cache for service principal Nov 3, 2021
@jiasli
Copy link
Member

jiasli commented Nov 3, 2021

Symptom

GitHub Action azure/CLI@v1 fails with

ERROR: Could not retrieve credential from local cache for service principal ea94e231-9b94-4844-bc6f-d773f9e07965. Run `az login` for this service principal.

Root cause

The is because Azure Login still uses the old ADAL-based Azure CLI 2.29.0 while Azure CLI Action uses the latest MSAL-based Azure CLI 2.30.0.

After the ADAL->MSAL migration (#19853), the latest Azure CLI is not compatible with old versions.

This can be reproduced with

# File: .github/workflows/workflow.yml

on: [push]

name: AzureCLISample

jobs:

  build-and-deploy:
    runs-on: ubuntu-latest
    steps:

    - name: Azure Login
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}

    - name: Azure CLI script
      uses: azure/CLI@v1
      with:
        azcliversion: latest
        inlineScript: |
          set -ex
          ls ~/.azure
          cat ~/.azure/versionCheck.json
          az --version
          az account show
          az group list

The output shows accessTokens.json and versionCheck.json from ADAL-based Azure CLI:

+ ls /root/.azure
accessTokens.json

+ cat /root/.azure/versionCheck.json
***"versions": ***"azure-cli": ***"local": "2.29.0", "pypi": "2.30.0"***, "core": ***"local": "2.29.0", "pypi": "2.30.0"***, "telemetry": ***"local": "1.0.6", "pypi": "1.0.6"***, "update_time": "2021-11-03 02:58:51.551907"***

Workaround (no longer needed now)

Change azcliversion in azure/CLI@v1 to 2.29.2 which is compatible with azure/login@v1:

    - name: Azure CLI script
      uses: azure/CLI@v1
      with:
        azcliversion: 2.29.2

Action plan

We are working with GitHub Action team to fix this issue with high priority.

@yonzhan yonzhan added Graph az ad and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Nov 3, 2021
@yonzhan yonzhan added this to the Backlog milestone Nov 3, 2021
@jiasli jiasli added Account az login/account and removed Graph az ad labels Nov 3, 2021
@jiasli jiasli modified the milestones: Backlog, Nov 2021 (2021-12-07) Nov 3, 2021
@jiasli jiasli changed the title az storage blob uploads fail from GH Action with CLI 2.30.0: Could not retrieve credential from local cache for service principal az storage blob upload fails from GitHub Action with Azure CLI 2.30.0: Could not retrieve credential from local cache for service principal Nov 3, 2021
@jiasli jiasli added the MSAL label Nov 3, 2021
@arthursantana
Copy link

Workaround

Change azcliversion in azure/CLI@v1 to 2.29.2 which is compatible with azure/login@v1:

This workaround stopped working for me today.
ERROR: Could not retrieve credential from local cache for service principal [...]

Undoing the downgrade seems to have fixed the issue. I guess the latest azure/login was changed to use MSAL-based Azure CLI and therefore 2.29.2 isn't compatible anymore.

@abhi-markan
Copy link

Workaround

Change azcliversion in azure/CLI@v1 to 2.29.2 which is compatible with azure/login@v1:

This workaround stopped working for me today. ERROR: Could not retrieve credential from local cache for service principal [...]

Undoing the downgrade seems to have fixed the issue. I guess the latest azure/login was changed to use MSAL-based Azure CLI and therefore 2.29.2 isn't compatible anymore.

Did you upgrade from 2.29.2 -> 2.30.0?

@arthursantana
Copy link

Workaround

Change azcliversion in azure/CLI@v1 to 2.29.2 which is compatible with azure/login@v1:

This workaround stopped working for me today. ERROR: Could not retrieve credential from local cache for service principal [...]
Undoing the downgrade seems to have fixed the issue. I guess the latest azure/login was changed to use MSAL-based Azure CLI and therefore 2.29.2 isn't compatible anymore.

Did you upgrade from 2.29.2 -> 2.30.0?

I upgraded 2.29.2 to latest, not sure what the specific version is. Here is the hash:
Download action repository 'azure/CLI@v1' (SHA:4b58c946a0f48d82cc2b6e31c0d15a6604859554)

@0gust1
Copy link

0gust1 commented Nov 10, 2021

so the fix is

- name: Deploy
  uses: azure/CLI@v1
  with:
    azcliversion: latest

or can we remove the azcliversion ?

@abhi-markan
Copy link

abhi-markan commented Nov 10, 2021

azcliversion: latest

azcliversion: latest is the fix, I would not recommend removing the version declaration.

@jiasli
Copy link
Member

jiasli commented Nov 11, 2021

2021-11-11 Update

As confirmed with GitHub Action team, Azure Login now uses the latest Azure CLI 2.30.0, so the workaround from #20154 (comment) is no longer needed now.

Instead, if you specify azcliversion as an version <2.30.0 in Azure CLI Action, the action will fail with

Could not retrieve credential from local cache for service principal xxx.

This is simply because Azure CLI 2.30.0 is not compatible with previous versions (<2.30.0).

Recommendation

You may leave azcliversion unspecified, so that it defaults to agentazcliversion and automatically uses the same version as Azure Login on the agent (Azure/cli#57).

Still, thanks to @abhi-markan for the explanation.

@jiasli jiasli closed this as completed Dec 22, 2021
@jiasli jiasli changed the title az storage blob upload fails from GitHub Action with Azure CLI 2.30.0: Could not retrieve credential from local cache for service principal Azure CLI GitHub Action fails from with Azure CLI 2.30.0: Could not retrieve credential from local cache for service principal Dec 22, 2021
@jiasli jiasli changed the title Azure CLI GitHub Action fails from with Azure CLI 2.30.0: Could not retrieve credential from local cache for service principal Azure CLI GitHub Action fails with Azure CLI 2.30.0: Could not retrieve credential from local cache for service principal Dec 22, 2021
vrdmr added a commit to Azure/azure-functions-python-worker that referenced this issue Feb 12, 2022
YunchuWang pushed a commit to Azure/azure-functions-python-worker that referenced this issue Apr 11, 2022
YunchuWang pushed a commit to Azure/azure-functions-python-worker that referenced this issue Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Account az login/account customer-reported Issues that are reported by GitHub users external to the Azure organization. MSAL
Projects
None yet
Development

No branches or pull requests

6 participants