airflow.providers.keycloak.auth_manager.services.token¶
Attributes¶
Functions¶
|
Raise a |
|
Return whether |
|
Build the Airflow user that Keycloak's UserInfo endpoint describes for |
|
|
|
Create a token from a Keycloak access token obtained outside of Airflow. |
|
Create token using OAuth2 client_credentials grant type. |
|
Create a CLI token from an authorization code obtained through |
|
Create a CLI token with fresh Keycloak tokens from a CLI token that is still valid. |
Module Contents¶
- airflow.providers.keycloak.auth_manager.services.token.translate_keycloak_outage(rejected_detail=None)[source]¶
Raise a
503instead of a Keycloak error thatis_keycloak_outage()matches.With
rejected_detail, any other Keycloak error becomes a403with that detail.
- airflow.providers.keycloak.auth_manager.services.token.is_cli_loopback_redirect_uri(redirect_uri)[source]¶
Return whether
redirect_uriis a loopback callback a command-line client listens on.
- airflow.providers.keycloak.auth_manager.services.token.build_user_from_userinfo(client, tokens, *, is_service_account=False)[source]¶
Build the Airflow user that Keycloak’s UserInfo endpoint describes for
tokens.
- airflow.providers.keycloak.auth_manager.services.token.create_token_for(username, password, expiration_time_in_seconds=conf.getint('api_auth', 'jwt_expiration_time'))[source]¶
- airflow.providers.keycloak.auth_manager.services.token.create_jwt_federated_token(assertion, expiration_time_in_seconds=conf.getint('api_auth', 'jwt_expiration_time'))[source]¶
Create a token from a Keycloak access token obtained outside of Airflow.
This authentication flow accepts an access token issued by Keycloak through any Keycloak-native mechanism (e.g. a “Signed JWT - Federated” client bound to an external OIDC identity provider such as a Kubernetes ServiceAccount issuer, or AWS IAM outbound identity federation). Airflow does not obtain the token on the caller’s behalf, the caller must obtain it directly from Keycloak’s token endpoint. Airflow verifies the token and calls Keycloak’s UserInfo endpoint to validate it and retrieve user information.
The token’s signature, issuer, and audience are verified against this realm’s JWKS. The
audclaim (a string or a list) must include this Airflow client’s id, which requires an Audience mapper on the federated client’s scope in Keycloak. The calling client (azp) must also appear in thejwt_federated_client_idsallow-list below – anaudmatch alone only proves the token was meant for Airflow, not that the issuing client has been vetted for machine auth. Any Keycloak validation error is returned as a generic403 Invalid Keycloak assertionresponse.
- airflow.providers.keycloak.auth_manager.services.token.create_client_credentials_token(client_id, client_secret, expiration_time_in_seconds=conf.getint('api_auth', 'jwt_expiration_time'))[source]¶
Create token using OAuth2 client_credentials grant type.
This authentication flow uses the provided client_id and client_secret to obtain a token for a service account. The Keycloak client must have: - Service accounts roles: ON - Client Authentication: ON (confidential client)
The service account must be configured with the appropriate roles/permissions.
Only the client Airflow is configured to use is accepted. The route this is reached from is unauthenticated, so without that restriction the credentials of any confidential client in the realm would be usable to obtain an Airflow token.
- airflow.providers.keycloak.auth_manager.services.token.create_token_from_authorization_code(code, code_verifier, redirect_uri, expiration_time_in_seconds)[source]¶
Create a CLI token from an authorization code obtained through
/login/cli.Keycloak checks
code_verifieragainst the challenge/login/cliforwarded, so the code is useless to anyone who intercepted it on the loopback redirect.
- airflow.providers.keycloak.auth_manager.services.token.refresh_cli_token(token, expiration_time_in_seconds)[source]¶
Create a CLI token with fresh Keycloak tokens from a CLI token that is still valid.
The new token expires no later than the old one, so refreshing never extends a CLI session, and lasts at most
expiration_time_in_seconds, so a longer-lived API token does not refresh into a CLI token outliving[api_auth] jwt_cli_expiration_time. On Airflow 3.2+ the old token is revoked; earlier versions have no token revocation, so it stays usable until it expires. Expired and revoked tokens are refused byget_user_from_token.