Skip to content

Commit 10b7e95

Browse files
Antonio Ojeaaojea
Antonio Ojea
authored andcommitted
detect required capabilities
1 parent fff3e52 commit 10b7e95

28 files changed

+4753
-13
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ require (
99
golang.org/x/net v0.0.0-20201224014010-6772e930b67b
1010
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c
1111
gvisor.dev/gvisor v0.0.0-20210506004418-fbfeba3024f0
12+
kernel.org/pub/linux/libs/security/libcap/cap v1.2.51
1213
)

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,10 @@ k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
602602
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
603603
k8s.io/kube-openapi v0.0.0-20200410163147-594e756bea31/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
604604
k8s.io/utils v0.0.0-20190801114015-581e00157fb1/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
605+
kernel.org/pub/linux/libs/security/libcap/cap v1.2.51 h1:2CHkVUXuBnW/jLVgbpfJ0PRdewDCS9h45Mmp6sLhurk=
606+
kernel.org/pub/linux/libs/security/libcap/cap v1.2.51/go.mod h1:1H1c41mQKQi1964hjtZ/Sb+KWgRsLos79wIwOOfwTVU=
607+
kernel.org/pub/linux/libs/security/libcap/psx v1.2.51 h1:VXVXjnTUsA9zeHIolNb6moSXZavDe1pD8Q0lPXZEOwc=
608+
kernel.org/pub/linux/libs/security/libcap/psx v1.2.51/go.mod h1:+l6Ee2F59XiJ2I6WR5ObpC1utCQJZ/VLsEbQCD8RG24=
605609
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
606610
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
607611
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

nk.go

+7-13
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"fmt"
77
"log"
88
"os"
9-
"os/exec"
109
"os/signal"
11-
"strconv"
1210

1311
"golang.org/x/sys/unix"
12+
13+
"kernel.org/pub/linux/libs/security/libcap/cap"
1414
)
1515

1616
//go:generate bpf2go filter bpf/filter.c -- -I/usr/include -I./bpf -nostdinc -O3
@@ -65,19 +65,13 @@ func main() {
6565
k, m, 5, 2)
6666
}
6767

68-
cmd := exec.Command("id", "-u")
69-
output, err := cmd.Output()
70-
if err != nil {
71-
log.Fatal(err)
68+
c := cap.GetProc()
69+
if on, _ := c.GetFlag(cap.Permitted, cap.NET_RAW); !on {
70+
log.Fatalf("insufficient privilege to open RAW sockets - want %q, have %q", cap.NET_RAW, c)
7271
}
7372

74-
// 0 = root, 501 = non-root user
75-
i, err := strconv.Atoi(string(output[:len(output)-1]))
76-
if err != nil {
77-
log.Fatal(err)
78-
}
79-
if i != 0 {
80-
log.Fatal("This program must be run as root! (sudo)")
73+
if on, _ := c.GetFlag(cap.Permitted, cap.SYS_RESOURCE); !on {
74+
log.Fatalf("insufficient privilege to set rlimit - want %q, have %q", cap.SYS_RESOURCE, c)
8175
}
8276

8377
// Parse command line flags and arguments

vendor/kernel.org/pub/linux/libs/security/libcap/cap/License

+396
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/kernel.org/pub/linux/libs/security/libcap/cap/README

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)