-
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: add AllowedFlexVolumes to manage a whitelist of allowed flexvolumes drivers #15558
SCC: add AllowedFlexVolumes to manage a whitelist of allowed flexvolumes drivers #15558
Conversation
f18f739
to
785e94c
Compare
@stevekuznetsov is there an easy way to trigger auto-labeling when a types.go file is modified? |
@@ -81,6 +81,9 @@ type SecurityContextConstraints struct { | |||
// used to generate a value for a pod the first non-wildcard profile will be used as | |||
// the default. | |||
SeccompProfiles []string `json:"seccompProfiles,omitempty" protobuf:"bytes,20,opt,name=seccompProfiles"` | |||
// AllowedFlexDrivers is a whitelist of allowed Flexvolume drivers. | |||
// Empty or nil indicates that all drivers may be used. | |||
AllowedFlexDrivers []string `json:"allowedFlexDrivers" protobuf:"bytes,21,opt,name=allowedFlexDrivers"` |
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.
So this field is used when the user already has flexVolume power right? If they don't, then this is never used?
If that's the case, I'd expect a validation rule and some more detail in the doc. Also, why not move up underneath Volumes
? The proto number can still be 21 up there.
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.
So this field is used when the user already has flexVolume power right? If they don't, then this is never used?
Correct.
If that's the case, I'd expect a validation rule and some more detail in the doc.
At present, it's possible to have non-empty AllowedFlexDrivers
and prohibited the usage of flexVolumes at the same time. Should we add validation to that case, and force user to have an empty AllowedFlexDrivers
?
Also, why not move up underneath Volumes? The proto number can still be 21 up there.
Hm. It's not clear what do you mean, so I put AllowedFlexDrivers
field right after Volumes
in the pkg/security/apis/security/types.go
file. I left the order the same in pkg/security/apis/security/v1/types.go
file, let me know if you want to see it updated too.
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.
Also, why not move up underneath Volumes?
Got it. Done.
allErrs = append(allErrs, field.Invalid( | ||
fldPath.Child("volumes").Index(i), string(fsType), | ||
fmt.Sprintf("%s volumes are not allowed to be used", string(fsType)))) | ||
if len(s.scc.AllowedFlexDrivers) > 0 && sccutil.SCCAllowsFSType(s.scc, securityapi.FSTypeFlexVolume) { |
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.
if the SCC doesn't allow flex volumes and you have any, wouldn't have already put errors on the return?
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'm sorry but I didn't understand what you mean here :(
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.
if the volume type is completely disallowed, line 306 would already have added an error. there's no need to add another error saying the specific flex driver is not allowed. making a single loop over all the volumes would let you short-circuit adding specific errors if there are general ones.
allowAllVolumeTypes := sccutil.SCCAllowsAllVolumes(s.scc)
allowedVolumeTypes := sccutil.FSTypeToStringSet(s.scc.Volumes)
for i, v := range pod.Spec.Volumes {
fsType, err := sccutil.GetVolumeFSType(v)
if err != nil {
... add the error...
continue
}
if !allowAllVolumeTypes && !allowedVolumes.Has(string(fsType)) {
... add an error about this volume type not being allowed...
continue
}
if v.FlexVolume != nil && len(s.scc.AllowedFlexDrivers) > 0 {
... ensure the particular flex volume is allowed...
}
}
|
||
for _, allowedDriver := range s.scc.AllowedFlexDrivers { | ||
driver := v.FlexVolume.Driver | ||
if driver != allowedDriver { |
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.
doesn't this mean that if I allow ["foo", "bar"]
and request one with "bar"
, I'll get an error even though I'm allowed? How about adding some tests here.
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.
Good catch, thanks! It's fixed now. I'll add tests after passing API review.
@deads2k yes IIRC |
Yes, there is. Will work on it today or tomorrow. |
785e94c
to
110dacd
Compare
pkg/security/apis/security/types.go
Outdated
// AllowedFlexDrivers is a whitelist of allowed Flexvolume drivers. | ||
// Empty or nil indicates that all drivers may be used. | ||
// +optional | ||
AllowedFlexDrivers []string |
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.
making this an array of structs lets us expand options in the future (like setting the readOnly option), similar to the discussion around allowedHostPaths.
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.
Fixed.
bd56ef8
to
7578913
Compare
pkg/oc/cli/describe/describer.go
Outdated
@@ -1865,6 +1866,13 @@ func stringOrNone(s string) string { | |||
return "<none>" |
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.
nit: change this to call stringOrDefaultValue
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.
Fixed.
7578913
to
dd7dc45
Compare
How to fix the following error?
I tried to run |
|
dd7dc45
to
44c1f27
Compare
Test flake #10327 |
44c1f27
to
adf7679
Compare
Examples:
|
c726ddb
to
f67f171
Compare
Test flake #15900
Test fake #16144
/test extended_conformance_install_update |
For testing this pull request, I try to create SCC with
but I get
What is the correct way to specify the list of drivers? |
@adelton Try this one: allowedFlexVolumes:
- driver: jezek |
/retest |
Thanks. Would it make sense to amend the documentation to show this syntax? |
The Trello card has |
From functional perspective, this feature works. My only concern is an extremely long and not really helpful error message when I try to create pod with flexVolume and the driver is not listed in
|
That's a pre-existing issue with the way SCC admission presents failures. A separate issue to improve that is probably a good idea. |
It looks like a regression or a wrong merge. I'll look at it today more closely. |
It looks normal to me (needs improvement, but normal). You get an error message for every SCC you have access to that does not allow flex volumes. |
@adelton I couldn't reproduce it. In my case the error is the following:
|
End-to-end tests fails because of #16144 |
/approve @enj you own merge. |
/lgtm No logic changes since last LGTM. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, 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 |
/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. |
If you create bunch of differently named copies of
|
Aha, I see. This is indeed a different case. Please, create a separate issue for that. Thanks! |
/retest Please review the full test history for this PR and help us cut down flakes. |
Automatic merge from submit-queue |
Proposal: kubernetes/community#723
Trello: https://trello.com/c/YT6sNEay/61-5-sccfsi-psp-scc-flex-volume-support
Examples: #15558 (comment)