Azure / login

Connect to Azure
MIT License
308 stars 291 forks source link

Azure Login error #312

Closed peeyushverma256 closed 1 year ago

peeyushverma256 commented 1 year ago

We are using azure/login@1 as OIDC from github to azure login It was working fine earlier but since today morning facing the below error { "Error": "You cannot call a method on a null-valued expression." } Error: Azure PowerShell Login failed. Please check the credentials and make sure az is installed on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"

Not sure why but nothing has been changed only this action is failing.

Please assist asap

YanaXu commented 1 year ago

Hi @peeyushverma256 ,

Could you provide your workflow file, rerun the workflow with "Enable debug logging", and provide the debug output? And do you run this on a GitHub-hosted runner or a self-hosted runner? Thanks.

peeyushverma256 commented 1 year ago

Logs for login failed 2023-05-05T07:56:42.6894568Z ##[debug]Evaluating condition for step: 'Login to azure' 2023-05-05T07:56:42.6896948Z ##[debug]Evaluating: success() 2023-05-05T07:56:42.6897742Z ##[debug]Evaluating success: 2023-05-05T07:56:42.6898389Z ##[debug]=> true 2023-05-05T07:56:42.6899109Z ##[debug]Result: true 2023-05-05T07:56:42.6900729Z ##[debug]Starting: Login to azure 2023-05-05T07:56:42.8540838Z ##[debug]Loading inputs 2023-05-05T07:56:42.8542834Z ##[debug]Evaluating: secrets.AZURE_CLIENT_ID 2023-05-05T07:56:42.8543387Z ##[debug]Evaluating Index: 2023-05-05T07:56:42.8543767Z ##[debug]..Evaluating secrets: 2023-05-05T07:56:42.8544189Z ##[debug]..=> Object 2023-05-05T07:56:42.8544573Z ##[debug]..Evaluating String: 2023-05-05T07:56:42.8544982Z ##[debug]..=> 'AZURE_CLIENT_ID' 2023-05-05T07:56:42.8545983Z ##[debug]=> '' 2023-05-05T07:56:42.8546493Z ##[debug]Result: '' 2023-05-05T07:56:42.8547513Z ##[debug]Evaluating: secrets.AZURE_TENANT_ID 2023-05-05T07:56:42.8547921Z ##[debug]Evaluating Index: 2023-05-05T07:56:42.8548298Z ##[debug]..Evaluating secrets: 2023-05-05T07:56:42.8548813Z ##[debug]..=> Object 2023-05-05T07:56:42.8549177Z ##[debug]..Evaluating String: 2023-05-05T07:56:42.8549588Z ##[debug]..=> 'AZURE_TENANT_ID' 2023-05-05T07:56:42.8550144Z ##[debug]=> '' 2023-05-05T07:56:42.8550637Z ##[debug]Result: '' 2023-05-05T07:56:42.8551496Z ##[debug]Evaluating: secrets.AZURE_SUBSCRIPTION_ID 2023-05-05T07:56:42.8551948Z ##[debug]Evaluating Index: 2023-05-05T07:56:42.8552323Z ##[debug]..Evaluating secrets: 2023-05-05T07:56:42.8552708Z ##[debug]..=> Object 2023-05-05T07:56:42.8553083Z ##[debug]..Evaluating String: 2023-05-05T07:56:42.8553659Z ##[debug]..=> 'AZURE_SUBSCRIPTIONID' 2023-05-05T07:56:42.8554207Z ##[debug]=> '' 2023-05-05T07:56:42.8554662Z ##[debug]Result: '' 2023-05-05T07:56:42.8558482Z ##[debug]Loading env 2023-05-05T07:56:42.8566242Z ##[group]Run azure/login@v1 2023-05-05T07:56:42.8566590Z with: 2023-05-05T07:56:42.8567038Z client-id: 2023-05-05T07:56:42.8567413Z tenant-id: 2023-05-05T07:56:42.8567863Z subscription-id: 2023-05-05T07:56:42.8568244Z enable-AzPSSession: true 2023-05-05T07:56:42.8568625Z environment: azurecloud 2023-05-05T07:56:42.8569032Z allow-no-subscriptions: false 2023-05-05T07:56:42.8569484Z audience: api://AzureADTokenExchange 2023-05-05T07:56:42.8569865Z ##[endgroup] 2023-05-05T07:56:47.0452266Z ##[debug]az cli version used: C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd 2023-05-05T07:56:47.2280607Z ##[debug]az cli version used: 2023-05-05T07:56:47.2281185Z ##[debug]azure-cli 2.44.1 2023-05-05T07:56:47.2281615Z ##[debug] 2023-05-05T07:56:47.2282022Z ##[debug]core 2.44.1 * 2023-05-05T07:56:47.2282490Z ##[debug]telemetry 1.0.8 2023-05-05T07:56:47.2282906Z ##[debug] 2023-05-05T07:56:47.2283291Z ##[debug]Dependencies: 2023-05-05T07:56:47.2283741Z ##[debug]msal 1.20.0 2023-05-05T07:56:47.2284252Z ##[debug]azure-mgmt-resource 21.1.0b1 2023-05-05T07:56:47.2285184Z ##[debug] 2023-05-05T07:56:47.2285766Z ##[debug]Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' 2023-05-05T07:56:47.2286525Z ##[debug]Extensions directory '*****' 2023-05-05T07:56:47.2287024Z ##[debug] 2023-05-05T07:56:47.2287553Z ##[debug]Python (Windows) 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:37:59) [MSC v.1933 32 bit (Intel)] 2023-05-05T07:56:47.2288063Z ##[debug] 2023-05-05T07:56:47.2288546Z ##[debug]Legal docs and information: aka.ms/AzureCliLegal 2023-05-05T07:56:47.2289021Z ##[debug] 2023-05-05T07:56:47.2289352Z ##[debug] 2023-05-05T07:56:47.2289677Z ##[debug] 2023-05-05T07:56:47.2418671Z Using OIDC authentication... 2023-05-05T07:56:47.2547051Z ##[debug]ID token url is ***** 2023-05-05T07:56:47.6354369Z ::add-mask::* 2023-05-05T07:56:47.6530310Z Federated token details: 2023-05-05T07:56:47.6661134Z issuer - https://token.actions.githubusercontent.com 2023-05-05T07:56:47.6817294Z subject claim - repo:equinor/Shared-Integration-Services:environment:test 2023-05-05T07:56:47.7124689Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" cloud set -n azurecloud" 2023-05-05T07:56:49.3885088Z Done setting cloud: "azurecloud" 2023-05-05T07:56:53.9178238Z Running Azure PS Login 2023-05-05T07:56:53.9315472Z ##[debug]GetLatestModuleScript: try { 2023-05-05T07:56:53.9316052Z ##[debug] $ErrorActionPreference = "Stop" 2023-05-05T07:56:53.9316556Z ##[debug] $WarningPreference = "SilentlyContinue" 2023-05-05T07:56:53.9317008Z ##[debug] $output = @{} 2023-05-05T07:56:53.9317684Z ##[debug] $data = Get-Module -Name Az.Accounts -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1 2023-05-05T07:56:53.9318427Z ##[debug] $output['AzVersion'] = $data.Version.ToString() 2023-05-05T07:56:53.9318927Z ##[debug] $output['Success'] = "true" 2023-05-05T07:56:53.9319347Z ##[debug] } 2023-05-05T07:56:53.9319696Z ##[debug] catch { 2023-05-05T07:56:53.9320142Z ##[debug] $output['Error'] = $.exception.Message 2023-05-05T07:56:53.9320594Z ##[debug] } 2023-05-05T07:56:53.9321033Z ##[debug] return ConvertTo-Json $output 2023-05-05T07:56:53.9506595Z [command]"C:\Program Files\PowerShell\7\pwsh.exe" -Command "try { 2023-05-05T07:56:54.0173929Z $ErrorActionPreference = \"Stop\" 2023-05-05T07:56:54.0313098Z $WarningPreference = \"SilentlyContinue\" 2023-05-05T07:56:54.0343166Z $output = @{} 2023-05-05T07:56:54.0348007Z $data = Get-Module -Name Az.Accounts -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1 2023-05-05T07:56:54.0349318Z $output['AzVersion'] = $data.Version.ToString() 2023-05-05T07:56:54.0350163Z $output['Success'] = \"true\" 2023-05-05T07:56:54.0350810Z } 2023-05-05T07:56:54.0351654Z catch { 2023-05-05T07:56:54.0352386Z $output['Error'] = $_.exception.Message 2023-05-05T07:56:54.0353054Z } 2023-05-05T07:56:54.0353710Z return ConvertTo-Json $output" 2023-05-05T07:56:55.2359348Z { 2023-05-05T07:56:55.2360659Z "Error": "You cannot call a method on a null-valued expression." 2023-05-05T07:56:55.2361401Z } 2023-05-05T07:56:55.3552627Z ##[error]Azure PowerShell Login failed. Please check the credentials and make sure az is installed on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows" 2023-05-05T07:56:55.3780167Z ##[debug]Node Action run completed with exit code 1 2023-05-05T07:56:55.3794553Z ##[debug]AZURE_HTTP_USERAGENT='GITHUBACTIONS/AzureLogin@v1****/**' 2023-05-05T07:56:55.3796012Z ##[debug]AZUREPS_HOSTENVIRONMENT='GITHUBACTIONS/AzureLogin@v1**/' 2023-05-05T07:56:55.3796664Z ##[debug]AZURE_HTTP_USER_AGENT='' 2023-05-05T07:56:55.3797341Z ##[debug]AZUREPS_HOST_ENVIRONMENT='' 2023-05-05T07:56:55.3807255Z ##[debug]Finishing: Login to azure


using below snippit for login

Its working properly fine with my another selfhosted runner in another Environment (Dev) All the details are same for dev and Test but failing in Test

YanaXu commented 1 year ago

Hi @peeyushverma256 ,

Please add below action part right before "azure/login@v1". And rerun your workflow.

    - name: Test Azure module
      if: ${{ success() || failure() }}
      shell: pwsh
      run: |
        '---------------------------- step 1'
        $env:PSModulePath -split ';'
        '---------------------------- step 2'
        $env:PSModulePath = "C:\\Modules\\;$env:PSModulePath"
        '---------------------------- step 3'
        $data = Get-Module -Name Az.Accounts -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
        '---------------------------- step 4'
        $data.Version.ToString()
        '---------------------------- step 5'

Please check if $data.Version.ToString() fails with the same error message. If yes, double check the output of $env:PSModulePath -split ';' to see if any of the module paths contains Azure PowerShell. If none contain Azure modules, you have to install Azure PowerShell on this self-hosted runner first.

peeyushverma256 commented 1 year ago

Run '---------------------------- step 1' '---------------------------- step 1' $env:PSModulePath -split ';' '---------------------------- step 2' $env:PSModulePath = "C:\Modules\;$env:PSModulePath" '---------------------------- step 3' $data = Get-Module -Name Az.Accounts -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1 '---------------------------- step 4' $data.Version.ToString() '---------------------------- step 5' shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"

---------------------------- step 1 C:\Users\a_sdiv\Documents\PowerShell\Modules C:\Program Files\PowerShell\Modules c:\program files\powershell\7\Modules C:\Program Files\WindowsPowerShell\Modules C:\Windows\system32\WindowsPowerShell\v1.0\Modules C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\ C:\Program Files\Microsoft Monitoring Agent\Agent\AzureAutomation\7.3.1455.3 ---------------------------- step 2 ---------------------------- step 3 ---------------------------- step 4 InvalidOperation: C:\Appl\actions-runner_work_temp\866dca64-29d9-4079-8901-46a849a59bc6.ps1:9 Line | 9 | $data.Version.ToString() | ~~~~~~~~ | You cannot call a method on a null-valued expression. Error: Process completed with exit code 1.

YanaXu commented 1 year ago

Hi @peeyushverma256 ,

Please check my comment in the last reply. It seems no Azure PowerShell modules are installed on this self-hosted runner. You can double-check following folders:

C:\Users\a_sdiv\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\7\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell
C:\Program Files\Microsoft Monitoring Agent\Agent\AzureAutomation\7.3.1455.3
C:\Modules

Since you said it used to be OK, the Azure PowerShell modules may be removed from your runner, or the action of Azure PowerShell installation is removed from your workflow. Please confirm it.

YanaXu commented 1 year ago

Close this issue since it's an env issue on a self-hosted runner.