Skip to content

Commit fc682be

Browse files
committed
core: when inheriting credentials from manager to service, make missing creds graceful
Let's be a bit less strict when setting up credentials: if the service manager didn't receieve a cred, and we shall propagate it down via LoadCredentials= don't fail. Fail on all other errors though, as before, and on explicitly listed paths.
1 parent 8a29862 commit fc682be

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/core/execute.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,7 @@ static int acquire_credentials(
25642564
ReadFullFileFlags flags = READ_FULL_FILE_SECURE;
25652565
_cleanup_(erase_and_freep) char *data = NULL;
25662566
_cleanup_free_ char *j = NULL, *bindname = NULL;
2567+
bool missing_ok = true;
25672568
const char *source;
25682569
size_t size, add;
25692570

@@ -2577,6 +2578,8 @@ static int acquire_credentials(
25772578
if (asprintf(&bindname, "@%" PRIx64"/unit/%s/%s", random_u64(), unit, *id) < 0)
25782579
return -ENOMEM;
25792580

2581+
missing_ok = false;
2582+
25802583
} else if (params->received_credentials) {
25812584
/* If this is a relative path, take it relative to the credentials we received
25822585
* ourselves. We don't support the AF_UNIX stuff in this mode, since we are operating
@@ -2589,16 +2592,23 @@ static int acquire_credentials(
25892592
} else
25902593
source = NULL;
25912594

2592-
25932595
if (source)
25942596
r = read_full_file_full(AT_FDCWD, source, UINT64_MAX, SIZE_MAX, flags, bindname, &data, &size);
25952597
else
25962598
r = -ENOENT;
2597-
if (r == -ENOENT &&
2598-
faccessat(dfd, *id, F_OK, AT_SYMLINK_NOFOLLOW) >= 0) /* If the source file doesn't exist, but we already acquired the key otherwise, then don't fail */
2599+
if (r == -ENOENT && (missing_ok || faccessat(dfd, *id, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)) {
2600+
/* Make a missing inherited credential non-fatal, let's just continue. After all apps
2601+
* will get clear errors if we don't pass such a missing credential on as they
2602+
* themselves will get ENOENT when trying to read them, which should not be much
2603+
* worse than when we handle the error here and make it fatal.
2604+
*
2605+
* Also, if the source file doesn't exist, but we already acquired the key otherwise,
2606+
* then don't fail either. */
2607+
log_debug_errno(r, "Couldn't read inherited credential '%s', skipping: %m", *fn);
25992608
continue;
2609+
}
26002610
if (r < 0)
2601-
return r;
2611+
return log_debug_errno(r, "Failed to read credential '%s': %m", *fn);
26022612

26032613
add = strlen(*id) + size;
26042614
if (add > left)

0 commit comments

Comments
 (0)