Skip to content

Commit

Permalink
lib/repo: For bare-user, make repo modes mirror checkout user-mode
Browse files Browse the repository at this point in the history
Having every object in a bare-user repo (and checkouts) be executable
is ugly.  I can't think of a good reason to do that.  So make
the committed mode semantics mirror that for user-mode checkouts; we
strip suid/sgid bits.

However, we also do ensure that the written files are read/writable by the
owning user, since otherwise we couldn't do anything to them. I'm not aware of
any real use cases for non-readable/non-writable by owner files in ostree.

Closes: #907
  • Loading branch information
cgwalters committed Jun 5, 2017
1 parent e18cacb commit 5fb31fd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/libostree/ostree-repo-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,16 @@ commit_loose_object_trusted (OstreeRepo *self,
{
if (!object_is_symlink)
{
/* We need to apply at least some mode bits, because the repo file was created
with mode 644, and we need e.g. exec bits to be right when we do a user-mode
checkout. To make this work we apply all user bits and the read bits for
group/other. Furthermore, setting user xattrs requires write access, so
this makes sure it's at least writable by us. (O_TMPFILE uses mode 0 by default) */
if (fchmod (fd, mode | 0744) < 0)
return glnx_throw_errno (error);
/* This mirrors the checkout path for suid state; however, we also
* always apply readable/writable owner bits, because setting
* xattrs requires write access, and there's really no use case
* right now for storing non-readable files in ostree. Note that
* previously this path added `| 0755` which made every file executable,
* see https://github.com/ostreedev/ostree/issues/907
*/
const mode_t content_mode = (mode & ~(S_ISUID|S_ISGID)) | S_IRUSR | S_IWUSR;
if (fchmod (fd, content_mode) < 0)
return glnx_throw_errno_prefix (error, "fchmod");
}

if (self->mode == OSTREE_REPO_MODE_BARE_USER &&
Expand Down
2 changes: 1 addition & 1 deletion tests/basic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

set -euo pipefail

echo "1..66"
echo "1..$((66 + ${extra_basic_tests:-0}))"

$CMD_PREFIX ostree --version > version.yaml
python -c 'import yaml; yaml.safe_load(open("version.yaml"))'
Expand Down
18 changes: 18 additions & 0 deletions tests/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,21 @@ libtest_cleanup_gpg () {
is_bare_user_only_repo () {
grep -q 'mode=bare-user-only' $1/config
}

# Given a path to a file in a repo for a ref, print its checksum
ostree_file_path_to_checksum() {
repo=$1
ref=$2
path=$3
$CMD_PREFIX ostree --repo=$repo ls -C $ref $path | awk '{ print $5 }'
}

# Given a path to a file in a repo for a ref, print the path to its object
ostree_file_path_to_object_path() {
repo=$1
ref=$2
path=$3
checksum=$(ostree_file_path_to_checksum $repo $ref $path)
test -n "${checksum}"
echo ${repo}/objects/${checksum:0:2}/${checksum:2}.file
}
23 changes: 23 additions & 0 deletions tests/test-basic-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,27 @@ skip_without_user_xattrs

setup_test_repository "bare-user"

extra_basic_tests=2
. $(dirname $0)/basic-test.sh

# 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)
# This actually depends on umask, that's going to be a pain
assert_file_has_mode ${objpath_nonexec} 664
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
assert_file_has_mode baz/cow 664
assert_file_has_mode baz/cowro 600
assert_file_has_mode baz/deeper/ohyeahx 755
echo "ok bare-user checkout modes"

0 comments on commit 5fb31fd

Please sign in to comment.