this post was submitted on 13 Jan 2024
24 points (96.2% liked)
Linux
48378 readers
1026 users here now
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I got interested, so I spent some time looking into what's going on here. I'm not intimately familiar with X11 or Wayland, but I figured out some stuff.
Why
sudo ip netns exec protected sudo -u user -i
doesn't work for X11 appsShort answer: file permissions and abstract unix sockets (which I didn't know were a thing before now).
File permissions: when I start an X11 login session, the
DISPLAY
is:0
and/tmp/.X11-unix/
has only 1 fileX0
. This file has 777 access. When I start my wayland session with Xwayland, theDISPLAY
is:1
and/tmp/.X11-unix/
has 2 filesX0
(777) andX1
(755). I can't figure out how to connect to display:0
, so I guess I'm stuck with:1
. When you change to a different (non-root) user, the user no longer has access to/tmp/.X11-unix/X1
.Abstract unix sockets: When I start my wayland/xwayland session, it creates abstract unix sockets with ids
@/tmp/.X11-unix/X0
and@/tmp/.X11-unix/X1
. Seess -lnp | grep Xwayland
. The network namespace also sandboxes these abstract unix sockets. Comparesocat ABSTRACT-CONNECT:/tmp/.X11-unix/X1 STDIN
andsudo ip netns exec private socat ABSTRACT-CONNECT:/tmp/.X11-unix/X1 STDIN
.When you do
sudo ip netns exec protected su - user
, you loose access to both the filesystem unix socket/tmp/.X11-unix/X1
and the abstract unix socket@/tmp/.X11-unix/X1
. You need access to one or the other for X11 applications to work.I tried using socat to forward X1 such that it works in the network namespace... and it kinda works.
sudo ip netns exec protected socat ABSTRACT-LISTEN:/tmp/.X11-unix/X1,fork UNIX-CONNECT:/tmp/.X11-unix/X1
. It appears having ABSTRACT-LISTEN before UNIX-CONNECT is important, I guess it would be worth it to properly learn socat. With thissudo ip netns exec protected su - testuser -c 'env DISPLAY=:1 xmessage hi'
works, butsudo ip netns exec protected su - testuser -c 'env DISPLAY=:1 QT_QPA_PLATFORM=xcb kcalc'
does not work. 😞Changing the file permissions on
/tmp/.X11-unix/X1
to give the user access seems to work better.Wayland waypipe
Waypipe works as advertised. But it's still a little bit tricky because you need to have two separate processes for the waypipe client and server, wait for the waypipe socket to be created, adjust file permissions for the waypipe socket file, and set (and probably mkdir)
XDG_RUNTIME_DIR
.Combined
into this script https://github.com/vole-dev/grabbag/blob/main/run-netns-user-wayland.bash
Sir, you're awesome! Thank you a lot for taking your time and explaining what you have found I will try these steps when I have some free time to tinker, and the info and script you have provided has cleared a lot of questions that I had