Skip to content

core/service: support credentials refreshing on reload - #40093

Merged
daandemeyer merged 17 commits into
systemd:mainfrom
YHNdnzj:reload-creds
Feb 13, 2026
Merged

daandemeyer merged 17 commits into
systemd:mainfrom
YHNdnzj:reload-creds

Conversation

@YHNdnzj

@YHNdnzj YHNdnzj commented Dec 15, 2025

Copy link
Copy Markdown
Member

Closes #21099
Closes #35227

@septatrix

Copy link
Copy Markdown
Contributor

Will this work with all services, or only with notify-reload like the extension refreshing currently does?

@YHNdnzj

YHNdnzj commented Dec 15, 2025

Copy link
Copy Markdown
Member Author

Will this work with all services, or only with notify-reload like the extension refreshing currently does?

Extension refreshing has been reworked in #39376 to work with any service already ;)

@septatrix

Copy link
Copy Markdown
Contributor

Will this work with all services, or only with notify-reload like the extension refreshing currently does?

Extension refreshing has been reworked in #39376 to work with any service already ;)

Great! That must have slipped under my radar (and I find no mention in NEWS). Though I guess the man pages are still outdated?

<para>This option can be used together with a <option>notify-reload</option> service type and
<citerefentry><refentrytitle>systemd.v</refentrytitle><manvolnum>7</manvolnum></citerefentry>
to manage configuration updates. When such a service carrying confext images is reloaded via
<command>systemctl reload foo.service</command> or equivalent D-Bus method, the confext itself will
be reloaded to pick up any changes. This only applies to confext extensions. Note that in case a
service has this configuration enabled at first, and then it is subsequently removed in an update
followed by a daemon-reload operation, reloading the confexts will be a no-op, and a full service
restart is required instead. See
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
also for details.</para>

@YHNdnzj

YHNdnzj commented Dec 16, 2025

Copy link
Copy Markdown
Member Author

Though I guess the man pages are still outdated?

Updated now

@YHNdnzj YHNdnzj changed the title wip: core/service: support credentials refreshing on reload core/service: support credentials refreshing on reload Dec 16, 2025
@YHNdnzj

YHNdnzj commented Feb 10, 2026

Copy link
Copy Markdown
Member Author

CI is passing, yay! PTAL!

Follow-up for 21eb636

Our sd_notify() protocol uses newline as separator, which
is not suitable for direct logging.
We should only fall back to the dir_is_empty() check if
it's a plain dir, where we can't reasonably differentiate
populated yet empty vs not set up. Otherwise let's stick
to the existing mount if we're told to reuse it.

Yes, this is a minor compat break, but with the to-be-introduced
credential reloading support it should fulfill the goal of
keeping the passed set of credentials stable better, while
still allowing things to be refreshed when requested.
Starting from cfbf753 we'd always
install the credentials dir regardless of whether it's empty,
with the correct permissions. Hence the problem stated in the comment
should no longer be a concern. Moreover, this ensures later in
setup_namespace() the mountpoint would be in-place. This is important
for credential reloading as it saves the trouble of remounting
the upper tmpfs as rw again and create the mountpoint.
… exec_setup_credentials()

No functional change, preparation for credential reloading support,
where we'd operate on Unit rather than ExecParameters.
Typically when entering a namespace the userns is handled last,
because we assume our process is more privileged than the userns.
However, that assumption no longer holds for user managers, which
have no privilege over initial userns and all other namespaces
are actually owned by the userns unshared first (in executor).
Hence, let's add another flavor namespace_enter_delegated() to
accommodate that use case.
This allows controlling resources to be refreshed before performing
reload, with one extra benefit that in the future we can permit
"seemless reload"s, i.e. no active signaling is done to the main process
after refreshing get updated. This could come in handy for programs
that loads stuff on demand or watches changes via inotify.
… even without exec/notify-reload

This was originally brought up by @poettering. If the process
loads stuff on demand and flushes them out after each use,
or actively monitors file changes, they can be reloaded
by merely refreshing the resources.

tunnel_fds[1] = safe_close(tunnel_fds[1]);

/* Wait for the child to validate the creds tree in the unit namespace is populated. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Messed up comment

Comment thread src/core/service.c
Comment on lines +759 to +762
if (s->refresh_on_reload_set && s->refresh_on_reload_flags != _SERVICE_REFRESH_ON_RELOAD_ALL) {
if (FLAGS_SET(s->refresh_on_reload_flags, SERVICE_RELOAD_EXTENSIONS))
service_can_reload_extensions(s, /* warn = */ true);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This could use a comment, not exactly sure at a glance what this does

Comment thread src/core/service.c
Comment on lines +901 to +904
if (!s->refresh_on_reload_set) {
assert_cc(SERVICE_REFRESH_ON_RELOAD_DEFAULT == SERVICE_RELOAD_EXTENSIONS);
s->refresh_on_reload_flags = service_can_reload_extensions(s, /* warn = */ false) ? SERVICE_RELOAD_EXTENSIONS : 0;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ditto, could use a comment

Comment thread src/core/service.c
_cleanup_free_ char *v = NULL;
ServiceRefreshOnReload f;

r = extract_first_word(&s, &v, NULL, 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing comments for null/0 arguments

Comment thread src/core/service.c
else if (streq(key, "refreshed-mask")) {
r = service_refresh_on_reload_from_string_many(value, &s->refreshed_mask);
if (r < 0)
log_unit_debug_errno(u, r, "Failed to parse refresh-mask value: %s", value);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

refreshed-mask

Comment on lines +1042 to +1043
r = service_refresh_on_reload_from_string_many("extensions", &flags);
ASSERT_OK(r);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why assign to r here?

Comment on lines +1050 to +1051
r = service_refresh_on_reload_from_string_many("credentials extensions", &flags);
ASSERT_OK(r);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ditto

systemctl start "$UNIT_NAME"
ls -l /run/credentials/"$UNIT_NAME"/

echo "neu" >/run/credstore/test.creds.new-refresh-1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

neu => new?

@daandemeyer

Copy link
Copy Markdown
Collaborator

None of my comments actually matter, so merging, feel free to do a follow up commit for yourself if you feel strongly about any of these.

@bluca

bluca commented Feb 13, 2026

Copy link
Copy Markdown
Member

The new test fails:

97/98 integration-tests - systemd:TEST-54-CREDS TIMEOUT 1800.19s (exit status 254 or 0xfe)

@YHNdnzj

YHNdnzj commented Feb 13, 2026

Copy link
Copy Markdown
Member Author

The new test fails:

97/98 integration-tests - systemd:TEST-54-CREDS TIMEOUT 1800.19s (exit status 254 or 0xfe)

That only failed once and seems to be in qemu infra? The subsequent retry succeeded?

@bluca

bluca commented Feb 13, 2026

Copy link
Copy Markdown
Member

Well sure, but it didn't fail before I don't think, so it's suspicious that a new test is added and it got stuck no?

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.

ExecReload= does not inherit credentials with mntns RFE: allow service credentials to be updated during service runtime

8 participants