Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

RBAC setup behind the aggregator. #936

Merged
merged 2 commits into from
Jul 17, 2017
Merged

RBAC setup behind the aggregator. #936

merged 2 commits into from
Jul 17, 2017

Conversation

MHBauer
Copy link
Contributor

@MHBauer MHBauer commented Jun 12, 2017

yaml was generated by putting rbac into permissive mode and seeing what it would have denied. then @liggitt processed the log messages to create the output and left some suggested TODOs.

@pmorie do you undestand the leader election TODOs?

Service accounts were done to see what each server was specificly doing. We can back that out and adapt the yaml.

Need to have the auth setup as in the auth docs.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 12, 2017
@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 12, 2017

@arschles @krancour can you help me understand if there's something I should be helm-izing and how to do it?

@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 13, 2017

resolves #880

@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 13, 2017

@kibbles-n-bytes is rbac on in jenkins CI? I'm not sure why this would fail over there.

- apiGroup: ""
kind: ServiceAccount
name: server
namespace: catalog
Copy link

Choose a reason for hiding this comment

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

Is this namespace right or does it need to be parameterized to match SVCCAT_NAMESPACE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unspecified assumption currently. Needs to be integrated into the helm chart to get parameterized.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MHBauer It would be best parameterized in the values.yaml file. Ping me if you want help with that

Copy link
Contributor

@arschles arschles left a comment

Choose a reason for hiding this comment

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

@MHBauer I think I answered a few helm questions, and I do think the namespace should at least be parameterized in the helm chart (even though that's separate from the shell scripts, it's a step in the right direction).

Also, I had a few additions to the markdown file.

Overall, this is great.

- apiGroup: ""
kind: ServiceAccount
name: server
namespace: catalog
Copy link
Contributor

Choose a reason for hiding this comment

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

After https://github.com/kubernetes-incubator/service-catalog/pull/936/files#r121578665 is done, this should read:

namespace: {{ .Values.namespace }}

- apiGroup: ""
kind: ServiceAccount
name: server
namespace: catalog
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here RE the parameterized namespace. There are some other similar changes below, but I won't comment on them all.

# RBAC Setup

If rbac is enabled, allow the service catalog to grant access for it's
service token.
Copy link
Contributor

Choose a reason for hiding this comment

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

@MHBauer could you add a bit here on what would have been set in the original helm install command, so that people know whether they enabled RBAC? It may not be obvious to a newcomer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arschles Gone!


## Install our rbac rules

See the [script in contrib](../contrib/rbac-setup.sh). See the
Copy link
Contributor

Choose a reason for hiding this comment

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

Should they run the script in contrib to install the RBAC rules? If so, can you add that little piece to the docs

@@ -20,6 +20,7 @@ spec:
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
serviceAccountName: server
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this and the serviceAccountName in controller-manager-deployment.yaml would be worth parameterizing in the values.yaml file as well

Copy link
Contributor

Choose a reason for hiding this comment

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

The walkthrough test fails because contrib/rbac-setup.sh isn't run in contrib/hack/test_walkthrough.sh, so the service account additions here break the deployment.

We should either make these serviceAccountNames optional, or update both contrib/hack/test_walkthrough.sh and the walkthrough docs to require running contrib/rbac-setup.sh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sheesh. You mentioned it and tagged it for me and I still missed it. sorry guys.

@pmorie pmorie added this to the 0.0.11 milestone Jun 14, 2017
@kibbles-n-bytes
Copy link
Contributor

@MHBauer I was out earlier this week, looking into this today.

@@ -20,6 +20,7 @@ spec:
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
serviceAccountName: server
Copy link
Contributor

Choose a reason for hiding this comment

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

The walkthrough test fails because contrib/rbac-setup.sh isn't run in contrib/hack/test_walkthrough.sh, so the service account additions here break the deployment.

We should either make these serviceAccountNames optional, or update both contrib/hack/test_walkthrough.sh and the walkthrough docs to require running contrib/rbac-setup.sh.

# See the License for the specific language governing permissions and
# limitations under the License.

SVCCAT_NAMESPACE=catalog
Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes the namespace will be "catalog". This should probably be parameterized. A simple way would be:

SVCCAT_NAMESPACE="${SVCCAT_NAMESPACE:-catalog}"

kubectl create namespace ${SVCCAT_NAMESPACE}
kubectl create serviceaccount server --namespace=${SVCCAT_NAMESPACE}
kubectl create serviceaccount controller --namespace=${SVCCAT_NAMESPACE}
kubectl create -f svc-cat-rbac.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes we're running this file while in contrib/. I'd add

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

to the top of the file, and then change the file reference to "${ROOT}/contrib/svc-cat-rbac.yaml

@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 16, 2017

I agree that the account names need to be parameterized here. The account names need to match the rbac definition yaml.

The service account creation should become part of the charts.

The rbac yaml should become part of the charts.

--clusterrole=cluster-admin --user="${ACCOUNT_NAME}" \
|| { echo 'Cannot not create cluster-admin role for service account.'; exit 1; }

${ROOT}/contrib/rbac-setup.sh \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe won't need this script at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since you got rid of it now, lines 66-68 should be removed as well.

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 am really dumb some times.

@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 17, 2017

I think we're good now. rbac by default. At the very least it shouldn't break anything on someone running without rbac on.
@kibbles-n-bytes thanks much for helping me solve jenkins issue.

@MHBauer MHBauer requested review from duglin, pmorie and vaikas June 17, 2017 04:36
@@ -20,6 +20,7 @@ spec:
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
serviceAccountName: controller
Copy link
Contributor

@kibbles-n-bytes kibbles-n-bytes Jun 19, 2017

Choose a reason for hiding this comment

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

You still need to templatize the definition here and in apiserver-deployment.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.

🦈 good eye. I'll take another pass through. Thanks!

@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 19, 2017

@kibbles-n-bytes @arschles I can't believe you both tagged some things and I still overlooked them. Sorry about that. We should be good now. Not sure why jenkins is failing. Looks to me like it successfully installs.

@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 19, 2017

This can go in before or after #895, but you'll need to manually disable rbac if #895 goes in first.

@arschles
Copy link
Contributor

@MHBauer is the jenkins failure a flake?

@kibbles-n-bytes
Copy link
Contributor

@arschles @MHBauer I'm looking into it now. At first it was because the RBAC stuff needed a newer version of Helm than I had installed, but there is still something causing it to consistently fail.

@liggitt
Copy link

liggitt commented Jun 21, 2017

if you're testing with an apiserver build from master, kubernetes/kubernetes#46812 (comment) would have broken this a couple days ago

@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 21, 2017

@liggitt our apiserver stuff is somewhere between levels v1.5.5 and v1.6.0-rc1

@MHBauer MHBauer closed this Jun 21, 2017
@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 21, 2017

undo!

@MHBauer MHBauer reopened this Jun 21, 2017
@MHBauer
Copy link
Contributor Author

MHBauer commented Jun 21, 2017

looking at https://service-catalog-jenkins.appspot.com/job/service-catalog-PR-testing2/885/
I see

Error syncing pod, skipping: failed to "StartContainer" for "etcd" with ImagePullBackOff: "Back-off pulling image \"quay.io/coreos/etcd:latest\""

which would be a flake to me.

@arschles arschles modified the milestones: 0.0.11, 0.0.12 Jun 21, 2017
@kibbles-n-bytes
Copy link
Contributor

@MHBauer As I mentioned on Slack, I believe that's the same issue I hit when trying to run this on GKE. I had to create a ClusterRoleBinding with the "cluster-admin" role before doing any of the RBAC stuff.

# cluster roles. Needed for RBAC setup.
ACCOUNT_NAME="$(gcloud info | grep Account | sed 's/.*\[\(.*\)\]/\1/')"
kubectl create clusterrolebinding jenkins-cluster-admin-binding \
--clusterrole=cluster-admin --user="${ACCOUNT_NAME}" \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arschles @kibbles-n-bytes for default minikube I did
kubectl create clusterrolebinding minikube-cluster-admin-binding --clusterrole=cluster-admin --user=minikube

Copy link
Contributor Author

@MHBauer MHBauer Jul 7, 2017

Choose a reason for hiding this comment

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

Nope, did not help, same
Error: release catalog failed: clusterroles.rbac.authorization.k8s.io "servicecatalog.k8s.io:apiserver" is forbidden: attempt to grant extra privileges: [PolicyRule{Resources:["namespaces"], APIGroups:[""], Verbs:["get"]} PolicyRule{Resources:["namespaces"], APIGroups:[""], Verbs:["list"]} PolicyRule{Resources:["namespaces"], APIGroups:[""], Verbs:["watch"]}] user=&{system:serviceaccount:kube-system:default d6100657-632b-11e7-8c06-befc308e6091 [system:serviceaccounts system:serviceaccounts:kube-system system:authenticated] map[]} ownerrules=[] ruleResolutionErrors=[]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rbac wasn't on in minikube, oops.

add --extra-config=apiserver.Authorization.Mode=RBAC

Copy link
Contributor

Choose a reason for hiding this comment

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

We can add this to the walkthrough docs in a follow-up

Copy link
Contributor

Choose a reason for hiding this comment

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

Tracked in #1021

@kibbles-n-bytes
Copy link
Contributor

@MHBauer Still investigating this failure, should have a fix out soon.

@kibbles-n-bytes kibbles-n-bytes added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 7, 2017
@MHBauer
Copy link
Contributor Author

MHBauer commented Jul 7, 2017

@kibbles-n-bytes rebased on to 34ed5cd.

@kibbles-n-bytes kibbles-n-bytes removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 7, 2017
@arschles
Copy link
Contributor

Service accounts were done to see what each server was specificly doing. We can back that out and adapt the yaml.

@MHBauer IMO it's fine to leave these

@luxas
Copy link
Contributor

luxas commented Jul 12, 2017

@MHBauer ready to review and merge?

@@ -0,0 +1,127 @@
apiVersion: v1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pmorie @arschles @luxas @liggitt should I make a helm chart and wrap this whole thing in it? Not sure if it's okay to unconditionally send rbac objects. Would helm fail?

Copy link
Contributor

Choose a reason for hiding this comment

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

@MHBauer I believe we should be able to use the following to test whether the rbac API group is available:

{{- if .Capabilities.APIVersions.Has "rbac.k8s.io/v1beta1" }}
// stuff
{{- end }}

Copy link
Contributor

@pmorie pmorie left a comment

Choose a reason for hiding this comment

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

Looking great, just a couple suggestions / gaps to close.

@@ -0,0 +1,127 @@
apiVersion: v1
Copy link
Contributor

Choose a reason for hiding this comment

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

@MHBauer I believe we should be able to use the following to test whether the rbac API group is available:

{{- if .Capabilities.APIVersions.Has "rbac.k8s.io/v1beta1" }}
// stuff
{{- end }}

items:

# TODO: if this is just for namespace lifecycle admission, move to a generic role
- apiVersion: rbac.authorization.k8s.io/v1beta1
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this should be the only use for the API server, and does constitute what is necessary for namespace lifecycle admission. I'm cool calling this role something like namespace-lifecycle-admission, your choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there more to do to address the todo? or a followup.

# TODO: do not grant global access, limit to particular secrets referenced from bindings
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get","create"]
Copy link
Contributor

Choose a reason for hiding this comment

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

The controller manager deletes secrets when bindings are deleted, so delete is definitely needed.

resources: ["secrets"]
verbs: ["get","create"]
- apiGroups: [""]
resources: ["configmaps"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we have any uses of configmaps in the code today, do we? Does auth delegation rely on it?

resources: ["secrets"]
verbs: ["get","create"]
- apiGroups: [""]
resources: ["configmaps"]
Copy link
Contributor

Choose a reason for hiding this comment

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

(It might be handy to comment saying what each of these permissions is used for)

- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get", "list", "watch"]
- apiVersion: rbac.authorization.k8s.io/v1beta1
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 we are missing RBAC rules for settings API group

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What should that look like?

@MHBauer
Copy link
Contributor Author

MHBauer commented Jul 14, 2017

I know that the 'requestheader-ca' information is looked up by the apiserver in a configmap. I know for api aggregation it's needed. Maybe for auth delegation as well. Any comment @DirectXMan12 ?

@MHBauer
Copy link
Contributor Author

MHBauer commented Jul 14, 2017

What's the proper way to drop comments in? Is there a way to get the comment into kube so we know what it does later? I obviously want a very specific name, but there's only so many characters I can use in there.

@luxas
Copy link
Contributor

luxas commented Jul 14, 2017

I know that the 'requestheader-ca' information is looked up by the apiserver in a configmap. I know for api aggregation it's needed. Maybe for auth delegation as well. Any comment @DirectXMan12 ?

The extension-apiserver-authentication-reader Role in kube-system grants that for you, not needed to grant access to all configmaps.

What's the proper way to drop comments in? Is there a way to get the comment into kube so we know what it does later? I obviously want a very specific name, but there's only so many characters I can use in there.

I think commenting in the yaml spec is good enough.

@MHBauer
Copy link
Contributor Author

MHBauer commented Jul 14, 2017

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  creationTimestamp: 2017-07-12T16:58:34Z
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
  name: extension-apiserver-authentication-reader
  namespace: kube-system
  resourceVersion: "137"
  selfLink: /apis/rbac.authorization.k8s.io/v1beta1/namespaces/kube-system/roles/extension-apiserver-authentication-reader
  uid: 5726faf6-6723-11e7-97c3-02420ac00002
rules:
- apiGroups:
  - ""
  resourceNames:
  - extension-apiserver-authentication
  resources:
  - configmaps
  verbs:
  - get

I see that now.

This was always intended as a rough draft of "what happened" when I ran some tests with the rbac in permissive mode. I don't know of any more definitive way to determine the exact permissions we may need. This is a bad UX.

I'll take configmaps out and test, but it's going to delay this again.

@kibbles-n-bytes kibbles-n-bytes added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 14, 2017
@MHBauer
Copy link
Contributor Author

MHBauer commented Jul 14, 2017

@kibbles-n-bytes rebase why?

@kibbles-n-bytes
Copy link
Contributor

@MHBauer The GKE cluster version time bomb went off. 😅 #1023

@MHBauer
Copy link
Contributor Author

MHBauer commented Jul 14, 2017

gotcha gotch. I'll do some refactoring of the commits while I'm rebasing.

 - RBAC in chart
 - add the ServiceAccount definitions to chart
 - parameterize namespace and ServiceAccount names

Thanks to
 - liggitt for helping me with discovering RBAC rules.
 - DirectXMan12 for helping me troubleshoot aggregator setup.
@MHBauer MHBauer removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 14, 2017
@MHBauer
Copy link
Contributor Author

MHBauer commented Jul 14, 2017

/retest

@kibbles-n-bytes
Copy link
Contributor

@MHBauer Check my latest comment on contrib/jenkins/init_cluster.sh!

@MHBauer
Copy link
Contributor Author

MHBauer commented Jul 14, 2017

@kibbles-n-bytes thanks

@pmorie pmorie added the LGTM1 label Jul 14, 2017
@kibbles-n-bytes kibbles-n-bytes merged commit 8ec0874 into kubernetes-retired:master Jul 17, 2017
@MHBauer MHBauer mentioned this pull request Jul 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. LGTM1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants