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

Add RBAC policies for NetworkPolicy #56650

Merged
merged 1 commit into from
Dec 16, 2017

Conversation

danwinship
Copy link
Contributor

What this PR does / why we need it:
When using RBAC, none of the namespace-level roles currently have permission to do anything with NetworkPolicy. (Only cluster-admin does, by virtue of having permission on "*".) This fixes it so "admin" and "edit" have read/write permission, and "view" has read-only permission.

I added permission for both the extensions and networking objects, which I believe is correct as long as both of them exist?

(This would be nice to fix in 1.9, although it's not a regression. It's always been broken.)

Release note:

When using Role-Based Access Control, the "admin", "edit", and "view" roles now have the expected permissions on NetworkPolicy resources.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 30, 2017
@danwinship
Copy link
Contributor Author

@soltysh (re openshift/origin#17491)
@deads2k This is what's breaking test_branch_origin_extended_networking

@liggitt
Copy link
Member

liggitt commented Nov 30, 2017

Are namespace constrained users expected to have write access to network policy? Or is that a tool for the cluster administrator to optionally grant?

@danwinship
Copy link
Contributor Author

NetworkPolicy was specifically designed to be used by namespace admins. (They give you the power to keep other users out of your namespace, but don't give you the power to get into other users' namespaces or anything like that.) (And these policies match what we do in OpenShift.)

I guess in theory a cluster admin might want to create a policy like "allow connections from pods in the magic-admin-can-connect-to-everything namespace" in each namespace and then not let namespace admins delete it. But I don't think that's much different from "in theory a cluster admin might want to create a pod/service and not let the namespace admin delete it".

@ericchiang
Copy link
Contributor

Naively, I would have expected a common network policy to be something like "don't let pods hit the AWS metadata service" to prevent pods from getting node credentials. That seems like something a cluster admin wouldn't want a user in a namespace to be able to get around.

@liggitt
Copy link
Member

liggitt commented Nov 30, 2017

Does network policy not control egress as well?

@danwinship
Copy link
Contributor Author

NetworkPolicy can control egress now, but the feature is explicitly described as being for namespace-admin use, not for cluster-admin use. Well, OK, actually it's not documented very well, but it that's how it was always discussed and how it was designed. The use case it solves is

As a project administrator/developer I want to ensure that my pods only make outgoing connections to the pods/services/IPs they are expected to connect to, so that if hackers break into my pods, they can’t use them to attack arbitrary targets.

and not

As the administrator of a kubernetes cluster, I want to allow some pods/namespaces to access certain restricted IP addresses, but not allow all pods to access all IPs; and project admins and developers must not be able to override these rules.

which we discussed but assumed we couldn't implement with NetworkPolicy because we were still thinking in a pre-RBAC mindset where there is no one (within the Kubernetes API) more powerful than a namespace admin. If we implement that use case later, it would be via a separate resource type, because the expectation with NetworkPolicies has always been that namespace admins have complete control over NetworkPolicies in their namespace.

(Use cases from this doc.)

@danwinship
Copy link
Contributor Author

@thockin can you confirm that I'm representing the intent of NetworkPolicy correctly? (That namespace admins are expected to have complete control over NetworkPolicies in their namespaces.)

@liggitt
Copy link
Member

liggitt commented Dec 6, 2017

@kubernetes/sig-auth-pr-reviews @kubernetes/sig-network-pr-reviews

@k8s-ci-robot k8s-ci-robot added sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/network Categorizes an issue or PR as relevant to SIG Network. labels Dec 6, 2017
@liggitt
Copy link
Member

liggitt commented Dec 6, 2017

@thockin can you confirm that I'm representing the intent of NetworkPolicy correctly? (That namespace admins are expected to have complete control over NetworkPolicies in their namespaces.)

talked with @thockin, and that was the intent (the app owner controls network policy for their app). if we want a control for the cluster-admin to lock down namespaces, that's likely to be represented as a separate resource (possibly cluster-scoped, possibly namespace-selecting, etc)

@liggitt
Copy link
Member

liggitt commented Dec 6, 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 Dec 6, 2017
@kubernetes kubernetes deleted a comment from k8s-github-robot Dec 6, 2017
@liggitt
Copy link
Member

liggitt commented Dec 6, 2017

/approve no-issue

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danwinship, liggitt

Associated issue requirement bypassed by: liggitt

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-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 6, 2017
openshift-merge-robot added a commit to openshift/origin that referenced this pull request Dec 15, 2017
Automatic merge from submit-queue (batch tested with PRs 17549, 17785).

NetworkPolicy RBAC fixes

As part of the k8s 1.8 rebase, the NetworkPolicy code was changed to use networking.NetworkPolicy rather than extensions.NetworkPolicy, but the roles weren't updated to have the right permissions.. (This wasn't caught because only extended-networking-minimal gets run on PRs by default, and that only tests multitenant.)

Fixes test_branch_origin_extended_networking 

(kubernetes/kubernetes#56650 hasn't actually merged yet.)
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Dec 16, 2017

@danwinship: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-gce-device-plugin-gpu ac336a6 link /test pull-kubernetes-e2e-gce-device-plugin-gpu

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.

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 7f87337 into kubernetes:master Dec 16, 2017
@danwinship danwinship deleted the networkpolicy-rbac branch March 26, 2018 13:30
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. 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. sig/network Categorizes an issue or PR as relevant to SIG Network. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants