On Sun, 20 Oct 2024 at 19:56:42 +0000, Daniel Markstedt wrote: > In the end, I went with the "needs-sudo" restriction instead, to be > able to run the actual test suite as non-root.
That's often a good choice if only a minority of your test needs to do privileged things. gvfs is one of the canonical examples of this: it uses its sudo access to set up a Samba server to test against, but then runs the actual test as the non-root user. > I'm using Perl and the Test::Simple module as the runner, and > couldn't figure out how to drop to non-root when using the "needs-root" > restriction. Any of the same ways you might drop to non-root in production code should work (for example running commands wrapped in runuser, setpriv or sudo, or calling POSIX::setuid or similar). There is nothing particularly special about autopkgtest here. > I attempted setting the AUTOPKGTEST_NORMAL_USER environment variable > subsequently in the Perl script, but it didn't take any effect with this > particular test runner. That isn't how that environment variable works, and I'm not aware of any way that setting an environment variable could change your uid as a side-effect. It works the other way round: it isn't how you tell autopkgtest to change to the normal user, it's how autopkgtest tells your test-case a normal user that you might want to use. Specifically, if your test was run as root via the needs-root restriction, and you want to drop privileges to a non-root uid by whatever mechanism is most appropriate for your test (runuser or POSIX::setuid or whatever), then $AUTOPKGTEST_NORMAL_USER is the username of a non-root uid that autopkgtest suggests as being appropriate for that purpose. smcv