Skip to content

Run X11 display server without root privileges - #1371

Merged
plfiorini merged 2 commits into
sddm:developfrom
plfiorini:feature/xorguser
Apr 19, 2021
Merged

plfiorini merged 2 commits into
sddm:developfrom
plfiorini:feature/xorguser

Conversation

@plfiorini

Copy link
Copy Markdown
Member

Introduce an alternative display server option to run the greeter the
X11 server as an unprivileged user.

Closes: #246

@plfiorini
plfiorini marked this pull request as draft February 22, 2021 09:19
Comment thread src/daemon/XorgUserDisplayServer.h Resolved
Comment thread src/common/XAuth.h Resolved
@davidedmundson

Copy link
Copy Markdown
Contributor

Let me know if this gets out of WIP, or if you hit something that you need a second set of eyes on.

@plfiorini

plfiorini commented Mar 1, 2021 •

Copy link
Copy Markdown
Member Author

Things to do:

  • Save xauthority in the runtime directory not cache
  • Run DisplayCommand script, set cursor and DisplayStop command as user
  • Document that those scripts will be executed as sddm in sddm.conf man
  • Create a socket to pass the display from sddm-helper-x11 to sddm-helper
  • Set said display in XorgUserDisplayServer
  • Why do Xorg fail saying that only console users are allowed? From the code I see that this error is given when either stdin, stdout or stderr is not a character device. I just don't understand why S_ISCHR fails
  • Why Xorg user sessions do not work? i3 fails to connect to the display
  • After a while input devices are paused by logind and we cannot do anything in the greeter. This happens after I have tried to launch a user session.
  • Go through all the themes and clear the password field when the auth fails

@aleixpol

aleixpol commented Mar 2, 2021

Copy link
Copy Markdown
Contributor

Why do Xorg fail saying that only console users are allowed? From the code I see that this error is given when either stdin, stdout or stderr is not a character device. I just don't understand why S_ISCHR fails

I did see this when redirecting the output, maybe it's the same reason?

@marcthe12

Copy link
Copy Markdown

Xorg needs have stdin (from a simple test with startx). I suggest we need set stdin to be set to /dev/ttyN for the Xserver as workaround.

@plfiorini

Copy link
Copy Markdown
Member Author

Rebased on top of #1377

@davidedmundson

Copy link
Copy Markdown
Contributor

Why Xorg user sessions do not work? i3 fails to connect to the display

Fixed in the PR that I just sent to your personal branch that this is based on.
We were creating the xauthority cookie before we worked out what display to use.

@plfiorini plfiorini added this to the 0.20 milestone Mar 13, 2021
@plfiorini plfiorini changed the title WIP Rootless X11 display server Rootless X11 display server Mar 13, 2021
@plfiorini
plfiorini marked this pull request as ready for review March 13, 2021 09:13
@plfiorini

Copy link
Copy Markdown
Member Author

Thanks guys for the help. This PR is now ready for your reviews.
At this point, it doesn't even matter to review #1377 since it's contained here.

@plfiorini plfiorini mentioned this pull request Mar 13, 2021

@Conan-Kudo Conan-Kudo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pretty much LGTM

Comment thread src/common/Configuration.h Resolved
@plfiorini plfiorini changed the title Rootless X11 display server Run X11 display server without root privileges Mar 13, 2021
@aleixpol

Copy link
Copy Markdown
Contributor

I quickly tested it and I don't seem to be able to log out from X11 sessions using this. Tried it with plasma, gnome and icewm.

Starting them seems to work fine. 👍

Comment thread src/helper-x11/xorguserhelper.cpp Resolved
@davidedmundson

Copy link
Copy Markdown
Contributor

There's still a few things left to fix, there's the issue above which is breaking our logout, but even with that fixed my original greeter we go back to is in a broken state.

I'll try to follow up on that.

Comment thread components/2.0/PictureBox.qml Resolved
Comment thread src/daemon/Greeter.cpp Resolved
Comment thread src/helper-x11/main.cpp Resolved
Comment thread src/daemon/Display.cpp Resolved
@aleixpol

aleixpol commented Mar 30, 2021 •

Copy link
Copy Markdown
Contributor

I have been testing it and it seems to work fine except that in some instances it seems to fail at switching to the user's xorg session tty. I'll see if I can provide a patch.

@aleixpol

Copy link
Copy Markdown
Contributor

I have been testing it and it seems to work fine except that in some instances it seems to fail at switching to the user's xorg session tty. I'll see if I can provide a patch.

I'm pretty sure this was an issue with my installation and cannot reproduce anymore.

If I had the powers I'd approve the patch.

@davidedmundson davidedmundson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I still want to do the helper refactor before release, but as stated in the in-line comment we can resolve that after merging this so we don't stall this forever.

@davidedmundson

Copy link
Copy Markdown
Contributor

It's worth noting that one of these commits is of super-importance even with the current Xorg daemon: "Allocate VT for the display"

We have an important downstream bug that if you start a wayland session then call switch user, SDDM will start on what SDDM thinks is the next available VT, which naturally is the one the wayland session is on. This fails and we can't switch users.

This patch here fixes that, which is nice \o/

@Vogtinator

Copy link
Copy Markdown
Contributor

It's worth noting that one of these commits is of super-importance even with the current Xorg daemon: "Allocate VT for the display"

Does this PR also help with #1281?

Replace the old crude algorithm to find the next available VT with a
more reliable method using the VT_OPENQRY ioctl.

General.MinimumVT setting is now obsolete and it's no longer used.
@plfiorini

Copy link
Copy Markdown
Member Author

Ready for review!

Introduce an alternative display server option to run the greeter with
the X11 server as an unprivileged user.

Root privileges are required by default, but this will change in the
future.

Greeter output is forwarded to the helper process, instead of saving it
into a separate file like user sessions do.
This means the greeter output is available in the journal with the
daemon and helper logs.

Display start and stop commands are executed as sddm user and this might
break the workflow of our users.
That is the reason why we still run Xorg as root for the greeter by
default.

X11 user session always spawn a new display server without root
privileges.

Closes: #246
@aleixpol

Copy link
Copy Markdown
Contributor

+1 just tested, worked as expected.

@plfiorini
plfiorini merged commit 9881225 into sddm:develop Apr 19, 2021
@plfiorini
plfiorini deleted the feature/xorguser branch April 19, 2021 14:42
@AdamWill

AdamWill commented Apr 19, 2021 •

Copy link
Copy Markdown

What happened to the commit "Make sure the helper process is stopped when shutting down." that was previously part of this PR?

edit: oh, I guess it was its own PR as #1377 , and was in this one accidentally?

@plfiorini

Copy link
Copy Markdown
Member Author

What happened to the commit "Make sure the helper process is stopped when shutting down." that was previously part of this PR?

edit: oh, I guess it was its own PR as #1377 , and was in this one accidentally?

It was needed due to an error that is now solved

@ThisNekoGuy

ThisNekoGuy commented May 6, 2021 •

Copy link
Copy Markdown

How would a user run the Xorg server as rootless with SDDM?
This isn't done by default (I don't understand why, considering it's a potential security risk) and editing Xwrapper.config to set needs_root_rights = no doesn't seem to make a difference.

@aleixpol

aleixpol commented May 7, 2021

Copy link
Copy Markdown
Contributor

You need to set DisplayServer=x11-user as the documentation says.

@ThisNekoGuy

Copy link
Copy Markdown

You need to set DisplayServer=x11-user as the documentation says.

I did put this in the Xwrapper.config file but this caused my system to hang on startup.
(I'm on Arch)

@plfiorini

Copy link
Copy Markdown
Member Author

You need to set DisplayServer=x11-user as the documentation says.

I did put this in the Xwrapper.config file but this caused my system to hang on startup.
(I'm on Arch)

No, you have to put it in the SDDM configuration file.

@ThisNekoGuy

Copy link
Copy Markdown

You need to set DisplayServer=x11-user as the documentation says.

I did put this in the Xwrapper.config file but this caused my system to hang on startup.
(I'm on Arch)

No, you have to put it in the SDDM configuration file.

Ah, okay; sorry, I misunderstood where it was supposed to go.
Is this going to be enabled by default going forward?

@plfiorini

Copy link
Copy Markdown
Member Author

You need to set DisplayServer=x11-user as the documentation says.

I did put this in the Xwrapper.config file but this caused my system to hang on startup.
(I'm on Arch)

No, you have to put it in the SDDM configuration file.

Ah, okay; sorry, I misunderstood where it was supposed to go.
Is this going to be enabled by default going forward?

Yes sure, but right now we can't make it the default because some people rely on the fact that it's running as root

@Xwang1976

Copy link
Copy Markdown

The man files says "For x11-user you might need to configure Xorg.wrap(1)".
Is there any specific option which must be present in Xwrapper.config to have a rootless Xorg with sddm?
I suppose I have to put:
allowed_users = anybody
needs_root_rights = no

Is it correct?

@plfiorini

Copy link
Copy Markdown
Member Author

The man files says "For x11-user you might need to configure Xorg.wrap(1)".

Tweak that file only if it's not working.

Is there any specific option which must be present in Xwrapper.config to have a rootless Xorg with sddm?
I suppose I have to put:
allowed_users = anybody
needs_root_rights = no

Is it correct?

Yes that is correct and should force X11 to run without root privileges, but you only have to configure this stuff if really needed.
I don't expect much people (or even no one) to need to tweak it.

@Xwang1976

Copy link
Copy Markdown

I've set x11-user in the sddm conf file and now I have Xorg owned by my user. The same happens for sddm-helper. Sddm is running as root.
Is it correct?
Meantime I can confirm you that I did not have to create the Xwrapper.config file at all

@Xwang1976

Copy link
Copy Markdown

I've noted that command launched with firejail are not able to connect to the X server. With GDM in rootless mode the same command works correctly.
It seems that GDM and SDDM call Xorg using different options.

@Xwang1976

Copy link
Copy Markdown

When using sddm, echo $XAUTHORITY gives /run/user/1000/c04e4bb9-0531-4ab3-86a8-caaa6f30a661 with the file name changingat every reboot
Using GDM echo $XAUTHORITY gives /run/user/1000/gdm/Xauthority

Moreover when I look at the Xorg process it is runned by sddm as:
/usr/lib/Xorg -nolisten tcp -background none -seat seat0 -noreset -keeptty -novtswitch -verbose 3 -auth /run/user/1000/c04e4bb9-0531-4ab3-86a8-caaa6f30a661 -displayfd 8 vt1 -logfile /dev/null

GDM instead runs Xorg in this way:
/usr/lib/Xorg vt2 -displayfd 3 -auth run run/user/1000/gdm/Xauthority -nolisten tcp -background none -noreset -keeptty -novtswitch -verbose 3

Finally running xauth when started by sddm I get:
access control enabled, only authorized clients can connect

Whereas running when uning GDM I get:
access control enabled, only authorized clients can connect
SI:localuser:andreak

@Xwang1976

Copy link
Copy Markdown

When using sddm, echo $XAUTHORITY gives /run/user/1000/c04e4bb9-0531-4ab3-86a8-caaa6f30a661 with the file name changingat every reboot
Using GDM echo $XAUTHORITY gives /run/user/1000/gdm/Xauthority

Moreover when I look at the Xorg process it is runned by sddm as:
/usr/lib/Xorg -nolisten tcp -background none -seat seat0 -noreset -keeptty -novtswitch -verbose 3 -auth /run/user/1000/c04e4bb9-0531-4ab3-86a8-caaa6f30a661 -displayfd 8 vt1 -logfile /dev/null

GDM instead runs Xorg in this way:
/usr/lib/Xorg vt2 -displayfd 3 -auth run run/user/1000/gdm/Xauthority -nolisten tcp -background none -noreset -keeptty -novtswitch -verbose 3

Finally running xauth when started by sddm I get:
access control enabled, only authorized clients can connect

Whereas running when using GDM I get:
access control enabled, only authorized clients can connect
SI:localuser:andreak

@silverqx

Copy link
Copy Markdown

Does this mean we will have a rootless X in the v0.20 release? That would be 🔥

What will be needed? I have read the conversations above and it looks like a user will have to add the following to the /etc/sddm.conf.d/rootless.conf as it will not be a default:

[General]
DisplayServer=x11-user

Am I right or did I misunderstand something 😁? thx

@Conan-Kudo

Copy link
Copy Markdown
Contributor

That is how you do it, yes.

@silverqx

Copy link
Copy Markdown

When do you plan to release 0.20? I'm really waiting for this.

@silverqx

silverqx commented Sep 24, 2023 •

Copy link
Copy Markdown

Ok, I tried this and I have been using it for the last month or so, it really works as we described, just adding the DisplayServer=x11-user to the sddm.conf is enough and the X server will start rootless. 👌

Everything works fine for me but I have one big issue, when I log into the system, write the password down and press enter, then the sddm switches me to the tty1 (ctrl+alt+F1) to the first console and I have to manually switch to the vt7 (alt+F7). If I don't do this it stays on the tty1 for around 1min or so and then it switches to the vt7, it takes soo long and I'm not even sure if it's true because I didn't try this a long time. 🐛

I'm on Gentoo with OpenRC and the X server is started like this:

exec /usr/bin/X -nolisten tcp -keeptty "$@" "vt$XDG_VTNR"

And the $XDG_VTNR is set to the 7 number, I don't think changing it to the 1 would be a good idea.

This problem is not happening without the DisplayServer=x11-user so with the previous so-called root mode. It is only happening with this new rootless mode.

Is there any workaround for this or a patch? How can I force the sddm to switch to the vt7 after login? @plfiorini

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix rootless xorg support

10 participants