Keyring backend, that automatically retrieves credentials for Azure Artifacts.
Project description
Keyring for Azure DevOps Artifacts
Overview
The keyrings.artifacts backend integrates with the keyring library to provide authentication for publishing or consuming Python packages to or from Azure Artifacts feeds within Azure DevOps. The package is a platform-agnostic, plain Python implementation of the original artifact-keyring package leverageging azure-identity, without its dependency on DotNet.
The package is designed to be used with the pixi, uv or pip package manager to authenticate with Azure DevOps Artifacts. It provides a secure and convenient way to store and retrieve credentials without exposing them in the source code or local configuration files.
Disclaimer
Warning: This package is in an early development stage and may contain bugs or other issues. It is recommended to use this package for local development and testing purposes only, and not in production environments or CI pipelines. Please report any issues or bugs you encounter to help us improve the package.
Acknowledgements
This package was heavily inspired by a pull request of tomporaer and javuc1 in Microsoft's artifacts-keyring repository and their idea of a plain Python version. Since the PR has not been merged since February 2023, it seems unlikely that it will be merged, which led to the decision to create this package.
Installation
Detailed documentation on how to setup the usage can be found in the respective package manager documentation:
Note: As the
keyrings.artifactspackage is a drop-in replacement for the originalartifact-keyringpackage and it supports the same methods (and more). To use thekeyrings.artifactspackage, follow the same installation and configuration instructions provided in the listed documentations below, but replace the package name accordingly.
pipis available in the pip documentation.pixiis available in the Pixi documentation.uvis available in the uv documentation.
System-Wide Installation
Following the installation and configuration instructions in the pip documentation, keyring and third-party backends should best be installed system-wide. The simplest way to install the keyring with keyrings.artifacts-backend system-wide is to use pixi, uv (If don't know uv yet, I suggest you to check it out here) and pipx:
pixi
Note:
pixiversion 0.33.0rc1 or higher is required to install multiple packages into the global environment. If you are using an older version ofpixi, please update to the latest version usingpixi self-update.
# Install keyring and keyrings.artifacts globally from conda-forge using pixi
pixi global install --environment keyring --expose keyring keyring keyrings.artifacts
uv
# Install keyring and the keyrings.artifacts from PyPI using uv
uv tool install keyring --with keyrings.artifacts
pipx
# Install keyring from PyPI using pipx and inject the keyrings.artifacts package
$ pipx install keyring && pipx inject keyring keyrings.artifacts
Usage
Command Line
If you don't have a token stored in the system keyring, you can fetch and store it interactively using the keyring command line tool:
$ keyring get https://pkgs.dev.azure.com/{organization}/{project}/_packaging/{feed}/pypi/simple/ VssSessionToken
If you already have a token stored in the system keyring and want to update it, you can use the keyring command line tool:
# first delete the existing token
$ keyring del https://pkgs.dev.azure.com/{organization}/{project}/_packaging/{feed}/pypi/simple/ VssSessionToken
# then fetch and store the new token
$ keyring get https://pkgs.dev.azure.com/{organization}/{project}/_packaging/{feed}/pypi/simple/ VssSessionToken
Note:
keyrings.artifactspackage handles the token refresh of expired tokens automatically, so you don't need to worry about it. 🤓
How It Works
The keyrings.artifacts package extends the keyring library to securely manage credentials for Azure DevOps Artifacts. It supports authentication using either bearer tokens or personal access tokens (PATs), configurable via the KEYRINGS_ARTIFACTS_USE_BEARER_TOKEN environment variable (default is False).
Authentication Methods
The package supports two authentication methods:
-
Bearer Token Authentication: Set
KEYRINGS_ARTIFACTS_USE_BEARER_TOKENtoTrueto use bearer tokens. Authentication methods for obtaining a bearer token include:- Using environment variables for the
EnvironmentCredentialprovider. This provider is capable of authenticating as a service principal using a client secret or a certificate, or as a user with a username and password, and requires setting a few environment variables. Learn more - Requesting a token from the Azure CLI (requires prior
az login). Learn more - Shared token cache. Learn more
- Interactive browser-based authentication. Learn more
- Device code authentication. Learn more
- Using environment variables for the
-
Personal Access Token (PAT) Authentication: To use a personal access token (PAT), set
KEYRINGS_ARTIFACTS_USE_BEARER_TOKENtoFalse. The package will automatically manage the PAT as follows:-
If the
AZURE_DEVOPS_EXT_PATenvironment variable is set, this token will be used. -
If
AZURE_DEVOPS_EXT_PATis not set, the package will look for a stored PAT in the system keyring. -
If no PAT is found, a new PAT will be generated and stored in the system keyring. The duration of the PAT can be configured using the
AZURE_DEVOPS_PAT_DURATIONenvironment variable (default is 365 days).Note: To generate a new PAT, an intermediate bearer token authentication is required. The bearer token can be obtained using any of the methods mentioned above.
Any new PAT will be stored in the system keyring for future use. Depending on the operating system, the following keyrings are used:
- Windows: Stored in Windows Credential Manager.
- macOS: Stored in macOS Keychain.
- Linux: Stored in the Secret Service API via
dbusor in an encrypted file usingkeyrings.alt.EncryptedKeyring.
Note: For more information on setting up and configuring system keyrings, refer to the keyring documentation.
-
Configuration Guidelines
Environment Variables
-
General Configuration:
KEYRINGS_ARTIFACTS_USE_BEARER_TOKEN: Set toTrueto use bearer tokens,Falseto use PATs (default isFalse).
-
Personal Access Token (PAT) Configuration:
AZURE_DEVOPS_EXT_PAT: This environment variable can be used to set a PAT for the package to use.AZURE_DEVOPS_PAT_DURATION: If a new PAT is generated, this environment variable sets the duration of the PAT in days (default is 365 days).
-
Bearer Token Configuration:
- Details about the environment variables required for the
EnvironmentCredentialprovider can be found in the Azure Identity documentation.
- Details about the environment variables required for the
Contributing
We welcome contributions to this project. Please refer to our Contributing Guidelines for more information on how to get involved.
Pixi package manager
We use pixi as our project and package manager. pixi is a cross-platform, multi-language package manager and workflow tool built on the foundation of the conda ecosystem. It provides developers with an experience similar to popular package managers like cargo or yarn, but for any language. Some of its key features include:
- Support for conda and PyPi packages, with global dependency resolution.
- Always includes an up-to-date lock file.
- Entirely written in Rust, making it super fast.
For more information on doing Python development with pixi, please refer to this tutorial.
Installing requirements
Once you've cloned the repository, you can prepare the project by executing:
pixi install -e dev
pixi run post-install
These commands install the necessary packages, set up the pre-commit hooks, and prepare the project for development. Verify the installation by running
pixi list
You should see the packages installed in the list.
For more detailed instructions on setting up your environment, including the use of the pixi package manager, refer to the Setting Up Your Development Environment section in CONTRIBUTING.md.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keyrings_artifacts-1.0.2.tar.gz.
File metadata
- Download URL: keyrings_artifacts-1.0.2.tar.gz
- Upload date:
- Size: 50.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6368c6df12e9ab42aa6fe871bd545811429acd5d67e8abada68d4cc3ee4f034
|
|
| MD5 |
b7945fb6d0e3989646326b88e9900d64
|
|
| BLAKE2b-256 |
4bf5f37ee581a3b45183f18fe57904d5fc90ec0195631b98e68137e13e55ebc8
|
Provenance
The following attestation bundles were made for keyrings_artifacts-1.0.2.tar.gz:
Publisher:
release.yml on jslorrma/keyrings.artifacts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keyrings_artifacts-1.0.2.tar.gz -
Subject digest:
d6368c6df12e9ab42aa6fe871bd545811429acd5d67e8abada68d4cc3ee4f034 - Sigstore transparency entry: 248639673
- Sigstore integration time:
-
Permalink:
jslorrma/keyrings.artifacts@667a1e5b16a90e37b386faa9206f8524263dd6be -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/jslorrma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@667a1e5b16a90e37b386faa9206f8524263dd6be -
Trigger Event:
push
-
Statement type:
File details
Details for the file keyrings_artifacts-1.0.2-py3-none-any.whl.
File metadata
- Download URL: keyrings_artifacts-1.0.2-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c62666931adb15c0d2f6b1ad4d0a87ce566b24f7e5fa04dd31305c82981f2fa
|
|
| MD5 |
876bfb5eae913c2ff5cd9a36aa7eb27a
|
|
| BLAKE2b-256 |
0a6f4aaa50f7cc0832a05b12a9f872c87a4ab1727076d78bce018771348f22c6
|
Provenance
The following attestation bundles were made for keyrings_artifacts-1.0.2-py3-none-any.whl:
Publisher:
release.yml on jslorrma/keyrings.artifacts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keyrings_artifacts-1.0.2-py3-none-any.whl -
Subject digest:
6c62666931adb15c0d2f6b1ad4d0a87ce566b24f7e5fa04dd31305c82981f2fa - Sigstore transparency entry: 248639682
- Sigstore integration time:
-
Permalink:
jslorrma/keyrings.artifacts@667a1e5b16a90e37b386faa9206f8524263dd6be -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/jslorrma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@667a1e5b16a90e37b386faa9206f8524263dd6be -
Trigger Event:
push
-
Statement type: