Replace atomic_move() with a higher level function #71324
Closed
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.
SUMMARY
CVE-2020-1736
Related to #70221, #71200
Fixes #67794
The original fix for this CVE which changed the default permissions to
600
unlessmode
was explicitly specified in the task was too disruptive. This is an attempt at a better solution, but it will be a more invasive change to the code.The CVE has two main problems that need to be addressed:
The previous fix addressed the first item, but did not adequately address the second item. Asking that tasks explcitly specify
mode
was too much of a change requirement. Furthermore, it resulted in overwhelming surprise from the community to find that in the absense ofmode
the defaultumask
of the system was not used. That鈥檚 a sign it was not a good fix.Here is my plan for how to fix this:
atomic_move()
atomic_move()
so it is easier to read and maintainmove_file()
method as well asset_mode_if_different()
The main reasoning behind this is that
atomic_move()
is not a good API. It has a very strong, but unenforced, relationship toset_fs_attributes_if_different()
and it lacks information about the intended final permissions of the file.In order to ensure that temporary files are created securely, and that they are never set to a mode greater than the
mode
specified in the task, if present, the new method needs to know about the final intended permissions, not just the system defaults.The new method will accept
src
,dest
, andmode
at a minimum. It may accept the samefile_args
thatset_fs_attributes_if_different()
accepts, but I am not sure at this time.ISSUE TYPE
COMPONENT NAME
lib/ansible/module_utils/basic.py
ADDITIONAL INFORMATION
In its current state, I am in the process of writing
move_file()
as a function rather than (yet another) method ofAnsibleModule
. Ultimately, I believe this approach will be too disruptive and will have to be done at a later date. There are many methods, particularlyrun_command()
that will require a lot of work to remove fromAnsibleModule
.I will most likely end up creating new methods so this change may be backported, then do the work of moving those methods to functions. Apologies to my future self. 馃槃