-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Fix Connection or Variable access in Server context #56602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| Fix Connection & Variable access in API server contexts (plugins, log handlers) | ||
|
|
||
| Previously, hooks used in API server contexts (plugins, middlewares, log handlers) would fail with an ``ImportError`` | ||
| for ``SUPERVISOR_COMMS``, because ``SUPERVISOR_COMMS`` only exists in task runner child processes. | ||
|
|
||
| This has been fixed by implementing automatic context detection with three separate secrets backend chains: | ||
|
|
||
| **Context Detection:** | ||
|
|
||
| 1. **Client contexts** (task runner in worker): Detected via ``SUPERVISOR_COMMS`` presence | ||
| 2. **Server contexts** (API server, scheduler): Explicitly marked with ``_AIRFLOW_PROCESS_CONTEXT=server`` environment variable | ||
| 3. **Fallback contexts** (supervisor, unknown contexts): Neither marker present, uses minimal safe chain | ||
|
|
||
| **Backend Chains:** | ||
|
|
||
| - **Client**: ``EnvironmentVariablesBackend`` → ``ExecutionAPISecretsBackend`` (routes to Execution API via SUPERVISOR_COMMS) | ||
| - **Server**: ``EnvironmentVariablesBackend`` → ``MetastoreBackend`` (direct database access) | ||
| - **Fallback**: ``EnvironmentVariablesBackend`` only (+ external backends from config like AWS Secrets Manager, Vault) | ||
|
|
||
| The fallback chain is crucial for supervisor processes (worker-side, before task runner starts) which need to access | ||
| external secrets for remote logging setup but should not use ``MetastoreBackend`` (to maintain worker isolation). | ||
|
|
||
| **Architecture Benefits:** | ||
|
|
||
| - Workers (supervisor + task runner) never use ``MetastoreBackend``, maintaining strict isolation | ||
| - External secrets backends (AWS Secrets Manager, Vault, etc.) work in all three contexts | ||
| - Supervisor falls back to Execution API client for connections not found in external backends | ||
| - API server and scheduler have direct database access for optimal performance | ||
|
|
||
| **Impact:** | ||
|
|
||
| - Hooks like ``GCSHook``, ``S3Hook`` now work correctly in log handlers and plugins | ||
| - No code changes required for existing plugins or hooks | ||
| - Workers remain isolated from direct database access (network-level DB blocking fully supported) | ||
| - External secrets work everywhere (workers, supervisor, API server) | ||
| - Robust handling of unknown contexts with safe minimal chain | ||
|
|
||
| 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>`__ | ||
|
|
||
| * Types of change | ||
|
|
||
| * [ ] Dag changes | ||
| * [ ] Config changes | ||
| * [ ] API changes | ||
| * [ ] CLI changes | ||
| * [ ] Behaviour changes | ||
| * [ ] Plugin changes | ||
| * [ ] Dependency changes | ||
| * [ ] Code interface changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
task-sdk/src/airflow/sdk/execution_time/secrets/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| """Secrets backends for task execution contexts.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from airflow.sdk.execution_time.secrets.execution_api import ExecutionAPISecretsBackend | ||
|
|
||
| __all__ = ["ExecutionAPISecretsBackend", "DEFAULT_SECRETS_SEARCH_PATH_WORKERS"] | ||
|
|
||
| DEFAULT_SECRETS_SEARCH_PATH_WORKERS = [ | ||
| "airflow.secrets.environment_variables.EnvironmentVariablesBackend", | ||
| "airflow.sdk.execution_time.secrets.execution_api.ExecutionAPISecretsBackend", | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.