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

integration: fix rootless tests #4101

Merged
merged 2 commits into from
Aug 7, 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: 6 additions & 0 deletions cmd/buildkitd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Config struct {
// GRPC configuration settings
GRPC GRPCConfig `toml:"grpc"`

OTEL OTELConfig `toml:"otel"`

Workers struct {
OCI OCIConfig `toml:"oci"`
Containerd ContainerdConfig `toml:"containerd"`
Expand Down Expand Up @@ -46,6 +48,10 @@ type TLSConfig struct {
CA string `toml:"ca"`
}

type OTELConfig struct {
SocketPath string `toml:"socketPath"`
}

type GCConfig struct {
GC *bool `toml:"gc"`
GCKeepStorage DiskSpace `toml:"gckeepstorage"`
Expand Down
6 changes: 5 additions & 1 deletion cmd/buildkitd/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ insecure-entitlements = ["security.insecure"]
[gc]
enabled=true


[grpc]
address=["buildkit.sock"]
debugAddress="debug.sock"
gid=1234
[grpc.tls]
cert="mycert.pem"

[otel]
socketPath="/tmp/otel-grpc.sock"

[worker.oci]
enabled=true
snapshotter="overlay"
Expand Down Expand Up @@ -83,6 +85,8 @@ searchDomains=["example.com"]
require.Equal(t, 1234, *cfg.GRPC.GID)
require.Equal(t, "mycert.pem", cfg.GRPC.TLS.Cert)

require.Equal(t, "/tmp/otel-grpc.sock", cfg.OTEL.SocketPath)

require.NotNil(t, cfg.Workers.OCI.Enabled)
require.Equal(t, int64(123456789), cfg.Workers.OCI.GCKeepStorage.Bytes)
require.Equal(t, true, *cfg.Workers.OCI.Enabled)
Expand Down
19 changes: 14 additions & 5 deletions cmd/buildkitd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func main() {
Name: "allow-insecure-entitlement",
Usage: "allows insecure entitlements e.g. network.host, security.insecure",
},
cli.StringFlag{
Name: "otel-socket-path",
Usage: "OTEL collector trace socket path",
},
)
app.Flags = append(app.Flags, appFlags...)
app.Flags = append(app.Flags, serviceFlags()...)
Expand Down Expand Up @@ -458,6 +462,10 @@ func setDefaultConfig(cfg *config.Config) {
appdefaults.EnsureUserAddressDir()
}
}

if cfg.OTEL.SocketPath == "" {
cfg.OTEL.SocketPath = appdefaults.TraceSocketPath(userns.RunningInUserNS())
}
}

func applyMainFlags(c *cli.Context, cfg *config.Config) error {
Expand Down Expand Up @@ -511,6 +519,11 @@ func applyMainFlags(c *cli.Context, cfg *config.Config) error {
if tlsca := c.String("tlscacert"); tlsca != "" {
cfg.GRPC.TLS.CA = tlsca
}

if c.IsSet("otel-socket-path") {
cfg.OTEL.SocketPath = c.String("otel-socket-path")
}

applyPlatformFlags(c)

return nil
Expand Down Expand Up @@ -661,11 +674,7 @@ func newController(c *cli.Context, cfg *config.Config) (*control.Controller, err

var traceSocket string
if tc != nil {
if v, ok := os.LookupEnv("BUILDKIT_TRACE_SOCKET"); ok {
traceSocket = v
} else {
traceSocket = appdefaults.TraceSocketPath(userns.RunningInUserNS())
}
traceSocket = cfg.OTEL.SocketPath
if err := runTraceController(traceSocket, tc); err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions docs/buildkitd.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
key = "/etc/buildkit/tls.key"
ca = "/etc/buildkit/tlsca.crt"

[otel]
# OTEL collector trace socket path
socketPath = "/run/buildkit/otel-grpc.sock"

# config for build history API that stores information about completed build commands
[history]
# maxAge is the maximum age of history entries to keep, in seconds.
Expand Down
2 changes: 1 addition & 1 deletion util/testutil/integration/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func newSandbox(ctx context.Context, w Worker, mirror string, mv matrixValue) (s
}

func RootlessSupported(uid int) bool {
cmd := exec.Command("sudo", "-E", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility
cmd := exec.Command("sudo", "-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
4 changes: 2 additions & 2 deletions util/testutil/workers/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", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i",
containerdArgs = append(append([]string{"sudo", "-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", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
buildkitdArgs = append([]string{"sudo", "-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/workers/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *OCI) New(ctx context.Context, cfg *integration.BackendConfig) (integrat
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", "-E", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
}

var extraEnv []string
Expand Down
4 changes: 2 additions & 2 deletions util/testutil/workers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func runBuildkitd(ctx context.Context, conf *integration.BackendConfig, args []s

address = getBuildkitdAddr(tmpdir)

args = append(args, "--root", tmpdir, "--addr", address, "--debug")
args = append(args, "--root", tmpdir, "--addr", address, "--otel-socket-path", getTraceSocketPath(tmpdir), "--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", "BUILDKIT_TRACE_SOCKET="+getTraceSocketPath(tmpdir), "TMPDIR="+filepath.Join(tmpdir, "tmp"))
cmd.Env = append(os.Environ(), "BUILDKIT_DEBUG_EXEC_OUTPUT=1", "BUILDKIT_DEBUG_PANIC_ON_ERROR=1", "TMPDIR="+filepath.Join(tmpdir, "tmp"))
cmd.Env = append(cmd.Env, extraEnv...)
cmd.SysProcAttr = getSysProcAttr()

Expand Down