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

    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull 
request.
   Write a good git commit message following this guide: 
https://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the 
documentation.
   
   For user-facing UI changes, please attach before/after screenshots (or a 
short
   screen recording) so reviewers can assess the visual impact.
   
   Feel free to ping (in general) for the review if you do not see reaction for 
a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we 
sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   In PR https://github.com/apache/airflow/pull/68082, I added a new plugin 
under the Kafka Provider which uses the airflow internal listener API, that 
monitors `dag_run` and `task_instance` state events and runs a callback on 
every state change. `dag_run` event hooks execute in the scheduler process 
while `task_instance` event hooks execute in the worker process.
   
   Before using Kafka, we have to create a new airflow connection which will 
carry the necessary configuration.
    
   As part of the changes, I added support for string based callbacks which can 
be specified as part of the extra option in the connection.
   
   The main idea is that users will be able to install trusted packages with 
tools like `pip` and then specify the full path along with the callback 
attribute in a string. The Kafka Provider will resolve the string from the 
connection back to the package and execute the callback.
   
   For example,
   
   ```
   airflow connections add kafka_default --conn-type kafka --conn-extra 
'{"bootstrap.servers": "broker:29092", "group.id": "kafka_event_producer", 
"enable.auto.commit": false, "auto.offset.reset": "earliest", "oauth_cb": 
"my_company.auth.my_callback"}'
   ```
   
   The problem is that we resolve the callback string without any validations 
or restrictions and as an unwanted consequence, users can specify whatever they 
want.
   
   A malicious user could do something like this
   
   ```
   {"oauth_cb": "os.system", "sasl.mechanism": "OAUTHBEARER", 
"sasl.oauthbearer.config": "<shell command>"}
   ```
   
   and for the `dag_run` events, they will end up running a shell command in 
the scheduler process, causing a serious security incident.
   
   This PR adds a new allowlist config option where deployment managers have to 
specify all trusted callbacks. If the config is empty, which is the default, no 
string-based callbacks are allowed. If a callback doesn't exist in the 
allowlist, the provider refuses to resolve it from the string.
   
   ## Testing
   
   I've added unit tests for the changes. All existing tests are passing.
   
   ---
   
   ##### 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)
   Claude-code Opus 4.8
   
   <!--
   Generated-by: [Tool Name] 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