Skip to content

Commit e2337ff

Browse files
author
cl-ment
committed
feat(sandbox): insert __sandbox-helper verb in bwrap plan for self-exec binary
1 parent 0e1d8c3 commit e2337ff

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎internal/sandbox/linux_helper.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ func buildLinuxSandboxBwrapPlan(options LinuxSandboxBwrapOptions) (linuxSandboxB
213213
}
214214
}
215215
args = append(args, "--", helperPath)
216+
if filepath.Base(helperPath) != LinuxSandboxHelperName {
217+
args = append(args, "__sandbox-helper")
218+
}
216219
args = append(args, innerArgs...)
217220
return linuxSandboxBwrapPlan{
218221
Args: args,

‎internal/sandbox/linux_helper_test.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,23 @@ func TestFindLinuxSandboxHelperCommandSelfExec(t *testing.T) {
483483
}
484484
}
485485

486+
func TestBuildLinuxSandboxBwrapPlanSelfExecInsertsHelperVerb(t *testing.T) {
487+
plan, err := buildLinuxSandboxBwrapPlan(LinuxSandboxBwrapOptions{
488+
Config: LinuxSandboxHelperConfig{
489+
SandboxPolicyCWD: t.TempDir(),
490+
CommandCWD: t.TempDir(),
491+
Command: []string{"echo", "hello"},
492+
},
493+
HelperPath: "/usr/local/bin/zero",
494+
})
495+
if err != nil {
496+
t.Fatalf("buildLinuxSandboxBwrapPlan failed: %v", err)
497+
}
498+
if !argsContainSequence(plan.Args, "--", "/usr/local/bin/zero", "__sandbox-helper", "--sandbox-policy-cwd") {
499+
t.Fatalf("bwrap plan args missing __sandbox-helper after self-exec helperPath: %v", plan.Args)
500+
}
501+
}
502+
486503
func argsContainSequence(args []string, sequence ...string) bool {
487504
return argsSequenceIndex(args, sequence...) >= 0
488505
}

0 commit comments

Comments
 (0)