Skip to content

Commit 7f41241

Browse files
committed
Fix Dag processor token docs and renewal test flakiness
Slow CI responses can exceed the best-effort renewal deadline, while the authentication guidance must reflect the scoped Execution API contract.
1 parent eb40af7 commit 7f41241

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

‎airflow-core/docs/security/jwt_token_authentication.rst‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,21 @@ Token structure (Execution API)
254254
* - ``aud``
255255
- Audience (from ``[execution_api] jwt_audience``, default: ``urn:airflow.apache.org:task``).
256256
* - ``sub``
257-
- Task instance UUID — the identity of the workload.
257+
- UUID identifying the task instance, callback, processor session, or parsing attempt, depending on the scope.
258258
* - ``scope``
259-
- Token scope: ``"execution"`` or ``"workload"``.
259+
- Token scope: ``"execution"``, ``"workload"``, ``"callback"``, ``"dag_processor_session"``,
260+
``"dag_processor"``, or ``"dag_parse"``.
260261
* - ``iat``
261262
- Issued-at timestamp.
262263
* - ``nbf``
263264
- Not-before timestamp.
264265
* - ``exp``
265-
- Expiration timestamp (``iat + [execution_api] jwt_expiration_time``).
266+
- Expiration timestamp, determined by the scope's lifetime and any parent credential's expiry.
266267

267268
Token scopes (Execution API)
268269
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
269270

270-
The Execution API defines two token scopes with different lifetimes:
271+
The Execution API uses the following token scopes. Each endpoint accepts only its declared scopes:
271272

272273
**workload**
273274
A token embedded in the workload JSON payload when the Scheduler
@@ -281,12 +282,28 @@ The Execution API defines two token scopes with different lifetimes:
281282
backed-up queue before its workload token expires.
282283

283284
**execution**
284-
A short-lived token (default 10 minutes) accepted by all Execution API endpoints.
285+
A short-lived token (default 10 minutes) accepted by endpoints that allow task or callback execution.
285286
This is the standard scope for worker communication during task execution. Issued
286287
by the server when the worker transitions to running via the ``/run`` endpoint.
287288
The ``JWTReissueMiddleware`` refreshes ``execution`` tokens transparently,
288289
so the worker maintains access for the duration of the task.
289290

291+
**callback**
292+
A single-use token exchanged at ``/callbacks/{callback_id}/run`` for an ``execution``
293+
token when a queued callback starts.
294+
295+
**dag_processor_session**
296+
A provisioned credential accepted only by ``POST /jobs`` for Job registration and renewal.
297+
298+
**dag_processor**
299+
A Job credential for heartbeats, completion, Connection and Variable reads for granted bundles,
300+
and parsing-token exchange.
301+
302+
**dag_parse**
303+
A credential for one parsing attempt, granting parse-time access within its signed bundle.
304+
305+
See `Dag processor HTTP client credentials`_ for provisioning, lifetime limits, and authorization details.
306+
290307
Tokens without a ``scope`` claim default to ``"execution"`` for backwards compatibility.
291308

292309
Token delivery to workers

‎airflow-core/tests/unit/api_fastapi/execution_api/test_dag_processor_client.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ async def shutdown(self, sockets=None):
110110
("execution_api", "jwt_expiration_time"): "300",
111111
}
112112
),
113+
# Real HTTP/DB responses can exceed the one-second renewal deadline on CI.
114+
# Unit tests in dag_processing/test_api_client.py cover that deadline separately.
115+
mock.patch.object(
116+
DagProcessorAPIClient,
117+
"_get_bounded_timeout",
118+
autospec=True,
119+
side_effect=lambda client: client.timeout,
120+
),
113121
socket.socket() as listener,
114122
):
115123
listener.bind((api_bind_host, 0))

0 commit comments

Comments
 (0)