ashb commented on pull request #20114:
URL: https://github.com/apache/airflow/pull/20114#issuecomment-988311050


   We can make it a single sudo chwon call like this:
   
   ```diff
   diff --git a/airflow/task/task_runner/base_task_runner.py 
b/airflow/task/task_runner/base_task_runner.py
   --- airflow/task/task_runner/base_task_runner.py
   +++ airflow/task/task_runner/base_task_runner.py
   @@ -56,8 +56,11 @@
                    self.run_as_user = conf.get('core', 'default_impersonation')
                except AirflowConfigException:
                    self.run_as_user = None
    
   +
   +        self._error_file = NamedTemporaryFile(delete=True)
   +
            # Add sudo commands to change user if we need to. Needed to handle 
SubDagOperator
            # case using a SequentialExecutor.
            self.log.debug("Planning to run as the %s user", self.run_as_user)
            if self.run_as_user and (self.run_as_user != getuser()):
   @@ -67,9 +70,9 @@
                # might not be able to run the cmds to get credentials
                cfg_path = tmp_configuration_copy(chmod=0o600, 
include_env=True, include_cmds=True)
    
                # Give ownership of file to user; only they can read and write
   -            subprocess.call(['sudo', 'chown', self.run_as_user, cfg_path], 
close_fds=True)
   +            subprocess.check_call(['sudo', 'chown', self.run_as_user, 
cfg_path, self._error_file.name], close_fds=True)
    
                # propagate PYTHONPATH environment variable
                pythonpath_value = os.environ.get(PYTHONPATH_VAR, '')
                popen_prepend = ['sudo', '-E', '-H', '-u', self.run_as_user]
   @@ -83,11 +86,8 @@
                # variables then we don't need to include those in the config 
copy
                # - the runner can read/execute those values as it needs
                cfg_path = tmp_configuration_copy(chmod=0o600, 
include_env=False, include_cmds=False)
    
   -        self._error_file = NamedTemporaryFile(delete=True)
   -        if self.run_as_user:
   -            subprocess.call(['sudo', 'chown', self.run_as_user, 
self._error_file.name], close_fds=True)
    
            self._cfg_path = cfg_path
            self._command = (
                popen_prepend
   ```


-- 
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