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

homed uidmapping (just for the directory backend) #21136

Merged
merged 6 commits into from Oct 27, 2021

Conversation

poettering
Copy link
Member

This is the first part of #21135, to make things easier to digest for reviewers.

This contains uidmapping for the directory backend only. the fscrypt + luks + cifs changes are left out and will be submitted in a separate PR later on.

@bluca
Copy link
Member

bluca commented Oct 26, 2021

../src/home/homework-mount.c:123:30: error: unused variable 'a' [-Werror,-Wunused-variable]
        _cleanup_free_ char *a = NULL;
                             ^

@bluca bluca added the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Oct 26, 2021
@poettering
Copy link
Member Author

force pushed a new version, with the CI issue hopefully fixed

@poettering poettering removed the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Oct 26, 2021
@bluca
Copy link
Member

bluca commented Oct 26, 2021

test-process-util in CentOS is failing, but doesn't seem related as the changes are contained in src/home - @mrc0mmand seen this before?

22:13:53 #1  0x00007f32ccef1db5 in abort () from /lib64/libc.so.6
22:13:53 No symbol table info available.
22:13:53 #2  0x00007f32cd406a85 in log_assert_failed (
22:13:53     text=text@entry=0x408e00 "limit >= INT_MAX || get_process_ppid(limit+1, NULL) == -ESRCH", file=file@entry=0x407b63 "src/test/test-process-util.c", 
22:13:53     line=line@entry=855, 
22:13:53     func=func@entry=0x408f90 <__PRETTY_FUNCTION__.10378> "test_get_process_ppid") at ../src/basic/log.c:866
22:13:53 No locals.
22:13:53 #3  0x0000000000406aa4 in test_get_process_ppid ()
22:13:53     at ../src/test/test-process-util.c:855
22:13:53         limit = 3416
22:13:53         r = <optimized out>
22:13:53         __PRETTY_FUNCTION__ = "test_get_process_ppid"
22:13:53         __func__ = "test_get_process_ppid"
22:13:53 #4  0x0000000000406e53 in main (argc=1, argv=0x7ffefe2da4a8)
22:13:53     at ../src/test/test-process-util.c:925
``

@mrc0mmand
Copy link
Member

test-process-util in CentOS is failing, but doesn't seem related as the changes are contained in src/home - @mrc0mmand seen this before?

22:13:53 #1  0x00007f32ccef1db5 in abort () from /lib64/libc.so.6
22:13:53 No symbol table info available.
22:13:53 #2  0x00007f32cd406a85 in log_assert_failed (
22:13:53     text=text@entry=0x408e00 "limit >= INT_MAX || get_process_ppid(limit+1, NULL) == -ESRCH", file=file@entry=0x407b63 "src/test/test-process-util.c", 
22:13:53     line=line@entry=855, 
22:13:53     func=func@entry=0x408f90 <__PRETTY_FUNCTION__.10378> "test_get_process_ppid") at ../src/basic/log.c:866
22:13:53 No locals.
22:13:53 #3  0x0000000000406aa4 in test_get_process_ppid ()
22:13:53     at ../src/test/test-process-util.c:855
22:13:53         limit = 3416
22:13:53         r = <optimized out>
22:13:53         __PRETTY_FUNCTION__ = "test_get_process_ppid"
22:13:53         __func__ = "test_get_process_ppid"
22:13:53 #4  0x0000000000406e53 in main (argc=1, argv=0x7ffefe2da4a8)
22:13:53     at ../src/test/test-process-util.c:925
``

Yep, I've seen the a couple of times and it's definitely unrelated.

src/home/homework-mount.c Show resolved Hide resolved
return TAKE_FD(userns_fd);
}

int home_shift_uid(int dir_fd, const char *target, uid_t stored_uid, uid_t exposed_uid, int *ret_mount_fd) {
Copy link
Member

Choose a reason for hiding this comment

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

This will be useful in the near future for other components, maybe add it directly to the library (eg, basic/namespace-util.c or similar)? The only homed-specific part as far as I can see are HOME_UID_MIN and HOME_UID_MAX, which could simply be taken as parameters.
Then there could even be a unit test added, which would be quite useful to ensure the fallback/detection works nicely everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

i am always concerned about putting stuff in src/basic/ + src/shared/ if it doesn't have at least two users — unless it's a totally obvious case.

I am not sure about this one. Yes, this might be something we can reuse later, but I am pretty sure it's something that will require further modifications. But if that's the case we might as well move it into generic code later on. Unless the needed semantics of the other stuff are really clear and obvious I doubt we can generalize this properly.

Copy link
Member

Choose a reason for hiding this comment

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

ok, makes sense

@poettering
Copy link
Member Author

added the assert.

(actually a few others too)

ptal

Copy link
Member

@bluca bluca left a comment

Choose a reason for hiding this comment

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

lgtm

@bluca bluca added the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Oct 27, 2021
Copy link
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

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

One question, and one minor suggestion.

src/home/home-util.h Show resolved Hide resolved
src/home/homework-directory.c Outdated Show resolved Hide resolved
@yuwata yuwata added good-to-merge/with-minor-suggestions and removed good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed labels Oct 27, 2021
Let's migrate home_create_directory_or_subvolume() to also use HomeSetup
for storing its runtime objects we'd like to destroy in case of failure.

In the beginning this is just the root_fd, but later on we can add more.

No change in behaviour, just shifting things around.
…ting record

For the other backends we synthesize a "binding" section in the json
record of the user that stores meta info how a user record is "bound" to
the local host. It declares storage info and such. Let's do the same for
the directory/subvolume backends.
…ser-home-mount before moving them to /home

This does what we already do for the LUKS backend: instead of mounting
the source directory directly to the final home dir, we instead bind
mount it to /run/systemd/user-home-mount (where /run/ is unshared and
specific to our own mount namespace), then adjust its mount flags and
then bind mount it in a single atomic operation into the final
destination, fully set up.

This doesn't improve much on its own, but it makes things a tiny bit
more correct: this way MS_NODEV/MS_NOEXEC/MS_NOSUID will already be
applied when the bind mount appears in the host mount namespace, instead
of being adjusted after the fact.

Doing things this way also makes things work more like the LUKS backend,
reducing surprises. Most importantly it's preparation for doing
uidmapping for directory homes, added in a later commit.
This new helper is not used yet, but it's useful for apply UID/GID
shifts so that the underlying home dir can use an arbitrary UID (for
example "nobody") and we'll still make it appear as owned by the target
UID.

This operates roughly like this:

1. The relevant underlying UID is mapped to the target UID
2. Everything in the homed UID range except for the target UID is left
   unmapped (and thus will appear as "nobody")
3. Everything in the 16bit UID range outside of the homed UID
   range/target UID/nobody user is mapped to itself
4. Everything else is left unmapped (in particular everything outside of
   the 16 bit range).

Why do it like this?

The 2nd rule done to ensure that any files from homed's managed UID
range that do not match the user's own UID will be shown as "unmapped"
basically. Of course, IRL this should never happen, except if people
managed to manipulate the underlying fs directly.

The 3rd rule is to allow that if devs untar an OS image it more or
less just works as before: 16bit UIDs outside of the homed range will
be mapped onto themselves: you can untar things and tar it back up and
things will just work.
@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels Oct 27, 2021
@poettering
Copy link
Member Author

poettering commented Oct 27, 2021

made the two indicated changes. since so minor upgrading green label again

@yuwata yuwata merged commit 1462a94 into systemd:main Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed homed homed, homectl, pam_homed
Development

Successfully merging this pull request may close these issues.

None yet

4 participants