id: OIDC Identity Generator
id is a Python tool for generating OIDC identities, currently at version 1.6.1. It can automatically detect and produce OIDC credentials on various environments, including GitHub Actions, GitLab pipelines, and Google Cloud. The library maintains an active release cadence with frequent updates and improvements.
Warnings
- gotcha The library name `id` collides with Python's built-in `id()` function. Importing `import id` could shadow the built-in function or lead to confusion. Always use explicit imports like `from id import detect_credential` to prevent this conflict.
- breaking Python 3.8 is no longer supported starting from version 1.6.0. The library now requires Python 3.9 or newer.
- breaking The internal dependency on `pydantic` was removed in version 1.5.0. If your project indirectly relied on `pydantic` being installed via `id`, this change could lead to `ModuleNotFoundError` if `pydantic` is not explicitly listed in your project's dependencies.
- breaking Version 1.6.0 internally replaced the `requests` library with `urllib3` for HTTP operations. While this change might not directly affect users of `detect_credential`, applications that relied on `requests`' specific behavior (e.g., monkey-patching `requests`, or assumptions about `requests`' session management) when using the `id` library might experience unexpected changes.
- gotcha When detecting OIDC tokens in GitLab CI/CD environments, the token is provided via an environment variable. This variable is named `<AUD>_ID_TOKEN`, where `<AUD>` is the uppercased audience argument with all non-alphanumeric characters replaced by underscores, and leading digits also replaced by an underscore. Incorrectly forming this environment variable name will lead to token detection failure.
Install
-
pip install id
Imports
- detect_credential
from id import detect_credential
Quickstart
from id import detect_credential
import os
audience = os.environ.get('OIDC_AUDIENCE', 'my-oidc-audience')
try:
token = detect_credential(audience=audience)
if token:
print(f"Successfully detected OIDC token for audience '{audience}':\n{token}")
else:
print(f"No OIDC token detected for audience '{audience}' in the current environment.")
except Exception as e:
print(f"An error occurred: {e}")