-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't bake ENV and _cmd into tmp config for non-sudo
If we are running tasks via sudo then AIRFLOW__ config env vars won't be visible anymore (without them showing up in `ps`) and we likely might not have permission to run the _cmd's specified to find the passwords. But if we are running as the same user then there is no need to "bake" those options in to the temporary config file -- if the operator decided they didn't want those values appearing in a config file on disk, then lets do our best to respect that. Note: this commit originally appears in 2019 but a critical piece was missing, meaning that the secrets/envs were still actually appearing.
- Loading branch information
Showing
4 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,54 @@ | ||
# | ||
# 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. | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from airflow.jobs.local_task_job import LocalTaskJob | ||
from airflow.models.baseoperator import BaseOperator | ||
from airflow.task.task_runner.base_task_runner import BaseTaskRunner | ||
|
||
|
||
@pytest.mark.parametrize(["impersonation"], (("nobody",), (None,))) | ||
@mock.patch('subprocess.call') | ||
@mock.patch('os.chown') | ||
@mock.patch('airflow.task.task_runner.base_task_runner.tmp_configuration_copy') | ||
def test_config_copy_mode(tmp_configuration_copy, chown, subprocess_call, dag_maker, impersonation): | ||
with dag_maker("test"): | ||
BaseOperator(task_id="task_1", run_as_user=impersonation) | ||
|
||
dr = dag_maker.create_dagrun() | ||
|
||
ti = dr.task_instances[0] | ||
job = LocalTaskJob(ti) | ||
runner = BaseTaskRunner(job) | ||
# So we don't try to delete it -- cos the file wont exist | ||
del runner._cfg_path | ||
|
||
includes = bool(impersonation) | ||
|
||
tmp_configuration_copy.assert_called_with(chmod=0o600, include_env=includes, include_cmds=includes) | ||
|
||
if impersonation: | ||
chown.assert_called() | ||
subprocess_call.assert_called_with( | ||
['sudo', 'chown', impersonation, tmp_configuration_copy.return_value], close_fds=True | ||
) | ||
else: | ||
chown.assert_not_called() | ||
subprocess_call.not_assert_called() |