microsoft/artifacts-keyring

pip install from azure dev asking for username & password for pkgs.dev.azure.com

saideep2407 opened this issue · 5 comments

I am trying to install package from azure repo with the index url https://pkgs.dev.azure.com/****/_packaging/****/pypi/simple/ but I am getting below issue:
Looking in indexes: https://pkgs.dev.azure.com/****/_packaging/****/pypi/simple/

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
at NuGetCredentialProvider.Program.

d__11.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
at NuGetCredentialProvider.Program.Main(String[] args)
at NuGetCredentialProvider.Program.(String[] args)
WARNING: Keyring is skipped due to an exception: Failed to get credentials: process with PID 17148 exited with code 3762504530; additional error message:
User for pkgs.dev.azure.com:

@saideep2407 , how did you install the artifacts-keyring? Which OS platform you are running on? Can you share the command line you are calling?

Closing it since we haven't had a reply. Feel free to re-open it in case you can provide the information requested

Hitting the same issue on Arch linux (Manjaro), python 3.9.9, dotnet SDK/Runtime (6.0.100 [/usr/share/dotnet/sdk], Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]):

$ python39 -m venv .venv
$ source .venv/bin/activate
$ pip install artifacts-keyring
...
$ pip install <package> --extra-index-url=<azure_pypi_url>
Looking in indexes: https://pypi.org/simple, <azure_pypi_url>
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Security.Cryptography.ProtectedData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

File name: 'System.Security.Cryptography.ProtectedData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at NuGetCredentialProvider.Util.EncryptedFile.ReadFileBytes(String filePath, Boolean readUnencrypted)
   at NuGetCredentialProvider.Util.SessionTokenCache.ReadFileBytes()
   at NuGetCredentialProvider.Util.SessionTokenCache.get_Cache()
   at NuGetCredentialProvider.Util.SessionTokenCache.TryGetValue(Uri key, String& value)
   at NuGetCredentialProvider.RequestHandlers.GetAuthenticationCredentialsRequestHandler.TryCache(GetAuthenticationCredentialsRequest request, String& cachedToken)
   at NuGetCredentialProvider.RequestHandlers.GetAuthenticationCredentialsRequestHandler.HandleRequestAsync(GetAuthenticationCredentialsRequest request)
   at NuGetCredentialProvider.Program.Main(String[] args)
   at NuGetCredentialProvider.Program.<Main>(String[] args)
WARNING: Keyring is skipped due to an exception: Failed to get credentials: process with PID 2151029 exited with code -6; additional error message: 
User for pkgs.dev.azure.com: ^CERROR: Operation cancelled by user
$

NOTE: Digging into the above sources I only have: /usr/share/dotnet/sdk/6.0.100/System.Security.Cryptography.ProtectedData.dll

The community supported dotnet-sdk options are:

$ yay -Ss dotnet-sdk
aur/dotnet-sdk-3.0 3.0.3.sdk103-4 (+0 0.00) 
    The .NET Core SDK (binary) - End-of-life
aur/dotnet-sdk-lts-bin 3.1.201-1 (+0 0.00) 
    Provides the .NET core software development kit (sdk).
aur/dotnet-sdk-2.2-vs2017 2.2.8.sdk110-1 (+0 0.00) 
    The .NET Core SDK binary version 2.2 - latest (End of Life) Visual Studio 2017 compatible
aur/dotnet-sdk-2.2 2.2.8.sdk207-1 (+1 0.00) 
    The .NET Core SDK binary version 2.2 - latest (End of Life)
aur/dotnet-sdk-1.1 1.0.4-1 (+1 0.00) (Orphaned) (Out-of-date: 2018-06-11) 
    Provides the .NET core software development kit (sdk).
aur/dotnet-sdk-5.0-bin 5.0.13.sdk404-1 (+3 1.24) 
    The .NET Core SDK version 5.0 (binary)
aur/dotnet-sdk-2.1 2.1.30.sdk818-1 (+4 0.00) 
    The .NET Core SDK version 2.1
aur/dotnet-sdk-preview-bin 6.0.0.sdk100+rc.2.21505.57-2 (+11 0.21) 
    The .NET Core SDK (preview, binary)
aur/dotnet-sdk-bin 6.0.1.sdk101-4 (+33 2.37) 
    The .NET Core SDK (binary)
community/dotnet-sdk-3.1 3.1.20.sdk120-1 (39.8 MiB 143.1 MiB) 
    The .NET Core SDK
community/dotnet-sdk 6.0.0.sdk100-2 (70.1 MiB 268.4 MiB) (Installed)
    The .NET Core SDK
$

Virtual env state:

$ pip list
Package            Version
------------------ ---------
artifacts-keyring  0.3.1
certifi            2021.10.8
cffi               1.15.0
charset-normalizer 2.0.9
cryptography       36.0.1
idna               3.3
importlib-metadata 4.10.0
jeepney            0.7.1
keyring            23.5.0
pip                21.3.1
pycparser          2.21
requests           2.27.0
SecretStorage      3.3.1
setuptools         58.1.0
urllib3            1.26.7
zipp               3.7.0
$

Workaround is to downgrade to: pip install artifacts-keyring==0.2.9, to get the old behaviour of prompting via the Web Authentication if no PAT is set in the environment yet.

@edgarrs I'm also seeing the same issue after following the instructions verbatim from Azure DevOps for connecting to a pip artifacts feed.

> pip install -i *** pkg_a pkg_b
Looking in indexes: ***

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
   at NuGetCredentialProvider.Program.<Main>d__11.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine)
   at NuGetCredentialProvider.Program.Main(String[] args)
   at NuGetCredentialProvider.Program.<Main>(String[] args)
WARNING: Keyring is skipped due to an exception: Failed to get credentials: process with PID 1800 exited with code 3762504530; additional error message:
> python --version
Python 3.9.13

Search paths:
Procmon_qKwHeCFSPJ

I'm on Windows 11 (22000.795), using PowerShell 7 inside of the VS command prompt.

The root cause may likely be related to a long filesystem path. The Python distribution I'm using comes from the Windows store, and the path is long enough that I can't directly extract a zip folder to the same path that artifacts-keyring is installed to.

I can confirm it works after installing Python to C:\Python310 and running the exact same steps.