11 ms·
Binctr: Static, unprivileged, self-contained containers as executable binaries
- pritambaral 8y agoI see that it extracts files into `/tmp/...` inside the container first before running it. It'd be better if it could read the files directly from the image, say, like a self-executable squashfs image.
- zozbot123 8y agoWouldn't in-place decompression for a "self-executable" squashfs require one to disable NX for that binary? That seems like it would be a terrible idea from a security perspective. (Even for pure data, in-place decompression seems like it would heavily interfere with e.g. demand paging of such data into RAM, using the binary itself as backing store. Disk space is so cheap these days - I don't think things like squashfs should be used nowadays unless truly necessary.)
- dullgiulio 8y agoYes, but for the same reason /tmp is also often a non-executable partition.
- _wmd 8y agoPhysical pages can be mapped more than once, it is the mapping that describes protection bits. Implementing an in-place FUSE filesystem for example would have no bearing on whether other mappings of the same file lacked execute bits, and in the case of the FUSE interface, the kernel does not even know the original source of the data I think this could also be achieved with a loopback device setup to cover some of the file, again no relevance to NX etc, but that would require setuid or similar to configure the device
- pritambaral 8y agoWith the recent (with upcoming improvements) userspace mount support in Linux, even suid may be unnecessary.
- pritambaral 8y agoIt doesn't have to be in-place, or even compressed; it just has to be automatic and OS-integrated. With something like squashfs (with or without compression) the kernel handles all the paging, mapping, and decompression (if any). Of course there are the classical benefits like resource usage being more efficient, but more importantly, less userspace code that needs to worry/care about filesystems and file layout etc.
- zozbot123 8y ago> It doesn't have to be in-place, or even compressed; it just has to be automatic and OS-integrated. With something like squashfs (with or without compression) the kernel handles all the paging, mapping, and decompression (if any). Sure, but I don't think you can do that within a self-contained binary, the kernel doesn't really support that. It would have to just be a loopback image, and lose the whole "self-contained binary" angle that makes this different from all sorts of other container tech.
- pritambaral 8y ago> Sure, but I don't think you can do that within a self-contained binary, the kernel doesn't really support that. An executable binary can set up a mount namespace, mount /proc/self/exe or argv[0] (with some offset) as a loopback device within the namespace, and then execute a process within the mount.
- hedora 8y agoIt would probably only be a few lines of portable shell code. Mounting at an offset is one line; runing the executable is a second. Not sure what you have to do to manually drop into a container. (Though, I think you need to be root to run those lines, and you could put setuid root binaries in the image...)
- pritambaral 8y ago> Though, I think you need to be root to run those lines If you're thinking of mounts, Linux is getting there: https://lwn.net/Articles/697278/ https://lwn.net/Articles/697278/ and https://lwn.net/Articles/755498/ https://lwn.net/Articles/755498/ If you're thinking containerisation, it has been possible for a while, and new improvements are coming up: https://www.youtube.com/watch?v=-PZNF8XDNn8 https://www.youtube.com/watch?v=-PZNF8XDNn8 and https://events.linuxfoundation.org/wp-content/uploads/2017/12/2018-LSS-Europe-Edinburgh-Namespaces-and-Capabilities_Christian-Brauner.pdf https://events.linuxfoundation.org/wp-content/uploads/2017/1...
- exrook 8y agoNX does not need to be disabled[1] for the binary thanks to W^X[0]. As long as pages are never mapped as writeable and executable at the same time, you don't lose any protection. [0] https://en.wikipedia.org/wiki/W%5EX https://en.wikipedia.org/wiki/W%5EX [1] AFAIK, on Linux NX isn't something that is enabled or disabled for individual programs anyways, it's up to the userland whether or not it takes advantage of the mmap(2) mapping flags
- bdonlan 8y agoIn general, you lose some protection, as a two-stage exploit might write some data in W state then flip to (or wait for) X state for execution. That being said, a self-decompressing binary would only do this at startup, before it consumes untrusted input, so given a way to drop map-executable permissions that wouldn't be a problem.
- mwcampbell 8y ago> Disk space is so cheap these days And yet we always find new ways to waste it. 16 GB was once an unimaginable amount of space, and yet one of my coworkers now takes it for granted that 16 GB isn't enough storage for a smartphone. We should do our best not to waste any more.
- mroche 8y agoAgreed. We had a petabyte storage for scratch data on our cluster. We were stuck around 95-100% capacity used for the past month and some change until we recently added another half petabyte or so. We were constantly deleting and automating warnings to people that info would be removed and their access restricted if things weren’t removed. We ended up suspending the cluster for a day while we tried to figure out how we were exponentially losing data (one user decided to start uploading terabytes of data to scratch, which is against policy). No one seemed to understand that if data filled up completely, the entire cluster would go offline because _we wouldn’t have the space for anything_.
- tfigment 8y agoCynically, I think its not that they don't understand its that they don't care and that it is why you are probably there to care for them and solve it. I have similar engineers and its a struggle. Didn't Douglas Adams invent the concept of the SEP Field to explain this (somebody else's problem)?
- gnufx 8y agoYes, it's part of system management to prevent users interfering with one another -- and at least detect problems that are difficult to prevent, like activity crippling a parallel filesystem, and sorting it out.
- hden 8y agoThe same idea two years ago: https://github.com/bfirsh/whalebrew https://github.com/bfirsh/whalebrew
- cyphar 8y agoThis project was written in 2016 too.
- sandGorgon 8y agoIsn't CNAB doing this (and more) and is going to be more widely adopted? https://github.com/deislabs/cnab-workshop/blob/master/content/01-what-is-cnab.md https://github.com/deislabs/cnab-workshop/blob/master/conten...
- solarengineer 8y agoContext: https://cnab.io https://cnab.io
- deleted 8y ago[deleted]
- Annatar 8y agoSo basically a full circle on running single binary executable processes, a multitude of them, as was done on a UNIX system back in the '90's, only with more complexity (this effort is an attempt to reduce that complexity, which in and of itself is telling). And still nowhere near the flexibility, security, the power and simplicity of illumos zones and SMF.
- p2t2p 8y agoWell, you can't statically link bunch of python scripts. With this one you can do it easily (relatively).
- progval 8y agoYes you can: eggs and wheels.
- filmor 8y agoStill needs Python itself.
- deleted 8y ago[deleted]
- pritambaral 8y agoFreezing python scripts+runtime to generate static executables has long been possible. Of course, all such methods are specific to python and have python-specific caveats. One could say static-containerisation is just a general form of the practice of freezing runtimes with scripts.
- fpoling 8y agoFor Python and other interpreters one does not need containers. LD_PRELOAD and similar hacks is sufficient to redirect reading of script files into reading from a file system embedded into the executable.
- 8y ago
- amelius 8y agoWhy does the Linux kernel/Posix make sandboxing so difficult?
- gronne 8y agocompared to?
- yoshuaw 8y agoI'm assuming they're referring to BSD here. Admittedly jails and pledge(2) seem rather nice to work with compared to Linux's equivalents.
- GordonS 8y agoInterestingly, there was a post in HN recently about the next build of Windows introducing sandboxing. It really feels like there has been a steady stream of new security features coming out of Microsoft lately, which is great to see.
- walterbell 8y agoThe upcoming Microsoft capability appears to be inspired by Bromium, https://www.pcworld.com/article/3169668/browsers/hp-hardens-elitebook-protection-with-sure-click-a-browser-secured-in-virtual-hardware.html https://www.pcworld.com/article/3169668/browsers/hp-hardens-..., which has long provided "seamless ephermal virtualization" on Win 7/10.
- saagarjha 8y agoOf course, this “sandboxing” is the equivalent of running apps in a CoW virtual machine.
- nijave 8y agoThe sandbox can share memory with the host but says it is running a separate kernel https://techcommunity.microsoft.com/t5/Windows-Kernel-Internals/Windows-Sandbox/ba-p/301849 https://techcommunity.microsoft.com/t5/Windows-Kernel-Intern... I think just saying it's a VM is an over simplification
- hkt 8y agoStrongly reminds me of UML: https://en.m.wikipedia.org/wiki/User-mode_Linux https://en.m.wikipedia.org/wiki/User-mode_Linux
- rkeene2 8y agoI used UML to do this very thing 15+ years ago !
- cat199 8y agohow does this compare to: https://en.wikipedia.org/wiki/Singularity_(software) https://en.wikipedia.org/wiki/Singularity_(software)
- TheDong 8y agoRequires set-uid, it's not fully unprivileged containers.
- jclarkcom 8y agoI worked on something similar for Windows for nearly 10 years, called Thinstall (acquired by vmware and renamed to Thinapp). I love the idea of something like that for linux. We put a lot of effort into being able to run an application directly from a compressed single-file binary, you have a small executable with a big payload attached to the end of it. The payload essentially contains a mountable filesystem, however because windows doesn't support doing anything like that from an unprivileged account we had to emulate many things Windows normally does, including execution of binary images. We did some tricks where executable data was stored on disk in a format it can be directly memory mapped and run without reading anything - this allowed us to launch most applications over a network without extracting anything to disk locally and achieve millisecond launch times. Pages would get pulled into local memory by the OS as needed while the application was running. The end result was that you can create a single EXE file could contain things like python + script, or more complex like photoshop & Word. Just go to a new computer from a guest account, launch the EXE and you instantly start using that app. I haven't been involved with it for the last 6 years, but I believe vmware still offers it.
- zozbot123 8y agoOr, you know, you could just uncompress the application in a newly-created subfolder of C:\WINDOWS\TEMP\ and launch the binary that is to be run afterwards (which of course is conveniently named SETUP.EXE). The way it's always been done.
- fooker 8y agoHow do you stop the app from permanently writing stuff to the registry or filesystem?
- jclarkcom 8y agoThinapp solved this by presenting a synthetic view of the filesystem and registry to the app. This view merged the contents of the real system with the contents of the package, so the app thought everything was were it expected when it runs. In addition, we provided a copy-on-write sandbox of this view, so any writes would be redirected to a local folder without the app knowing about it. If you delete the sandbox, the app goes back to it's "first run" state.
- mroche 8y ago> Well judging by the original GitHub issue about unprivileged runc containers, the largest group of commenters is from the scientific community who are restricted to not run certain programs as root. Which is why we use Singularity[0]. Apologies if I’m missing something, but to me this problem they’re trying to solve, has already been solved. As stated in the README: > Singularity is an open source container platform designed to be simple, fast, and secure. Singularity is optimized for EPC and HPC workloads, allowing untrusted users to run untrusted containers in a trusted way. Singularity ‘requires’ root or elevated privileges to create and modify containers, but running them is done in the user’s namespace with that user’s permission set. And privileges can’t be elevated during the containers runtime as there are kernel level catches that prevent sudo and su from working inside the container. In terms of the ‘static’ part, Singularity uses SquashFS to produce a single binary image, and uses the SIF (Singularity Image File) format to define applications, their dependencies, and runscripts. On top of being able to run anything inside the container with the `exec` subcommand. You can also create sandbox development images that are just a directory on disk for testing things out and installing/building tools manually, then convert it into a SIF container after for cluster deployment. Or be nicer and port your process into a recipe/definition file. Most scientific/HPC related centers have started utilizing Singularity for their container workflow. Tools like Docker are essentially banned because of their perma-root privileges[1]. [0] https://github.com/sylabs/singularity https://github.com/sylabs/singularity [1] I’m an admin who reimplemented Singularity on our university’s cluster. With a heavy need on filesystem integration (which Singularity solves with great configuration options), containers which run with root privileges would be a massive security vulnerability.
- batbomb 8y agoIt should be said that Singularity does actually rely on setuid scripts to actually work with images.
- mroche 8y agoIs there anyway to do what it does without them? Genuine question, there’s still a lot about Linux system/user space that I’m not up to snuff on yet (part of a team here, and I don’t handle users, mostly tools). I’m trying to compare/contrast the goals of binctr to existing solutions that appear to do the same or similar thing(s) already, so I’m open to learning something new today! The only new thing I’m seeing from this solution is the ability to create containers as an unprivileged user, which for most scenarios I tend to view as a non-issue. Or am I misunderstanding that?
- zbentley 8y agoThe container revolution appears to have come full circle and reinvented static linking.
- markbnj 8y agoWhich language produces statically linked binaries that embed their own root filesystem?
- groestl 8y agoThe question is: which languages _require_ their own root filesystem. Because all of them can join the single executable party now too.
- rkeene2 8y agoTcl.
- TheDong 8y agoSmalltalk, which distributes code as a vm. Java jars aren't far off from having their own rootfs included along with the compiled class files.
- groestl 8y agoYepp, almost there. I'm still waiting for some mechanism to statically link a distributed binary, so we can get rid of kubernetes too.
- wpietri 8y agoIf it takes a container to get static linking for dynamic languages, that's fine by me. I have one Python project where I'm just using Docker to produce a single, self-contained lump so I don't have to fuck around when installing. This would be a step forward for me. And then I have a Python library and command-line tool [1] where an awful lot of the issues people report are library version nonsense. I tried to help the first few, but at this point I've decided it's just not my job to make up for the Python community's packaging issues and/or issues related to other open-source projects and OSes. I'd love to be able to produce the equivalent of a statically linked binary for those people. [1] https://github.com/wpietri/sucks https://github.com/wpietri/sucks
- nwmcsween 8y agoI'm not too excited about embedding the data (rootfs) within the image. Have a .preinit_array section that runs a seccomp-bpf filter, unshare, etc with filter, unshare, etc data in their own sections (this allows zeroing a section to get original behaviour)
- equalunique 8y agoThe advantages of this are kind of like two security features recently added to OpenBSD: pledge & unveil