Skip to content

Commit 231caa6

Browse files
committed
[executor] Explicitly set additional GIDs when running as custom user
1 parent f30fe1e commit 231caa6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

executor/executable/task.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func prepareTaskCmd(commandInfo *common.TaskCommandInfo) (*exec.Cmd, error) {
136136
// We must setpgid(2) in order to be able to kill the whole process group which consists of
137137
// the containing shell and all of its children
138138
taskCmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
139+
taskCmd.SysProcAttr.Pdeathsig = syscall.SIGKILL
139140

140141
// If the commandInfo specifies a username
141142
if commandInfo.User != nil && len(*commandInfo.User) > 0 {
@@ -154,11 +155,36 @@ func prepareTaskCmd(commandInfo *common.TaskCommandInfo) (*exec.Cmd, error) {
154155
return nil, err
155156
}
156157

158+
gidStrings, err := targetUser.GroupIds()
159+
if err != nil {
160+
return nil, err
161+
}
162+
163+
gids := make([]uint32, len(gidStrings))
164+
for i, v := range gidStrings {
165+
parsed, err := strconv.ParseUint(v, 10, 32)
166+
if err != nil {
167+
return nil, err
168+
}
169+
gids[i] = uint32(parsed)
170+
}
171+
157172
credential := &syscall.Credential{
158173
Uid: uint32(uid),
159174
Gid: uint32(gid),
175+
Groups: gids,
176+
NoSetGroups: false,
160177
}
161178
taskCmd.SysProcAttr.Credential = credential
179+
log.WithFields(logrus.Fields{
180+
"shell": *commandInfo.Shell,
181+
"value": *commandInfo.Value,
182+
"args": commandInfo.Arguments,
183+
"uid": credential.Uid,
184+
"gid": credential.Gid,
185+
"groups": gidStrings,
186+
}).
187+
Debug("custom credentials set")
162188
}
163189

164190
return taskCmd, nil

0 commit comments

Comments
 (0)