Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .agent/specs/SPEC-P5_TENANT_GUARDRAILS.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ Evidence: `docs/evidence/p5/P5-T2.1_L2_KIND_BASELINE_<date>.md`.
- [x] Webhook scope and `failurePolicy` per D8; verified in the rendered
`ValidatingWebhookConfiguration`, not only in values.
(24/11: `gitops/platform/apps/45-kyverno.yaml`, `47-kyverno-policies.yaml`,
`gitops/platform/policies/`; `kyverno test` 14/14; `check.sh` rule 17 with
`gitops/platform/policies/`; `kyverno test` 14/14, in CI since 24/11 (job
`kyverno` of `static-gates`, `gitops/tests/kyverno_test.sh`); `check.sh` rule 17 with
guards; on kind the rendered webhook `vpol.validate.kyverno.svc-fail` is
`Fail` and selects only namespaces with the tenant label. Findings F1–F6
in §10.)
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/static-gates.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Static gates on pull requests (SPEC-P4 P4-T3.2 B, D12; ver3 §9.1 step 2).
# gitops/check.sh with its guard tests, and the Terraform static gate
# gitops/check.sh with its guard tests, kyverno test for the Kyverno policies,
# and the Terraform static gate
# (fmt, validate, mocked contract tests, plan_assert guards, pins, leak scan).
# No cloud or cluster credential: no secret is referenced, the token is read-only,
# Terraform runs with -backend=false and mock providers only.
Expand Down Expand Up @@ -47,6 +48,18 @@ jobs:
- name: Guard tests (each rule must be able to fail)
run: bash gitops/tests/check_guards.sh

kyverno:
# L1 for the Kyverno policies (SPEC-P5 P5-T2.2 A): kyverno test in the pinned
# kyverno-cli image by digest, no network in the container, plus a self-test.
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: kyverno test (kyverno-cli v1.20.0 by digest)
run: bash gitops/tests/kyverno_test.sh

terraform:
runs-on: ubuntu-24.04
timeout-minutes: 15
Expand Down
16 changes: 16 additions & 0 deletions docs/runbooks/P5_L2_KIND_KYVERNO.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,19 @@ kind delete cluster --name zdr-p5-kyv; rm -rf "$HOME/zdr-p5-kyv"; unset K POD LA
| 4 bỏ bước scale thì sao | | | |

Sau lab, trả lời một câu: **vì sao `noreq` không bị Kyverno chặn, và khi nào `zdr-require-resources` mới có tác dụng?**

## Phụ lục: L1 `kyverno test` (không cần cluster)

Đây là kiểm tra tĩnh, chạy trước lab: mỗi luật có một Pod phải qua và một Pod phải bị chặn
(`gitops/tests/kyverno/`). Từ 24/11, CI `static-gates` (job `kyverno`) chạy lệnh này trên mọi PR đụng `gitops/`.
Ví von: diễn tập bảo vệ bằng hàng mẫu trước khi mở cửa toà nhà.

Chạy lại trên máy (cần Docker đang chạy, tải image `kyverno-cli` v1.20.0 theo digest, không cần AWS):

```bash
bash gitops/tests/kyverno_test.sh
```

Phải thấy: `Test Summary: 14 tests passed and 0 tests failed`, rồi dòng self-test
`… tests failed` khác 0 (một kỳ vọng bị cố ý lật trong bản sao), cuối cùng `PASS kyverno test and self-test`.
Không có gì để dọn: container tự xoá (`--rm`), thư mục tạm tự xoá khi script thoát.
47 changes: 47 additions & 0 deletions gitops/tests/kyverno_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# L1 gate (SPEC-P5 P5-T2.2 A, L1 in §8): run the kyverno test cases in
# gitops/tests/kyverno/ with the pinned kyverno-cli v1.20.0 image, the same
# digest the chart uses (docs/evidence/p5/P5-T1_PINS_20261122.md).
# Then a self-test: one expected result is flipped in a copy, and the run must
# fail, so a CLI that passes everything cannot turn this gate green.
# Needs Docker. No network inside the container, the repo is mounted read-only.
# Usage: bash gitops/tests/kyverno_test.sh
set -euo pipefail

IMG="reg.kyverno.io/kyverno/kyverno-cli@sha256:bd2b8b7c9d550ecf04e0bacaf351adce2f82ce67fd3f291075edcee7f8ab4ab4"
cd "$(dirname "$0")/.." # gitops/

# run DIR: prints the CLI summary, returns 0 only on "N passed and 0 failed", N >= 1.
run() {
local src out rc summary
src="$(cd "$1" && { pwd -W 2>/dev/null || pwd; })" # Git Bash needs the Windows path for -v
out="$(MSYS_NO_PATHCONV=1 docker run --rm --network none -v "$src:/g:ro" -w /g/tests/kyverno "$IMG" test . 2>&1)" && rc=0 || rc=$?
summary="$(printf '%s\n' "$out" | grep -E '^Test Summary: ' | tail -n 1 || true)"
echo "exit $rc: ${summary:-no summary}"
if [[ $rc -eq 0 && "$summary" =~ ^Test\ Summary:\ [1-9][0-9]*\ tests\ passed\ and\ 0\ tests\ failed$ ]]; then
return 0
fi
printf '%s\n' "$out" | tail -n 40
return 1
}

echo "== kyverno test (gitops/tests/kyverno)"
run . || { echo "FAIL kyverno test"; exit 1; }

echo "== self-test: one flipped expectation must fail"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
mkdir -p "$tmp/platform" "$tmp/tests"
cp -R platform/policies "$tmp/platform/"
cp -R tests/kyverno "$tmp/tests/"
f="$tmp/tests/kyverno/kyverno-test.yaml"
n="$(grep -c '^ result: pass$' "$f" || true)"
[[ "$n" -ge 1 ]] || { echo "FAIL self-test: no 'result: pass' to flip"; exit 1; }
sed -i '0,/^ result: pass$/s// result: fail/' "$f"
r=0; s="$(run "$tmp")" || r=$?
echo "${s%%$'\n'*}"
if [[ $r -eq 0 ]]; then
echo "FAIL self-test: flipped expectation still passed"
exit 1
fi
echo "PASS kyverno test and self-test"