Skip to content

core/service: imply Type=exec if credentials are used - #32612

Merged
YHNdnzj merged 2 commits into
systemd:mainfrom
YHNdnzj:creds-test
Jul 21, 2024
Merged

YHNdnzj merged 2 commits into
systemd:mainfrom
YHNdnzj:creds-test

Conversation

@YHNdnzj

@YHNdnzj YHNdnzj commented May 1, 2024 •

Copy link
Copy Markdown
Member

See also: #32583 (comment)

@YHNdnzj YHNdnzj added the pid1 label May 1, 2024
@YHNdnzj
YHNdnzj requested a review from poettering May 1, 2024 13:37
@github-actions github-actions Bot added documentation tests please-review PR is ready for (re-)review by a maintainer labels May 1, 2024
@github-actions

github-actions Bot commented May 1, 2024 •

Copy link
Copy Markdown

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.

@yuwata

yuwata commented May 1, 2024

Copy link
Copy Markdown
Member

When credentials are used with Type=simple, i.e. when
multiple sd-executor instances are running in parallel
for a single service, the state of final credential dir
might be unexpected wrt path_is_mount_point() and other
steps.

What happens when Type=simple is forcibly used with credentials?? Should we refuse such combination? Or, should we fix something in loading credentials??

@YHNdnzj

YHNdnzj commented May 1, 2024 •

Copy link
Copy Markdown
Member Author

What happens when Type=simple is forcibly used with credentials?? Should we refuse such combination?

I don't feel too strong about this. But note that this race only happens if ExecStartPost= is used, so refusing Type=simple might be overkill?

Or, should we fix something in loading credentials??

The credentials are created in a shared final dir, so that pretty much requires locking? Instead of doing locking in sd-executor, I think our job logic is sufficient to handle this in a reasonable enough way, i.e. Type=exec.

@poettering

Copy link
Copy Markdown
Member

So I take it that the problem this is addresses is if creds are used together with Type=simple and at least one ExecStartPost= line?

I have the suspicion that ExecStartPost= is not that commonly used. It is definitely used by some, but probably not the most typical thing.

In an ideal world we'd just make this combo work, i.e. make the credential setup logic safe so that multiple of them can run in parallel (a simple way could be via some fd we pass to all instances of systemd-executor that we use file locks on, for the time window when we are setting up the creds).

Now, if we are too lazy to just make it work for I think the next best thing would be to simply catch the explicit case (i.e. creds + Type=simple + ExecStartPost=) and then warn about this, explaining in a log message that this is currently not safe, and people should use Type=exec to make it work.

So basically what I am saying, that fixing this properly, or keeping the door open to fixing this properly is better than changing the logic to route around it.

Does that make any sense?

@YHNdnzj

YHNdnzj commented May 2, 2024

Copy link
Copy Markdown
Member Author

In an ideal world we'd just make this combo work, i.e. make the credential setup logic safe so that multiple of them can run in parallel (a simple way could be via some fd we pass to all instances of systemd-executor that we use file locks on, for the time window when we are setting up the creds).

I'd still say that the way we make this work could (and IMO should just) be Type=exec. We generally recommend Type=exec over Type=simple, and it solves this race perfectly. We only run each control process in sequence, so only the main process needs to be synchronized.

Adding a warning for people that use Type=simple + creds + ExecStartPost= is good, and that should be done nonetheless. But shoving in another synchronization fd to solve a problem that can just be easily solved using job engine is not worth it.

@YHNdnzj

YHNdnzj commented May 3, 2024 •

Copy link
Copy Markdown
Member Author

(I'll be off for a few days. Unsetting the please-review flag since the warning shall be added)

@YHNdnzj YHNdnzj removed the please-review PR is ready for (re-)review by a maintainer label May 3, 2024
@github-actions github-actions Bot added the please-review PR is ready for (re-)review by a maintainer label May 7, 2024
@YHNdnzj YHNdnzj added this to the v257 milestone May 15, 2024
@YHNdnzj

YHNdnzj commented May 15, 2024 •

Copy link
Copy Markdown
Member Author

Another reason why I think explicit ordering through state engine is desirable: If there're multiple sd-executor instances, the order in which exec_setup_credentials gets called isn't deterministic, and locking doesn't prevent the one for ExecStartPost= to run before the one for ExecStart=.

YHNdnzj added 2 commits July 21, 2024 19:10
When credentials are used with Type=simple + ExecStartPost=,
i.e. when multiple sd-executor instances are running in parallel
for a single service, the state of final credential dir
might be unexpected wrt path_is_mount_point() and other
steps. So, let's imply Type=exec if not explicitly specified,
and emit a warning otherwise.
@bluca bluca 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 Jul 21, 2024
@YHNdnzj
YHNdnzj merged commit 52ffb3c into systemd:main Jul 21, 2024
@YHNdnzj
YHNdnzj deleted the creds-test branch July 21, 2024 20:27
@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 Jul 21, 2024
dniku pushed a commit to dniku/selfhostblocks that referenced this pull request Nov 3, 2026
Remove the Type=exec workaround and use the NixOS module's Type=notify default. The systemd notification issue behind the workaround was fixed in systemd 256; the pinned nixpkgs provides 261.3:
systemd/systemd#32612

Extend the existing restart test to call Forgejo's version API immediately after systemctl returns, verifying that restart completion means the service is ready.

Validation: vm_forgejo_basic evaluates with Type=notify and formatting passes. The new runtime assertion still requires CI because this container lacks KVM.
ibizaman pushed a commit to dniku/selfhostblocks that referenced this pull request Nov 4, 2026
Remove the Type=exec workaround and use the NixOS module's Type=notify default. The systemd notification issue behind the workaround was fixed in systemd 256; the pinned nixpkgs provides 261.3:
systemd/systemd#32612

Extend the existing restart test to call Forgejo's version API immediately after systemctl returns, verifying that restart completion means the service is ready.

Validation: vm_forgejo_basic evaluates with Type=notify and formatting passes. The new runtime assertion still requires CI because this container lacks KVM.
ibizaman pushed a commit to ibizaman/selfhostblocks that referenced this pull request Nov 4, 2026
Remove the Type=exec workaround and use the NixOS module's Type=notify default. The systemd notification issue behind the workaround was fixed in systemd 256; the pinned nixpkgs provides 261.3:
systemd/systemd#32612

Extend the existing restart test to call Forgejo's version API immediately after systemctl returns, verifying that restart completion means the service is ready.

Validation: vm_forgejo_basic evaluates with Type=notify and formatting passes. The new runtime assertion still requires CI because this container lacks KVM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants