Azure / azure-cli

Azure Command-Line Interface
MIT License
4k stars 2.98k forks source link

az login as service principal fails, JSONDecodeError: Expecting value: line 1 column 1 (char 0) #26267

Closed iTiamo closed 1 year ago

iTiamo commented 1 year ago

Describe the bug

It seems that an empty body is returned when trying to login as a service principal.

Command Name az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID --output none

Errors:

The command failed with an unexpected error. Here is the traceback:
Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/command_modules/profile/custom.py", line 139, in login
    subscriptions = profile.login(
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/_profile.py", line 159, in login
    identity.login_with_service_principal(username, password, scopes=scopes)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/auth/identity.py", line 188, in login_with_service_principal
    self._service_principal_store.save_entry(entry)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/auth/identity.py", line 321, in save_entry
    self._load_persistence()
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/auth/identity.py", line 350, in _load_persistence
    self._entries = self._secret_store.load()
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/decorators.py", line 102, in _wrapped_func
    return func(*args, **kwargs)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/auth/persistence.py", line 67, in load
    return json.loads(self._persistence.load())
  File "/opt/az/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/opt/az/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/az/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

Expected Behavior

To be logged in as the service principal

Environment Summary

Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.31, Ubuntu 20.04.6 LTS
Python 3.10.10
Installer: DEB

azure-cli 2.48.1

Extensions:
appservice-kube 0.1.7
automation 0.2.1
azure-devops 0.26.0
bastion 0.2.3
connectedk8s 1.3.2
customlocation 0.1.3
k8s-extension 1.3.3
ssh 1.1.3

Dependencies:
msal 1.20.0
azure-mgmt-resource 22.0.0

Additional Context

yonzhan commented 1 year ago

Thank you for opening this issue, we will look into it.

iTiamo commented 1 year ago

I expected the issue to be related to the release of 2.48.x yesterday. I downgraded to 2.46.0 and ran into the same issue.

iTiamo commented 1 year ago

az account clear fixed the issue