Skip to content

Commit 73e75a4

Browse files
authored
[v4.9.0] docs(doc-1106): document custom ClusterRoles for tenant cluster RBAC (#2139) (#2149)
* Backport: Copy platform/administer/templates/create-templates.mdx to platform_versioned_docs/version-4.9.0/administer/templates/create-templates.mdx * Backport: Copy platform/administer/users-permissions/permissions/vcluster.mdx to platform_versioned_docs/version-4.9.0/administer/users-permissions/permissions/vcluster.mdx
1 parent 32a9539 commit 73e75a4

2 files changed

Lines changed: 90 additions & 1 deletion

File tree

platform_versioned_docs/version-4.9.0/administer/templates/create-templates.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ The **Apps** section lets you select pre-built applications that install automat
239239
240240
Selected apps deploy immediately after virtual cluster creation. Development teams have required tools and services available without manual installation. This approach standardizes the application stack across virtual clusters. It also reduces setup time for development teams.
241241
242-
The **Objects** section defines Kubernetes manifests that are applied during virtual cluster creation. These include ConfigMaps, Secrets, or NetworkPolicies that establish baseline configurations.
242+
The **Objects** section defines Kubernetes manifests that are applied during virtual cluster creation. These include ConfigMaps, Secrets, NetworkPolicies, or custom ClusterRoles that establish baseline configurations. For an example of injecting a custom ClusterRole to control in-cluster permissions, see [Custom ClusterRoles](../users-permissions/permissions/vcluster.mdx#custom-clusterroles).
243243
244244
245245
### Management access

platform_versioned_docs/version-4.9.0/administer/users-permissions/permissions/vcluster.mdx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,92 @@ In this example:
144144
- All other users default to `cluster-admin`.
145145

146146
Custom mapping rules allow more precise and secure access control inside the virtual cluster.
147+
148+
### Custom ClusterRoles
149+
150+
The platform UI's **Permissions** section lists only the four built-in roles: `cluster-admin`, `admin`, `edit`, and `view`. To use any other role, inject it into the tenant cluster using the `objects` field and reference it by name in `access.rules`.
151+
152+
Two approaches are available depending on what you need:
153+
154+
- **Define a new ClusterRole** specify exactly the rules you want. Use this when you need to remove specific permissions from a built-in role.
155+
- **Aggregate into a built-in role** add rules to an existing role using Kubernetes label selectors. Use this when you need to extend a built-in role with additional access, without redefining its full rule set.
156+
157+
:::note
158+
If the tenant cluster is deployed from a template, add `objects` to the **template's** `spec.template`. The template controls those fields and overrides any changes made directly on the tenant cluster.
159+
:::
160+
161+
#### Define a new ClusterRole
162+
163+
Kubernetes RBAC is additive. A ClusterRole only grants what its rules explicitly allow. To restrict specific verbs from a built-in role, define a new ClusterRole that includes only the permissions you want.
164+
165+
One common scenario is a team that uses `edit` but must not be able to create PersistentVolumeClaims. For example, a shared PersistentVolume references a sensitive secret, and unrestricted PVC creation would expose that access.
166+
167+
```yaml
168+
apiVersion: management.loft.sh/v1
169+
kind: VirtualClusterTemplate
170+
metadata:
171+
name: restricted-storage
172+
spec:
173+
template:
174+
objects: |
175+
apiVersion: rbac.authorization.k8s.io/v1
176+
kind: ClusterRole
177+
metadata:
178+
name: edit-no-pvc-write
179+
rules:
180+
- apiGroups: [""]
181+
resources: ["pods", "services", "configmaps", "secrets", "endpoints"]
182+
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
183+
- apiGroups: [""]
184+
resources: ["persistentvolumeclaims"]
185+
verbs: ["get", "list", "watch", "delete"]
186+
- apiGroups: ["apps"]
187+
resources: ["deployments", "statefulsets", "daemonsets", "replicasets"]
188+
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
189+
access:
190+
defaultClusterRole: cluster-admin
191+
rules:
192+
- teams:
193+
- storage-restricted-team
194+
clusterRole: edit-no-pvc-write
195+
```
196+
197+
`create`, `update`, and `patch` are omitted from the `persistentvolumeclaims` entry. Those verbs return `Forbidden` for users assigned this role. To build from the full `edit` rule set, run `kubectl get clusterrole edit -o yaml`. Copy its `rules` section into `objects` and remove the verbs you want to block.
198+
199+
#### Extend a built-in role using aggregation
200+
201+
Kubernetes ClusterRole aggregation lets you inject additional rules into a built-in role using label selectors. The built-in `admin`, `edit`, and `view` roles each automatically aggregate any ClusterRole carrying the corresponding label:
202+
203+
| Label | Aggregates into |
204+
|-------|----------------|
205+
| `rbac.authorization.k8s.io/aggregate-to-admin: "true"` | `admin` |
206+
| `rbac.authorization.k8s.io/aggregate-to-edit: "true"` | `edit` |
207+
| `rbac.authorization.k8s.io/aggregate-to-view: "true"` | `view` |
208+
209+
The following example adds namespace creation to the `admin` role. Any team assigned `admin` automatically gains the added permission.
210+
211+
```yaml
212+
apiVersion: management.loft.sh/v1
213+
kind: VirtualClusterInstance
214+
metadata:
215+
name: vcluster-rbac-example
216+
spec:
217+
template:
218+
objects: |
219+
apiVersion: rbac.authorization.k8s.io/v1
220+
kind: ClusterRole
221+
metadata:
222+
name: admin-create-namespace
223+
labels:
224+
rbac.authorization.k8s.io/aggregate-to-admin: "true"
225+
rules:
226+
- apiGroups: [""]
227+
resources: ["namespaces"]
228+
verbs: ["create"]
229+
access:
230+
defaultClusterRole: view
231+
rules:
232+
- teams:
233+
- api-framework
234+
clusterRole: admin
235+
```

0 commit comments

Comments
 (0)