Skip to content

Commit b57eeb2

Browse files
committed
integration: preserve existing environment variables when using sudo
Signed-off-by: CrazyMax <[email protected]>
1 parent a7690c5 commit b57eeb2

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

util/testutil/integration/containerd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ disabled_plugins = ["cri"]
168168
containerdArgs := []string{c.Containerd, "--config", configFile}
169169
rootlessKitState := filepath.Join(tmpdir, "rootlesskit-containerd")
170170
if rootless {
171-
containerdArgs = append(append([]string{"sudo", "-u", fmt.Sprintf("#%d", c.UID), "-i",
171+
containerdArgs = append(append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i",
172172
fmt.Sprintf("CONTAINERD_ROOTLESS_ROOTLESSKIT_STATE_DIR=%s", rootlessKitState),
173173
// Integration test requires the access to localhost of the host network namespace.
174174
// TODO: remove these configurations
@@ -211,7 +211,7 @@ disabled_plugins = ["cri"]
211211
if err != nil {
212212
return nil, nil, err
213213
}
214-
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
214+
buildkitdArgs = append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", c.UID), "-i", "--", "exec",
215215
"nsenter", "-U", "--preserve-credentials", "-m", "-t", fmt.Sprintf("%d", pid)},
216216
append(buildkitdArgs, "--containerd-worker-snapshotter=native")...)
217217
}

util/testutil/integration/oci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *OCI) New(ctx context.Context, cfg *BackendConfig) (Backend, func() erro
6565
return nil, nil, errors.Errorf("unsupported id pair: uid=%d, gid=%d", s.UID, s.GID)
6666
}
6767
// TODO: make sure the user exists and subuid/subgid are configured.
68-
buildkitdArgs = append([]string{"sudo", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
68+
buildkitdArgs = append([]string{"sudo", "-E", "-u", fmt.Sprintf("#%d", s.UID), "-i", "--", "exec", "rootlesskit"}, buildkitdArgs...)
6969
}
7070

7171
var extraEnv []string

util/testutil/integration/sandbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func getBackend(sb Sandbox) (*backend, error) {
260260
}
261261

262262
func rootlessSupported(uid int) bool {
263-
cmd := exec.Command("sudo", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility
263+
cmd := exec.Command("sudo", "-E", "-u", fmt.Sprintf("#%d", uid), "-i", "--", "exec", "unshare", "-U", "true") //nolint:gosec // test utility
264264
b, err := cmd.CombinedOutput()
265265
if err != nil {
266266
bklog.L.Warnf("rootless mode is not supported on this host: %v (%s)", err, string(b))

0 commit comments

Comments
 (0)