Skip to content

Commit 2bfbb6c

Browse files
committed
Make SCC with less capabilities more restrictive.
1 parent b518297 commit 2bfbb6c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pkg/security/scc/byrestrictions.go

+33
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func pointValue(constraint *kapi.SecurityContextConstraints) int {
2828
// add points based on volume requests
2929
points += volumePointValue(constraint)
3030

31+
// add points based on capabilities
32+
points += capabilitiesPointValue(constraint)
33+
3134
// strategies in order of least restrictive to most restrictive
3235
switch constraint.SELinuxContext.Type {
3336
case kapi.SELinuxStrategyRunAsAny:
@@ -82,3 +85,33 @@ func volumePointValue(scc *kapi.SecurityContextConstraints) int {
8285
}
8386
return 0
8487
}
88+
89+
// hasCap checks for needle in haystack.
90+
func hasCap(needle kapi.Capability, haystack []kapi.Capability) bool {
91+
for _, c := range haystack {
92+
if needle == c {
93+
return true
94+
}
95+
}
96+
return false
97+
}
98+
99+
// capabilitiesPointValue returns a score based on the capabilities allowed,
100+
// added, or removed by the SCC.
101+
func capabilitiesPointValue(scc *kapi.SecurityContextConstraints) int {
102+
points := 500
103+
points += 30 * len(scc.DefaultAddCapabilities)
104+
if hasCap(kapi.CapabilityAll, scc.AllowedCapabilities) {
105+
points += 300
106+
} else {
107+
points += 10 * len(scc.AllowedCapabilities)
108+
}
109+
points -= 50 * len(scc.RequiredDropCapabilities)
110+
if (points > 1000) {
111+
return 1000
112+
} else if (points < 0) {
113+
return 0
114+
} else {
115+
return points
116+
}
117+
}

0 commit comments

Comments
 (0)