From 07d08627c66ea4644138636c5a65ff075988b35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 14 Nov 2018 12:37:00 +0100 Subject: [PATCH] koji_wrapper: Change owner of runroot output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The files created in runroot task are owned by root by default (because that's who is running the processes to create them). Making the results world readable allows the compose to work, but it still can be difficult to clean up old composes if they contain random files owned by root. Fixes: https://pagure.io/pungi/issue/1039 JIRA: COMPOSE-2906 Signed-off-by: Lubomír Sedlář --- pungi/wrappers/kojiwrapper.py | 3 +++ tests/test_koji_wrapper.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pungi/wrappers/kojiwrapper.py b/pungi/wrappers/kojiwrapper.py index c69af800..3cd9ac97 100644 --- a/pungi/wrappers/kojiwrapper.py +++ b/pungi/wrappers/kojiwrapper.py @@ -114,7 +114,10 @@ class KojiWrapper(object): command = "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; " + command if destdir: + # Make the files world readable command += " && chmod -R a+r %s" % shlex_quote(destdir) + # and owned by the same user that is running the process + command += " && chown -R %d %s" % (os.getuid(), shlex_quote(destdir)) cmd.append(command) return cmd diff --git a/tests/test_koji_wrapper.py b/tests/test_koji_wrapper.py index e99cc137..34d8b3a3 100644 --- a/tests/test_koji_wrapper.py +++ b/tests/test_koji_wrapper.py @@ -430,6 +430,7 @@ class RunrootKojiWrapperTest(KojiWrapperBaseTestCase): '--task-id', '--weight=1000', '--package=some_other_package', '--package=lorax', '--mount=/tmp']) + @mock.patch("os.getuid", new=lambda: 1010) def test_with_destdir(self): cmd = self.koji.get_runroot_cmd('tgt', 's390x', ['/bin/echo', '&'], quiet=True, channel='chan', @@ -441,7 +442,7 @@ class RunrootKojiWrapperTest(KojiWrapperBaseTestCase): self.assertEqual(cmd[-2], 's390x') self.assertEqual( cmd[-1], - "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&' && chmod -R a+r '/output dir'" + "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&' && chmod -R a+r '/output dir' && chown -R 1010 '/output dir'" ) self.assertItemsEqual(cmd[3:-3], ['--channel-override=chan', '--quiet', '--use-shell',