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

move kube-dns to a separate service account #38816

Merged

Conversation

deads2k
Copy link
Contributor

@deads2k deads2k commented Dec 15, 2016

Switches the kubedns addon to run as a separate service account so that we can subdivide RBAC permission for it. The RBAC permissions will need a little more refinement which I'm expecting to find in #38626 .

@cjcullen @kubernetes/sig-auth since this is directly related to enabling RBAC with subdivided permissions
@thockin @kubernetes/sig-network since this directly affects now kubedns is added.

`kube-dns` now runs using a separate `system:serviceaccount:kube-system:kube-dns` service account which is automatically bound to the correct RBAC permissions.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 15, 2016
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 15, 2016
// a role to use for the kube-dns pod
ObjectMeta: api.ObjectMeta{Name: "system:kube-dns"},
Rules: []rbac.PolicyRule{
rbac.NewRule("list", "watch").Groups(legacyGroup).Resources("endpoints", "services").RuleOrDie(),
Copy link
Member

Choose a reason for hiding this comment

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

Would kube-dns have the permission to fetch ConfigMap in general with this setup? Fetching ConfigMap might not be a right permission for kube-dns but we introduced it (#36775) as a short term fix for the federation issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would kube-dns have the permission to fetch ConfigMap in general with this setup? Fetching ConfigMap might not be a right permission for kube-dns but we introduced it (#36775) as a short term fix for the federation issue.

Like I've set it up here, no. I saw that access and assumed it was a bug. This role is a good starting point and we can have a separate pull to add questionable permissions.

Copy link
Member

Choose a reason for hiding this comment

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

If we get the optional config maps in 1.6, we won't need that permission, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we get the optional config maps in 1.6, we won't need that permission, right?

The configmap permission could be done as a secondary, optional role attached to your service account. A cluster-admin could add it if he needed the feature. We've done that with a few permissions in openshift. There's a base role that works 90% of the time and if you need more power, you grant more power with a second role: opt-in.

@davidopp
Copy link
Member

@deads2k Just for my edification, can you explain what RBAC with subdivided permissions means? (And how it related to this PR.) Or if there is something written up, can you point me to it?

@deads2k
Copy link
Contributor Author

deads2k commented Dec 15, 2016

@deads2k Just for my edification, can you explain what RBAC with subdivided permissions means? (And how it related to this PR.) Or if there is something written up, can you point me to it?

RBAC is an authorizer described here: http://kubernetes.io/docs/admin/authorization/ . It allows you to control permissions based on roles (examples in the doc). By more tightly controlling roles for controllers and powerful components, we can prevent bugs or exploits from causing excessive damage. One of our requirements for beta here: https://docs.google.com/document/d/1woLGRoONE3EBVx-wTb4pvp4CI7tmLZ6lS26VTbosLKM/edit?ts=570fa5c5#heading=h.9kaxh998i32c is to tighten permissions on our components. I found this one by inspecting which subject was making requests without RBAC permissions.

In order to create a role and bind it to a proper subject, the subject running the kube-dns needs to separated from other components. This attempts to start that separation.

@davidopp
Copy link
Member

So this can be used to reduce the power that stuff running in the context of the DNS pod has, in terms of operations on the Kubernetes API objects?

@deads2k
Copy link
Contributor Author

deads2k commented Dec 15, 2016

So this can be used to reduce the power that stuff running in the context of the DNS pod has, in terms of operations on the Kubernetes API objects?

Correct.

@thockin
Copy link
Member

thockin commented Dec 15, 2016 via email

@bowei
Copy link
Member

bowei commented Dec 17, 2016

change looks ok to me modulo the configmap issue

@liggitt
Copy link
Member

liggitt commented Dec 19, 2016

For the time being DNS needs to be able to access configmaps.

Rather than expanding the role to include permissions that don't make sense, I'd rather see the work done to support optional configmaps and/or addon tolerating existing objects. That is landing in 1.6, right?

@deads2k
Copy link
Contributor Author

deads2k commented Dec 19, 2016

Rather than expanding the role to include permissions that don't make sense, I'd rather see the work done to support optional configmaps and/or addon tolerating existing objects. That is landing in 1.6, right?

The permissions are for 1.6. Knowing now what this is for, I agree that adding the permission is the wrong approach.

@thockin
Copy link
Member

thockin commented Dec 22, 2016 via email

@deads2k
Copy link
Contributor Author

deads2k commented Dec 22, 2016

In the interim, DNS doesn't work on HEAD?

I think so. We'd create a P1 bug and perhaps provide a manual workaround (adding a new role and binding), but expanding SA rights against the recommended way to use the platform isn't something I want to propagate in our bootstrap authorization rules.

@bowei
Copy link
Member

bowei commented Dec 22, 2016

This seems to be the wrong order of commits. I would prefer not to break HEAD due to a forward dependency on two features (optional configmaps + kube-dns support). Can this PR not wait until those features have been committed?

I am concerned about confusion involving kube-dns in the interim period. Anyone debugging issues would have to know about the breakage + fix.

@thockin
Copy link
Member

thockin commented Dec 22, 2016

+1. This PR can wait until the rest are done, then. We don't (knowingly) break head like this.

@liggitt
Copy link
Member

liggitt commented Dec 22, 2016

I'd rather hold this PR then set up an overly broad role for kube DNS

@liggitt
Copy link
Member

liggitt commented Dec 22, 2016

actually, isn't kube-dns broken in HEAD today with authorization enabled if it is assuming it has access to all configmaps? seems like the instructions to make kube-dns use a configmap could include granting authorization to read that configmap

@deads2k
Copy link
Contributor Author

deads2k commented Dec 22, 2016

actually, isn't kube-dns broken in HEAD today with authorization enabled if it is assuming it has access to all configmaps? seems like the instructions to make kube-dns use a configmap could include granting authorization to read that configmap

It breaks as soon as you stop granting all permissions to service accounts, which is a permission that should definitely be removed. API security that equates the power to create a pod with root power against the API isn't very effective.

@luxas
Copy link
Member

luxas commented Jan 16, 2017

Any chance we could give kube-dns the configmap permission for now with a P1 issue that explains why and when we should do it the right way when we can? (I know, I know, long-term it's the wrong thing to do, but anyway?)

I think it was suggested already, but that's what I think should do, in order to get this merged.

@liggitt
Copy link
Member

liggitt commented Jan 16, 2017

you can give it the configmap permission with a second namespaced role grant already:

kubectl create rolebinding kube-dns-configmap-binding \
  --clusterrole=view \
  --namespace=my-configmap-namespace \
  --serviceaccount=kube-system:kube-dns

I wouldn't want to add a global configmap permission to this role

@luxas
Copy link
Member

luxas commented Jan 16, 2017

@liggitt Yes, so why don't we do that for now along with an issue to completely remove that dep?

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] Needs approval from an approver in each of these OWNERS Files:

We suggest the following people:
cc @zmerlynn @erictune
You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@deads2k
Copy link
Contributor Author

deads2k commented Feb 16, 2017

These scripts are a nightmare. Somehow this pull is breaking either the authn or authz setup.

@@ -1195,8 +1195,10 @@ function start-kube-addons {
setup-addon-manifests "addons" "dns"
local -r dns_controller_file="${dst_dir}/dns/kubedns-controller.yaml"
local -r dns_svc_file="${dst_dir}/dns/kubedns-svc.yaml"
local -r dns_sa_file="${dst_dir}/dns/kubedns-sa.yaml"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I'm betting I borked the add-on manager somehow. @cjcullen @ncdc @mikedanese anything obvious?

Copy link
Member

Choose a reason for hiding this comment

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

I think you don't need this line local -r dns_sa_file="${dst_dir}/dns/kubedns-sa.yaml", because setup-addon-manifests "addons" "dns" already copy all the files.

And it seems like "kube-addon-manager.yaml" is not copied on to the master, which means start_kube_addons() met some errors in the middle.

mv "${dst_dir}/dns/kubedns-controller.yaml.in" "${dns_controller_file}"
mv "${dst_dir}/dns/kubedns-svc.yaml.in" "${dns_svc_file}"
mv "${dst_dir}/dns/kubedns-sa.yaml" "${dns_sa_file}"
Copy link
Member

Choose a reason for hiding this comment

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

I think you are moving "${dst_dir}/dns/kubedns-sa.yaml" into "${dst_dir}/dns/kubedns-sa.yaml", which are the same file, so it broke.

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 think you are moving "${dst_dir}/dns/kubedns-sa.yaml" into "${dst_dir}/dns/kubedns-sa.yaml", which are the same file, so it broke.

Thanks!

@luxas
Copy link
Member

luxas commented Feb 17, 2017

@k8s-bot kops aws e2e test this

@luxas luxas added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Feb 17, 2017
@luxas
Copy link
Member

luxas commented Feb 17, 2017

@deads2k Super cool to have this PR green!
Please fill in a relnote and I think @erictune and @bowei will merge this

@liggitt
Copy link
Member

liggitt commented Feb 17, 2017

@deads2k I've seen some of the other addons include the service account in the same yaml file as a separate record... would remove the need for any of the script changes, and make it so anyone else who was using the add-on would get the change automatically.

Copy link
Member

@bowei bowei left a comment

Choose a reason for hiding this comment

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

/approve

@luxas luxas added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 19, 2017
@luxas
Copy link
Member

luxas commented Feb 19, 2017

@bowei approved this, added the label (/approve doesn't work in a review comment I think)

@liggitt @bowei @erictune Can we get this /lgtm'd as well?
It would be super-cool to get this into v1.6.0-alpha.4 which is cut on Monday

@luxas
Copy link
Member

luxas commented Feb 19, 2017

@deads2k please squash though

@liggitt liggitt added this to the v1.6 milestone Feb 19, 2017
@deads2k
Copy link
Contributor Author

deads2k commented Feb 20, 2017

Squashed. Didn't add the SA to the RC file. Is that a thing we want to do? Seems a little weird.

@liggitt
Copy link
Member

liggitt commented Feb 20, 2017

Squashed. Didn't add the SA to the RC file. Is that a thing we want to do? Seems a little weird.

I don't feel strongly either way

@liggitt
Copy link
Member

liggitt commented Feb 22, 2017

tagging per #38816 (review) #38816 (review)

@liggitt liggitt added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 22, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit b799bbf into kubernetes:master Feb 23, 2017
@deads2k deads2k deleted the rbac-23-switch-kubedns-sa branch March 7, 2017 20:05
k8s-github-robot pushed a commit that referenced this pull request Mar 29, 2017
Automatic merge from submit-queue

Moves dns-horizontal-autoscaler to a separate service account

Similar to #38816.

As one of the cluster add-ons, dns-horizontal-autoscaler is now using the default service account in kube-system namespace, which is introduced by https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/e2e-rbac-bindings/random-addon-grabbag.yaml for the ease of transition. This default service account will be removed in the future.

This PR subdivides dns-horizontal-autoscaler to a separate service account and setup the necessary permissions.

@bowei 

**Release note**:

```release-note
NONE
```
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. 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.

None yet