lib/commit: Fix hardlink checkout commit with bare-user + mod xattrs
This is more subtle fallout from:
https://github.com/ostreedev/ostree/pull/1170
AKA commit: 8fe4536257
Before, if we found a devino cache hit, we'd use it unconditionally.
Recall that `bare-user` repositories are very special in that they're the only
mode where the on disk state ("physical state") is not the "real" state. The
latter is stored in the `user.ostreemeta` xattr. (`bare-user` repos are also
highly special in that symlinks are regular files physically, but that's not
immediately relevant here).
Since we now have `bare-user-only` for the "pure unprivileged container" case,
`bare-user` should just be used for "OS builds" which have nonzero uids (and
possibly SELinux labels etc.)
In an experimental tool I'm writing "skopeo2ostree" which imports OCI images
into refs, then squashes them together into a single final commit, we lost the
the `81` group ID for `/usr/libexec/dbus-1/dbus-daemon-launch-helper`.
This happened because the commit code was loading the "physical" disk state,
where the uid/gid are zero because that's the uid I happened to be using. We
didn't just directly do the link speedup because I was using `--selinux-policy`
which caused the xattrs to change, which caused us to re-commit objects from the
physical state.
The unit test I added actually doesn't quite trigger this, but I left
it because "why not". Really testing this requires the installed test
which uses SELinux policy from `/`.
The behavior without this fix looks like:
```
-00755 0 0 12 { [(b'user.ostreemeta', [byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x81, 0xed]), (b'security.selinux', b'system_u:object_r:lib_t:s0')] } /usr/lib/dbus-daemon-helper
```
which was obviously totally broken - we shouldn't be picking up the
`user.ostreemeta` xattr and actually committing it of course.
Closes: #1297
Approved by: jlebon
This commit is contained in:
1 parent
4c0f67be0c
commit
ed15723cd1
3 files changed
+101
-16
No files matched your search
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Tests of the "raw ostree" functionality using the host's ostree repo as uid 0.
|
||||
|
||||
set -xeuo pipefail
|
||||
|
||||
dn=$(dirname $0)
|
||||
. ${dn}/libinsttest.sh
|
||||
|
||||
echo "1..1"
|
||||
|
||||
prepare_tmpdir
|
||||
ostree --repo=repo init --mode=bare-user
|
||||
mkdir -p components/{dbus,systemd}/usr/{bin,lib}
|
||||
echo dbus binary > components/dbus/usr/bin/dbus-daemon
|
||||
chmod a+x components/dbus/usr/bin/dbus-daemon
|
||||
echo dbus lib > components/dbus/usr/lib/libdbus.so.1
|
||||
echo dbus helper > components/dbus/usr/lib/dbus-daemon-helper
|
||||
chmod a+x components/dbus/usr/lib/dbus-daemon-helper
|
||||
echo systemd binary > components/systemd/usr/bin/systemd
|
||||
chmod a+x components/systemd/usr/bin/systemd
|
||||
echo systemd lib > components/systemd/usr/lib/libsystemd.so.1
|
||||
|
||||
# Make the gid on dbus 81 like fedora, also ensure no xattrs
|
||||
ostree --repo=repo commit --no-xattrs -b component-dbus --owner-uid 0 --owner-gid 81 --tree=dir=components/dbus
|
||||
ostree --repo=repo commit --no-xattrs -b component-systemd --owner-uid 0 --owner-gid 0 --tree=dir=components/systemd
|
||||
rm rootfs -rf
|
||||
for component in dbus systemd; do
|
||||
ostree --repo=repo checkout -U -H component-${component} --union rootfs
|
||||
done
|
||||
echo 'some rootfs data' > rootfs/usr/lib/cache.txt
|
||||
# Commit using the host's selinux policy
|
||||
ostree --repo=repo commit --selinux-policy / -b rootfs --link-checkout-speedup --tree=dir=rootfs
|
||||
ostree --repo=repo ls rootfs /usr/bin/systemd >ls.txt
|
||||
assert_file_has_content ls.txt '^-007.. 0 0 .*/usr/bin/systemd'
|
||||
ostree --repo=repo ls -X rootfs /usr/lib/dbus-daemon-helper >ls.txt
|
||||
assert_file_has_content ls.txt '^-007.. 0 81 .*security.selinux.*/usr/lib/dbus-daemon-helper'
|
||||
assert_not_file_has_content ls.txt 'user.ostreemeta'
|
||||
echo "ok bare-user link-checkout-speedup with modified xattrs maintains uids"
|
||||
Reference in new issue
Block a user