Azure / Azure-Functions

1.11k stars 198 forks source link

Function app azure login with $ServicePrincipalId not working #1246

Open ghost opened 5 years ago

ghost commented 5 years ago

I have created timer trigger inside function app, below is my specfiication

create function app on window machine stack - powershell consumption plan

i have powershell script

D:/home/CLI2/wbin/az.cmd login --service-principal -u $ServicePrincipalId -p $ServicePrincipalPass --tenant $ServicePrincipalTenant

i have installed azure cli in Kudu console.

when i run my timer trigger, getting below error while doing authentication.

2019-06-13T08:23:59.100 [Information] INFORMATION: Establishing authentication with Azure...:fb3fd119-f2bb-4316-b737-18af99a89185 2019-06-13T08:24:14.360 [Error] ERROR: ERROR: The command failed with an unexpected error. Here is the traceback: Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: ERROR: The command failed with an unexpected error. Here is the traceback: Exception: ERROR: The command failed with an unexpected error. Here is the traceback: Stack: 2019-06-13T08:24:14.392 [Error] ERROR: Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: Exception: Stack: 2019-06-13T08:24:14.414 [Error] ERROR: ERROR: 'NoneType' object is not callable Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: ERROR: 'NoneType' object is not callable Exception: ERROR: 'NoneType' object is not callable Stack: 2019-06-13T08:24:14.441 [Error] ERROR: Traceback (most recent call last): Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: Traceback (most recent call last): Exception: Traceback (most recent call last): Stack: 2019-06-13T08:24:14.467 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\knack\knack\cli.py", line 206, in invoke Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\knack\knack\cli.py", line 206, in invoke Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\knack\knack\cli.py", line 206, in invoke Stack: 2019-06-13T08:24:14.495 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands__init.py", line 523, in execute Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands__init.py", line 523, in execute Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands__init.py", line 523, in execute Stack: 2019-06-13T08:24:14.525 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands__init.py", line 581, in _run_jobs_serially Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands__init.py", line 581, in _run_jobs_serially Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands__init.py", line 581, in _run_jobs_serially Stack: 2019-06-13T08:24:14.550 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands__init.py", line 574, in _run_job Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands__init.py", line 574, in _run_job Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands__init.py", line 574, in _run_job Stack: 2019-06-13T08:24:14.580 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\six\six.py", line 693, in reraise Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\six\six.py", line 693, in reraise Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\six\six.py", line 693, in reraise Stack: 2019-06-13T08:24:14.606 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\init__.py", line 551, in _run_job Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\init__.py", line 551, in _run_job Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\init__.py", line 551, in _run_job Stack: 2019-06-13T08:24:14.632 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\init.py", line 289, in call__ Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\init.py", line 289, in call__ Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\init.py", line 289, in call__ Stack: 2019-06-13T08:24:14.648 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\init__.py", line 453, in default_command_handler Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\init__.py", line 453, in default_command_handler Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\init__.py", line 453, in default_command_handler Stack: 2019-06-13T08:24:14.685 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-profile\azure\cli\command_modules\profile\custom.py", line 133, in login Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-profile\azure\cli\command_modules\profile\custom.py", line 133, in login Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-profile\azure\cli\command_modules\profile\custom.py", line 133, in login Stack: 2019-06-13T08:24:14.905 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 204, in find_subscriptions_on_login Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 204, in find_subscriptions_on_login Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 204, in find_subscriptions_on_login Stack: 2019-06-13T08:24:15.025 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 808, in find_from_service_principal_id Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 808, in find_from_service_principal_id Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 808, in find_from_service_principal_id Stack: 2019-06-13T08:24:15.103 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 853, in _find_using_specific_tenant Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 853, in _find_using_specific_tenant Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 853, in _find_using_specific_tenant Stack: 2019-06-13T08:24:15.147 [Error] ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 751, in create_arm_client_factory Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 751, in create_arm_client_factory Exception: File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core_profile.py", line 751, in create_arm_client_factory Stack: 2019-06-13T08:24:15.171 [Error] ERROR: TypeError: 'NoneType' object is not callable Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: TypeError: 'NoneType' object is not callable Exception: TypeError: 'NoneType' object is not callable Stack: 2019-06-13T08:24:15.186 [Error] ERROR: WARNING: Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: WARNING: Exception: WARNING: Stack: 2019-06-13T08:24:15.205 [Error] ERROR: To open an issue, please run: 'az feedback' Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: To open an issue, please run: 'az feedback' Exception: To open an issue, please run: 'az feedback' Stack:

ColbyTresness commented 5 years ago

@eamonoreilly

eamonoreilly commented 5 years ago

We have not tested Az Cli within the PowerShell worker (or any other language). I see you have copied this in manually using Kudo and it is failing. We do have constraints on some types of calls within the service so it might be hitting one of these when it tries to authenticate. I'll see if I have time to investigate further and update the issue. Are there specific calls you want to do with Az CLI that are not available with the Az modules? Thanks, Eamon

ghost commented 5 years ago

i am new to powershell scripts, and i have power shell script which uses cli commands to execute some task. ideally i am trying to delete older images from container registry. az acr repository delete --name $AzureRegistryName --image $ImageName --yes

please let me know how can i achieve this with az modules. or any other solution which works in powershell or any other scripting language

eamonoreilly commented 5 years ago

There is not a PowerShell equivalent for this yet. It is tracked on https://github.com/Azure/azure-powershell/issues/7599

I'll have to do some research to see what other options might be available. Thanks, Eamon

tyler-suard-parker commented 4 months ago

@eamonoreilly Is there a way to install and use azure cli in a web app? As of right now I install azure cli during my build phase, but after being deployed my web app can't find the az command.