csaccess
A Python library for authenticating and accessing CONTACT resources in AWS CodeArtifact and Elastic Container Registry (ECR) using OIDC.
Overview
csaccess simplifies access to CONTACT cloud resources by providing a streamlined authentication flow with support for both interactive user-based and automated service-based authentication methods.
Authentication Methods
Feature |
User OIDC |
Static OIDC (Client Credentials) |
GitLab CI OIDC (JWT) |
|---|---|---|---|
CLI flag |
(default) |
--static-oidc |
--gitlab-oidc |
Programmatic |
(no secret) |
static_oidc_secret |
gitlab_oidc_secret |
Authentication |
Interactive user login via web browser |
Application authenticates itself using its secret |
GitLab CI mints a short-lived OIDC JWT |
Grant Type |
Authorization Code with PKCE |
Client Credentials |
Web Identity (AssumeRoleWithWebIdentity) |
User Context |
Represents a specific user |
Represents the application/service itself |
Represents the CI job (project, ref, etc.) |
Security |
Relies on user credentials and browser |
Relies on the client secret’s security |
Short-lived CI-issued JWT, no stored secret |
Use Cases |
Applications acting on behalf of a user |
Service accounts, background processes, etc. |
GitLab CI pipelines authenticating to AWS |
Token Audience |
Targeted to specific user and application |
Targeted to the application |
The configured aud of the id_tokens entry |
Security Warning: Be extremely careful when handling access tokens. Treat them like passwords:
Avoid logging them or storing them insecurely
Never paste sensitive tokens into untrusted online services
Use environment variables where possible to avoid exposing secrets
Installation
pip install csaccess
Setup and Configuration
Configuration
The “relying party” local server requires port 29398 to be free and available
The default user OIDC flow is interactive (browser login) and does not require a client secret.
CS_AWS_OIDC_CLIENT_SECRET is only used in static OIDC mode (--static-oidc, client credentials grant):
The --gitlab-oidc mode is intended for GitLab CI: it reads the GitLab-issued OIDC JWT from the CS_GITLAB_JWT environment variable and passes it directly to AWS STS as a web identity token. No client secret is involved.
--static-oidc and --gitlab-oidc are mutually exclusive.
The programmatic API takes no mode flags: the auth mode is derived from the secrets passed (gitlab_oidc_secret, static_oidc_secret) or found in the environment (CS_GITLAB_JWT, CS_AWS_OIDC_CLIENT_SECRET), in that order of precedence. The console parameters take precedence. Without any secret the interactive user flow is used.
On Linux / macOS:
export CS_AWS_OIDC_CLIENT_SECRET="<OIDC-client-secret>"
Windows CMD:
set CS_AWS_OIDC_CLIENT_SECRET="<OIDC-client-secret>"
Windows PowerShell:
$env:CS_AWS_OIDC_CLIENT_SECRET = "<OIDC-client-secret>"
For GitLab CI, use --gitlab-oidc. GitLab populates CS_GITLAB_JWT automatically via the id_tokens keyword. The --aws-role-arn must point to a role whose trust policy federates the GitLab OIDC provider (the default role trusts Keycloak and will not accept a GitLab JWT):
# .gitlab-ci.yml
get-token:
id_tokens:
CS_GITLAB_JWT:
aud: <configured-audience>
script:
- python -m csaccess ca-auth-token --gitlab-oidc --aws-role-arn <gitlab-trusting-role-arn>
Usage Examples
Important: unset AWS specific vars existing in local env as they will interfere with AWS STS functionality.
unset AWS_PROFILE
unset AWS_DEFAULT_PROFILE
Basic Usage
Get PyPI URL with embedded auth token (default action):
import csaccess
ca_pypi_url = csaccess.get_ca_pypi_url_programmatic()
You should amend the returned value with specific repo name and interface, for example /16.0/simple.
Get CodeArtifact or ECR tokens in Python:
ca_auth_token = csaccess.get_ca_auth_token_programmatic()
ecr_auth_token = csaccess.get_ecr_auth_token_programmatic()
Pass a client secret to use the client-credentials flow, or a GitLab CI JWT to use it directly as the AWS STS web identity token (the JWT takes precedence):
csaccess.get_ca_auth_token_programmatic(static_oidc_secret="<OIDC-client-secret>")
csaccess.get_ca_auth_token_programmatic(gitlab_oidc_secret="<GitLab-CI-JWT>", aws_role_arn="<gitlab-trusting-role-arn>")
Command-Line Interface
Returns the CodeArtifact URL with an injected token (default):
python -m csaccess
Get the CodeArtifact token:
python -m csaccess ca-auth-token
Get the ECR token:
python -m csaccess ecr-auth-token
Integration Examples
Following are examples for Linux / macOS:
Using with pip
CA_PYPI_URL=$(python -m csaccess --quiet)
pip install -i "${CA_PYPI_URL}/16.0/simple" cs.platform
Using with Docker
ECR_TOKEN=$(python -m csaccess ecr-auth-token --quiet)
echo $ECR_TOKEN | base64 -d | cut -d: -f2 | docker login --username AWS --password-stdin <ECR-registry-url>
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 csaccess-0.3.0-py3-none-any.whl.
File metadata
- Download URL: csaccess-0.3.0-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89574a844be87f31af41dd50ac2c647ff3d937744e8db88b9d7a0d045dbcc855
|
|
| MD5 |
33a36c0df0b51ff249d31312f1077e84
|
|
| BLAKE2b-256 |
48f3d9ec29f874e2417e6994f11b9c9a6b93db85496b708b6abfec7293f6d426
|