Skip to content

Failed to set up credentials: Protocol error with systemd 254 #258371

Open

Description

@jtojnar

Describe the bug

After bumping systemd from 253.6 to 254.3, a oneshot service using credentials no longer starts:

Oct 01 12:15:59 azazel systemd[1]: Starting Wallabag install service...
Oct 01 12:15:59 azazel (ll-start)[519003]: wallabag-install.service: Failed to set up credentials: Protocol error
Oct 01 12:15:59 azazel (ll-start)[519003]: wallabag-install.service: Failed at step CREDENTIALS spawning /nix/store/mlwk9kpwsvq82phwcwcq42da0giwsypr-unit-script-wallabag-install-start/bin/wallabag-install-start: Protocol error
Oct 01 12:16:00 azazel systemd[1]: wallabag-install.service: Main process exited, code=exited, status=243/CREDENTIALS
Oct 01 12:16:00 azazel systemd[1]: wallabag-install.service: Failed with result 'exit-code'.
Oct 01 12:16:00 azazel systemd[1]: Failed to start Wallabag install service.

Steps To Reproduce

Trying to switch to a configuration with this service: https://github.com/jtojnar/nixfiles/blob/384248379d6d6a8bddbc6f8334ecbea886671483/hosts/azazel/ogion.cz/bag/default.nix#L201-L204

wallabag-install.service
[Unit]
After=postgresql.service
Before=phpfpm-bag.service
Description=Wallabag install service

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/23j503pfa2gvdi4hgldsqkwzg80bdicn-glibc-locales-2.37-8/lib/locale/locale-archive"
Environment="PATH=/nix/store/y9gr7abwxvzcpg5g73vhnx1fpssr5frr-coreutils-9.3/bin:/nix/store/ysdsy30i42qbm0d4sl0illn52bam46rk-php-with-extensions-8.2.10/bin:/nix/store/binxgxrbqm8bavili2kr7vy1s2257mzv-composer-2.6.3/bin:/nix/store/y9gr7abwxvzcpg5g73vhnx1fpssr5frr-coreutils-9.3/bin:/nix/store/b6izr8wh0p7dyvh3cyg14wq2rn8d31ik-findutils-4.9.0/bin:/nix/store/xafzciap7acqhfx84dvqkp18bg4lrai3-gnugrep-3.11/bin:/nix/store/x23by79p38ll0js1alifmf3y56vqfs49-gnused-4.9/bin:/nix/store/1zmmnm0r0bdga398rl7fc7s4hkyqxjk4-systemd-254.3/bin:/nix/store/y9gr7abwxvzcpg5g73vhnx1fpssr5frr-coreutils-9.3/sbin:/nix/store/ysdsy30i42qbm0d4sl0illn52bam46rk-php-with-extensions-8.2.10/sbin:/nix/store/binxgxrbqm8bavili2kr7vy1s2257mzv-composer-2.6.3/sbin:/nix/store/y9gr7abwxvzcpg5g73vhnx1fpssr5frr-coreutils-9.3/sbin:/nix/store/b6izr8wh0p7dyvh3cyg14wq2rn8d31ik-findutils-4.9.0/sbin:/nix/store/xafzciap7acqhfx84dvqkp18bg4lrai3-gnugrep-3.11/sbin:/nix/store/x23by79p38ll0js1alifmf3y56vqfs49-gnused-4.9/sbin:/nix/store/1zmmnm0r0bdga398rl7fc7s4hkyqxjk4-systemd-254.3/sbin"
Environment="TZDIR=/nix/store/dk5vk3c9zknbjzzxmiglzv46qgv32gb0-tzdata-2023c/share/zoneinfo"



CacheDirectory=wallabag
CacheDirectoryMode=700
ConfigurationDirectory=wallabag
ExecStart=/nix/store/mlwk9kpwsvq82phwcwcq42da0giwsypr-unit-script-wallabag-install-start/bin/wallabag-install-start 
LoadCredential=secret:/run/agenix/bag.ogion.cz-secret
LogsDirectory=wallabag
StateDirectory=wallabag
StateDirectoryMode=700
Type=oneshot
User=bag

More minimal steps TBD.

I tried building a minimal configuration in a VM but it worked there.

Expected behavior

The service should start without issue as before.

Additional context

I am using LoadCredential with agenix path owned by the user service:

$ ls -la /run/agenix/bag.ogion.cz-secret
-r-------- 1 bag bag 49 Oct  1 12:38 /run/agenix/bag.ogion.cz-secret

It fails with store path as well.

There are some credentials-related changes in 254: https://github.com/systemd/systemd/blob/174e8e9897c2d1c8b2c8324f07a6c784d7127410/NEWS#L304-L309

Notify maintainers

Metadata

This is running on VPSAdminOS so maybe there is something weird going on.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
 - host os: `Linux 6.5.4, NixOS, 23.11 (Tapir), 23.11.20230927.eb9b1d1`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.15.1`
 - channels(jtojnar): `""`
 - channels(root): `""`
 - nixpkgs: `not found`

Activity

  1. added
    0.kind: bug
    on Oct 1, 2023
  2. ElvishJerricco commented on Oct 1, 2023

    @ElvishJerricco
    Contributor

    Can you try this with systemd's log_level set to debug? Either boot with systemd.log_level=debug, or run systemctl log-level debug before starting the service.

  3. jtojnar commented on Oct 1, 2023

    @jtojnar
    MemberAuthor

    I also tried applying the patch below to find out where it returns:

    Oct 01 17:53:15 azazel (sd-mkdcre[540246]: Mounting ramfs (ramfs) on /dev/shm (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOSYMFOLLOW "mode=0700")...
    Oct 01 17:53:15 azazel (sd-mkdcre[540246]: Failed to mount ramfs (type ramfs) on /dev/shm (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOSYMFOLLOW "mode=0700"): Permission denied
    Oct 01 17:53:15 azazel (sd-mkdcre[540246]: Mounting tmpfs (tmpfs) on /dev/shm (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOSYMFOLLOW "mode=0700,nr_inodes=1024,size=1048576")...
    Oct 01 17:53:15 azazel (sd-mkdcre[540246]: Changing mount flags /dev/shm (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_NOSYMFOLLOW|MS_BIND "")...
    Oct 01 17:53:15 azazel (sd-mkdcre[540246]: Failed to mount n/a (type n/a) on /dev/shm (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_NOSYMFOLLOW|MS_BIND ""): Permission denied
    Oct 01 17:53:15 azazel (sd-mkdcre[540246]: setup_credentials_internal: return 10: -13
    Oct 01 17:53:15 azazel (ll-start)[540229]: (sd-mkdcreds) failed with exit status 1.
    Oct 01 17:53:15 azazel (ll-start)[540229]: return setup_credentials 7: -71
    Oct 01 17:53:15 azazel (ll-start)[540229]: wallabag-install.service: Failed to set up credentials: Protocol error
    Oct 01 17:53:15 azazel (ll-start)[540229]: wallabag-install.service: Failed at step CREDENTIALS spawning /nix/store/mlwk9kpwsvq82phwcwcq42da0giwsypr-unit-script-wallabag-install-start/bin/wallabag-install-start: Protocol error
    

    This is the line where EPROTO is returned:

    https://github.com/systemd/systemd/blob/v254/src/core/execute.c#L3501

    Debug patch
    diff --git a/src/core/execute.c b/src/core/execute.c
    index 9dafdffa08..1035d2904b 100644
    --- a/src/core/execute.c
    +++ b/src/core/execute.c
    @@ -3333,7 +3333,7 @@ static int setup_credentials_internal(
             if (reuse_workspace) {
                     r = path_is_mount_point(workspace, NULL, 0);
                     if (r < 0)
    -                        return r;
    +                        {log_error("setup_credentials_internal: return 1: %d\n", r); return r;}
                     if (r > 0)
                             workspace_mounted = true; /* If this is already a mount, and we are supposed to reuse it, let's keep this in mind */
                     else
    @@ -3343,7 +3343,7 @@ static int setup_credentials_internal(
     
             r = path_is_mount_point(final, NULL, 0);
             if (r < 0)
    -                return r;
    +                {log_error("setup_credentials_internal: return 2: %d\n", r); return r;}
             if (r > 0) {
                     /* If the final place already has something mounted, we use that. If the workspace also has
                      * something mounted we assume it's actually the same mount (but with MS_RDONLY
    @@ -3357,11 +3357,11 @@ static int setup_credentials_internal(
     
                             r = mount_nofollow_verbose(LOG_DEBUG, final, workspace, NULL, MS_BIND|MS_REC, NULL);
                             if (r < 0)
    -                                return r;
    +                                {log_error("setup_credentials_internal: return 3: %d\n", r); return r;}
     
                             r = mount_nofollow_verbose(LOG_DEBUG, NULL, workspace, NULL, MS_BIND|MS_REMOUNT|credentials_fs_mount_flags(/* ro= */ false), NULL);
                             if (r < 0)
    -                                return r;
    +                                {log_error("setup_credentials_internal: return 4: %d\n", r); return r;}
     
                             workspace_mounted = true;
                     }
    @@ -3377,11 +3377,11 @@ static int setup_credentials_internal(
                             r = mount_nofollow_verbose(LOG_DEBUG, final, workspace, NULL, MS_BIND|MS_REC, NULL);
                             if (r < 0) {
                                     if (!ERRNO_IS_PRIVILEGE(r)) /* Propagate anything that isn't a permission problem */
    -                                        return r;
    +                                        {log_error("setup_credentials_internal: return 5: %d\n", r); return r;}
     
                                     if (must_mount) /* If we it's not OK to use the plain directory
                                                      * fallback, propagate all errors too */
    -                                        return r;
    +                                        {log_error("setup_credentials_internal: return 6: %d\n", r); return r;}
     
                                     /* If we lack privileges to bind mount stuff, then let's gracefully
                                      * proceed for compat with container envs, and just use the final dir
    @@ -3392,7 +3392,7 @@ static int setup_credentials_internal(
                                     /* Make the new bind mount writable (i.e. drop MS_RDONLY) */
                                     r = mount_nofollow_verbose(LOG_DEBUG, NULL, workspace, NULL, MS_BIND|MS_REMOUNT|credentials_fs_mount_flags(/* ro= */ false), NULL);
                                     if (r < 0)
    -                                        return r;
    +                                        {log_error("setup_credentials_internal: return 7: %d\n", r); return r;}
     
                                     workspace_mounted = true;
                             }
    @@ -3407,7 +3407,7 @@ static int setup_credentials_internal(
     
             r = acquire_credentials(context, params, unit, where, uid, workspace_mounted);
             if (r < 0)
    -                return r;
    +                {log_error("setup_credentials_internal: return 8: %d\n", r); return r;}
     
             if (workspace_mounted) {
                     bool install;
    @@ -3422,7 +3422,7 @@ static int setup_credentials_internal(
                     else {
                             r = dir_is_empty(where, /* ignore_hidden_or_backup= */ false);
                             if (r < 0)
    -                                return r;
    +                                {log_error("setup_credentials_internal: return 9: %d\n", r); return r;}
     
                             install = r == 0; /* install only if non-empty */
                     }
    @@ -3431,7 +3431,7 @@ static int setup_credentials_internal(
                             /* Make workspace read-only now, so that any bind mount we make from it defaults to read-only too */
                             r = mount_nofollow_verbose(LOG_DEBUG, NULL, workspace, NULL, MS_BIND|MS_REMOUNT|credentials_fs_mount_flags(/* ro= */ true), NULL);
                             if (r < 0)
    -                                return r;
    +                                {log_error("setup_credentials_internal: return 10: %d\n", r); return r;}
     
                             /* And mount it to the final place, read-only */
                             r = mount_nofollow_verbose(LOG_DEBUG, workspace, final, NULL, MS_MOVE, NULL);
    @@ -3439,7 +3439,7 @@ static int setup_credentials_internal(
                             /* Otherwise get rid of it */
                             r = umount_verbose(LOG_DEBUG, workspace, MNT_DETACH|UMOUNT_NOFOLLOW);
                     if (r < 0)
    -                        return r;
    +                        {log_error("setup_credentials_internal: return 11: %d\n", r); return r;}
             } else {
                     _cleanup_free_ char *parent = NULL;
     
    @@ -3448,12 +3448,12 @@ static int setup_credentials_internal(
     
                     r = path_extract_directory(final, &parent);
                     if (r < 0)
    -                        return r;
    +                        {log_error("setup_credentials_internal: return 12: %d\n", r); return r;}
                     if (chmod(parent, 0755) < 0)
    -                        return -errno;
    +                        {log_error("setup_credentials_internal: return 13: %d\n", -errno); return -errno;}
             }
     
    -        return 0;
    +        {log_error("setup_credentials_internal: return 14: %d\n", 0); return 0;}
     }
     
     static int setup_credentials(
    @@ -3469,28 +3469,28 @@ static int setup_credentials(
             assert(params);
     
             if (!exec_context_has_credentials(context))
    -                return 0;
    +                {log_error("return setup_credentials 1: %d", 0);return 0;}
     
             if (!params->prefix[EXEC_DIRECTORY_RUNTIME])
    -                return -EINVAL;
    +                {log_error("return setup_credentials 2: %d", -EINVAL);return -EINVAL;}
     
             /* This where we'll place stuff when we are done; this main credentials directory is world-readable,
              * and the subdir we mount over with a read-only file system readable by the service's user */
             q = path_join(params->prefix[EXEC_DIRECTORY_RUNTIME], "credentials");
             if (!q)
    -                return -ENOMEM;
    +                {log_error("return setup_credentials 3: %d", -ENOMEM);return -ENOMEM;}
     
             r = mkdir_label(q, 0755); /* top-level dir: world readable/searchable */
             if (r < 0 && r != -EEXIST)
    -                return r;
    +                {log_error("return setup_credentials 4: %d", r);return r;}
     
             p = path_join(q, unit);
             if (!p)
    -                return -ENOMEM;
    +                {log_error("return setup_credentials 5: %d", -ENOMEM);return -ENOMEM;}
     
             r = mkdir_label(p, 0700); /* per-unit dir: private to user */
             if (r < 0 && r != -EEXIST)
    -                return r;
    +                {log_error("return setup_credentials 6: %d", r);return r;}
     
             r = safe_fork("(sd-mkdcreds)", FORK_DEATHSIG|FORK_WAIT|FORK_NEW_MOUNTNS, NULL);
             if (r < 0) {
    @@ -3498,25 +3498,25 @@ static int setup_credentials(
     
                     /* If this is not a privilege or support issue then propagate the error */
                     if (!ERRNO_IS_NOT_SUPPORTED(r) && !ERRNO_IS_PRIVILEGE(r))
    -                        return r;
    +                        {log_error("return setup_credentials 7: %d", r);return r;}
     
                     /* Temporary workspace, that remains inaccessible all the time. We prepare stuff there before moving
                      * it into place, so that users can't access half-initialized credential stores. */
                     t = path_join(params->prefix[EXEC_DIRECTORY_RUNTIME], "systemd/temporary-credentials");
                     if (!t)
    -                        return -ENOMEM;
    +                        {log_error("return setup_credentials 8: %d", -ENOMEM);return -ENOMEM;}
     
                     /* We can't set up a mount namespace. In that case operate on a fixed, inaccessible per-unit
                      * directory outside of /run/credentials/ first, and then move it over to /run/credentials/
                      * after it is fully set up */
                     u = path_join(t, unit);
                     if (!u)
    -                        return -ENOMEM;
    +                        {log_error("return setup_credentials 9: %d", -ENOMEM);return -ENOMEM;}
     
                     FOREACH_STRING(i, t, u) {
                             r = mkdir_label(i, 0700);
                             if (r < 0 && r != -EEXIST)
    -                                return r;
    +                                {log_error("return setup_credentials 10: %d", r);return r;}
                     }
     
                     r = setup_credentials_internal(
    @@ -3532,7 +3532,7 @@ static int setup_credentials(
                     (void) rmdir(u); /* remove the workspace again if we can. */
     
                     if (r < 0)
    -                        return r;
    +                        {log_error("return setup_credentials 11: %d", r);return r;}
     
             } else if (r == 0) {
     
    @@ -3580,7 +3580,7 @@ static int setup_credentials(
              * actually end up mounting anything on it. In that case we'd rather have ENOENT than EACCESS being
              * seen by users when trying access this inode. */
             (void) rmdir(p);
    -        return 0;
    +        {printf("return setup_credentials 12: %d", 0);return 0;}
     }
     
     #if ENABLE_SMACK
  4. ElvishJerricco commented on Oct 1, 2023

    @ElvishJerricco
    Contributor

    @jtojnar FYI, for that patch, you can shorthand a lot of those changes with return log_error_errno(r, "foo bar: %m");, which will also print the human readable version of the error.

  5. added a commit that references this issue on Oct 15, 2023
  6. happysalada commented on Oct 24, 2023

    @happysalada
    Contributor

    I had the same problem without specifying Type="oneshot" to one of my services. I believe the default type is "simple". This doesn't seem related to the service type.

  7. aither64 commented on Nov 1, 2023

    @aither64
    Contributor

    The error is caused by AppArmor profile on vpsAdminOS denying mount of ramfs and then remount of /dev/shm. The denials can be seen in kernel logs on the host system. I haven't been able to fix the profile so far, I don't see what I'm missing. Anyways, vpsAdminOS is transitioning away from AppArmor in any case. Should anyone else encounter it on vpsFree.cz VPS, we can migrate the VPS to a node that is already without AppArmor. It's not possible to disable it at runtime and it can be a while until all nodes are rebooted.

    @jtojnar, please feel free to ping me or @snajpa when you find issues related to vpsAdminOS.

  8. happysalada commented on Nov 1, 2023

    @happysalada
    Contributor

    Vpsadminos is only used in providers that use virtualization right ?
    I encountered the error on hetzner baremetal instances so there might be another cause for the error.

  9. t184256 commented on Nov 1, 2023

    @t184256
    Contributor
  10. aither64 commented on Nov 1, 2023

    @aither64
    Contributor

    @happysalada Yes, as far as I know, vpsAdminOS is only used for virtual servers (Linux containers actually) at vpsFree.cz. If you see this error elsewhere on baremetal or fully virtualized servers, then the cause is different and my comment above is not relevant.

  11. wahjava commented on Nov 1, 2023

    @wahjava
    Contributor

    In my case, I received following spurious error (whole log):

    Oct 22 23:31:25 hostname (sd-mkdcre[679814]: Failed to write credential 'pqpk': No space left on device
    
  12. happysalada commented on Nov 20, 2023

    @happysalada
    Contributor

    This is fixed for me on master.

  13. wahjava commented on Nov 20, 2023

    @wahjava
    Contributor

    This is fixed for me on master.

    @happysalada do you know which commit ? Thanks!

  14. happysalada commented on Nov 20, 2023

    @happysalada
    Contributor

    Its latest nixpkgs-unstable.

    This is weird though, i thought that systemd was updated, but it doesnt look like it was.

    Let me know if this works for you too.

  15. wahjava commented on Nov 20, 2023

    @wahjava
    Contributor

    Nope, doesn't work on nixpkgs-unstable:

    Nov 20 15:40:23 marcus (sd-mkdcre[2344]: Changing mount propagation /dev (MS_REC|MS_SLAVE "")
    Nov 20 15:40:23 marcus (sd-mkdcre[2344]: Bind-mounting /run/credentials/rosenpass.service on /dev/shm (MS_BIND|MS_REC "")...
    Nov 20 15:40:23 marcus (sd-mkdcre[2344]: Changing mount flags /dev/shm (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_NOSYMFOLLOW|MS_BIND "")...
    Nov 20 15:40:23 marcus (sd-mkdcre[2344]: Failed to write credential 'pqpk': No space left on device
    Nov 20 15:40:23 marcus (ss-start)[2342]: (sd-mkdcreds) failed with exit status 1.
    Nov 20 15:40:23 marcus (ss-start)[2342]: rosenpass.service: Failed to set up credentials: Protocol error
    Nov 20 15:40:23 marcus (ss-start)[2342]: rosenpass.service: Failed at step CREDENTIALS spawning /nix/store/zzy14099zxva74cg4qvhmc4jx1zdk81l-unit-script-rosenpass-start/bin/rosenpass-start: Protocol error
    
  16. happysalada commented on Nov 20, 2023

    @happysalada
    Contributor

    Very weird. The next thing to track then is the 254-6 merge of systemd, if that doesnt work after that then it will take a lot longer until the release of 255.
    Very weird that my service worked.

  17. wahjava commented on Nov 20, 2023

    @wahjava
    Contributor

    Also tried master branch (revision ed5e926), and that didn't work either.

  18. wahjava commented on Jan 28, 2024

    @wahjava
    Contributor

    And it still happens with systemd 255.2:

    Jan 28 13:07:36 chateau systemd[1]: rosenpass.service: User lookup succeeded: uid=61692 gid=61692
    Jan 28 13:07:36 chateau (ss-start)[9261]: Found cgroup2 on /sys/fs/cgroup/, full unified hierarchy
    Jan 28 13:07:36 chateau (ss-start)[9261]: Found cgroup2 on /sys/fs/cgroup/, full unified hierarchy
    Jan 28 13:07:36 chateau systemd[1]: systemd-journald.service: Got notification message from PID 1927 (FDSTORE=1)
    Jan 28 13:07:36 chateau systemd[1]: systemd-journald.service: Trying to stash fd for dev=0:8/inode=45490
    Jan 28 13:07:36 chateau systemd[1]: systemd-journald.service: Added fd 304 (stored) to fd store.
    Jan 28 13:07:36 chateau (ss-start)[9261]: Successfully forked off '(sd-mkdcreds)' as PID 9269.
    Jan 28 13:07:36 chateau (sd-mkdcre[9269]: Changing mount propagation /dev (MS_REC|MS_SLAVE "")
    Jan 28 13:07:36 chateau (sd-mkdcre[9269]: Bind-mounting /run/credentials/rosenpass.service on /dev/shm (MS_BIND|MS_REC "")...
    Jan 28 13:07:36 chateau (sd-mkdcre[9269]: Changing mount flags /dev/shm (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_NOSYMFOLLOW|MS_BIND "")...
    Jan 28 13:07:36 chateau (sd-mkdcre[9269]: Failed to write credential 'pqpk': No space left on device
    Jan 28 13:07:36 chateau (ss-start)[9261]: (sd-mkdcreds) failed with exit status 1.
    Jan 28 13:07:36 chateau (ss-start)[9261]: rosenpass.service: Failed to set up credentials: Protocol error
    Jan 28 13:07:36 chateau systemd[1]: systemd-journald.service: Received EPOLLHUP on stored fd 304 (stored), closing.
    Jan 28 13:07:36 chateau systemd[1]: Received SIGCHLD from PID 9261 ((ss-start)).
    Jan 28 13:07:36 chateau systemd[1]: Child 9261 ((ss-start)) died (code=exited, status=243/CREDENTIALS)
    Jan 28 13:07:36 chateau systemd[1]: rosenpass.service: Child 9261 belongs to rosenpass.service.
    
  19. con-f-use commented on Feb 2, 2024

    @con-f-use
    Contributor

    This might be because of PrivateDevices=true or similar systemd directives. The credential-backend need access to stuff like /dev/tpm0 in some situations. Also there's just been systemd/systemd#31197

  20. ElvishJerricco commented on Feb 4, 2024

    @ElvishJerricco
    Contributor

    Thanks to @wahjava for figuring out that this can be caused by having credentials that are larger than half the maximum size (1M) when using ExecStartPre. This causes systemd to write the credentials twice (once for ExecStartPre and once for ExecStart), which runs out of space and causes Failed to set up credentials: Protocol error. That's a great find.

    However, it's not a perfect explanation. The original issue said:

    After bumping systemd from 253.6 to 254.3

    But the PR which introduced this double-credential-writing behavior was released in 252. So the problem should have been evident before then? The size limit of 1M had been there long before that PR was introduced.

  21. PetarKirov commented on Feb 12, 2024

    @PetarKirov

    I haven't had the chance to carefully follow the discussion here and on the SystemD GH repo side, but I wonder if this change would fix the issue: systemd/systemd#31202

  22. wahjava commented on Feb 12, 2024

    @wahjava
    Contributor

    @PetarKirov yes, but it needs to be backported to systemd 255.2 (which is nixos-unstable atm), or wait for new release. I submitted wahjava/systemd@af57967 which was rejected, but it's what I'm using in my setup until a new systemd release with the fix makes it to nixpkgs.

  23. in-pursuit-of-ash commented on Aug 6, 2024

    @in-pursuit-of-ash
    Contributor

    Not the same issue as OP's, but since this page comes up as the first thing on search engines and the symptoms are very similar, another issue with the same error message will be fixed in the next systemd release: systemd/systemd#32612. tldr; Type = simple with LoadCredential is unreliable and Type = exec should be used instead.

  24. davispuh commented on May 10, 2025

    @davispuh

    I encountered different issue with same error message. This is completely unrelated to NixOS but this thread seems good place for future reference and others 😄

    Thanks to @aither64 comment above I found my issue is similar with his AppArmor profile issue.

    In my case I'm running LXC container with openSUSE on Proxmox and inside LXC agetty fails to start with

    [email protected]: Failed to set up credentials: Protocol error
    [email protected]: Failed at step CREDENTIALS spawning /sbin/agetty: Protocol error
    

    In Proxmox dmesg I see

    audit: type=1400 audit(1746902438.020:570): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-101_</var/lib/lxc>" name="/dev/shm/" pid=248129 comm="(sd-mkdcreds)" fstype="ramfs" srcname="ramfs" flags="rw, nosuid, nodev, noexec"
    audit: type=1400 audit(1746902438.020:571): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-101_</var/lib/lxc>" name="/dev/shm/" pid=248129 comm="(sd-mkdcreds)" flags="ro, nosuid, nodev, noexec, remount, bind"
    

    So looks like it fails because trying to mount /dev/shm with different flags.

    One weird thing is that I have another openSUSE LXC with same software versions but it doesn't happen there.

    I found that in failing LXC I have
    /run/systemd/system/service.d/zzz-lxc-service.conf

    [Service]
    ProcSubset=all
    ProtectProc=default
    ProtectControlGroups=no
    ProtectKernelTunables=no
    NoNewPrivileges=no
    LoadCredential=
    PrivateNetwork=no
    

    So here that LoadCredential comes from. In working LXC this file is not present. Also in [email protected] there is Type=idle so it seems different thing than above issue.

    I figured out that LXC with Features: nested=1 causes zzz-lxc-service.conf to not be present while without it's present.
    Another thing I realized is that this used work fine before updating from systemd 254 (254.15+suse.93.g957aeb6452) (works fine) to systemd 254 (254.24+suse.148.g83b9060b6e) (stuff breaks)

    Right now I don't know how to actually fix it other than using nested=1 workaround.

  25. avsdev-cw commented on Sep 24, 2025

    @avsdev-cw

    This is one of the top results for issues with containers so I'm adding a bump with some of my own details (below). I don't know how specific to versions of systemd/lxc/etc this is. If there is a more appropriate place to put this (lxc/proxmox/systemd) then by all means, copy/paste/link to it.

    Using Proxmox v9.0.9 the issue is present and it does seem that the cause revolves around nested=0|1.

    When 1 there seem to be no issues however when 0 then apparmor issues start occurring:

    Sep 24 09:41:29 indus kernel: audit: type=1400 audit(1758703289.059:728): apparmor="DENIED" operation="userns_create" class="namespace" profile="lxc-105_</var/lib/lxc>" pid=280918 comm="(sshd)" requested="userns_create" denied="userns_create"
    Sep 24 09:41:29 indus kernel: audit: type=1400 audit(1758703289.082:729): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-105_</var/lib/lxc>" name="/run/systemd/namespace-M2yQ67/" pid=280916 comm="(mandos)" fstype="proc" srcname="proc" flags="rw, nosuid, nodev, noexec"
    Sep 24 09:41:29 indus kernel: audit: type=1400 audit(1758703289.200:730): apparmor="DENIED" operation="userns_create" class="namespace" profile="lxc-105_</var/lib/lxc>" pid=280923 comm="(sshd)" requested="userns_create" denied="userns_create"
    Sep 24 09:41:30 indus kernel: audit: type=1400 audit(1758703290.160:731): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-105_</var/lib/lxc>" name="/run/systemd/namespace-hLQKnf/" pid=281035 comm="(postfix)" fstype="proc" srcname="proc" flags="rw, nosuid, nodev, noexec"
    Sep 24 09:41:30 indus kernel: audit: type=1400 audit(1758703290.346:732): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-105_</var/lib/lxc>" name="/dev/shm/" pid=281048 comm="(sd-mkdcreds)" fstype="ramfs" srcname="ramfs" flags="rw, nosuid, nodev, noexec, nosymfollow"
    Sep 24 09:41:30 indus kernel: audit: type=1400 audit(1758703290.347:733): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-105_</var/lib/lxc>" name="/dev/shm/" pid=281049 comm="(sd-mkdcreds)" fstype="ramfs" srcname="ramfs" flags="rw, nosuid, nodev, noexec, nosymfollow"
    Sep 24 09:41:30 indus kernel: audit: type=1400 audit(1758703290.347:734): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-105_</var/lib/lxc>" name="/dev/shm/" pid=281048 comm="(sd-mkdcreds)" flags="ro, nosuid, nodev, noexec, remount, nosymfollow, bind"
    Sep 24 09:41:30 indus kernel: audit: type=1400 audit(1758703290.347:735): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-105_</var/lib/lxc>" name="/dev/shm/" pid=281049 comm="(sd-mkdcreds)" flags="ro, nosuid, nodev, noexec, remount, nosymfollow, bind"
    Sep 24 09:41:30 indus kernel: audit: type=1400 audit(1758703290.348:736): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-105_</var/lib/lxc>" name="/dev/shm/" pid=281050 comm="(sd-mkdcreds)" fstype="ramfs" srcname="ramfs" flags="rw, nosuid, nodev, noexec, nosymfollow"
    Sep 24 09:41:30 indus kernel: audit: type=1400 audit(1758703290.349:737): apparmor="DENIED" operation="mount" class="mount" info="failed flags match" error=-13 profile="lxc-105_</var/lib/lxc>" name="/dev/shm/" pid=281050 comm="(sd-mkdcreds)" flags="ro, nosuid, nodev, noexec, remount, nosymfollow, bind"
    

    This leads to numerous startup issues, particularly with systemd and, more annoyingly, getty services which result in no console for the container (also no journal service so there's no log in the container to show what the container is crashing out on):

      UNIT                                     LOAD   ACTIVE SUB       DESCRIPTION
      -.mount                                  loaded active mounted   Root Mount
      dev-full.mount                           loaded active mounted   /dev/full
    ● dev-mqueue.mount                         loaded failed failed    POSIX Message Queue File System
      dev-null.mount                           loaded active mounted   /dev/null
      dev-ptmx.mount                           loaded active mounted   /dev/ptmx
      dev-random.mount                         loaded active mounted   /dev/random
      dev-tty.mount                            loaded active mounted   /dev/tty
      dev-tty1.mount                           loaded active mounted   /dev/tty1
      dev-tty2.mount                           loaded active mounted   /dev/tty2
      dev-urandom.mount                        loaded active mounted   /dev/urandom
      dev-zero.mount                           loaded active mounted   /dev/zero
      proc-cpuinfo.mount                       loaded active mounted   /proc/cpuinfo
      proc-diskstats.mount                     loaded active mounted   /proc/diskstats
      proc-loadavg.mount                       loaded active mounted   /proc/loadavg
      proc-meminfo.mount                       loaded active mounted   /proc/meminfo
      proc-slabinfo.mount                      loaded active mounted   /proc/slabinfo
      proc-stat.mount                          loaded active mounted   /proc/stat
      proc-swaps.mount                         loaded active mounted   /proc/swaps
      proc-sys-net.mount                       loaded active mounted   /proc/sys/net
      proc-sysrq\x2dtrigger.mount              loaded active mounted   /proc/sysrq-trigger
      proc-uptime.mount                        loaded active mounted   /proc/uptime
    ● run-lock.mount                           loaded failed failed    Legacy Locks Directory /run/lock
      sys-devices-system-cpu.mount             loaded active mounted   /sys/devices/system/cpu
      sys-devices-virtual-net.mount            loaded active mounted   /sys/devices/virtual/net
      sys-fs-fuse-connections.mount            loaded active mounted   FUSE Control File System
    ● tmp.mount                                loaded failed failed    Temporary Directory /tmp
      postfix-resolvconf.path                  loaded active waiting   Watch for resolv.conf updates for postfix
      systemd-ask-password-console.path        loaded active waiting   Dispatch Password Requests to Console Directory Watch
      systemd-ask-password-wall.path           loaded active waiting   Forward Password Requests to Wall Directory Watch
      init.scope                               loaded active running   System and Service Manager
      avahi-daemon.service                     loaded active running   Avahi mDNS/DNS-SD Stack
    ● console-getty.service                    loaded failed failed    Console Getty
    ● [email protected]                loaded failed failed    Container Getty on /dev/tty1
    ● [email protected]                loaded failed failed    Container Getty on /dev/tty2
      cron.service                             loaded active running   Regular background program processing daemon
      dbus.service                             loaded active running   D-Bus System Message Bus
      ifupdown-pre.service                     loaded active exited    Helper to synchronize boot up for ifupdown
      mandos.service                           loaded active running   Server of encrypted passwords to Mandos clients
      networking.service                       loaded active exited    Raise network interfaces
      nftables.service                         loaded active exited    nftables
      postfix.service                          loaded active running   Postfix Mail Transport Agent (main/default instance)
      ssh.service                              loaded active running   OpenBSD Secure Shell server
    ● systemd-journal-flush.service            loaded failed failed    Flush Journal to Persistent Storage
    ● systemd-journald.service                 loaded failed failed    Journal Service
      systemd-logind.service                   loaded active running   User Login Management
      systemd-modules-load.service             loaded active exited    Load Kernel Modules
    ● systemd-network-generator.service        loaded failed failed    Generate network units from Kernel command line
    ● systemd-networkd.service                 loaded failed failed    Network Configuration
      systemd-remount-fs.service               loaded active exited    Remount Root and Kernel File Systems
    ● systemd-sysctl.service                   loaded failed failed    Apply Kernel Variables
    ● systemd-tmpfiles-setup-dev-early.service loaded failed failed    Create Static Device Nodes in /dev gracefully
    ● systemd-tmpfiles-setup-dev.service       loaded failed failed    Create Static Device Nodes in /dev
    ● systemd-tmpfiles-setup.service           loaded failed failed    Create System Files and Directories
    ● systemd-udev-load-credentials.service    loaded failed failed    Load udev Rules from Credentials
      systemd-user-sessions.service            loaded active exited    Permit User Sessions
      wtmpdb-update-boot.service               loaded active exited    Write boot and shutdown times into wtmpdb
    
  26. added
    2.status: stale
    on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug2.status: stale

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions