Blame SOURCES/0003-limit-permissions-on-def_log_file.patch

936480
From 0101e1677a1ae5ba328657e0b060277707de3913 Mon Sep 17 00:00:00 2001
936480
From: Lars Kellogg-Stedman <lars@redhat.com>
936480
Date: Fri, 7 Apr 2017 18:50:54 -0400
936480
Subject: limit permissions on def_log_file
936480
936480
This sets a default mode of 0600 on def_log_file, and makes this
936480
configurable via the def_log_file_mode option in cloud.cfg.
936480
936480
LP: #1541196
936480
Resolves: rhbz#1424612
936480
X-approved-upstream: true
936480
---
936480
 cloudinit/settings.py         | 1 +
936480
 cloudinit/stages.py           | 3 ++-
936480
 doc/examples/cloud-config.txt | 4 ++++
936480
 3 files changed, 7 insertions(+), 1 deletion(-)
936480
936480
diff --git a/cloudinit/settings.py b/cloudinit/settings.py
936480
index c536768..d982a4d 100644
936480
--- a/cloudinit/settings.py
936480
+++ b/cloudinit/settings.py
936480
@@ -43,6 +43,7 @@ CFG_BUILTIN = {
936480
         'None',
936480
     ],
936480
     'def_log_file': '/var/log/cloud-init.log',
936480
+    'def_log_file_mode': 0o600,
936480
     'log_cfgs': [],
936480
     'mount_default_fields': [None, None, 'auto', 'defaults,nofail', '0', '2'],
936480
     'ssh_deletekeys': False,
936480
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
936480
index 8a06412..4f15484 100644
936480
--- a/cloudinit/stages.py
936480
+++ b/cloudinit/stages.py
936480
@@ -148,8 +148,9 @@ class Init(object):
936480
     def _initialize_filesystem(self):
936480
         util.ensure_dirs(self._initial_subdirs())
936480
         log_file = util.get_cfg_option_str(self.cfg, 'def_log_file')
936480
+        log_file_mode = util.get_cfg_option_int(self.cfg, 'def_log_file_mode')
936480
         if log_file:
936480
-            util.ensure_file(log_file)
936480
+            util.ensure_file(log_file, mode=log_file_mode)
936480
             perms = self.cfg.get('syslog_fix_perms')
936480
             if not perms:
936480
                 perms = {}
936480
diff --git a/doc/examples/cloud-config.txt b/doc/examples/cloud-config.txt
936480
index eb84dcf..0e82b83 100644
936480
--- a/doc/examples/cloud-config.txt
936480
+++ b/doc/examples/cloud-config.txt
936480
@@ -413,10 +413,14 @@ timezone: US/Eastern
936480
 # if syslog_fix_perms is a list, it will iterate through and use the
936480
 # first pair that does not raise error.
936480
 #
936480
+# 'def_log_file' will be created with mode 'def_log_file_mode', which
936480
+# is specified as a numeric value and defaults to 0600.
936480
+#
936480
 # the default values are '/var/log/cloud-init.log' and 'syslog:adm'
936480
 # the value of 'def_log_file' should match what is configured in logging
936480
 # if either is empty, then no change of ownership will be done
936480
 def_log_file: /var/log/my-logging-file.log
936480
+def_log_file_mode: 0600
936480
 syslog_fix_perms: syslog:root
936480
 
936480
 # you can set passwords for a user or multiple users
936480
-- 
936480
1.8.3.1
936480