iT邦幫忙

2025 iThome 鐵人賽

DAY 27
0
自我挑戰組

30 天工程師雜學之旅系列 第 27

Kubernetes × HIPAA Part3 控制與政策:RBAC、PSA、Admission、鏡像驗簽與審計

  • 分享至 

  • xImage
  •  

1) RBAC 最小權限實作

反模式:給人或 CI/CD cluster-admin

建議:職能導向角色 + 命名空間邊界。

# 只能讀取同 NS 的 Pod
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: pod-reader
  namespace: ephi-core
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: bind-dev-to-pod-reader
  namespace: ephi-core
subjects:
- kind: Group
  name: devs
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

2) Admission Policy(Gatekeeper / Kyverno)

禁止特權、HostPath、要求資源與探針(Kyverno 範例)

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: disallow-privileged-and-hostpath
spec:
  validationFailureAction: enforce
  rules:
  - name: no-privileged
    match:
      resources:
        kinds: [Pod]
    validate:
      message: "Privileged containers are not allowed"
      pattern:
        spec:
          containers:
          - =(securityContext):
              =(privileged): false
  - name: no-hostpath
    match:
      resources:
        kinds: [Pod]
    validate:
      message: "HostPath volumes are forbidden"
      deny:
        conditions:
          any:
          - key: "{{ request.object.spec.volumes[].hostPath }}"
            operator: NotEquals
            value: null
  - name: require-requests-limits-and-probes
    match:
      resources:
        kinds: [Deployment,StatefulSet,DaemonSet,Job,CronJob]
    validate:
      message: "Containers must set resources and liveness/readiness probes"
      foreach:
      - list: "request.object.spec.template.spec.containers[]"
        deny:
          conditions:
            any:
            - key: "{{ element.resources.requests.cpu }}"
              operator: Equals
              value: null
            - key: "{{ element.livenessProbe }}"
              operator: Equals
              value: null
            - key: "{{ element.readinessProbe }}"
           

鏡像簽章驗證(Cosign)

apiVersion: kyverno.io/v2
kind: ClusterPolicy
metadata:
  name: verify-image-signatures
spec:
  validationFailureAction: enforce
  rules:
    - name: verify-signature
      match:
        resources:
          kinds: [Pod]
      verifyImages:
      - imageReferences:
        - "registry.example.com/*"
        attestors:
        - entries:
          - keys:
              publicKeys: |
                -----BEGIN PUBLIC KEY-----
                ...
                -----END PUBLIC KEY-----

3) K8s 審計(Audit Policy)與留痕

apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: Metadata
  resources:
  - group: ""
    resources: ["secrets"]
- level: RequestResponse
  verbs: ["update","patch","create","delete"]
  resources:
  - group: "rbac.authorization.k8s.io"
    resources: ["roles","rolebindings","clusterroles","clusterrolebindings"]
- level: Metadata
  userGroups: ["system:authenticated"]

審計日誌需送往集中式 SIEM(可用 OTel Collector → Kafka/ELK/Cloud SIEM)。

4) Runtime 偵測(Falco)與基線檢查(CIS/kube‑bench)

  • Falco:偵測容器逃逸、寫可執行檔、shell 啟動等異常行為。
  • kube‑bench:對照 CIS Kubernetes Benchmark 產出報告,納入每季檢核。

5) 相關連結(Part 3)


上一篇
Kubernetes × HIPAA Part2 參考架構藍圖:網段、節點池、mTLS、KMS 與備份
系列文
30 天工程師雜學之旅27
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言