base
mlflow_secrets_auth.base
¶
Base classes and abstractions for MLflow secrets-backed authentication providers.
This module defines
- Lightweight
requests.auth.AuthBase
implementations for Bearer, Basic, and custom-header auth. SecretsBackedAuthProvider
, an abstract base for MLflowRequestAuthProvider
s that obtain credentials from secret managers and cache them with a TTL.
Design notes
- Providers implement
_fetch_secret
,_get_cache_key
,_get_auth_mode
, and_get_ttl
. - Caching is delegated to
cached_fetch
and TTL validation tovalidate_ttl
. - Secrets are parsed centrally via
parse_secret_json
and must resolve to either:- {"token": "
"} OR - {"username": "...", "password": "..."}
- {"token": "
- Header name can be configured; "Authorization" is normalized to the canonical header.
All logging goes through safe_log
to avoid leaking sensitive values.
BasicAuth(username, password, header_name=DEFAULT_AUTH_HEADER)
¶
Bases: AuthBase
HTTP Basic authentication for requests
.
If a non-standard header is configured, the base64 credentials are put into that header.
Attributes:
Name | Type | Description |
---|---|---|
username |
Basic auth username. |
|
password |
Basic auth password. |
|
header_name |
Target header (defaults to "Authorization"). |
Initialize basic authentication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
username
|
str
|
Username for basic auth. |
required |
password
|
str
|
Password for basic auth. |
required |
header_name
|
str
|
HTTP header to inject (defaults to "Authorization"). |
DEFAULT_AUTH_HEADER
|
Source code in src/mlflow_secrets_auth/base.py
__call__(r)
¶
Attach the basic auth header to the outgoing request.
Source code in src/mlflow_secrets_auth/base.py
BearerAuth(token, header_name=DEFAULT_AUTH_HEADER)
¶
Bases: AuthBase
Bearer token authentication for requests
.
The token is injected as: <header_name>: Bearer <token>
Attributes:
Name | Type | Description |
---|---|---|
token |
Opaque bearer token. |
|
header_name |
Target header (defaults to "Authorization"). |
Initialize bearer authentication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
str
|
Bearer token string. |
required |
header_name
|
str
|
HTTP header to inject (defaults to "Authorization"). |
DEFAULT_AUTH_HEADER
|
Source code in src/mlflow_secrets_auth/base.py
__call__(r)
¶
Attach the bearer token header to the outgoing request.
CustomHeaderAuth(token, header_name)
¶
Bases: AuthBase
Custom header authentication for requests
(token placed as-is).
Attributes:
Name | Type | Description |
---|---|---|
token |
Opaque token to inject. |
|
header_name |
Target header. |
Initialize custom header authentication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
str
|
Token value to inject directly. |
required |
header_name
|
str
|
Header name where the token is placed. |
required |
Source code in src/mlflow_secrets_auth/base.py
__call__(r)
¶
SecretData
¶
Bases: TypedDict
Structured representation of parsed secret material.
SecretsBackedAuthProvider(provider_name, default_ttl=DEFAULT_TTL_SECONDS)
¶
Bases: RequestAuthProvider
, ABC
Abstract base class for secrets-backed MLflow auth providers.
Subclasses implement secret retrieval for a specific backend (e.g., Vault, AWS, Azure) and supply configuration inputs (cache key, auth mode, TTL).
This class handles
- Provider enablement checks.
- Host allowlisting for
get_request_auth
. - Cache + TTL validation.
- Secret parsing and Auth object construction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider_name
|
str
|
Stable identifier used for logging and configuration. |
required |
default_ttl
|
int
|
Fallback TTL in seconds if configured TTL is invalid. |
DEFAULT_TTL_SECONDS
|
Attributes:
Name | Type | Description |
---|---|---|
provider_name |
Provider identifier. |
|
default_ttl |
Default TTL for cache. |
|
logger |
Namespaced logger instance. |
Initialize the provider base.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider_name
|
str
|
Identifier of the provider (e.g., "vault"). |
required |
default_ttl
|
int
|
Default cache TTL in seconds. |
DEFAULT_TTL_SECONDS
|
Source code in src/mlflow_secrets_auth/base.py
get_auth()
¶
Return a requests
Auth object (no URL filtering).
This method is used by MLflow when a per-request URL is not available.
Returns:
Type | Description |
---|---|
AuthBase | None
|
A |
Source code in src/mlflow_secrets_auth/base.py
get_name()
¶
Return the provider name (instance method in recent MLflow versions).
Returns:
Type | Description |
---|---|
str
|
Provider name for MLflow plugin discovery. |
get_request_auth(url)
¶
Return a requests
Auth object for a given MLflow request URL.
Applies host allowlisting to avoid credential leakage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
Full request URL for an MLflow call. |
required |
Returns:
Type | Description |
---|---|
AuthBase | None
|
A |