Skip to content

Commit

Permalink
Merge pull request #89 from Mashimiao/runtime-test-optimize-cap-valid…
Browse files Browse the repository at this point in the history
…ation

runtimetest: optimize capabilities validation
  • Loading branch information
Mrunal Patel committed Jun 3, 2016
2 parents 18f8dd7 + 9182c46 commit 8fb606b
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,30 @@ func validateProcess(spec *rspec.Spec) error {

func validateCapabilities(spec *rspec.Spec) error {
fmt.Println("validating capabilities")
capabilityMap := make(map[string]capability.Cap)
expectedCaps := make(map[capability.Cap]bool)

last := capability.CAP_LAST_CAP
// workaround for RHEL6 which has no /proc/sys/kernel/cap_last_cap
if last == capability.Cap(63) {
last = capability.CAP_BLOCK_SUSPEND
}
for _, cap := range capability.List() {
if cap > last {
continue
}
capKey := fmt.Sprintf("CAP_%s", strings.ToUpper(cap.String()))
capabilityMap[capKey] = cap
expectedCaps[cap] = false
}

for _, ec := range spec.Process.Capabilities {
cap := capabilityMap[ec]
expectedCaps[cap] = true
}

processCaps, err := capability.NewPid(1)
if err != nil {
return err
}

expectedCaps := make(map[string]bool)
for _, ec := range spec.Process.Capabilities {
expectedCaps[ec] = true
}

for _, cap := range capability.List() {
expectedSet := expectedCaps[cap]
if cap > last {
continue
}

capKey := fmt.Sprintf("CAP_%s", strings.ToUpper(cap.String()))
expectedSet := expectedCaps[capKey]
actuallySet := processCaps.Get(capability.EFFECTIVE, cap)
if expectedSet != actuallySet {
if expectedSet {
Expand Down

0 comments on commit 8fb606b

Please sign in to comment.