Skip to content

Commit

Permalink
Chrooted executor (#711)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Scherba <[email protected]>
  • Loading branch information
miklezzzz authored Feb 5, 2025
1 parent 3ff5dae commit f632bb6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ func (e *Executor) WithLogger(logger *log.Logger) *Executor {
return e
}

func (e *Executor) WithChroot(path string) *Executor {
if len(path) > 0 {
e.cmd.SysProcAttr = &syscall.SysProcAttr{
Chroot: path,
}
e.cmd.Path = strings.TrimPrefix(e.cmd.Path, path)
e.cmd.Dir = "/"
}

return e
}

func (e *Executor) WithCMDStdout(w io.Writer) *Executor {
e.cmd.Stdout = w

Expand Down
5 changes: 2 additions & 3 deletions pkg/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ func TestRunAndLogLines(t *testing.T) {
_, err := ex.RunAndLogLines(map[string]string{"a": "b"})
assert.NoError(t, err)

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"+
`{"level":"info","msg":"[\"a\",\"b\",\"c\"]\n","source":"executor/executor.go:180","a":"b","output":"stdout","time":"2006-01-02T15:04:05Z"}`+"\n")

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"+
`{"level":"info","msg":"[\"a\",\"b\",\"c\"]\n","source":"executor/executor.go:192","a":"b","output":"stdout","time":"2006-01-02T15:04:05Z"}`+"\n")
buf.Reset()
})

Expand Down

0 comments on commit f632bb6

Please sign in to comment.