diff --git a/pkg/container/bubblewrap_runner.go b/pkg/container/bubblewrap_runner.go index 2cda0690d..576e23a11 100644 --- a/pkg/container/bubblewrap_runner.go +++ b/pkg/container/bubblewrap_runner.go @@ -16,6 +16,7 @@ package container import ( "archive/tar" + "bytes" "context" "fmt" "io" @@ -72,6 +73,27 @@ func (bw *bubblewrap) Run(ctx context.Context, cfg *Config, envOverride map[stri return execCmd.Run() } +func (bw *bubblewrap) testUnshareUser(ctx context.Context) error { + execCmd := exec.CommandContext(ctx, "bwrap", "--unshare-user", "true") + execCmd.Env = append(os.Environ(), "LANG=C") + out, err := execCmd.CombinedOutput() + if err == nil { + return nil + } + + if !bytes.Contains(out, []byte("setting up uid map")) { + return nil + } + + return fmt.Errorf("%s\n", + strings.Join([]string{ + "Unable to execute 'bwrap --unshare-user true'.", + "Command failed with: ", + " " + string(out), + "See https://github.com/chainguard-dev/melange/issues/1508 for fix", + }, "\n")) +} + func (bw *bubblewrap) cmd(ctx context.Context, cfg *Config, debug bool, envOverride map[string]string, args ...string) *exec.Cmd { baseargs := []string{} @@ -148,6 +170,11 @@ func (bw *bubblewrap) TestUsability(ctx context.Context) bool { return false } + if err := bw.testUnshareUser(ctx); err != nil { + log.Warnf("%s", err) + return false + } + return true }