]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-systemd-tmpfiles: skip when /tmp has unexpected ownership
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 25 Oct 2023 16:39:04 +0000 (17:39 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 26 Oct 2023 13:46:15 +0000 (14:46 +0100)
The systemd-tmpfiles binary will report a fatal error if /tmp is not owned
either by root, or by the current user:

  Detected unsafe path transition /tmp (owned by nobody) →
    /tmp/test-systemd-tmpfiles.a8qc6n18 (owned by berrange)
    during canonicalization of
    tmp/test-systemd-tmpfiles.a8qc6n18/test-content.7chd7rdi

When doing development inside a 'toolbox' container (which is required
on a Fedora SilverBlue distro), /tmp is owned by 'nobody', because it
has been passed through from the host and host UID 0 gets mapped to
UID 65536 by usernamespaces. This triggers the unsafe path transition
error message.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
test/test-systemd-tmpfiles.py

index 77ef53b9839d4ec904c38beb57f64ed2100f8aee..37a5e9ef3e4b23e6952cbfcc6476c1ed06ccaa49 100755 (executable)
@@ -31,6 +31,14 @@ except AttributeError:
 exe_with_args = sys.argv[1:]
 temp_dir = tempfile.TemporaryDirectory(prefix='test-systemd-tmpfiles.')
 
+# If /tmp isn't owned by either 'root' or the current user
+# systemd-tmpfiles will exit with "Detected unsafe path transition"
+# breaking this test
+tmpowner = os.stat("/tmp").st_uid
+if tmpowner != 0 and tmpowner != os.getuid():
+    print("Skip: /tmp is not owned by 'root' or current user")
+    sys.exit(EXIT_TEST_SKIP)
+
 def test_line(line, *, user, returncode=EX_DATAERR, extra={}):
     args = ['--user'] if user else []
     print('Running {} on {!r}'.format(' '.join(exe_with_args + args), line))