remove go-archive and bound ADD archive extraction - #7034
Conversation
| {0x42, 0x5A, 0x68}, // bzip2 | ||
| {0x1F, 0x8B, 0x08}, // gzip | ||
| {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00}, // xz | ||
| {0x28, 0xB5, 0x2F, 0xFD}, // zstd |
There was a problem hiding this comment.
I added zstd to this archive sniffing list because the previous go-archive decompression path already supported zstd archives. Without this magic value, the new decompression helper can handle zstd, but HTTP context archive detection would still fail to classify zstd-compressed tar streams as archives.
a91199d to
f77f604
Compare
This removes github.com/moby/go-archive from Dockerfile ADD extraction and archive probing. Extraction now uses containerd's archive.Apply, with a small local decompression helper for Docker-compatible formats while preserving whiteout and ownership mapping behavior. Tests cover symlink and hardlink escape attempts around the extraction root so this does not regress the confinement expected from the old chrootarchive path. Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
f77f604 to
467d8c1
Compare
| GID: u.GID, | ||
| opts = append(opts, unpackPlatformApplyOpts()...) | ||
|
|
||
| _, err = archive.Apply(ctx, dest, rdr, opts...) |
There was a problem hiding this comment.
Hum it doesn't perform extraction inside a chroot 🙈. It relies on archive path validation and guarded filesystem operations instead. Given that this code handles user-provided Dockerfile ADD archives, an explicit extraction-root boundary here would be needed so symlinks, hardlinks, absolute paths, or .. paths cannot write outside the destination.
There was a problem hiding this comment.
So I guess best is to still rely on go-archive or extract through os.Root ourselves.
8f8a223 to
f58b77c
Compare
Replace direct containerd archive application in the Dockerfile ADD unpack path with a local tar extractor that opens the destination through os.Root. This keeps extraction operations scoped to the destination root while preserving regular files, directories, symlinks, hardlinks, whiteout files, ownership mapping, and Windows no-owner behavior. Add coverage for parent-directory paths, Windows volume paths, hardlinks outside the destination, and symlink traversal through both archive-created and preexisting symlinks. Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
f58b77c to
0bad7f4
Compare
closes #6965
closes #6964
This removes
github.com/moby/go-archivefrom DockerfileADDarchive handling instead of updating the vendored module. Archive probing now uses a small local decompression helper for Docker-compatible gzip, bzip2, xz, zstd, and uncompressed tar streams, while extraction preserves the existing ownership mapping, whiteout-file behavior, and Windows no-owner behavior.The extraction path is intentionally not just a direct replacement with containerd
archive.Apply, because that doesn't recreate the oldchrootarchive.Untarboundary.ADDarchives are now extracted throughos.Rootso archive paths, hardlinks, archive-created symlinks, and preexisting symlinks cannot write outside the destination root, which keeps the replacement aligned with the escape class described in GHSA-hfg8-hc9c-6c3h.