Skip to content

Check the order of bootstrapped SCCs. #15923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions pkg/cmd/server/bootstrappolicy/securitycontextconstraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,43 @@ package bootstrappolicy

import (
"reflect"
"sort"
"testing"

"k8s.io/apiserver/pkg/authentication/serviceaccount"

securityapi "github.com/openshift/origin/pkg/security/apis/security"
scc "github.com/openshift/origin/pkg/security/securitycontextconstraints"
sccutil "github.com/openshift/origin/pkg/security/securitycontextconstraints/util"
)

func TestBootstrappedConstraints(t *testing.T) {
expectedConstraints := []string{
SecurityContextConstraintPrivileged,
// ordering of expectedConstraintNames is important, we check it against scc.ByPriority
expectedConstraintNames := []string{
SecurityContextConstraintsAnyUID,
SecurityContextConstraintsHostNetwork,
SecurityContextConstraintRestricted,
SecurityContextConstraintNonRoot,
SecurityContextConstraintHostMountAndAnyUID,
SecurityContextConstraintHostNS,
SecurityContextConstraintsAnyUID,
SecurityContextConstraintsHostNetwork,
SecurityContextConstraintHostMountAndAnyUID,
SecurityContextConstraintPrivileged,
Copy link
Contributor

@php-coder php-coder Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pweil- Do you agree with such order?

I don't understand it: if user has access to all the SCCs then I'd expect the following order: anyuid, restricted, ..., privileged.

In other words, the question is why hostnetwork goes before restricted?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a bug. The host namespaces should be involved in the values. I'm betting they have matching point value and no priority so they're sorting by name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pweil- I've submitted #15933

}
expectedGroups, expectedUsers := getExpectedAccess()
expectedVolumes := []securityapi.FSType{securityapi.FSTypeEmptyDir, securityapi.FSTypeSecret, securityapi.FSTypeDownwardAPI, securityapi.FSTypeConfigMap, securityapi.FSTypePersistentVolumeClaim}

groups, users := GetBoostrapSCCAccess(DefaultOpenShiftInfraNamespace)
bootstrappedConstraints := GetBootstrapSecurityContextConstraints(groups, users)

if len(expectedConstraints) != len(bootstrappedConstraints) {
t.Errorf("unexpected number of constraints: found %d, wanted %d", len(bootstrappedConstraints), len(expectedConstraints))
if len(expectedConstraintNames) != len(bootstrappedConstraints) {
t.Errorf("unexpected number of constraints: found %d, wanted %d", len(bootstrappedConstraints), len(expectedConstraintNames))
}

for _, constraint := range bootstrappedConstraints {
sort.Sort(scc.ByPriority(bootstrappedConstraints))

for i, constraint := range bootstrappedConstraints {
if constraint.Name != expectedConstraintNames[i] {
t.Errorf("unexpected contraint no. %d (by priority). Found %v, wanted %v", i, constraint.Name, expectedConstraintNames[i])
}
g := expectedGroups[constraint.Name]
if !reflect.DeepEqual(g, constraint.Groups) {
t.Errorf("unexpected group access for %s. Found %v, wanted %v", constraint.Name, constraint.Groups, g)
Expand Down