forked from opencontainers/runtime-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WiP: validate: prevent generate gojsonschema dependency.
Split out the capabilty validation functions LastCap() and CapValid() from validate to validate/capabilities. This prevents gojsonschema (which is regarded by some as a package with questionable quality) from sneaking in to the dependencies of generate.Generator. Signed-off-by: Krisztian Litkey <[email protected]>
- Loading branch information
Showing
6 changed files
with
81 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package capabilities | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/syndtr/gocapability/capability" | ||
) | ||
|
||
// CapValid checks whether a capability is valid | ||
func CapValid(c string, hostSpecific bool) error { | ||
isValid := false | ||
|
||
if !strings.HasPrefix(c, "CAP_") { | ||
return fmt.Errorf("capability %s must start with CAP_", c) | ||
} | ||
for _, cap := range capability.List() { | ||
if c == fmt.Sprintf("CAP_%s", strings.ToUpper(cap.String())) { | ||
if hostSpecific && cap > LastCap() { | ||
return fmt.Errorf("%s is not supported on the current host", c) | ||
} | ||
isValid = true | ||
break | ||
} | ||
} | ||
|
||
if !isValid { | ||
return fmt.Errorf("invalid capability: %s", c) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package capabilities | ||
|
||
import ( | ||
"github.com/syndtr/gocapability/capability" | ||
) | ||
|
||
// LastCap return last cap of system | ||
func LastCap() capability.Cap { | ||
last := capability.CAP_LAST_CAP | ||
// hack for RHEL6 which has no /proc/sys/kernel/cap_last_cap | ||
if last == capability.Cap(63) { | ||
last = capability.CAP_BLOCK_SUSPEND | ||
} | ||
|
||
return last | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build !linux | ||
// +build !linux | ||
|
||
package validate | ||
|
||
import ( | ||
"github.com/syndtr/gocapability/capability" | ||
) | ||
|
||
// LastCap return last cap of system | ||
func LastCap() capability.Cap { | ||
return capability.Cap(-1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters