Skip to content

Commit dc15065

Browse files
committed
[workspacekit] Establish IWS conn for proc mounts
1 parent 8aab84e commit dc15065

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

components/workspacekit/cmd/rings.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,10 @@ var ring1Cmd = &cobra.Command{
361361
log.WithError(err).Error("cannot connect to daemon")
362362
return
363363
}
364-
365364
_, err = client.MountProc(ctx, &daemonapi.MountProcRequest{
366365
Target: procLoc,
367366
Pid: int64(cmd.Process.Pid),
368367
})
369-
370368
client.Close()
371369

372370
if err != nil {
@@ -442,8 +440,10 @@ var ring1Cmd = &cobra.Command{
442440
log.Warn("received 0 as ring2 seccomp fd - syscall handling is broken")
443441
} else {
444442
handler := &seccomp.InWorkspaceHandler{
445-
FD: scmpfd,
446-
Daemon: client,
443+
FD: scmpfd,
444+
Daemon: func(ctx context.Context) (seccomp.InWorkspaceServiceClient, error) {
445+
return connectToInWorkspaceDaemonService(ctx)
446+
},
447447
Ring2PID: cmd.Process.Pid,
448448
Ring2Rootfs: ring2Root,
449449
BindEvents: make(chan seccomp.BindEvent),

components/workspacekit/pkg/seccomp/notify.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package seccomp
77
import (
88
"context"
99
"fmt"
10+
"io"
1011
"os"
1112
"path/filepath"
1213
"strconv"
@@ -168,10 +169,19 @@ func Errno(err unix.Errno) (val uint64, errno int32, flags uint32) {
168169
return ^uint64(0), int32(errno), 0
169170
}
170171

172+
// IWSClientProvider provides a client to the in-workspace-service.
173+
// Consumers of this provider will close the client after use.
174+
type IWSClientProvider func(ctx context.Context) (InWorkspaceServiceClient, error)
175+
176+
type InWorkspaceServiceClient interface {
177+
daemonapi.InWorkspaceServiceClient
178+
io.Closer
179+
}
180+
171181
// InWorkspaceHandler is the seccomp notification handler that serves a Gitpod workspace
172182
type InWorkspaceHandler struct {
173183
FD libseccomp.ScmpFd
174-
Daemon daemonapi.InWorkspaceServiceClient
184+
Daemon IWSClientProvider
175185
Ring2PID int
176186
Ring2Rootfs string
177187
BindEvents chan<- BindEvent
@@ -260,9 +270,16 @@ func (h *InWorkspaceHandler) Mount(req *libseccomp.ScmpNotifReq) (val uint64, er
260270

261271
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
262272
defer cancel()
263-
call := h.Daemon.MountProc
273+
iws, err := h.Daemon(ctx)
274+
if err != nil {
275+
log.WithField("target", target).WithField("dest", dest).WithField("mode", stat.Mode()).WithError(err).Errorf("cannot get IWS client to mount %s", filesystem)
276+
return Errno(unix.EFAULT)
277+
}
278+
defer iws.Close()
279+
280+
call := iws.MountProc
264281
if filesystem == "sysfs" {
265-
call = h.Daemon.MountSysfs
282+
call = iws.MountSysfs
266283
}
267284
_, err = call(ctx, &daemonapi.MountProcRequest{
268285
Target: dest,

0 commit comments

Comments
 (0)