Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give a pointer to solution if bubblewrap runner cannot use user namespace #1628

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/container/bubblewrap_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package container

import (
"archive/tar"
"bytes"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -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{}

Expand Down Expand Up @@ -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
}

Expand Down
Loading