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

core: do not enforce PrivateTmp with DynamicUser if /tmp and /var/tmp are already private tmpfs #32724

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bluca
Copy link
Member

@bluca bluca commented May 8, 2024

DynamicUser= enables PrivateTmp= implicitly to avoid files owned by reusable uids
leaking into the host. Configuring TemporaryFileSystem=/tmp/ /var/ also ensures
this, so allow it as an alternative, since it has less impactful semantics with
respect to PrivateTmp=yes, which links the mount namespace to the host's /tmp/
instead.

@github-actions github-actions bot added documentation tests portable Anything to do with systemd-portable and portablectl and portables please-review PR is ready for (re-)review by a maintainer labels May 8, 2024
Copy link

github-actions bot commented May 8, 2024

Note

We had successfully released a new major release. We are no longer in a development freeze phase.
We will try our best to get back to your PR as soon as possible. Thank you for your patience.

src/core/unit.c Outdated Show resolved Hide resolved
src/core/unit.c Outdated Show resolved Hide resolved
@bluca bluca force-pushed the dynamic_user_no_private_tmp branch from 8e1acb1 to 35570fa Compare May 8, 2024 19:34
@bluca bluca force-pushed the dynamic_user_no_private_tmp branch from 35570fa to cf0dd4e Compare May 8, 2024 22:34
@bluca bluca changed the title core: do not enforce PrivateTmp with DynamicUser if /tmp and /var/tmp are tmpfs core: do not enforce PrivateTmp with DynamicUser if /tmp and /var/tmp are already private tmpfs May 9, 2024
@bluca bluca added this to the v256 milestone May 9, 2024
@YHNdnzj YHNdnzj requested a review from poettering May 9, 2024 16:38
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.

Should we also check InaccessiblePaths=, BindReadOnlyPaths= ??

src/core/unit.c Outdated Show resolved Hide resolved
@bluca
Copy link
Member Author

bluca commented May 10, 2024

Should we also check InaccessiblePaths=, BindReadOnlyPaths= ??

Not sure, but if so then it's a pre-existing issue as we don't do any enforcement in PrivateTmp=yes either, so it can be handled in a separate PR if needed:

$ sudo systemd-run --wait --quiet -p DynamicUser=yes -p BindPaths=/tmp/ touch /tmp/foo
$ ls -l /tmp/foo
-rw-r--r-- 1 63013 63013 0 May 10 09:54 foo

src/core/unit.c Outdated Show resolved Hide resolved
src/core/unit.c Outdated

if (!tmp_found || !var_tmp_found)
ec->private_tmp = true;

Copy link
Member

Choose a reason for hiding this comment

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

that said, maybe a simple fix is to not imply PrivateTmp= in case of DynamicUser=1 but instead imply TemporaryFileSystem=/tmp /var/tmp?

wouldn't that be better and simpler?

i mean, there definitely is value in keeping dynamic uids/gids local to file systems that are destroyed when the service is dead, hence changing the logic liek that would make sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I've applied this change, it's slightly backward incompatible unlike the original version but if that's what it takes

@poettering poettering added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels May 10, 2024
@poettering
Copy link
Member

or well, i generally think that things such as PrivateTmp=1 as high-level knobs are the way to go, and they should abstract what happens in the bg a bit.

so i think we should just make sure it has a different effect in case DynamicUser=1 is used, i.e. make it act like TemporaryFs=/tmp + Bind=/var/tmp:/tmp

@bluca bluca force-pushed the dynamic_user_no_private_tmp branch from 07f51a2 to 772b5b8 Compare May 10, 2024 20:51
@github-actions github-actions bot added documentation tests please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels May 10, 2024
@bluca
Copy link
Member Author

bluca commented May 10, 2024

or well, i generally think that things such as PrivateTmp=1 as high-level knobs are the way to go, and they should abstract what happens in the bg a bit.

so i think we should just make sure it has a different effect in case DynamicUser=1 is used, i.e. make it act like TemporaryFs=/tmp + Bind=/var/tmp:/tmp

This is logically equivalent to your comment above - we do want to enforce that private tmpfses are used with DynamicUser=yes, so the PrivateTmp knob becomes essentially meaningless in that case - whether it's enabled or disabled, same result applies

I am not making /tmp an alias of /var/tmp as that changes too much the existing setup, where they are different directories, we can't just change that from one version to another as it is most likely going to break things, DynamicUser is used by hundreds of units in Debian alone, plus it's the default for portables

bluca added 2 commits May 11, 2024 00:49
… are tmpfs

DynamicUser= enables PrivateTmp= implicitly to avoid files owned by reusable uids
leaking into the host. Configuring TemporaryFileSystem=/tmp/ /var/ also ensures
this, so allow it as an alternative, since it has less impactful semantics with
respect to PrivateTmp=yes, which links the mount namespace to the host's /tmp
instead.
It is already implied by DynamicUser=yes if not set, but dropping it
allows users to instead define TemporaryFileSystem=/tmp/ /var/tmp/
in their portable services, which has fewer side effects.
@bluca bluca force-pushed the dynamic_user_no_private_tmp branch from 772b5b8 to 7cc35c8 Compare May 10, 2024 23:50
@bluca bluca modified the milestones: v256, v257 May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation pid1 please-review PR is ready for (re-)review by a maintainer portable Anything to do with systemd-portable and portablectl and portables tests
Development

Successfully merging this pull request may close these issues.

None yet

4 participants