08c715
From 6134624f10ef56534e37624adc12f11b09910591 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
08c715
index e690c0fd..43a1490c 100644
222d62
--- a/cloudinit/settings.py
222d62
+++ b/cloudinit/settings.py
08c715
@@ -46,6 +46,7 @@ CFG_BUILTIN = {
222d62
         'None',
222d62
     ],
222d62
     'def_log_file': '/var/log/cloud-init.log',
222d62
+    'def_log_file_mode': 0o600,
222d62
     'log_cfgs': [],
222d62
     'mount_default_fields': [None, None, 'auto', 'defaults,nofail', '0', '2'],
222d62
     'ssh_deletekeys': False,
222d62
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
08c715
index 3ef4491c..83e25dd1 100644
222d62
--- a/cloudinit/stages.py
222d62
+++ b/cloudinit/stages.py
08c715
@@ -147,6 +147,7 @@ class Init(object):
222d62
     def _initialize_filesystem(self):
222d62
         util.ensure_dirs(self._initial_subdirs())
222d62
         log_file = util.get_cfg_option_str(self.cfg, 'def_log_file')
222d62
+        log_file_mode = util.get_cfg_option_int(self.cfg, 'def_log_file_mode')
222d62
         if log_file:
08c715
             util.ensure_file(log_file, preserve_mode=True)
222d62
             perms = self.cfg.get('syslog_fix_perms')
222d62
diff --git a/doc/examples/cloud-config.txt b/doc/examples/cloud-config.txt
08c715
index de9a0f87..bb33ad45 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
-- 
08c715
2.27.0
222d62