Chainctl keyring backend for Python package authentication
Project description
keyrings-chainguard-libraries
Keyring backend for Chainguard Python Libraries
A Python keyring backend that provides seamless authentication to internal PyPI repositories using Chainguard's chainctl pull tokens.
Overview
This package extends Python's keyring library to automatically authenticate with private package repositories using chainctl pull tokens. When pip or other Python package managers request credentials for HTTPS repositories ending with .cgr.dev, this backend generates short-lived authentication tokens using the chainctl CLI tool.
Features
- Automatic Authentication: Seamlessly integrates with pip, poetry, and other Python package managers
- Token Caching: Caches credentials to minimize repeated
chainctlcalls - Secure Token Generation: Uses
chainctlto generate short-lived (8-hour) pull tokens - Tox Integration: Includes a tox plugin for authentication in test environments
Installation
pip install keyrings-chainguard-libraries
Prerequisites
- Python 3.7 or higher
chainctlCLI tool installed and configuredCHAINCTL_PARENTenvironment variable set to your organization's parent resource
Configuration
Set the required environment variable:
export CHAINCTL_PARENT="your-organization-parent-id"
Usage
Once installed, the keyring backend will automatically activate for HTTPS URLs ending with .cgr.dev. When pip or other tools request credentials for a private repository on a *.cgr.dev domain, the backend will:
- Check if credentials are cached
- If not cached, run
chainctl auth pull-tokento generate new credentials - Return the credentials to the requesting tool
Example with pip
# Install from a private Chainguard repository
pip install package-name --index-url https://libraries.cgr.dev/python/simple/
Manual Testing
You can test the keyring backend directly:
import keyring
from keyrings.chainctl_auth import ChainctlAuth
# Set the backend
keyring.set_keyring(ChainctlAuth())
# Get credentials for a Chainguard service
password = keyring.get_password("https://libraries.cgr.dev", "username")
How It Works
The ChainctlAuth backend:
- Intercepts credential requests for HTTPS services ending with
.cgr.dev - Executes
chainctl auth pull-token --library-ecosystem=python --parent=$CHAINCTL_PARENT --ttl=8h - Parses the username and password from the command output
- Caches the credentials for the service
- Returns the credentials to the requesting application
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/chainguard-dev/keyrings-chainguard-libraries
cd keyrings-chainguard-libraries
# Install in development mode with dev dependencies
pip install -e ".[dev]"
Running Tests
# Run tests
pytest
# Run tests with coverage
pytest --cov=keyrings.chainctl_auth
# Run linting
flake8
mypy keyrings/
Building
# Build the package
python -m build
Troubleshooting
Common Issues
-
"CHAINCTL_PARENT environment variable not set"
- Set the
CHAINCTL_PARENTenvironment variable to your organization's parent ID
- Set the
-
"chainctl command not found"
- Ensure
chainctlis installed and available in your PATH
- Ensure
-
Authentication failures
- Verify
chainctlis properly configured and authenticated - Check that your organization has access to the target repository
- Verify
Debug Logging
Enable debug logging to troubleshoot issues:
import logging
logging.basicConfig(level=logging.DEBUG)
Security Considerations
- Credentials are cached in memory only for the duration of the process
- Pull tokens are generated with an 8-hour TTL
- The backend only handles HTTPS URLs for domains ending with
.cgr.devto ensure secure transmission
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Support
For issues and questions:
- Open an issue on the GitHub repository
- Contact the maintainers
Project details
Release history Release notifications | RSS feed
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_chainguard_libraries-0.1.2.tar.gz.
File metadata
- Download URL: keyrings_chainguard_libraries-0.1.2.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd30612d928c7d9243f4cf35fe87252e333d752f726b619f333e292a2f001c2f
|
|
| MD5 |
eec9a8c3a365f991df9a1fa1308a2faa
|
|
| BLAKE2b-256 |
2538b84081eb42ef3c949cca7016a8ce1927b034304ff703743db4ab9ba579ee
|
Provenance
The following attestation bundles were made for keyrings_chainguard_libraries-0.1.2.tar.gz:
Publisher:
release.yml on chainguard-dev/keyrings-chainguard-libraries
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keyrings_chainguard_libraries-0.1.2.tar.gz -
Subject digest:
bd30612d928c7d9243f4cf35fe87252e333d752f726b619f333e292a2f001c2f - Sigstore transparency entry: 436075129
- Sigstore integration time:
-
Permalink:
chainguard-dev/keyrings-chainguard-libraries@30599406017af14a058fc5ace673e52f9d0577b0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/chainguard-dev
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@30599406017af14a058fc5ace673e52f9d0577b0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file keyrings_chainguard_libraries-0.1.2-py3-none-any.whl.
File metadata
- Download URL: keyrings_chainguard_libraries-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.1 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 |
4ac9a08049d3f04cdd8649d000213ff7aa8ce576f0ef45bf137c38d0694ce7c0
|
|
| MD5 |
f700a3f74713373c56a1949adbf1e0d8
|
|
| BLAKE2b-256 |
674f7699da7fcc07a5cba8d985047fa0b59006c319ac4a584ae9f6ad1e1c26bc
|
Provenance
The following attestation bundles were made for keyrings_chainguard_libraries-0.1.2-py3-none-any.whl:
Publisher:
release.yml on chainguard-dev/keyrings-chainguard-libraries
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keyrings_chainguard_libraries-0.1.2-py3-none-any.whl -
Subject digest:
4ac9a08049d3f04cdd8649d000213ff7aa8ce576f0ef45bf137c38d0694ce7c0 - Sigstore transparency entry: 436075178
- Sigstore integration time:
-
Permalink:
chainguard-dev/keyrings-chainguard-libraries@30599406017af14a058fc5ace673e52f9d0577b0 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/chainguard-dev
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@30599406017af14a058fc5ace673e52f9d0577b0 -
Trigger Event:
push
-
Statement type: