News for hackers. Stuff that matters.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @03:44AM (#26899939)
And don't forget to include making sure to create the right resource and namespace constraints so that the one binary doesn't gobble up memory endlessly or use up the file system or put your infrastructure completely at risk if/when it's compromised -- whether you do that with systemd units, raw cgroup/namespace finagling, or regular tried-and-true linux user-based resource segregation.

Containers do provide benefits.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by krageon on Thursday April 22, 2021 @03:56AM (#26900046)
> compromised

Containers are not a security measure. They're acceptable for some resource constraint considerations, but you should not ever use them because of security concerns. If that's something to worry about, use VMs at the very least.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by raesene9 on Thursday April 22, 2021 @04:43AM (#26900357)
I'm going to have to disagree with that statement. Containers (as implemented by Docker/containerD/CRI-O) do add security controls. Specifically, separate namespaces, restrictions on capabilities, seccomp filters and apparmor profiles.

If you can easily break out of any containerized enviornment, I'd suggest you could register for bug bounty programmes and make quite a lot of money also you can get a reward from Jessie Frazelle by escaping from https://contained.af/

Obviously containers have a larger attack surface than say a VM hypervisor, but security is not an absolute and both containers and VMs have suffered from breakout issues in the past. No security measure in isolation provides perfect protection.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by ex_amazon_sde on Thursday April 22, 2021 @08:29AM (#26901959)
No, you are confusing containers with sandboxing and they are completely orthogonal.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by emteycz on Thursday April 22, 2021 @05:22PM (#26908372)
Containers as understood in context of LXC or Docker are a strong variant of sandbox.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @04:05AM (#26900101)
> Containers are not a security measure. They're acceptable for some resource constraint considerations, but you should not ever use them because of security concerns. If that's something to worry about, use VMs at the very least.

This is repeatedly really commonly, but is bordering on wrong more and more every year. At the lowest level it's not even completely correct. Containers are resource + namespace isolation -- cgroups and namespaces -- isolation and kernel-assisted resource hiding/access control is absolutely a facet of good defence-in-depth. Enhanced security is not a core feature of containerization as a whole but it can absolutely help with your security posture.

For what % that satement is wrong, it's even more so because it fails to consider the container runtime. Container runtimes these days (containerd is the best one IMO) include ways to run containers at different levels of isolation (VMs and as micro kernels), so a move to containers can absolutely help security posture, because now you don't have to pull out packer/ansible/etc to build your VM, you can just take the same container you were running and change the runtime. Time to ship/launch improved security features is important, and containers can reduce that burden for teams.

Containers are a process isolation and resource control tool -- they can absolutely aid in security posture. Would you say the same about BSD Jails?

Just so there's some more value here, here are some projects that are somewhat close to cutting edge (though it's been a while) in this space that I like:

- nabla-containers.github.io/

- https://github.com/firecracker-microvm/firecracker-container...

- https://github.com/kata-containers/runtime (see https://github.com/kata-containers/documentation/blob/master...)

- https://rootlesscontaine.rs/

- https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2...

- https://starkandwayne.com/blog/the-capable-kernel-an-introdu...

The container ecosystem surfaces a lot of really cool resource limiting and isolation techniques and puts them in very close reach.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by jeffbee on Thursday April 22, 2021 @08:10AM (#26901810)
I’ll double down on what the GP said: containers provide less security than people imagine, and contrary to your comments Linux control groups provide no meaningful resource isolation.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @08:22AM (#26901903)
> containers provide less security than people imagine

Well sure, this heavily depends on the people you're talking to and what their imaginations are like. If it's the "containers are lightweight VMs" crowd then sure -- that view is fundamentally wrong.

> Linux control groups provide no meaningful resource isolation.

So this is a pretty bold claim -- as far as I can see processes certainly get OOMkilled when they use more resources than allowed for by their cgroup.

Do you have a link you could share? Is some fundamental part of cgroups (v1? v2?) broken in some way I haven't heard of up until now such that everyone has patched around it and it does what it says on the tin but despite the code in the kernel?

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by jeffbee on Thursday April 22, 2021 @09:13AM (#26902359)
The incompressible resources, including memory, have the best isolation story, but it is by no means perfect. A process in a given control group can easily cause external memory consumption that either escapes accounting altogether, or is charged to another control group. An example is the way kernel slabs are assigned to control groups. There were some patches in late 2020 from Facebook to help fix this, but I am not sure if they are merged and released yet. Those patches are also just better, not perfect.

Another example is a control group that is chronically out of memory. It may page vigorously, which will have external effects on other control groups through unaccounted resources like nvme controller time, memory fragmentation, global vmscan, etc.

A third popular way to abuse the resources of other containers is through networking. The way Linux handles network traffic is frankly hostile to proportional resource sharing. A control group with zero CPU quota can still easily cause external CPU time consumption.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @10:36AM (#26903233)
Thanks for explaining, while I still think what you said was a bit hyperbolic, I definitely didn't know about these... externalities, I guess you could call them? Learned something today.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by jeffbee on Thursday April 22, 2021 @12:38PM (#26904778)
I think of control groups as being adequate for what their inventor intended: approximate sharing of resources between non-antagonistic, first-party processes. Outside of that zone they can't be relied on for much of anything.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by dundarious on Thursday April 22, 2021 @11:27AM (#26903836)
GP is noting the security limitations of Linux containers, the mechanism, not some management daemon like containerd or some API or workflow. firecracker-containerd is not a container, per-se, as stated in their README.

> Like traditional containers, Firecracker microVMs offer fast start-up and shut-down and minimal overhead. Unlike traditional containers, however, they can provide an additional layer of isolation via the KVM hypervisor.

I think the security mechanism of note there is the hypervisor -- a VM technology. The fact that it is manageable via a daemon/API that was created for containers, does not mean it provides security via Linux containers, the mechanism.

A similar story can be told regarding capabilities, a mechanism that is orthogonal to containers -- all combinations of with and without capabilities and containers have their uses.

I do think GP is overly glib and assumes a particular threat model in order to dismiss Linux containers so thoroughly, and you are right to note "they can absolutely aid in security posture", etc. But GP is correct to note that VMs (though also imperfect) provide certain kinds of security/isolation that Linux containers, the mechanism, cannot yet match.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by SahAssar on Thursday April 22, 2021 @03:51AM (#26899995)
So ship the static binary and a systemd unit file like a lot of packages in the repos of your linux distro do.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by jeroenhd on Thursday April 22, 2021 @07:44AM (#26901632)
I don't understand why this isn't being done more. systemd has pretty much every convenience Docker has these days, without any of the ridiculous overhead and cognitive load that comes with managing a Docker daemon.

Yes, you'd need to learn how to make a systemd unit file but honestly, that shouldn't be a problem at all. I've had much worse headaches fighting Docker's networks and firewall-overruling network configuration in the past. Every time I forget to specify a restart option, I have to dig through my shell history again to see how I launched the image so I can kill and recreate it, or I have to look up that oneliner that shows you the docker run command for a running container.

I run stuff in Docker for one simple reason: I have it installed and I'm too lazy to think about software sometimes. If you're packaging software, that laziness isn't a reason to pick a distribution tool.

Static binaries have other problems, perhaps most importantly package management. How do you distribute your app? Traditional deb/rpm packages? curl-to-bash installers? Snap? Flatpak? Binaries that people flog into /usr/bin? What about automated updates, do you set up a repository, do you include a self-updater in your code? The list goes on. Docker solves that by having one general source of packages with the option of adding a repo of your own (take note, Canonical, your shitty Snap Store is practically useless without that last bit).

For services I run on servers, I much prefer traditional packages with dynamically linked executables, for a simple reason: automatically fixing security issues and bugs across applications with a single update command, instead of having to wait for every maintainer of their statically-linked tool to update their dependencies.

It's one of the big problems I have with Rust; many dependencies and applications embed their own versions of dependencies with sometimes very specific versions, and when there will eventually be a massive security problem in one of the TLS packages I'm dependent on recompiles and code modifications from random open source maintainers.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by dolmen on Friday April 23, 2021 @09:48AM (#26914726)
Here, we use docker-compose to automate container creation. And we have just one Makefile to automate docker-compose (to fetch credentials from secrets storage).

Our images are made from Go binaries, so thanks to Go modules, we can manage dependencies centrally from the main module and rebuild.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by goodpoint on Thursday April 22, 2021 @08:30AM (#26901969)
> I don't understand why this isn't being done more.

I can only offer one explanation: marketing.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @03:57AM (#26900054)
Yep, and you'd generally expect to spend time understanding the complexity that systemd brings, the subsystems that power it, and how you can separate resources there! There is no free lunch.

Restated, my point here is that while containers can be more complex and have pitfalls (a lot of which have been worked out somewhat at this point), there is no complexity free lunch -- `[docker|podman|crictl] run --rm --cpus 2 --memory 500mb ...` is pretty darn easy, and more so than writing properly portable and well-considered systemd unit files (and putting them in the right place, with the right permissions, under the right slice, etc). It's easier than most of the options out there (including the old methods of per-user resource segregation).

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by SahAssar on Thursday April 22, 2021 @04:27AM (#26900258)
Let's say you are installing this from a normal package manager and want to limit it:

To install:

    apt install mypackage
To edit the systemd unit (automatically creating the file in the right place):

    systemctl edit mypackage
Then add these lines to limit to 2 cpus and 500mb memory:

    [Service]
    CPUAccounting=true
    CPUQuota=200%
    MemoryAccounting=true
    MemoryHigh=500M
And then to start it now and on boot:

    systemctl enable --now mypackage
This is now integrated with package updates, starts on boot, logs to the same place that most other system utilities do and so on.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @04:57AM (#26900442)
I'm not about to argue against systemd, it's great software, and it's in every distro right now for a reason. Understanding apt (+/- how to package for it), systemctl, and the options you've laid out in your unit file are not trivial, and I would argue that they are less trivial (or harder) than understanding what's happening with containers, especially if you're running rootless containers, and/or using a container tool like podman which does without the daemon.

  --cpus 2 --memory 500M
is easier, and gets you the same results though they may not be as permanent or as well managed -- the management and external stuff is an orthogonal concern, and that's not the situation I was addressing. The original point was insinuating that throwing up a binary and getting it to run. your filesystem is also not available to the container by default, and in this way docker sort of fails closed. If you're running a rootless container, the story is even better.

One thing you have not covered is filesystem isolation, which docker also does very easily. There is a lot to configure on the systemd side[0] and the parts that are overlapping are just easier to configure and run with docker. Systemd is the better tool to build repeatable installs for pet processes, but again, there is a lot of knowledge underneath that is related. People to this day still complain that systemd does too much (I personally like it a lot, and it's great to have everything in one place).

[EDIT] Just to make myself clear, systemd is an amazing tool -- I like it, I run it, I'm not smart enough to administer a more complicated setup -- but docker is easier, for a large part of the small subset of systemd's capabilities that docker covers.

[0]: https://www.redhat.com/sysadmin/mastering-systemd

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by aequitas on Thursday April 22, 2021 @05:19AM (#26900567)
But there is a lot of work to be done before you can do the simple apt install. I (gladly) don't know how it is nowadays but before Dockerfiles/Docker creating your own packages according to the various standards was a pita. Most companies needed a 'packaging specialist/release engineer' role as most developers where not up to the task. Solutions like FPM[0] did help somewhat, but it was still hard when dealing with non-homogeneous environments. Containers solved that problem universally for all distributions.

[0] https://github.com/jordansissel/fpm

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by c0l0 on Thursday April 22, 2021 @04:07AM (#26900112)
I don't see how appending

    --cpus 2 --memory 500mb
to the argument vector liberates these options' definer from "understanding [...] the subsystems that power it", and reflect on their potential impact. And I'd argue that THIS is the real complexity incurred by these kinds of resource constraints that seem so simple on the surface - not the specific syntax or location you have to use to introduce them. All of which makes systemd unit files and their settings' implications (which are amazingly well-documented btw) as good as any other option, imho.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @04:23AM (#26900221)
Systemd is great software -- it is useful, and powerful. A systemd unit file, the idea of what a unit is, when they run, how they run, what shells they use, what permissions they run under, and lots of other complexities are expressed as options in the unit file, configuration files on the system, and in other places.

If I want to run a useful piece of software like redis let's say, but I want to run it with a resource constraint to make sure that it doesn't take more than 2CPUs and 500MB of memory, it is far easier to do that with the following command line:

   docker run --rm redis --cpus 2 --memory 500mb -p 6379:6379
Than to write the equivalent systemd unit file, set up the isolated filesystems that docker would let you easily bind mount in, etc. This is like comparing systemd-nspawn to systemd -- if systemd-nspawn isn't simpler than systemd then what are we even doing.

Docker won because of it's developer ergonomics (containers weren't new), systemd won because of it's feature set, convenience and sturdiness. They're different tools with different primary use-cases.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hartmel on Thursday April 22, 2021 @04:53AM (#26900407)
Then you will want to manage the configuration file and to browse logs, and you ll have to mount files to you container. And your deployment start to reimplement (a subset to your needs) what distros did System integration complexity didn't disappear thanks to containers. It was just moved to another place. I dd add that, being convenient for developers doesn't mean it's convenient for hosting management. At the end, when one side convenience is taken in consideration, it often translate to complexity and pain at the other side. K8S become in some companies more a mandatory runtime requirement than a hosting commodity/facility.

As a (former) developer I d rather ran redis in a container during development, but for production I d rather rely on boring VMs unless some scaling is required. (Managed k8s case set apart)

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @05:32AM (#26900649)
> Then you will want to manage the configuration file and to browse logs, and you ll have to mount files to you container. And your deployment start to reimplement (a subset to your needs) what distros did System integration complexity didn't disappear thanks to containers.

Agree, but my view on this is that the implicit answer of how you do all that (i.e. the file system, syslog) is now gone. There will be pain (complexity) in the short term, but at the end of the day, we're going to be able to build much better orchestration and systems. To kind of restate that, before you had to worry where a process wrote out it's output (stdout? /var/log/<program>? /etc/<program>/logs? /home/<user>/<program>/logs? syslog?), now you know want to get the non-stdout/stderr logs of the thing you're running, you'd better give it a volume to write to (which may be fake, and actually write everything to some remote storage or something), and I think that's a step forward.

Of course, I'm not saying containers should go everywhere -- relying on boring VMs over containers is fine too -- but I think rich world of functionality available to container-driven workflows is popular for good and bad reasons, and the good reasons are worth exploring/beneficial to me.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by slt2021 on Thursday April 22, 2021 @08:53AM (#26902171)
can anyone explain why you might need to limit memory consumption of your service?

I thought the kernel has virtual memory and if you consume more it will swap some memory and thats it.

Couldnt you just manage memory from inside your app? if its redis, then check the db size and shutdown/cleanup gracefully, and not crash redis with OOM?

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @10:44AM (#26903317)
> can anyone explain why you might need to limit memory consumption of your service?

> I thought the kernel has virtual memory and if you consume more it will swap some memory and thats it.

Well just to make sure the right memory goes to the right places -- if someone uploads a large file and you've made a mistake in your code that tries to hold it all in memory instead of buffering it straight to disk for example, you'd want that process to crash, and not your machine.

Also you generally don't want to swap, so much so that Kubernetes disables it immediately[0]. Not that Google is the only group with the right answer but they seem to think nothing can come of a machine having to swap. Maybe they're right. Even if they're not, A world where one service swaps[1] (I've never done this with docker to try it though) is probably better than one where it uses all the memory and everything swaps.

> Couldnt you just manage memory from inside your app? if its redis, then check the db size and shutdown/cleanup gracefully, and not crash redis with OOM?

You'd be surprised -- some languages just don't have a way to very easily get feedback from GC[2]. It's also something that I don't think most people think about, messing with the -XmXx<setting>s in Java is definitely year 2/3/4 java development for most people.

[0]: https://github.com/kubernetes/kubernetes/issues/53533

[1]: https://docs.docker.com/config/containers/resource_constrain...

[2]: https://github.com/golang/go/issues/29696

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by slt2021 on Thursday April 22, 2021 @11:11AM (#26903634)
Also thank you very much for kubernetes link.

Wow, given how expensive RAM is it is no surprise they will never allow kubernetes work with swap, becausr it directly translates to $$$ for GCP and other cloud providers. Also since everyone loves using Java/Spring/Node and other memory hungry frameworks - it print enormous $ for cloud providers to require users overallocate RAM and disable swap.

or am I just spitballing conspiracy theory here and there is no conflict btw decisions like these and vendors' revenue streams?

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by lanstin on Friday April 23, 2021 @10:23AM (#26915057)
For years, nay decades, the standard for data centers is no swapping. An incident caused by machine went slow due to swapping is almost as embarrassing as one caused by disk filling. Better to orchestrate a restart every night on your leaky code.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by slt2021 on Thursday April 22, 2021 @11:06AM (#26903580)
I think it is just different thinking: DEV where software is a pet, where I want full control of my memory and take care of it carefully, and dont want anyone shutting down my service violently.

contrast it to Ops mentality of software is a cattle (here is your memory quota and if its OOM, just kill/restart the service and hope next run it wont run OOM)

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by pjmlp on Thursday April 22, 2021 @04:20AM (#26900203)
My first container experience goes back to HP-UX Vaults.

I let you research when that was, and wonder what container technologies might have used since then.

I know when they make sense and when they happen to be fashion.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @05:04AM (#26900488)
Didn't doubt your experience (I read and enjoy your comments all the time on HN), just pointed out that the feature set offered by single static binary (which arguably is not easy to build depending on what language you're using, etc) is not the same as what's offered by linux containerization in the current day.

Half the "static" binaries that used to float around weren't even fully static because of glibc, until building with musl (and getting bit by getaddrinfo) became widespread -- the situation is not as simple as you made it seem.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by pjmlp on Thursday April 22, 2021 @05:18AM (#26900563)
I agree with the glibc issue, but that is a problem of GCC specifically.

My point is that I see containers being overused nowadays, like "big data" that fits on a USB pen kind of scenario.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @05:27AM (#26900612)
Agreed -- containers are certainly being overused these days, I find a big indicator of when people know what they're talking about is when they mention/realize that docker is containerd these days (docker is simply a shim over containerd which uses runc underneath), but it is absolutely still very buzzword-y.

I think we've basically stumbled into a very effective and widespread packaging paradigm though -- now you don't even have to pick the right language/toolset to get static binaries easily -- just throw a container over the wall and your filesystem requirements (mounts), network requirements, etc will be made pretty obvious to the person doing the deployment

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by pjmlp on Friday April 23, 2021 @02:11AM (#26911474)
Assuming that source and target hardware are the same, otherwise VMs enter into the picture, and stuff like Kata Containers add even more layers.

Then I remember Linus point of view about monolitic kernels and how they are supposed to beat micro-kernels, what for, when people put hundreds of virtualization layers on top.

Re:Tiny Container Challenge: Building a 6kB Containerized HT... by dolmen on Friday April 23, 2021 @10:53AM (#26915326)
Well as Docker even abstracts VMs (you can build and run a Linux/amd64 container from a MacOS/amd64 (soon MacOS/arm64 also)) the target OS and hardware become more and more just a deployment detail.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by pjmlp on Saturday April 24, 2021 @04:40AM (#26923357)
Docker doesn't abstract VMs, it rather needs one to package Linux along for the party.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by ex_amazon_sde on Thursday April 22, 2021 @08:27AM (#26901945)
You are describing sandboxing and it's completely orthogonal to containers.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by IshKebab on Thursday April 22, 2021 @03:54AM (#26900026)
Most servers are already running in a VM that takes care of all that.
Re:Tiny Container Challenge: Building a 6kB Containerized HT... by hardwaresofton on Thursday April 22, 2021 @04:17AM (#26900186)
yeah but that bit of complexity wasn't mentioned :). If every process you need to run in it's own VMs/per-instance then you've got best-in-class isolation already, no need to bother with containers, and you can get your resource and namespace isolation. Not quite the same as just throwing a static binary over the wall though, a little bit more complexity there.