Skip to content

run0 and other interactive polkit authorization do not work in WSL #37149

Closed

Description

@NekkoDroid

systemd version the issue has been seen with

systend-258.devel.r80793.5d902cc21f8-1

Used distribution

Archlinux (WSL)

Linux kernel version used

6.6.84.1-microsoft-standard-WSL2

CPU architectures issue was seen on

x86_64

Component

systemd-run

Expected behaviour you didn't see

When running inside WSL run0 should bring up a shell as the root user. run0 echo hello should run the specified command as root user.

Unexpected behaviour you saw

Both run0 and run0 echo hello fail to run and exit with the error message (similar message for systemctl enable as non-root):

[nekko@wsl ~]$ run0
Failed to start transient service unit: Interactive authentication required.

Testing both commands with pkexec instead of run0 the results are as expected (root shell and run command as root, tested by installing packages).

[nekko@wsl ~]$ pkexec
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ====
Authentication is needed to run `/usr/bin/bash' as the super user
Authenticating as: nekko
Password:
==== AUTHENTICATION COMPLETE ====
[root@wsl ~]# exit

Steps to reproduce the problem

  1. Install a WSL distro with new enough systemd for run0 (confirmed this appears on both Arch and Fedora installs)
  2. Run run0 echo hello as an unpriviledged user in the wheel group

Additional program output to the terminal or log subsystem illustrating the issue

[nekko@wsl ~]$ SYSTEMD_LOG_LEVEL=debug run0
Using pty stdio mode.
Setting XDG_SESSION_CLASS to 'user-early-light'.
Bus n/a: changing state UNSET → OPENING
sd-bus: starting bus by connecting to /run/dbus/system_bus_socket...
Bus n/a: changing state OPENING → AUTHENTICATING
Successfully forked off '(polkit-agent)' as PID 891.
Skipping PR_SET_MM, as we don't have privileges.
Successfully forked off '(sd-askpwagent)' as PID 896.
Failed to acquire pidfd ID of myself, defaulting to randomized unit name: Operation not supported
Skipping PR_SET_MM, as we don't have privileges.
Bus n/a: changing state AUTHENTICATING → HELLO
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a
Got message type=method_return sender=org.freedesktop.DBus destination=:1.64 path=n/a interface=n/a member=n/a  cookie=4294967295 reply_cookie=1 signature=s error-name=n/a error-message=n/a
Bus n/a: changing state HELLO → RUNNING
Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=StartTransientUnit cookie=2 reply_cookie=0 signature=ssa(sv)a(sa(sv)) error-name=n/a error-message=n/a
Failed to open /run/systemd/ask-password-block/136:0: Permission denied
Got message type=error sender=:1.2 destination=:1.64 path=n/a interface=n/a member=n/a  cookie=3390 reply_cookie=2 signature=s error-name=org.freedesktop.DBus.Error.InteractiveAuthorizationRequired error-message=Interactive authentication required.
Failed to start transient service unit: Interactive authentication required.
Bus n/a: changing state RUNNING → CLOSED

Activity

  1. added
    bug 🐛
    on Apr 15, 2025
  2. poettering commented on Apr 16, 2025

    @poettering
    Member

    my educated guess is that wsl doesn't register a pam session properly, hence pk's agent logic cannot work.

    please contact wsl for help about this, systemd cannot do anything about it.

  3. septatrix commented on Apr 16, 2025

    @septatrix
    Contributor

    my educated guess is that wsl doesn't register a pam session properly, hence pk's agent logic cannot work.

    A quick loginctl could confirm that.

    My question then would be why pkexec does work?

  4. NekkoDroid commented on Apr 16, 2025

    @NekkoDroid
    ContributorAuthor

    For completeness sake here is loginctls output:

    SESSION  UID USER  SEAT LEADER CLASS   TTY   IDLE SINCE
         c1 1000 nekko -    197    user    pts/1 no   -
         c2 1000 nekko -    221    manager -     no   -
    
    2 sessions listed.
    

    (tty gives me /dev/pts/2)

  5. arvidjaar commented on Apr 16, 2025

    @arvidjaar
    Contributor

    For completeness sake here is loginctls output

    Which does not change with additional terminals logons or even if I close everything and open new terminal session. So, the listed sessions really do not have anything to do with your actual terminal session.

  6. NekkoDroid commented on Apr 16, 2025

    @NekkoDroid
    ContributorAuthor

    Yea, I didn't exactly think it did, hense for completeness sake. To my knowledge WSL actually doesn't actually do full logins for the shells, but instead just spawns them as the user :/

    Looking at the process tree I get roughtly the following:

    /init
    ├─ /init
    ├─ /init
    │  ├─ /init
    │     ├─ -bash        <-- Current shell
    │        ├─ htop
    ├─ login -- nekko
       ├─ -bash
    

    So it seems the actual logon is just somewhere lost in the aether

    (Seems there is already an open ticket for the login shell on the WSL repo microsoft/WSL#9213)

  7. arvidjaar commented on Apr 16, 2025

    @arvidjaar
    Contributor

    there is already an open ticket for the login shell on the WSL repo microsoft/WSL#9213

    Using example from this issue:

    andrei@tumbleweed:~> sudo sudo -iu andrei
    andrei@tumbleweed:~> run0
    ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
    Authentication is required to start transient unit 'run-r44c8e78c2eb749e9aa6bf174d5b4aa31.service'.
    Authenticating as: root
    Password:
    ==== AUTHENTICATION COMPLETE ====
    tumbleweed:/home/andrei #
    
  8. NekkoDroid commented on Apr 16, 2025

    @NekkoDroid
    ContributorAuthor

    Weird, since those same steps also just fail with the same problem I originally encountered when run on Arch, but not when I run it on Fedora.

    When looking into the differences for the PAM config I noticed that pam_systemd.so is part of Fedora's, while it isn't for Arch only pam_systemd_home.so (in system-auth). Manually adding it seems to allow the workaround to function.

    I'll bring this up on the Arch bug tracker. Thanks for getting me (at least partially) on the right track.

  9. YHNdnzj commented on Apr 16, 2025

    @YHNdnzj
    Member

    Weird, since those same steps also just fail with the same problem I originally encountered when run on Arch, but not when I run it on Fedora.

    When looking into the differences for the PAM config I noticed that pam_systemd.so is part of Fedora's, while it isn't for Arch only pam_systemd_home.so (in system-auth). Manually adding it seems to allow the workaround to function.

    I'll bring this up on the Arch bug tracker. Thanks for getting me (at least partially) on the right track.

    pam_systemd.so is intentionally left out there IIUC. It was a deliberate choice that only actual "login" stacks get a session, but not sudo ones (unlike run0 that's forked off from pid1, sudo acquires privilege via suid, so IMO that behavior makes more sense)

    And as you noted already, it's a workaround that involves a new session, which doesn't resolve the original problem about the startup session not being set up properly in WSL. I don't think there's anything actionable for Arch.

  10. added and removed
    bug 🐛
    on Apr 16, 2025
  11. greyltc commented on Jun 18, 2025

    @greyltc

    @poettering @YHNdnzj

    my educated guess is that wsl doesn't register a pam session properly, hence pk's agent logic cannot work.

    $ pkexec --user root works as expected though:

    [greyltc@WSLbox~]$ pkexec --user root
    ==== AUTHENTICATING FOR org.freedesktop.policykit.exec ====
    Authentication is needed to run `/usr/bin/bash' as the super user
    Authenticating as: greyltc
    Password:
    ==== AUTHENTICATION COMPLETE ====
    [root@WSLbox~]#
    

    So wouldn't that suggest that polkit (via PAM) is not the issue here?

  12. arvidjaar commented on Jun 18, 2025

    @arvidjaar
    Contributor

    So wouldn't that suggest that polkit (via PAM) is not the issue here?

    pkexec registers internal polkit agent which directly gets authentication request.

    run0 invokes pkttyagent --fallback. In this case polkit attempts first to find "better" agent registered for the user session. If it cannot get session it bails out.

    To have valid session user needs to go via PAM pam_systemd.

    I suppose run0 could mimic pkexec which first attempts to start the given program and if polkit responds with "authentication required" (meaning - no other agent was found) then pkexec registers its own internal agent and repeats request.

  13. greyltc commented on Jun 19, 2025

    @greyltc

    If it cannot get session it bails out.

    Why should it bail out? It clearly has the capability to authenticate the user in this environment (see pkexec). Is this a polkit bug then? Of course in addition to microsoft's PAM bug, microsoft/WSL#9213, but that bug is now several years old with seemingly zero attention from microsoft, who knows if it's ever going to be addressed.

    polkit's job here is to authenticate the user. If something is screwed up with PAM that stops it from working normally, shouldn't it then try the approach it uses in the pkexec case?

    By the way, I see what you mean with pkexec's internal agent:

    [greyltc@WSLbox]$ pkexec --disable-internal-agent --user root
    Error executing command as another user: No authentication agent found.
    
  14. arvidjaar commented on Jun 19, 2025

    @arvidjaar
    Contributor

    Why should it bail out?

    Whether it is intentional or not needs to be discussed with polkit folks. I believe it is not and should be fixed to actually fall back to --fallback agent.

    https://github.com/polkit-org/polkit/blob/f506138c71a17ac99bfaa9c3414dad698f93428b/src/polkitbackend/polkitbackendinteractiveauthority.c#L1775-L1779

    Is this a polkit bug then?

    I think so. Care to open polkit issue?

  15. greyltc commented on Jun 19, 2025

    @greyltc

    Could it be that in this case polkit won't have/know the details needed to actually read and write to the same terminal that run0 was invoked from to do the authentication?

    (in which case, maybe what you said before is true: systemd could then set up an internal polkit agent to do the auth in the local terminal in the case when the first try, asking polkit over dbus, fails due to screwed up/missing PAM environment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions