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

az login unexpected error: invalid argument #28156

Open
r0dg3rd0dg3r opened this issue Jan 8, 2024 · 11 comments
Open

az login unexpected error: invalid argument #28156

r0dg3rd0dg3r opened this issue Jan 8, 2024 · 11 comments
Assignees
Labels
Account az login/account Auto-Assign Auto assign by bot Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Milestone

Comments

@r0dg3rd0dg3r
Copy link

Describe the bug

We normally use az login before locally debugging microservices that use DefaultAzureCredential to fetch a token via Azure AD. As of a few days ago, attempting az lo az logingin from the command terminal results in an unexpected error.

Related command

az login

Errors

A web browser has been opened at https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with az login --use-device-code.

The command failed with an unexpected error. Here is the traceback:
[Errno 22] Invalid argument: 'C:\Users\rsmith\.azure\msal_token_cache.bin'
Traceback (most recent call last):
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 663, in execute
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 726, in _run_jobs_serially
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 697, in _run_job
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 333, in call
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/profile/custom.py", line 139, in login
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_profile.py", line 154, in login
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/auth/identity.py", line 160, in login_with_auth_code
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 1861, in acquire_token_interactive
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 281, in obtain_token_by_browser
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 639, in obtain_token_by_browser
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 677, in _obtain_token_by_browser
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 153, in obtain_token_by_auth_code_flow
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 205, in obtain_token_by_auth_code_flow
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 547, in obtain_token_by_auth_code_flow
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 731, in _obtain_token_by_authorization_code
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 116, in _obtain_token
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 788, in _obtain_token
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 707, in
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 317, in add
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 128, in add
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 247, in __add
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/token_cache.py", line 69, in modify
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/persistence.py", line 215, in save
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/persistence.py", line 137, in _open
OSError: [Errno 22] Invalid argument: 'C:\Users\\.azure\msal_token_cache.bin'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues


### Issue script & Debug output

cli.knack.cli: Command arguments: ['login', '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
Enable VT mode.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x0314E7F8>, <function OutputProducer.on_global_arguments at 0x034788E8>, <function CLIQuery.on_global_arguments at 0x034986B8>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'login': ['azure.cli.command_modules.profile']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name                  Load Time    Groups  Commands
cli.azure.cli.core: profile                   0.004         2         8
cli.azure.cli.core: Total (1)                 0.004         2         8
cli.azure.cli.core: Loaded 2 groups, 8 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command  : login
cli.azure.cli.core: Command table: login
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x0557AED8>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\rsmith\.azure\commands\2024-01-08.16-54-28.login.15768.log'.
az_command_data_logger: command args: login --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x0558CB18>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x055BA2A8>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x055BA2F8>]   
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x03478938>, <function CLIQuery.handle_query_parameter at 0x03498708>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x055BA258>]
cli.azure.cli.core.auth.persistence: build_persistence: location='C:\\Users\\rsmith\\.azure\\msal_token_cache.bin', encrypt=True
cli.azure.cli.core.auth.binary_cache: load: C:\Users\rsmith\.azure\msal_http_cache.bin
urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
msal.authority: openid_config = {'token_endpoint': 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt', 'client_secret_ba
sic'], 'jwks_uri': 'https://login.microsoftonline.com/organizations/discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'], 'id_token_signing_alg_val
ues_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer': 'https://login.microsoftonli
ne.com/{tenantid}/v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://graph.microsoft.com/oidc/userinfo', 'authorization_endpoint': 'https://login.microsoftonline.com/organizations/oauth2/v2.0/
authorize', 'device_authorization_endpoint': 'https://login.microsoftonline.com/organizations/oauth2/v2.0/devicecode', 'http_logout_supported': True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https:
//login.microsoftonline.com/organizations/oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name', 'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_tim
e', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint': 'https://login.microsoftonline.com/organizations/kerberos', 'tenant_region_scope': None, 'cloud_instance_name': 'microsoftonline.com', 'cloud_graph_host_name': 'graph.windows.net', 'msgraph_host': 'graph.microsoft.com', 'rbac_url': 'https://pas.windows.net'}
msal.application: Broker enabled? False
cli.azure.cli.core.auth.identity: A web browser has been opened at https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.
msal.telemetry: Generate or reuse correlation_id: 1c8b01ac-1aec-40fd-ae47-7cc2c14d657e
msal.oauth2cli.oauth2: Using http://localhost:50882 as redirect_uri
msal.oauth2cli.authcode: Abort by visit http://localhost:50882?error=abort
msal.oauth2cli.authcode: Open a browser on this device to visit: https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize?client_id=04b07795-8ddb-461a-bbee-02f9e1bf7b46&response_type=code&redirect_uri=http%3
A%2F%2Flocalhost%3A50882&scope=https%3A%2F%2Fmanagement.core.windows.net%2F%2F.default+offline_access+openid+profile&state=vsXKyoTnmWalcHZi&code_challenge=XjVeLatT59SJKEb_NqRpvztVs-ovN1nsgmaaF-47g7o&code_challenge_method=S256&nonce=da1d4bfbd0545bbd742b35af2b9527c9d09f875b94032da04103e7259ef29e40&client_info=1&claims=%7B%22access_token%22%3A+%7B%22xms_cc%22%3A+%7B%22values%22%3A+%5B%22CP1%22%5D%7D%7D%7D&prompt=select_account
msal.oauth2cli.authcode: Got auth response: {'code': '0.AW8A7btKZPwq80qL6u0_sQX-jJV3sATbjRpGu-4C-eG_e0ZvADU.AgABAAIAAAAmoFfGtYxvRrNriQdPKIZ-AgDs_wUA9P_us80F8DXLghzKqdeLLQX88qFdU5N5b-jZh9jB2xBfbHCTZyeEu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4zrf_qBVzYkW2PTOd9GQBHwYqir4hlx7KJFnmrSOxYUcd8AopanDrwDrhaXAFtVAR7u-pHB-sEtBgFVJl9x-vy0my1UQY9eI8lxjrRZyjtROuuTCH-_sxi-WqWzuxzNNMpU0OsJ2r2qzbmUb8-e7Vab4HM20CZrvQOZB2idQ1ZWyUC4cTlkM
Ec35ocnh0R6XZdiTeKTwuVUfA8E6yTmdixj6Kv7TdEsBzzkAWwYWWDHIB9lya70r4FDoid4m1e97PZkTNO_JBsi1ksTgowZLEVI8_AH&client_info=eyJ1aWQiOiJkNDkwYTZkNC0yNTJkLTQ4OTgtYmE4OS00NmY3MTJmMGNkYzIiLCJ1dGlkIjoiNjQ0YWJiZWQtMmFmYy00YWYzLThiZWEtZWQzZmIxMDVmZThjIn0&state=vsXKyoTnmWalcHZi&session_state=acc097ca-257c-47c1-bf76-0fcf84ba3403 HTTP/1.1" 200 -
urllib3.connectionpool: Starting new HTTPS connection (1): login.microsoftonline.com:443
urllib3.connectionpool: https://login.microsoftonline.com:443 "POST /organizations/oauth2/v2.0/token HTTP/1.1" 200 7019
msal.token_cache: event={
    "client_id": "04b07795-8ddb-461a-bbee-02f9e1bf7b46",
    "data": {
        "claims": "{\"access_token\": {\"xms_cc\": {\"values\": [\"CP1\"]}}}",
        "client_id": "04b07795-8ddb-461a-bbee-02f9e1bf7b46",
        "code": "0.AW8A7btKZPwq80qL6u0_sQX-jJV3sATbjRpGu-4C-eG_e0ZvADU.AgABAAIAAAAmoFfGtYxvRrNriQdPKIZ-AgDs_wUA9P_us80F8DXLghzKqdeLLQX88qFdU5N5b-jZh9jB2xBfbHCTZyeEuRrXpo3EUzTK6La1GKxFk9-WKFuwoqNqTWwlnOP6U0k_ew9FjoUyOQb-b
6TnHhLEVt8c9aYu-Hojm7fuh6ecO2Wcltsg4lBoNx8jtDjjuZU8Pb4IERq_H32LQDerhoidAg-BwO6uw8Ed3SIufZTtNVNlLsyw3XGuE79Bg5Sw_Fo53PDtkUNtdnHF4rcF2KOwyh80QjBc13YHQaoWwbdhERGwrYiuAMFkXiEKZpP8NsNXlR80cv4ZH2YEdrPgDO2gcisP9UcIyBgNkDpuLYt9X
9SkqdJYIUwFe_CcMpmT2jV_moJSoJyIsw_3EsYO_cZ_rmUAK2og_3gS-N2nsxY3CBzXwdHirmGjb5kTOnvemwSX-LPj1k03HzB-d89KA3PzN239C5IYJD6MpYRjUtt7JpROP3w2Lg7ehpi3YpEzHUlqjk6GLooZNFjdVebDSnbkAhVeTpj8fomKs7BBBgOoI2cI2Cs93Jd8ZcwM4ShR13ldHWwJo
ZSGafONPXSmUYN5pSS7B91kAUsiK0yBSbR7axpSLYjylkiu8xPIOYmT-JaRethgaWKLrlnz26FcfLFD0CQPm2wwFQD9KGjKOCRnJ_tzYqtp_00ONt_3-dYl_ROB-MIlN1zBOdC3LtYDbxXNPMjH9CriKvJbqomhsP8FtIZveOIqnZXCdyMhK--zLJmlIevRQYbzvVVNXAxFf7mowlPWg0LJ7DWnv
QcGqLx2_HaKU0VLIXDtS4zrf_qBVzYkW2PTOd9GQBHwYqir4hlx7KJFnmrSOxYUcd8AopanDrwDrhaXAFtVAR7u-pHB-sEtBgFVJl9x-vy0my1UQY9eI8lxjrRZyjtROuuTCH-_sxi-WqWzuxzNNMpU0OsJ2r2qzbmUb8-e7Vab4HM20CZrvQOZB2idQ1ZWyUC4cTlkMEc35ocnh0R6XZdiTeKTwuVUfA8E6yTmdixj6Kv7TdEsBzzkAWwYWWDHIB9lya70r4FDoid4m1e97PZkTNO_JBsi1ksTgowZLEVI8_AH",
        "code_verifier": "l-~hBQwcnWJYf601NqRLy.gGum8ESa72vxToV_rziZH",
        "redirect_uri": "http://localhost:50882",
        "scope": [
            "openid",
            "offline_access",
            "https://management.core.windows.net//.default",
            "profile"
        ]
    },
    "environment": "login.microsoftonline.com",
    "grant_type": "authorization_code",
    "params": null,
    "response": {
        "access_token": "********",
        "client_info": "eyJ1aWQiOiJkNDkwYTZkNC0yNTJkLTQ4OTgtYmE4OS00NmY3MTJmMGNkYzIiLCJ1dGlkIjoiNjQ0YWJiZWQtMmFmYy00YWYzLThiZWEtZWQzZmIxMDVmZThjIn0",
        "expires_in": 4984,
        "ext_expires_in": 4984,
        "foci": "1",
        "id_token": "********",
        "refresh_token": "********",
        "scope": "https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default",
        "token_type": "Bearer"
    },
    "scope": [
        "https://management.core.windows.net//user_impersonation",
        "https://management.core.windows.net//.default"
    ],
    "token_endpoint": "https://login.microsoftonline.com/organizations/oauth2/v2.0/token"
}
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/profile/custom.py", line 139, in login
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_profile.py", line 154, in login
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/auth/identity.py", line 160, in login_with_auth_code
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 1861, in acquire_token_interactive
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 281, in obtain_token_by_browser
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 639, in obtain_token_by_browser
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 677, in _obtain_token_by_browser
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 153, in obtain_token_by_auth_code_flow
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 205, in obtain_token_by_auth_code_flow
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 547, in obtain_token_by_auth_code_flow
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 731, in _obtain_token_by_authorization_code
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 116, in _obtain_token
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 788, in _obtain_token
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 707, in <lambda>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 317, in add
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 128, in add
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 213, in __add
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/token_cache.py", line 69, in modify
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/persistence.py", line 215, in save
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/persistence.py", line 137, in _open
OSError: [Errno 22] Invalid argument: 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin'

cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback:
az_command_data_logger: The command failed with an unexpected error. Here is the traceback:
cli.azure.cli.core.azclierror: [Errno 22] Invalid argument: 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin'
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/profile/custom.py", line 139, in login
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_profile.py", line 154, in login
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/auth/identity.py", line 160, in login_with_auth_code
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 1861, in acquire_token_interactive
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 281, in obtain_token_by_browser
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 639, in obtain_token_by_browser
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 677, in _obtain_token_by_browser
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 153, in obtain_token_by_auth_code_flow
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 205, in obtain_token_by_auth_code_flow
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 547, in obtain_token_by_auth_code_flow
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 731, in _obtain_token_by_authorization_code
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 116, in _obtain_token
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 788, in _obtain_token
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 707, in <lambda>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 317, in add
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 128, in add
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 213, in __add
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/token_cache.py", line 69, in modify
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/persistence.py", line 215, in save
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/persistence.py", line 137, in _open
OSError: [Errno 22] Invalid argument: 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin'
az_command_data_logger: [Errno 22] Invalid argument: 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin'
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/profile/custom.py", line 139, in login
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/_profile.py", line 154, in login
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/auth/identity.py", line 160, in login_with_auth_code
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 1861, in acquire_token_interactive
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 281, in obtain_token_by_browser
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 639, in obtain_token_by_browser
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 677, in _obtain_token_by_browser
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 153, in obtain_token_by_auth_code_flow
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 205, in obtain_token_by_auth_code_flow
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 547, in obtain_token_by_auth_code_flow
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 731, in _obtain_token_by_authorization_code
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oidc.py", line 116, in _obtain_token
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/oauth2cli/oauth2.py", line 788, in _obtain_token
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/application.py", line 707, in <lambda>
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 317, in add
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 128, in add
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal/token_cache.py", line 213, in __add
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/token_cache.py", line 69, in modify
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/persistence.py", line 215, in save
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/persistence.py", line 137, in _open
OSError: [Errno 22] Invalid argument: 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x0557E078>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 6.109 seconds (init: 0.352, invoke: 5.757)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 6974 in cache
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages\azure\cli\telemetry\__init__.pyc C:\Users\rsmith\.azure"
telemetry.process: Return from creating process
telemetry.main: Finish creating telemetry upload process.


### Expected behavior

normal fetching of the token for locally developing against azure server

### Environment Summary

azure-cli                         2.55.0

core                              2.55.0
telemetry                          1.1.0

Dependencies:
msal                            1.24.0b2
azure-mgmt-resource             23.1.0b2

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\<my user>\.azure\cliextensions'

Python (Windows) 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:21:31) [MSC v.1936 32 bit (Intel)]


### Additional context

_No response_
@r0dg3rd0dg3r r0dg3rd0dg3r added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Jan 8, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. Auto-Assign Auto assign by bot Account az login/account labels Jan 8, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Azure CLI Team The command of the issue is owned by Azure CLI team label Jan 8, 2024
@yonzhan
Copy link
Collaborator

yonzhan commented Jan 8, 2024

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

@microsoft-github-policy-service microsoft-github-policy-service bot added the question The issue doesn't require a change to the product in order to be resolved. Most issues start as that label Jan 8, 2024
@yonzhan yonzhan added this to the Backlog milestone Jan 8, 2024
@yonzhan yonzhan removed the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Jan 8, 2024
@jiasli
Copy link
Member

jiasli commented Jan 9, 2024

OSError: [Errno 22] Invalid argument indicates incorrect file name, but 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin' looks totally valid.

I am also not able to repro this Errno 22 by executing:

> & "C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe"
>>> open('C:\\Users\\rsmith\\.azure\\msal_token_cache.bin')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin'

@r0dg3rd0dg3r, could you try the above commands and check the output? You need to run python.exe with & "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe" as you are using 32-bit Azure CLI.

@rayluo, by any chance you have encountered this issue before?

@rayluo
Copy link
Member

rayluo commented Jan 9, 2024

@r0dg3rd0dg3r , how do you reproduce this error?

I do not remember encountering OSError: [Errno 22] Invalid argument. That being said, I hardly use/test with MSAL Extension's persistence in my usage. Or perhaps if @jiasli can guide @r0dg3rd0dg3r to temporarily turn off encryption to see if it makes any difference.

@jiasli
Copy link
Member

jiasli commented Jan 9, 2024

In my opinion, if 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin' is invalid, 'C:\\Users\\rsmith\\.azure\\msal_token_cache.json' can also be invalid. 🤔

@r0dg3rd0dg3r
Copy link
Author

PS C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2> python
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec 7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

open('C:\Users\rsmith\.azure\msal_token_cache.bin')
<_io.TextIOWrapper name='C:\Users\rsmith\.azure\msal_token_cache.bin' mode='r' encoding='cp1252'>

@rayluo
Copy link
Member

rayluo commented Jan 9, 2024

In my opinion, if 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin' is invalid, 'C:\\Users\\rsmith\\.azure\\msal_token_cache.json' can also be invalid. 🤔

Empirically, encryption (DPAPI) could raise some weird errors and we never really know why. There are multiple issues reported before in Azure CLI issues, although not necessarily this OSError: [Errno 22] Invalid argument.

Regardless, we can't really investigate without a reproduce.

@r0dg3rd0dg3r
Copy link
Author

Any recommendation of what to try next?

@r0dg3rd0dg3r
Copy link
Author

Running this command seems to have gotten me past it, but I don't know why.
az config set core.encrypt_token_cache=false

@rayluo
Copy link
Member

rayluo commented Jan 9, 2024

Running this command seems to have gotten me past it, but I don't know why. az config set core.encrypt_token_cache=false

Interesting.

The last line in log before that error was:

File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\msal_extensions/persistence.py", line 137, in _open
OSError: [Errno 22] Invalid argument: 'C:\Users\rsmith\.azure\msal_token_cache.bin'

And that line 137 is here.

Perhaps @r0dg3rd0dg3r can manually run that line on your file, for example,

python -c "import os; os.open('C:\\Users\\rsmith\\.azure\\msal_token_cache.bin', os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0o600)"

And perhaps that can "reproduce" the error in your current environment.

Next, you may try renaming your existing problematic file into a different name, and then re-enable the encryption, and see if Azure CLI will generate a new file and work fine.

If you can reach that far, you may then somehow compare the old and new files and see what their difference is. Could it be the old file's handler somehow being occupied? Could it recover after a reboot? Anyway, I'm just guessing at this point...

@jiasli
Copy link
Member

jiasli commented Jan 10, 2024

PS C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2> python
Python 3.12.1 (tags/v3.12.1:2305ca5, Dec 7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32

@r0dg3rd0dg3r, this is not executing the python.exe (3.11.5) embedded in Azure CLI. In PowerShell, you have to run ./python.exe, otherwise it will execute the python.exe on PATH which is Python 3.12.1.

Running this command seems to have gotten me past it, but I don't know why. az config set core.encrypt_token_cache=false

@r0dg3rd0dg3r, this will make Azure CLI use 'C:\\Users\\rsmith\\.azure\\msal_token_cache.json' as the MSAL token cache, but as I pointed out in #28156 (comment), name-wise, 'C:\\Users\\rsmith\\.azure\\msal_token_cache.bin' is no more special than 'C:\\Users\\rsmith\\.azure\\msal_token_cache.json'.

Empirically, encryption (DPAPI) could raise some weird errors and we never really know why.

@rayluo, as you pointed out later, it hasn't reached DPAPI yet. It is merely an os.open function call.

@rayluo
Copy link
Member

rayluo commented Jan 10, 2024

Empirically, encryption (DPAPI) could raise some weird errors and we never really know why.

@rayluo, as you pointed out later, it hasn't reached DPAPI yet. It is merely an os.open function call.

I don't know whether a previous unsuccessful operation (stuck in a DPAPI call?) would cause the file handler still being "occupied". So, in my last message, I suggested @r0dg3rd0dg3r to run some tests to see whether the existing "msal_token_cache.bin" file can be opened. If that python -c "import os; os.open(...)" one-liner reproduce the same error on that old file (but not on any other new file), at least we can validate the assumption above. And we can go from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Account az login/account Auto-Assign Auto assign by bot Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

4 participants