News for hackers. Stuff that matters.
Re:Running GUI apps within Docker containers by mg on Saturday March 26, 2022 @06:04AM (#30810569)
You can also do it with this one-liner:

docker run -it --rm -e DISPLAY --net=host -v $XAUTHORITY:/root/.Xauthority -v /tmp/.X11-unix:/tmp/.X11-unix debian:11-slim

Then inside the container, run:

    apt update
    apt install firefox-esr
    firefox
Now Firefox runs inside the container but displays on your hosts screen and you can use it right away.
Re:Running GUI apps within Docker containers by remram on Saturday March 26, 2022 @10:19AM (#30812015)
This has less isolation. The container has full access to your X server and can record your screen or log all key presses, for example. It also has access to the host's network interfaces, and can access services bound to localhost (even if firewalled). There is little point in running software this way, if the software is available on the host.

On the other hand the use cases that the article describes can already be accomplished by Firefox's "account containers" feature or just creating another profile and running `firefox --no-remote`

Re:Running GUI apps within Docker containers by yjftsjthsd-h on Saturday March 26, 2022 @11:43AM (#30812849)
> There is little point in running software this way, if the software is available on the host.

1. That's a big "if"; I'm fond of docker precisely for fixing software availability issues.

2. It's diminished, but it still provides significant protection, since the containerized program still can't see the real filesystem or process table without going through X or something networked. That's still pretty significant; it would, for instance, protect against a Firefox zero-day that was being used to read people's private SSH keys (not a hypothetical; that incident is what pushed me personally to start sandboxing my browser).

Re:Running GUI apps within Docker containers by javajosh on Saturday March 26, 2022 @05:57PM (#30815719)
>Firefox zero-day that was being used to read people's private SSH keys

Backup there. I somehow have not heard about this. What was the vector? What was the exposure? E.g. have I leaked the contents of ~/.ssh to some (hopefully small, at least) subset of sites I've visited? Where can I learn more?

Re:Running GUI apps within Docker containers by rrampage on Sunday March 27, 2022 @05:26AM (#30818933)
Re:Running GUI apps within Docker containers by tedunangst on Saturday March 26, 2022 @06:30PM (#30815942)
Re:Running GUI apps within Docker containers by beardog on Saturday March 26, 2022 @01:00PM (#30813440)
Using it for fixing availability is fine, but I disagree that it provides protection.

I don't deny that in theory someone could deploy a Firefox zero day that steals ssh keys and that having an abnormal setup via docker could throw a wrench in that, but you are essentially relying on obscurity of your setup which is not an acceptable approach - in the same way that the obscurity of TempleOS would not be a good security approach.

Re:Running GUI apps within Docker containers by BoorishBears on Saturday March 26, 2022 @01:47PM (#30813791)
I feel like security through obscurity is the most prominent example of the Dunning-Kruger effect

Where beginners in security wrongly rely on it entirely

Then intermediate experts proudly proclaim that it's not acceptable

Then expert experts realize it's an excellent part of defense in depth.

-

I mean I know it's a hyperbolic example in your comment, but do you really think leveraging the obscurity of TempleOS wouldn't be an extremely potent way of dodging 99.99999% of malware in existence?

Forcing a tailored attack to breach your isolation is already miles ahead of just running it on your desktop and is most certainly an "acceptable approach", even if it's not infallible.

Re:Running GUI apps within Docker containers by chrsig on Sunday March 27, 2022 @01:36PM (#30822169)
There are quite a number of vectors that are activated similarly regardless of large swaths of the implementation.

For example: if you're hosting a self made shopping cart versus an open source/commercial product, there's probably a higher risk of being vulnerable to SQL injections. It's conceivable that open source and commercial offerings have been beaten on more and as a result hardened against more attack vectors.

Of course to your point, it means that you're not vulnerable to a zero day that impacts many deployments. I imagine the shops that made their own logging library were quite pleased with themselves when the log4j vulnerabilities came out.

My point being that it's not a simple calculus, and it's really hard to evaluate the relative risks of one versus the other. It's probably best to look at the cost of implementing and maintaining security through obscurity and using that as a litmus test for if it's reasonable or not.

Running something on a non-standard port has a very different cost than making your own operating system.

Re:Running GUI apps within Docker containers by tedunangst on Saturday March 26, 2022 @06:34PM (#30815964)
The container should only have access to the server's keyboard input if you give it the magic cookie to do so. If you want a secure container, you would only grant limited permissions.

https://www.x.org/releases/X11R7.6/doc/xextproto/security.ht...

Re:Running GUI apps within Docker containers by remram on Saturday March 26, 2022 @11:59PM (#30817580)
You're in a thread about mounting $HOME/.Xauthority and /tmp/.X11-unix in the container
Re:Running GUI apps within Docker containers by joombaga on Saturday March 26, 2022 @11:16AM (#30812557)
The container would only be able to record the screens or key presses that occur in the same xserver, right? I never thought about access to localhost services. I'm guessing there's some xserver configuration that could prevent that.
Re:Running GUI apps within Docker containers by 0x0 on Saturday March 26, 2022 @11:28AM (#30812664)
Nobody runs more than one X server. And the X server isn't involved with other localhost services.
Re:Running GUI apps within Docker containers by d110af5ccf on Saturday March 26, 2022 @08:59PM (#30816762)
Wait I thought distros ran one X server per logged in user account and put them on different ttys. Out of the box on Ubuntu I can log in as two separate users simultaneously and switch between those unlocked sessions as well as the login screen by changing the tty.

If you pass the GPU device node through to an LXC container I believe you can run an X or Wayland server fully inside of it but I'm not sure if changing ttys will work correctly because you might need access to more than just the GPU to handle the handoff with the kernel correctly.

Re:Running GUI apps within Docker containers by joombaga on Saturday March 26, 2022 @11:47AM (#30812878)
I don't intend to run more than one X server. Most of my GUI applications don't use X.
Re:Running GUI apps within Docker containers by remram on Saturday March 26, 2022 @01:47PM (#30813797)
The parent's setup makes the host's X server socket available to the container, so there's only one X server in that case. In the article, they run a separate X server, which offers some isolation as you note.
Re:Running GUI apps within Docker containers by ranger_danger on Sunday March 27, 2022 @04:33AM (#30818694)
All X programs can already log all other apps' key presses.
Re:Running GUI apps within Docker containers by naikrovek on Wednesday April 06, 2022 @10:45PM (#30940055)
I can’t find a source for this. I believe this to be true, but I can’t find evidence of it. Do you know of one?
Re:Running GUI apps within Docker containers by remram on Tuesday March 29, 2022 @09:12AM (#30842095)
The original article uses a separate X server with VNC. So those can't.
Re:Running GUI apps within Docker containers by paskozdilar on Saturday March 26, 2022 @06:14AM (#30810615)
Thanks, this is much simpler than the original post.

Here's the equivalent Dockerfile + docker-compose.yaml for convenience:

    # Dockerfile
    FROM debian:11-slim
    RUN apt-get -y update && apt-get -y install firefox-esr 
    CMD ["firefox"]


    # docker-compose.yaml
    services:
      firefox:
        image: firefox
        build: .
        environment:
          DISPLAY: ${DISPLAY}
        network_mode: host
        volumes:
          - ${XAUTHORITY}:/root/.Xauthority
          - /tmp/.X11-unix:/tmp.X11-unix

This way you can run it with just:

    docker-compose up
Re:Running GUI apps within Docker containers by moody5bundle on Saturday March 26, 2022 @09:10AM (#30811510)
if you want to remove network_mode=host you need to run firefox with the --no-xshm flag
Re:Running GUI apps within Docker containers by ThePhysicist on Saturday March 26, 2022 @06:20AM (#30810642)
Yes, I think few people seem to realize X Windows can be operated over a network as well. I used to do that with the Windows Subsystem for Linux to use the KDE Konsole and other great tools on my Windows machine using an X server running on the Windows side and a few environment variable tweaks on the Linux side. My colleagues were always confused when they saw the Linux UI seamlessly mixed with the Windows stuff on my display. For the use case mentioned in the article xvfb probably makes more sense though as that stuff often runs on a server and you don't want to stream the output somewhere to work with it interactively.
Re:Running GUI apps within Docker containers by zozbot234 on Saturday March 26, 2022 @07:18AM (#30810886)
This is not running X on any network, just sharing access to the resources that the containerized app needs to find the X server on the same host. There's probably an equivalent incantation for Wayland, too.
Re:Running GUI apps within Docker containers by nrdvana on Saturday March 26, 2022 @07:49AM (#30811048)
Well, that's sort of splitting hairs... It is a unix socket, which at the API level is the same as a network connection, but the kernel skips the hassle of attaching protocol headers and routing the packets.

The example above is writing and reading every X11 message over a socket, and not reaching into /dev on the host, else it would need additional parameters added to the docker command.

I'm not current on Wayland, but as of a few years ago all attempts to run it non-locally required the X11 back-compat layer. I have no idea what /dev nodes would be required to be shared for wayland to run in a chroot.

Re:Running GUI apps within Docker containers by OJFord on Saturday March 26, 2022 @08:17AM (#30811215)
I found your comment grepping for someone sharing how to do it in Wayland, so here it is for the next person:

    docker run -e XDG_RUNTIME_DIR=/tmp \
           -e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
           -v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/tmp/$WAYLAND_DISPLAY  \
           --user=$(id -u):$(id -g) \
           imagename waylandapplication
Pretty simple and reasonable really, just needs to use the same Wayland socket and (in order to access it) user ID. From: https://unix.stackexchange.com/a/359244

I suppose if you were adventurous you could give it whatever other known user ID, and start a separate Wayland compositor for it. But I don't know why you would, when surely the point is to get containerised GUIs visible to you alongside others. Containerised multi-seat I suppose?

Re:Running GUI apps within Docker containers by nrdvana on Sunday March 27, 2022 @10:56AM (#30820697)
You got me curious, so I looked it up:

  Transports
  
  To date all known Wayland implementations work over a
  Unix domain  socket. This is used for one reason in
  particular: file descriptor messages. Unix sockets are
  the most practical transport capable of transferring file
  descriptors between processes, and this is necessary for
  large data transfers (keymaps, pixel buffers, and
  clipboard contents being the main use-cases). In theory,
  a different transport (e.g. TCP) is possible, but someone
  would have to figure out an alternative way of
  transferring bulk data.
So, that is why I hear about needing X11 compat for remote connections; wayland connections are still sockets (not e.g. shared mem), but they require the ability to pass file descriptors through the socket, which can only be done with Unix sockets. (and those file descriptors provide access to shared mem)

I don't see any details about how this interacts with OpenGL, like whether indirect rendering is possible or if applications would need /dev mounted.

Re:Running GUI apps within Docker containers by bdavis__ on Saturday March 26, 2022 @09:22AM (#30811581)
thanks for posting this, but I don't think it meets the definition of "Pretty simple".
Re:Running GUI apps within Docker containers by OJFord on Saturday March 26, 2022 @10:30AM (#30812114)
It's verbose, but that's why I included the description 'just needs same socket and user ID'. That's simple isn't it? Of course it'll always need something.

It could be made less verbose by encapsulating in a compose file, or by removing the env var to point into /tmp and instead using whatever the default is for the chosen image. Also it's not necessary to specify the value for an env var being passed through with the same name (I just copied from SO).

Re:Running GUI apps within Docker containers by nousermane on Saturday March 26, 2022 @08:24AM (#30811249)
> X Windows can be operated over a network as well

Yes, but GP's example is X over a unix socket. Not sure if that counts as network.

Re:Running GUI apps within Docker containers by yjftsjthsd-h on Saturday March 26, 2022 @11:50AM (#30812900)
> Yes, I think few people seem to realize X Windows can be operated over a network as well.

Because in practice it generally can't; I'm not aware of any Linux distribution not shipping their X server with `-nolisten tcp` by default.

Re:Running GUI apps within Docker containers by ranger_danger on Sunday March 27, 2022 @09:37PM (#30826103)
LTSP?
Re:Running GUI apps within Docker containers by yjftsjthsd-h on Monday March 28, 2022 @01:38AM (#30827451)
Hah, good point:) Forgot that existed.
Re:Running GUI apps within Docker containers by i_like_waiting on Saturday March 26, 2022 @07:36AM (#30810975)
So WSL is a must? Because I tried already countless of times without that and it never worked.
Re:Running GUI apps within Docker containers by nrdvana on Saturday March 26, 2022 @07:57AM (#30811089)
You could do the same thing with User Mode Linux or a virtual machine. WSL is just the easiest/fastest way to run native Linux binaries on a Windows system. If you have a X11 server installed properly on windows and can run Linux apps over ssh (which I've done with cygwin, but there are other paid options as well), then you can run them over ssh to a virtual linux on your own host, or look for ways to skip the ssh tunnel if they can route packets to eachother.

I'm a little surprised the examples don't require fiddling with X permissions, which I always had to do when not using ssh.

Re:Running GUI apps within Docker containers by bstpierre on Saturday March 26, 2022 @07:45AM (#30811024)
Also this method avoids “xhost +” which is a huge security hole