Pod のセキュリティポリシーを設定して、デプロイメントと更新リクエストのセキュリティを検証できます。Container Service for Kubernetes (ACK) クラスターのポリシー管理機能は、Compliance、Infra、K8s-general、PSP、FinOps などの複数の組み込みルールライブラリを提供します。
ルールの紹介
ACK コンテナーセキュリティポリシールールライブラリには、次のルールテンプレートが含まれています:
Compliance:Alibaba Cloud K8s Reinforcement などのコンプライアンス基準に基づいてカスタマイズされたセキュリティルール。
Infra:クラウドインフラストラクチャリソースのセキュリティを強化および保護するルール。
K8s-general:Kubernetes クラスター内の機密リソースの構成を制約および標準化して、アプリケーションセキュリティを強化するルール。
PSP:Kubernetes Pod セキュリティポリシー (PSP) を置き換えるポリシー。これらのポリシーは、ACK ポリシー管理の元の PSP 機能によって提供されるものと同等のセキュリティ制約を提供します。
FinOps:コストガバナンスプロセスのためのコントロールおよび最適化ポリシールール。
ポリシールールライブラリ
Container Service for Kubernetes (ACK) は、次の組み込みポリシールールライブラリを提供します。ポリシーのカテゴリとその説明は次のとおりです:
カテゴリ | ポリシー | 説明 | 重要度 |
Compliance |
| `secretKeyRef` を使用して、アプリケーション Pod に Secret を環境変数としてマウントすることを制限します。 | 中間 |
| Pod 内のすべてのコンテナーに | 低 | |
| クラスター内の指定された名前空間へのリソースのデプロイメントを制限します。 | 低 | |
| 指定された名前空間のロールバインディングを、指定された範囲のロールまたはクラスターロールのみを使用するように制限します。 | 高 | |
| 指定された名前空間が誤って削除されるのを防ぎます。 | 中間 | |
| 名前空間内のサービスインスタンスが誤って削除されるのを防ぎます。 | 中間 | |
| バインド状態にある永続ボリューム (PV) の削除を防ぎます。 | 高 | |
| カスタムタグを持つノードの削除を防ぎます。 | 高 | |
| カスタムタグを持つさまざまなリソース (Service、Namespace、Ingress を含む) の削除を防ぎます。 | 高 | |
| kube-system 名前空間内の CoreDNS 関連リソースの削除を防ぎます。 | 高 | |
ACKBlockCrdDeletion | 関連するカスタムリソース (CR) がまだ存在する CustomResourceDefinition (CRD) の削除を防ぎます。 | 中 | |
Infra |
| クラスター内の指定された範囲にデプロイされたアプリケーションでの shareProcessNamespace の使用を制限します。 | 高 |
| `emptyDir` タイプのボリュームに | 低 | |
| クラスター内の指定された範囲にデプロイされた Pod に | 低 | |
| 指定された名前空間でのデプロイメントを、指定されたリージョンの Alibaba Cloud OSS 永続ボリューム (PV) のみを使用するように制限します。 | 低 | |
| クラスターで作成された PV インスタンスに要求できる最大ディスク容量を制限します。 | 中間 | |
| 永続ボリューム要求 (PVC) インスタンスのデプロイメントを名前空間のホワイトリストに制限し、PVC インスタンスにリクエストできる最大ディスク容量を制限します。 | 中間 | |
| クラスターの特定の範囲にデプロイされた Pod で禁止されているボリュームマウントタイプを指定します。 | 中間 | |
| Pod に ASM サイドカーがインジェクションされている必要があります。 | 高 | |
K8s-general |
| クラスター内の指定された範囲にデプロイされたアプリケーション Pod が、ホワイトリストにないイメージをプルすることを制限します。 | 高 |
| Pod の環境変数にサービス IP が公開されるのを防ぐために、アプリケーションに | 低 | |
|
| 高 | |
| クラスター内の指定された範囲のアプリケーション Pod でのエフェメラルコンテナーの起動を制限します。 | 中間 | |
| クラスター内の指定された範囲での LoadBalancer タイプのサービスのデプロイメントを制限します。 | 高 | |
| クラスター内の指定された範囲での NodePort タイプのサービスの使用を制限します。 | 高 | |
| クラスター内の指定された範囲のアプリケーション Pod にリソース | 低 | |
| クラスター内の指定された範囲の Service インスタンスが、ホワイトリストにない externalIPs を使用することを制限します。 | 高 | |
| クラスター内の指定された範囲で、ダイジェスト形式を使用しないイメージのデプロイメントを制限します。 | 低 | |
| クラスター内の指定された範囲で、指定された標準ラベルを持たないアプリケーションのデプロイメントを制限します。 | 低 | |
| クラスター内の指定された範囲にデプロイされた Pod に、指定されたタイプの readinessProbe と livenessProbe を設定する必要があります。 | 中間 | |
| Ingress インスタンスの | 高 | |
| Ingress インスタンスの | 高 | |
| パブリックに公開される LoadBalancer サービスの作成を制限します。 | 高 | |
| マーケットプレイスから Ratify コンポーネントをインストールした後、クラスター内の指定された範囲にデプロイされた Pod イメージの署名や部品表 (BOM) などのセキュリティメタデータを検証します。 | 高 | |
PSP |
| クラスター内の指定された範囲にデプロイされた Pod の | 中間 |
| クラスター内の指定された範囲にデプロイされた Pod の起動時の | 中間 | |
| クラスター内の指定された範囲にデプロイされた Pod の AppArmor 構成を制限します。 | 低 | |
| クラスター内の指定された範囲にデプロイされた Pod の Linux Capabilities 構成を制限します。 | 高 | |
| クラスター内の指定された範囲にデプロイされた Pod の fsGroup 構成を制限します。 | 中間 | |
| クラスター内の指定された範囲にデプロイされた Pod の FlexVolume ドライバー構成を制限します。 | 中間 | |
| クラスター内の指定された範囲にデプロイされた Pod の禁止されている sysctl の範囲を制限します。 | 高 | |
| クラスター内の指定された範囲にデプロイされた Pod がマウントできるホストディレクトリの範囲を制限します。 | 高 | |
| クラスター内の指定された範囲にデプロイされた Pod がホスト名前空間を共有できるかどうかを制限します。 | 高 | |
| クラスター内の指定された範囲にデプロイされた Pod によるホストネットワークと指定されたポートの使用を制限します。 | 高 | |
| クラスター内の指定された範囲にデプロイされた Pod での特権コンテナーの起動を制限します。 | 高 | |
| クラスター内の指定された範囲にデプロイされた Pod で許可される proc マウントタイプを制限します。 | 低 | |
| クラスター内の指定された範囲にデプロイされた Pod に、読み取り専用ルートファイルシステムを使用することを要求します。 | 中間 | |
| クラスター内の指定された範囲にデプロイされた Pod に、`allowedSELinuxOptions` パラメーターで指定された SELinux 構成を使用することを要求します。 | 低 | |
| クラスター内の指定された範囲にデプロイされた Pod に、指定された Seccomp プロファイルを使用することを制限します。 | 低 | |
| クラスター内の指定された範囲にデプロイされた Pod に、指定されたボリュームマウントタイプを使用することを制限します。 | 中間 | |
FinOps |
| クラスター内の一部のアプリケーション Pod がリソース | 低 |
| クラスター内の一部のアプリケーション Pod の CPU およびメモリリソース構成は、事前定義されたオプションのリストから選択する必要があります。 | 低 | |
| クラスター内の一部のアプリケーション Pod のリソース構成を、指定された範囲内に制限します。 | 低 | |
| クラスター内の一部のアプリケーション Pod に、指定された | 低 | |
| アプリケーションレプリカの数を指定された最小値と最大値に制限します。 | 低 | |
| 既存の ALB インスタンスの再利用を強制し、AlbConfig を介した新しい ALB リソースインスタンスの作成を禁止します。 | 低 |
Compliance
ACKNoEnvVarSecrets
ルールの説明:`secretKeyRef` を使用して、アプリケーション Pod に Secret を環境変数としてマウントすることを制限します。
重要度:中。
パラメーター:なし。
例:
制約:
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:
- name: mycontainer
image: redis
env:
- name: SECRET_USERNAME
valueFrom:
secretKeyRef:
name: mysecret
key: username
- name: SECRET_PASSWORD
valueFrom:
secretKeyRef:
name: mysecret
key: password
restartPolicy: NeverACKPodsRequireSecurityContext
ルールの説明: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: test2
- image: test
name: test
resources: {}
securityContext:
runAsNonRoot: falseACKRestrictNamespaces
ルールの説明:クラスター内の指定された名前空間へのリソースのデプロイメントを制限します。
重要度:低。
パラメーター:
パラメーター名 | タイプ | 説明 |
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: NeverACKRestrictRoleBindings
説明:指定された名前空間の 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.ioACKNamespacesDeleteProtection
ルールの説明:指定された名前空間の偶発的な削除を防ぎます。protectionNamespaces パラメーターを使用して、保護する名前空間の名前を設定できます。
前提条件:Gatekeeper コンポーネントは v3.10.0.130-g0e79597d-aliyun 以降である必要があります。Gatekeeper コンポーネントのバージョンの詳細については、「Gatekeeper」をご参照ください。
重要度:中。
パラメーター:
パラメーター | パラメータータイプ | 説明 |
| 配列 | 保護された名前空間名のリスト。 |
例:
制約:
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-gatekeeperACKServicesDeleteProtection
ルールの説明:指定された名前空間内の 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-svcACKProtectBoundingPV
ルールの説明:クラスター内の永続ボリューム要求 (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: BoundACKBlockNodeDelete
ルールの説明:クラスター内でカスタムタグを持つノードの削除を防ぎます。複数のキーと値のペアを定義できます。指定されたキーと値のペアのいずれかに一致する場合、ノードは保護されます。
重要度:高。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 配列 | 保護されたノードを識別するために使用されるカスタムタグ。 |
| 文字列 | カスタムタグのキー。 |
| 文字列 | カスタムタグの値。 |
例:
制約:
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-3ACKResourceDeletionProtection
ルールの説明:クラスター内でカスタムタグを持つリソースの削除を防ぎます。このルールは、Service、Namespace、Ingress、Deployment、StatefulSet、DaemonSet、Job、CronJob などのリソースタイプをサポートします。複数のキーと値のペアを定義できます。指定されたキーと値のペアのいずれかに一致する場合、リソースは保護されます。
重要度:高。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 配列 | 保護されたノードを識別するために使用されるカスタムタグ。 |
| 文字列 | カスタムタグのキー。 |
| 文字列 | カスタムタグの値。 |
例:
制約:
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: 80ACKProtectCoreDNS
ルールの説明:kube-system 名前空間内の CoreDNS 関連リソース (関連する Deployment、Service、ConfigMap を含む) の削除を防ぎます。
重要度:高。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| int | CoreDNS 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-systemACKBlockCrdDeletion
ルールの説明:関連するカスタムリソース (CR) がまだ存在する CustomResourceDefinition (CRD) の削除を防ぎます。
重要度:中。
パラメーター:なし。
例と使用法:ポリシーをデプロイする前に、まず ack-policy-external-provider のインストールと設定を行う必要があります。その後、ポリシーをデプロイして CRD を保護できます。
制約:
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: ACKBlockCrdDeletion
metadata:
name: block-crd-deletion
spec:
enforcementAction: deny
match:
kinds:
- apiGroups:
- '*'
kinds:
- CustomResourceDefinitionInfra
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:
# 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: 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) のみを使用するように制限します。
重要度:低。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 文字列 | ホワイトリストを使用するかどうかを指定します。デフォルト値の |
| 配列 | 指定された 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 インスタンスに要求できる最大ディスク容量を制限します。
重要度:中。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 文字列 | 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) インスタンスのデプロイメントを名前空間のホワイトリストに制限し、PVC インスタンスにリクエストできる最大ディスク容量を制限します。
重要度:中
パラメーター:
パラメーター | パラメータータイプ | 説明 |
| 文字列 | PV インスタンスにリクエストできる最大ディスク容量。デフォルト値は 50 GiB です。 |
| 配列 | 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 で禁止されているボリュームマウントタイプを指定します。
重要度:中
パラメーター:
パラメーター名 | タイプ | 説明 |
| 配列 | 禁止されているボリュームマウントタイプのリスト。 |
例:
制約:
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: testK8s-general
ACKAllowedRepos
ルールの説明:クラスター内の指定された範囲にデプロイされたアプリケーション Pod が、ホワイトリストに登録されたリポジトリからのみイメージをプルすることを要求します。
重要度:高。
パラメーター:
パラメーター名 | タイプ | 説明 |
| 配列 | 許可されたイメージリポジトリのホワイトリスト。 |
例:
制約:
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-3ACKBlockAutoinjectServiceEnv
ルールの説明:サービス 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-containerACKBlockAutomountToken
ルールの説明:ServiceAccount トークンの自動マウントを防ぐために、アプリケーションに 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-containerACKBlockEphemeralContainer
ルールの説明:クラスター内の指定された範囲のアプリケーション Pod でのエフェメラルコンテナーの起動を防ぎます。
重要度:中。
パラメーター:なし。
例:
制約:
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 タイプのサービスのデプロイメントを防ぎます。
重要度:高。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
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: 9376ACKBlockNodePort
ルールの説明:クラスター内の指定された範囲での 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: 9376ACKContainerLimits
ルールの説明:クラスター内の指定された範囲のアプリケーション Pod にリソース 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 のみを使用することを要求します。
重要度:高。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 配列 |
|
例:
制約:
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.XXACKImageDigests
ルールの説明:クラスター内の指定された範囲にデプロイされるイメージに 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: openpolicyagent/test-webserver@sha256:12e469267d21d66ac9dcae33a4d3d202ccb2591869270b95d0aad7516c7d075b
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-container2ACKRequiredLabels
ルールの説明:Pod に特定のラベルが含まれていることを検証し、ラベルの値が事前定義された形式に一致することを確認します。各ラベルキーに正規表現を指定して、その値を検証できます。optional パラメーターを使用して、ラベルの検証が必須かどうかを制御することもできます。
重要度:低。
パラメーター:
パラメーター名 | タイプ | 説明 |
| 文字列 | ラベルのホワイトリストの正規表現。 |
| 文字列 | 検証するタグキー。 |
| bool | Pod がこのタグを欠落させることが許可されるかどうかを指定します。
|
例:
制約:
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: redisACKRequiredProbes
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod に、指定されたタイプの readinessProbe と livenessProbe を設定する必要があります。
重要度:中。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 配列 | Pod に設定する必要があるプローブ。例:readinessProbe および livenessProbe。 |
| 配列 | Pod に設定する必要があるプローブタイプ。例:tcpSocket、httpGet、および 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/busyboxACKCheckNginxPath
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: 80ACKCheckNginxAnnotation
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: 80ACKBlockInternetLoadBalancer
ルールの説明:インターネット向け 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: 9376RatifyVerification
ルールの説明:クラスターのマーケットプレイスから 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 # Deploy an image with a valid signature.
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-containerPSP
ACKPSPAllowedUsers
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod の起動時の user、group、supplementalGroups、および fsGroup を制限します。
重要度:中。
パラメーター:
パラメーター | パラメータータイプ | 説明 |
| オブジェクト | このパラメーターの詳細な説明については、元の PSP ルールのユーザー構成をご参照ください。ルールタイプと最大および最小 UID の設定をサポートします。詳細については、「ユーザーとグループ」をご参照ください。 |
| オブジェクト | このパラメーターの詳細な説明については、元の PSP ルールのグループ構成をご参照ください。ルールタイプと最大および最小 UID の設定をサポートします。詳細については、「ユーザーとグループ」をご参照ください。 |
| オブジェクト | このパラメーターの詳細な説明については、元の PSP ルールの SupplementalGroups 構成をご参照ください。ルールタイプと最大および最小 UID の設定をサポートします。詳細については、「ユーザーとグループ」をご参照ください。 |
| オブジェクト | このパラメーターの詳細な説明については、元の 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: testACKPSPAllowPrivilegeEscalationContainer
ルールの説明:クラスター内の指定された範囲にデプロイされた 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: testACKPSPAppArmor
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod の AppArmor 構成を制限します。
重要度:低。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 配列 | Pod に設定する必要があるプローブ。例:readinessProbe および livenessProbe。 |
| 配列 | Pod に設定する必要があるプローブタイプ。例:tcpSocket、httpGet、および 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: testACKPSPCapabilities
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod の Linux Capabilities 構成を制限します。
重要度:高。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 配列 | 許可された capabilities のホワイトリスト。 |
| 配列 | ドロップする必要がある capabilities。 |
例:
制約:
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: testACKPSPFlexVolumes
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod の FlexVolume ドライバー構成を制限します。
重要度:中。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 配列 | 許可された 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 の禁止されている sysctl の範囲を制限します。
重要度:高。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 配列 | Pod 内の禁止された 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
- "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: testACKPSPFSGroup
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod の fsGroup 構成を制限します。
重要度:中。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 文字列 | このパラメーターの詳細な説明については、元の PSP ルールの fsGroup 構成をご参照ください。サポートされている値は MustRunAs、MayRunAs、および RunAsAny です。詳細については、「ボリュームとファイルシステム」をご参照ください。 |
| オブジェクト | 次の値が含まれます:
|
例:
制約:
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: testACKPSPHostFilesystem
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod がマウントできるホストディレクトリの範囲を制限します。
重要度:高。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| オブジェクト | ホストパスのホワイトリスト構成。 |
| boolean | パスが読み取り専用かどうかを指定します。 |
| 文字列 | パスプレフィックス。 |
例:
制約:
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: FileACKPSPHostNamespace
ルールの説明:クラスター内の指定された範囲にデプロイされた 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 によるホストネットワークと指定されたポートの使用を制限します。
重要度:高。
パラメーター:
パラメーター名 | タイプ | 説明 |
| boolean | Pod がホストネットワークを共有できるかどうかを指定します。 |
| int | hostPort の最小値。 |
| int | 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: 22ACKPSPPrivilegedContainer
ルールの説明:クラスター内の指定された範囲にデプロイされた 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: NeverACKPSPProcMount
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod で許可される proc マウントタイプを制限します。
重要度:高。
パラメーター:
パラメーター名 | タイプ | 説明 |
| 文字列 | 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許可:
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: test2ACKPSPReadOnlyRootFilesystem
ルールの説明:クラスター内の指定された範囲にデプロイされた 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: test2ACKPSPSeccomp
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod に、指定された Seccomp プロファイルを使用することを制限します。
重要度:低
パラメーター:
パラメーター名 | パラメータータイプ | メトリックの説明 |
| 配列 | 許可された Seccomp プロファイルタイプのホワイトリスト。 |
| 配列 | 許可された 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: testACKPSPSELinuxV2
ルールの説明:クラスター内の指定された範囲にデプロイされた Pod に、allowedSELinuxOptions パラメーターで指定された SELinux 構成を使用することを要求します。
重要度:低。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| オブジェクト | 許可された 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
ルールの説明:クラスター内の指定された範囲にデプロイされた 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: /dataFinOps
ACKContainerRequests
ルールの説明:クラスター内の指定されたアプリケーション Pod がリソース requests を宣言することを要求します。
重要度:低。
パラメーター:
パラメーター | パラメータータイプ | 説明 |
| 文字列 | コンテナーの CPU |
| 文字列 | コンテナーのメモリ |
例:
制約:
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-containerACKContainerResourcesWhitelist
ルールの説明:クラスター内の指定されたアプリケーション Pod の CPU およびメモリリソース構成が、事前定義されたオプションのリストから選択されることを要求します。
重要度:低。
パラメーター:
パラメーター | パラメータータイプ | 説明 |
| 配列 | コンテナーの CPU |
| 配列 | コンテナーの CPU |
| 配列 | コンテナーのメモリ |
| 配列 | コンテナーのメモリ |
例:
制約:
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: 1GiACKContainerResourcesRange
ルールの説明:クラスター内の指定されたアプリケーション Pod のリソース構成を、指定された範囲内に制限します。
重要度:低。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| オブジェクト | 次の値が含まれます:
|
| オブジェクト | 次の値が含まれます:
|
| オブジェクト | 次の値が含まれます:
|
| オブジェクト | 次の値が含まれます:
|
例:
制約:
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: 128MiACKRequiredNodeSelector
ルールの説明:クラスター内の指定されたアプリケーション Pod に nodeSelector ラベルが設定されていることを要求します。
重要度:低。
パラメーター:
パラメーター名 | パラメータータイプ | 説明 |
| 配列 | 次の値が含まれます:
|
例:
制約:
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: windowsACKWorkloadReplicasRange
ルールの説明:アプリケーションレプリカの数を指定された範囲に制限します。
重要度:低。
パラメーター:
パラメーター | パラメータータイプ | 説明 |
| int | アプリケーションの最小レプリカ数。 |
| int | アプリケーションの最大レプリカ数。 |
例:
制約:
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