|
1 | | -Fix connection access in API server contexts (plugins, log handlers) |
| 1 | +Fix Connection & Variable access in API server contexts (plugins, log handlers) |
2 | 2 |
|
3 | 3 | Previously, hooks used in API server contexts (plugins, middlewares, log handlers) would fail with an ``ImportError`` |
4 | | -for ``SUPERVISOR_COMMS``, because ``SUPERVISOR_COMMS`` only exists in worker execution contexts. |
| 4 | +for ``SUPERVISOR_COMMS``, because ``SUPERVISOR_COMMS`` only exists in task runner child processes. |
5 | 5 |
|
6 | | -This has been fixed by implementing automatic context detection with separate secrets backend chains: |
| 6 | +This has been fixed by implementing automatic context detection with three separate secrets backend chains: |
7 | 7 |
|
8 | 8 | **Context Detection:** |
9 | 9 |
|
10 | | -- **Client contexts** (workers, DAG processors, triggerers): Automatically detected via ``SUPERVISOR_COMMS`` presence |
11 | | -- **Server contexts** (API server, scheduler, plugins): Automatically detected when ``SUPERVISOR_COMMS`` is not available |
12 | | -- No configuration required - works regardless of import order or plugin loading timing |
| 10 | +1. **Client contexts** (task runner in worker): Detected via ``SUPERVISOR_COMMS`` presence |
| 11 | +2. **Server contexts** (API server, scheduler): Explicitly marked with ``_AIRFLOW_PROCESS_CONTEXT=server`` environment variable |
| 12 | +3. **Fallback contexts** (supervisor, unknown contexts): Neither marker present, uses minimal safe chain |
13 | 13 |
|
14 | 14 | **Backend Chains:** |
15 | 15 |
|
16 | | -- **Client**: ``EnvironmentVariablesBackend`` → ``ExecutionAPISecretsBackend`` (routes to Execution API) |
17 | | -- **Server**: ``EnvironmentVariablesBackend`` → ``MetastoreBackend`` (direct DB access) |
| 16 | +- **Client**: ``EnvironmentVariablesBackend`` → ``ExecutionAPISecretsBackend`` (routes to Execution API via SUPERVISOR_COMMS) |
| 17 | +- **Server**: ``EnvironmentVariablesBackend`` → ``MetastoreBackend`` (direct database access) |
| 18 | +- **Fallback**: ``EnvironmentVariablesBackend`` only (+ external backends from config like AWS Secrets Manager, Vault) |
18 | 19 |
|
19 | | -This maintains the architectural separation where workers access resources only through the Execution API, |
20 | | -while API server components have direct database access. |
| 20 | +The fallback chain is crucial for supervisor processes (worker-side, before task runner starts) which need to access |
| 21 | +external secrets for remote logging setup but should not use ``MetastoreBackend`` (to maintain worker isolation). |
| 22 | + |
| 23 | +**Architecture Benefits:** |
| 24 | + |
| 25 | +- Workers (supervisor + task runner) never use ``MetastoreBackend``, maintaining strict isolation |
| 26 | +- External secrets backends (AWS Secrets Manager, Vault, etc.) work in all three contexts |
| 27 | +- Supervisor falls back to Execution API client for connections not found in external backends |
| 28 | +- API server and scheduler have direct database access for optimal performance |
21 | 29 |
|
22 | 30 | **Impact:** |
23 | 31 |
|
24 | 32 | - Hooks like ``GCSHook``, ``S3Hook`` now work correctly in log handlers and plugins |
25 | 33 | - No code changes required for existing plugins or hooks |
26 | | -- Workers remain isolated from direct database access (network-level blocking still possible) |
27 | | -- External secrets backends (AWS Secrets Manager, Vault, etc.) continue to work in all contexts |
28 | | -- Automatic detection works regardless of initialization order |
| 34 | +- Workers remain isolated from direct database access (network-level DB blocking fully supported) |
| 35 | +- External secrets work everywhere (workers, supervisor, API server) |
| 36 | +- Robust handling of unknown contexts with safe minimal chain |
29 | 37 |
|
30 | | -See: `#56120 <https://github.com/apache/airflow/issues/56120>`__, `#56583 <https://github.com/apache/airflow/issues/56583>`__ |
| 38 | +See: `#56120 <https://github.com/apache/airflow/issues/56120>`__, `#56583 <https://github.com/apache/airflow/issues/56583>`__, `#51816 <https://github.com/apache/airflow/issues/51816>`__ |
31 | 39 |
|
32 | 40 | * Types of change |
33 | 41 |
|
|
0 commit comments