@@ -7,6 +7,7 @@ package seccomp
7
7
import (
8
8
"context"
9
9
"fmt"
10
+ "io"
10
11
"os"
11
12
"path/filepath"
12
13
"strconv"
@@ -168,10 +169,19 @@ func Errno(err unix.Errno) (val uint64, errno int32, flags uint32) {
168
169
return ^ uint64 (0 ), int32 (errno ), 0
169
170
}
170
171
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
+
171
181
// InWorkspaceHandler is the seccomp notification handler that serves a Gitpod workspace
172
182
type InWorkspaceHandler struct {
173
183
FD libseccomp.ScmpFd
174
- Daemon daemonapi. InWorkspaceServiceClient
184
+ Daemon IWSClientProvider
175
185
Ring2PID int
176
186
Ring2Rootfs string
177
187
BindEvents chan <- BindEvent
@@ -260,9 +270,16 @@ func (h *InWorkspaceHandler) Mount(req *libseccomp.ScmpNotifReq) (val uint64, er
260
270
261
271
ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
262
272
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
264
281
if filesystem == "sysfs" {
265
- call = h . Daemon .MountSysfs
282
+ call = iws .MountSysfs
266
283
}
267
284
_ , err = call (ctx , & daemonapi.MountProcRequest {
268
285
Target : dest ,
0 commit comments