Skip to content

Commit c26b6b8

Browse files
committed
[supervisor] add ptrace cap for all child process
1 parent f7a95c2 commit c26b6b8

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

components/supervisor/pkg/supervisor/ssh.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"path/filepath"
1616
"strings"
1717

18+
"golang.org/x/sys/unix"
1819
"golang.org/x/xerrors"
1920

2021
"github.com/gitpod-io/gitpod/common-go/log"
@@ -170,6 +171,7 @@ func (s *sshServer) handleConn(ctx context.Context, conn net.Conn) {
170171
cmd.Env = s.envvars
171172
cmd.ExtraFiles = []*os.File{socketFD}
172173
cmd.Stderr = os.Stderr
174+
cmd.SysProcAttr.AmbientCaps = append(cmd.SysProcAttr.AmbientCaps, unix.CAP_SYS_PTRACE)
173175
if s.cfg.WorkspaceLogRateLimit > 0 {
174176
limit := int64(s.cfg.WorkspaceLogRateLimit)
175177
cmd.Stderr = dropwriter.Writer(cmd.Stderr, dropwriter.NewBucket(limit*1024*3, limit*1024))

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/prometheus/common/route"
4343
"github.com/soheilhy/cmux"
4444
"golang.org/x/crypto/ssh"
45+
"golang.org/x/sys/unix"
4546
"golang.org/x/xerrors"
4647
"google.golang.org/grpc"
4748
"google.golang.org/grpc/codes"
@@ -356,6 +357,9 @@ func Run(options ...RunOption) {
356357
Uid: gitpodUID,
357358
Gid: gitpodGID,
358359
}
360+
if !cfg.isHeadless() {
361+
termMuxSrv.DefaultAmbientCaps = append(termMuxSrv.DefaultAmbientCaps, unix.CAP_SYS_PTRACE)
362+
}
359363

360364
taskManager := newTasksManager(cfg, termMuxSrv, cstate, nil, ideReady, desktopIdeReady)
361365

@@ -1036,6 +1040,8 @@ func prepareIDELaunch(cfg *Config, ideConfig *IDEConfig) *exec.Cmd {
10361040
cmd.SysProcAttr.Setpgid = true
10371041
cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL
10381042

1043+
cmd.SysProcAttr.AmbientCaps = append(cmd.SysProcAttr.AmbientCaps, unix.CAP_SYS_PTRACE)
1044+
10391045
// Here we must resist the temptation to "neaten up" the IDE output for headless builds.
10401046
// This would break the JSON parsing of the headless builds.
10411047
cmd.Stdout = os.Stdout

components/supervisor/pkg/terminal/service.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ type MuxTerminalService struct {
4848
// if returns empty string then DefaultWorkdir is used
4949
DefaultWorkdirProvider func() string
5050

51-
DefaultShell string
52-
Env []string
53-
DefaultCreds *syscall.Credential
51+
DefaultShell string
52+
Env []string
53+
DefaultCreds *syscall.Credential
54+
DefaultAmbientCaps []uintptr
5455

5556
api.UnimplementedTerminalServiceServer
5657
}
@@ -109,6 +110,14 @@ func (srv *MuxTerminalService) OpenWithOptions(ctx context.Context, req *api.Ope
109110
Y: uint16(req.Size.HeightPx),
110111
}
111112
}
113+
114+
if srv.DefaultAmbientCaps != nil {
115+
if cmd.SysProcAttr == nil {
116+
cmd.SysProcAttr = &syscall.SysProcAttr{}
117+
}
118+
cmd.SysProcAttr.AmbientCaps = srv.DefaultAmbientCaps
119+
}
120+
112121
alias, err := srv.Mux.Start(cmd, options)
113122
if err != nil {
114123
return nil, status.Error(codes.Internal, err.Error())

0 commit comments

Comments
 (0)