Containers, Kubernetes, OpenShift on Power

Containers, Kubernetes, OpenShift on Power

Connect, learn, share, and engage with IBM Power.

 View Only

Securing NFS Attached Storage Notes

By PAUL BASTIDE posted Thu December 14, 2023 08:52 PM

  

This post was originally posted to link

Persistent storage using NFS

# cat /etc/exports
/export *(rw,sync,root_squash)

# ls -ld /export
drwxrwxrwx. 3 nobody nobody 92 Nov 21 06:33 /export

# id nobody
uid=65534(nobody) gid=65534(nobody) groups=65534(nobody)

NFS Volume Security

# cat pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0001
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
nfs:
path: /export
server: <nfs-server-ip>
persistentVolumeReclaimPolicy: Recycle

# oc create -f pv.yaml
persistentvolume/pv0001 created

# oc get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv0001 5Gi RWO Recycle Available 14s
pvc-0134f991-8be5-406f-962f-ece86d26b21d 20Gi RWX Delete Bound openshift-image-registry/registry-pvc nfs-storage-provisioner 6d22h
# cat pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-claim1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
volumeName: pv0001
storageClassName: ""

# oc create -f pvc.yaml
persistentvolumeclaim/nfs-claim1 created

# oc get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
nfs-claim1 Bound pv0001 5Gi RWO 4s

Group ID

spec:
containers:
- name:
...
securityContext:
supplementalGroups: []

User ID

spec:
containers:
- name:
...
securityContext:
runAsUser: 65534

SELinux

securityContext:
seLinuxOptions:
level: "s0:c123,c456"
# cat test-pod_selinux.yaml
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo-1
spec:
securityContext:
seLinuxOptions:
level: "s0:c26,c15"
runAsUser: 3333
supplementalGroups: [5555]
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
containers:
- name: sec-ctx-demo-1
image: docker.io/library/tomcat:9.0
volumeMounts:
- name: my-volume
mountPath: "/data"
securityContext:
seLinuxOptions:
level: "s0:c26,c15"
runAsUser: 3333
supplementalGroups: [5555]
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
capabilities:
drop: ["ALL"]
allowPrivilegeEscalation: false
serviceAccountName: my-custom-sa
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: nfs-claim1
# oc get pod security-context-demo-1 -oyaml | grep scc
openshift.io/scc: my-custom-scc
# oc get pods -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
security-context-demo-1 1/1 Running 0 7m29s 10.128.2.194 osa21-worker-0.storage-2111-db9d.ibm.com <none> <none>
# oc exec -it security-context-demo-1 -- sh
$ id
uid=3333(3333) gid=0(root) groups=0(root),5555,1000680000
$ df -h | grep data
Filesystem Size Used Avail Use% Mounted on
192.168.100.253:/export 300G 2.2G 298G 1% /data
$ ls -Z /data
system_u:object_r:nfs_t:s0 hsperfdata_3333 system_u:object_r:nfs_t:s0 hsperfdata_5555
$ ls -Z | grep bin
system_u:object_r:container_file_t:s0:c26,c15 bin
0 comments
7 views

Permalink