Skip to content

Commit

Permalink
Allow builtin 'admin' role to manage HNC objects
Browse files Browse the repository at this point in the history
The builtin 'admin' clusterrole doesn't include custom resources by
default. This change allows 'admin' to modify any HNC resource. If
granted at the cluster level, it will allow the user to administer HNC
itself (via the HNCConfiguration object); otherwise, it will allow a
user to administer the HierarchyConfiguration singleton in the namespace
(and its descendants) as well as SubnamespaceAnchors. Note that this
will *not* allow that user to change the _parent_ of that namespace
without permissions in the root of its tree (see user guide for more
details).

Tested: before this change, I gave the 'admin' role to the default
service account in 'foo' and ran the following command:

```
k hns create bar -n foo --as system:serviceaccount:foo:default
```

Result:
```
Could not create subnamespace anchor.
Reason: subnamespaceanchors.hnc.x-k8s.io "bar" is forbidden: User "system:serviceaccount:foo:default" cannot create resource "subnamespaceanchors" in API group "hnc.x-k8s.io" in the namespace "foo"
```

After this change, the same command passes.
  • Loading branch information
adrianludwin committed Apr 27, 2021
1 parent aef17d3 commit 0fa702a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions incubator/hnc/config/rbac/hnc_admin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

---
# This role is intended to be used by *humans*, and is aggregated to the
# builtin 'admin' ClusterRole. By default, 'admin' doesn't get permissions
# to custom resources (see issue #1341).
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: admin-role
labels:
rbac.authorization.k8s.io/aggregate-to-admin: "true"
rules:
- apiGroups:
- hnc.x-k8s.io
resources:
- '*'
verbs:
- '*'
1 change: 1 addition & 0 deletions incubator/hnc/config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resources:
- role.yaml
- role_binding.yaml
- hnc_admin.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
# Comment the following 3 lines if you want to disable
Expand Down

0 comments on commit 0fa702a

Please sign in to comment.