Skip to content

core: Also refresh confext extensions when reloading notify-reload service - #33995

Merged
bluca merged 6 commits into
systemd:mainfrom
leafcompost:reload-vpick-extensions
May 20, 2025
Merged

bluca merged 6 commits into
systemd:mainfrom
leafcompost:reload-vpick-extensions

Conversation

@leafcompost

@leafcompost leafcompost commented Aug 14, 2024 •

Copy link
Copy Markdown
Contributor

ExtensionImages= and ExtensionDirectories= now let you specify vpick-named extensions; however, since they just get set up once when the service is started, you can't see newer versions without restarting the service entirely. Here, also reload confext extensions when you reload a service. This allows you to deploy a new version of some configuration and have it picked up at reload time without interruption to your workload.

Right now, we would only reload confext extensions and leave the sysext ones behind, since it didn't seem prudent to swap out what is likely program code at reload. This is made possible by only going for the SYSTEMD_CONFEXT_HIERARCHIES overlays (which only contains /etc).

This PR:

  • Adjusts service.c to also refresh extensions when needed.
  • Adds integration tests to check that a confext reload actually occurred.
  • Adds to the systemd.exec man pages to document this behavior.

This is a follow up to #24864 and #31364. Thank you to @bluca and @goenkam for help in getting this up.

@leafcompost
leafcompost marked this pull request as ready for review August 14, 2024 18:37
@github-actions github-actions Bot added the please-review PR is ready for (re-)review by a maintainer label Aug 14, 2024
@YHNdnzj

YHNdnzj commented Aug 14, 2024 •

Copy link
Copy Markdown
Member

This is a compat break. Some services might not be able to cope with the sudden change of confexts, or simply don't want these to change. Please guard this behind a RefreshOnReload= knob, that takes a bunch of indicators joined by +. I have a local branch that would do something similar, but for credentials. With the new option user would use something like RefreshOnReload=extension+credential to specify what should be refreshed.

@YHNdnzj YHNdnzj added pid1 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 Aug 14, 2024
@bluca

bluca commented Aug 14, 2024

Copy link
Copy Markdown
Member

This is a compat break. Some services might not be able to cope with the sudden change of confexts, or simply don't want these to change. Please guard this behind a RefreshOnReload= knob, that takes a bunch of indicators joined by +. I have a local branch that would do something similar, but for credentials. With the new option user would use something like RefreshOnReload=extension+credential to specify what should be refreshed.

I'm not sure it's necessary - confext are an extremely new thing, so if it's configured to use one, and it's configured to also do Reload=notify-reload, the chance of something using both and not wanting this seem extremely slim to me. In fact, with the read-only /etc/, it would be very strange if someone didn't want this. It doesn't happen automatically, you have to manually hit the reload button anyway

@bluca

bluca commented Aug 14, 2024

Copy link
Copy Markdown
Member

Merge branch 'main' into reload-vpick-extensions

There will be some button somewhere in git (or github?) to configure it to avoid pushing merge commits

for your local client you'll want git config --global pull.rebase true or so

@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 Aug 14, 2024
@YHNdnzj

YHNdnzj commented Aug 14, 2024

Copy link
Copy Markdown
Member

I'm not sure it's necessary - confext are an extremely new thing, so if it's configured to use one, and it's configured to also do Reload=notify-reload, the chance of something using both and not wanting this seem extremely slim to me. In fact, with the read-only /etc/, it would be very strange if someone didn't want this. It doesn't happen automatically, you have to manually hit the reload button anyway

I still prefer to make this opt-in. As mentioned, we'd introduce a knob for other resources anyway. And it would be inconsistent/annoying that some resources are implicitly reloaded, while others aren't

@leafcompost

Copy link
Copy Markdown
Contributor Author

Merge branch 'main' into reload-vpick-extensions

There will be some button somewhere in git (or github?) to configure it to avoid pushing merge commits

Thanks! Got rid of the merge commit (that was from using GitHub's built-in "sync with upstream" button). (@YHNdnzj you may want to slap the reviewed/needs-rework label back for now; sorry)

@bluca

bluca commented Aug 14, 2024

Copy link
Copy Markdown
Member

Even for credentials, we should just reload them - it's the right thing to do. Having such granular and complex options is just confusing. People can opt out of the automated reloads entirely by avoiding the notify-reload type, and then nothing happens, and they can have their own reload methods via ExecReload that are entirely custom and we don't do anything magic. But if the fully automated, all-bells-and-whistles thing is enabled, then we should just do the right thing, without making people go spelunking through thousands of lines of manpages, and that includes adding new stuff from time to time where it makes sense, documenting it clearly

@YHNdnzj

YHNdnzj commented Aug 14, 2024

Copy link
Copy Markdown
Member

Even for credentials, we should just reload them - it's the right thing to do. Having such granular and complex options is just confusing. People can opt out of the automated reloads entirely by avoiding the notify-reload type, and then nothing happens, and they can have their own reload methods via ExecReload that are entirely custom and we don't do anything magic.

Why should this be tied to notify-reload? I'm really not convinced. If I use cred to pass config to a program that's completely unaware of systemd and its protocols, I should still be able to reload creds. The process would read the new config - in this case creds as manually passed through --config. Actually that's a way more common pattern.

@YHNdnzj

YHNdnzj commented Aug 14, 2024

Copy link
Copy Markdown
Member

OTOH, even if a program natively supports creds + notify protocol, based on our previous promises it could assume creds are immutable and re-reading is not done on reload. It would be very confusing to users.

Note that we currently state that creds are immutable during the whole lifetime of service. Now it isn't considered a compat break anymore?

@leafcompost

leafcompost commented Aug 14, 2024 •

Copy link
Copy Markdown
Contributor Author

With how it's written right now, it does reload the confext when a systemctl reload is done, not just for the notify-reload type. Reloading a confext to /etc by default, though, is probably closer to what you would expect when you use a config file in your /etc directly without using extensions. That is the scenario that I had in my head and as things are now you would be able to read that new version when you reload.

@bluca

bluca commented Aug 14, 2024

Copy link
Copy Markdown
Member

Why should this be tied to notify-reload?

Because that's the config knob that says "I am fully opted in to all the magic, please do stuff for me", and, if documented, that's a good enough sign that stuff should happen. If you want to also make reloading creds tied to something else additionally that's fine. And if you don't want to automatically reload creds in this case, that can be discussed separately. But for this, I definitely do not want a different option, because it's just the only sensible option: with a read-only /etc/, which is what you get if you use any confext, it doesn't make sense to reload, as you cannot get any config changes, because it's read-only. So making the confext reload work automatically is the logical and expected thing.

@YHNdnzj

YHNdnzj commented Aug 14, 2024 •

Copy link
Copy Markdown
Member

Because that's the config knob that says "I am fully opted in to all the magic, please do stuff for me", and, if documented, that's a good enough sign that stuff should happen.

I can probably accept that RefreshOnReload= defaults to extension if notify-reload. But come on, some legacy systemd-unaware programs can still benefit from this. Let's not deliberately alienate those, but provide a way to enable this logic for them.

@bluca

bluca commented Aug 14, 2024

Copy link
Copy Markdown
Member

Because that's the config knob that says "I am fully opted in to all the magic, please do stuff for me", and, if documented, that's a good enough sign that stuff should happen.

I can probably accept that RefreshOnReload= defaults to extension if notify-reload. But come on, some legacy systemd-unaware programs can still benefit from this. Let's not deliberately alienate those, but provide a way to enable this logic for them.

These extensions are a systemd-specific thing, you can't really have a systemd-unaware setup and run it with extensions. Again, it does not make sense to do anything else - reloading is explicitly to notify that configuration in /etc has changed, and if your /etc is read-only, it's just meaningless to reload, as it cannot changed by definition

@YHNdnzj

YHNdnzj commented Aug 14, 2024

Copy link
Copy Markdown
Member

Because that's the config knob that says "I am fully opted in to all the magic, please do stuff for me", and, if documented, that's a good enough sign that stuff should happen.

I can probably accept that RefreshOnReload= defaults to extension if notify-reload. But come on, some legacy systemd-unaware programs can still benefit from this. Let's not deliberately alienate those, but provide a way to enable this logic for them.

These extensions are a systemd-specific thing, you can't really have a systemd-unaware setup and run it with extensions. Again, it does not make sense to do anything else - reloading is explicitly to notify that configuration in /etc has changed, and if your /etc is read-only, it's just meaningless to reload, as it cannot changed by definition

I don't grok this. The hierarchy is set up by the service manager, and the processes running inside the namespace don't really need to know what's going on?

And again, let's not force notify-reload upon others, nor the reloading to users. It can be the default, as mentioned, but we should still map it to an option, which as mentioned will need to be added anyway.

@bluca

bluca commented Aug 14, 2024

Copy link
Copy Markdown
Member

You have to opt in, not only to confext via ExtensionImages, but also to the vpick logic, otherwise it's a no-op, so you cannot use this unless you have explicitly configured it to do so, so there's no way this happens in a systemd-unaware system. And once again, it makes absolutely zero sense to not refresh these, as a reload is pointless without it, the configuration dirs are read-only, so I am not sure what one would even be reloading - nothing can change. There is no way anybody is opting in to confext PLUS opting in to vpick PLUS opting in to notify-reload PLUS calling a reload, and also wants to have yet another opt in on top of that, and would be surprised if it happens. We already have seventeen million options, at some point for some things we just need to do the right thing out of the box, and this is one of them.

@YHNdnzj

YHNdnzj commented Aug 15, 2024 •

Copy link
Copy Markdown
Member

You have to opt in, not only to confext via ExtensionImages, but also to the vpick logic, otherwise it's a no-op, so you cannot use this unless you have explicitly configured it to do so, so there's no way this happens in a systemd-unaware system.

I have never questioned about this part - but please focus on the actual payload/process/program. Then would run in a FHS environment with all overlays/... set up by service manager. They do not need to know what's exactly going on under the hood.

And once again, it makes absolutely zero sense to not refresh these, as a reload is pointless without it, the configuration dirs are read-only, so I am not sure what one would even be reloading - nothing can change. There is no way anybody is opting in to confext PLUS opting in to vpick PLUS opting in to notify-reload PLUS calling a reload, and also wants to have yet another opt in on top of that, and would be surprised if it happens. We already have seventeen million options, at some point for some things we just need to do the right thing out of the box, and this is one of them.

Again, that's only one part of the story, which I agree to enable as default. However, payloads that has no understanding of systemd CAN still use this feature. And this impl is not restrained to notify-reload either - as explained by @leafcompost. Hence I'm really baffled why you're constantly bringing that up.

@bluca

bluca commented Aug 15, 2024

Copy link
Copy Markdown
Member

You have to opt in, not only to confext via ExtensionImages, but also to the vpick logic, otherwise it's a no-op, so you cannot use this unless you have explicitly configured it to do so, so there's no way this happens in a systemd-unaware system.

I have never questioned about this part - but please focus on the actual payload/process/program. Then would run in a FHS environment with all overlays/... set up by service manager. They do not need to know what's exactly going on under the hood.

Why would they need to?

And once again, it makes absolutely zero sense to not refresh these, as a reload is pointless without it, the configuration dirs are read-only, so I am not sure what one would even be reloading - nothing can change. There is no way anybody is opting in to confext PLUS opting in to vpick PLUS opting in to notify-reload PLUS calling a reload, and also wants to have yet another opt in on top of that, and would be surprised if it happens. We already have seventeen million options, at some point for some things we just need to do the right thing out of the box, and this is one of them.

Again, that's only one part of the story, which I agree to enable as default. However, payloads that has no understanding of systemd CAN still use this feature.

No, they cannot, as sd-notify needs to be used

And this impl is not restrained to notify-reload either - as explained by @leafcompost. Hence I'm really baffled why you're constantly bringing that up.

Yes, that's something to fix, I'll submit a full review later today

Comment thread src/core/service.c Resolved
Comment thread src/core/service.c Resolved
Comment thread src/core/service.c Resolved
Comment thread src/core/service.c Resolved
Comment thread src/core/namespace.c Resolved
Comment thread src/core/namespace.c Resolved
Comment thread src/core/namespace.c Resolved
Comment thread src/core/service.c Resolved
@bluca

This comment was marked as resolved.

@bluca bluca added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR and removed please-review PR is ready for (re-)review by a maintainer labels Aug 15, 2024
leafcompost and others added 3 commits May 14, 2025 15:13
Include 'socat' as part of the tools built with minimal-0/minimal-1
images used for integration testing. This would allow notify-reload
services to signal reloading without using the systemd-notify tool
and other socket communication test cases.

Note that 'ncat', although included in the minimal image, cannot be
used because it dies before systemd can figure out the unit it's
from. See 67e5622.
Add a path_uses_vpick helper method to determine if a path matches
the vpick format ('PATH/NAME.SUFFIX.v' or 'PATH.v/NAME___.SUFFIX'):

	/* good: returns 1 */
	path_uses_vpick("/var/lib/machines/mymachine.raw.v/")
	path_uses_vpick("to.v/foo___.raw

	/* bad: returns <= 0 */
	path_uses_vpick("/")
	path_uses_vpick("path/to/foo.mp4.vtt
@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 May 14, 2025
@bluca

bluca commented May 14, 2025

Copy link
Copy Markdown
Member

hmm, could you add a test that checks this in combination with PrivateUsers=? i am pretty sure this is might reveal some issues because you enter the mount namespace, but not the userns that owns it.

Added, seems to work fine

@bluca

bluca commented May 14, 2025

Copy link
Copy Markdown
Member

Comment thread src/core/namespace.c Resolved
Comment thread src/core/namespace.c Resolved
Comment thread src/core/namespace.c Resolved
Comment thread src/core/namespace.c Resolved
Comment thread src/core/namespace.c Resolved
Comment thread src/core/namespace.c Resolved
leafcompost and others added 3 commits May 19, 2025 13:36
`ExtensionImages=` and `ExtensionDirectories=` now let you specify
vpick-named extensions; however, since they just get set up once when
the service is started, you can't see newer versions without restarting
the service entirely.  Here, also reload confext extensions when you
reload a service. This allows you to deploy a new version of some
configuration and have it picked up at reload time without interruption
to your workload.

Right now, we would only reload confext extensions and leave the sysext
ones behind, since it didn't seem prudent to swap out what is likely
program code at reload. This is made possible by only going for the
`SYSTEMD_CONFEXT_HIERARCHIES` overlays (which only contains `/etc`).

Implementation wise, this uses the new kernel API and two collaborating
child processes under the host & child namespaces in order to gather the
right FDs needed:

  - (1) In child, set up the extension images and directories in a slave
	mountns, and obtain their FDs.
  - (2) Fork into a grandchild under target process namespace, and do a
        "fake" unmount to obtain the FD of the underlying target folder
	say /etc).
  - (3) In the child again, set up new overlay under host NS rights.

We do not want to do I/O heavy jobs inline in PID1 blocking the state
machine, so add separate async states to handle this case.

Co-authored-by: Luca Boccassi <[email protected]>
In TEST-50-DISSECT.dissect, this adds the following cases:
- testservice-50g: vpick extension in ExtensionDirectories
- testservice-50h: vpick extension in ExtensionImages
- testservice-50i: ExtensionDirectories + RootImage
- testservice-50j: ExtensionDirectories + RootDirectory
@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 please-review PR is ready for (re-)review by a maintainer labels May 20, 2025
@bluca
bluca merged commit 6946eed into systemd:main May 20, 2025
@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 May 20, 2025
YHNdnzj added a commit that referenced this pull request May 21, 2025
@septatrix

Copy link
Copy Markdown
Contributor

I have a local branch that would do something similar, but for credentials

Any chance you could push that? It would be really great to be able to rotate secrets that way

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.

Signed, verity-protected, live configuration updates: confext