@@ -13,12 +13,14 @@ import (
1313 "net/url"
1414 "os"
1515 "os/exec"
16+ "os/user"
1617 "path"
1718 "path/filepath"
1819 "reflect"
1920 "regexp"
2021 "strconv"
2122 "strings"
23+ "syscall"
2224
2325 "github.com/google/go-github/github"
2426 "github.com/gorilla/securecookie"
@@ -151,6 +153,11 @@ type ConfigLog struct {
151153 Events * EventLogType `json:"events,omitempty"`
152154}
153155
156+ type ConfigProcess struct {
157+ User string `json:"user,omitempty" env:"SEMAPHORE_PROCESS_USER"`
158+ Chroot string `json:"chroot,omitempty" env:"SEMAPHORE_PROCESS_CHROOT"`
159+ }
160+
154161// ConfigType mapping between Config and the json file that sets it
155162type ConfigType struct {
156163 MySQL * DbConfig `json:"mysql,omitempty"`
@@ -252,6 +259,8 @@ type ConfigType struct {
252259 ForwardedEnvVars []string `json:"forwarded_env_vars,omitempty" env:"SEMAPHORE_FORWARDED_ENV_VARS"`
253260
254261 Log * ConfigLog `json:"log,omitempty"`
262+
263+ Process * ConfigProcess `json:"process,omitempty"`
255264}
256265
257266func NewConfigType () * ConfigType {
@@ -299,6 +308,35 @@ func ClearDir(dir string, preserveFiles bool, prefix string) error {
299308 return nil
300309}
301310
311+ func (conf * ConfigType ) GetSysProcAttr () (res * syscall.SysProcAttr ) {
312+
313+ if conf .Process .Chroot != "" {
314+ res = & syscall.SysProcAttr {}
315+ res .Chroot = conf .Process .Chroot
316+ }
317+
318+ if conf .Process .User != "" {
319+ if res == nil {
320+ res = & syscall.SysProcAttr {}
321+ }
322+
323+ u , err := user .Lookup (conf .Process .User )
324+ if err != nil {
325+ return
326+ }
327+
328+ uid , _ := strconv .Atoi (u .Uid )
329+ gid , _ := strconv .Atoi (u .Gid )
330+
331+ res .Credential = & syscall.Credential {
332+ Uid : uint32 (uid ),
333+ Gid : uint32 (gid ),
334+ }
335+ }
336+
337+ return
338+ }
339+
302340func (conf * ConfigType ) ClearTmpDir () error {
303341 return ClearDir (conf .TmpPath , false , "" )
304342}
0 commit comments