File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ func pointValue(constraint *kapi.SecurityContextConstraints) int {
28
28
// add points based on volume requests
29
29
points += volumePointValue (constraint )
30
30
31
+ // add points based on capabilities
32
+ points += capabilitiesPointValue (constraint )
33
+
31
34
// strategies in order of least restrictive to most restrictive
32
35
switch constraint .SELinuxContext .Type {
33
36
case kapi .SELinuxStrategyRunAsAny :
@@ -82,3 +85,33 @@ func volumePointValue(scc *kapi.SecurityContextConstraints) int {
82
85
}
83
86
return 0
84
87
}
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
+ }
You can’t perform that action at this time.
0 commit comments