Skip to content

Add jwt auth keycloak provider - #72978

Merged
vincbeck merged 4 commits into
apache:mainfrom
dlactin:feat/add-jwt-auth-keycloak-provider
Sep 14, 2026
Merged

vincbeck merged 4 commits into
apache:mainfrom
dlactin:feat/add-jwt-auth-keycloak-provider

Conversation

@dlactin

@dlactin dlactin commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

What changed:

Added a new urn:ietf:params:oauth:grant-type:jwt-bearer grant to the Keycloak auth manager's /auth/token endpoint (TokenJwtFederatedBody / create_jwt_federated_token), alongside a new jwt_federated_client_ids config option.

It lets a client that already authenticated to Keycloak by some other means (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) exchange its Keycloak access token for an Airflow-minted JWT, without re-authenticating to Keycloak through Airflow.

Why:

The existing client_credentials grant requires a static client_secret per caller, and doesn't support multiple distinct client identities cleanly going forward (upstream hardening restricts it to a single configured client id).

Machine identities that already prove themselves to Keycloak via a federated/no-static-secret mechanism had no way to obtain an Airflow API token. This grant closes that gap: Airflow verifies an already-issued Keycloak assertion (signature, issuer, aud) and authorizes the caller via a new jwt_federated_client_ids allow-list keyed off the token's azp claim — fail-closed if unset.

More details in #72903 if needed, but the core goal was to support temporary credentials to the Airflow API from external services using k8s service accounts.

How to test:

  1. Configure a Keycloak client with Service accounts roles: ON, openid in its default client scopes, and either a client secret or Signed JWT - Federated auth.
  2. Add the client's id to [keycloak_auth_manager] jwt_federated_client_ids.
  3. Obtain a Keycloak access token for that client (e.g. client_credentials grant against Keycloak directly).
  4. POST /auth/token with {"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer", "assertion": ""} — expect 201 with an access_token.
  5. Use that access_token (not the Keycloak token) as Authorization: Bearer against /api/v2/dags — expect a successful response.
  6. Negative cases: expired assertion, wrong issuer/audience, azp not in the allow-list, and empty/unset allow-list should all return 403.
  7. Unit tests: providers/keycloak/tests/unit/keycloak/auth_manager/{services,datamodels,routes}/test_token.py.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [GitHub Copilot] following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@vincbeck vincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotted by my agent

@shahar1 shahar1 changed the title Feat/add jwt auth keycloak provider Add jwt auth keycloak provider Sep 13, 2026
@vincbeck

Copy link
Copy Markdown
Contributor

CI is failing

@dlactin
dlactin force-pushed the feat/add-jwt-auth-keycloak-provider branch from 2c7ba36 to 7933ba0 Compare September 14, 2026 15:57
@dlactin

dlactin commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

CI is failing

Apologies for the spam folks, rebased without including merge commits :(

@henry3260

Copy link
Copy Markdown
Member

rerun CI

@vincbeck
vincbeck merged commit 35d64d2 into apache:main Sep 14, 2026
85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Keycloak Signed JWT - Federated flow for machine authentication to Airflow

3 participants