mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
phase42: fix lifecycle owner admission gate
This commit is contained in:
1 parent
4b31ec4dc7
commit
f61309251e
6 files changed
+248
-22
No files matched your search
@@ -1,6 +1,6 @@
|
||||
# Current Plan: Phase 42 - Lifecycle Owner API / Admission Gate
|
||||
|
||||
Status: open, 14% complete. Started on 2026-06-14.
|
||||
Status: open, 21% complete. Started on 2026-06-14.
|
||||
|
||||
Branch: `phase41-lifecycle-owner-foundation`
|
||||
|
||||
@@ -70,6 +70,7 @@ Acceptance:
|
||||
[x] install lifecycle-owner RBAC separate from operator-status
|
||||
[x] install admission policy/webhook or equivalent finalizer-only enforcement
|
||||
[x] prove operator-status RBAC remains status/events-only
|
||||
[x] fail on real admission mistakes instead of mock-only proof
|
||||
```
|
||||
|
||||
Verification:
|
||||
@@ -93,8 +94,9 @@ Allowed patch shape:
|
||||
Acceptance:
|
||||
|
||||
```text
|
||||
[ ] lifecycle-owner can add the Seaweed Block finalizer
|
||||
[ ] lifecycle-owner can remove the Seaweed Block finalizer
|
||||
[ ] lifecycle-owner can add the Seaweed Block finalizer on a real apiserver
|
||||
[ ] lifecycle-owner can remove the Seaweed Block finalizer on a real apiserver
|
||||
[ ] admission policy propagation is proven before positive/negative assertions
|
||||
[ ] repeated add/remove is idempotent
|
||||
[ ] spec, labels, annotations, ownerReferences, and status are preserved
|
||||
[ ] audit evidence records request, decision, reason, and object diff
|
||||
@@ -215,6 +217,11 @@ Phase 42 can close only if:
|
||||
remains status/events-only. Local Rancher Desktop smoke fails closed with
|
||||
`blocked_reason=validating_admission_policy_unavailable`; QA must run this on
|
||||
a cluster with `ValidatingAdmissionPolicy` support.
|
||||
- 21%: D1 QA found a real live-admission defect: optional-field CEL comparisons
|
||||
denied a legitimate finalizer add when `.status` or `ownerReferences` were
|
||||
absent, and the gate had no VAP propagation wait. The harness now guards
|
||||
optional fields with `has()` and waits until a known-bad lifecycle-owner patch
|
||||
is denied before running assertions. This is pending QA rerun on m02.
|
||||
|
||||
## Prerequisites / Risks
|
||||
|
||||
@@ -228,7 +235,16 @@ Phase 42 can close only if:
|
||||
|
||||
## Next Step
|
||||
|
||||
Implement D1: choose the harness shape, wire the real CRD/RBAC/admission test
|
||||
surface, and prove the existing status-only observer remains unchanged. QA
|
||||
assignment:
|
||||
Re-run D1 on m02 or another `ValidatingAdmissionPolicy`-capable cluster. The
|
||||
rerun must show:
|
||||
|
||||
```text
|
||||
phase42_lifecycle_owner_admission_status=ok
|
||||
admission_policy_propagated=true
|
||||
lifecycle_owner_finalizer_add_allowed=true
|
||||
lifecycle_owner_finalizer_remove_allowed=true
|
||||
all forbidden patch checks=false
|
||||
```
|
||||
|
||||
QA assignment:
|
||||
`internal/docs/qa-assignments/phase42-d1-lifecycle-owner-admission-gate-qa.md`.
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
# QA Sign-off — Phase 42 D1 Lifecycle Owner Admission Gate
|
||||
|
||||
Verdict: **FAIL (blocking product defect in the VAP policy).** On a real
|
||||
VAP-capable cluster the admission gate denies the **legitimate** lifecycle-owner
|
||||
finalizer add — the policy CEL errors on absent optional fields. This is a
|
||||
live-only defect: it is invisible to the Phase 41 schema-aware mock and to the
|
||||
dev's VAP-less rancher-desktop, and is exactly the class Phase 42 exists to catch.
|
||||
|
||||
Date: 2026-06-14
|
||||
Source: branch `phase41-lifecycle-owner-foundation` @ `bc5ffc0 phase42: add live
|
||||
lifecycle owner admission gate`
|
||||
Environment: m02 k3s **v1.34.4+k3s1** — `admissionregistration.k8s.io/v1`
|
||||
`ValidatingAdmissionPolicy` + `ValidatingAdmissionPolicyBinding` served and
|
||||
enforced (this is **not** the env-blocked case; the gate's environment
|
||||
requirement is met).
|
||||
|
||||
## How It Was Run
|
||||
|
||||
`bash scripts/run-phase42-lifecycle-owner-admission-gate.sh /tmp/seaweed_block`
|
||||
on m02 (`KUBECONFIG=/etc/rancher/k3s/k3s.yaml`), artifacts in `/tmp/p42d1`. A
|
||||
second diagnostic run injected a 25 s VAP-propagation wait after the policy apply
|
||||
to separate the propagation race from the policy logic.
|
||||
|
||||
## Result
|
||||
|
||||
`GATE_EXIT=1`; summary stops at `status=running` (incomplete):
|
||||
|
||||
```text
|
||||
phase42_lifecycle_owner_admission_status=running
|
||||
harness=live_kubernetes_validating_admission_policy
|
||||
operator_status_main_patch_allowed=false
|
||||
lifecycle_owner_finalizer_add_allowed=true <- first run only (VAP not yet active)
|
||||
lifecycle_owner_finalizer_remove_allowed=true <- first run only (VAP not yet active)
|
||||
```
|
||||
|
||||
- **Run 1 (no wait):** the VAP had not propagated, so the lifecycle-owner
|
||||
finalizer add/remove succeeded and the **spec-patch deny-check** (the first
|
||||
negative case) was *not* denied — the patch went through. Gate aborted at
|
||||
`lifecycle-owner-spec-patch`.
|
||||
- **Run 2 (25 s wait, VAP active):** the gate aborted *earlier*, at the
|
||||
**legitimate** `lifecycle-owner-add-finalizer` — the active VAP denied it:
|
||||
|
||||
```text
|
||||
ValidatingAdmissionPolicy 'sw-block-phase42-finalizer-only' ... denied request:
|
||||
expression '... object.status == oldObject.status ...' resulted in error:
|
||||
no such key: status
|
||||
```
|
||||
|
||||
## Root Cause
|
||||
|
||||
The VAP CEL (script lines 165–178) compares optional object fields directly:
|
||||
|
||||
```text
|
||||
object.spec == oldObject.spec &&
|
||||
object.status == oldObject.status && <-- errors when .status absent
|
||||
object.metadata.labels == oldObject.metadata.labels &&
|
||||
object.metadata.annotations == oldObject.metadata.annotations &&
|
||||
object.metadata.ownerReferences == oldObject.metadata.ownerReferences && <-- also absent on the test object
|
||||
...
|
||||
```
|
||||
|
||||
The test object `phase42-a` is created with only `metadata` (labels/annotations)
|
||||
and `spec` — **no `.status`, no `.ownerReferences`**. In Kubernetes VAP CEL,
|
||||
reading an absent key (`object.status`) raises `no such key: status`. With
|
||||
`validationActions: [Deny]` and the default `failurePolicy: Fail`, a CEL
|
||||
**evaluation error is treated as DENY**. So the active policy denies the very
|
||||
finalizer add it is meant to allow. (Once `status` is guarded, the next absent
|
||||
field — `ownerReferences` — would error the same way.)
|
||||
|
||||
So there are two defects, in priority order:
|
||||
|
||||
1. **(Blocking, product) VAP CEL does not handle absent optional fields.**
|
||||
`object.status`, `object.metadata.ownerReferences` (and any optional
|
||||
metadata) must be `has()`-guarded, e.g. per field:
|
||||
`(has(object.X) == has(oldObject.X)) && (!has(object.X) || object.X == oldObject.X)`
|
||||
(or CEL optional access `object.?X.orValue(null) == oldObject.?X.orValue(null)`).
|
||||
Until this is fixed, the gate cannot pass: a real apiserver denies the
|
||||
approved finalizer mutation.
|
||||
2. **(Gate robustness) No wait for VAP propagation before the deny-checks.**
|
||||
The script runs the patch checks immediately after `kubectl apply` of the
|
||||
policy/binding (line 194 → 215). VAP enforcement is not synchronous, so the
|
||||
negative checks are non-deterministic and, in run 1, raced an inactive policy
|
||||
(which masked defect #1 by letting the spec patch through). Add a readiness
|
||||
wait — poll until a known-bad patch is actually denied, or `kubectl wait` /
|
||||
bounded sleep — before any check.
|
||||
|
||||
## Gate Coverage Reached
|
||||
|
||||
```text
|
||||
G1 run the gate FAIL (policy denies legitimate finalizer add; spec deny-check raced in run 1)
|
||||
G2 forbidden resource mutations NOT REACHED (gate aborts at G1)
|
||||
G3 object integrity NOT REACHED
|
||||
G4 cleanup PASS (ns/VAP/VAPBinding/ClusterRole/Binding all removed on failure exit;
|
||||
verified 0 leftovers after both runs)
|
||||
```
|
||||
|
||||
`operator_status_main_patch_allowed=false` is correct (RBAC-enforced; the
|
||||
operator-status SA has no main-object patch). The harness is genuinely live VAP —
|
||||
it *did* enforce in run 2; it enforced the wrong outcome.
|
||||
|
||||
## Blocking Findings
|
||||
|
||||
1. VAP CEL errors on absent optional fields (`no such key: status`) →
|
||||
`failurePolicy:Fail` → the approved lifecycle-owner finalizer add/remove is
|
||||
denied on a real API server. Fix the CEL to `has()`-guard optional-field
|
||||
immutability comparisons, then re-run.
|
||||
|
||||
## Non-Blocking Findings
|
||||
|
||||
1. Gate has no VAP-propagation wait; the negative checks are order/timing
|
||||
dependent. Add a readiness gate so a fixed policy is deterministically
|
||||
enforced before the checks. (Surface this even after #1 is fixed.)
|
||||
2. tp01 `NotReady` — unrelated to this single-node admission gate.
|
||||
|
||||
## Recommendation
|
||||
|
||||
**Hold Phase 42 D1.** The live gate did its job — it surfaced a real CEL defect
|
||||
that no mock could. Dev should: (a) `has()`-guard the optional-field comparisons
|
||||
in the VAP (status, ownerReferences, and any optional metadata), and (b) add a
|
||||
VAP-propagation readiness wait before the deny-checks. Then re-run on m02
|
||||
(v1.34.4, VAP-capable) for the full G1–G4 sweep. I can re-run as soon as the fix
|
||||
lands.
|
||||
+5
@@ -77,6 +77,7 @@ Pass criteria in
|
||||
```text
|
||||
phase42_lifecycle_owner_admission_status=ok
|
||||
harness=live_kubernetes_validating_admission_policy
|
||||
admission_policy_propagated=true
|
||||
operator_status_main_patch_allowed=false
|
||||
lifecycle_owner_finalizer_add_allowed=true
|
||||
lifecycle_owner_finalizer_remove_allowed=true
|
||||
@@ -142,3 +143,7 @@ PASS only if G1-G4 pass on a real Kubernetes API/admission surface.
|
||||
Do not mark Phase 42 D1 passed using the old Phase 41 schema-aware fake server.
|
||||
That fake server was sufficient for Phase 41's non-mutating slice, but Phase 42
|
||||
is specifically about the real admission boundary.
|
||||
|
||||
The gate must wait until a known-bad lifecycle-owner patch is denied before it
|
||||
runs the positive and negative assertions. A success before admission policy
|
||||
propagation is not a product PASS.
|
||||
@@ -171,13 +171,17 @@ spec:
|
||||
request.userInfo.username != 'system:serviceaccount:${Namespace}:sw-block-lifecycle-owner' ||
|
||||
(
|
||||
object.spec == oldObject.spec &&
|
||||
object.status == oldObject.status &&
|
||||
object.metadata.labels == oldObject.metadata.labels &&
|
||||
object.metadata.annotations == oldObject.metadata.annotations &&
|
||||
object.metadata.ownerReferences == oldObject.metadata.ownerReferences &&
|
||||
has(object.metadata.finalizers) &&
|
||||
size(object.metadata.finalizers) <= 1 &&
|
||||
object.metadata.finalizers.all(f, f == '${Finalizer}') &&
|
||||
(has(object.status) == has(oldObject.status)) &&
|
||||
(!has(object.status) || object.status == oldObject.status) &&
|
||||
(has(object.metadata.labels) == has(oldObject.metadata.labels)) &&
|
||||
(!has(object.metadata.labels) || object.metadata.labels == oldObject.metadata.labels) &&
|
||||
(has(object.metadata.annotations) == has(oldObject.metadata.annotations)) &&
|
||||
(!has(object.metadata.annotations) || object.metadata.annotations == oldObject.metadata.annotations) &&
|
||||
(has(object.metadata.ownerReferences) == has(oldObject.metadata.ownerReferences)) &&
|
||||
(!has(object.metadata.ownerReferences) || object.metadata.ownerReferences == oldObject.metadata.ownerReferences) &&
|
||||
(!has(object.metadata.finalizers) ||
|
||||
(size(object.metadata.finalizers) <= 1 &&
|
||||
object.metadata.finalizers.all(f, f == '${Finalizer}'))) &&
|
||||
(!has(oldObject.metadata.finalizers) ||
|
||||
(size(oldObject.metadata.finalizers) <= 1 &&
|
||||
oldObject.metadata.finalizers.all(f, f == '${Finalizer}')))
|
||||
@@ -198,6 +202,8 @@ spec:
|
||||
"@ | Set-Content -Path (Join-Path $ArtifactDir "admission.yaml")
|
||||
Expect-Success "apply-admission" @("apply", "-f", (Join-Path $ArtifactDir "admission.yaml"))
|
||||
|
||||
$ownerAs = "system:serviceaccount:${Namespace}:sw-block-lifecycle-owner"
|
||||
|
||||
@"
|
||||
apiVersion: block.seaweedfs.com/v1alpha1
|
||||
kind: SwBlockVolume
|
||||
@@ -214,8 +220,42 @@ spec:
|
||||
"@ | Set-Content -Path (Join-Path $ArtifactDir "volume.yaml")
|
||||
Expect-Success "apply-volume" @("apply", "-f", (Join-Path $ArtifactDir "volume.yaml"))
|
||||
|
||||
@"
|
||||
apiVersion: block.seaweedfs.com/v1alpha1
|
||||
kind: SwBlockVolume
|
||||
metadata:
|
||||
name: phase42-admission-probe
|
||||
namespace: $Namespace
|
||||
labels:
|
||||
probe: "initial"
|
||||
spec:
|
||||
pvcName: phase42-admission-probe
|
||||
storageClass: sw-block
|
||||
"@ | Set-Content -Path (Join-Path $ArtifactDir "admission-probe.yaml")
|
||||
Expect-Success "apply-admission-probe" @("apply", "-f", (Join-Path $ArtifactDir "admission-probe.yaml"))
|
||||
|
||||
$propagated = $false
|
||||
foreach ($attempt in 1..30) {
|
||||
$patch = "{`"metadata`":{`"labels`":{`"probe`":`"denied-$attempt`"}}}"
|
||||
$code = Invoke-Capture -Name "admission-policy-propagation-$attempt" -Args @("patch", "swblockvolume", "phase42-admission-probe", "-n", $Namespace, "--as", $ownerAs, "--type=merge", "-p", $patch)
|
||||
if ($code -eq 0) {
|
||||
Start-Sleep -Seconds 1
|
||||
continue
|
||||
}
|
||||
$stderr = Get-Content (Join-Path $ArtifactDir "admission-policy-propagation-$attempt.stderr.txt") -ErrorAction SilentlyContinue
|
||||
if ($stderr -match "lifecycle-owner may patch only") {
|
||||
$propagated = $true
|
||||
Add-Summary "admission_policy_propagated=true"
|
||||
break
|
||||
}
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
if (-not $propagated) {
|
||||
Add-Summary "admission_policy_propagated=false"
|
||||
throw "validating admission policy did not deny a known-bad lifecycle-owner patch in time"
|
||||
}
|
||||
|
||||
$operatorAs = "system:serviceaccount:${Namespace}:sw-block-operator-status"
|
||||
$ownerAs = "system:serviceaccount:${Namespace}:sw-block-lifecycle-owner"
|
||||
|
||||
Expect-Failure "operator-status-main-patch" @("patch", "swblockvolume", "phase42-a", "-n", $Namespace, "--as", $operatorAs, "--type=merge", "-p", "{`"metadata`":{`"finalizers`":[`"$Finalizer`"]}}")
|
||||
Add-Summary "operator_status_main_patch_allowed=false"
|
||||
|
||||
@@ -166,13 +166,17 @@ spec:
|
||||
request.userInfo.username != 'system:serviceaccount:${NAMESPACE}:sw-block-lifecycle-owner' ||
|
||||
(
|
||||
object.spec == oldObject.spec &&
|
||||
object.status == oldObject.status &&
|
||||
object.metadata.labels == oldObject.metadata.labels &&
|
||||
object.metadata.annotations == oldObject.metadata.annotations &&
|
||||
object.metadata.ownerReferences == oldObject.metadata.ownerReferences &&
|
||||
has(object.metadata.finalizers) &&
|
||||
size(object.metadata.finalizers) <= 1 &&
|
||||
object.metadata.finalizers.all(f, f == '${FINALIZER}') &&
|
||||
(has(object.status) == has(oldObject.status)) &&
|
||||
(!has(object.status) || object.status == oldObject.status) &&
|
||||
(has(object.metadata.labels) == has(oldObject.metadata.labels)) &&
|
||||
(!has(object.metadata.labels) || object.metadata.labels == oldObject.metadata.labels) &&
|
||||
(has(object.metadata.annotations) == has(oldObject.metadata.annotations)) &&
|
||||
(!has(object.metadata.annotations) || object.metadata.annotations == oldObject.metadata.annotations) &&
|
||||
(has(object.metadata.ownerReferences) == has(oldObject.metadata.ownerReferences)) &&
|
||||
(!has(object.metadata.ownerReferences) || object.metadata.ownerReferences == oldObject.metadata.ownerReferences) &&
|
||||
(!has(object.metadata.finalizers) ||
|
||||
(size(object.metadata.finalizers) <= 1 &&
|
||||
object.metadata.finalizers.all(f, f == '${FINALIZER}'))) &&
|
||||
(!has(oldObject.metadata.finalizers) ||
|
||||
(size(oldObject.metadata.finalizers) <= 1 &&
|
||||
oldObject.metadata.finalizers.all(f, f == '${FINALIZER}')))
|
||||
@@ -193,6 +197,8 @@ spec:
|
||||
YAML
|
||||
run_expect_success apply-admission "${KUBECTL}" apply -f "${ARTIFACT_DIR}/admission.yaml"
|
||||
|
||||
OWNER_AS="system:serviceaccount:${NAMESPACE}:sw-block-lifecycle-owner"
|
||||
|
||||
cat >"${ARTIFACT_DIR}/volume.yaml" <<YAML
|
||||
apiVersion: block.seaweedfs.com/v1alpha1
|
||||
kind: SwBlockVolume
|
||||
@@ -209,8 +215,41 @@ spec:
|
||||
YAML
|
||||
run_expect_success apply-volume "${KUBECTL}" apply -f "${ARTIFACT_DIR}/volume.yaml"
|
||||
|
||||
cat >"${ARTIFACT_DIR}/admission-probe.yaml" <<YAML
|
||||
apiVersion: block.seaweedfs.com/v1alpha1
|
||||
kind: SwBlockVolume
|
||||
metadata:
|
||||
name: phase42-admission-probe
|
||||
namespace: ${NAMESPACE}
|
||||
labels:
|
||||
probe: "initial"
|
||||
spec:
|
||||
pvcName: phase42-admission-probe
|
||||
storageClass: sw-block
|
||||
YAML
|
||||
run_expect_success apply-admission-probe "${KUBECTL}" apply -f "${ARTIFACT_DIR}/admission-probe.yaml"
|
||||
|
||||
wait_for_admission_policy() {
|
||||
local attempt
|
||||
for attempt in $(seq 1 30); do
|
||||
if run_capture "admission-policy-propagation-${attempt}" "${KUBECTL}" patch swblockvolume phase42-admission-probe -n "${NAMESPACE}" --as "${OWNER_AS}" --type=merge -p "{\"metadata\":{\"labels\":{\"probe\":\"denied-${attempt}\"}}}"; then
|
||||
sleep 1
|
||||
continue
|
||||
fi
|
||||
if grep -q "lifecycle-owner may patch only" "${ARTIFACT_DIR}/admission-policy-propagation-${attempt}.stderr.txt"; then
|
||||
write_summary "admission_policy_propagated=true"
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
write_summary "admission_policy_propagated=false"
|
||||
echo "validating admission policy did not deny a known-bad lifecycle-owner patch in time" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for_admission_policy
|
||||
|
||||
OPERATOR_AS="system:serviceaccount:${NAMESPACE}:sw-block-operator-status"
|
||||
OWNER_AS="system:serviceaccount:${NAMESPACE}:sw-block-lifecycle-owner"
|
||||
|
||||
run_expect_failure operator-status-main-patch "${KUBECTL}" patch swblockvolume phase42-a -n "${NAMESPACE}" --as "${OPERATOR_AS}" --type=merge -p "{\"metadata\":{\"finalizers\":[\"${FINALIZER}\"]}}"
|
||||
write_summary "operator_status_main_patch_allowed=false"
|
||||
|
||||
@@ -27,6 +27,10 @@ phases:
|
||||
name: operator_status_no_main_patch
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase42-lifecycle-owner-admission-gate/phase42-lifecycle-owner-admission-gate-summary.txt"
|
||||
pattern: "^operator_status_main_patch_allowed=false$"
|
||||
- type: grep_log
|
||||
name: admission_policy_propagated
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase42-lifecycle-owner-admission-gate/phase42-lifecycle-owner-admission-gate-summary.txt"
|
||||
pattern: "^admission_policy_propagated=true$"
|
||||
- type: grep_log
|
||||
name: lifecycle_owner_finalizer_add_allowed
|
||||
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase42-lifecycle-owner-admission-gate/phase42-lifecycle-owner-admission-gate-summary.txt"
|
||||
|
||||
Reference in new issue
Block a user