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

set tracing socket path to runtime dir #4078

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion cmd/buildkitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,11 @@ func newController(c *cli.Context, cfg *config.Config) (*control.Controller, err

var traceSocket string
if tc != nil {
traceSocket = traceSocketPath(cfg.Root)
if v, ok := os.LookupEnv("BUILDKIT_TRACE_SOCKET"); ok {
traceSocket = v
} else {
traceSocket = appdefaults.TraceSocketPath(userns.RunningInUserNS())
}
if err := runTraceController(traceSocket, tc); err != nil {
return nil, err
}
Expand Down
5 changes: 0 additions & 5 deletions cmd/buildkitd/main_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/tls"
"net"
"os"
"path/filepath"
"syscall"

"github.com/containerd/containerd/sys"
Expand Down Expand Up @@ -47,10 +46,6 @@ func listenFD(addr string, tlsConfig *tls.Config) (net.Listener, error) {
return nil, errors.New("not supported yet")
}

func traceSocketPath(root string) string {
return filepath.Join(root, "otel-grpc.sock")
}

func getLocalListener(listenerPath string) (net.Listener, error) {
uid := os.Getuid()
l, err := sys.GetLocalListener(listenerPath, uid, uid)
Expand Down
8 changes: 0 additions & 8 deletions cmd/buildkitd/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@ import (
"github.com/pkg/errors"
)

const (
defaultTraceSocketPath = `\\.\pipe\buildkit-otel-grpc`
)

func listenFD(addr string, tlsConfig *tls.Config) (net.Listener, error) {
return nil, errors.New("listening server on fd not supported on windows")
}

func traceSocketPath(root string) string {
return defaultTraceSocketPath
}

func getLocalListener(listenerPath string) (net.Listener, error) {
pc := &winio.PipeConfig{
// Allow generic read and generic write access to authenticated users
Expand Down
10 changes: 10 additions & 0 deletions util/appdefaults/appdefaults_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ func UserConfigDir() string {
}
return ConfigDir
}

func TraceSocketPath(inUserNS bool) string {
if inUserNS {
if xrd := os.Getenv("XDG_RUNTIME_DIR"); xrd != "" {
dirs := strings.Split(xrd, ":")
return filepath.Join(dirs[0], "buildkit", "otel-grpc.sock")
}
}
return "/run/buildkit/otel-grpc.sock"
}
4 changes: 4 additions & 0 deletions util/appdefaults/appdefaults_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ func UserRoot() string {
func UserConfigDir() string {
return ConfigDir
}

func TraceSocketPath(inUserNS bool) string {
return `\\.\pipe\buildkit-otel-grpc`
}
4 changes: 2 additions & 2 deletions util/testutil/integration/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ disabled_plugins = ["cri"]
containerdArgs := []string{c.Containerd, "--config", configFile}
rootlessKitState := filepath.Join(tmpdir, "rootlesskit-containerd")
if rootless {
containerdArgs = append(append([]string{"sudo", "-u", fmt.Sprintf("#%d", c.UID), "-i",
containerdArgs = append(append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i",
fmt.Sprintf("CONTAINERD_ROOTLESS_ROOTLESSKIT_STATE_DIR=%s", rootlessKitState),
// Integration test requires the access to localhost of the host network namespace.
// TODO: remove these configurations
Expand Down Expand Up @@ -211,7 +211,7 @@ disabled_plugins = ["cri"]
if err != nil {
return nil, nil, err
}
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
buildkitdArgs = append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
"nsenter", "-U", "--preserve-credentials", "-m", "-t", fmt.Sprintf("%d", pid)},
append(buildkitdArgs, "--containerd-worker-snapshotter=native")...)
}
Expand Down
2 changes: 1 addition & 1 deletion util/testutil/integration/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *OCI) New(ctx context.Context, cfg *BackendConfig) (Backend, func() erro
return nil, nil, errors.Errorf("unsupported id pair: uid=%d, gid=%d", s.UID, s.GID)
}
// TODO: make sure the user exists and subuid/subgid are configured.
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
buildkitdArgs = append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crazy-max looks like this actually disables all the rootless tests 👀

See https://github.com/moby/buildkit/actions/runs/5749062460/job/15583230313:

time="2023-08-03T09:40:23Z" level=warning msg="rootless mode is not supported on this host: exit status 1 (sudo: you may not specify both the -i and -E options\nusage: sudo -h | -K | -k | -V\nusage: sudo -v [-ABkNnS] [-g group] [-h host] [-p prompt] [-u user]\nusage: sudo -l [-ABkNnS] [-g group] [-h host] [-p prompt] [-U user] [-u user]\n            [command [arg ...]]\nusage: sudo [-ABbEHkNnPS] [-C num] [-D directory] [-g group] [-h host] [-p\n            prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i | -s]\n            [command [arg ...]]\nusage: sudo -e [-ABkNnS] [-C num] [-D directory] [-g group] [-h host] [-p\n            prompt] [-R directory] [-T timeout] [-u user] file ...\n)"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes test step didn't failed 😕

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

var extraEnv []string
Expand Down
13 changes: 2 additions & 11 deletions util/testutil/integration/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -181,14 +180,6 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
}, cl, nil
}

func getBuildkitdAddr(tmpdir string) string {
address := "unix://" + filepath.Join(tmpdir, "buildkitd.sock")
if runtime.GOOS == "windows" {
address = "//./pipe/buildkitd-" + filepath.Base(tmpdir)
}
return address
}

func runBuildkitd(ctx context.Context, conf *BackendConfig, args []string, logs map[string]*bytes.Buffer, uid, gid int, extraEnv []string) (address string, cl func() error, err error) {
deferF := &multiCloser{}
cl = deferF.F()
Expand Down Expand Up @@ -224,7 +215,7 @@ func runBuildkitd(ctx context.Context, conf *BackendConfig, args []string, logs

args = append(args, "--root", tmpdir, "--addr", address, "--debug")
cmd := exec.Command(args[0], args[1:]...) //nolint:gosec // test utility
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "TMPDIR="+filepath.Join(tmpdir, "tmp"))
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "BUILDKIT_TRACE_SOCKET="+getTraceSocketPath(tmpdir), "TMPDIR="+filepath.Join(tmpdir, "tmp"))
cmd.Env = append(cmd.Env, extraEnv...)
cmd.SysProcAttr = getSysProcAttr()

Expand Down Expand Up @@ -269,7 +260,7 @@ func getBackend(sb Sandbox) (*backend, error) {
}

func rootlessSupported(uid int) bool {
cmd := exec.Command("sudo", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility
cmd := exec.Command("sudo", "-E", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility
b, err := cmd.CombinedOutput()
if err != nil {
bklog.L.Warnf("rootless mode is not supported on this host: %v (%s)", err, string(b))
Expand Down
13 changes: 12 additions & 1 deletion util/testutil/integration/sandbox_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@

package integration

import "syscall"
import (
"path/filepath"
"syscall"
)

func getSysProcAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{
Setsid: true, // stretch sudo needs this for sigterm
}
}

func getBuildkitdAddr(tmpdir string) string {
return "unix://" + filepath.Join(tmpdir, "buildkitd.sock")
}

func getTraceSocketPath(tmpdir string) string {
return filepath.Join(tmpdir, "otel-grpc.sock")
}
13 changes: 12 additions & 1 deletion util/testutil/integration/sandbox_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@

package integration

import "syscall"
import (
"path/filepath"
"syscall"
)

func getSysProcAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{}
}

func getBuildkitdAddr(tmpdir string) string {
return "//./pipe/buildkitd-" + filepath.Base(tmpdir)
}

func getTraceSocketPath(tmpdir string) string {
return `\\.\pipe\buildkit-otel-grpc-` + filepath.Base(tmpdir)
}