koji_wrapper: Change owner of runroot output

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-11-14 12:37:00 +01:00
parent 1d020dbedd
commit 07d08627c6
2 changed files with 5 additions and 1 deletions

View File

@ -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

View File

@ -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',