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

Container Service for Kubernetes:コンテナセキュリティポリシールールライブラリの概要

最終更新日:Mar 24, 2026

ACK ポリシー管理では、Pod のデプロイメントおよび更新要求に対してセキュリティ制約を適用する組み込みのルールライブラリを提供します。各ルールは、constraints.gatekeeper.sh/v1beta1 リソースとしてデプロイされる Gatekeeper 制約テンプレートです。本ページでは、重大度、パラメーター、設定例を含め、利用可能なすべてのポリシーをカテゴリ別に一覧表示します。

適用モード

各制約では、enforcementAction フィールドを使用して違反時の処理方法を制御します。

モード動作使用タイミング
deny要求をブロックします。準拠していないリソースは作成・更新できません。既存のワークロードに影響を与えないことが確認済みの場合に、本番環境で使用します。
warn要求を許可しますが、警告メッセージを返します。ポリシーを deny に切り替える前に、準拠状況を監査する場合に使用します。

ポリシーの適用前に準拠状況を監査するには、まず enforcementAction: warn を指定して制約をデプロイし、違反が検出されないことを確認したうえで、deny に切り替えます。

ポリシーカテゴリ

カテゴリ説明
コンプライアンスAlibaba Cloud K8s 強化などのコンプライアンス基準に基づくセキュリティルールです。
インフラクラウドインフラストラクチャリソースのセキュリティを保護するルールです。
K8s-generalKubernetes クラスター内で機密性の高いリソース構成を制約・標準化するルールです。
PSPKubernetes Pod Security Policies (PSP) を置き換えるポリシーです。ACK ポリシー管理における元の PSP 機能と同等のセキュリティ制約を提供します。
FinOpsコストガバナンスのためのポリシールールです。

ポリシールールライブラリ

コンプライアンス

ポリシー説明重大度
ACKNoEnvVarSecretssecretKeyRef を使用して、アプリケーションポッドへのシークレットの環境変数マウントを制限します。中間
ACKPodsRequireSecurityContextPod 内のすべてのコンテナに securityContext フィールドの設定を必須とします。
ACKRestrictNamespacesクラスター内の指定された名前空間へのリソースデプロイメントを制限します。
ACKRestrictRoleBindings指定された名前空間内の RoleBinding が、指定された範囲の Role または ClusterRole のみを使用することを制限します。
ACKNamespacesDeleteProtection指定された名前空間の誤った削除を防止します。中間
ACKServicesDeleteProtection名前空間内の Service インスタンスの誤った削除を防止します。中間
ACKProtectBoundingPVバインド状態にある永続ボリューム (PV) の削除を防止します。
ACKBlockNodeDeleteカスタムタグを持つノードの削除を防止します。
ACKResourceDeletionProtectionカスタムタグを持つリソース(Service、Namespace、Ingress を含む)の削除を防止します。
ACKProtectCoreDNSkube-system 名前空間内の CoreDNS 関連リソースの削除を防止します。
ACKBlockCrdDeletion関連するカスタムリソース (CR) がまだ存在する CustomResourceDefinitions (CRD) の削除を防止します。中間

インフラ

ポリシー説明重大度
ACKBlockProcessNamespaceSharingクラスター内の指定された範囲でデプロイされるアプリケーションにおける shareProcessNamespace の使用を制限します。
ACKEmptyDirHasSizeLimitemptyDir 型ボリュームが sizeLimit を指定することを必須とします。
ACKLocalStorageRequireSafeToEvict指定された範囲でデプロイされる Pod に "cluster-autoscaler.kubernetes.io/safe-to-evict": "true" アノテーションの設定を必須とします。
ACKOSSStorageLocationConstraint指定された名前空間でのデプロイメントを、指定されたリージョンの Alibaba Cloud Object Storage Service (OSS) 永続ボリューム (PV) のみで使用することに制限します。
ACKPVSizeConstraintクラスター内で作成される PV インスタンスに対する最大ディスク容量の要求を制限します。中間
ACKPVCConstraint永続ボリューム要求 (PVC) インスタンスのデプロイメントを、ホワイトリストに登録された名前空間に限定し、要求可能な最大ディスク容量を制限します。中間
ACKBlockVolumeTypes使用可能なボリュームタイプを制限します。中間
ASMSidecarInjectionEnforcedPod に Alibaba Cloud Service Mesh (ASM) サイドカーの注入を必須とします。

K8s-general

ポリシー説明重大度
ACKAllowedRepos指定された範囲でデプロイされるアプリケーションポッドが、許可されたリポジトリからのみイメージをプルすることを必須とします。
ACKBlockAutoinjectServiceEnvサービス環境変数の自動インジェクションを制限します。
ACKBlockAutomountTokenサービスアカウントトークンの自動マウントを制限します。
ACKBlockEphemeralContainerエフェメラルコンテナの使用を制限します。中間
ACKBlockLoadBalancerLoadBalancer 型 Service の作成を制限します。
ACKBlockNodePortNodePort 型 Service の作成を制限します。
ACKContainerLimitsコンテナがリソース使用制限を指定することを必須とします。
ACKExternalIPsexternal IPs の使用を制限します。
ACKImageDigestsコンテナイメージがイメージダイジェスト形式で指定されることを必須とします。
ACKRequiredLabelsリソースが指定されたラベルを持つことを必須とします。
ACKRequiredProbesコンテナが readiness プローブおよび liveness プローブの設定を持つことを必須とします。中間
ACKCheckNginxPathnginx Ingress の path 構成を検証します。
ACKCheckNginxAnnotationnginx Ingress のアノテーション構成を検証します。
ACKBlockInternetLoadBalancerインターネット向けロードバランサーの作成を制限します。
RatifyVerificationRatify を使用したコンテナイメージの署名検証を必須とします。

PSP

ポリシー説明重大度
ACKPSPAllowedUsersコンテナが実行されるユーザーおよびグループ ID を制限します。中間
ACKPSPAllowPrivilegeEscalationContainerコンテナにおける権限昇格を制限します。中間
ACKPSPAppArmorコンテナが使用する AppArmor プロファイルを制限します。
ACKPSPCapabilitiesコンテナの Linux 権限を制限します。
ACKPSPFlexVolumesFlexVolume ドライバーの使用を制限します。中間
ACKPSPForbiddenSysctls指定された sysctls の使用を制限します。
ACKPSPFSGroup使用可能な補助グループを制限します。中間
ACKPSPHostFilesystemホストファイルシステムパスの使用を制限します。
ACKPSPHostNamespaceホスト名前空間の共有を制限します。
ACKPSPHostNetworkingPortsホストネットワークの使用およびポート範囲を制限します。
ACKPSPPrivilegedContainer特権付きコンテナの実行を制限します。
ACKPSPProcMount非デフォルトの proc mount タイプの使用を制限します。
ACKPSPReadOnlyRootFilesystemコンテナが読み取り専用のルートファイルシステムを使用することを必須とします。中間
ACKPSPSeccompseccomp プロファイルを制限します。
ACKPSPSELinuxV2SELinux ラベルを制限します。
ACKPSPVolumeTypes使用可能なボリュームタイプを制限します。中間

FinOps

ポリシー説明重大度
ACKContainerRequestsコンテナがリソース要求を指定することを必須とします。
ACKContainerResourcesWhitelistコンテナのリソース構成を事前定義されたホワイトリストに限定します。
ACKContainerResourcesRangeコンテナのリソース要求および使用制限を指定された範囲に制限します。
ACKRequiredNodeSelectorPod が指定された nodeSelector を使用することを必須とします。
ACKWorkloadReplicasRangeワークロードのレプリカ数範囲を制限します。
ACKRestrictALBCreationApplication Load Balancer (ALB) の作成を制限します。

コンプライアンス

ACKNoEnvVarSecrets

secretKeyRef を使用して、アプリケーションポッドへのシークレットの環境変数マウントを制限します。

重大度: 中間

パラメーター: なし

制約:

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: redis
    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:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

ACKPodsRequireSecurityContext

Pod 内のすべてのコンテナに securityContext フィールドの設定を必須とします。

重大度:

パラメーター: なし

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKPodsRequireSecurityContext
metadata:
  name: pods-require-security-context
  annotations:
    description: "Requires that Pods must have a `securityContext` defined."
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: test-gatekeeper
spec:
  containers:
  - image: test
    name: test

ACKRestrictNamespaces

クラスター内の指定された名前空間へのリソースデプロイメントを制限します。

重大度:

パラメーター:

パラメーター説明
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: redis
  restartPolicy: Never

ACKRestrictRoleBindings

指定された名前空間内の RoleBinding を、特定の Role または ClusterRole のセットに制限します。

重大度:

パラメーター:

パラメーター説明
restrictedRoleオブジェクト制限される ClusterRole または Role です。
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 コンポーネント v3.10.0.130-g0e79597d-aliyun 以降が必要です。バージョン情報については、「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

指定された名前空間内の Service インスタンスの誤った削除を防止します。protectionServices パラメーターを使用して、保護対象の Service インスタンスを設定します。

重大度: 中間

パラメーター:

パラメーター説明
protectionServices配列指定された名前空間内で保護対象となる Service インスタンスの名前です。

制約:

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

ACKProtectBoundingPV

クラスター内で永続ボリューム要求 (PVC) にバインドされている永続ボリューム (PV) の削除を防止します。

重大度:

パラメーター: なし

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKProtectBoundingPV
metadata:
  name: protect-pv-deletion
spec:
  enforcementAction: deny
  match:
    kinds:
    - apiGroups:
      - ""
      kinds:
      - PersistentVolume

許可済み:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-pv-bound-should-be-blocked
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 1Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual-sc
  hostPath:
    path: /tmp/data
    type: DirectoryOrCreate
status:
  phase: Released

不許可:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-pv-bound-should-be-blocked
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 1Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual-sc
  hostPath:
    path: /tmp/data
    type: DirectoryOrCreate
status:
  phase: Bound

ACKBlockNodeDelete

クラスター内でカスタムタグを持つノードの削除を防止します。ノードが指定されたキーと値のペアのいずれかに一致する場合、そのノードは保護されます。複数のペアを定義できます。

重大度:

パラメーター:

パラメーター説明
protectedLabels配列保護対象のノードを識別するカスタムタグです。
protectedLabels.labelName文字列タグキーです。
protectedLabels.labelValue文字列タグ値です。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKBlockNodeDelete
metadata:
  name: block-node-delete
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: ["*"]
        kinds: ["Node"]
  parameters:
    protectedLabels:
    - labelName: policy.alibabacloud.vpc.com/node-delete-protection
      labelValue: "true"
    - labelName: policy.alibabacloud.com/node-delete-protection
      labelValue: "true"

許可済み:

apiVersion: v1
kind: Node
metadata:
  name: cn-hangzhou-1

禁止されています:

apiVersion: v1
kind: Node
metadata:
  labels:
    policy.alibabacloud.vpc.com/node-delete-protection: "true"
  name: cn-hangzhou-1
---
apiVersion: v1
kind: Node
metadata:
  labels:
    policy.alibabacloud.vpc.com/node-delete-protection: "true"
  name: cn-hangzhou-2
---
apiVersion: v1
kind: Node
metadata:
  labels:
    policy.alibabacloud.com/node-delete-protection: "true"
    policy.alibabacloud.vpc.com/node-delete-protection: "true"
  name: cn-hangzhou-3

ACKResourceDeletionProtection

クラスター内でカスタムタグを持つリソースの削除を防止します。サポートされるリソースタイプ:Service、Namespace、Ingress、Deployment、StatefulSet、DaemonSet、Job、CronJob。リソースが指定されたキーと値のペアのいずれかに一致する場合、そのリソースは保護されます。複数のペアを定義できます。

重大度:

パラメーター:

パラメーター説明
labels配列保護対象のリソースを識別するカスタムタグです。
labels.labelName文字列タグキーです。
labels.labelValue文字列タグ値です。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKResourceDeletionProtection
metadata:
  name: resource-deletion-protection
  annotations:
    description: "Protect resources from being accidentally deleted."
spec:
  enforcementAction: deny
  match:
    kinds:
    - apiGroups:
      - ""
      kinds:
      - Service
      - Namespace
    - apiGroups:
      - extensions
      - networking.k8s.io
      kinds:
      - Ingress
    - apiGroups:
      - apps
      kinds:
      - Deployment
      - StatefulSet
      - DaemonSet
    - apiGroups:
      - batch
      kinds:
      - Job
      - CronJob
  parameters:
    labels:
    - labelName: policy.alibabacloud.com/delete-protection
      labelValue: "true"

許可:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deployment
  namespace: test-gatekeeper
spec:
  replicas: 2
  selector:
    matchLabels:
      app: test-app
  template:
    metadata:
      labels:
        app: test-app
    spec:
      containers:
        - name: nginx
          image: nginx:latest
          ports:
            - containerPort: 80

禁止されています:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deployment
  namespace: test-gatekeeper
  labels:
    policy.alibabacloud.com/delete-protection: "true"
spec:
  replicas: 2
  selector:
    matchLabels:
      app: test-app
  template:
    metadata:
      labels:
        app: test-app
    spec:
      containers:
        - name: nginx
          image: nginx:latest
          ports:
            - containerPort: 80

ACKProtectCoreDNS

kube-system 名前空間内の CoreDNS 関連リソース(関連する Deployment、Service、ConfigMap を含む)の削除を防止します。

重大度:

パラメーター:

パラメーター説明
min_replicasintCoreDNS Deployment に必要な最小レプリカ数です。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKProtectCoreDNS
metadata:
  name: coredns-protect-rule
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: ["*"]
        kinds: ["Deployment", "Service", "Scale", "ConfigMap"]
    scope: "Namespaced"
    namespaces: ["kube-system"]
  parameters:
    min_replicas: 2

許可済み:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: coredns
  namespace: kube-system
spec:
  replicas: 3
  selector:
    matchLabels:
      k8s-app: kube-dns
  template:
    metadata:
      labels:
        k8s-app: kube-dns
    spec:
      containers:
        - name: coredns
          image: registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/coredns:latest
          imagePullPolicy: IfNotPresent

不許可な例:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: coredns
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: kube-dns
  template:
    metadata:
      labels:
        k8s-app: kube-dns
    spec:
      containers:
        - name: coredns
          image: registry-cn-hangzhou-vpc.ack.aliyuncs.com/acs/coredns:latest
          imagePullPolicy: IfNotPresent
---
apiVersion: v1
data:
  Corefile: ""
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: kube-dns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: KubeDNS
  name: kube-dns
  namespace: kube-system

ACKBlockCrdDeletion

関連するカスタムリソース (CR) がまだ存在する CustomResourceDefinitions (CRD) の削除を防止します。

重大度: 中間

パラメーター: なし

前提条件: このポリシーをデプロイする前に、「ack-policy-external-provider のインストールと構成」を行ってください。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKBlockCrdDeletion
metadata:
  name: block-crd-deletion
spec:
  enforcementAction: deny
  match:
    kinds:
    - apiGroups:
      - '*'
      kinds:
      - CustomResourceDefinition

インフラ

ACKBlockProcessNamespaceSharing

クラスター内の指定された範囲でデプロイされるアプリケーションにおける shareProcessNamespace の使用を制限します。

重大度:

パラメーター: なし

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKBlockProcessNamespaceSharing
metadata:
  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: k8s.gcr.io/test-webserver
    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: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

ACKLocalStorageRequireSafeToEvict

指定された範囲でデプロイされる Pod に "cluster-autoscaler.kubernetes.io/safe-to-evict": "true" アノテーションの設定を必須とします。オートスケーリング時、クラスターのオートスケーラーはこのアノテーションを持たない Pod をエビクトしません。

重大度:

パラメーター: なし

制約:

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: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      path: /data
      type: Directory

不許可な例:

apiVersion: v1
kind: Pod
metadata:
  name: bad
  namespace: test-gatekeeper
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

ACKOSSStorageLocationConstraint

指定された名前空間でのデプロイメントを、指定されたリージョンの Alibaba Cloud Object Storage Service (OSS) 永続ボリューム (PV) のみで使用することに制限します。

重大度:

パラメーター:

パラメーター説明
mode文字列ホワイトリスト機能の有効化設定です。デフォルト値 allowlist ではホワイトリストモードが有効になります。それ以外の値ではブラックリストモードが有効になります。
regions配列許可される Alibaba Cloud リージョン ID です。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKOSSStorageLocationConstraint
metadata:
  name: restrict-oss-location
  annotations:
    description: "Restricts location of oss storage in cluster."
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: nginx:latest
  volumes:
    - name: test
      csi:
        driver: ossplugin.csi.alibabacloud.com
        nodePublishSecretRef:
          name: oss-secret
        volumeAttributes:
          bucket: "oss"
          url: "oss-cn-hangzhou.aliyuncs.com"
          otherOpts: "-o max_stat_cache_size=0 -o allow_other"
          path: "/"

ACKPVSizeConstraint

クラスター内で作成される PV インスタンスに対する最大ディスク容量の要求を制限します。

重大度: 中間

パラメーター:

パラメーター説明
maxSize文字列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."
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) インスタンスのデプロイメントを、ホワイトリストに登録された名前空間に限定し、要求可能な最大ディスク容量を制限します。

重大度: 中間

パラメーター:

パラメーター説明
maxSize文字列PVC インスタンスの最大ディスク容量です。デフォルト値: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."
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

ACKBlockVolumeTypes

クラスター内の指定された範囲でデプロイされる Pod に対して、指定されたボリュームマウントタイプの使用を禁止します。

重大度: 中間

パラメーター:

パラメーター説明
volumes配列禁止するボリュームマウントタイプです。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKBlockVolumeTypes
metadata:
  name: block-volume-types
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
    namespaces: ["test-gatekeeper"]
  parameters:
    volumes:
      - "gitRepo"

許可:

apiVersion: v1
kind: Pod
metadata:
  name: use-empty-dir
  namespace: test-gatekeeper
spec:
  containers:
    - name: test
      image: test
  volumes:
  - name: emptydir-volume
    emptyDir: {}

不許可な例:

apiVersion: v1
kind: Pod
metadata:
  name: use-git-repo
  namespace: test-gatekeeper
spec:
  containers:
    - name: test
      image: test
  volumes:
  - name: git-volume
    gitRepo:
      repository: "git@***:***/my-git-repository.git"
      revision: "22f1d8406d464b0c08***"

ASMSidecarInjectionEnforced

Pod に Alibaba Cloud Service Mesh (ASM) サイドカーの注入を必須とします。

重大度:

パラメーター: なし

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ASMSidecarInjectionEnforced
metadata:
  name: asm-sidecar-injectionen-forced
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
    namespaces: ["test-gatekeeper"]

許可:

apiVersion: v1
kind: Pod
metadata:
  name: sidecar-injection
  namespace: test-gatekeeper
spec:
  containers:
    - name: test
      image: test
    - name: istio-proxy
      image: xxx/proxyv2:xxx

不許可な例:

apiVersion: v1
kind: Pod
metadata:
  name: sidecar-injection
  namespace: test-gatekeeper
spec:
  containers:
    - name: test
      image: test

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: k8s.gcr.io/test-webserver
    name: test-container
  initContainers:
  - image: k8s.gcr.io/test-webserver
    name: test-container-3

ACKBlockAutoinjectServiceEnv

サービス IP アドレスが Pod の環境変数として公開されるのを防ぐために、アプリケーションが enableServiceLinks: false を設定することを必須とします。

重大度:

パラメーター: なし

制約:

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: k8s.gcr.io/test-webserver
    name: test-container

ACKBlockAutomountToken

サービスアカウントトークンの自動マウントを防ぐために、アプリケーションが automountServiceAccountToken: false を設定することを必須とします。

重大度:

パラメーター: なし

制約:

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: k8s.gcr.io/test-webserver
    name: test-container
  initContainers:
  - image: k8s.gcr.io/test-webserver
    name: test-container2

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: hello-pod
  namespace: test-gatekeeper
spec:
  containers:
  - name: hello-pod
    image: redis

不許可な例:

既存の Pod にエフェメラルコンテナを起動します。

kubectl debug -it hello-pod -n test-gatekeeper --image=test --target=hello-pod

予期される出力:

Error from server (Forbidden): admission webhook "validation.gatekeeper.sh" denied the request: [block-ephemeral-container-w5c6n] Creating ephemeral containers is disallowed, pod: hello-pod

ACKBlockLoadBalancer

クラスター内の指定された範囲において、LoadBalancer 型 Service のデプロイメントを防止します。

重大度:

パラメーター:

パラメーター説明
restrictedNamespaces配列LoadBalancer 型 Service の作成が拒否される名前空間です。

制約:

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 型 Service を防止します。

重大度:

パラメーター: なし

制約:

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

指定された範囲内の Service インスタンスが、ホワイトリストに登録された externalIPs のみを使用することを必須とします。

重大度:

パラメーター:

パラメーター説明
allowedIPs配列許可される externalIPs です。

制約:

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

指定された範囲でデプロイされるイメージが digest 形式を使用することを必須とします。

重大度:

パラメーター: なし

制約:

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: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
      name: test-container
      resources:
        requests:
          cpu: 10m
          memory: 512Mi
        limits:
          cpu: "1"
          memory: 1Gi

不許可な例:

apiVersion: v1
kind: Pod
metadata:
  name: bad-1
  namespace: test-gatekeeper
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
  initContainers:
  - image: k8s.gcr.io/test-webserver
    name: test-container2

ACKRequiredLabels

Pod が特定のラベルを含み、ラベル値が定義されたフォーマットに一致することを検証します。各ラベル値の検証には正規表現を使用します。optional パラメーターにより、ラベルの必須性を制御できます。

重大度:

パラメーター:

パラメーター説明
allowedRegex文字列ラベル値を検証するための正規表現です。
key文字列検証対象のラベルキーです。
optionalboolラベルが任意であるかどうかを指定します。true の場合、ラベルが存在するときのみ検証されます。false の場合、ラベルは存在し、検証を通過する必要があります。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKRequiredLabels
metadata:
  name: must-have-label-test
spec:
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
    namespaces:
      - "test-gatekeeper"
  parameters:
    labels:
      - key: test
        allowedRegex: "^test.*$"
      - key: env
        allowedRegex: "^(dev|prod)$"
        optional: true

許可される:

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

禁止:

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  name: bad2
  namespace: test-gatekeeper
  labels:
    'test': '233'
    'env': 'invalid'
spec:
  containers:
  - name: mycontainer
    image: redis

ACKRequiredProbes

指定された範囲でデプロイされる Pod が readinessProbe および livenessProbe の設定を持つことを必須とします。

重大度: 中間

パラメーター:

パラメーター説明
probes配列必須となるプローブタイプです。例:readinessProbelivenessProbe
probeTypes配列必須となるプローブ機構タイプです。例:tcpSockethttpGetexec

制約:

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 フィールドにおける危険な構成を防止します。Ingress-nginx のバージョンが 1.2.1 より前の場合に、このポリシーを有効化してください。

重大度:

パラメーター: なし

制約:

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 フィールドにおける危険な構成を防止します。Ingress-nginx のバージョンが 1.2.1 より前の場合に、このポリシーを有効化してください。

重大度:

パラメーター: なし

制約:

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 Service の作成を防止します。

重大度:

パラメーター: なし

制約:

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

RatifyVerification

マーケットプレイスから Ratify コンポーネントをインストールした後、このポリシーを使用して、指定された範囲でデプロイされる Pod イメージのセキュリティメタデータ(署名や部品表 (BOM) など)を検証します。

重大度:

パラメーター: なし

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: RatifyVerification
metadata:
  name: ratify-constraint
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
    namespaces: ["default"]

許可:

apiVersion: v1
kind: Pod
metadata:
  name: pod-1
  namespace: test-gatekeeper
spec:
  containers:
  - image: registry.cn-hangzhou.aliyuncs.com/acs/signed   # 有効な署名を持つイメージをデプロイします。
    name: test-container

不許可な例:

apiVersion: v1
kind: Pod
metadata:
  name: bad-1
  namespace: test-gatekeeper
spec:
  containers:
  - image: registry.cn-hangzhou.aliyuncs.com/acs/unsigned   # Ratify 署名検証に失敗する無効なイメージをデプロイします。
    name: test-container

PSP

ACKPSPAllowedUsers

指定された範囲でデプロイされる Pod が実行される usergroupsupplementalGroups、および fsGroup を制限します。

重大度: 中間

パラメーター:

パラメーター説明
runAsUserオブジェクトユーザー構成です。ルールタイプおよび UID 範囲(最小/最大)をサポートします。「Users and groups」をご参照ください。
runAsGroupオブジェクトグループ構成です。ルールタイプおよび GID 範囲(最小/最大)をサポートします。「Users and groups」をご参照ください。
supplementalGroupsオブジェクトSupplementalGroups 構成です。ルールタイプおよび GID 範囲(最小/最大)をサポートします。「Users and groups」をご参照ください。
fsGroupオブジェクトfsGroup 構成です。ルールタイプおよび GID 範囲(最小/最大)をサポートします。「Users and groups」をご参照ください。

制約:

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

指定された範囲でデプロイされる Pod の 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

指定された範囲でデプロイされる Pod の AppArmor 構成を制限します。

重大度:

パラメーター:

パラメーター説明
allowedProfiles配列許可される AppArmor プロファイルです。

制約:

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

指定された範囲でデプロイされる Pod の Linux 権限構成を制限します。

重大度:

パラメーター:

パラメーター説明
allowedCapabilities配列許可される Linux 権限です。
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

指定された範囲でデプロイされる Pod の 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: 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

指定された範囲でデプロイされる Pod が使用できる sysctls を制限します。

重大度:

パラメーター:

パラメーター説明
forbiddenSysctls配列Pod で禁止される sysctls です。* を使用してすべての sysctls を禁止します。

制約:

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
      - "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

指定された範囲でデプロイされる Pod の fsGroup 構成を制限します。

重大度: 中間

パラメーター:

パラメーター説明
rule文字列fsGroup ルールタイプです。サポートされる値:MustRunAsMayRunAsRunAsAny。「Volumes and file systems」をご参照ください。
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

指定された範囲でデプロイされる Pod がマウントできるホストディレクトリパスを制限します。

重大度:

パラメーター:

パラメーター説明
allowedHostPathsオブジェクトホストパスのホワイトリスト構成です。
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
    securityContext:
      readOnlyRootFilesystem: true

禁止されています:

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

指定された範囲でデプロイされる Pod がホスト名前空間を共有できるかどうかを制限します。

重大度:

パラメーター: なし

制約:

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

指定された範囲でデプロイされる Pod のホストネットワーク使用およびポート範囲を制限します。

重大度:

パラメーター:

パラメーター説明
hostNetworkブール値Pod がホストネットワークを共有することを許可するかどうかを示します。
minint許可される最小 hostPort です。
maxint許可される最大 hostPort です。

制約:

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: k8s.gcr.io/test-webserver
    name: test-container
    ports:
      - hostPort: 80
        containerPort: 80
  initContainers:
    - image: k8s.gcr.io/test-webserver
      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: k8s.gcr.io/test-webserver
    name: test-container
    ports:
      - hostPort: 22
        containerPort: 22

ACKPSPPrivilegedContainer

指定された範囲でデプロイされる Pod における特権付きコンテナの起動を防止します。

重大度:

パラメーター: なし

制約:

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

指定された範囲でデプロイされる Pod に許可される proc mount タイプを制限します。サポートされる値:Default/proc をマスク)および Unmasked/proc をマスクしない)。詳細については、「AllowedProcMountTypes」をご参照ください。

重大度:

パラメーター:

パラメーター説明
procMount文字列許可される proc mount タイプ:Default または Unmasked

制約:

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

許可:

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:
  hostUsers: false
  containers:
  - image: test
    name: test
    securityContext:
      procMount: "Unmasked"
  initContainers:
  - image: test
    name: test2

ACKPSPReadOnlyRootFilesystem

指定された範囲でデプロイされる Pod が読み取り専用のルートファイルシステムを使用することを必須とします。

重大度: 中間

パラメーター: なし

制約:

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

指定された範囲でデプロイされる Pod が、指定された 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
  name: bad
  namespace: test-gatekeeper
spec:
  containers:
  - image: test
    name: test

ACKPSPSELinuxV2

指定された範囲でデプロイされる Pod が、allowedSELinuxOptions で指定された SELinux 構成を使用することを必須とします。パラメーターの詳細については、「SELinuxOptions v1 core」をご参照ください。

重大度:

パラメーター:

パラメーター説明
allowedSELinuxOptionsオブジェクト許可される SELinux 構成です。

制約:

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

指定された範囲でデプロイされる Pod が、指定されたボリュームマウントタイプのみを使用することを制限します。

重大度: 中間

パラメーター:

パラメーター説明
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
      - flexVolume #required for 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: test-gatekeeper
spec:
  containers:
  - image: test
    name: test
  volumes:
  - name: test-volume
    hostPath:
      path: /data

FinOps

ACKContainerRequests

クラスター内の指定されたアプリケーションポッドがリソース requests を宣言することを必須とします。

重大度:

パラメーター:

パラメーター説明
cpu文字列コンテナの最大 CPU requests 値です。
memory文字列コンテナの最大メモリ requests 値です。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKContainerRequests
metadata:
  name: container-must-have-requests
spec:
  enforcementAction: deny
  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:
      requests:
        memory: "100Mi"
        cpu: "500m"

不許可な例:

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

ACKContainerResourcesWhitelist

指定されたアプリケーションポッドの CPU およびメモリリソース構成が、事前定義されたオプションのリストから選択されることを必須とします。

重大度:

パラメーター:

パラメーター説明
cpuRequests配列許可される CPU requests 値です。空の配列 [] はすべての値を許可します。
cpuLimits配列許可される CPU limits 値です。空の配列 [] はすべての値を許可します。
memoryRequests配列許可されるメモリ requests 値です。空の配列 [] はすべての値を許可します。
memoryLimits配列許可されるメモリ limits 値です。空の配列 [] はすべての値を許可します。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKContainerResourcesWhitelist
metadata:
  name: container-resources-whitelist
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
    namespaces:
      - "test-gatekeeper"
  parameters:
    cpuRequests:
      - "100m"
      - "500m"
      - "1"
    cpuLimits:
      - "2"
      - "4000m"
    memoryRequests:
      - "256Mi"
      - "512Mi"
    memoryLimits:
      - "1Gi"
      - "2048Mi"

許可:

apiVersion: v1
kind: Pod
metadata:
  name: pod-0
  namespace: test-gatekeeper
spec:
  containers:
    - image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
      name: test-container
      resources:
        requests:
          cpu: 100m
          memory: 512Mi
        limits:
          cpu: "2"
          memory: 1Gi

不許可な例:

apiVersion: v1
kind: Pod
metadata:
  name: pod-0
  namespace: test-gatekeeper
spec:
  containers:
    - image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
      name: test-container
      resources:
        requests:
          cpu: 10m
          memory: 512Mi
        limits:
          cpu: "1"
          memory: 1Gi

ACKContainerResourcesRange

指定されたアプリケーションポッドのリソース構成を、指定された範囲に制限します。

重大度:

パラメーター:

パラメーター説明
cpuRequestsオブジェクトrequestsmin および max 値です。
cpuLimitsオブジェクトlimitsmin および max 値です。
memoryRequestsオブジェクトrequestsmin および max 値です。
memoryLimitsオブジェクトlimitsmin および max 値です。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKContainerResourcesRange
metadata:
  name: container-resources-range
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
    namespaces:
      - "test-gatekeeper"
  parameters:
    cpuRequests:
      min: "100m"
      max: "1"
    cpuLimits:
      min: "500m"
      max: "2"
    memoryRequests:
      min: "256Mi"
      max: "512Mi"
    memoryLimits:
      min: "1Gi"
      max: "2048Mi"

許可:

apiVersion: v1
kind: Pod
metadata:
  name: pod-0
  namespace: test-gatekeeper
spec:
  containers:
    - image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
      name: test-container
      resources:
        requests:
          cpu: 100m
          memory: 512Mi
        limits:
          cpu: "2"
          memory: 2Gi

不許可な例:

apiVersion: v1
kind: Pod
metadata:
  name: pod-0
  namespace: test-gatekeeper
spec:
  containers:
    - image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
      name: test-container
      resources:
        requests:
          cpu: 10m
          memory: 5Mi
        limits:
          cpu: "3"
          memory: 128Mi

ACKRequiredNodeSelector

クラスター内の指定されたアプリケーションポッドが nodeSelector の設定を持つことを必須とします。

重大度:

パラメーター:

パラメーター説明
nodeSelector配列key(ラベルキー)および allowedRegex(ラベル値の正規表現)を含みます。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKRequiredNodeSelector
metadata:
  name: must-have-nodeselector
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
    namespaces:
      - "test-gatekeeper"
  parameters:
    nodeSelector:
      - key: "node.alibabacloud.com/nodepool-id"
        allowedRegex: "^np.*$"
      - key: "kubernetes.io/os"
        allowedRegex: "^linux$"

許可:

apiVersion: v1
kind: Pod
metadata:
  name: pod-0
  namespace: test-gatekeeper
spec:
  containers:
    - image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
      name: test-container
      resources:
        requests:
          cpu: 100m
          memory: 512Mi
        limits:
          cpu: "2"
          memory: 1Gi
  nodeSelector:
    node.alibabacloud.com/nodepool-id: npd37f0e64410c41328a6282dbe5d35cae
    kubernetes.io/os: linux

不許可な例:

apiVersion: v1
kind: Pod
metadata:
  name: pod-0
  namespace: test-gatekeeper
spec:
  containers:
    - image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
      name: test-container
      resources:
        requests:
          cpu: 100m
          memory: 512Mi
        limits:
          cpu: "2"
          memory: 1Gi
  nodeSelector:
    node.alibabacloud.com/nodepool-id: npd37f0e64410c41328a6282dbe5d35cae
    kubernetes.io/os: windows

ACKWorkloadReplicasRange

ワークロードのレプリカ数範囲を制限します。

重大度:

パラメーター:

パラメーター説明
minReplicasint最小レプリカ数です。
maxReplicasint最大レプリカ数です。

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKWorkloadReplicasRange
metadata:
  name: replica-limiter
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: ["*"]
        kinds: ["Deployment", "StatefulSet", "ReplicaSet", "Scale"]
    namespaces:
      - "test-gatekeeper"
  parameters:
    minReplicas: 2
    maxReplicas: 3

許可済み:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-basic
  namespace: test-gatekeeper
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
          ports:
            - containerPort: 80
          resources:
            limits:
              cpu: "500m"

不許可な例:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-basic-0
  namespace: test-gatekeeper
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
          ports:
            - containerPort: 80
          resources:
            limits:
              cpu: "500m"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-basic-1
  namespace: test-gatekeeper
  labels:
    app: nginx
spec:
  replicas: 4
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
          ports:
            - containerPort: 80
          resources:
            limits:
              cpu: "500m"

ACKRestrictALBCreation

既存の Application Load Balancer (ALB) インスタンスの再利用を強制し、AlbConfig を介した新しい ALB インスタンスの作成を禁止します。

重大度:

パラメーター: なし

制約:

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKRestrictALBCreation
metadata:
  name: restrict-alb-creation
spec:
  enforcementAction: deny
  match:
    kinds:
      - apiGroups: ["alibabacloud.com"]
        kinds: ["AlbConfig"]

許可済み:

apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
  name: reuse-alb
spec:
  config:
    id: 'abcdefghijklmnopqrstuvwxyz'
    forceOverride: false
    listenerForceOverride: false

不許可な例:

apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
  name: alb
spec:
  config:
    name: alb
    addressType: Internet
    zoneMappings:
    - vSwitchId: vsw-uf6ccg2a9g71hx8go****  # クラスターが存在する VPC 内の異なるゾーンにある少なくとも 2 つの vSwitch の vSwitch ID に置き換えてください。
      allocationId: eip-asdfas****          # EIP ID に置き換えてください。デフォルトオプションは、パブリック IP アドレスを自動的に割り当てることです。
    - vSwitchId: vsw-uf6nun9tql5t8nh15****  # クラスターが存在する VPC 内の異なるゾーンにある少なくとも 2 つの vSwitch の vSwitch ID に置き換えてください。
      allocationId: eip-dpfmss****          # EIP ID に置き換えてください。
  listeners:
    - port: 80
      protocol: HTTP