Skip to content

Commit f632bb6

Browse files
authored
Chrooted executor (#711)
Signed-off-by: Mikhail Scherba <[email protected]>
1 parent 3ff5dae commit f632bb6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pkg/executor/executor.go

+12
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ func (e *Executor) WithLogger(logger *log.Logger) *Executor {
5555
return e
5656
}
5757

58+
func (e *Executor) WithChroot(path string) *Executor {
59+
if len(path) > 0 {
60+
e.cmd.SysProcAttr = &syscall.SysProcAttr{
61+
Chroot: path,
62+
}
63+
e.cmd.Path = strings.TrimPrefix(e.cmd.Path, path)
64+
e.cmd.Dir = "/"
65+
}
66+
67+
return e
68+
}
69+
5870
func (e *Executor) WithCMDStdout(w io.Writer) *Executor {
5971
e.cmd.Stdout = w
6072

pkg/executor/executor_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ func TestRunAndLogLines(t *testing.T) {
107107
_, err := ex.RunAndLogLines(map[string]string{"a": "b"})
108108
assert.NoError(t, err)
109109

110-
assert.Equal(t, buf.String(), `{"level":"debug","msg":"json log line not map[string]interface{}","source":"executor/executor.go:177","a":"b","line":["a","b","c"],"output":"stdout","time":"2006-01-02T15:04:05Z"}`+"\n"+
111-
`{"level":"info","msg":"[\"a\",\"b\",\"c\"]\n","source":"executor/executor.go:180","a":"b","output":"stdout","time":"2006-01-02T15:04:05Z"}`+"\n")
112-
110+
assert.Equal(t, buf.String(), `{"level":"debug","msg":"json log line not map[string]interface{}","source":"executor/executor.go:189","a":"b","line":["a","b","c"],"output":"stdout","time":"2006-01-02T15:04:05Z"}`+"\n"+
111+
`{"level":"info","msg":"[\"a\",\"b\",\"c\"]\n","source":"executor/executor.go:192","a":"b","output":"stdout","time":"2006-01-02T15:04:05Z"}`+"\n")
113112
buf.Reset()
114113
})
115114

0 commit comments

Comments
 (0)