Skip to content

Commit 850645b

Browse files
committed
fix(platform): skip recursive chown in containers to avoid overlayfs exec race
PreserveOwnershipRecursive walks the freshly-extracted source tree and chowns every file from root to the original sudo user. On overlayfs (k3s Jenkins pods on Fedora CoreOS), each chown triggers a copy-up that can race with a subsequent execve, making the kernel return ENOEXEC on a perfectly valid '#!/bin/bash' script — observed as 'fork/exec .../configure: exec format error' a few ms into the build step. In containerised builds (YAP_IN_CONTAINER=1, baked into every yap image by build/deploy/generate.sh) the runtime user already owns the workspace end-to-end; the chown is pure overhead. Skip it there.
1 parent 9fa41a1 commit 850645b

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

pkg/platform/ownership.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,21 @@ func PreserveOwnership(path string) error {
155155
}
156156

157157
// PreserveOwnershipRecursive recursively changes ownership to original user if under sudo.
158+
//
159+
// In container environments (detected via YAP_IN_CONTAINER=1, baked into all
160+
// yap Docker images by build/deploy/generate.sh) the chown is skipped. The
161+
// container's runtime user is already the intended build user, so chowning the
162+
// source tree adds nothing and on overlayfs can trigger copy-up races that
163+
// cause execve() of freshly-chowned scripts to return ENOEXEC (observed in
164+
// k3s/Fedora CoreOS Jenkins pods).
158165
func PreserveOwnershipRecursive(path string) error {
166+
if os.Getenv("YAP_IN_CONTAINER") == "1" {
167+
logger.Debug("skipping recursive ownership preservation in container",
168+
"path", path)
169+
170+
return nil
171+
}
172+
159173
originalUser, err := GetOriginalUser()
160174
if err != nil {
161175
logger.Warn(i18n.T("logger.platform.warn.get_user"), "error", err)

0 commit comments

Comments
 (0)