-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
SCC: recognize that SELinux levels can be logically equivalent #16432
Conversation
We should be able to support ranges, like I'm also not sure that we are looking for equality here -- don't we look for dominance and superset instead? |
Ok, I'll add it.
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. |
4513467
to
391aba5
Compare
Added. @adelton PTAL |
/retest |
But are we really looking for equality? IMHO, |
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. |
func parseCategories(categories string) []string { | ||
parts := strings.Split(categories, ",") | ||
|
||
// "c0.c3" => [ "c0", "c1", "c2", c3" ] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"?
There was a problem hiding this 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" ] |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
b08f614
to
4d85ee1
Compare
More code and tests were added. Feedback is highly appreciated! |
4d85ee1
to
3ff59a9
Compare
Test flake #14085 |
Test flake #16402 |
Bug in Kubernetes: kubernetes/kubernetes#53590 |
@openshift/sig-security PTAL |
Ping. |
In general, my question is if the SCC allows |
3ff59a9
to
7f13165
Compare
@adelton Could you create an issue (or even a PR) for that? |
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 So maybe this PR is the best thing we can do. |
security_canonicalize_context(3) from libselinux. Oddly, no man page. $ 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 |
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
@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. |
Actually I would even endorse copying the psputil function as a private function for mustrunas.go and avoid the vendoring warnings. |
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. 👍 |
…make its meaning obvious.
…tions configurable.
… to improve code coverage.
84d7867
to
bcd5b33
Compare
/lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[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 |
/test gcp |
/retest Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
/retest Please review the full test history for this PR and help us cut down flakes. |
/test gcp |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue (batch tested with PRs 16432, 18308, 18311). |
@php-coder: The following test failed, say
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. |
For example: s0:c0,c6 is the same as s0:c6,c0
Fixes #15627