Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/commit: autofix permissions for bare-user-only #2412

Merged
merged 1 commit into from
Aug 20, 2021

Conversation

lucab
Copy link
Member

@lucab lucab commented Aug 17, 2021

This tweaks commit logic to detect bare-user-only repositories and
canonicalize permissions automatically.

@lucab lucab force-pushed the ups/lib-commit-canonicalize branch from 8dda504 to 620bbc1 Compare August 18, 2021 13:15
@dbnicholson
Copy link
Member

Obviously it would be good to add a test that committing to a bare-user-only repo without --canonical-permissions results in canonical permissions begin used. I think it would also be useful to document in OstreeRepoCommitModifierFlags that OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS is implied when the target repository is in bare-user-only mode.

Also, are you planning to handle OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS in this PR?

@lucab
Copy link
Member Author

lucab commented Aug 19, 2021

@dbnicholson I'd like to scope this to the uid/gid/mode part only, and tackle xattrs separately. Thanks for your other suggestions, I'll incorporate them.

Right now though this is a WIP as I'm blocked tracking down the non-identical glitch I'm seeing, which for some reason does not happen in CI (possibly because it runs as root in a container).

@lucab lucab force-pushed the ups/lib-commit-canonicalize branch from 620bbc1 to f5f8014 Compare August 20, 2021 10:58
@lucab lucab changed the title [WIP] lib/commit: autofix permissions for bare-user-only lib/commit: autofix permissions for bare-user-only Aug 20, 2021
@lucab
Copy link
Member Author

lucab commented Aug 20, 2021

Rebased, this is now ready to land.

@@ -678,10 +678,14 @@ typedef OstreeRepoCommitFilterResult (*OstreeRepoCommitFilter) (OstreeRepo *r
* @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_NONE: No special flags
* @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS: Do not process extended attributes
* @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES: Generate size information.
* @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS: Canonicalize permissions for bare-user-only mode.
* @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS: Canonicalize permissions, for bare-user-only mode.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just simplify this to

Suggested change
* @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS: Canonicalize permissions, for bare-user-only mode.
* @OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS: Canonicalize permissions

?

Since the only reason you would pass this explicitly now is if you want the behaviour on non-bare-user-only repos.

ostree_repo_init repo init --mode=bare-user-only
rm files -rf && mkdir files
echo afile > files/afile
$OSTREE commit --no-xattrs -b perms files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to drop --canonical-permissions from COMMIT_ARGS and use COMMIT_ARGS here too, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! And... it uncovered another bug 😞
It looks like file adoption (commit --consume) is also broken for bare-user-only.

(modifier->filter == NULL &&
(modifier->flags & OSTREE_REPO_COMMIT_MODIFIER_FLAGS_CANONICAL_PERMISSIONS) == 0))
/* Auto-detect bare-user-only repo, force canonical permissions. */
canonicalize_perms |= (self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: this is OK, though to be consistent with the rest of the codebase might be worth avoiding bitwise ops for these pseudo-booleans.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you prefer to write this? if (mode is user-only) { canonicalize_perms = TRUE }?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, exactly! With a newline and less braces. :)

}

modified_info = g_file_info_dup (file_info);
if (modifier->filter)

if (has_filter)
result = modifier->filter (self, path, modified_info, modifier->user_data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: hmm, we should be able to just return early here if the filter returned OSTREE_REPO_COMMIT_FILTER_SKIP. Need to double-check, maybe there's a subtle reason we still need to modify the GFileInfo.

@lucab lucab force-pushed the ups/lib-commit-canonicalize branch from f5f8014 to 132adfc Compare August 20, 2021 15:55
This tweaks commit logic to detect bare-user-only repositories and
canonicalize permissions automatically.
@lucab lucab force-pushed the ups/lib-commit-canonicalize branch from 132adfc to 8a5241d Compare August 20, 2021 16:17
@lucab
Copy link
Member Author

lucab commented Aug 20, 2021

Rebased once more.

@cgwalters cgwalters merged commit 2f675cf into ostreedev:main Aug 20, 2021
@lucab lucab deleted the ups/lib-commit-canonicalize branch August 23, 2021 10:56
@cgwalters
Copy link
Member

OK I can't run make check as non-root anymore due to this.

#2423

fixes one bug, but there are more.

@lucab
Copy link
Member Author

lucab commented Aug 26, 2021

I did test each individual PR locally plus the current tip of main, and the testsuite as non-root is green for me (PASS: 834, SKIP: 41).
I just do a ./autogen.sh && make -j && make check from a clean git state. Am I missing some tests that way? Is there maybe something else (SELinux?) involved in the failures you see?

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.

4 participants