From ea48cbb506baa607d26a950080e904cc6a4887f1 Mon Sep 17 00:00:00 2001 From: Blaine Gardner Date: Thu, 18 Apr 2019 16:13:30 -0600 Subject: [PATCH] doc: split rback.md into General and Ceph files Also rename to psp.md, which is more correct than RBAC. Signed-off-by: Blaine Gardner --- Documentation/{rbac.md => ceph-psp.md} | 79 +++++++++++++------------- Documentation/k8s-pre-reqs.md | 3 +- Documentation/psp.md | 72 +++++++++++++++++++++++ 3 files changed, 115 insertions(+), 39 deletions(-) rename Documentation/{rbac.md => ceph-psp.md} (58%) create mode 100644 Documentation/psp.md diff --git a/Documentation/rbac.md b/Documentation/ceph-psp.md similarity index 58% rename from Documentation/rbac.md rename to Documentation/ceph-psp.md index ec24f480c..e42e1de74 100644 --- a/Documentation/rbac.md +++ b/Documentation/ceph-psp.md @@ -1,40 +1,20 @@ --- -title: RBAC Security +title: Ceph cluster Pod Security Policies weight: 1400 indent: true --- -# RBAC Security +# Using Rook-Ceph with Pod Security Policies (PSPs) -## Cluster Role - -**NOTE** This is only needed when you are not already `cluster-admin` in your Kubernetes cluster! - -Creating the Rook operator requires privileges for setting up RBAC. To launch the operator you need to have created your user certificate that is bound to ClusterRole `cluster-admin`. - -One simple way to achieve it is to assign your certificate with the `system:masters` group: - -``` --subj "/CN=admin/O=system:masters" -``` - -`system:masters` is a special group that is bound to `cluster-admin` ClusterRole, but it can't be easily revoked so be careful with taking that route in a production setting. -Binding individual certificate to ClusterRole `cluster-admin` is revocable by deleting the ClusterRoleBinding. - -## RBAC for PodSecurityPolicies - -If you have activated the [PodSecurityPolicy Admission Controller](https://kubernetes.io/docs/admin/admission-controllers/#podsecuritypolicy) and thus are -using [PodSecurityPolicies](https://kubernetes.io/docs/concepts/policy/pod-security-policy/), you will require additional `(Cluster)RoleBindings` -for the different `ServiceAccounts` Rook uses to start the Rook Storage Pods. - -**Note**: You do not have to perform these steps if you do not have the `PodSecurityPolicy` Admission Controller activated! +See the [Rook overall PSP document](./psp.md) before continuing on here with Ceph specifics. ##### PodSecurityPolicy -You need one `PodSecurityPolicy` that allows privileged `Pod` execution. Here is an example: +You need at least one `PodSecurityPolicy` that allows privileged `Pod` execution. Here is an example +that is reasonably pared down for Ceph, though more work to minimize permissions can be done: ```yaml -apiVersion: apps/v1 +apiVersion: policy/v1beta1 kind: PodSecurityPolicy metadata: name: privileged @@ -49,19 +29,26 @@ spec: supplementalGroups: rule: RunAsAny volumes: - - '*' - allowedCapabilities: - - '*' + - 'configMap' + - 'emptyDir' + - 'projected' + - 'secret' + - 'downwardAPI' + - 'hostPath' + - 'flexVolume' hostPID: true - hostIPC: true + # hostNetwork is required for using host networking hostNetwork: false ``` -**Hint**: Allowing `hostNetwork` usage is required when using `hostNetwork: true` in the Cluster `CustomResourceDefinition`! -You are then also required to allow the usage of `hostPorts` in the `PodSecurityPolicy`. The given port range is a minimal -working recommendation for a Rook Ceph cluster: +**Hint**: Allowing `hostNetwork` usage is required when using `hostNetwork: true` in the Cluster +Resource Definition! You are then also required to allow the usage of `hostPorts` in the +`PodSecurityPolicy`. The given port range is a minimal working recommendation for a Rook Ceph cluster: ```yaml hostPorts: + # Ceph msgr2 port + - min: 3300 + max: 3300 # Ceph ports - min: 6789 max: 7300 @@ -80,10 +67,10 @@ with privileged rights. Here are the definitions: apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: privileged-psp-user + name: psp:rook rules: - apiGroups: - - apps + - policy resources: - podsecuritypolicies resourceNames: @@ -107,7 +94,7 @@ metadata: roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: privileged-psp-user + name: psp:rook subjects: - kind: ServiceAccount name: rook-ceph-system @@ -134,7 +121,7 @@ metadata: roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: privileged-psp-user + name: psp:rook subjects: - kind: ServiceAccount name: default @@ -149,9 +136,25 @@ metadata: roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: privileged-psp-user + name: psp:rook subjects: - kind: ServiceAccount name: rook-ceph-osd namespace: rook-ceph +--- +# Allow the rook-ceph-mgr serviceAccount to use the privileged PSP +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: rook-ceph-mgr-psp + namespace: rook-ceph +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: psp:rook +subjects: +- kind: ServiceAccount + name: rook-ceph-mgr + namespace: rook-ceph + ``` diff --git a/Documentation/k8s-pre-reqs.md b/Documentation/k8s-pre-reqs.md index f82cfb353..000fc3549 100644 --- a/Documentation/k8s-pre-reqs.md +++ b/Documentation/k8s-pre-reqs.md @@ -13,7 +13,8 @@ Kubernetes v1.10 or higher is supported by Rook. ## Privileges and RBAC -Rook requires privileges to manage the storage in your cluster. See the details [here](rbac.md) for setting up RBAC. +Rook requires privileges to manage the storage in your cluster. See the details [here](psp.md) for +setting up Rook in a Kubernetes cluster with Pod Security Policies enabled. ## Flexvolume Configuration diff --git a/Documentation/psp.md b/Documentation/psp.md new file mode 100644 index 000000000..8e241d147 --- /dev/null +++ b/Documentation/psp.md @@ -0,0 +1,72 @@ +--- +title: Pod Security Policies +weight: 1400 +indent: true +--- + +# Using Rook with Pod Security Policies + +## Cluster Role + +**NOTE** Cluster role configuration is only needed when you are not already `cluster-admin` in your Kubernetes cluster! + +Creating the Rook operator requires privileges for setting up RBAC. To launch the operator you need to have created your user certificate that is bound to ClusterRole `cluster-admin`. + +One simple way to achieve it is to assign your certificate with the `system:masters` group: + +``` +-subj "/CN=admin/O=system:masters" +``` + +`system:masters` is a special group that is bound to `cluster-admin` ClusterRole, but it can't be easily revoked so be careful with taking that route in a production setting. +Binding individual certificate to ClusterRole `cluster-admin` is revocable by deleting the ClusterRoleBinding. + +## RBAC for PodSecurityPolicies + +If you have activated the [PodSecurityPolicy Admission Controller](https://kubernetes.io/docs/admin/admission-controllers/#podsecuritypolicy) and thus are +using [PodSecurityPolicies](https://kubernetes.io/docs/concepts/policy/pod-security-policy/), you will require additional `(Cluster)RoleBindings` +for the different `ServiceAccounts` Rook uses to start the Rook Storage Pods. + +Security policies will differ for different backends. See +[Ceph's Pod Security Policy document](./ceph-psp.md) for an example of how this is done in practice. + +**Note**: You do not have to perform these steps if you do not have the `PodSecurityPolicy` Admission Controller activated! + +##### PodSecurityPolicy + +You need at least one `PodSecurityPolicy` that allows privileged `Pod` execution. Here is an example +which should be more permissive than is needed for any backend: + +```yaml +apiVersion: policy/v1beta1 +kind: PodSecurityPolicy +metadata: + name: privileged +spec: + fsGroup: + rule: RunAsAny + privileged: true + runAsUser: + rule: RunAsAny + seLinux: + rule: RunAsAny + supplementalGroups: + rule: RunAsAny + volumes: + - '*' + allowedCapabilities: + - '*' + hostPID: true + # hostNetwork is required for using host networking + hostNetwork: false +``` + +**Hint**: Allowing `hostNetwork` usage is required when using `hostNetwork: true` in a Cluster `CustomResourceDefinition`! +You are then also required to allow the usage of `hostPorts` in the `PodSecurityPolicy`. The given +port range will allow all ports: + ```yaml + hostPorts: + # Ceph msgr2 port + - min: 1 + max: 65535 +```