Updated on 2024-02-01 GMT+08:00

k8sallowedrepos

Basic Information

  • Policy type: compliance
  • Recommended level: L1
  • Effective resource type: Pod
  • Parameter

    repos: String array

Function

The container image must start with a string in a specified string list.

Policy Example

The following policy instance specifies that the container image must start with openpolicyagent/.

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sAllowedRepos
metadata:
  name: repo-is-openpolicyagent
spec:
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]
    namespaces:
      - "default"
  parameters:
    repos:
      - "openpolicyagent/"

Resource Definition That Complies with the Policy

The container image starts with openpolicyagent/, which complies with the policy instance.

apiVersion: v1
kind: Pod
metadata:
  name: opa-allowed
spec:
  containers:
    - name: opa
      image: openpolicyagent/opa:0.9.2

Resource Definition That Does Not Comply with the Policy

The container image starts with nginx, which does not comply with the policy instance.

apiVersion: v1
kind: Pod
metadata:
  name: nginx-disallowed
spec:
  containers:
    - name: nginx
      image: nginx