すべてのプロダクト
Search
ドキュメントセンター

Container Compute Service:ACS の定義済みセキュリティポリシー

最終更新日:Dec 27, 2024

ポッドのセキュリティポリシーを設定して、ポッドのデプロイまたは更新のリクエストのセキュリティを検証できます。Alibaba Cloud Container Compute Service (ACS) クラスタポリシー管理機能は、コンプライアンス、インフラ、K8s-general、PSP の 4 つの組み込みルールライブラリを提供します。

背景情報

ACS は、以下のタイプの定義済みセキュリティポリシーを提供します。

  • コンプライアンス: このタイプのセキュリティポリシーは、Alibaba Cloud Kubernetes セキュリティ強化などのコンプライアンス基準に基づいてカスタマイズされます。

  • インフラ: このタイプのセキュリティポリシーは、クラウドインフラストラクチャリソースのセキュリティを確保および強化するために使用されます。

  • K8s-general: このタイプのセキュリティポリシーは、ACS クラスタ内の機密リソースの構成を制限および正規化し、ACS クラスタ内のアプリケーションのセキュリティを強化するために使用されます。

  • PSP: このタイプのセキュリティポリシーは、オープンソース Kubernetes の Pod セキュリティポリシー (PSP) の代替として使用でき、同じアクセス制御機能を提供します。

定義済みセキュリティポリシー

次の表に、ACS の定義済みセキュリティポリシーを示します。

カテゴリ

ポリシー

説明

重大度

コンプライアンス

ACKNoEnvVarSecrets

ポッド環境変数を指定するときに、secretKeyRef パラメータを使用して Secrets を参照することはできません。

ACKPodsRequireSecurityContext

指定された名前空間のポッドは、securityContext パラメータで構成する必要があります。

ACKRestrictNamespaces

指定されたタイプのresourceを、指定された名前空間にデプロイすることはできません。

ACKRestrictRoleBindings

指定された名前空間の RoleBindings は、指定されたロールまたはクラスタロールのバインドにのみ使用できます。

ACKNamespacesDeleteProtection

指定された名前空間は削除できません。

ACKServicesDeleteProtection

指定された名前空間のサービスインスタンスは削除できません。

インフラ

ACKBlockProcessNamespaceSharing

指定された名前空間のポッドは、shareProcessNamespace パラメータで構成することはできません。

ACKEmptyDirHasSizeLimit

emptyDir ボリュームをマウントするときは、sizelimit パラメータを設定する必要があります。

ACKLocalStorageRequireSafeToEvict

指定された名前空間のポッドは、"cluster-autoscaler.kubernetes.io/safe-to-evict": "true" アノテーションで構成する必要があります。デフォルトでは、autoscaler は、自動スケーリングアクティビティ中に hostPath ボリュームまたは emptyDir ボリュームにマウントされているポッドを削除しません。autoscaler がこれらのポッドを削除できるようにするには、このアノテーションをポッドの構成に追加する必要があります。

ACKOSSStorageLocationConstraint

指定されたリージョンの Object Storage Service (OSS) バケットを、指定された名前空間のポッドにマウントできます。

ACKPVSizeConstraint

ACS クラスタに作成される Persistent Volume (PV) にリクエストできる最大ディスク容量を指定します。

ACKPVCConstraint

Persistent Volume Claim (PVC) をデプロイできる名前空間と、PV にリクエストできる最大ディスク容量を指定します。

K8s-general

ACKAllowedRepos

指定された名前空間のポッドは、指定されたイメージリポジトリからのみイメージをプルできます。

ACKBlockAutoinjectServiceEnv

指定された名前空間のポッドは、enableServiceLinks: false で構成する必要があります。これは、サービス IP アドレスがポッド環境変数に挿入されないことを指定します。

ACKBlockAutomountToken

指定された名前空間のポッドは、automountServiceAccountToken: false で構成する必要があります。これは、service accounts が自動的にマウントされないことを指定します。

ACKBlockEphemeralContainer

指定された名前空間のポッドは、一時コンテナを起動できません。

ACKBlockLoadBalancer

LoadBalancer サービスを指定された名前空間にデプロイすることはできません。

ACKContainerLimits

指定された名前空間のポッドは、リソース limits で構成する必要があります。

ACKExternalIPs

指定された名前空間のサービスは、ポリシーコンテンツで指定されていない外部 IP アドレスを使用できません。

ACKImageDigests

指定された名前空間のポッドは、ダイジェストが指定された形式に準拠するイメージからデプロイする必要があります。

ACKRequiredLabels

指定された名前空間のポッドには、ポリシーコンテンツに準拠するラベルが必要です。

ACKRequiredProbes

指定された名前空間のポッドは、指定されたタイプの readiness probe と liveness probe で構成する必要があります。

ACKCheckNginxAnnotation

Ingress 構成の metadata.annotations パラメータには、危険な設定を含めることができません。1.2.1 より前の ingress-nginx バージョンでは、このポリシーを有効にすることをお勧めします。

ACKBlockInternetLoadBalancer

インターネット向け LoadBalancer サービスを作成できません。

PSP

ACKPSPAllowPrivilegeEscalationContainer

指定された名前空間のポッドは、allowPrivilegeEscalation パラメータで構成する必要があります。

ACKPSPAllowedUsers

指定された名前空間のポッドは、usergroupsupplementalGroups、および fsGroup 設定で構成する必要があります。

ACKPSPAppArmor

指定された名前空間のポッドは、AppArmor 設定で構成する必要があります。

ACKPSPCapabilities

指定された名前空間のポッドは、Linux ケーパビリティ設定で構成する必要があります。

ACKPSPFSGroup

指定された名前空間のポッドは、ポリシーコンテンツに準拠する fsGroup 設定で構成する必要があります。

ACKPSPFlexVolumes

指定された名前空間のポッドは、ポリシーコンテンツで指定されていない FlexVolume ドライバを使用できません。

ACKPSPForbiddenSysctls

指定された名前空間のポッドは、指定された sysctl を使用できません。

ACKPSPHostFilesystem

指定された名前空間のポッドにマウントされている hostPath ボリュームは、指定された条件を満たしている必要があります。

ACKPSPPrivilegedContainer

指定された名前空間のポッドは、特権コンテナを実行できません。

ACKPSPReadOnlyRootFilesystem

指定された名前空間のポッドは、読み取り専用のルートファイルシステムで実行する必要があります。

ACKPSPSELinuxV2

指定された名前空間のポッドは、ポリシーコンテンツで指定されていない SELinux オプションで構成することはできません。

ACKPSPSeccomp

指定された名前空間のポッドは、指定された seccomp プロファイルで構成する必要があります。

ACKPSPVolumeTypes

指定された名前空間のポッドには、指定されたタイプのボリュームのみをマウントできます。

コンプライアンス

  • ACKNoEnvVarSecrets

    ポリシーの説明: ポッド環境変数を指定するときに、secretKeyRef パラメータを使用して Secrets を参照することはできません。

    重大度: 中

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKNoEnvVarSecrets
    metadata:
      name: no-env-var-secrets
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces: ["test-gatekeeper"]

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: mypod
      namespace: test-gatekeeper
    spec:
      containers:
      - name: mypod
        image: testimage
        volumeMounts:
        - name: foo
          mountPath: "/etc/foo"
      volumes:
      - name: foo
        secret:
          secretName: mysecret
          items:
          - key: username
            path: my-group/my-username

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - name: mycontainer
        image: testimage
        env:
          - name: SECRET_USERNAME
            valueFrom:
              secretKeyRef:
                name: mysecret
                key: username
          - name: SECRET_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mysecret
                key: password
      restartPolicy: Never
  • ACKPodsRequireSecurityContext

    ポリシーの説明: 指定された名前空間のポッドは、securityContext パラメータで構成する必要があります。

    重大度: 低

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPodsRequireSecurityContext
    metadata:
      name: pods-require-security-context
      annotations:
        description: "Requires that Pods must have a `securityContext` defined." // ポッドに `securityContext` が定義されている必要があります。
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces: ["test-gatekeeper"]

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: test
      namespace: test-gatekeeper
    spec:
      securityContext:
        runAsNonRoot: false
      containers:
      - image: test
        name: test
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Never
    status: {}

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad
      namespace: non-test-gatekeeper
    spec:
      containers:
      - image: testimage
        name: test2
      - image: testimage
        name: test
        resources: {}
        securityContext:
          runAsNonRoot: false
  • ACKRestrictNamespaces

    ポリシーの説明: 指定されたタイプのresourceを、指定された名前空間にデプロイすることはできません。

    重大度: 低

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    restrictedNamespaces

    配列

    リソースをデプロイできない名前空間の名前を指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKRestrictNamespaces
    metadata:
      name: restrict-default-namespace
      annotations:
        description: "Restricts resources from using the restricted namespace." // 制限された名前空間の使用からリソースを制限します。
    spec:
      match:
        kinds:
          - apiGroups: ['']
            kinds: ['Pod']
      parameters:
        restrictedNamespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: test
      namespace: non-test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Never
    status: {}

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - name: mycontainer
        image: testimage
      restartPolicy: Never
  • ACKRestrictRoleBindings

    ポリシーの説明: 指定された名前空間の Rolebindings は、指定されたロールまたはクラスタロールのバインドにのみ使用できます。

    重大度: 高

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    restrictedRole

    オブジェクト

    割り当てが許可されていないクラスタロールまたはロールを指定します。

    allowedSubjects

    配列

    マウントできるサブジェクトを指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKRestrictRoleBindings
    metadata:
      name: restrict-clusteradmin-rolebindings
      annotations:
        description: "Restricts use of sensitive role in specific rolebinding." // 特定のロールバインディングでの機密ロールの使用を制限します。
    spec:
      match:
        kinds:
          - apiGroups: ["rbac.authorization.k8s.io"]
            kinds: ["RoleBinding"]
      parameters:
        restrictedRole:
          apiGroup: "rbac.authorization.k8s.io"
          kind: "ClusterRole"
          name: "cluster-admin"
        allowedSubjects:
          - apiGroup: "rbac.authorization.k8s.io"
            kind: "Group"
            name: "system:masters"

    許可:

    kind: RoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: good-2
      namespace: test-gatekeeper
    subjects:
      - kind: Group
        name: 'system:masters'
    roleRef:
      kind: ClusterRole
      name: cluster-admin
      apiGroup: rbac.authorization.k8s.io

    拒否:

    kind: RoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: bad-1
      namespace: test-gatekeeper
    subjects:
      - kind: ServiceAccount
        name: policy-template-controller
    roleRef:
      kind: ClusterRole
      name: cluster-admin
      apiGroup: rbac.authorization.k8s.io
  • ACKNamespacesDeleteProtection

    ポリシーの説明: 指定された名前空間は削除できません。protectionNamespaces パラメータを、削除できない名前空間の名前に設定できます。

    このポリシーを有効にするには、gatekeeper 3.10.0.130-g0e79597d-aliyun 以降を使用する必要があります。gatekeeper のバージョンの詳細については、gatekeeper を参照してください。

    重大度: 中

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    protectionNamespaces

    配列

    削除できない名前空間の名前。

    例:

    制約:

       apiVersion: constraints.gatekeeper.sh/v1beta1
      kind: ACKNamespacesDeleteProtection
      metadata:
        name: namespace-delete-protection
      spec:
        match:
          kinds:
            - apiGroups: ['']
              kinds: ['Namespace']
        parameters:
          protectionNamespaces:
            - test-gatekeeper

    許可:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: will-delete

    拒否:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: test-gatekeeper
  • ACKServicesDeleteProtection

    ポリシーの説明: 指定された名前空間のサービスインスタンスは削除できません。protectionServices パラメータを、削除できないサービスインスタンスの名前に設定できます。

    重大度: 中

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    protectionServices

    配列

    指定された名前空間で削除できないサービスインスタンスの名前。

    例:

    制約:

      apiVersion: constraints.gatekeeper.sh/v1beta1
      kind: ACKServicesDeleteProtection
      metadata:
        name: service-delete-protection
        annotations:
          description: "Protect to delete specific service." // 特定のサービスの削除を保護します。
      spec:
        enforcementAction: deny
        match:
          kinds:
            - apiGroups: ['']
              kinds: ['Service']
          namespaces: ["test-gatekeeper"]
        parameters:
          protectionServices:
            - test-svc

    許可:

    apiVersion: v1
    kind: Service
    metadata:
      name: good
      namespace: test-gatekeeper

    拒否:

    apiVersion: v1
    kind: Service
    metadata:
      name: test-svc
    

インフラ

  • ACKBlockProcessNamespaceSharing

    ポリシーの説明: 指定された名前空間のポッドは、shareProcessNamespace パラメータで構成```

    ポリシーの説明: 指定された名前空間のポッドは、shareProcessNamespace パラメータで構成することはできません。

    重大度: 高

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKBlockProcessNamespaceSharing
    ACKCheckNginxPathmetadata:
      name: block-share-process-namespace
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces: ["test-gatekeeper"]

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: test-3
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Never
    status: {}

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad
      namespace: test-gatekeeper
    spec:
      shareProcessNamespace: true
      containers:
      - image: test
        name: test
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Never
    status: {}
  • ACKEmptyDirHasSizeLimit

    ポリシーの説明: emptyDir ボリュームをマウントするときは、sizelimit パラメータを設定する必要があります。

    重大度: 低

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKEmptyDirHasSizeLimit
    metadata:
      name: empty-dir-has-sizelimit
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces: ["test-gatekeeper"]

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test-container
        volumeMounts:
        - mountPath: /cache
          name: cache-volume
      volumes:
      - name: cache-volume
        emptyDir:
          sizeLimit: "10Mi"

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test-container
        volumeMounts:
        - mountPath: /cache
          name: cache-volume
      volumes:
      - name: cache-volume
        emptyDir: {}
  • ACKLocalStorageRequireSafeToEvict

    ポリシーの説明: 指定された名前空間のポッドは、"cluster-autoscaler.kubernetes.io/safe-to-evict": "true" アノテーションで構成する必要があります。このアノテーションで構成されていないポッドは、スケーリングアクティビティ中に削除されません。

    重大度: 低

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKLocalStorageRequireSafeToEvict
    metadata:
      name: local-storage-require-safe-to-evict
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces: ["test-gatekeeper"]

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-1
      namespace: test-gatekeeper
      annotations:
        'cluster-autoscaler.kubernetes.io/safe-to-evict': 'true'
    spec:
      containers:
      - image: test
        name: test-container
        volumeMounts:
        - mountPath: /test-pd
          name: test-volume
      volumes:
      - name: test-volume
        hostPath:
          # directory location on host // ホスト上のディレクトリの場所
          path: /data
          # this field is optional // このフィールドはオプションです
          type: Directory

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test-container
        volumeMounts:
        - mountPath: /cache
          name: cache-volume
      volumes:
      - name: cache-volume
        emptyDir: {}
  • ACKOSSStorageLocationConstraint

    ポリシーの説明: 指定されたリージョンの OSS バケットを、指定された名前空間のポッドにマウントできるかどうかを指定します。

    重大度: 低

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    mode

    文字列

    ホワイトリストモードを有効にするかどうかを指定します。デフォルト値: allowlist。これは、ホワイトリストモードが有効になっていることを示します。その他の値は、ブラックリストモードが有効になっていることを示します。

    regions

    配列

    指定されたリージョン ID。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKOSSStorageLocationConstraint
    metadata:
      name: restrict-oss-location
      annotations:
        description: "Restricts location of oss storage in cluster." // クラスタ内の OSS ストレージの場所を制限します。
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["PersistentVolume", "Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        mode: "allowlist"
        regions:
          - "cn-beijing"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-oss-csi-good
      namespace: test-gatekeeper
    spec:
      containers:
        - name: test
          image: test
      volumes:
        - name: test
          csi:
            driver: ossplugin.csi.alibabacloud.com
            volumeAttributes:
              bucket: "oss"
              url: "oss-cn-beijing.aliyuncs.com"
              otherOpts: "-o max_stat_cache_size=0 -o allow_other"
              path: "/"

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-oss-csi
      namespace: test-gatekeeper
    spec:
      containers:
        - name: test
          image: test
      volumes:
        - name: test
          csi:
            driver: ossplugin.csi.alibabacloud.com
            volumeHandle: pv-oss
            nodePublishSecretRef:
              name: oss-secret
              namespace: default
            volumeAttributes:
              bucket: "oss"
              url: "oss-cn-hangzhou.aliyuncs.com"
              otherOpts: "-o max_stat_cache_size=0 -o allow_other"
              path: "/"
  • ACKPVSizeConstraint

    ポリシーの説明: ACS クラスタに作成される永続ボリューム (PV) にリクエストできる最大ディスク容量を指定します。

    重大度: 中

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    maxSize

    文字列

    ACS クラスタの PV にリクエストできる最大ディスク容量。デフォルト値: 50 GiB。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPVSizeConstraint
    metadata:
      name: limit-pv-size
      annotations:
        description: "Limit the pv storage capacity size within a specified maximum amount." // 指定された最大量以内に PV ストレージ容量サイズを制限します。
    spec:
      enforcementAction: deny
      match:
        kinds:
          - apiGroups: [ "" ]
            kinds: [ "PersistentVolume" ]
      parameters:
        maxSize: "50Gi"

    許可:

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: pv-oss-csi
      labels:
        alicloud-pvname: pv-oss
    spec:
      capacity:
        storage: 25Gi
      accessModes:
        - ReadWriteMany
      persistentVolumeReclaimPolicy: Retain
      csi:
        driver: ossplugin.csi.alibabacloud.com
        volumeHandle: pv-oss
        nodePublishSecretRef:
          name: oss-secret
          namespace: default
        volumeAttributes:
          bucket: "oss"
          url: "oss-cn-beijing.aliyuncs.com"
          otherOpts: "-o max_stat_cache_size=0 -o allow_other"
          path: "/"

    拒否:

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: pv-oss-csi-bad
      labels:
        alicloud-pvname: pv-oss
    spec:
      capacity:
        storage: 500Gi
      accessModes:
        - ReadWriteMany
      persistentVolumeReclaimPolicy: Retain
      csi:
        driver: ossplugin.csi.alibabacloud.com
        volumeHandle: pv-oss
        nodePublishSecretRef:
          name: oss-secret
          namespace: default
        volumeAttributes:
          bucket: "oss"
          url: "oss-cn-beijing.aliyuncs.com"
          otherOpts: "-o max_stat_cache_size=0 -o allow_other"
          path: "/"
  • ACKPVCConstraint

    ポリシーの説明: PVC をデプロイできる名前空間と、PV にリクエストできる最大ディスク容量を指定します。

    重大度: 中

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    maxSize

    文字列

    PV にリクエストできる最大ディスク容量。デフォルト値: 50 GiB。

    allowNamespaces

    配列

    PVC をデプロイできる名前空間の名前。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPVCConstraint
    metadata:
      name: limit-pvc-size-and-ns
      annotations:
        description: "Limit the maximum pvc storage capacity size and the namespace whitelists that can be deployed." // デプロイできる最大 PVC ストレージ容量サイズと名前空間ホワイトリストを制限します。
    spec:
      enforcementAction: deny
      match:
        kinds:
          - apiGroups: [ "" ]
            kinds: [ "PersistentVolumeClaim" ]
      parameters:
        maxSize: "50Gi"
        allowNamespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: disk-pvc
      namespace: test-gatekeeper
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 20Gi

    拒否:

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: bad-disk-pvc
      namespace: test-gatekeeper
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 200Gi
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: bad-namespace-pvc
      namespace: test-gatekeeper-bad
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 20Gi      

K8s-general

  • ACKAllowedRepos

    ポリシーの説明: 指定された名前空間のポッドは、指定されたイメージリポジトリからのみイメージをプルできます。

    重大度: 高

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    repos

    配列

    ポッドがイメージをプルできるイメージリポジトリを指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKAllowedRepos
    metadata:
      name: allowed-repos
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        repos:
          - "registry-vpc.cn-hangzhou.aliyuncs.com/acs/"
          - "registry.cn-hangzhou.aliyuncs.com/acs/"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-01
      namespace: test-gatekeeper
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/acs/test-webserver
        name: test-container-1
      initContainers:
      - image: registry.cn-hangzhou.aliyuncs.com/acs/test-webserver
        name: test-container

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad-1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test-container
      initContainers:
      - image: test
        name: test-container-3
  • ACKBlockAutoinjectServiceEnv

    ポリシーの説明: 指定された名前空間のポッドは、enableServiceLinks: false で構成する必要があります。これは、サービス IP アドレスがポッド環境変数に挿入されないことを指定します。

    重大度: 低

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKBlockAutoinjectServiceEnv
    metadata:
      name: block-auto-inject-service-env
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-0
      namespace: test-gatekeeper
    spec:
      enableServiceLinks: false
      containers:
      - image: openpolicyagent/test-webserver:1.0
        name: test-container

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad-1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test-container
  • ACKBlockAutomountToken

    ポリシーの説明: 指定された名前空間のポッドは、automountServiceAccountToken: false で構成する必要があります。これは、service accounts が自動的にマウントされないことを指定します。

    重大度: 高

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKBlockAutomountToken
    metadata:
      name: block-auto-mount-service-account-token
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-0
      namespace: test-gatekeeper
    spec:
      automountServiceAccountToken: false
      containers:
      - image: openpolicyagent/test-webserver:v1.0
        name: test-container

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad-1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test-container
  • ACKBlockEphemeralContainer

    ポリシーの説明: 指定された名前空間のポッドは、一時コンテナを起動できません。

    重大度: 中

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKBlockEphemeralContainer
    metadata:
      name: block-ephemeral-container
    spec:
      enforcementAction: deny
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: good-1
      namespace: test-gatekeeper
    spec:
      containers:
      - name: mycontainer
        image: testimage

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad-1
      namespace: non-test-gatekeeper
    spec:
      containers:
      - name: mycontainer
        image: testimage
      ephemeralContainers:
        - name: test
          image: test
  • ACKBlockLoadBalancer

    ポリシーの説明: LoadBalancer サービスを指定された名前空間にデプロイすることはできません。

    重大度: 高

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    restrictedNamespaces

    配列

    リソースをデプロイできない名前空間の名前を指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKBlockLoadBalancer
    metadata:
      name: block-load-balancer
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Service"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service-1
      namespace: test-gatekeeper
    spec:
      selector:
        app: MyApp
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 9376

    拒否:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service
      namespace: test-gatekeeper
    spec:
      type: LoadBalancer
      selector:
        app: MyApp
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 9376
  • ACKBlockNodePort

    ポリシーの説明: NodePort サービスを指定された名前空間にデプロイすることはできません。

    重大度: 低

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKBlockNodePort
    metadata:
      name: block-node-port
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Service"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service-1
      namespace: test-gatekeeper
    spec:
      selector:
        app: MyApp
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 9376

    拒否:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service
      namespace: test-gatekeeper
    spec:
      type: NodePort
      selector:
        app: MyApp
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 9376
  • ACKContainerLimits

    ポリシーの説明: 指定された名前空間のポッドは、リソース limits で構成する必要があります。

    重大度: 低

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKContainerLimits
    metadata:
      name: container-must-have-limits
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        cpu: "1000m"
        memory: "1Gi"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: openpolicyagent/test-webserver
        name: test-container
        resources:
          limits:
            memory: "100Mi"
            cpu: "500m"

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-2
      namespace: non-test-gatekeeper
    spec:
      containers:
      - image: openpolicyagent/test-webserver
        name: test-container
        resources:
          limits:
            memory: "100Gi"
            cpu: "2000m"
  • ACKExternalIPs

    ポリシーの説明: 指定された名前空間のサービスは、ポリシーコンテンツで指定されていない 外部 IP アドレス を使用できません。

    重大度: 高

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    allowedIPs

    配列

    使用できる 外部 IP アドレス を指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKExternalIPs
    metadata:
      name: external-ips
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Service"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        allowedIPs:
          - "192.168.0.5"

    許可:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service-3
      namespace: test-gatekeeper
    spec:
      selector:
        app: MyApp
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 9376

    拒否:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service
      namespace: test-gatekeeper
    spec:
      selector:
        app: MyApp
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 9376
      externalIPs:
        - 80.11.XX.XX
  • ACKImageDigests

    ポリシーの説明: 指定された名前空間のポッドは、ダイジェスト が指定された形式に準拠するイメージからデプロイする必要があります。

    重大度: 低

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKImageDigests
    metadata:
      name: container-image-must-have-digest
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-0
      namespace: test-gatekeeper
    spec:
      containers:
      - image: openpolicyagent/test-webserver@sha256:12e469267d21d66ac9dcae33a4d3d202ccb2591869270b95d0aad7516c7d075b
        name: test-container

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad-1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test-container
      initContainers:
      - image: test
        name: test-container2
  • ACKRequiredLabels

    ポリシーの説明: 指定された名前空間のポッドには、ラベルallowedRegex パラメータで指定されている必要があります。

    重大度: 低

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    allowedRegex

    文字列

    正規表現でラベルを指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKRequiredLabels
    metadata:
      name: must-have-label-test
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
    #            message: ''
        labels:
          - key: test
            # value // 値
            allowedRegex: "^test.*$"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      name: test
      namespace: test-gatekeeper
      labels:
        'test': 'test_233'
    spec:
      containers:
      - name: mycontainer
        image: testimage

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      name: bad2
      namespace: test-gatekeeper
      labels:
        'test': '233'
    spec:
      containers:
      - name: mycontainer
        image: testimage
  • ACKRequiredProbes

    ポリシーの説明: 指定された名前空間のポッドは、指定されたタイプの readiness probe および liveness probe で構成する必要があります。

    重大度: 中

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    probes

    配列

    ポッドに設定する必要があるプローブを指定します。有効な値: readinessProbe および livenessProbe

    probeTypes

    配列

    ポッドに設定する必要があるプローブのタイプを指定します。有効な値: tcpSockethttpGet、および exec

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKRequiredProbes
    metadata:
      name: must-have-probes
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        probes: ["readinessProbe", "livenessProbe"]
        probeTypes: ["tcpSocket", "httpGet", "exec"]

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: p4
      namespace: test-gatekeeper
    spec:
      containers:
      - name: liveness
        image: k8s.gcr.io/busybox
        readinessProbe:
          exec:
            command:
              - cat
              - /tmp/healthy
          initialDelaySeconds: 5
          periodSeconds: 5
        livenessProbe:
          exec:
            command:
              - cat
              - /tmp/healthy
          initialDelaySeconds: 5
          periodSeconds: 5

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: p1
      namespace: test-gatekeeper
    spec:
      containers:
      - name: liveness
        image: k8s.gcr.io/busybox
  • ACKCheckNginxPath

    このポリシーは、Ingress の spec.rules[].http.paths[].path フィールドでリスクの高い構成を使用することを防ぎます。バージョンが 1.2.1 より前の Ingress-nginx に対してこのポリシーを有効にすることをお勧めします。

    重大度: 高

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKCheckNginxPath
    metadata:
      name: block-nginx-path
    spec:
      enforcementAction: deny
      match:
        kinds:
          - apiGroups: ["extensions", "networking.k8s.io"]
            kinds: ["Ingress"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: good-paths
      namespace: test-gatekeeper
    spec:
      rules:
        - host: cafe.example.com
          http:
            paths:
              - path: /tea
                pathType: Prefix
                backend:
                  service:
                    name: tea-svc
                    port:
                      number: 80
              - path: /coffee
                pathType: Prefix
                backend:
                  service:
                    name: coffee-svc
                    port:
                      number: 80

    拒否:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: bad-path-secrets
      namespace: test-gatekeeper
    spec:
      rules:
        - host: cafe.example.com
          http:
            paths:
              - path: /var/run/secrets
                pathType: Prefix
                backend:
                  service:
                    name: tea-svc
                    port:
                      number: 80
  • ACKCheckNginxAnnotation

    このポリシーは、Ingress の metadata.annotations フィールドでリスクの高い構成を使用することを防ぎます。バージョンが 1.2.1 より前の Ingress-nginx に対してこのポリシーを有効にすることをお勧めします。

    重大度: 高

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKCheckNginxAnnotation
    metadata:
      name: block-nginx-annotation
    spec:
      match:
        kinds:
          - apiGroups: ["extensions", "networking.k8s.io"]
            kinds: ["Ingress"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: good-annotations
      namespace: test-gatekeeper
      annotations:
        nginx.org/good: "value"
    spec:
      rules:
        - host: cafe.example.com
          http:
            paths:
              - path: /tea
                pathType: Prefix
                backend:
                  service:
                    name: tea-svc
                    port:
                      number: 80
              - path: /coffee
                pathType: Prefix
                backend:
                  service:
                    name: coffee-svc
                    port:
                      number: 80

    拒否:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: var-run-secrets
      namespace: test-gatekeeper
      annotations:
        nginx.org/bad: "/var/run/secrets"
    spec:
      rules:
        - host: cafe.example.com
          http:
            paths:
              - path: /tea
                pathType: Prefix
                backend:
                  service:
                    name: tea-svc
                    port:
                      number: 80
              - path: /coffee
                pathType: Prefix
                backend:
                  service:
                    name: coffee-svc
                    port:
                      number: 80
  • ACKBlockInternetLoadBalancer

    ポリシーの説明: インターネット向け LoadBalancer サービスを作成できません。

    重大度: 高

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKBlockInternetLoadBalancer
    metadata:
      name: block-internet-load-balancer
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Service"]
        namespaces: ["test-gatekeeper"]

    許可:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service
      namespace: non-test-gatekeeper
      annotations:
        'service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type': 'intranet'
    spec:
      selector:
        app: MyApp
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 9376
      type: LoadBalancer

    拒否:

    apiVersion: v1
    kind: Service
    metadata:
      name: bad-service-2
      namespace: test-gatekeeper
      annotations:
        'service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type': 'internet'
    spec:
      type: LoadBalancer
      selector:
        app: MyApp
      ports:
        - name: http
          protocol: TCP
          port: 80
          targetPort: 9376

PSP

  • ACKPSPAllowedUsers

    ポリシーの説明: 指定された名前空間のポッドは、usergroupsupplementalGroups、および fsGroup 設定で構成する必要があります。

    重大度: 中

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    runAsUser

    オブジェクト

    パラメータの詳細については、Kubernetes の PSP におけるユーザーの構成、サポートされているルールタイプ、UID の最大値と最小値を参照してください。詳細については、ユーザーとグループを参照してください。

    runAsGroup

    オブジェクト

    パラメータの詳細については、Kubernetes の PSP におけるグループの構成、サポートされているルールタイプ、UID の最大値と最小値を参照してください。詳細については、ユーザーとグループを参照してください。

    supplementalGroups

    オブジェクト

    パラメータの詳細については、Kubernetes の PSP における SupplementalGroups の構成、サポートされているルールタイプ、UID の最大値と最小値を参照してください。詳細については、ユーザーとグループを参照してください。

    fsGroup

    オブジェクト

    パラメータの詳細については、Kubernetes の PSP における fsGroup の構成、サポートされているルールタイプ、UID の最大値と最小値を参照してください。詳細については、ユーザーとグループを参照してください。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPAllowedUsers
    metadata:
      name: psp-pods-allowed-user-ranges
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        runAsUser:
          rule: MustRunAs # MustRunAsNonRoot # RunAsAny
          ranges:
            - min: 100
              max: 200
        runAsGroup:
          rule: MustRunAs # MayRunAs # RunAsAny
          ranges:
            - min: 100
              max: 200
        supplementalGroups:
          rule: MustRunAs # MayRunAs # RunAsAny
          ranges:
            - min: 100
              max: 200
        fsGroup:
          rule: MustRunAs # MayRunAs # RunAsAny
          ranges:
            - min: 100
              max: 200

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good2
      namespace: test-gatekeeper
    spec:
      securityContext:
        fsGroup: 150
        supplementalGroups:
          - 150
      containers:
      - image: test
        name: test
        securityContext:
          runAsUser: 150
          runAsGroup: 150

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
  • ACKPSPAllowPrivilegeEscalationContainer

    ポリシーの説明: 指定された名前空間のポッドは、allowPrivilegeEscalation パラメータで構成する必要があります。

    重大度: 中

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPAllowPrivilegeEscalationContainer
    metadata:
      name: psp-allow-privilege-escalation-container
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        securityContext:
          allowPrivilegeEscalation: false
      initContainers:
        - image: test
          name: test2
          securityContext:
            allowPrivilegeEscalation: false

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
  • ACKPSPAppArmor

    ポリシーの説明: 指定された名前空間のポッドは AppArmor 設定で構成する必要があります。

    重大度: 低

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    probes

    配列

    ポッドに構成する必要があるプローブを指定します。有効な値:readinessProbe および livenessProbe

    probeTypes

    配列

    ポッドに構成する必要があるプローブのタイプを指定します。有効な値:tcpSockethttpGet、および exec

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPAppArmor
    metadata:
      name: psp-apparmor
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        allowedProfiles:
          - runtime/default

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good
      namespace: test-gatekeeper
      annotations:
        'container.apparmor.security.beta.kubernetes.io/test': 'runtime/default'
        'container.apparmor.security.beta.kubernetes.io/test2': 'runtime/default'
    spec:
      containers:
      - image: test
        name: test
      initContainers:
      - image: test
        name: test2

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
  • ACKPSPCapabilities

    ポリシーの説明: 指定された名前空間のポッドは Linux ケーパビリティ設定で構成する必要があります。

    重大度: 高

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    allowedCapabilities

    配列

    ポッドに構成できる ケーパビリティ を指定します。

    requiredDropCapabilities

    配列

    ポッドに構成できない ケーパビリティ を指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPCapabilities
    metadata:
      name: psp-capabilities
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        allowedCapabilities: ["CHOWN"]
        requiredDropCapabilities: ["NET_ADMIN", "SYS_ADMIN", "NET_RAW"]

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good-4
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        securityContext:
          capabilities:
            add:
              - CHOWN
            drop:
             - "NET_ADMIN"
             - "SYS_ADMIN"
             - "NET_RAW"

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad-1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
  • ACKPSPFlexVolumes

    ポリシーの説明: 指定された名前空間のポッドは、ポリシーコンテンツで指定されていない FlexVolume ドライバを使用できません。

    重大度: 中

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    allowedFlexVolumes

    配列

    ポッドが使用できる FlexVolume ドライバを指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPFlexVolumes
    metadata:
      name: psp-flexvolume-drivers
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod", "PersistentVolume"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        allowedFlexVolumes: #[]
          - driver: "alicloud/disk"
          - driver: "alicloud/nas"
          - driver: "alicloud/oss"
          - driver: "alicloud/cpfs"
    許可:apiVersion: v1 kind: Pod metadata: name: pv-nas namespace```

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pv-nas
      namespace: test-gatekeeper
    spec:
      containers:
        - name: test
          image: test
      volumes:
        - name: test
          flexVolume:
            driver: "alicloud/nas"

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pv-oss-flexvolume
      namespace: test-gatekeeper
    spec:
      containers:
        - name: test
          image: test
      volumes:
        - name: test
          flexVolume:
            driver: "alicloud/ossxx"
  • ACKPSPForbiddenSysctls

    ポリシーの説明: 指定された名前空間のポッドは、指定された sysctl を使用できません。

    重大度: 高

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    forbiddenSysctls

    配列

    ポッドが使用できない sysctl を指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPForbiddenSysctls
    metadata:
      name: psp-forbidden-sysctls
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        forbiddenSysctls:
          # - "*" # * may be used to forbid all sysctls // * はすべての sysctl を禁止するために使用できます
          - "kernel.*"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good-2
      namespace: test-gatekeeper
    spec:
      securityContext:
        sysctls:
          - name: 'net.ipv4.tcp_syncookies'
            value: "65536"
      containers:
      - image: test
        name: test

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad-1
      namespace: test-gatekeeper
    spec:
      securityContext:
        sysctls:
          - name: 'kernel.shm_rmid_forced'
            value: '1024'
      containers:
      - image: test
        name: test
  • ACKPSPFSGroup

    ポリシーの説明: 指定された名前空間のポッドは、ポリシーコンテンツに準拠する fsGroup 設定で構成する必要があります。

    重大度: 中

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    rule

    文字列

    パラメータの詳細については、Kubernetes の PSP の fsGroup の構成を参照してください。MustRunAsMayRunAs、および RunAsAny パラメータがサポートされています。詳細については、ボリュームとファイルシステムを参照してください。

    ranges

    オブジェクト

    有効な値:

    • min: fsGroup ID の最小値。

    • max: fsGroup ID の最大値。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPFSGroup
    metadata:
      name: psp-fsgroup
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        rule: "MayRunAs" #"MustRunAs" #"MayRunAs", "RunAsAny"
        ranges:
          - min: 1
            max: 1000

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good
      namespace: test-gatekeeper
    spec:
      securityContext:
        fsGroup: 100
      containers:
      - image: test
        name: test

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad-1
      namespace: non-test-gatekeeper
    spec:
      securityContext:
        fsGroup: 0
      shareProcessNamespace: true
      containers:
      - image: test
        name: test
  • ACKPSPHostFilesystem

    ポリシーの説明: 指定された名前空間のポッドにマウントされている hostPath ボリュームは、指定された条件を満たしている必要があります。

    重大度: 高

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    allowedHostPaths

    オブジェクト

    ポッドにマウントできる hostPath ボリュームを指定します。

    readOnly

    ブール値

    ボリュームが読み取り専用かどうかを指定します。

    pathPrefix

    文字列

    ボリュームのプレフィックスを指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPHostFilesystem
    metadata:
      name: psp-host-filesystem
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        allowedHostPaths:
          - readOnly: true
            pathPrefix: "/foo"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        volumeMounts:
          - name: test-volume
            mountPath: "/projected-volume"
            readOnly: true
      volumes:
      - name: test-volume
        hostPath:
          path: /foo

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
      volumes:
      - name: test-volume
        hostPath:
          path: /data
          type: File
  • ACKPSPHostNamespace

    ポリシーの説明: 指定された名前空間のポッドは、ホストの名前空間を共有できません。

    重大度: 高

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPHostNamespace
    metadata:
      name: psp-host-namespace
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Never
    status: {}

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad
      namespace: test-gatekeeper
    spec:
      hostPID: true
      containers:
      - image: test
        name: test
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Never
    status: {}
  • ACKPSPHostNetworkingPorts

    ポリシーの説明: 指定された名前空間のポッドがホストネットワークと指定されたポートを使用できるかどうかを指定します。

    重大度: 高

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    hostNetwork

    ブール値

    ポッドがホストネットワークを使用できるかどうかを指定します。

    min

    整数

    最小ホストポート番号を指定します。

    max

    整数

    最大ホストポート番号を指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPHostNetworkingPorts
    metadata:
      name: psp-host-network-ports
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        hostNetwork: true
        min: 80
        max: 9000

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: good-2
      namespace: test-gatekeeper
    spec:
      hostNetwork: true
      containers:
      - image: test
        name: test-container
        ports:
          - hostPort: 80
            containerPort: 80
      initContainers:
        - image: test
          name: test-container2
          ports:
            - hostPort: 8080
              containerPort: 8080

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      name: bad-1
      namespace: non-test-gatekeeper
    spec:
      hostNetwork: true
      containers:
      - image: test
        name: test-container
        ports:
          - hostPort: 22
            containerPort: 22
  • ACKPSPPrivilegedContainer

    ポリシーの説明: 指定された名前空間のポッドは、特権コンテナを実行できません。

    重大度: 高

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPPrivilegedContainer
    metadata:
      name: psp-privileged-container
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        securityContext:
          privileged: true
      dnsPolicy: ClusterFirst
      restartPolicy: Never
  • ACKPSPProcMount

    ポリシーの説明: 指定された名前空間のポッドは、ポリシーコンテンツで指定された Proc Mount タイプで構成する必要があります。

    重大度: 高

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    procMount

    文字列

    Proc Mount タイプを指定します。有効な値:

    • Default: /proc ディレクトリをマウントできません。

    • Unmasked: /proc ディレクトリをマウントできます。

    詳細については、AllowedProcMountTypes を参照してください。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPProcMount
    metadata:
      name: psp-proc-mount
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        procMount: Default  # Default or Unmasked // Default または Unmasked
    

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        securityContext:
          procMount: "Default"

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad3
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        securityContext:
          procMount: "Unmasked"
      initContainers:
      - image: test
        name: test2
  • ACKPSPReadOnlyRootFilesystem

    ポリシーの説明: 指定された名前空間のポッドは、読み取り専用のルートファイルシステムで実行する必要があります。

    重大度: 中

    パラメータの説明: なし

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPReadOnlyRootFilesystem
    metadata:
      name: psp-readonlyrootfilesystem
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good1
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        securityContext:
          readOnlyRootFilesystem: true

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad2
      namespace: non-test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        securityContext:
          readOnlyRootFilesystem: false
      initContainers:
      - image: test
        name: test2
  • ACKPSPSeccomp

    ポリシーの説明: 指定された名前空間のポッドは、指定された seccomp プロファイルで構成する必要があります。

    重大度: 低

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    allowedProfileTypes

    配列

    許可される seccomp プロファイルのタイプを指定します。

    allowedProfiles

    配列

    許可される seccomp プロファイルを指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPSeccomp
    metadata:
      name: psp-seccomp
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        allowedProfileTypes:
          # - Unconfined
          - RuntimeDefault
          - Localhost
        allowedProfiles:
          - runtime/default
          - docker/default
          - localhost/profiles/audit.json

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        securityContext:
          seccompProfile:
            type: Localhost
            localhostProfile: profiles/audit.json
      initContainers:
      - image: test
        name: test2
        securityContext:
          seccompProfile:
            type: Localhost
            localhostProfile: profiles/audit.json

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
        echo-k8s-webhook-enabled: 'true'
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
  • ACKPSPSELinuxV2

    ポリシーの説明: 指定された名前空間のポッドは、allowedSELinuxOptions パラメータで指定されていない SELinux オプションで構成することはできません。

    重大度: 低

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    allowedSELinuxOptios

    オブジェクト

    ポッドに構成できる SELinux オプションを指定します。詳細については、SELinuxOptions v1 core を参照してください。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPSELinuxV2
    metadata:
      name: psp-selinux-v2
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        allowedSELinuxOptions:
          - level: s0:c123,c456
            role: object_r
            type: svirt_sandbox_file_t
            user: system_u

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: good
      namespace: test-gatekeeper
    spec:
      securityContext:
        seLinuxOptions:
          level: "s0:c123,c456"
      containers:
      - image: test
        name: test

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad
      namespace: test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
        securityContext:
          seLinuxOptions:
            level: "s0:c123,c455"
  • ACKPSPVolumeTypes

    ポリシーの説明: 指定された名前空間のポッドには、指定されたタイプのボリュームのみをマウントできます。

    重大度: 低

    次のセクションでは、パラメータについて説明します。

    パラメータ

    タイプ

    説明

    volumes

    オブジェクト

    マウントが許可されているボリュームのタイプを指定します。

    例:

    制約:

    apiVersion: constraints.gatekeeper.sh/v1beta1
    kind: ACKPSPVolumeTypes
    metadata:
      name: psp-volume-types
    spec:
      match:
        kinds:
          - apiGroups: [""]
            kinds: ["Pod"]
        namespaces:
          - "test-gatekeeper"
      parameters:
        volumes:
          # - "*" # * may be used to allow all volume types // * はすべてのボリュームタイプを許可するために使用できます
          - configMap
          # - emptyDir
          - projected
          - secret
          - downwardAPI
          - persistentVolumeClaim
          # - hostPath #required for allowedHostPaths // allowedHostPaths に必要
          - flexVolume #required for allowedFlexVolumes // allowedFlexVolumes に必要
    

    許可:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pv-oss
      namespace: test-gatekeeper
    spec:
      containers:
        - name: test
          image: test
      volumes:
        - name: test
          flexVolume:
            driver: "alicloud/oss"

    拒否:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: test
      name: bad-1
      namespace: non-test-gatekeeper
    spec:
      containers:
      - image: test
        name: test
      volumes:
      - name: test-volume
        hostPath:
          path: /data