fix foreach
This commit is contained in:
@@ -7,7 +7,16 @@
|
|||||||
"Bash(sudo mv /tmp/kyverno /usr/local/bin/kyverno)",
|
"Bash(sudo mv /tmp/kyverno /usr/local/bin/kyverno)",
|
||||||
"Bash(mv /tmp/kyverno ~/bin/kyverno)",
|
"Bash(mv /tmp/kyverno ~/bin/kyverno)",
|
||||||
"Bash(mv /tmp/kyverno ~/.local/bin/kyverno)",
|
"Bash(mv /tmp/kyverno ~/.local/bin/kyverno)",
|
||||||
"Bash(export PATH=\"$HOME/bin:$HOME/.local/bin:$PATH\")"
|
"Bash(export PATH=\"$HOME/bin:$HOME/.local/bin:$PATH\")",
|
||||||
|
"Bash(~/.local/bin/kyverno apply *)",
|
||||||
|
"Bash(rtk ls *)",
|
||||||
|
"Bash(/bin/ls *)",
|
||||||
|
"Bash(export PATH=\"$HOME/.local/bin:$PATH\")",
|
||||||
|
"Bash(kyverno apply *)",
|
||||||
|
"Read(//private/tmp/**)",
|
||||||
|
"Bash(mkdir -p polsdir1 polsdir2)",
|
||||||
|
"Bash(cp t1.yaml polsdir1/)",
|
||||||
|
"Bash(cp t2.yaml polsdir2/)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,14 +26,14 @@ spec:
|
|||||||
- kube-system
|
- kube-system
|
||||||
- kyverno
|
- kyverno
|
||||||
validate:
|
validate:
|
||||||
|
message: >-
|
||||||
|
Все контейнеры в поде '{{ request.object.metadata.name }}'
|
||||||
|
обязаны иметь resources.limits.memory и resources.limits.cpu.
|
||||||
foreach:
|
foreach:
|
||||||
- list: >-
|
- list: >-
|
||||||
request.object.spec.containers[] |
|
request.object.spec.containers[] |
|
||||||
merge(request.object.spec.initContainers[] || `[]`, @) |
|
merge(request.object.spec.initContainers[] || `[]`, @) |
|
||||||
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
||||||
message: >-
|
|
||||||
Контейнер '{{ element.name }}' в поде '{{ request.object.metadata.name }}'
|
|
||||||
не имеет resource limits. Добавьте resources.limits.memory и resources.limits.cpu.
|
|
||||||
pattern:
|
pattern:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ spec:
|
|||||||
namespaces:
|
namespaces:
|
||||||
- kube-system
|
- kube-system
|
||||||
validate:
|
validate:
|
||||||
|
message: >-
|
||||||
|
Один из образов в поде '{{ request.object.metadata.name }}' использует
|
||||||
|
тег :latest или не имеет тега. Используйте конкретный тег или digest.
|
||||||
foreach:
|
foreach:
|
||||||
- list: >-
|
- list: >-
|
||||||
request.object.spec.containers[] |
|
request.object.spec.containers[] |
|
||||||
merge(request.object.spec.initContainers[] || `[]`, @) |
|
merge(request.object.spec.initContainers[] || `[]`, @) |
|
||||||
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
||||||
message: >-
|
|
||||||
Образ '{{ element.image }}' использует тег :latest или не имеет тега.
|
|
||||||
Используйте конкретный тег (nginx:1.25.3) или digest (nginx@sha256:...).
|
|
||||||
deny:
|
deny:
|
||||||
conditions:
|
conditions:
|
||||||
any:
|
any:
|
||||||
|
|||||||
@@ -27,15 +27,14 @@ spec:
|
|||||||
- kube-system
|
- kube-system
|
||||||
- kyverno
|
- kyverno
|
||||||
validate:
|
validate:
|
||||||
|
message: >-
|
||||||
|
Один из образов в поде '{{ request.object.metadata.name }}' из недоверенного реестра.
|
||||||
|
Разрешены: registry.company.com/, gcr.io/company-project/.
|
||||||
foreach:
|
foreach:
|
||||||
- list: >-
|
- list: >-
|
||||||
request.object.spec.containers[] |
|
request.object.spec.containers[] |
|
||||||
merge(request.object.spec.initContainers[] || `[]`, @) |
|
merge(request.object.spec.initContainers[] || `[]`, @) |
|
||||||
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
||||||
message: >-
|
|
||||||
Образ '{{ element.image }}' из недоверенного реестра.
|
|
||||||
Разрешены: registry.company.com/, gcr.io/company-project/.
|
|
||||||
Загрузите образ в внутренний реестр и обновите манифест.
|
|
||||||
deny:
|
deny:
|
||||||
conditions:
|
conditions:
|
||||||
all:
|
all:
|
||||||
|
|||||||
@@ -26,14 +26,14 @@ spec:
|
|||||||
namespaces:
|
namespaces:
|
||||||
- kube-system
|
- kube-system
|
||||||
validate:
|
validate:
|
||||||
|
message: >-
|
||||||
|
Один из контейнеров в поде '{{ request.object.metadata.name }}' добавляет
|
||||||
|
запрещённые capabilities. Разрешена только NET_BIND_SERVICE.
|
||||||
foreach:
|
foreach:
|
||||||
- list: >-
|
- list: >-
|
||||||
request.object.spec.containers[] |
|
request.object.spec.containers[] |
|
||||||
merge(request.object.spec.initContainers[] || `[]`, @) |
|
merge(request.object.spec.initContainers[] || `[]`, @) |
|
||||||
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
||||||
message: >-
|
|
||||||
Контейнер '{{ element.name }}' добавляет запрещённые capabilities.
|
|
||||||
Разрешена только NET_BIND_SERVICE. Пересмотрите необходимость привилегий.
|
|
||||||
deny:
|
deny:
|
||||||
conditions:
|
conditions:
|
||||||
any:
|
any:
|
||||||
|
|||||||
@@ -26,14 +26,14 @@ spec:
|
|||||||
namespaces:
|
namespaces:
|
||||||
- kube-system
|
- kube-system
|
||||||
validate:
|
validate:
|
||||||
|
message: >-
|
||||||
|
Один из контейнеров в поде '{{ request.object.metadata.name }}'
|
||||||
|
имеет securityContext.privileged: true. Запрещено.
|
||||||
foreach:
|
foreach:
|
||||||
- list: >-
|
- list: >-
|
||||||
request.object.spec.containers[] |
|
request.object.spec.containers[] |
|
||||||
merge(request.object.spec.initContainers[] || `[]`, @) |
|
merge(request.object.spec.initContainers[] || `[]`, @) |
|
||||||
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
||||||
message: >-
|
|
||||||
Контейнер '{{ element.name }}' имеет securityContext.privileged: true.
|
|
||||||
Привилегированные контейнеры запрещены. Удалите поле или установите false.
|
|
||||||
deny:
|
deny:
|
||||||
conditions:
|
conditions:
|
||||||
any:
|
any:
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ spec:
|
|||||||
namespaces:
|
namespaces:
|
||||||
- kube-system
|
- kube-system
|
||||||
validate:
|
validate:
|
||||||
|
message: >-
|
||||||
|
Каждый контейнер в поде '{{ request.object.metadata.name }}' должен
|
||||||
|
сбрасывать все capabilities: securityContext.capabilities.drop: [ALL].
|
||||||
foreach:
|
foreach:
|
||||||
- list: >-
|
- list: >-
|
||||||
request.object.spec.containers[] |
|
request.object.spec.containers[] |
|
||||||
merge(request.object.spec.initContainers[] || `[]`, @) |
|
merge(request.object.spec.initContainers[] || `[]`, @) |
|
||||||
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
merge(request.object.spec.ephemeralContainers[] || `[]`, @)
|
||||||
message: >-
|
|
||||||
Контейнер '{{ element.name }}' не сбрасывает все capabilities.
|
|
||||||
Добавьте securityContext.capabilities.drop: [ALL].
|
|
||||||
deny:
|
deny:
|
||||||
conditions:
|
conditions:
|
||||||
all:
|
all:
|
||||||
|
|||||||
@@ -45,11 +45,13 @@ spec:
|
|||||||
namespaces:
|
namespaces:
|
||||||
- kube-system
|
- kube-system
|
||||||
validate:
|
validate:
|
||||||
|
message: >-
|
||||||
|
Один из контейнеров в поде '{{ request.object.metadata.name }}'
|
||||||
|
использует runAsUser: 0 (root). Установите runAsUser >= 1000.
|
||||||
foreach:
|
foreach:
|
||||||
- list: >-
|
- list: >-
|
||||||
request.object.spec.containers[] |
|
request.object.spec.containers[] |
|
||||||
merge(request.object.spec.initContainers[] || `[]`, @)
|
merge(request.object.spec.initContainers[] || `[]`, @)
|
||||||
message: "Контейнер '{{ element.name }}' использует runAsUser: 0 (root). Установите runAsUser >= 1000."
|
|
||||||
deny:
|
deny:
|
||||||
conditions:
|
conditions:
|
||||||
any:
|
any:
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ kubectl get clusterpolicy my-policy -o yaml | grep -A 10 "status:"
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Kyverno CLI — самый быстрый способ проверить
|
# Kyverno CLI — самый быстрый способ проверить
|
||||||
kyverno apply test-pols/policy-require-labels.yaml \
|
kyverno apply test-pols/ \
|
||||||
--resource test-deployment.yaml \
|
--resource test-deployment.yaml \
|
||||||
--detailed-results
|
--detailed-results
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,9 @@ spec:
|
|||||||
kinds:
|
kinds:
|
||||||
- Pod
|
- Pod
|
||||||
validate:
|
validate:
|
||||||
|
message: "All containers must have resources.limits.cpu and resources.limits.memory."
|
||||||
foreach:
|
foreach:
|
||||||
- list: "request.object.spec.containers"
|
- list: "request.object.spec.containers"
|
||||||
message: >-
|
|
||||||
Container '{{ element.name }}' must have resources.limits.cpu
|
|
||||||
and resources.limits.memory defined.
|
|
||||||
pattern:
|
pattern:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
|
|||||||
@@ -36,14 +36,14 @@ spec:
|
|||||||
value: >-
|
value: >-
|
||||||
{{ join('', ['^(', join('|', split(allowedRegistries.data.\"allowed-registries\", '\n')[?@ != '']), ')']) }}
|
{{ join('', ['^(', join('|', split(allowedRegistries.data.\"allowed-registries\", '\n')[?@ != '']), ')']) }}
|
||||||
validate:
|
validate:
|
||||||
|
message: >-
|
||||||
|
Образ в поде '{{ request.object.metadata.name }}' из недоверенного реестра.
|
||||||
|
Список разрешённых (обновлён {{ allowedRegistries.data.\"last-updated\" }}):
|
||||||
|
{{ allowedRegistries.data.\"allowed-registries\" }}
|
||||||
foreach:
|
foreach:
|
||||||
- list: >-
|
- list: >-
|
||||||
request.object.spec.containers[] |
|
request.object.spec.containers[] |
|
||||||
merge(request.object.spec.initContainers[] || `[]`, @)
|
merge(request.object.spec.initContainers[] || `[]`, @)
|
||||||
message: >-
|
|
||||||
Образ '{{ element.image }}' из недоверенного реестра.
|
|
||||||
Список разрешённых реестров (обновлён {{ allowedRegistries.data.\"last-updated\" }}):
|
|
||||||
{{ allowedRegistries.data.\"allowed-registries\" }}
|
|
||||||
deny:
|
deny:
|
||||||
conditions:
|
conditions:
|
||||||
all:
|
all:
|
||||||
|
|||||||
Reference in New Issue
Block a user