subuser-security / subuser

Run programs on linux with selectively restricted permissions.
http://subuser.org
GNU Lesser General Public License v3.0
890 stars 65 forks source link

Unable to start X11 programs. #268

Closed ypid closed 8 years ago

ypid commented 8 years ago
subuser run keepassx
Traceback (most recent call last):
  File "/var/local/testuser/subuser/logic/subuserlib/classes/subuserSubmodules/run/x11Bridge.py", line 171, in mkdirs
    self.getUser().getEndUser().makedirs(directory)
  File "/var/local/testuser/subuser/logic/subuserlib/classes/endUser.py", line 68, in makedirs

When you strace this it seems that it is going thought the whole filesystem.

access("/usr/bin/xfce4-settings-manager", X_OK) = 0
stat("/usr/bin/dpkg-gensymbols", {st_mode=S_IFREG|0755, st_size=10500, ...}) = 0
access("/usr/bin/dpkg-gensymbols", X_OK) = 0
stat("/usr/bin/nicstat", {st_mode=S_IFREG|0755, st_size=31032, ...}) = 0
access("/usr/bin/nicstat", X_OK)        = 0
stat("/usr/bin/cal", {st_mode=S_IFREG|0755, st_size=29776, ...}) = 0
access("/usr/bin/cal", X_OK)            = 0
stat("/usr/bin/rst-buildhtml", {st_mode=S_IFREG|0755, st_size=9962, ...}) = 0
access("/usr/bin/rst-buildhtml", X_OK)  = 0
stat("/usr/bin/delpart", {st_mode=S_IFREG|0755, st_size=18632, ...}) = 0
access("/usr/bin/delpart", X_OK)        = 0
stat("/usr/bin/xfce4-mime-settings", {st_mode=S_IFREG|0755, st_size=55336, ...}) = 0
access("/usr/bin/xfce4-mime-settings", X_OK) = 0
stat("/usr/bin/col1", {st_mode=S_IFREG|0755, st_size=963, ...}) = 0
access("/usr/bin/col1", X_OK)           = 0
stat("/usr/bin/lzfgrep", {st_mode=S_IFREG|0755, st_size=5421, ...}) = 0
access("/usr/bin/lzfgrep", X_OK)        = 0

The programs does this for a few minutes then it terminates with:

  File "/var/local/testuser/subuser/logic/subuserlib/classes/subuserSubmodules/run/x11Bridge.py", line 163, in cleanUp
    self.getUser().getDockerDaemon().execute(["run","--rm","--volume",os.path.join(self.getUser().getConfig()["volumes-dir"],"xpra")+":/xpra-volume","--entrypoint","/bin/rm",self.getServerSubuser().getImageId(),"-rf",os.path.join("/xpra-volume/",self.getSubuser().getName())])
  File "/var/local/testuser/subuser/logic/subuserlib/classes/docker/dockerDaemon.py", line 226, in execute
    return subuserlib.docker.run(args,cwd=cwd)
  File "/var/local/testuser/subuser/logic/subuserlib/docker.py", line 52, in run
    return subprocessExtras.call([getAndVerifyExecutable()]+args,cwd)
  File "/var/local/testuser/subuser/logic/subuserlib/subprocessExtras.py", line 20, in call
    process = subprocess.Popen(args,cwd=cwd)
  File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.4/subprocess.py", line 1386, in _execute_child
    for dir in os.get_exec_path(env))
  File "/usr/lib/python3.4/os.py", line 588, in get_exec_path
    with warnings.catch_warnings():
RuntimeError: maximum recursion depth exceeded

Running non X11 programs like Vim works fine.

timthelion commented 8 years ago

This is using the latest subuser from git? I don't have this problem, but I'm certainly looking into it.

ypid commented 8 years ago

Yes I was using latest master.

timthelion commented 8 years ago

Can you please pull the latest master and give me the full output of:

$ SUBUSER_DEBUG_XPRA=TRUE SUBUSER_VERBOSITY=5 subuser run keepassx
ypid commented 8 years ago

I put the logs here: https://github.com/ypid/subuser-x11-xpra-issue Test system is a Virtualbox VM running Debian Jessie but I was also testing on a bare metal Debian Jessie system. Maybe you can reproduce this also.

Just a note. I am going with Firejail for lightweight compartmentalization in AppVMs https://github.com/ypid/firejail-scripts I got xpra working with it. Thanks again for your work :+1:

timthelion commented 8 years ago

I just noticed: /var/local/testuser Is that really the value of $HOME? It seems the problem is a permissions problem in writting to that directory... I'm still not sure what could be causing thhat, because it appears that subuser has no problem writting to that directory up till that point.

timthelion commented 8 years ago

What is the reason you chose to go with firejail? Disk space usage? Or seccomp support? Something else?

ypid commented 8 years ago

I just noticed: /var/local/testuser

Yes. That is really the $HOME. The test system has been setup using Ansible and https://github.com/debops/ansible-bootstrap. Also not sure. I did run it on a normally configured desktop system with the same issue. Maybe you are able to reproduce this bug in a Debian Jessie environment.

What is the reason you chose to go with firejail? Disk space usage? Or seccomp support? Something else?

Makes sense to write a short comparison now that I know both a bit. So here it is:

Pro Subuser:

About equal:

Pro FireJail

Conclusion. I use FireJail for most things. I might consider using Subuser for example when I want to install packages from Debian unstable (althought I found it easier to just fall back to using Docker directly once I had a need for this (OK, quite a special case which probably does not count because of x86-32): https://github.com/ypid/docker-libreoffice-duden). I hope that gave you some insight's from a users perspective. Thanks again for your work.

timthelion commented 8 years ago

Reproduced and fixed. This is a nasty-reoccurant bug which is caused by launching a Docker container with a volume that points to a non-existant directory on the host. When you do that, Docker automatically creates the directory and the directory that is created by Docker is owned by root.

timthelion commented 8 years ago

Thanks a lot for your patience in reporting this. And also thanks for the thourough analysis of subuser and firejail. I will definitely take your sugestions into account.

ypid commented 8 years ago

Thanks very much for the fix :+1: