Sync from SUSE:ALP:Source:Standard:1.0 cloud-init revision 0df56b6a95c1a3d23a1ff16dbde8cc94

This commit is contained in:
Adrian Schröter 2024-05-02 14:23:09 +02:00
parent 2f12ac28aa
commit f36e7c619f
3 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,68 @@
--- cloudinit/distros/__init__.py.orig
+++ cloudinit/distros/__init__.py
@@ -880,9 +880,12 @@ class Distro(persistence.CloudInitPickle
# it actually exists as a directory
sudoers_contents = ""
base_exists = False
+ system_sudo_base = "/usr/etc/sudoers"
if os.path.exists(sudo_base):
sudoers_contents = util.load_file(sudo_base)
base_exists = True
+ elif os.path.exists(system_sudo_base):
+ sudoers_contents = util.load_file(system_sudo_base)
found_include = False
for line in sudoers_contents.splitlines():
line = line.strip()
@@ -907,7 +910,7 @@ class Distro(persistence.CloudInitPickle
"#includedir %s" % (path),
"",
]
- sudoers_contents = "\n".join(lines)
+ sudoers_contents += "\n".join(lines)
util.write_file(sudo_base, sudoers_contents, 0o440)
else:
lines = [
--- tests/unittests/distros/test__init__.py.orig
+++ tests/unittests/distros/test__init__.py
@@ -230,6 +230,41 @@ class TestGenericDistro(helpers.Filesyst
self.assertIn("josh", contents)
self.assertEqual(2, contents.count("josh"))
+ def test_sudoers_ensure_append_sudoer_file(self):
+ cls = distros.fetch("ubuntu")
+ d = cls("ubuntu", {}, None)
+ self.patchOS(self.tmp)
+ self.patchUtils(self.tmp)
+ util.write_file("/etc/sudoers", "josh, josh\n")
+ d.ensure_sudo_dir("/b", "/etc/sudoers")
+ contents = util.load_file("/etc/sudoers")
+ self.assertIn("includedir /b", contents)
+ self.assertTrue(os.path.isdir("/b"))
+ self.assertIn("josh", contents)
+ self.assertEqual(2, contents.count("josh"))
+
+ def test_usr_sudoers_ensure_new(self):
+ cls = distros.fetch("ubuntu")
+ d = cls("ubuntu", {}, None)
+ self.patchOS(self.tmp)
+ self.patchUtils(self.tmp)
+ util.write_file("/usr/etc/sudoers", "josh, josh\n")
+ d.ensure_sudo_dir("/b")
+ contents = util.load_file("/etc/sudoers")
+ self.assertIn("josh", contents)
+ self.assertEqual(2, contents.count("josh"))
+ self.assertIn("includedir /b", contents)
+ self.assertTrue(os.path.isdir("/b"))
+
+ def test_usr_sudoers_ensure_no_etc_creat(self):
+ cls = distros.fetch("ubuntu")
+ d = cls("ubuntu", {}, None)
+ self.patchOS(self.tmp)
+ self.patchUtils(self.tmp)
+ util.write_file("/usr/etc/sudoers", "#includedir /b")
+ d.ensure_sudo_dir("/b")
+ self.assertTrue(not os.path.exists("/etc/sudoers"))
+
def test_sudoers_ensure_only_one_includedir(self):
cls = distros.fetch("ubuntu")
d = cls("ubuntu", {}, None)

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Apr 29 21:49:48 UTC 2024 - Robert Schweikert <rjschwei@suse.com>
- Add cloud-init-usr-sudoers.patch (bsc#1223469)
+ Handle the existence of /usr/etc/sudoers to search for the expected
include location
------------------------------------------------------------------- -------------------------------------------------------------------
Tue Apr 9 16:00:13 UTC 2024 - Robert Schweikert <rjschwei@suse.com> Tue Apr 9 16:00:13 UTC 2024 - Robert Schweikert <rjschwei@suse.com>

View File

@ -49,6 +49,8 @@ Patch11: cloud-init-ds-deterministic.patch
Patch12: cloud-init-no-openstack-guess.patch Patch12: cloud-init-no-openstack-guess.patch
# FIXME upstream comit 812df5038 # FIXME upstream comit 812df5038
Patch13: cloud-init-no-nmcfg-needed.patch Patch13: cloud-init-no-nmcfg-needed.patch
# FIXME https://github.com/canonical/cloud-init/pull/5161
Patch14: cloud-init-usr-sudoers.patch
BuildRequires: fdupes BuildRequires: fdupes
BuildRequires: filesystem BuildRequires: filesystem
# pkg-config is needed to find correct systemd unit dir # pkg-config is needed to find correct systemd unit dir
@ -160,6 +162,7 @@ Documentation and examples for cloud-init tools
%patch -P 11 %patch -P 11
%patch -P 12 %patch -P 12
%patch -P 13 %patch -P 13
%patch -P 14
# patch in the full version to version.py # patch in the full version to version.py
version_pys=$(find . -name version.py -type f) version_pys=$(find . -name version.py -type f)