設定檔適用性:級別 1
預設情況下,容器在其自身的上下文中允許大多數不受限制的執行。獲得容器執行權限的網路攻擊者可以在容器內創建檔案、下載腳本並修改應用程式。Kubernetes 可以鎖定容器的檔案系統,從而防止許多後期利用活動。然而,這些限制也會影響合法的容器應用程式,並可能導致崩潰或異常行為。為了防止損壞合法應用程式,Kubernetes
管理員可以為應用程式需要寫入權限的特定目錄掛載次要讀/寫檔案系統。
稽核
執行以下命令並檢查每個 Pod 容器的 securityContext:
kubectl get pods --all-namespaces
確保每個容器的
securityContext.readOnlyRootFilesystem 設定為 true。補救
將
containers[].securityContext.readOnlyRootFilesystem 更改為 true。以下範例是一個 Kubernetes 部署範本,使用唯讀根檔案系統。
securityContext: readOnlyRootFilesystem: true
設定
volumeMounts 和 volumes 的行顯示如何為需要此功能的應用程式建立可寫入的卷。apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
name: web
spec:
containers:
- command: ["sleep"]
args: ["999"]
image: ubuntu:latest
name: web
securityContext:
readOnlyRootFilesystem: true
volumeMounts:
- mountPath: /writeable/location/here
name: volName
volumes:
- emptyDir: {}
name: volName
