Repository navigation
Layers with an absolute hard-link target unpack, as with Docker - #322
talaatmagdyx wants to merge 1 commit into
Conversation
A layer's hard link to `/usr/bin/perl` names the layer's own `usr/bin/perl`, as Docker, containerd and Podman read it. tar-rs joins the target onto the layer directory, which a leading `/` replaces, and refuses the result as outside the layer, so the image could not start. Such a link is now made in `untar`, from the layer's root. Both paths go through the walk whiteouts use (now `layer_dir`): every step must be a real directory of the layer and `..` is refused, so a link still cannot reach outside. Relative hard links and every other entry go through tar-rs as before. Fixes libracoder#302
The hosted Docker reference rejected our old metadata expectation: a hard-link header changes the shared inode's owner and mode. Preserve the conflicting headers in the fixture and require Docker's observed result. The installed Asagiri0.1.5 reproduces the opposite values as a negative control and its owned resources were removed. Apply ownership, mode, time and xattrs in the Linux layer extractor using a pinned inode and final-symlink-safe metadata operations. Keep tar-rs's path checks and add safe replacement for an existing destination. Do not open special files for I/O. Add real tests for shared metadata, PAX fields, replacement and symlink-inode boundaries, plus eight Docker API cases. Local validation: seven portable filesystem tests passed; Python syntax and diff checks passed. Linux extraction and hosted Docker/Asagiri matrix remain pending. Retain the failed run43806691901 as reference evidence. Related: libracoder/kiri#302 and libracoder/kiri#322. Attribute semantics checked against moby/moby pkg/archive/archive.go at v28.0.4. Signed-off-by: Andre Kurait <akurait@amazon.com>
The real Linux run passed the new regular-file and symlink metadata regressions, but two older FIFO/device tests still expected the first header's mode and timestamp after a conflicting hard-link header. Docker applies the later link header to the shared inode. Keep the original special-entry checks, then separately require the later header's attributes and shared inode/link count. Verify device numbers and types survive both paths. Use the test process's UID/GID so the FIFO case also works without root; no device is opened for I/O. Related: libracoder/kiri#302 Related: libracoder/kiri#322 Signed-off-by: Andre Kurait <akurait@amazon.com>
Keep each layer path unique and put the replaced file in a lower layer. The Docker reference rejected the previous duplicate-path fixture; its seven name and metadata cases passed. Retain all eight API cases and the separate Linux extraction replacement tests. Related: libracoder/kiri#302, libracoder/kiri#322 Signed-off-by: Andre Kurait <akurait@amazon.com>
|
@talaatmagdyx thanks. Your fix and tests are what showed the problem in #302. #398 is now merged. Its hard-link path handles every link (absolute and relative) through Kiri's confined Could you rebase onto main and keep only your tests? That's |
Fixes #302
Problem
A layer with a hard link whose target starts with
/(usr/bin/perl5.38.2→/usr/bin/perl, as some image pipelines write them) failed to unpack, sodocker createanddocker runrefused the image:Docker, containerd and Podman read a hard link's target from the layer's root, so the leading
/is harmless there.Cause
The guest agent unpacks layers with tar-rs. For a hard link, tar-rs joins the target onto the layer directory with
Path::join, which an absolute path replaces. The target becomes the guest's own/usr/bin/perl, and tar-rs refuses it as outside the destination.Change
crates/kiri-init/src/linux/layers.rs, inuntar:hard_link_in, with the leading/taken as the layer's root. Every other entry, including relative hard links, still goes through tar-rs as before.whiteout_dir, nowlayer_dir): every step must be a real directory of this layer, and..is refused. A target through a symlink, or one that climbs out, is still refused withpath escapes the layer.linkatdoesn't follow a symlink target, so the link stays in the layer.hard link … to /…: No such file or directory, instead of tar-rs's barefailed to unpack.Tests
absolute_hard_link_is_read_from_the_layer_root:/bin/toollinks the layer'sbin/tool(same inode);/../../etc/hostname,/root/etc/hostname(withroot→/in the layer) and a missing target are refused, and nothing is linked.images: tag, save, load):load-hardlink-absoluteloads a one-layer image with the issue's link and reads/bin/tool-1.0withdocker cp;load-hardlink-escapechecks that/../../etc/hostnameis refused. The image comes fromtests/hardlink-image.py, the issue's script.mainae3467e:main, created here, and/bin/tool-1.0holds the file;//./bin/./tool: works;.., through a symlink, missing: refused;tests/e2e.sh, the same setup withmain's guest and with this one: the two new checks fail onmain(the issue's error) and pass here; the other results are the same on both, apart from one-off failures early in the run, on different tests each time. The failures common to both come from the throwaway test setup (no Finder mount, a credential helper that keeps no logins, a kernel without patches 0003 and 0005, a home outside/Users);cargo test -p kiri-init linux::layersas root: all pass butwhiteout_becomes_char_device, which needsmknodand fails the same way onmainin an unprivileged container;main, none inlayers.rs.Notes
cargo xtask guest)...in an absolute target is stricter than Docker, which cleans/a/../bto/bfirst. No image I know of writes that.