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

Update RBAC roles for apprepositories to be clusterroles so they can be used in many namespaces. #1654

Merged
merged 3 commits into from
Apr 15, 2020

Conversation

absoludity
Copy link
Contributor

@absoludity absoludity commented Apr 9, 2020

Renames the apprepositories-read cluster role so that it is no longer controller specific, and can be used to assign users to the role in specific namespaces. (Also removed the 'update' verb from this, not sure why it was there given the name, seems to work without it, but I assume the controller needed to update app repo resources at some point?).

Similarly, add a related apprepositories-write cluster role (unbound).

Updates the dev setup (which I use) so that the kubeapps-operator user can create app repos in the kubeapps-user-namespace, while the kubeapps-user user can only read them (so can deploy).

Include usage of these clusterroles in the docs.

Ref: #1521

@absoludity absoludity requested a review from andresmgot April 9, 2020 05:55
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

Thanks @absoludity. Check my comments, we already have roles for reading and writing apprepositories for users.

- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: "kubeapps:controller:apprepository-reader-{{ .Release.Namespace }}"
name: "kubeapps:controller:appreposities-read"
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: apprepositories

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.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: "kubeapps:apprepositories-write"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would create just one ClusterRole (this is internal, see my comment below)

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 there's some confusion here... it's not internal. The reader cluster-role was internal, but this is renaming it so it can be both used internally for the controller, but also available to be bound in any namespace to give users the ability to read (or write - hence the second) app repos in specific namespaces. More below.

Comment on lines 207 to 217
You can give specific users the ability to create App Repositories in a specific namespace by granting them the necessary RBAC:

```bash
kubectl -n custom-namespace create rolebinding username-apprepositories-read --user username --clusterrole kubeapps:apprepositories-write
```

or other users the ability to deploy charts from App Repositories in a specific namespace by granting them read access:

```bash
kubectl -n custom-namespace create rolebinding username-apprepositories-read --user username --clusterrole kubeapps:apprepositories-read
```
Copy link
Contributor

Choose a reason for hiding this comment

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

we already have those roles per namespace:

https://github.com/kubeapps/kubeapps/blob/master/chart/kubeapps/templates/apprepository-rbac.yaml#L68

It is also documented in docs/user/access-control.md . We should use the same roles in this guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we already have those roles per namespace:

https://github.com/kubeapps/kubeapps/blob/master/chart/kubeapps/templates/apprepository-rbac.yaml#L68

Yes, I was going to delete those, as unless I'm missing something, they are no longer useful. They are created in the release namespace only as they are intended to be bound in the release namespace only (ie. before per-namespace app repositories, we provided these unbound roles so people could easily add app repo readers / writers in the release namespace only.) Now we similarly want to provide unbound roles which can be applied in any namespace, hence the new cluster roles.

It is also documented in docs/user/access-control.md . We should use the same roles in this guide.

Depending whether you agree with the above, I'll update that doc to use the new cluster roles 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.

ah, right, I missed the cluster/namespace context. To avoid a breaking change we can have both, the role and the clusterrole and modify the documentation to point to that clusterrole.

One thing we need to handle is several instances of Kubeapps per cluster. The easiest thing to do is to include the namespace in the name (even if it's a clusterrole): kubeapps:{ns}:apprepositories-write. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, right, I missed the cluster/namespace context. To avoid a breaking change we can have both, the role and the clusterrole and modify the documentation to point to that clusterrole.

Done. I initially was updating the access-control.md to per-namespace instructions, but then realised we shouldn't do that until we switch the default. For now I've just switched the reference to the cluster role.

One thing we need to handle is several instances of Kubeapps per cluster. The easiest thing to do is to include the namespace in the name (even if it's a clusterrole): kubeapps:{ns}:apprepositories-write. WDYT?

I'd originally removed the release name, because it seemed redundant: helm doesn't resource-count anyway, so deleting a chart just deletes all its resources which I thought meant it would delete the (cluster-wide) CRD too, breaking other releases, but I checked and found that deleting a helm release (with helm 3) does not delete any CRD's it creates. So yep, I agree - I'll update them to be unique to the release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this also required removing the condition (the feature flag), so that now this RBAC is always added if .Values.rbac.create is true.

@absoludity
Copy link
Contributor Author

Please take another look :)

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

thanks! It looks good to me now

@absoludity absoludity merged commit 1d159f6 into master Apr 15, 2020
@absoludity absoludity deleted the create-and-doc-perms branch April 15, 2020 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants