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

Conversation

adelton
Copy link
Contributor

@adelton adelton commented Aug 23, 2017

Related to #14530 and #14825.

Cc @simo5 @openshift/sig-security

@openshift-merge-robot openshift-merge-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 23, 2017
@csrwng csrwng assigned pweil- and unassigned csrwng Aug 23, 2017
SecurityContextConstraintNonRoot,
SecurityContextConstraintHostMountAndAnyUID,
SecurityContextConstraintHostNS,
SecurityContextConstraintRestricted,
Copy link
Contributor

Choose a reason for hiding this comment

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

expectedConstraints were not sorted properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not according to my running this on master. I specifically made this completely separate commit on top of master, so that we get to agree on the proper semantics first.

Copy link

Choose a reason for hiding this comment

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

expectedConstraints didn't need to be sorted until this PR, if that's what you're asking. Let's add a comment here that this ordering is now important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done -> 90e5ef3.

@adelton
Copy link
Contributor Author

adelton commented Aug 23, 2017

Cc @openshift/sig-security.

sort.Sort(scc.ByPriority(orderedBootstrappedConstraints))

for i := 0; i < len(orderedBootstrappedConstraints); i++ {
constraint := bootstrappedConstraints[i]
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.

-	for i := 0; i < len(orderedBootstrappedConstraints); i++ {
+	for i := range orderedBootstrappedConstraints {

Copy link
Contributor

Choose a reason for hiding this comment

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

I've corrected my comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, this is not equivalent -- I then get

	securitycontextconstraints_test.go:43: unexpected contraint no. 0 (by priority).  Found hostnetwork, wanted privileged
	securitycontextconstraints_test.go:43: unexpected contraint no. 1 (by priority).  Found hostnetwork, wanted nonroot
	securitycontextconstraints_test.go:43: unexpected contraint no. 2 (by priority).  Found hostnetwork, wanted hostmount-anyuid
	securitycontextconstraints_test.go:43: unexpected contraint no. 3 (by priority).  Found hostnetwork, wanted hostaccess
	securitycontextconstraints_test.go:43: unexpected contraint no. 4 (by priority).  Found hostnetwork, wanted restricted
	securitycontextconstraints_test.go:43: unexpected contraint no. 5 (by priority).  Found hostnetwork, wanted anyuid

Copy link

Choose a reason for hiding this comment

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

shouldn't you be getting the constraint from orderedBootstrappedConstraints to compare against expectedConstraintNames rather than bootstrappedConstraints? You still want the counter anyway to know which expected name to check against.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right.
I'll need to rethink this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adelton Could you try the following then?

-	for i := 0; i < len(orderedBootstrappedConstraints); i++ {
-		constraint := bootstrappedConstraints[i]
+	for i, constraint := range orderedBootstrappedConstraints {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed -> d3c8d27.

"testing"

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

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

func TestBootstrappedConstraints(t *testing.T) {
expectedConstraints := []string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider to rename expectedConstraints to expectedConstraintNames to better express it's content.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done -> 70aaf89.

@adelton adelton force-pushed the issue-14530-sort-test branch from 05f482f to 2cec279 Compare August 23, 2017 13:14
}

var orderedBootstrappedConstraints []*securityapi.SecurityContextConstraints
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to introduce orderedBootstrappedConstraints? Why we can't sort bootstrappedConstraints and use it later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because ByPriority wants pointers and bootstrappedConstraints does not get pointers from GetBootstrapSecurityContextConstraints.

I tried sort.Sort(scc.ByPriority(bootstrappedConstraints)) but that did not pan out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because ByPriority wants pointers and bootstrappedConstraints does not get pointers from GetBootstrapSecurityContextConstraints.

Ok, I see. I'll try to prepare PR that changes the return result of GetBootstrapSecurityContextConstraints.

SecurityContextConstraintNonRoot,
SecurityContextConstraintHostMountAndAnyUID,
SecurityContextConstraintHostNS,
SecurityContextConstraintRestricted,
Copy link

Choose a reason for hiding this comment

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

expectedConstraints didn't need to be sorted until this PR, if that's what you're asking. Let's add a comment here that this ordering is now important.

@adelton adelton force-pushed the issue-14530-sort-test branch from 2cec279 to 70aaf89 Compare August 23, 2017 13:27
@adelton adelton changed the title Check the order fo bootstrapped SCCs. Check the order of bootstrapped SCCs. Aug 23, 2017
@adelton adelton force-pushed the issue-14530-sort-test branch from 70aaf89 to 90e5ef3 Compare August 23, 2017 13:32
pweil-
pweil- previously requested changes Aug 23, 2017
Copy link

@pweil- pweil- left a comment

Choose a reason for hiding this comment

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

added pending question

@adelton adelton changed the title Check the order of bootstrapped SCCs. [do not merge] Check the order of bootstrapped SCCs. Aug 23, 2017
SecurityContextConstraintNonRoot,
SecurityContextConstraintHostMountAndAnyUID,
SecurityContextConstraintHostNS,
SecurityContextConstraintRestricted,
SecurityContextConstraintsAnyUID,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this order correct? Why anyuid isn't the last? It has priority: 10 AFAIR. What I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the latest logic fixes, anyuid is now actually first. Which sounds correct, it matches

[...]
        // a higher priority is considered "less" so that it moves to the front of the line
        if iSCCPriority > jSCCPriority {
                return true
        }

@adelton adelton force-pushed the issue-14530-sort-test branch from 90e5ef3 to d3c8d27 Compare August 23, 2017 14:13
@openshift-merge-robot openshift-merge-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 23, 2017
@adelton
Copy link
Contributor Author

adelton commented Aug 23, 2017

added pending question

Logic fixed -> d3c8d27.

@adelton adelton dismissed pweil-’s stale review August 23, 2017 14:22

Logic now fixed in d3c8d27.

@adelton adelton changed the title [do not merge] Check the order of bootstrapped SCCs. Check the order of bootstrapped SCCs. Aug 23, 2017
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

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 24, 2017
openshift-merge-robot added a commit that referenced this pull request Aug 28, 2017
…sult

Automatic merge from submit-queue (batch tested with PRs 15964, 15624, 15924)

GetBootstrapSecurityContextConstraints: change return type to a slice of pointers

Extracted from #15923 (comment):

It turned out that in all the places we need `[]*SecurityContextConstraints`. This PR updates `GetBootstrapSecurityContextConstraints` function to return this type. This change simplify our code.

PTAL @pweil- @adelton 
CC @simo5
@adelton adelton force-pushed the issue-14530-sort-test branch from d3c8d27 to 4a1bceb Compare September 7, 2017 07:57
@openshift-ci-robot openshift-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 7, 2017
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 7, 2017
@adelton
Copy link
Contributor Author

adelton commented Sep 7, 2017

Rebased on master -> 4a1bceb.

Could we get this reviewed and merged? Yes, the order will have to change but I'd like to have the test in as a safeguard for any other changes that might go into the code in the mean time. When #15933 is addressed, it will explicitly change the order in expectedConstraintNames.

Copy link
Contributor

@php-coder php-coder left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 7, 2017
@php-coder
Copy link
Contributor

/unassign

@enj
Copy link
Contributor

enj commented Sep 7, 2017

@pweil- can you approve? I do not have enough context to do so.

@adelton
Copy link
Contributor Author

adelton commented Sep 7, 2017

The context is basically: we pre-create some SCCs, so we wonder what their ordering is. This test adds the check. Yes, it uncovered that the order is actually not what we expected, hence #15933 was filed. But to address that, we need some changes that we have in queue for #14530 in #14825. That's why I'd like to add this test now to cover the situation as it is now, and amend the expected results in the test once we actually change the behaviour.

@php-coder
Copy link
Contributor

@pweil- can you approve? I do not have enough context to do so.

@enj Paul is on PTO this week.

@liggitt could you take a look and approve?

@liggitt
Copy link
Contributor

liggitt commented Sep 7, 2017

/approve
agree we should check the order and agree hostnetwork should come after restricted

@openshift-merge-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adelton, liggitt, php-coder

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 7, 2017
@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 15923, 16172)

@openshift-merge-robot openshift-merge-robot merged commit ef2a29e into openshift:master Sep 7, 2017
@adelton adelton deleted the issue-14530-sort-test branch September 8, 2017 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants