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

Allow PSP's to specify a whitelist of allowed paths for host volume #50212

Merged
merged 2 commits into from
Sep 1, 2017

Conversation

jhorwit2
Copy link
Contributor

@jhorwit2 jhorwit2 commented Aug 6, 2017

What this PR does / why we need it:

Reverts the revert for the allowed host path feature that was moved from v1.7 to v1.8. This PR also changes the api as discussed in #47811.

Original pr: #43946
revert: #47851

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #29326

Special notes for your reviewer:

cc @liggitt @ericchiang @php-coder

It seems the api build process has changed. Hopefully I did it right 👼 .

Release note:

Allow PSP's to specify a whitelist of allowed paths for host volume

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 6, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @jhorwit2. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

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.

@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Aug 6, 2017
@sttts
Copy link
Contributor

sttts commented Aug 7, 2017

/unassign
/assign @derekwaynecarr

@k8s-ci-robot k8s-ci-robot assigned derekwaynecarr and unassigned sttts Aug 7, 2017
@php-coder
Copy link
Contributor

CC @pweil-

if !psputil.PSPAllowsHostVolumePath(s.psp, v.HostPath.Path) {
allErrs = append(allErrs, field.Invalid(
field.NewPath("spec", "volumes").Index(i), string(fsType),
fmt.Sprintf("host path %s is not allowed to be used. allowed host paths", v.HostPath.Path)))
Copy link
Contributor

Choose a reason for hiding this comment

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

"host path %s is not allowed to be used. allowed host paths" -> "host path %s is not allowed to be used"

continue
}

if fsType == extensions.HostPath {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this check will be triggered only when volumes not equal to *. This is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I updated the PR.

for k, v := range tests {
allows := PSPAllowsHostVolumePath(v.psp, v.path)
if v.allows != allows {
t.Errorf("%s expected PSPAllowsHostVolumePath to return %t but got %t", k, v.allows, allows)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/PSPAllowsHostVolumePath//

}

// AllowedHostPath defines the host volume conditions that will be enabled by a policy
// for pods to use. It requires the path to be defined.
Copy link
Contributor

Choose a reason for hiding this comment

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

"It requires the path to be defined." Code for validating this scenario is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

// for pods to use. It requires the path to be defined.
type AllowedHostPath struct {
// Path is the path prefix that the host volume must match
Path string
Copy link
Contributor

Choose a reason for hiding this comment

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

It's confusing me that we use path anywhere but we mean "path prefix" really.

@jhorwit2 @pweil- @liggitt Maybe we should rename the fields? For example, it can be named AllowedHostPathPrefixes.

Copy link
Member

Choose a reason for hiding this comment

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

could name the field PathPrefix, the parent should remain AllowedHostPath

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


// PSPAllowsHostVolumePath is a utility for checking if a PSP allows the host volume path.
// This only checks the path. You should still check to make sure the host volume fs type is allowed.
func PSPAllowsHostVolumePath(psp *extensions.PodSecurityPolicy, hostPath string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it mandatory to use PSP in the function name? I don't see a reason for that. psputil.AllowsHostVolumePath() looks good to me either.

@jhorwit2 jhorwit2 force-pushed the jah/psp-hostpath branch 3 times, most recently from d7ec40a to 2c3925b Compare August 11, 2017 00:44
@jhorwit2
Copy link
Contributor Author

@liggitt @php-coder i've addressed all the major concerns. Could someone please enable the test suite for me 👼

@ericchiang
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 11, 2017
@jhorwit2
Copy link
Contributor Author

jhorwit2 commented Aug 11, 2017 via email

@jhorwit2
Copy link
Contributor Author

Is there anyone else that should review this? Tests all look good.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 16, 2017
@jhorwit2
Copy link
Contributor Author

@bgrant0607 @liggitt it should all be good now!

@liggitt liggitt assigned liggitt and ericchiang and unassigned jianhuiz and derekwaynecarr Aug 25, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 26, 2017
@jhorwit2
Copy link
Contributor Author

jhorwit2 commented Aug 26, 2017 via email

@smarterclayton
Copy link
Contributor

Spawned #51422 for the checker

@jhorwit2
Copy link
Contributor Author

Is there anyone else that should review this? I was told we wanted this in for 1.8 so i just want to make sure we meet code freeze.

@liggitt
Copy link
Member

liggitt commented Aug 27, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 27, 2017
@jhorwit2
Copy link
Contributor Author

@smarterclayton @ericchiang @liggitt do we still plan to make this before code freeze?

@liggitt
Copy link
Member

liggitt commented Aug 30, 2017

adding @smarterclayton for docs/ pkg/ approval

@liggitt
Copy link
Member

liggitt commented Aug 30, 2017

/test pull-kubernetes-bazel-build
/test pull-kubernetes-bazel-test

@smarterclayton
Copy link
Contributor

/approve

based on the history and comments in this thread and previous approval in last release

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jhorwit2, liggitt, smarterclayton

Associated issue: 29326

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

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 30, 2017
@jhorwit2
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-etcd3
/test pull-kubernetes-e2e-kops-aws

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 50719, 51216, 50212, 51408, 51381)

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/auth Categorizes an issue or PR as relevant to SIG Auth. 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.

Pods should not be able to mount arbitrary host volumes