Skip to content

Commit

Permalink
Merge pull request #8298 from pweil-/scc-pvc
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Mar 30, 2016
2 parents 4859fed + 020adab commit d92dd0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pkg/cmd/server/bootstrappolicy/securitycontextconstraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func GetBootstrapSecurityContextConstraints(sccNameToAdditionalGroups map[string
DescriptionAnnotation: SecurityContextConstraintNonRootDesc,
},
},
Volumes: []kapi.FSType{kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap},
Volumes: []kapi.FSType{kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap, kapi.FSTypePersistentVolumeClaim},
SELinuxContext: kapi.SELinuxContextStrategyOptions{
// This strategy requires that annotations on the namespace which will be populated
// by the admission controller. If namespaces are not annotated creating the strategy
Expand Down Expand Up @@ -119,7 +119,7 @@ func GetBootstrapSecurityContextConstraints(sccNameToAdditionalGroups map[string
DescriptionAnnotation: SecurityContextConstraintHostMountAndAnyUIDDesc,
},
},
Volumes: []kapi.FSType{kapi.FSTypeHostPath, kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap},
Volumes: []kapi.FSType{kapi.FSTypeHostPath, kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap, kapi.FSTypePersistentVolumeClaim},
SELinuxContext: kapi.SELinuxContextStrategyOptions{
// This strategy requires that annotations on the namespace which will be populated
// by the admission controller. If namespaces are not annotated creating the strategy
Expand Down Expand Up @@ -148,7 +148,7 @@ func GetBootstrapSecurityContextConstraints(sccNameToAdditionalGroups map[string
DescriptionAnnotation: SecurityContextConstraintHostNSDesc,
},
},
Volumes: []kapi.FSType{kapi.FSTypeHostPath, kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap},
Volumes: []kapi.FSType{kapi.FSTypeHostPath, kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap, kapi.FSTypePersistentVolumeClaim},
AllowHostNetwork: true,
AllowHostPorts: true,
AllowHostPID: true,
Expand Down Expand Up @@ -180,7 +180,7 @@ func GetBootstrapSecurityContextConstraints(sccNameToAdditionalGroups map[string
DescriptionAnnotation: SecurityContextConstraintRestrictedDesc,
},
},
Volumes: []kapi.FSType{kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap},
Volumes: []kapi.FSType{kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap, kapi.FSTypePersistentVolumeClaim},
SELinuxContext: kapi.SELinuxContextStrategyOptions{
// This strategy requires that annotations on the namespace which will be populated
// by the admission controller. If namespaces are not annotated creating the strategy
Expand Down Expand Up @@ -210,7 +210,7 @@ func GetBootstrapSecurityContextConstraints(sccNameToAdditionalGroups map[string
DescriptionAnnotation: SecurityContextConstraintsAnyUIDDesc,
},
},
Volumes: []kapi.FSType{kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap},
Volumes: []kapi.FSType{kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap, kapi.FSTypePersistentVolumeClaim},
SELinuxContext: kapi.SELinuxContextStrategyOptions{
// This strategy requires that annotations on the namespace which will be populated
// by the admission controller. If namespaces are not annotated creating the strategy
Expand Down Expand Up @@ -241,7 +241,7 @@ func GetBootstrapSecurityContextConstraints(sccNameToAdditionalGroups map[string
},
AllowHostNetwork: true,
AllowHostPorts: true,
Volumes: []kapi.FSType{kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap},
Volumes: []kapi.FSType{kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap, kapi.FSTypePersistentVolumeClaim},
SELinuxContext: kapi.SELinuxContextStrategyOptions{
// This strategy requires that annotations on the namespace which will be populated
// by the admission controller. If namespaces are not annotated creating the strategy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package bootstrappolicy

import (
"k8s.io/kubernetes/pkg/serviceaccount"
"reflect"
"testing"

kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/serviceaccount"
)

func TestBootstrappedConstraints(t *testing.T) {
Expand All @@ -17,6 +19,7 @@ func TestBootstrappedConstraints(t *testing.T) {
SecurityContextConstraintsHostNetwork,
}
expectedGroups, expectedUsers := getExpectedAccess()
expectedVolumes := []kapi.FSType{kapi.FSTypeEmptyDir, kapi.FSTypeSecret, kapi.FSTypeDownwardAPI, kapi.FSTypeConfigMap, kapi.FSTypePersistentVolumeClaim}

groups, users := GetBoostrapSCCAccess(DefaultOpenShiftInfraNamespace)
bootstrappedConstraints := GetBootstrapSecurityContextConstraints(groups, users)
Expand All @@ -35,6 +38,12 @@ func TestBootstrappedConstraints(t *testing.T) {
if !reflect.DeepEqual(u, constraint.Users) {
t.Errorf("unexpected user access for %s. Found %v, wanted %v", constraint.Name, constraint.Users, u)
}

for _, expectedVolume := range expectedVolumes {
if !supportsFSType(expectedVolume, &constraint) {
t.Errorf("%s does not support %v which is required for all default SCCs", constraint.Name, expectedVolume)
}
}
}
}

Expand Down Expand Up @@ -77,3 +86,12 @@ func getExpectedAccess() (map[string][]string, map[string][]string) {
}
return groups, users
}

func supportsFSType(fsType kapi.FSType, scc *kapi.SecurityContextConstraints) bool {
for _, v := range scc.Volumes {
if v == kapi.FSTypeAll || v == fsType {
return true
}
}
return false
}

0 comments on commit d92dd0d

Please sign in to comment.