Skip to content
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

SCC sorting by priority #5543

Merged
merged 3 commits into from
Nov 4, 2015
Merged

Conversation

pweil-
Copy link
Contributor

@pweil- pweil- commented Oct 30, 2015

Sorts SCCs by a priority field and then by name. Adds a priority to the privileged SCC so that if you have administrative access you will use that SCC by default (though this is largely unnecessary since the first commit allows authenticated users to run as any uid).

Builds on #5498 which is hanging out in the merge queue right now so only the last three commits need reviewed.

Fixes #5317

@liggitt @smarterclayton

@pweil-
Copy link
Contributor Author

pweil- commented Oct 30, 2015

fixing commits so I don't incur rebase wrath, I packaged v1beta3 in with non-v1beta3.

edit: fixed. Last 3 commits need reviewed

@pweil- pweil- force-pushed the scc-sorting branch 2 times, most recently from a711f59 to 209fc92 Compare October 30, 2015 19:10
@liggitt
Copy link
Contributor

liggitt commented Oct 30, 2015

Ones with priority specified should come before ones without. Equal priority should maybe sort by the current sort behavior, rather than name, for backwards compatibility

@liggitt
Copy link
Contributor

liggitt commented Oct 30, 2015

In the case of a tie between priority AND old security score, name is fine to break the tie

// SortPriority influences the sort order of SCCs when evaluating which SCCs to try first for
// a given pod request based on access in the Users and Groups fields. The higher the int, the
// higher priority. If scores for multiple SCCs are equal they will be sorted by name.
SortPriority int `json:"sortPriority" description:"influences the sort order when evaluating SCCs available to the user"`
Copy link
Contributor

Choose a reason for hiding this comment

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

"determines which SCC is used when multiple SCCs allow a particular pod; higher priority SCCs are preferred"

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer priority over sortPriority... priority implies a sort, I think

@pweil- pweil- mentioned this pull request Oct 30, 2015
@deads2k
Copy link
Contributor

deads2k commented Oct 31, 2015

I was wondering this during SCC review as well. Why not simply merge all the user's available SCCs together, taking the highest privilege and preserving ranges alongside the "any's" for defaulting purposes. Then attempt to fill in the default pod a single time instead of once per SCC with the full set of available options. Wouldn't that solve the union problem, the separate of SCCs without specifying all combinations problem, the improper priority problem, and make the code easier to understand all at the same time? Seems like that would only become weird if you wanted crazy things like, "you can use these GIDs, but only as this UID".

I'm guessing you guys considered and discarded this, but I'd like to understand why.

@liggitt
Copy link
Contributor

liggitt commented Oct 31, 2015

Why not simply merge all the user's available SCCs together, taking the highest privilege and preserving ranges alongside the "any's" for defaulting purposes. Then attempt to fill in the default pod a single time instead of once per SCC with the full set of available options. Wouldn't that solve the union problem, the separate of SCCs without specifying all combinations problem, the improper priority problem, and make the code easier to understand all at the same time?

Mixing and matching bits of different SCCs isn't a good idea... privileges can combine to allow things that weren't intended. For example:

  • SCC A lets you host mount, but only as a particular user and with a specific selinux context
  • SCC B does not let you host mount, but lets you run as any non-root user

Mixing and matching would let someone host mount without getting the accompanying uid and selinux restriction the admin specified.

@deads2k
Copy link
Contributor

deads2k commented Oct 31, 2015

Maybe there's a better structure to use for constraints or the bindings. Having to specify every possible combination is pretty ridiculous and scales horribly as more options are added. Even just assuming on/off, we have 11 options making 2048 different potential policies to manage instead of 11.

Also for amusement, 2048 options taken 2048 at a time where order matters yields 1.6x10^5894 options. A simple, predictable system, :).

@liggitt
Copy link
Contributor

liggitt commented Oct 31, 2015

1.6x10^5894 options.

Sounds pretty powerful to me :)

@smarterclayton
Copy link
Contributor

I doubt you're going to see more than 10 in use at any one site. And we
can survive until then.

On Oct 31, 2015, at 8:25 AM, David Eads [email protected] wrote:

Maybe there's a better structure to use for constraints or the bindings.
Having to specify every possible combination is pretty ridiculous and
scales horribly as more options are added. Even just assuming on/off, we
have 11 options making 2048 different potential policies to manage instead
of 11.


Reply to this email directly or view it on GitHub
#5543 (comment).

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 31, 2015
@pweil-
Copy link
Contributor Author

pweil- commented Nov 2, 2015

@liggitt - round 2 ready for your eyes

  1. sort by priority first
  2. if priorities are equal, sort by score in the old behavior
  3. if priorities and score are equal sort by name
  4. admin has access to privileged and anyuid
  5. anyuid is given priority 1
  6. changed field and descriptions according to comments

// Priority influences the sort order of SCCs when evaluating which SCCs to try first for
// a given pod request based on access in the Users and Groups fields. The higher the int, the
// higher priority. If scores for multiple SCCs are equal they will be sorted by name.
Priority int `json:"sortPriority" description:"determines which SCC is used when multiple SCCs allow a particular pod; higher priority SCCs are preferred"`
Copy link
Contributor

Choose a reason for hiding this comment

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

change json field name to priority

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Damn, you're too quick. I just caught it. Fixed.

@smarterclayton smarterclayton added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 2, 2015
@pweil- pweil- force-pushed the scc-sorting branch 2 times, most recently from 2abbb7b to d40d15e Compare November 2, 2015 15:10
@@ -68,9 +68,11 @@ func TestAdmit(t *testing.T) {
Type: kapi.SupplementalGroupsStrategyMustRunAs,
},
Groups: []string{"system:serviceaccounts"},
// give this scc priority since it is what we want to validate with
SortPriority: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

don't you need a more restrictive SCC that also matches to actually check that you're matching on sort priority, and not just the secondary pointScore sort?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, I don't need this priority at all. The SCC below it is more restrictive (a MustRunAs uid strategy rather than a MustRunAsRange) that is in scc-sa. Removing the priority they would have equal priorities. The scores should ensure that scc-sa-exact is tried before scc-sa but it should be failing to validate. We check the matched name in the test run which will ensure we're matching against what we expect....removing.

@pweil- pweil- force-pushed the scc-sorting branch 2 times, most recently from 390e56c to 3ee3f37 Compare November 2, 2015 15:44
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 2, 2015
@liggitt
Copy link
Contributor

liggitt commented Nov 2, 2015

LGTM

@liggitt
Copy link
Contributor

liggitt commented Nov 3, 2015

it matters when we want to set defaults if the admin hasn't expressed a priority intent. Also, validate priority to be >= 0.

@liggitt
Copy link
Contributor

liggitt commented Nov 3, 2015

I would expect the following behavior:

Missing priority behaves like priority=0 for purposes of sorting
Missing priority gets set on reconcile
Present priority only gets set on reconcile if they explicitly do --overwrite-priority or similar

@liggitt liggitt self-assigned this Nov 3, 2015
@pweil-
Copy link
Contributor Author

pweil- commented Nov 3, 2015

Missing priority gets set on reconcile
Present priority only gets set on reconcile if they explicitly do --overwrite-priority or similar

I see what you're saying here. I was considering it an option of either "overwrite all priorities" or "don't touch priorities" during reconcile but if the options are really "set missing" or "overwrite all" then nil makes sense. That was my disconnect.

In that case, the first reconcile run (regardless of option) will set all the missing priorities on bootstrapped commands and subsequent changes to the bootstrap SCC priorities will never update until --overwrite-priority is used. Sound about right to you?

@liggitt
Copy link
Contributor

liggitt commented Nov 3, 2015

In that case, the first reconcile run (regardless of option) will set all the missing priorities on bootstrapped commands and subsequent changes to the bootstrap SCC priorities will never update until --overwrite-priority is used. Sound about right to you?

Yes, so choose priorities carefully (or just set the one we care about to 1?)

@pweil- pweil- force-pushed the scc-sorting branch 2 times, most recently from 25e7686 to 0b829bc Compare November 3, 2015 18:38
@pweil-
Copy link
Contributor Author

pweil- commented Nov 3, 2015

@liggitt - updated to be a pointer, added checks in sorting, and a nil vs non-nil test. Also updated the printer so that nil priority doesn't show as 0 which would be confusing since 0 > nil now. Please take another pass.

@pweil-
Copy link
Contributor Author

pweil- commented Nov 3, 2015

oh, btw, I set anyuid to 10 to give wiggle room if an admin wants to adjust other priorities (so they don't have to immediately adjust anyuid just to keep it prioritized).

@liggitt
Copy link
Contributor

liggitt commented Nov 3, 2015

0 should equal nil for sorting purposes, imo

@liggitt
Copy link
Contributor

liggitt commented Nov 3, 2015

add validation to make sure non-nil priority is >= 0

var (
// this is set to 10 to allow wiggle room for admins to set other priorities without
// having to adjust anyUID.
securityContextConstraintsAnyUIDPriority = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

10 PRINT "HELLO"
20 PRINT "WORLD"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

parse exception. Do you want the lower score (except 0) to be considered higher priority?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was just amused at setting to 10 to allow space... took me back...

@pweil-
Copy link
Contributor Author

pweil- commented Nov 3, 2015

made nil == 0 for sorting, added in the printer, added validation method for negative priorities.

@liggitt
Copy link
Contributor

liggitt commented Nov 3, 2015

LGTM

@liggitt liggitt added the lgtm Indicates that a PR is ready to be merged. label Nov 3, 2015
@smarterclayton smarterclayton added area/usability priority/P1 area/security and removed lgtm Indicates that a PR is ready to be merged. labels Nov 3, 2015
@smarterclayton
Copy link
Contributor

[test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 4c9aeb1

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/6827/)

smarterclayton added a commit that referenced this pull request Nov 4, 2015
@smarterclayton smarterclayton merged commit 6e3342f into openshift:master Nov 4, 2015
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. area/security area/usability priority/P1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants