mirror of
https://github.com/moby/buildkit.git
synced 2026-08-09 17:18:11 +00:00
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 change adds an XAttrErrorHandler to the copy.Copy call that ignores ENOTSUP errors, allowing the copy to succeed on SELinux-enabled systems. Fixes #5544 🤖 Generated with [Claude Code](https://claude.ai/code) Signed-off-by: Tiger Kaovilai <passawit.kaovilai@gmail.com> Refactor xattr error handler to be a simple function Changed ignoreSELinuxXAttrErrorHandler from a function that returns a function to a direct error handler function. This simplifies the code while maintaining the same functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Signed-off-by: Tiger Kaovilai <passawit.kaovilai@gmail.com> Add tests for xattr error handling in exec_binfmt Signed-off-by: Tiger Kaovilai <passawit.kaovilai@gmail.com> Update xattr error handling to ignore ENOTSUP for security.selinux only Signed-off-by: Tiger Kaovilai <passawit.kaovilai@gmail.com> Refactor xattr error handling in exec_binfmt to use a single error handler function Signed-off-by: Tiger Kaovilai <passawit.kaovilai@gmail.com> Co-Authored-By: Claude <noreply@anthropic.com>
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package ops
|
|
|
|
import (
|
|
"syscall"
|
|
"testing"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestBinfmtXAttrErrorHandler(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dst string
|
|
src string
|
|
xattrKey string
|
|
inputErr error
|
|
expectErr bool
|
|
description string
|
|
}{
|
|
{
|
|
name: "ENOTSUP_security_selinux_ignored",
|
|
dst: "/tmp/dest",
|
|
src: "/tmp/src",
|
|
xattrKey: "security.selinux",
|
|
inputErr: syscall.ENOTSUP,
|
|
expectErr: false,
|
|
description: "ENOTSUP error for security.selinux should be ignored",
|
|
},
|
|
{
|
|
name: "ENOTSUP_other_xattr_propagated",
|
|
dst: "/tmp/dest",
|
|
src: "/tmp/src",
|
|
xattrKey: "user.some_attr",
|
|
inputErr: syscall.ENOTSUP,
|
|
expectErr: true,
|
|
description: "ENOTSUP error for non-selinux xattr should propagate",
|
|
},
|
|
{
|
|
name: "ENOTSUP_security_capability_propagated",
|
|
dst: "/tmp/dest",
|
|
src: "/tmp/src",
|
|
xattrKey: "security.capability",
|
|
inputErr: syscall.ENOTSUP,
|
|
expectErr: true,
|
|
description: "ENOTSUP error for other security xattr should propagate",
|
|
},
|
|
{
|
|
name: "other_error_security_selinux_propagated",
|
|
dst: "/tmp/dest",
|
|
src: "/tmp/src",
|
|
xattrKey: "security.selinux",
|
|
inputErr: syscall.EPERM,
|
|
expectErr: true,
|
|
description: "Non-ENOTSUP errors should always propagate",
|
|
},
|
|
{
|
|
name: "wrapped_ENOTSUP_error_handled",
|
|
dst: "/tmp/dest",
|
|
src: "/tmp/src",
|
|
xattrKey: "security.selinux",
|
|
inputErr: errors.Wrap(syscall.ENOTSUP, "wrapped error"),
|
|
expectErr: false,
|
|
description: "Wrapped ENOTSUP errors should be handled with errors.Is",
|
|
},
|
|
{
|
|
name: "nil_error_returns_nil",
|
|
dst: "/tmp/dest",
|
|
src: "/tmp/src",
|
|
xattrKey: "security.selinux",
|
|
inputErr: nil,
|
|
expectErr: false,
|
|
description: "Nil error should return nil",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
result := ignoreSELinuxXAttrErrorHandler(tt.dst, tt.src, tt.xattrKey, tt.inputErr)
|
|
|
|
if tt.expectErr {
|
|
require.Error(t, result, tt.description)
|
|
require.Equal(t, tt.inputErr, result, "Error should be propagated unchanged")
|
|
} else {
|
|
require.NoError(t, result, tt.description)
|
|
}
|
|
})
|
|
}
|
|
}
|