59e311
From 40ad855b883050069393b9c00db2a6d222d949db Mon Sep 17 00:00:00 2001
c36ff1
From: Eduardo Otubo <otubo@redhat.com>
c36ff1
Date: Fri, 7 May 2021 13:36:08 +0200
c36ff1
Subject: limit permissions on def_log_file
c36ff1
c36ff1
This sets a default mode of 0600 on def_log_file, and makes this
c36ff1
configurable via the def_log_file_mode option in cloud.cfg.
c36ff1
c36ff1
LP: #1541196
c36ff1
Resolves: rhbz#1424612
c36ff1
X-approved-upstream: true
c36ff1
c36ff1
Conflicts 21.1:
c36ff1
    cloudinit/stages.py: adjusting call of ensure_file() to use more
c36ff1
recent version
c36ff1
c36ff1
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
c36ff1
---
c36ff1
 cloudinit/settings.py         | 1 +
c36ff1
 cloudinit/stages.py           | 1 +
c36ff1
 doc/examples/cloud-config.txt | 4 ++++
c36ff1
 3 files changed, 6 insertions(+)
c36ff1
c36ff1
diff --git a/cloudinit/settings.py b/cloudinit/settings.py
59e311
index a780e21e..aa2d6b95 100644
c36ff1
--- a/cloudinit/settings.py
c36ff1
+++ b/cloudinit/settings.py
59e311
@@ -49,6 +49,7 @@ CFG_BUILTIN = {
59e311
         "None",
c36ff1
     ],
c36ff1
     'def_log_file': '/var/log/cloud-init.log',
c36ff1
+    'def_log_file_mode': 0o600,
c36ff1
     'log_cfgs': [],
c36ff1
     'mount_default_fields': [None, None, 'auto', 'defaults,nofail', '0', '2'],
c36ff1
     'ssh_deletekeys': False,
c36ff1
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
59e311
index 3f17294b..61db1dbd 100644
c36ff1
--- a/cloudinit/stages.py
c36ff1
+++ b/cloudinit/stages.py
59e311
@@ -205,6 +205,7 @@ class Init(object):
c36ff1
     def _initialize_filesystem(self):
c36ff1
         util.ensure_dirs(self._initial_subdirs())
59e311
         log_file = util.get_cfg_option_str(self.cfg, "def_log_file")
59e311
+        log_file_mode = util.get_cfg_option_int(self.cfg, "def_log_file_mode")
c36ff1
         if log_file:
59e311
             util.ensure_file(log_file, mode=0o640, preserve_mode=True)
59e311
             perms = self.cfg.get("syslog_fix_perms")
c36ff1
diff --git a/doc/examples/cloud-config.txt b/doc/examples/cloud-config.txt
59e311
index a2b4a3fa..0ccf3147 100644
c36ff1
--- a/doc/examples/cloud-config.txt
c36ff1
+++ b/doc/examples/cloud-config.txt
c36ff1
@@ -414,10 +414,14 @@ timezone: US/Eastern
c36ff1
 # if syslog_fix_perms is a list, it will iterate through and use the
c36ff1
 # first pair that does not raise error.
c36ff1
 #
c36ff1
+# 'def_log_file' will be created with mode 'def_log_file_mode', which
c36ff1
+# is specified as a numeric value and defaults to 0600.
c36ff1
+#
c36ff1
 # the default values are '/var/log/cloud-init.log' and 'syslog:adm'
c36ff1
 # the value of 'def_log_file' should match what is configured in logging
c36ff1
 # if either is empty, then no change of ownership will be done
c36ff1
 def_log_file: /var/log/my-logging-file.log
c36ff1
+def_log_file_mode: 0600
c36ff1
 syslog_fix_perms: syslog:root
c36ff1
 
c36ff1
 # you can set passwords for a user or multiple users
c36ff1
-- 
59e311
2.31.1
c36ff1