From 1659687d3738e684eac49d91fddda8cef7d350b2 Mon Sep 17 00:00:00 2001 From: Ahmad Nurus S Date: Mon, 13 Jul 2020 11:02:38 +0700 Subject: [PATCH] nfs: fix nfs issue on openshift Signed-off-by: Ahmad Nurus S --- Documentation/nfs.md | 52 ++++++++++++++++++- cluster/examples/kubernetes/nfs/nfs-ceph.yaml | 6 +++ cluster/examples/kubernetes/nfs/nfs.yaml | 6 +++ cluster/examples/kubernetes/nfs/scc.yaml | 36 +++++++++++++ pkg/operator/nfs/spec.go | 1 + tests/framework/installer/nfs_manifests.go | 6 +++ 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 cluster/examples/kubernetes/nfs/scc.yaml diff --git a/Documentation/nfs.md b/Documentation/nfs.md index 71561cd78..332e1d797 100644 --- a/Documentation/nfs.md +++ b/Documentation/nfs.md @@ -80,6 +80,57 @@ rook-nfs-provisioner-7b5ff479f6-688dm 1/1 Running 0 102s rook-nfs-webhook-74749cbd46-6jw2w 1/1 Running 0 102s ``` +## Create Openshift Security Context Constraints + +On Openshift cluster, before creating NFS Server we need to create the security context constraints needed by nfs-server pods which running on openshift. The following yaml is found in `scc.yaml` under `/cluster/examples/kubernetes/nfs`. + +> *NOTE: Older versions of OpenShift may require ```apiVersion: v1```* + +```yaml +kind: SecurityContextConstraints +apiVersion: security.openshift.io/v1 +metadata: + name: rook-nfs +allowHostDirVolumePlugin: true +allowHostIPC: false +allowHostNetwork: false +allowHostPID: false +allowHostPorts: false +allowPrivilegedContainer: false +allowedCapabilities: +- SYS_ADMIN +- DAC_READ_SEARCH +defaultAddCapabilities: null +fsGroup: + type: MustRunAs +priority: null +readOnlyRootFilesystem: false +requiredDropCapabilities: +- KILL +- MKNOD +- SYS_CHROOT +runAsUser: + type: RunAsAny +seLinuxContext: + type: MustRunAs +supplementalGroups: + type: RunAsAny +volumes: +- configMap +- downwardAPI +- emptyDir +- persistentVolumeClaim +- secret +users: + - system:serviceaccount:rook-nfs:rook-nfs-server +``` + +You can create scc with following command: + +```console +oc create -f scc.yaml +``` + ## Create and Initialize NFS Server Now that the operator is running, we can create an instance of a NFS server by creating an instance of the `nfsservers.nfs.rook.io` resource. @@ -124,7 +175,6 @@ metadata: name: rook-nfs namespace: rook-nfs spec: - serviceAccountName: rook-nfs replicas: 1 exports: - name: share1 diff --git a/cluster/examples/kubernetes/nfs/nfs-ceph.yaml b/cluster/examples/kubernetes/nfs/nfs-ceph.yaml index 10bfc6179..d7214a8e7 100644 --- a/cluster/examples/kubernetes/nfs/nfs-ceph.yaml +++ b/cluster/examples/kubernetes/nfs/nfs-ceph.yaml @@ -3,6 +3,12 @@ kind: Namespace metadata: name: rook-nfs --- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: rook-nfs-server + namespace: rook-nfs +--- # A rook ceph cluster must be running # Create a rook ceph cluster using examples in rook/cluster/examples/kubernetes/ceph # Refer to https://rook.io/docs/rook/master/ceph-quickstart.html for a quick rook cluster setup diff --git a/cluster/examples/kubernetes/nfs/nfs.yaml b/cluster/examples/kubernetes/nfs/nfs.yaml index 153d6498b..f88702627 100644 --- a/cluster/examples/kubernetes/nfs/nfs.yaml +++ b/cluster/examples/kubernetes/nfs/nfs.yaml @@ -3,6 +3,12 @@ kind: Namespace metadata: name: rook-nfs --- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: rook-nfs-server + namespace: rook-nfs +--- # A default storageclass must be present apiVersion: v1 kind: PersistentVolumeClaim diff --git a/cluster/examples/kubernetes/nfs/scc.yaml b/cluster/examples/kubernetes/nfs/scc.yaml new file mode 100644 index 000000000..6f9a236ad --- /dev/null +++ b/cluster/examples/kubernetes/nfs/scc.yaml @@ -0,0 +1,36 @@ +kind: SecurityContextConstraints +apiVersion: security.openshift.io/v1 +metadata: + name: rook-nfs +allowHostDirVolumePlugin: true +allowHostIPC: false +allowHostNetwork: false +allowHostPID: false +allowHostPorts: false +allowPrivilegedContainer: false +allowedCapabilities: +- SYS_ADMIN +- DAC_READ_SEARCH +defaultAddCapabilities: null +fsGroup: + type: MustRunAs +priority: null +readOnlyRootFilesystem: false +requiredDropCapabilities: +- KILL +- MKNOD +- SYS_CHROOT +runAsUser: + type: RunAsAny +seLinuxContext: + type: MustRunAs +supplementalGroups: + type: RunAsAny +volumes: +- configMap +- downwardAPI +- emptyDir +- persistentVolumeClaim +- secret +users: + - system:serviceaccount:rook-nfs:rook-nfs-server diff --git a/pkg/operator/nfs/spec.go b/pkg/operator/nfs/spec.go index 8081612ef..ca2b0f0b6 100644 --- a/pkg/operator/nfs/spec.go +++ b/pkg/operator/nfs/spec.go @@ -84,6 +84,7 @@ func newStatefulSetForNFSServer(cr *nfsv1alpha1.NFSServer) *appsv1.StatefulSet { Labels: newLabels(cr), }, Spec: corev1.PodSpec{ + ServiceAccountName: "rook-nfs-server", Containers: []corev1.Container{ { ImagePullPolicy: "IfNotPresent", diff --git a/tests/framework/installer/nfs_manifests.go b/tests/framework/installer/nfs_manifests.go index 4674ca7e8..bfda108ab 100644 --- a/tests/framework/installer/nfs_manifests.go +++ b/tests/framework/installer/nfs_manifests.go @@ -510,6 +510,12 @@ spec: func (i *NFSManifests) GetNFSServer(namespace string, count int, storageClassName string) string { return ` apiVersion: v1 +kind: ServiceAccount +metadata: + name: rook-nfs-server + namespace: ` + namespace + ` +--- +apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-claim