Skip to content

Commit 64fa9d6

Browse files
committed
Make space in the point logic for capabilities accounting.
1 parent c3c286b commit 64fa9d6

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

Diff for: pkg/security/scc/byrestrictions.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func pointValue(constraint *kapi.SecurityContextConstraints) int {
2222

2323
// make sure these are always valued higher than the combination of the highest strategies
2424
if constraint.AllowPrivilegedContainer {
25-
points += 20
25+
points += 200000
2626
}
2727

2828
// add points based on volume requests
@@ -31,28 +31,28 @@ func pointValue(constraint *kapi.SecurityContextConstraints) int {
3131
// strategies in order of least restrictive to most restrictive
3232
switch constraint.SELinuxContext.Type {
3333
case kapi.SELinuxStrategyRunAsAny:
34-
points += 4
34+
points += 40000
3535
case kapi.SELinuxStrategyMustRunAs:
36-
points += 1
36+
points += 10000
3737
}
3838

3939
switch constraint.RunAsUser.Type {
4040
case kapi.RunAsUserStrategyRunAsAny:
41-
points += 4
41+
points += 40000
4242
case kapi.RunAsUserStrategyMustRunAsNonRoot:
43-
points += 3
43+
points += 30000
4444
case kapi.RunAsUserStrategyMustRunAsRange:
45-
points += 2
45+
points += 20000
4646
case kapi.RunAsUserStrategyMustRunAs:
47-
points += 1
47+
points += 10000
4848
}
4949
return points
5050
}
5151

5252
// volumePointValue returns a score based on the volumes allowed by the SCC.
53-
// Allowing a host volume will return a score of 10. Allowance of anything other
53+
// Allowing a host volume will return a score of 100000. Allowance of anything other
5454
// than Secret, ConfigMap, EmptyDir, DownwardAPI, Projected, and None will result in
55-
// a score of 5. If the SCC only allows these trivial types, it will have a
55+
// a score of 50000. If the SCC only allows these trivial types, it will have a
5656
// score of 0.
5757
func volumePointValue(scc *kapi.SecurityContextConstraints) int {
5858
hasHostVolume := false
@@ -75,10 +75,10 @@ func volumePointValue(scc *kapi.SecurityContextConstraints) int {
7575
}
7676

7777
if hasHostVolume {
78-
return 10
78+
return 100000
7979
}
8080
if hasNonTrivialVolume {
81-
return 5
81+
return 50000
8282
}
8383
return 0
8484
}

Diff for: pkg/security/scc/byrestrictions_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ func TestPointValue(t *testing.T) {
2424
}
2525

2626
seLinuxStrategies := map[kapi.SELinuxContextStrategyType]int{
27-
kapi.SELinuxStrategyRunAsAny: 4,
28-
kapi.SELinuxStrategyMustRunAs: 1,
27+
kapi.SELinuxStrategyRunAsAny: 40000,
28+
kapi.SELinuxStrategyMustRunAs: 10000,
2929
}
3030
userStrategies := map[kapi.RunAsUserStrategyType]int{
31-
kapi.RunAsUserStrategyRunAsAny: 4,
32-
kapi.RunAsUserStrategyMustRunAsNonRoot: 3,
33-
kapi.RunAsUserStrategyMustRunAsRange: 2,
34-
kapi.RunAsUserStrategyMustRunAs: 1,
31+
kapi.RunAsUserStrategyRunAsAny: 40000,
32+
kapi.RunAsUserStrategyMustRunAsNonRoot: 30000,
33+
kapi.RunAsUserStrategyMustRunAsRange: 20000,
34+
kapi.RunAsUserStrategyMustRunAs: 10000,
3535
}
3636

37-
privilegedPoints := 20
37+
privilegedPoints := 200000
3838

3939
// run through all combos of user strategy + seLinux strategy + priv
4040
for userStrategy, userStrategyPoints := range userStrategies {
@@ -61,7 +61,7 @@ func TestPointValue(t *testing.T) {
6161
scc := newSCC(false, kapi.SELinuxStrategyMustRunAs, kapi.RunAsUserStrategyMustRunAs)
6262
scc.Volumes = []kapi.FSType{kapi.FSTypeHostPath}
6363
actualPoints := pointValue(scc)
64-
if actualPoints != 12 { //1 (SELinux) + 1 (User) + 10 (host path volume)
64+
if actualPoints != 120000 { //10000 (SELinux) + 10000 (User) + 100000 (host path volume)
6565
t.Errorf("volume score was not added to the scc point value correctly!")
6666
}
6767
}
@@ -94,27 +94,27 @@ func TestVolumePointValue(t *testing.T) {
9494
}{
9595
"all volumes": {
9696
scc: allowAllSCC,
97-
expectedPoints: 10,
97+
expectedPoints: 100000,
9898
},
9999
"host volume": {
100100
scc: newSCC(true, false, false),
101-
expectedPoints: 10,
101+
expectedPoints: 100000,
102102
},
103103
"host volume and non trivial volumes": {
104104
scc: newSCC(true, true, false),
105-
expectedPoints: 10,
105+
expectedPoints: 100000,
106106
},
107107
"host volume, non trivial, and trivial": {
108108
scc: newSCC(true, true, true),
109-
expectedPoints: 10,
109+
expectedPoints: 100000,
110110
},
111111
"non trivial": {
112112
scc: newSCC(false, true, false),
113-
expectedPoints: 5,
113+
expectedPoints: 50000,
114114
},
115115
"non trivial and trivial": {
116116
scc: newSCC(false, true, true),
117-
expectedPoints: 5,
117+
expectedPoints: 50000,
118118
},
119119
"trivial": {
120120
scc: newSCC(false, false, true),

0 commit comments

Comments
 (0)