Skip to content

Commit ef66ca1

Browse files
author
Christian Weichel
committed
[supervisor] execve into ring3
1 parent 2918771 commit ef66ca1

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

components/supervisor/BUILD.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ packages:
1818
config:
1919
buildFlags:
2020
- "-ldflags=-w"
21+
# build with >= go1.16beta1 to make libcap work without CGO. See
22+
# - https://pkg.go.dev/kernel.org/pub/linux/libs/security/libcap/cap, search for allthreadssyscall
23+
# - https://github.com/golang/go/issues/1435
24+
goVersion: go1.16beta1
2125
- name: docker
2226
type: docker
2327
srcs:

components/supervisor/cmd/rings.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
sigproxysignal "github.com/rootless-containers/rootlesskit/pkg/sigproxy/signal"
2525
"github.com/spf13/cobra"
2626
"golang.org/x/sys/unix"
27+
"kernel.org/pub/linux/libs/security/libcap/cap"
2728
)
2829

2930
const (
@@ -364,29 +365,21 @@ var ring2Cmd = &cobra.Command{
364365
return
365366
}
366367

367-
cmd := exec.Command("/proc/self/exe", "run", "--inns")
368-
cmd.SysProcAttr = &syscall.SysProcAttr{
369-
Pdeathsig: syscall.SIGKILL,
370-
Credential: &syscall.Credential{
371-
Uid: 33333,
372-
Gid: 33333,
373-
},
368+
err = cap.SetGroups(33333)
369+
if err != nil {
370+
log.WithError(err).Error("cannot setgid")
371+
failed = true
372+
return
374373
}
375-
cmd.Stdin = os.Stdin
376-
cmd.Stdout = os.Stdout
377-
cmd.Stderr = os.Stderr
378-
cmd.Env = os.Environ()
379-
if err := cmd.Start(); err != nil {
380-
log.WithError(err).Error("failed to start the child process")
374+
err = cap.SetUID(33333)
375+
if err != nil {
376+
log.WithError(err).Error("cannot setuid")
381377
failed = true
382378
return
383379
}
384-
sigc := sigproxy.ForwardAllSignals(context.Background(), cmd.Process.Pid)
385-
defer sigproxysignal.StopCatch(sigc)
386-
387-
err = cmd.Wait()
380+
err = unix.Exec("/proc/self/exe", []string{"supervisor", "run", "--inns"}, os.Environ())
388381
if err != nil {
389-
log.WithError(err).Error("unexpected exit")
382+
log.WithError(err).Error("cannot exec")
390383
failed = true
391384
return
392385
}

components/supervisor/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
2929
google.golang.org/grpc v1.34.0
3030
google.golang.org/grpc/examples v0.0.0-20200902210233-8630cac324bf // indirect
31+
kernel.org/pub/linux/libs/security/libcap/cap v0.2.46
3132
)
3233

3334
replace github.com/gitpod-io/gitpod/common-go => ../common-go // leeway

components/supervisor/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,10 @@ k8s.io/klog v0.3.1/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
724724
k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
725725
k8s.io/utils v0.0.0-20190221042446-c2654d5206da/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0=
726726
k8s.io/utils v0.0.0-20191030222137-2b95a09bc58d/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
727+
kernel.org/pub/linux/libs/security/libcap/cap v0.2.46 h1:2my+JWsYxD0mFKUbqgtEf7r9A0m/fCMUv21RGgknTiU=
728+
kernel.org/pub/linux/libs/security/libcap/cap v0.2.46/go.mod h1:Xni6/5rCuzPoHAac5sCFMuDxz9FuI8GTUyQ4qlw3e0w=
729+
kernel.org/pub/linux/libs/security/libcap/psx v0.2.46 h1:9GvXrCSQAcgQ3zZVxRN8K866o1aAY1DYdXj0vHIHvYA=
730+
kernel.org/pub/linux/libs/security/libcap/psx v0.2.46/go.mod h1:+l6Ee2F59XiJ2I6WR5ObpC1utCQJZ/VLsEbQCD8RG24=
727731
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
728732
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
729733
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

components/ws-daemon/go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
397397
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
398398
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
399399
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
400+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
400401
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
401402
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
402403
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
@@ -718,8 +719,6 @@ google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3Iji
718719
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
719720
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
720721
google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
721-
google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
722-
google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
723722
google.golang.org/grpc v1.34.0 h1:raiipEjMOIC/TO2AvyTxP25XFdLxNIBwzDh3FM3XztI=
724723
google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8=
725724
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=

0 commit comments

Comments
 (0)