Validate task identity token claims with a typed schema#63604
Validate task identity token claims with a typed schema#63604henry3260 wants to merge 6 commits intoapache:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a typed, validated schema for Task Identity Token (TI) JWT claims in the Execution API, replacing the previous “raw dict” approach to make claim access and validation more explicit and reliable.
Changes:
- Add
TIClaims(typed Pydantic model) and updateTIToken.claimsto use it. - Update JWT bearer authentication to validate decoded JWT claims against
TIClaims. - Adjust unit tests and Cadwyn version bundle metadata to reflect the schema change.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| airflow-core/src/airflow/api_fastapi/execution_api/datamodels/token.py | Introduces TIClaims and makes TIToken.claims typed. |
| airflow-core/src/airflow/api_fastapi/execution_api/security.py | Validates decoded JWT claims into TIClaims and uses typed access to scope. |
| airflow-core/src/airflow/api_fastapi/execution_api/app.py | Updates in-process auth override to construct TIClaims. |
| airflow-core/src/airflow/api_fastapi/execution_api/versions/v2026_03_31.py | Adds a version-change note describing the TIToken.claims schema change. |
| airflow-core/src/airflow/api_fastapi/execution_api/versions/init.py | Registers the new version change in the bundle. |
| airflow-core/tests/unit/api_fastapi/execution_api/conftest.py | Updates mocked JWT bearer token to use TIClaims. |
| airflow-core/tests/unit/api_fastapi/execution_api/test_security.py | Adds TIClaims behavior test and updates token construction to typed claims. |
| airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py | Updates mocked validator claims to include required JWT time claims and aligns expected error text. |
You can also share your feedback on Copilot code review. Take the survey.
|
Hey @henry3260, nice improvement — replacing the raw The Cadwyn version change may not have any effect.
The error message for invalid scopes changes. Previously, an invalid scope produced a clean "Invalid token scope" message from A couple of test gaps:
The core change is solid and the |
I think we still need to add the Cadwyn version changes. If we modify any files in airflow-core/src/airflow/api_fastapi/execution_api/datamodels/, we need to handle the API migration. |
|
I think it's unrelated CI failure :( |
|
LGTM. With my comprehension, I think the response convert is not necessary in this case cause the TIClaim already contained those required field. Thanks for your work!! |
| from airflow.api_fastapi.execution_api.datamodels.token import TIToken | ||
|
|
||
|
|
||
| class ValidateTaskIdentityTokenClaims(VersionChange): |
There was a problem hiding this comment.
I think the name of this class should be changed, because it only handles versioning and describes upgrade/downgrade behavior, rather than validating the TIToken. The name can be ChangeTITokenClaimsToTIClaims or other better names.
What
TIToken.claimsfrom a rawdict[str, Any]to a typedTIClaimsmodel.TIClaims:sub,exp,iat,nbfscope,aud,iss,jtiWas generative AI tooling used to co-author this PR?
{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.