dlactin opened a new pull request, #72978:
URL: https://github.com/apache/airflow/pull/72978

    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   
   ## 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": "<token>"} — 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.
   
   * closes: #72903 
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change below checkbox to `[X]` followed by the name of the tool, uncomment 
the "Generated-by".
   -->
   
   - [x] Yes (please specify the tool below)
   
   Generated-by: [GitHub Copilot] following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#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](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
 You can add this file in a follow-up commit after the PR is created so you 
know the PR number.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to