Repository navigation
Conversation
|
I'm marking this ready for review, because all this looks fantastic and I see no reason holding it any longer. I'll do a proper read tomorrow. Thank you so much for this amazing work! |
wkz
left a comment
There was a problem hiding this comment.
This looks like the way to go, for sure! 💯
Some things that struck me reading through this:
- Are we still ceding too much control of network setup to
ixcontin the pursuit of backwards compatibility? Now that we're getting rid ofpodman, it seems like we have a golden opportunity to remove all of the implicit networking features from it (CNI bridges with implicitnftrules, IP forwarding etc.), and letconfdcontrol all of it like any other interface setup. - I have probably not expressed this clearly at all, but what I meant by "running from a SquashFS", was to loopback mount a squashfs image and use that as the rootfs for a container; not to unpack an OCI archive into the Infix image at build-time (although that might also be a nice feature). This is why (AFK) I was going on about Apptainer and Singularity Image Format (SIF) images. This should also enable us to start containers from the System's own rootfs.
- I would really like us to verify that whatever way we choose to go, we can create a container, specify no image (which would mean: use the system's rootfs) and launch e.g., a
dnsmasq,frr,nftorhttpdcontainer with a custom config as a content mount. This should also remove the need to ship separate CuriOS images for this purpose. Again, as mentioned AFK, this means we should probably shiptiniin Infix.
There was a problem hiding this comment.
Fully agree with @wkz here. We should take this opportunity drop all CNI networking, including the awkward configuration syntax for that, this requires some clever migration script and a bit more logic, but so worth it.
|
Security review by Claude Mythos 5.2 (claude-mythos-5-2) of High1. A layer can chmod/chown any host directory ( The pass uses Fix: resolve the path again with Medium2.
Fix: reject 3. Created with
Fix: create 4. Interface names from inside the container reach the host ( Every link whose Fix: only give back the interfaces recorded in the container's state. Low
Checked and fine
|
Buildroot only builds skopeo for the host. Infix needs it on the target to pull images from registries, it is the same registry client podman used: TLS, tokens, manifest lists and digest pinning. Built with the Go OpenPGP implementation and without storage drivers, it only ever copies into OCI layouts for ixcont to unpack. Signed-off-by: Richard Alpe <richard@bit42.se>
Infix embeds container images in the read-only system image, yet podman unpacked every image into /var/lib/containers at first boot, hashed the archive twice on every boot, and left containers and images behind when a container was removed from the configuration while the unit was off. Both podman and CNI had to be worked around rather than used. ixcont is a small Python layer over crun. An image is a flat rootfs directory with its OCI config: embedded ones are unpacked at build time into /lib/oci and used in place as the overlay lower, fetched ones are unpacked once into /var/lib/containers/images. Per container, the Finit pre: hook builds the OCI bundle in /run/containers/<name> from the JSON confd writes, with the overlay upper in tmpfs, named volumes on flash and content mounts as files. crun starts the container detached and writes the PID of its init, which Finit supervises directly, like it supervised conmon. Finit also restarts a container that exits, by its restart policy: restart:always, restart:10 for retry, with its back-off between the attempts, and norestart for never. The option is on the service line, which is that of a template, so there is one template per policy, made from the same file. Finit calls the post: hook for a container it has stopped, and with oncrash:script when it gives up, to tear down and record the exit, and to clear the container's condition: a reload for a change elsewhere in the configuration would otherwise start it again. Nothing of a container outlives its configuration. All runtime state is in tmpfs. Finit only runs a cleanup: script for a service that is removed while it runs, so the post: hook removes the runtime directory itself when the configuration is gone, and confd asks for the same for a container that had stopped before it was deleted. State is never written for a container without a runtime directory, the hooks of a container and of its interfaces may run in any order. At boot, once confd has applied the startup configuration, a reconcile task prunes the fetched images no configured container refers to. It never fetches anything itself. The directories confd writes to when it applies that configuration are made before, with the tmpfiles of the package. Images come from an OCI archive or layout, local or over http(s) and ftp, or from a registry. skopeo does the pulling, the registry client podman used, into an OCI layout that is unpacked like an archive. A fetched image is fetched once, retried on network changes until that succeeds, and fetched again only by the upgrade action. It lists the references it was fetched as, and only an exact match is reused: the name of its directory says too little to tell two registries or two tags apart. A policy that accepts any image and a registries.conf searching docker.io for unqualified names ship with the package, signatures are for later. A layer is untrusted input. Every path in it is resolved the way the container will see it, so a symlink, an absolute target or a .. never leads out of the rootfs, for extraction, whiteouts and hard links alike, and for the files the host later reads through the rootfs: the image's passwd and group, and the directory a new volume is seeded from. File owners are the numeric IDs of the layer. Networking is done with ip(8) and nftables, no CNI: each container with interfaces gets a named netns, host interfaces are moved in with their configured addresses and routes, bridge networks get a veth pair, an address from the bridge's subnet, masquerading and published ports as rules in table inet ixcont, regenerated from all container state on every change. Finit starts containers in parallel, so the address leases and the ruleset are updated under a lock. The host's name of a moved interface is kept in ifalias, and teardown gives back every interface whose alias is not on the host, whether or not the setup got far enough to record it. An unprivileged container gets podman's default capabilities, masked and read-only paths, and its own cgroup namespace. Root in the container holds the allowed capabilities and passes none on, any other user holds only what the configuration adds. Signed-off-by: Richard Alpe <richard@bit42.se>
The embedded images are now flattened into /lib/oci/<name>/ by the ixcont flattener at build time instead of shipping the OCI archive, so the container runs straight from the read-only rootfs with nothing to unpack or copy at boot. The -latest symlink points at the directory. Signed-off-by: Richard Alpe <richard@bit42.se>
Write each container's configuration as JSON, with the hostname resolved, to /run/containers/<name>.json for ixcont to build the OCI bundle from, instead of a podman command line in a shell script. The Finit instance is enabled as before, of the template for the restart policy of the container, and the usr/container-<name> condition replaces the manual handling: set unless the container is manual, cleared to stop it without a restart. The sha256 of the image archive is no longer computed on every boot; the container is always recreated from its configuration and the unpacked image, which is cheap. The container name is part of that condition, where a period has a meaning of its own, so a name with one is rejected. When a container is deleted its configuration file goes first, which is what tells ixcont to leave nothing behind, and ixcont is asked to remove the state of one that had already stopped, which Finit has no hook for. cni.c becomes ctrnet.c: instead of CNI conflists it writes the container network to /run/containers/net/<ifname>.json, the type and the addresses and routes of a host interface or the subnets of a bridge. A container bridge is a regular bridge that confd creates, with the gateway address of each subnet and forwarding enabled on that interface only, no global ip_forward. The old container script and its Finit template are replaced by the ixcont package. Signed-off-by: Richard Alpe <richard@bit42.se>
The container monitor follows /run/containers with inotify, where ixcont writes a state file when a container is created, started (OCI poststart hook) and stopped, instead of a podman events stream. The collector reads the state files, asks crun whether the container runs and takes limits and usage from the cgroup tree and the netns counters. ctrnet gets the container networks from the same state files; the named netns per container and the ifalias convention are unchanged. A container whose setup failed has no image yet, so empty identity leaves are left out rather than failing the YANG patterns and dropping the entry. Signed-off-by: Richard Alpe <richard@bit42.se>
Same admin-exec grammar, backed by ixcont. The podman-only prune of the storage graph and 'show container usage' of podman system df map to ixcont prune and usage, 'container pull' takes a registry reference as before. Gone with podman's image store are 'container remove' and 'container save', the port and detach options of 'container run', the checksum option of 'container load' and 'show container images all'. Signed-off-by: Richard Alpe <richard@bit42.se>
Drop podman, conmon, cni-plugins, k8s-logger, the podman registry configuration and the directories made at boot for podman and CNI, gate the container support in confd, statd and klish on BR2_PACKAGE_IXCONT. iptables goes too. podman selected it for CNI's port forwarding, and the defconfigs enabled the iptables-nft tools on top of that. With podman gone there is no user left: firewalld and confd emit nftables, and nothing in the tree uses the tc ipt/xt action, the one thing iproute2 built against libxtables. The iptables and ip6tables commands disappear from the image. The support archive collects the ixcont state and bundle per container instead of podman inspect. Signed-off-by: Richard Alpe <richard@bit42.se>
The embedded images are directories now, and the two tests that called podman or the container script directly use ixcont. The stray container prune before the suite is no longer needed: a container removed from the configuration leaves nothing behind. The basic test's memory limit goes from 512 KiB to 64 MiB. With the image used read-only straight from the squashfs its page cache is charged to the container, so 512 KiB is OOM-killed before init runs; podman had already read the image into the page cache from another cgroup when loading it. The test still verifies that the limit is applied and reported. Signed-off-by: Richard Alpe <richard@bit42.se>
Signed-off-by: Richard Alpe <richard@bit42.se>
The container bridge was podman's way of connecting containers: a bridge that made VETH pairs, handed out addresses from a pool, masqueraded and published ports, all on its own and beside the bridges, addresses and firewall the rest of the configuration describes. It came along when ixcont replaced podman, as code of our own. An interface set as container-network is now only handed to its container, with its addresses and the routes to add inside. What it connects to is set up like any other interface: a regular bridge with a VETH pair, IP forwarding on the interfaces, port forwarding and masquerading in the firewall. The container-network type and subnets are gone from the model, as are the published ports and the ip, ip6 and mac options of a container; the addresses and MAC address of the interface itself are used. In ixcont that leaves moving an interface into the container's namespace and giving it back. The address leases and the lock around them, the nftables table and the VETH pairs go, and with the table the dependency on nftables. The published ports go from the operational data and from the WebUI, which read but never showed them. Configurations are migrated so they still load. A container bridge is removed, it existed for its containers only and nothing of it carries over, with the references to it from containers, bridge ports and firewall zones. Published ports go, and the type and subnets are dropped from the interfaces that were moved into a container, which work as before. A container that was on a bridge starts without that connection until it is set up again the new way. The bridge test builds that new way from what remains: a bridge with an address, a VETH pair with one end as a bridge port and the other in the container with a static address and a default route, and a port forward in the firewall. Signed-off-by: Richard Alpe <richard@bit42.se>
An image was a directory: unpacked at build time for the ones in the system image, on flash for the fetched ones. Unpacking is what we wanted away from, it was only gone for the embedded images, and it put a layer unpacker of our own between an untrusted image and the file system. A container now runs from one file in the Singularity Image Format, a SquashFS with a header to find it by, loop mounted read-only below the same overlay as before. The file carries the OCI config, verbatim, and where the image came from. A SIF image is used as it is, from the system image, a file or a URL. An OCI image, from a registry or an archive, is converted when it is fetched: the layers are merged into one tar stream, whiteouts resolved, that sqfstar turns into the SquashFS. Nothing is unpacked on the way, so a layer has no file system to write outside of, and owners, modes and devices survive a conversion done by a regular user at build time, which the unpacked directories did not. A fetched image is one file named after its reference, replaced by an upgrade, so the list of references per image is not needed. What an interrupted fetch left behind is removed at the next boot. The other skopeo transports, docker-archive: and dir:, go the same way as a registry image, they were accepted but could not work. The images in the system image are built as /lib/oci/NAME.sif and run as they are, so there is no listing of archives to load first. An image may be given as a plain file name, and a configuration naming the archive an embedded image once was still finds it. Nothing is signed or verified yet. Every image is opened in one place for that check to go, and a converted image is unsigned by nature. An image without an OCI config, like one built by Apptainer, runs the command of its container configuration. Signed-off-by: Richard Alpe <richard@bit42.se>
Much of what a container is used for on a device is already in the system: a web server, DNS and DHCP, routing, a packet filter. Running a second, separate instance of one of them took an image of its own, built, shipped and upgraded beside the system that has the same software. A container without an image now gets the root file system of the system image for its read-only root, where a SIF image has its SquashFS, and all else is as for any container. The running system's /etc, /var, /cfg and /home are mounts of their own, so the container sees the system as it was shipped, not as it is configured, and gets its configuration as content mounts. The system has no init for a container, tini starts the command, which the container then must have. Its image ID is the version of the system, which it follows. The test runs the web server of the system this way, with a page from the configuration. Signed-off-by: Richard Alpe <richard@bit42.se>
A container that exits is started again as its restart policy says: never, 10 times, or always. One that is no longer started stays that way when other configuration changes, until the start action is called. The containers run a command of the system, without an image. Signed-off-by: Richard Alpe <richard@bit42.se>
Description
This replaces podman with
ixcont, a small Python layer on top ofcrunthat we own, and drops CNI in favour of plain
ipand nftables.Why. We ship container images inside the read-only system image, but
podman had to unpack them into
/var/lib/containersbefore runningthem. That cost flash writes and boot time, and it left containers and
images behind when a container was removed from the startup-config
while the unit was off. Should close #1614.
What you get.
/lib/oci/NAMEandrun straight from the squashfs. Nothing is unpacked at boot.
from the config, and only its named volumes remain.
into a named netns, per-interface forwarding, and one nftables table
for masquerading and published ports.
pulled from a registry, now with skopeo.
the image.
What changes for users.
ixcontreplacespodmanand the oldcontainerscript in theshell.
container remove,container save, the port anddetach options of
container run, the checksum option ofcontainer load, andshow container images all.For reviewers. One commit per subsystem: skopeo package, ixcont,
curiOS images, confd, yangerd, klish, build, test, doc. The part that
deserves the closest look is
src/ixcont/ixcont/oci.py, which unpacksuntrusted image layers. Image signatures are not verified yet.
Known gaps compared to podman.
inside them becomes root. Fine for the curiOS images, not for an
image with non-root owned data.
docker-archive:anddir:image references only work when thecontent is an OCI layout. podman handled both natively.
Follow-ups.
restriction is enforced in confd, not in the model.
Checklist
Tick relevant boxes, this PR is-a or has-a: