kubex.configuration¶
Auto-generated reference for the kubex.configuration module.
ClientConfiguration model¶
kubex.configuration.configuration ¶
AuthInfo ¶
Bases: ConfigModel
AuthInfo contains information that describes identity information. This is use to tell the kubernetes cluster who you are.
as_
class-attribute
instance-attribute
¶
Impersonate is the username to impersonate. The name matches the flag.
as_groups
class-attribute
instance-attribute
¶
ImpersonateGroups is the groups to impersonate.
as_uid
class-attribute
instance-attribute
¶
ImpersonateUID is the uid to impersonate.
as_user_extra
class-attribute
instance-attribute
¶
ImpersonateUserExtra contains additional information for impersonated user.
auth_provider
class-attribute
instance-attribute
¶
AuthProvider specifies a custom authentication plugin for the kubernetes cluster.
client_certificate
class-attribute
instance-attribute
¶
ClientCertificate is the path to a client cert file for TLS.
client_certificate_data
class-attribute
instance-attribute
¶
ClientCertificateData contains PEM-encoded data from a client cert file for TLS. Overrides ClientCertificate.
client_key
class-attribute
instance-attribute
¶
ClientKey is the path to a client key file for TLS.
client_key_data
class-attribute
instance-attribute
¶
ClientKeyData contains PEM-encoded data from a client key file for TLS. Overrides ClientKey.
password
class-attribute
instance-attribute
¶
Password is the password for basic authentication to the kubernetes cluster.
token
class-attribute
instance-attribute
¶
Token is the bearer token for authentication to the kubernetes cluster.
token_file
class-attribute
instance-attribute
¶
TokenFile is the path to a file containing the bearer token for authentication to the kubernetes cluster.
username
class-attribute
instance-attribute
¶
Username is the username for basic authentication to the kubernetes cluster.
AuthProviderConfig ¶
Bases: ConfigModel
AuthProviderConfig holds the configuration for a custom authentication plugin.
ClientConfiguration ¶
ClientConfiguration(
url: str | None = None,
server_ca_file: Path | str | None = None,
insecure_skip_tls_verify: bool | None = None,
client_cert_file: Path | str | None = None,
client_key_file: Path | str | None = None,
token_file: Path | str | None = None,
token: str | None = None,
namespace: str | None = None,
try_refresh_token: bool = False,
refreshable_token: SupportsAuthorizationHeader
| None = None,
tls_server_name: str | None = None,
username: str | None = None,
password: str | None = None,
impersonate_user: str | None = None,
impersonate_uid: str | None = None,
impersonate_groups: Sequence[str] | None = None,
impersonate_extra: Mapping[str, Sequence[str]]
| None = None,
)
Connection and credential settings for a client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tls_server_name
|
str | None
|
Name to verify the server certificate against (and
send as SNI) instead of the hostname in |
None
|
username
|
str | None
|
Basic-auth username; used only when no token source is set. |
None
|
password
|
str | None
|
Basic-auth password. |
None
|
impersonate_user
|
str | None
|
Username to act as ( |
None
|
impersonate_uid
|
str | None
|
UID to act as ( |
None
|
impersonate_groups
|
Sequence[str] | None
|
Groups to act as (one |
None
|
impersonate_extra
|
Mapping[str, Sequence[str]] | None
|
Extra user info to act with
( |
None
|
Source code in kubex/configuration/configuration.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
impersonation_headers
property
¶
Impersonate-* headers to send on every request (possibly repeated).
token
property
¶
The bearer token to send.
As in client-go, the last successfully read, non-empty token_file
content wins over token, which is the fallback until the file has been
read. A failed read raises only when there is nothing to fall back to.
get_authorization_header
async
¶
Return the Authorization header value to send, if any.
Prefers refreshable_token (exec/OIDC credential plugins) over the
static token/token_file path, since a kubeconfig context only
ever sets one credential source.
Source code in kubex/configuration/configuration.py
Cluster ¶
Bases: ConfigModel
Cluster contains information about how to communicate with a kubernetes cluster.
Fields are validated leniently so that one stale entry does not break
loading the whole kubeconfig; configure_from_kubeconfig() checks the
selected context's cluster (server URL, referenced files) when it is used.
certificate_authority
class-attribute
instance-attribute
¶
CertificateAuthority is the path to a cert file for the certificate authority.
certificate_authority_data
class-attribute
instance-attribute
¶
CertificateAuthorityData contains PEM-encoded certificate authority certificates. Overrides CertificateAuthority.
disable_compression
class-attribute
instance-attribute
¶
DisableCompression allows client to opt-out of response compression for all requests to the server. This is useful to speed up requests (specifically lists) when client-server network bandwidth is ample, by saving time on compression (server-side) and decompression (client-side): https://github.com/kubernetes/kubernetes/issues/112296.
extensions
class-attribute
instance-attribute
¶
Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields.
insecure_skip_tls_verify
class-attribute
instance-attribute
¶
InsecureSkipTLSVerify skips the validity check for the server's certificate. This will make your HTTPS connections insecure.
proxy_url
class-attribute
instance-attribute
¶
ProxyURL is the URL to the proxy to be used for all requests made by this client. URLs with "http", "https", and "socks5" schemes are supported. If this configuration is not provided or the empty string, the client attempts to construct a proxy configuration from http_proxy and https_proxy environment variables. If these environment variables are not set, the client does not attempt to proxy requests. socks5 proxying does not currently support spdy streaming endpoints (exec, attach, port forward).
server
class-attribute
instance-attribute
¶
Server is the address of the kubernetes cluster (https://hostname:port). A value without a scheme is treated as https://.
tls_server_name
class-attribute
instance-attribute
¶
TLSServerName is used to check server certificate. If TLSServerName is empty, the hostname used to contact the server is used.
ConfigModel ¶
Bases: BaseK8sModel
Base for kubeconfig / credential-plugin models.
Unlike resource models, unknown keys are dropped: nothing round-trips them, and keeping them would surface unexpected (possibly secret) kubeconfig content in reprs.
Context ¶
Bases: ConfigModel
Context holds user values, cluster values, and extension values.
cluster
class-attribute
instance-attribute
¶
Cluster is the name of the cluster for this context.
extensions
class-attribute
instance-attribute
¶
Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields.
namespace
class-attribute
instance-attribute
¶
Namespace is the default namespace to use on unspecified requests.
user
class-attribute
instance-attribute
¶
User is the name of the user for this context. Unset means anonymous access.
ExecConfig ¶
Bases: ConfigModel
ExecConfig specifies a command to provide client credentials.
api_version
class-attribute
instance-attribute
¶
APIVersion is the version of the API: client.authentication.k8s.io/v1 or client.authentication.k8s.io/v1beta1.
args
class-attribute
instance-attribute
¶
Args to pass to the command when executing it.
command
class-attribute
instance-attribute
¶
Command to execute. A relative path containing a path separator is resolved against the kubeconfig file's directory; a bare name is looked up on PATH.
env
class-attribute
instance-attribute
¶
Env defines the environment variables to pass to the command.
install_hint
class-attribute
instance-attribute
¶
InstallHint is shown to the user when the command cannot be found.
interactive_mode
class-attribute
instance-attribute
¶
InteractiveMode controls whether the plugin's stdin is connected; unset means IfAvailable.
provide_cluster_info
class-attribute
instance-attribute
¶
ProvideClusterInfo passes the cluster's connection details to the plugin in KUBERNETES_EXEC_INFO.
ExecInteractiveMode ¶
Bases: str, Enum
ExecInteractiveMode define the interactity of the child process
KubeConfig ¶
Bases: ConfigModel
Config holds the information needed to build connect to remote kubernetes clusters as a given user.
clusters
class-attribute
instance-attribute
¶
Clusters is a map of referencable names to cluster configs.
contexts
class-attribute
instance-attribute
¶
Contexts is a map of referencable names to context configs.
current_context
class-attribute
instance-attribute
¶
CurrentContext is the name of the context that you would like to use by default.
users
class-attribute
instance-attribute
¶
AuthInfos is a map of referencable names to user configs.
NamedAuthInfo ¶
Bases: ConfigModel
NamedAuthInfo holds an AuthInfo with name.
NamedClaster ¶
Bases: ConfigModel
NamedCluster holds a cluster with name.
NamedContext ¶
Bases: ConfigModel
NamedContext holds a context with name.
NamedExtension ¶
Bases: ConfigModel
NamedExtension holds an extension with name.
OIDCConfig ¶
Bases: ConfigModel
client_id
class-attribute
instance-attribute
¶
ClientID is the client ID for the OpenID Connect client, as described in https://tools.ietf.org/html/rfc6749#section-2.2.
client_secret
class-attribute
instance-attribute
¶
ClientSecret is the client secret for the OpenID Connect client, as described in https://tools.ietf.org/html/rfc6749#section-2.3. Omitted for public clients.
id_token
class-attribute
instance-attribute
¶
IDToken is the current id_token; used as-is until its exp claim is reached.
idp_certificate_authority
class-attribute
instance-attribute
¶
Path to a CA bundle for the issuer's TLS certificate. Relative to the kubeconfig file's directory.
idp_certificate_authority_data
class-attribute
instance-attribute
¶
Base64-encoded CA bundle for the issuer's TLS certificate. Overrides idp-certificate-authority.
idp_issuer_url
class-attribute
instance-attribute
¶
IDPIssuerURL is the URL of the OpenID issuer, only HTTPS scheme will be accepted.
refresh_token
class-attribute
instance-attribute
¶
RefreshToken is the refresh token for the OpenID Connect client, as described in https://tools.ietf.org/html/rfc6749#section-6. Redeemed only when id-token is missing or expired.
RawExtension ¶
Bases: ConfigModel
RawExtension is used to hold extensions in external versions
SupportsAuthorizationHeader ¶
Bases: Protocol
Structural type for a token source that can format its own Authorization header
describe_validation_error ¶
Summarise exc by error locations and types only.
pydantic's own message embeds the offending input, which for kubeconfig
and exec-plugin data can be a credential. Pass the validated data to
name list entries (e.g. users['dev']) instead of numbering them.
Source code in kubex/configuration/configuration.py
Kubeconfig file loading¶
kubex.configuration.file_config ¶
configure_from_kubeconfig
async
¶
configure_from_kubeconfig(
config: KubeConfig | None = None,
use_context: str | None = None,
*,
config_file: str | PathLike[str] | None = None,
) -> ClientConfiguration
Create a ClientConfiguration from a kubeconfig.
Only the selected context's cluster and user are checked (server URL, referenced files), so a stale entry for another context does not matter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
KubeConfig | None
|
An already-parsed kubeconfig. Relative file paths inside it are
used as-is (relative to the current directory); use |
None
|
use_context
|
str | None
|
Context to use instead of |
None
|
config_file
|
str | PathLike[str] | None
|
Kubeconfig file to load instead of |
None
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
No kubeconfig file exists. |
ConfigurationError
|
The kubeconfig, or the selected cluster/user, is invalid (e.g. a referenced certificate file is missing). |
ConfigurationValueError
|
The context, or the cluster/user it names, is
not defined. Also a |
ValueError
|
Both |
Source code in kubex/configuration/file_config.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
In-cluster configuration¶
kubex.configuration.incluster_config ¶
configure_from_pod_env
async
¶
configure_from_pod_env(
token_filename: Path | None = None,
cert_filename: Path | None = None,
kubernetes_service_host: str | None = None,
kubernetes_service_port: str | None = None,
try_refresh_token: bool = True,
) -> ClientConfiguration
Build a ClientConfiguration from the pod's service-account mount.
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
|
Source code in kubex/configuration/incluster_config.py
Exec provider authentication¶
kubex.configuration.auth.exec ¶
ExecAuthProvider ¶
Run a client-go credential plugin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ExecConfig
|
The kubeconfig |
required |
cluster_info
|
ExecCredentialCluster | None
|
Sent to the plugin in |
None
|
Source code in kubex/configuration/auth/exec.py
refresh_token
async
¶
Return the credential token and its RFC 3339 expirationTimestamp, if the plugin reported one.
Source code in kubex/configuration/auth/exec.py
ExecCredentialCluster ¶
Bases: ConfigModel
Cluster connection details passed to a plugin with provideClusterInfo: true.
OIDC authentication¶
kubex.configuration.auth.oidc ¶
OIDCAuthProvider ¶
Source code in kubex/configuration/auth/oidc.py
refresh_token
async
¶
Return a usable id_token, redeeming the refresh token only when needed.
Like client-go, the configured id-token is returned as long as its exp
claim is in the future; otherwise the refresh token is redeemed for a new
id_token (rotating the in-memory refresh token if the IdP issues a new one).
Raises ConfigurationError when there is neither a valid id-token nor a
refresh token.
Returns the id_token and its own exp claim (Unix epoch seconds), if it is a
decodable JWT carrying one. This is deliberately not the token response's
expires_in field, which describes the access token's lifetime -- a
separate token with its own, independently configured expiry -- not the
id_token that kubex actually sends to the API server.
A rotated refresh token is kept only on self.config for the life of this
process; it is not written back to the source kubeconfig file. Against an
IdP configured for refresh-token rotation (e.g. Auth0, Okta, Keycloak with
rotation enabled), the on-disk kubeconfig's refresh token is single-use and
is invalidated by the first successful refresh, so a fresh process (or a
concurrent kubectl using the same kubeconfig) must re-authenticate
interactively once this token has been used here.