Fix xattr copy failures on SELinux systems
Summary
- Fix xattr copy failures when copying buildkit-qemu-emulator on SELinux-enabled systems
- Add XAttrErrorHandler to ignore ENOTSUP errors during copy operation
Description
When copying the buildkit-qemu-emulator binary on systems with SELinux enabled, the copy operation fails with "operation not supported" errors when attempting to copy security.selinux xattrs.
This PR adds an XAttrErrorHandler to the copy.Copy call that ignores ENOTSUP errors, allowing the copy to succeed on SELinux-enabled systems.
Related Issues
Fixes #5544
Test plan
- [ ] Tested on SELinux-enabled system
- [ ] Existing tests pass
- [ ] No regression on non-SELinux systems
🤖 Generated with Claude Code
I won't be able to test this as I do not have time to build all the associated components I require. I am simply PR'ing the root cause of the issues I am having, and leaning on this project maintainers to get it merged.
Please squash the commits and also do some test on an SELinux-enabled host
(Just run go build ./cmd/buildkitd and overwrite the buildkitd binary on the host)
Testing Summary
Tested the fix for xattr copy failures on SELinux systems using the following approach:
Local Testing (macOS)
-
Unit tests: All tests pass, including the new
TestBinfmtXAttrErrorHandlertest that verifies:ENOTSUPerrors forsecurity.selinuxxattrs are ignoredENOTSUPerrors for other xattrs are propagated- Other errors for
security.selinuxare propagated - Security capabilities and other security xattrs are not affected
-
Built buildkitd binary: Successfully compiled for both macOS and Linux ARM64
SELinux Testing
Created a Lima VM with AlmaLinux 9 (minimal distro with SELinux enforcing by default) to reproduce the issue:
# Verified SELinux is enforcing
$ getenforce
Enforcing
# System has SELinux enabled with contexts
$ ls -Z /usr/local/bin/buildkit-qemu-x86_64
unconfined_u:object_r:bin_t:s0 /usr/local/bin/buildkit-qemu-x86_64
Comparison Test Results
Without the fix (unpatched):
-
Would fail with "operation not supported" when copying QEMU emulator binaries to tmpfs
-
This is the exact error reported in issue #5544:
failed to copy xattrs: failed to set xattr "security.selinux" on /tmp/buildkit-qemu-emulator538849571/dev/.buildkit_qemu_emulator: operation not supported
With the fix (patched):
- ✅ BuildKit starts successfully with OCI worker
- ✅ No xattr-related errors in logs
- ✅ The
ignoreSELinuxXAttrErrorHandlercorrectly handlesENOTSUPerrors forsecurity.selinuxattributes
Why the Fix Works
The issue occurs when BuildKit copies QEMU emulator binaries to /tmp (tmpfs filesystem), which doesn't support SELinux extended attributes. The fix adds an XAttrErrorHandler that specifically ignores ENOTSUP errors for security.selinux attributes, allowing the copy to succeed while preserving all other xattr handling.
The change is minimal and targeted - it only affects this specific error case without impacting other xattr operations or security attributes.
This was approved 2 weeks ago. What stands in the way of it being merged?
This was approved 2 weeks ago. What stands in the way of it being merged?
The merge button.