Skip to content

Commit d450768

Browse files
Add documentation on securing cross-namespace access for CC
Signed-off-by: Danil-Grigorev <[email protected]>
1 parent aa15355 commit d450768

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

docs/book/src/tasks/experimental-features/cluster-class/write-clusterclass.md

+75
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,81 @@ spec:
438438
template: "{{ .cluster.name }}-{{ .machinePool.topologyName }}-{{ .random }}"
439439
```
440440

441+
### Defining a custom namespace for ClusterClass object
442+
443+
As a user, I may need to create a `Cluster` from a `ClusterClass` object that exists only in a different namespace. To uniquely identify the `ClusterClass`, a `NamespaceName` ref is constructed from combination of:
444+
* `cluster.spec.topology.classNamespace` - namespace of the `ClusterClass` object.
445+
* `cluster.spec.topology.class` - name of the `ClusterClass` object.
446+
447+
Example of the `Cluster` object with the `name/namespace` reference:
448+
449+
```yaml
450+
apiVersion: cluster.x-k8s.io/v1beta1
451+
kind: Cluster
452+
metadata:
453+
name: my-docker-cluster
454+
namespace: default
455+
spec:
456+
topology:
457+
class: docker-clusterclass-v0.1.0
458+
classNamespace: default
459+
version: v1.22.4
460+
controlPlane:
461+
replicas: 3
462+
workers:
463+
machineDeployments:
464+
- class: default-worker
465+
name: md-0
466+
replicas: 4
467+
failureDomain: region
468+
```
469+
470+
#### Securing cross-namespace reference to the ClusterClass
471+
472+
It is often desirable to restrict free cross-namespace `ClusterClass` access for the `Cluster` object. This can be implemented by defining a [`ValidatingAdmissionPolicy`](https://kubernetes.io/docs/reference/access-authn-authz/validating-admission-policy/) on the `Cluster` object.
473+
474+
An example of such policy may be:
475+
476+
```yaml
477+
apiVersion: admissionregistration.k8s.io/v1
478+
kind: ValidatingAdmissionPolicy
479+
metadata:
480+
name: "cluster-class-ref.cluster.x-k8s.io"
481+
spec:
482+
failurePolicy: Fail
483+
paramKind:
484+
apiVersion: v1
485+
kind: Secret
486+
matchConstraints:
487+
resourceRules:
488+
- apiGroups: ["cluster.x-k8s.io"]
489+
apiVersions: ["v1beta1"]
490+
operations: ["CREATE", "UPDATE"]
491+
resources: ["clusters"]
492+
validations:
493+
- expression: "!has(object.spec.topology.classNamespace) || object.spec.topology.classNamespace in params.data"
494+
---
495+
apiVersion: admissionregistration.k8s.io/v1
496+
kind: ValidatingAdmissionPolicyBinding
497+
metadata:
498+
name: "cluster-class-ref-binding.cluster.x-k8s.io"
499+
spec:
500+
policyName: "cluster-class-ref.cluster.x-k8s.io"
501+
validationActions: [Deny]
502+
paramRef:
503+
name: "ref-list"
504+
namespace: "default"
505+
parameterNotFoundAction: Deny
506+
---
507+
apiVersion: v1
508+
kind: Secret
509+
metadata:
510+
name: "ref-list"
511+
namespace: "default"
512+
data:
513+
default: ""
514+
```
515+
441516
## Advanced features of ClusterClass with patches
442517

443518
This section will explain more advanced features of ClusterClass patches.

0 commit comments

Comments
 (0)