unit: add ordering dep relative to credentials dir

See: #25527
This commit is contained in:
Lennart Poettering
2023-05-24 10:17:31 +02:00
parent 5c4e96c28c
commit ce18c39623
3 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -1539,7 +1539,7 @@ static bool context_has_no_new_privileges(const ExecContext *c) {
context_has_syscall_logs(c);
}
static bool exec_context_has_credentials(const ExecContext *context) {
bool exec_context_has_credentials(const ExecContext *context) {
assert(context);
+1
View File
@@ -476,6 +476,7 @@ const char* exec_context_fdname(const ExecContext *c, int fd_index);
bool exec_context_may_touch_console(const ExecContext *c);
bool exec_context_maintains_privileges(const ExecContext *c);
bool exec_context_has_encrypted_credentials(ExecContext *c);
bool exec_context_has_credentials(const ExecContext *context);
int exec_context_get_effective_ioprio(const ExecContext *c);
bool exec_context_get_effective_mount_apivfs(const ExecContext *c);
+20
View File
@@ -1411,6 +1411,26 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
if (r < 0)
return r;
if (exec_context_has_credentials(c) && u->manager->prefix[EXEC_DIRECTORY_RUNTIME]) {
_cleanup_free_ char *p = NULL, *m = NULL;
/* Let's make sure the credentials directory of this service is unmounted *after* the service
* itself shuts down. This only matters if mount namespacing is not used for the service, and
* hence the credentials mount appears on the host. */
p = path_join(u->manager->prefix[EXEC_DIRECTORY_RUNTIME], "credentials", u->id);
if (!p)
return -ENOMEM;
r = unit_name_from_path(p, ".mount", &m);
if (r < 0)
return r;
r = unit_add_dependency_by_name(u, UNIT_AFTER, m, /* add_reference= */ true, UNIT_DEPENDENCY_FILE);
if (r < 0)
return r;
}
return 0;
}