sailesh1993 / rpms / cloud-init

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