airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Clean up the exception handler when run_as_user is the airflow user

Open squingo44 opened this issue 1 year ago • 2 comments

During the heartbeat check, the local_task_job_runner performs a check on the job's PID and raises an exception if it doesn't match what it expects.

In the case that the job is a child process (ie. when running as another user), this check will instead occur on the job's parent PID.

The condition for triggering this alternate route is run_as_user having a non-None value. This condition is correct, except for the case where run_as_user has been set to user as which Airflow is already running, in which case run_as_user is ignored when the TaskRunner is initialialized.

This means that whenever an Airflow user sets run_as_user to the user as which they're already running Airflow, they would get an error, and be told to unset the run_as_user attribute. However, there is a legitimate use case for this: run_as_user can be used to override default_impersonation back to the airflow_uid user.

This change updates the "is_child_process" condition within the exception handler to reflect this use case. It makes this use case succeed silently instead of throwing an error.


^ Add meaningful description above Read the Pull Request Guidelines for more information. In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed. In case of a new dependency, check compliance with the ASF 3rd Party License Policy. In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

squingo44 avatar Apr 03 '24 20:04 squingo44

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst) Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits. Apache Airflow is a community-driven project and together we are making it better 🚀. In case of doubts contact the developers at: Mailing List: [email protected] Slack: https://s.apache.org/airflow-slack

boring-cyborg[bot] avatar Apr 03 '24 20:04 boring-cyborg[bot]

Nice catch. Can you add a test case for that ?

potiuk avatar Apr 07 '24 20:04 potiuk