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

Make SCC with less capabilities more restrictive. #14825

Merged
merged 2 commits into from
Sep 7, 2017

Conversation

adelton
Copy link
Contributor

@adelton adelton commented Jun 22, 2017

Fixes #14530

@adelton
Copy link
Contributor Author

adelton commented Jun 22, 2017

Would appreciate comments about the logic change (namely the * 10000 change) before looking at test updates.

@adelton
Copy link
Contributor Author

adelton commented Jun 22, 2017

Cc @simo5 @openshift/security

return false
}

// capabilitiesPointValue returns a score based on the capabilities allowed,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add more comments about why we need this and what was the logic behind the statements?

// capabilitiesPointValue returns a score based on the capabilities allowed,
// added, or removed by the SCC.
func capabilitiesPointValue(scc *kapi.SecurityContextConstraints) int {
points := 500
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we're using 500 as initial value and not 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be able to substract and not get below zero easily.

func capabilitiesPointValue(scc *kapi.SecurityContextConstraints) int {
points := 500
points += 30 * len(scc.DefaultAddCapabilities)
if hasCap(kapi.CapabilityAll, scc.AllowedCapabilities) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add also checking for all (ALL).

}
points -= 50 * len(scc.RequiredDropCapabilities)
if (points > 1000) {
return 1000
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we're reducing value to 1000?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The goal was not to interfere with the other logic ... but that caps us at 10000, not 1000, will fix.

return 1000
} else if (points < 0) {
return 0
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat: we don't need last else block.

} else {
points += 10 * len(scc.AllowedCapabilities)
}
points -= 50 * len(scc.RequiredDropCapabilities)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a check for all/ALL value here?

@adelton
Copy link
Contributor Author

adelton commented Jun 23, 2017

Fixed the volumes logic, added tests, rebased on master -> aa30746.

@adelton
Copy link
Contributor Author

adelton commented Jun 23, 2017

Addressed comments by @php-coder -> 03b8ccf.

@pweil-
Copy link
Contributor

pweil- commented Jun 23, 2017

@liggitt fyi

@deads2k
Copy link
Contributor

deads2k commented Jun 23, 2017

please hold for #14701

scc := newSCC(false, kapi.SELinuxStrategyMustRunAs, kapi.RunAsUserStrategyMustRunAs)
scc.Volumes = []kapi.FSType{kapi.FSTypeHostPath}
actualPoints := pointValue(scc)
if actualPoints != 12 { //1 (SELinux) + 1 (User) + 10 (host path volume)
t.Errorf("volume score was not added to the scc point value correctly!")
if actualPoints != 125000 { //10000 (SELinux) + 10000 (User) + 100000 (host path volume) + 5000 capabilities
Copy link
Contributor

@php-coder php-coder Jun 23, 2017

Choose a reason for hiding this comment

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

Having these magic numbers and comments with explanation what they means, make me thinking about extracting the constants. Maybe it's too much here. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't consider myself expert on Golang/OpenShift best practices to do that refactoring. If you do that for the original pkg/security/scc/byrestrictions.go, I'd certainly make my patch align with that approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I've submitted #15116

@adelton
Copy link
Contributor Author

adelton commented Jun 26, 2017

Fixed the nils, updated the tests structure per comments by @php-coder, rebased on master -> 25f4554.

@adelton
Copy link
Contributor Author

adelton commented Jun 27, 2017

Now that #14701 was merged, rebased on master -> 99c756d.

@deads2k
Copy link
Contributor

deads2k commented Jun 27, 2017

Now that #14701 was merged, rebased on master -> 99c756d.

I'll turn it back over to @php-coder . Thanks for waiting on the structural change.

@enj
Copy link
Contributor

enj commented Jun 28, 2017

I do not know enough about the SCC stuff to really comment here. All the magic numbers are really concerning :/ @pweil- @php-coder I will have to defer to your expertise.

@adelton
Copy link
Contributor Author

adelton commented Jul 3, 2017

@php-coder, could we continue / finish the review?

@php-coder
Copy link
Contributor

@adelton Let's wait until #15116 will be rejected/merged first.

@adelton adelton changed the title Make SCC with less capabilities more restrictive. Make SCC with less capabilities more restrictive. [waiting for #15116] Jul 11, 2017
@adelton
Copy link
Contributor Author

adelton commented Jul 11, 2017

Let's wait until #15116 will be rejected/merged first.

I've rebased this PR on top of #15116 and have it available locally. Should I push it on top of #15116 to allow review to continue, possibly as different branch?

@php-coder
Copy link
Contributor

@adelton Just push it so I'll be able to review it as a separate commit. After #15116 you will rebase it again and my merged changes will gone.

@adelton
Copy link
Contributor Author

adelton commented Jul 11, 2017

Rebased on top of #15116 -> 07bf572.

@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 7, 2017
@adelton
Copy link
Contributor Author

adelton commented Aug 7, 2017

Brought up-to-date with the kapi.CapabilityAll -> securityapi.AllowAllCapabilities change. Rebased on master -> d36ab40.

@php-coder
Copy link
Contributor

/lgtm

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

adelton commented Aug 8, 2017

/assign @smarterclayton

@adelton
Copy link
Contributor Author

adelton commented Aug 21, 2017

@pweil- could you please review and potentially approve instead of @smarterclayton?

@adelton
Copy link
Contributor Author

adelton commented Aug 22, 2017

@eparis, could you please review and potentially approve instead of @smarterclayton?

Copy link
Contributor

@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.

can we get a test that ensures the bootstrapped sccs sort in the expected order so we can protect against that in the future?

other than that I have no issues with these changes. Thanks!

capsPoints += capAddOnePoints * points(len(scc.DefaultAddCapabilities))
if hasCap(string(securityapi.AllowAllCapabilities), scc.AllowedCapabilities) {
capsPoints += capAllowAllPoints
} else if hasCap("ALL", scc.AllowedCapabilities) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there going to be a sorting issue if all is used since we don't normalize to a case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do normalize, hasCap calls ToUpper.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, we do it in the search there but not the validation. Ok, disregard. Thanks

@adelton
Copy link
Contributor Author

adelton commented Aug 23, 2017

can we get a test that ensures the bootstrapped sccs sort in the expected order so we can protect against that in the future?

Should that test go to pkg/cmd/server/bootstrappolicy/securitycontextconstraints_test.go or pkg/security/securitycontextconstraints/byrestrictions_test.go (or elsewhere)?

@pweil-
Copy link
Contributor

pweil- commented Aug 23, 2017

I'm fine with it in the byrestrictions_test.go since it's pretty tightly coupled with that code.

@php-coder
Copy link
Contributor

Should that test go to pkg/cmd/server/bootstrappolicy/securitycontextconstraints_test.go or pkg/security/securitycontextconstraints/byrestrictions_test.go (or elsewhere)?

They should be in pkg/cmd/server/bootstrappolicy/securitycontextconstraints_test.go.

@php-coder
Copy link
Contributor

I'm fine with it in the byrestrictions_test.go since it's pretty tightly coupled with that code.

My point is that we're testing not how ByPriority sorts items but application behavior. So the test in securitycontextconstraints_test.go is like an integration test and ensures that if we modify ByPriority it will tell us whether we're breaking the backward compatibility or not.

@adelton
Copy link
Contributor Author

adelton commented Aug 23, 2017

Please see #15923 for the current order test.

@pweil-
Copy link
Contributor

pweil- commented Aug 23, 2017

Please see #15923 for the current order test.

Awesome, thanks. Let's get that one merged then we can merge this one since we've proven it works as expected

openshift-merge-robot added a commit that referenced this pull request Sep 7, 2017
Automatic merge from submit-queue (batch tested with PRs 15923, 16172)

Check the order of bootstrapped SCCs.

Related to #14530 and #14825.

Cc @simo5 @openshift/sig-security
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

@php-coder
Copy link
Contributor

Now, when #15923 was merged we can merge this one.

@smarterclayton PTAL

@enj
Copy link
Contributor

enj commented Sep 7, 2017

/lgtm

@openshift-merge-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adelton, enj, 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
@enj
Copy link
Contributor

enj commented Sep 7, 2017

I believe this has been discussed to death on IRC and BJ already.

@php-coder @adelton I will let you guys handle the test updates.

@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 14825, 15756, 16178, 16188, 16189)

@openshift-merge-robot openshift-merge-robot merged commit a2020c3 into openshift:master Sep 7, 2017
@adelton adelton deleted the issue-14530 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.