Skip to content

creds: make available to all ExecStartPre= and ExecStart= processes - #27279

Merged
bluca merged 1 commit into
systemd:mainfrom
bluca:creds_pre
Apr 17, 2023
Merged

bluca merged 1 commit into
systemd:mainfrom
bluca:creds_pre

Conversation

@bluca

@bluca bluca commented Apr 15, 2023

Copy link
Copy Markdown
Member

Fixes #27275

@github-actions github-actions Bot added tests please-review PR is ready for (re-)review by a maintainer labels Apr 15, 2023
@bluca

bluca commented Apr 15, 2023

Copy link
Copy Markdown
Member Author

Any reason not to make these available to stop/reload commands too?

@YHNdnzj
YHNdnzj requested a review from poettering April 16, 2023 12:53

@YHNdnzj YHNdnzj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would like @poettering's comment on ExecStop= and friends

@poettering

Copy link
Copy Markdown
Member

loading credentials might involve socket activation and stuff. And that's something you really shouldn't rely on during shutdown, hence I'd be very careful with loading creds in ExecStop=.

Sounds OK to load in ExecStartPre=, but let's be careful otherwise.

Comment thread src/core/service.c Resolved
@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 Apr 17, 2023
@poettering

Copy link
Copy Markdown
Member

i am not the maintainer of the stable git tree, but I'd not consider this backport worthy. It's an entirely new feature, not a regression nor a bug. This never was supposed. Sounds OK to support it, but that's a new thing.

@bluca

bluca commented Apr 17, 2023

Copy link
Copy Markdown
Member Author

i am not the maintainer of the stable git tree, but I'd not consider this backport worthy. It's an entirely new feature, not a regression nor a bug. This never was supposed. Sounds OK to support it, but that's a new thing.

Not really, this already works without sandboxing - it's only adding a sandboxing option that results in a mount namespace being used that breaks it, but it works otherwise. Hence why to me it's a bug fix, as that's an unexpected behaviour.

@github-actions github-actions Bot added 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 Apr 17, 2023
@bluca bluca removed the tests label Apr 17, 2023
@YHNdnzj YHNdnzj 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 please-review PR is ready for (re-)review by a maintainer labels Apr 17, 2023
@bluca
bluca merged commit c9210b7 into systemd:main Apr 17, 2023
@github-actions github-actions Bot removed 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 Apr 17, 2023
@poettering

Copy link
Copy Markdown
Member

Not really, this already works without sandboxing - it's only adding a sandboxing option that results in a mount namespace being used that breaks it, but it works otherwise. Hence why to me it's a bug fix, as that's an unexpected behaviour.

hmm? can't parse this.

@bluca

bluca commented Apr 20, 2023

Copy link
Copy Markdown
Member Author

Not really, this already works without sandboxing - it's only adding a sandboxing option that results in a mount namespace being used that breaks it, but it works otherwise. Hence why to me it's a bug fix, as that's an unexpected behaviour.

hmm? can't parse this.

Creds work with any number of ExecStartPre and ExecStart processes before this change, as long as there was no mount namespace in use by the unit. It's only when a mount namespace is enabled that it broke and this fix is needed. Hence, to me, it's a bug fix, because that's quite unexpected and clearly not documented.

@bluca
bluca deleted the creds_pre branch April 20, 2023 14:49
@poettering

Copy link
Copy Markdown
Member

are you sure that's the case? i mean, sure creds survived if namespaces are off, but at least for ExecStartPre= that#s not the case.

either way, i would claim it's mostly a side-effect that this ever worked for any setup tha tis not ExecMain.

@veehaitch

Copy link
Copy Markdown
Contributor

I reported #27275 as the following news entry got me thinking this should have worked (with or without namespaces):

systemd/NEWS

Lines 816 to 817 in 6b8e905

* Service credentials (i.e. SetCredential=/LoadCredential=/…) will now
also be provided to ExecStartPre= processes.

@bluca

bluca commented Apr 20, 2023

Copy link
Copy Markdown
Member Author

are you sure that's the case? i mean, sure creds survived if namespaces are off, but at least for ExecStartPre= that#s not the case.

either way, i would claim it's mostly a side-effect that this ever worked for any setup tha tis not ExecMain.

Yes:

[root@image ~]# systemd-run -p PrivateTmp=yes -p 'LoadCredential=os:/etc/os-release' -p 'ExecStartPre=true' -p 'ExecStartPre=systemd-creds cat os' --wait --pipe true
Running as unit: run-u11.service
Failed to open credentials directory '/run/credentials/run-u11.service': No such file or directory
Failed to open credentials directory: No such file or directory
Finished with result: exit-code
Service runtime: 43ms
CPU time consumed: 41ms
[root@image ~]# systemd-run -p 'LoadCredential=os:/etc/os-release' -p 'ExecStartPre=true' -p 'ExecStartPre=systemd-creds cat os' --wait --pipe true
Running as unit: run-u10.service
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo
Finished with result: success
Main processes terminated with: code=exited/status=0
Service runtime: 23ms
CPU time consumed: 18ms

YHNdnzj added a commit to YHNdnzj/systemd that referenced this pull request Feb 3, 2024
This is similar to systemd#27275 - currently, we set up credentials in
service_run_next_control() but not in service_enter_start_post(),
causing the first ExecStartPost= command to fail to access credentials
when using namespacing (see also systemd#27279). Let's set EXEC_WRITE_CREDENTIALS
in service_enter_start_post() too.

Fixes systemd#31194
YHNdnzj added a commit to YHNdnzj/systemd that referenced this pull request Feb 4, 2024
This seems to be a mistake in systemd#27279. I believe credentials
should not be made available to reload tasks - they should
only signal the main process about reloading and wait for
that to complete.
YHNdnzj added a commit to YHNdnzj/systemd that referenced this pull request Feb 4, 2024
This seems to be a mistake in systemd#27279. I believe credentials
should not be made available to reload tasks - they should
only signal the main process about reloading and wait for
that to complete.
YHNdnzj added a commit to YHNdnzj/systemd that referenced this pull request Feb 4, 2024
This seems to be a mistake in systemd#27279. I believe credentials
should not be made available to reload tasks - they should
only signal the main process about reloading and wait for
that to complete.
YHNdnzj added a commit to YHNdnzj/systemd that referenced this pull request Feb 4, 2024
This seems to be a mistake in systemd#27279. I believe credentials
should not be made available to reload tasks - they should
only signal the main process about reloading and wait for
that to complete.
YHNdnzj added a commit to YHNdnzj/systemd that referenced this pull request Feb 4, 2024
This seems to be a mistake in systemd#27279. I believe credentials should
not be made available to condition or reload tasks. In most cases
they're irrelevant from the actual job of the service. Also, currently
the first ExecCondition= or ExecReload= cannot access creds anyway,
making the incompatibility introduced negligible.

If people actually come up with valid use cases, we can always
revisit this.
@Gunni

Gunni commented Jun 26, 2025

Copy link
Copy Markdown

Note that I nack'd this as a fix in #24291 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Credentials only accessible to very first ExecStartPre= when using sandboxing (mount namespace)

5 participants