Skip to content

Conversation

Copy link

Copilot AI commented Jan 27, 2026

Adds test coverage for getHomeDirOwner, a helper function that retrieves directory ownership via os.Stat and syscall metadata, used when changing UIDs/GIDs to verify and update home directory ownership.

Changes:

  • Export getHomeDirOwner via export_test.go for test access
  • Add TestGetHomeDirOwner covering success cases (directory, file) and error cases (non-existent path, permission denied)
  • Verify correctness by comparing returned UID/GID against syscall.Stat_t rather than assuming process ownership (handles diverse CI environments)
// Test validates function correctly extracts ownership metadata
uid, gid, err := users.GetHomeDirOwner(path)
require.NoError(t, err)

sys := fileInfo.Sys().(*syscall.Stat_t)
require.Equal(t, sys.Uid, uid)
require.Equal(t, sys.Gid, gid)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

There's nothing encrypted in this string.
... instead of prefixing the error message with "permission denied"
Required to change the ownership of the user's home directory when
changing the user's UID.
We use this to recursively change the owner and group of the user's home
directory when changing the user's UID.
Needed to test fileutils.ChownRecursiveFrom. We can't use bubblewrap for
that because bubblewrap only creates UID mapping for one user, using
chown with a different UID fails with:

    chown: changing ownership of 'file': Invalid argument
Do the same usermod does when changing a UID of a user: If the home
directory is currently owned by the user, recursively change the owner
and group of the home directory and all files in the home directory from
the old UID and GID to the new UID and GID.
We need that for the SetUserID tests
We now support chown in bubblewrap, so we don't have to run the test as
root anymore.
We have a use case where we want to create a directory at a
deterministic path in /tmp. That fails if /tmp is shared with the host
and other bubblewrap sandboxes which use the same directory.
It doesn't test anything that's not already covered by other tests and
it's annoying to have to manually update the golden files of the SSH
integration tests whenever the authctl usage message changes.
userslocking.WriteLock() immediately returns ErrLock if the lock is
already taken *by the current process*. lckpwdf behaves similarly (even
though the man page doesn't mention it).

To avoid that issue, we now take another lock which blocks concurrent
goroutines.
adombeck and others added 16 commits January 26, 2026 22:08
We broke the bubblewrap tests in the CI without noticing it (at first)
because the tests were skipped. The only case where we really want to
skip the tests is on Launchpad builders. To detect that, we check if the
DEB_BUILD_ARCH environment variable is set and we're *not* in GitHub CI.
When executing `unshare --map-user` via exec.Command and connecting the
process's stdout or stderr, the command hangs forever if unprivileged
user namespaces are disabled.

We avoid that by checking via `unshare --user` if unprivileged user
namespaces are enabled.
The "Run autopkgtests" CI job runs the tests in an LXD container which
doesn't allow using bubblewrap. It fails with:

    bwrap: Failed to make / slave: Permission denied

To avoid that these jobs fail, we allow them to skip the bubblewrap
tests. We still run the tests in the "Go Tests" CI jobs.
Running our tests with -v produces so much output that it makes it
harder to inspect test failures, for example when viewing the logs of
the "Run autopkgtests" CI job in GitHub.

Running the tests without -v still prints the logs of the failed tests
which should include all the information we need to debug test failures.
As suggested by reviewer. It's not implemented for now, warnings are
always returned in English.
We don't need to load the bwrap-userns-restrict AppArmor profile for the
bubblewrap tests to work. In fact, we even have to circumvent the
AppArmor profile (if it's loaded) for the tests to work.

This reverts commit 7b926c0.
Copilot AI changed the title [WIP] Add tests for getHomeDirOwner in authctl user set-uid Add tests for getHomeDirOwner helper function Jan 27, 2026
Copilot AI requested a review from 3v1n0 January 27, 2026 19:20
@adombeck adombeck force-pushed the 630-set-uid branch 3 times, most recently from e905615 to de040d5 Compare February 3, 2026 19:48
@adombeck adombeck closed this Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants