2014-12-05 16:40:15 +03:00
#!/bin/bash
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
2016-01-27 19:44:10 +03:00
set -euo pipefail
2014-12-05 16:40:15 +03:00
. $( dirname $0 ) /libtest.sh
2016-03-31 13:06:05 +03:00
skip_without_user_xattrs
2014-12-05 16:40:15 +03:00
setup_test_repository "bare-user"
2017-12-01 05:43:17 +03:00
extra_basic_tests = 6
2014-12-05 16:40:15 +03:00
. $( dirname $0 ) /basic-test.sh
2017-06-05 18:32:52 +03:00
# Reset things so we don't inherit a lot of state from earlier tests
rm repo files -rf
setup_test_repository "bare-user"
cd ${ test_tmpdir }
objpath_nonexec = $( ostree_file_path_to_object_path repo test2 baz/cow)
2017-09-19 20:37:58 +03:00
assert_file_has_mode ${ objpath_nonexec } 644
2017-06-05 18:32:52 +03:00
objpath_ro = $( ostree_file_path_to_object_path repo test2 baz/cowro)
assert_file_has_mode ${ objpath_ro } 600
objpath_exec = $( ostree_file_path_to_object_path repo test2 baz/deeper/ohyeahx)
assert_file_has_mode ${ objpath_exec } 755
echo "ok bare-user committed modes"
rm test2-checkout -rf
$OSTREE checkout -U -H test2 test2-checkout
cd test2-checkout
2017-09-19 20:37:58 +03:00
assert_file_has_mode baz/cow 644
2017-06-05 18:32:52 +03:00
assert_file_has_mode baz/cowro 600
assert_file_has_mode baz/deeper/ohyeahx 755
echo "ok bare-user checkout modes"
rm test2-checkout -rf
$OSTREE checkout -U -H test2 test2-checkout
touch test2-checkout/unwritable
chmod 0400 test2-checkout/unwritable
$OSTREE commit -b test2-unwritable --tree= dir = test2-checkout
chmod 0600 test2-checkout/unwritable
rm test2-checkout -rf
$OSTREE checkout -U -H test2-unwritable test2-checkout
cd test2-checkout
assert_file_has_mode unwritable 400
echo "ok bare-user unwritable"
2017-06-30 16:40:47 +03:00
rm test2-checkout -rf
$OSTREE checkout -U -H test2 test2-checkout
cat > statoverride.txt <<EOF
= 0 /unreadable
EOF
touch test2-checkout/unreadable
$OSTREE commit -b test2-unreadable --statoverride= statoverride.txt --tree= dir = test2-checkout
$OSTREE fsck
rm test2-checkout -rf
$OSTREE checkout -U -H test2-unreadable test2-checkout
assert_file_has_mode test2-checkout/unreadable 400
echo "ok bare-user handled unreadable file"
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: 8fe45362578a43260876134d6547ebd0bb2485c3
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
2017-10-20 21:15:14 +03:00
cd ${ test_tmpdir }
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
$OSTREE commit -b component-dbus --owner-uid 0 --owner-gid 81 --tree= dir = components/dbus
$OSTREE commit -b component-systemd --owner-uid 0 --owner-gid 0 --tree= dir = components/systemd
rm rootfs -rf
for component in dbus systemd; do
$OSTREE checkout -U -H component-${ component } --union rootfs
done
echo 'some rootfs data' > rootfs/usr/lib/cache.txt
$OSTREE commit -b rootfs --link-checkout-speedup --tree= dir = rootfs
$OSTREE ls rootfs /usr/bin/systemd >ls.txt
assert_file_has_content ls.txt '^-007.. 0 0 .*/usr/bin/systemd'
$OSTREE ls rootfs /usr/lib/dbus-daemon-helper >ls.txt
assert_file_has_content ls.txt '^-007.. 0 81 .*/usr/lib/dbus-daemon-helper'
echo "ok bare-user link-checkout-speedup maintains uids"
2017-12-01 05:43:17 +03:00
cd ${ test_tmpdir }
rm -rf test2-checkout
$OSTREE checkout -H -U test2 test2-checkout
# With --link-checkout-speedup, specifying --owner-uid should "win" by default.
2017-12-10 22:39:38 +03:00
myuid = $( id -u)
mygid = $( id -g)
newuid = $(( ${ myuid } + 1 ))
newgid = $(( ${ mygid } + 1 ))
$OSTREE commit ${ COMMIT_ARGS } --owner-uid ${ newuid } --owner-gid ${ newgid } \
2017-12-01 05:43:17 +03:00
--link-checkout-speedup -b test2-linkcheckout-test --tree= dir = test2-checkout
$OSTREE ls test2-linkcheckout-test /baz/cow > ls.txt
2017-12-10 22:39:38 +03:00
assert_file_has_content ls.txt " ^-006.. ${ newuid } ${ newgid } .*/baz/cow "
2017-12-01 05:43:17 +03:00
# But --devino-canonical should override that
2017-12-10 22:39:38 +03:00
$OSTREE commit ${ COMMIT_ARGS } --owner-uid ${ newuid } --owner-gid ${ newgid } \
2017-12-01 05:43:17 +03:00
-I -b test2-devino-test --tree= dir = test2-checkout
$OSTREE ls test2-devino-test /baz/cow > ls.txt
2017-12-10 22:39:38 +03:00
assert_file_has_content ls.txt " ^-006.. ${ myuid } ${ mygid } .*/baz/cow "
2017-12-01 05:43:17 +03:00
$OSTREE refs --delete test2-{ linkcheckout,devino} -test
echo "ok commit with -I"