Skip to content

logging: keep current file mode of log file if its stricter than the new mode (#4250)

Ani Sinha requested to merge anisinha/cloud-init:bz-2222498 into c9s

BZ: 2222498

Cherry-pick the upstream commit: logging: keep current file mode of log file if its stricter than the new mode (#4250)

   By default, the cloud init log file is created with mode 0o644 with
    `preserve_mode` parameter of `write_file()` set to False. This means that when
    an existing log file is found, its mode will be unconditionally reset to the
    mode 0o644. It is possible that this might cause the change of the mode of the
    log file from the current more stricter mode to a less strict mode
    (when the new mode 0o644 is less strict than the existing mode of the file).
    
    In order to mitigate the above issue, check the current mode of the log file
    and if the current mode is stricter than the default new mode 0o644, then
    preserve the current mode of the file.
    
    Fixes GH-4243
    
    Signed-off-by: Ani Sinha <anisinha@redhat.com>
    (cherry picked from commit a0e4ec15a1adffabd1c539879514eae4807c834c)
    
     Conflicts:
            tests/unittests/test_util.py

The conflict in the test script arises because in downstream, we do not have class TestResolvable and class TestHashBuffer in tests/unittests/test_util.py

Merge request reports