fix: preserve binary file caps through Kaniko multi-stage COPY #55
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/preserve-file-capabilities"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #54.
Problem
Kaniko strips the
security.capabilityxattr when it executesCOPY --chownin a multi-stage build, so every image the new daemonless workflow pushed has been missingcap_net_adminandcap_net_bind_serviceon the relay binary. The container then crash-loops at startup with:This only surfaced now because the previous deploys to rly.best loaded a locally-built image (BuildKit, which preserves xattrs through
COPY --chown) rather than the registry one. The first attempt to deploy the registry-pushedv2.1.8+rs.1-arm64image hit the crash loop and was rolled back.Fix
Move
setcapout of the build stage and into a newcapstampintermediate stage that only depends onlibcap2-bin. The distroless final stage then pulls the cap-stamped binary in via a plainCOPY(no--chown):Key choices:
--chown=65532:65532. Linux file caps are uid-independent and distrolessnonrootruns the binary as 65532 regardless of file owner. Removing--chownis what sidesteps the Kaniko xattr strip.capstampruns onBUILDPLATFORM.setcaponly writes a filesystem xattr; it never executes the target-arch binary, so the stage does not need QEMU.libcap2-binis removed from the build stage, since it no longer runs setcap.Validation
cargo fmt --checkclean.cargo test --locked -p portal-relay86 passed, 3 ignored.cargo clippy --locked --all-targets -- -D warningsclean.Local BuildKit build of an equivalent multi-stage Dockerfile, then extracting
/usr/local/bin/portal-relayfrom the final image withsudo docker cp(to preserve xattrs on the host filesystem):i.e. caps survive the multi-stage plain COPY into distroless.
This PR does not address #53 (amd64 build still failing in CI). After this PR is merged we will deploy the cap-fixed arm64 image to rly.best as a stopgap, then continue with #53 to unblock the proper multi-arch v2.1.8+rs.1 release.