Skip to content

Enforcing StorageClass Usage at the Workload Level #1198

@pohanhuangtw

Description

@pohanhuangtw

Description

This policy restricts the usage of specific StorageClasses by Kubernetes resources.

Currently, the policy enforces checks at the PersistentVolumeClaim (PVC) level — PVCs using forbidden StorageClasses are rejected.

Unlike persistentvolumeclaim-storageclass-policy just prevent the pvc dreatehion, this policy should enforce at the workload level (e.g., rejecting a Deployment if any of its PVCs reference a forbidden StorageClass), similar to what NeuVector supports.

Restricting which StorageClasses can be used is useful in scenarios such as limiting workloads to a trusted storage provider or preventing the use of unsupported classes.

Configuration

You must configure either deniedStorageClasses or allowedStorageClasses (but not both).

# A list of storage classes that are forbidden.
# This setting is mutually exclusive with allowedStorageClasses.
deniedStorageClasses:
  - fast
  - nvme

# A list of storage classes that are permitted.
# This setting is mutually exclusive with deniedStorageClasses.
allowedStorageClasses:
  - standard
  - slow

Examples

❌ Denied Example

Configuration

deniedStorageClasses:
  - fast
  - nvme

PersistentVolumeClaim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-fast
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: fast   # forbidden StorageClass

Deployment using this PVC

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-using-fast
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
        - name: busybox
          image: busybox
          command: ["sleep", "3600"]
          volumeMounts:
            - name: data
              mountPath: /data
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: pvc-fast

👉 Result: This Deployment will be denied, because it references pvc-fast, which is bound to a forbidden StorageClass (fast).


✅ Allowed Example

Configuration

allowedStorageClasses:
  - standard
  - slow

PersistentVolumeClaim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-standard
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: standard   # explicitly allowed

Deployment using this PVC

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-using-standard
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
        - name: busybox
          image: busybox
          command: ["sleep", "3600"]
          volumeMounts:
            - name: data
              mountPath: /data
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: pvc-standard

👉 Result: This Deployment will be accepted, because it references pvc-standard, which is bound to an allowed StorageClass (standard).

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions