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: recognize that SELinux levels can be logically equivalent #16432

Conversation

php-coder
Copy link
Contributor

@php-coder php-coder commented Sep 19, 2017

For example: s0:c0,c6 is the same as s0:c6,c0

Fixes #15627

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 19, 2017
@adelton
Copy link
Contributor

adelton commented Sep 19, 2017

We should be able to support ranges, like s0-s0:c0.c255. Also, the categories shouldn't be sorted as strings as the numerical part can have multiple digits.

I'm also not sure that we are looking for equality here -- don't we look for dominance and superset instead?

@php-coder
Copy link
Contributor Author

We should be able to support ranges, like s0-s0:c0.c255.

Ok, I'll add it.

Also, the categories shouldn't be sorted as strings as the numerical part can have multiple digits.

It doesn't matter how they are sorted as we're sorting both parts. In other words, the sorting logic doesn't affect the result.

@php-coder
Copy link
Contributor Author

We should be able to support ranges, like s0-s0:c0.c255.

Added. @adelton PTAL

@php-coder
Copy link
Contributor Author

/retest

@adelton
Copy link
Contributor

adelton commented Sep 25, 2017

It doesn't matter how they are sorted as we're sorting both parts. In other words, the sorting logic doesn't affect the result.

But are we really looking for equality? IMHO, s0:c0.c2 should admit pod which asks for s0:c1, shouldn't it?

@rhatdan
Copy link
Contributor

rhatdan commented Sep 25, 2017

I think we should omit single category labels altogether. People understand the uniqueness, they don't understand dominance. MCS Separation has a hidden secret, dominance. In order to stop people confusion we should stick to a single count of Categories, and guarantee uniqueness.

@php-coder
Copy link
Contributor Author

@adelton @rhatdan I don't understand what are you talking about unfortunately :( If you want me to edit this PR somehow then could you be more specific, please?

func parseCategories(categories string) []string {
parts := strings.Split(categories, ",")

// "c0.c3" => [ "c0", "c1", "c2", c3" ]
Copy link
Contributor

Choose a reason for hiding this comment

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

why isn't this

categories := strings.Split('.')
sort.Strings(categories)

? Why are you go into deeper parsing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see that this is an expansion. Please add godoc to the method

expectedSeLinux: newValidOpts(),
expectedMsg: "",
},
"valid level with abbreviated categories": { // "s0:c0.c3" == "s0:c0,c1,c2,c3"
Copy link
Contributor

Choose a reason for hiding this comment

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

need some additional tests, test edges cases and multiple equivalences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "multiple equivalences"?

Copy link
Contributor

@Miciah Miciah left a comment

Choose a reason for hiding this comment

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

Maybe the parseFoo functions would be better named canonicalizeFoo, assuming I correctly understand the intent.

func parseCategories(categories string) []string {
parts := strings.Split(categories, ",")

// "c0.c3" => [ "c0", "c1", "c2", c3" ]
Copy link
Contributor

Choose a reason for hiding this comment

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

s/c3"/"c3"/

if err1 == nil && err2 == nil && from < to {
parts = make([]string, to-from+1)
for i := from; i <= to; i++ {
parts[i] = fmt.Sprintf("c%d", i)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will go out of bounds if categoryRange[0] is not c0 (e.g., parseCategories("c1.c4") panics—might be a good test case). You cannot use the same variable for the index and the format, at least not without some arithmetic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Miciah Indeed, good catch, thanks!

@php-coder php-coder force-pushed the gh15627_scc_and_selinux_levels branch 2 times, most recently from b08f614 to 4d85ee1 Compare October 3, 2017 18:14
@php-coder
Copy link
Contributor Author

More code and tests were added. Feedback is highly appreciated!

@php-coder php-coder force-pushed the gh15627_scc_and_selinux_levels branch from 4d85ee1 to 3ff59a9 Compare October 9, 2017 14:44
@php-coder
Copy link
Contributor Author

Test flake #14085
/test extended_conformance_gce

@php-coder
Copy link
Contributor Author

Test flake #16402
/test cmd

@php-coder
Copy link
Contributor Author

Bug in Kubernetes: kubernetes/kubernetes#53590
/test origin-ut

@php-coder
Copy link
Contributor Author

@openshift/sig-security PTAL

@php-coder
Copy link
Contributor Author

Ping.

@adelton
Copy link
Contributor

adelton commented Oct 17, 2017

In general, my question is if the SCC allows c0.c4 and the pod asks for c0, should it be permitted or not?

@php-coder php-coder force-pushed the gh15627_scc_and_selinux_levels branch from 3ff59a9 to 7f13165 Compare October 23, 2017 15:27
@php-coder
Copy link
Contributor Author

php-coder commented Oct 23, 2017

In general, my question is if the SCC allows c0.c4 and the pod asks for c0, should it be permitted or not?

<semushin> pweil, WDYT? Sounds like yes, a pod should be permitted; but it could be a case for another PR.
<pweil> semushin, yes, I think that would match, probably a lower priority follow up

@adelton Could you create an issue (or even a PR) for that?

@eparis
Copy link
Member

eparis commented Oct 23, 2017

What dan is saying in #16432 (comment) is that you should NOT try to determine dominance or any special relationship between category sets. That is all policy and you can't know what policy says. Some policies may have very wierd inter-relations between level and category sets. Please only account of exact equivalence.

This really needs to be a libselinux function :-(

@stephensmalley I can't find a libselinux function to really help us. We just want to know is the string s-s0:c1,c2,c3 the same as so:c1.c3. I was hoping that a combination of context_new, context_str and selinux_file_context_cmp could be used to get this answer but it doesn't look like we have anything which does some form of semantic category normalization...

So maybe this PR is the best thing we can do.

@openshift openshift deleted a comment from php-coder Oct 23, 2017
@stephensmalley
Copy link

stephensmalley commented Oct 23, 2017

security_canonicalize_context(3) from libselinux. Oddly, no man page.
Sample usage:

$ cat canon.c
#include <selinux/selinux.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
	const char *ctx;
	char *canoncon;
	int rc;

	ctx = argv[1];
	rc = security_canonicalize_context(ctx, &canoncon);
	if (rc < 0)
		perror(ctx);
	else {
		printf("%s\n", canoncon);
		free(canoncon);
	}
	exit(rc);
}
$ make LDLIBS+=-lselinux canon
$ $ ./canon unconfined_u:unconfined_r:unconfined_t:s0:c0,c1,c2
unconfined_u:unconfined_r:unconfined_t:s0:c0.c2

@openshift-merge-robot openshift-merge-robot added the vendor-update Touching vendor dir or related files label Jan 25, 2018
@php-coder
Copy link
Contributor Author

The PR has been updated. In order to merge in the upstream, it was decided to make it as simple as possible and solve only the original issue with ordering. No support for ranges and expansion at this point.

@openshift/sig-security PTAL


"k8s.io/apimachinery/pkg/util/validation/field"
api "k8s.io/kubernetes/pkg/apis/core"
psputil "k8s.io/kubernetes/pkg/security/podsecuritypolicy/util"
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 decided to use PSP's utils instead of duplicating them. That's why this PR has vendor-update tag.

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.

@php-coder do you think there is any benefit to just using the PSP strategy that is going to merge upstream for the comparison functions? They're just taking strings so it isn't type specific. It would require a change to the upstream PR but would reduce duplication here if we went that route. WDYT?

In any case this matches upstream and is LGTM

@simo5
Copy link
Contributor

simo5 commented Jan 25, 2018

@pweil- given we will eventually migrate away from SCC to PSP, I think I prefer to just copy here for now, or we'll have public functions in PSP that are used by nothing but PSP once we drop SCC. Also any change to PSP would end up with more maintenance to keep SCC working until we can drop it.
So IMO it is good as proposed.

@simo5
Copy link
Contributor

simo5 commented Jan 25, 2018

Actually I would even endorse copying the psputil function as a private function for mustrunas.go and avoid the vendoring warnings.

@pweil-
Copy link
Contributor

pweil- commented Jan 25, 2018

@pweil- given we will eventually migrate away from SCC to PSP, I think I prefer to just copy here for now, or we'll have public functions in PSP that are used by nothing but PSP once we drop SCC. Also any change to PSP would end up with more maintenance to keep SCC working until we can drop it.
So IMO it is good as proposed.

I'm ok with this strategy, however if the comparisons were exposed in psputil and used then any changes we do upstream to enhance it wouldn't have to be copied, we'd just get them upon rebase. It is also not something we'd need to do an in depth review on when we decide to migrate to make sure we're not missing a difference. That burden is on your team though so it's your call. 👍

@php-coder php-coder force-pushed the gh15627_scc_and_selinux_levels branch from 84d7867 to bcd5b33 Compare January 25, 2018 14:02
@openshift-merge-robot openshift-merge-robot removed the vendor-update Touching vendor dir or related files label Jan 25, 2018
@php-coder
Copy link
Contributor Author

@pweil- @simo5 Thanks for the feedback!

I updated the PR and removed the dependency to PSP's util package.

@simo5
Copy link
Contributor

simo5 commented Jan 25, 2018

/lgtm

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 25, 2018
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.

/lgtm

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: php-coder, pweil-, simo5

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

@php-coder
Copy link
Contributor Author

/test gcp

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@php-coder
Copy link
Contributor Author

/test gcp

@openshift-merge-robot
Copy link
Contributor

/test all [submit-queue is verifying that this PR is safe to merge]

@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 16432, 18308, 18311).

@openshift-merge-robot openshift-merge-robot merged commit 3a9bec1 into openshift:master Jan 27, 2018
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jan 27, 2018

@php-coder: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/openshift-jenkins/gcp bcd5b33 link /test gcp

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@php-coder php-coder deleted the gh15627_scc_and_selinux_levels branch January 28, 2018 22:15
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. sig/security 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.