Skip to content

Commit 24e0035

Browse files
committed
*: remove RHEL6 hack and loosen capability validation
The RHEL6 hack for CAP_LAST_CAP was causing us some annoyances, with the inter-dependency of generate and validate only existing because of CapValid (which then resulted in a bunch of build-time dependencies that were never used by projects that vendored us). To fix this issue, drop CapValid entirely so we don't have to touch it anymore -- just assume that CAP_LAST_CAP works on all systems. And in the case of validation we match new changes in the spec where capabilities are now just plain strings (but for the HostSpecific case we still do validation). Signed-off-by: Aleksa Sarai <[email protected]>
1 parent d0b0063 commit 24e0035

File tree

4 files changed

+10
-27
lines changed

4 files changed

+10
-27
lines changed

generate/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ func (g *Generator) SetupPrivileged(privileged bool) {
10231023
if privileged { // Add all capabilities in privileged mode.
10241024
var finalCapList []string
10251025
for _, cap := range capability.List() {
1026-
if g.HostSpecific && cap > validate.LastCap() {
1026+
if g.HostSpecific && cap > capability.CAP_LAST_CAP {
10271027
continue
10281028
}
10291029
finalCapList = append(finalCapList, fmt.Sprintf("CAP_%s", strings.ToUpper(cap.String())))

validate/validate.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,23 +687,28 @@ func (v *Validator) CheckAnnotations() (errs error) {
687687
return
688688
}
689689

690-
// CapValid checks whether a capability is valid
690+
// CapValid checks whether a capability is valid. This only really checks
691+
// anything with hostSpecific, otherwise we just ignore everything (because
692+
// capabilities are now free-form strings).
691693
func CapValid(c string, hostSpecific bool) error {
692-
isValid := false
694+
// Cannot speak to whether the capability makes sense.
695+
if !hostSpecific {
696+
return nil
697+
}
693698

699+
isValid := false
694700
if !strings.HasPrefix(c, "CAP_") {
695701
return fmt.Errorf("capability %s must start with CAP_", c)
696702
}
697703
for _, cap := range capability.List() {
698704
if c == fmt.Sprintf("CAP_%s", strings.ToUpper(cap.String())) {
699-
if hostSpecific && cap > LastCap() {
705+
if cap > capability.CAP_LAST_CAP {
700706
return fmt.Errorf("%s is not supported on the current host", c)
701707
}
702708
isValid = true
703709
break
704710
}
705711
}
706-
707712
if !isValid {
708713
return fmt.Errorf("invalid capability: %s", c)
709714
}

validate/validate_linux.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,13 @@ import (
1010
"strings"
1111
"syscall"
1212

13-
"github.com/syndtr/gocapability/capability"
14-
1513
multierror "github.com/hashicorp/go-multierror"
1614
rspec "github.com/opencontainers/runtime-spec/specs-go"
1715
osFilepath "github.com/opencontainers/runtime-tools/filepath"
1816
"github.com/opencontainers/runtime-tools/specerror"
1917
"github.com/sirupsen/logrus"
2018
)
2119

22-
// LastCap return last cap of system
23-
func LastCap() capability.Cap {
24-
last := capability.CAP_LAST_CAP
25-
// hack for RHEL6 which has no /proc/sys/kernel/cap_last_cap
26-
if last == capability.Cap(63) {
27-
last = capability.CAP_BLOCK_SUSPEND
28-
}
29-
30-
return last
31-
}
32-
3320
func deviceValid(d rspec.LinuxDevice) bool {
3421
switch d.Type {
3522
case "b", "c", "u":

validate/validate_unsupported.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
package validate
44

5-
import (
6-
"github.com/syndtr/gocapability/capability"
7-
)
8-
9-
// LastCap return last cap of system
10-
func LastCap() capability.Cap {
11-
return capability.Cap(-1)
12-
}
13-
145
// CheckLinux is a noop on this platform
156
func (v *Validator) CheckLinux() (errs error) {
167
return nil

0 commit comments

Comments
 (0)