phase47: add live status schema rbac gate

This commit is contained in:
pingqiu committed 2026-06-20 10:13:12 -07:00
1 parent e7e2850679
commit aebc738305
7 files changed
+387 -21

No files matched your search

+1 -1
View File
@@ -135,7 +135,7 @@ Recommended order from here:
frontend/ACK eligibility until evidence supports reintegration, and
volume-scoped across multi-volume reports. Automatic failback or broad
rebuild execution remains a later executor phase.
4. Phase 47: returned-replica executor admission. **Dev-validated; QA pending**
4. Phase 47: returned-replica executor admission. **Closed 2026-06-20, QA PASS**
(`internal/docs/finished-plans/phase47_finishedplan_returned_replica_executor_admission.md`).
`authority.reintegrate_returned_replica` is allowed only as a dry-run,
non-mutating action when exact fencing and frontier evidence is present.
+4 -4
View File
@@ -95,9 +95,9 @@ Acceptance:
Implementation note: `TestPhase40D1KubernetesStatusClientConformsToCRDSchemaAndRBAC`
now includes the Phase 47 `authority.reintegrate_returned_replica` allowed
dry-run payload and validates it against the CRD schema-aware mock. QA should
still run a real-apiserver server-side-dry-run gate before release or before a
later mutating executor phase.
dry-run payload and validates it against the CRD schema-aware mock. The live
server-side dry-run gate `returned-replica-status-schema-rbac-chain.yaml`
passed as run `20260620-101008-dbca`.
## D3: Product Surface Rerun
@@ -154,6 +154,6 @@ Acceptance:
Only after D5 should a later phase consider a real mutating executor for
catch-up/rebuild/failback.
Implementation note: Phase 47 is dev-validated and ready for independent QA.
Implementation note: Phase 47 is QA-validated for the dry-run admission slice.
It admits only a dry-run, non-mutating returned-replica reintegration action.
The next executor slice must separately gate any authority/storage mutation.
@@ -1,6 +1,6 @@
# Phase 47 Finished Plan: Returned-Replica Executor Admission
Status: dev-validated; ready for independent QA.
Status: complete; QA PASS.
Branch: `phase47-returned-replica-executor-gate`
@@ -43,6 +43,7 @@ authority.reintegrate_returned_replica decision=allowed mode=dry_run
|---|---|---|
| D1 dry-run admission | `go test -count=1 ./core/ops` | PASS |
| D2 schema/RBAC conformance | `TestPhase40D1KubernetesStatusClientConformsToCRDSchemaAndRBAC` | PASS |
| D2 live API status dry-run | `20260620-101008-dbca` | PASS, 12/12 |
| D3 product surfaces | `TestOpsReturnedReplicaFromBundleSurfacesAcrossReportExplainDashboard` | PASS |
| D4 component live gate | `20260619-155251-ac1e` | PASS, 16/16 |
| D4 iSCSI live gate | `20260619-155300-ba6d` | PASS, 57/57 |
@@ -77,7 +78,10 @@ The allowed action decision is therefore validated through the product-surface
bundle test, not directly from the live iSCSI chain.
Before any future mutating executor phase, add a live scenario artifact that
emits the required-frontier managed-volume evidence from the same run.
emits the required-frontier managed-volume evidence from the same run. The D2
live API gate already proves the returned-replica status/action payload validates
against the real Kubernetes status subresource and that operator-status cannot
patch the main object.
## Next Possible Phase
@@ -556,8 +556,7 @@ product risk. The recommended order is:
(`internal/docs/finished-plans/phase46_finishedplan_returned_replica_reintegration_productization.md`).
The phase intentionally stops short of automatic failback or broad rebuild
execution.
10. **Phase 47: returned-replica executor admission.** Dev-validated; QA
pending.
10. **Phase 47: returned-replica executor admission.** Closed.
First slice admits `authority.reintegrate_returned_replica` only as a
dry-run, non-mutating action after exact fencing and frontier evidence is
present
@@ -627,10 +626,10 @@ Approximate engineering effort if scope remains tight:
- Phase 46 Returned-Replica Rebuild / Reintegration Productization is closed.
Returned replicas are visible, fenced, action-gated, and QA-verifiable before
any automatic rebuild/failback executor is enabled.
- Phase 47 Returned-Replica Executor Admission is dev-validated and ready for
independent QA. It keeps `authority.reintegrate_returned_replica`
dry-run/non-mutating while proving exact fencing/frontier evidence and
schema/RBAC conformance.
- Phase 47 Returned-Replica Executor Admission is closed. It keeps
`authority.reintegrate_returned_replica` dry-run/non-mutating while proving
exact fencing/frontier evidence and schema/RBAC conformance, including a live
Kubernetes status-subresource server-side dry-run gate.
- Phase 41-44 are the Operation Layer v0.5 release train: lifecycle-owner
foundation, real API/admission proof, first bounded finalizer mutation, and
delete lifecycle close gate.
@@ -1,9 +1,8 @@
# Phase 47 D2 Returned-Replica Status Schema/RBAC QA Sign-off
Status: DEV VALIDATED. Real-apiserver QA rerun still recommended before any
mutating executor phase.
Status: PASS.
Validated source: local branch `phase47-returned-replica-executor-gate`.
Validated source: `2f3b864` plus the D2 live gate script/scenario additions.
## Gate
@@ -13,7 +12,7 @@ RBAC boundary that previously caught live-only failures.
## Evidence
Targeted test:
Local targeted test:
```text
go test -count=1 ./core/ops
@@ -28,6 +27,25 @@ The conformance path now writes a `SwBlockVolume.status` payload containing:
- `mutationAllowed=false`,
- returned-replica evidence and invariant refs.
Live TestOps gate:
```text
returned-replica-status-schema-rbac-chain.yaml
run: 20260620-101008-dbca
result: PASS, 12/12
```
Live summary:
```text
phase47_returned_replica_status_schema_rbac_status=ok
valid_returned_replica_status_server_dry_run=true
snake_case_action_rejected=true
unsupported_action_mode_rejected=true
operator_status_main_patch_allowed=no
server_dry_run_status_mutated=false
```
## Boundary
The schema/RBAC mock still enforces:
@@ -38,9 +56,16 @@ The schema/RBAC mock still enforces:
- lifecycle-owner main-object patch remains finalizer-only in its own gate,
- unsupported enum/casing drift returns 422.
## Cleanup
The temporary namespace and RBAC were removed:
```text
sw-block-phase47-status-gate: absent
sw-block-phase47-operator-status ClusterRole/Binding: absent
```
## Non-Claims
This is not a real Kubernetes API server. It is a schema-aware local gate that
shifts CRD casing/enum mistakes left. QA should still run a real-apiserver
server-side-dry-run validation before any later executor phase is allowed to
mutate storage or authority state.
This validates status payload admission and RBAC only. It does not enable or
execute a mutating returned-replica executor.
@@ -0,0 +1,266 @@
#!/usr/bin/env bash
set -euo pipefail
PRODUCT_ROOT="${1:-$(pwd)}"
ARTIFACT_DIR="${SW_BLOCK_ARTIFACT_DIR:-${PRODUCT_ROOT}/results/phase47-returned-replica-status-schema-rbac-gate}"
KUBECTL="${KUBECTL:-kubectl}"
NAMESPACE="${SW_BLOCK_PHASE47_NAMESPACE:-sw-block-phase47-status-gate}"
SA_NAME="sw-block-operator-status"
SA_USER="system:serviceaccount:${NAMESPACE}:${SA_NAME}"
SUMMARY="${ARTIFACT_DIR}/phase47-returned-replica-status-schema-rbac-summary.txt"
mkdir -p "${ARTIFACT_DIR}"
: >"${SUMMARY}"
write_summary() {
echo "$*" | tee -a "${SUMMARY}" >/dev/null
}
run_capture() {
local name="$1"
shift
"$@" >"${ARTIFACT_DIR}/${name}.stdout.txt" 2>"${ARTIFACT_DIR}/${name}.stderr.txt"
}
run_expect_success() {
local name="$1"
shift
if run_capture "$name" "$@"; then
return 0
fi
echo "expected success for ${name}" >&2
cat "${ARTIFACT_DIR}/${name}.stderr.txt" >&2 || true
return 1
}
run_expect_failure() {
local name="$1"
shift
if run_capture "$name" "$@"; then
echo "expected failure for ${name}" >&2
cat "${ARTIFACT_DIR}/${name}.stdout.txt" >&2 || true
return 1
fi
return 0
}
can_i() {
local name="$1"
local expected="$2"
shift 2
run_capture "can-i-${name}" "${KUBECTL}" auth can-i "$@" --as "${SA_USER}" -n "${NAMESPACE}" || true
local actual
actual="$(tr -d '\r\n' <"${ARTIFACT_DIR}/can-i-${name}.stdout.txt")"
write_summary "${name}=${actual}"
if [ "${actual}" != "${expected}" ]; then
echo "unexpected can-i ${name}: got ${actual}, expected ${expected}" >&2
return 1
fi
}
cleanup() {
set +e
"${KUBECTL}" delete clusterrolebinding sw-block-phase47-operator-status --ignore-not-found >/dev/null 2>&1
"${KUBECTL}" delete clusterrole sw-block-phase47-operator-status --ignore-not-found >/dev/null 2>&1
"${KUBECTL}" delete namespace "${NAMESPACE}" --ignore-not-found >/dev/null 2>&1
}
trap cleanup EXIT
write_summary "phase47_returned_replica_status_schema_rbac_status=running"
write_summary "harness=live_kubernetes_status_subresource_server_dry_run"
if ! run_capture kubectl-version "${KUBECTL}" version --client=true; then
write_summary "phase47_returned_replica_status_schema_rbac_status=blocked"
write_summary "blocked_reason=kubectl_unavailable"
exit 2
fi
if ! run_capture kubectl-api-versions "${KUBECTL}" api-versions; then
write_summary "phase47_returned_replica_status_schema_rbac_status=blocked"
write_summary "blocked_reason=kubernetes_api_unreachable"
exit 2
fi
run_expect_success apply-crd "${KUBECTL}" apply -f "${PRODUCT_ROOT}/charts/seaweed-block/crds/swblockvolumes.block.seaweedfs.com.yaml"
cat >"${ARTIFACT_DIR}/namespace.yaml" <<YAML
apiVersion: v1
kind: Namespace
metadata:
name: ${NAMESPACE}
labels:
block.seaweedfs.com/phase47-gate: "true"
YAML
run_expect_success apply-namespace "${KUBECTL}" apply -f "${ARTIFACT_DIR}/namespace.yaml"
cat >"${ARTIFACT_DIR}/rbac.yaml" <<YAML
apiVersion: v1
kind: ServiceAccount
metadata:
name: ${SA_NAME}
namespace: ${NAMESPACE}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: sw-block-phase47-operator-status
rules:
- apiGroups: ["block.seaweedfs.com"]
resources: ["swblockvolumes"]
verbs: ["get", "list", "watch"]
- apiGroups: ["block.seaweedfs.com"]
resources: ["swblockvolumes/status"]
verbs: ["get", "update", "patch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: sw-block-phase47-operator-status
subjects:
- kind: ServiceAccount
name: ${SA_NAME}
namespace: ${NAMESPACE}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: sw-block-phase47-operator-status
YAML
run_expect_success apply-rbac "${KUBECTL}" apply -f "${ARTIFACT_DIR}/rbac.yaml"
cat >"${ARTIFACT_DIR}/swblockvolume.yaml" <<YAML
apiVersion: block.seaweedfs.com/v1alpha1
kind: SwBlockVolume
metadata:
name: phase47-returned
namespace: ${NAMESPACE}
spec:
pvcName: phase47-returned
storageClass: seaweed-block
YAML
run_expect_success apply-volume "${KUBECTL}" apply -f "${ARTIFACT_DIR}/swblockvolume.yaml"
can_i "operator_status_patch_status_allowed" "yes" patch swblockvolumes --subresource=status
can_i "operator_status_update_status_allowed" "yes" update swblockvolumes --subresource=status
can_i "operator_status_create_events_allowed" "yes" create events
can_i "operator_status_main_patch_allowed" "no" patch swblockvolumes
can_i "operator_status_finalizers_patch_allowed" "no" patch swblockvolumes --subresource=finalizers
can_i "operator_status_pods_patch_allowed" "no" patch pods
can_i "operator_status_pvc_patch_allowed" "no" patch pvc
can_i "operator_status_storageclass_update_allowed" "no" update storageclasses
cat >"${ARTIFACT_DIR}/valid-status-patch.json" <<'JSON'
{
"status": {
"volumeID": "pvc-returned",
"pvcName": "phase47-returned",
"status": "recovering",
"reasonCode": "returned_replica_frontend_fenced",
"conditions": [
{
"type": "Ready",
"status": "Unknown",
"reason": "returned_replica_frontend_fenced",
"severity": "info",
"message": "returned replica is fenced pending reintegration evidence"
}
],
"replicaReintegrations": [
{
"replicaID": "r1",
"state": "fenced",
"reasonCode": "returned_replica_frontend_fenced",
"frontendFenced": true,
"frontendPrimaryReady": false,
"ackEligible": false,
"durableFrontierKnown": true,
"durableFrontierLsn": 52,
"requiredFrontierKnown": true,
"requiredFrontierLsn": 52,
"evidenceRefs": ["returned-replica-summary.txt"]
}
],
"allowedActions": [
{
"type": "authority.reintegrate_returned_replica",
"mode": "dry_run",
"sideEffectClass": "authority_mutating",
"ownerExecutor": "authority_recovery_executor",
"decision": "allowed",
"mutationAllowed": false,
"preconditions": ["returned_replica_frontend_fenced", "durable_frontier_evidence"],
"invariantRefs": ["INV-RETURNED-REPLICA-FENCING-001", "INV-RETURNED-REPLICA-FRONTIER-001"],
"evidenceRequired": "returned_replica_reintegration_evidence",
"evidenceRefs": ["returned-replica-summary.txt"]
}
],
"evidenceRefs": ["returned-replica-summary.txt"]
}
}
JSON
cat >"${ARTIFACT_DIR}/snake-status-patch.json" <<'JSON'
{
"status": {
"status": "recovering",
"allowedActions": [
{
"type": "authority.reintegrate_returned_replica",
"mode": "dry_run",
"mutation_allowed": false
}
]
}
}
JSON
cat >"${ARTIFACT_DIR}/bad-mode-status-patch.json" <<'JSON'
{
"status": {
"status": "recovering",
"allowedActions": [
{
"type": "authority.reintegrate_returned_replica",
"mode": "execute",
"mutationAllowed": false
}
]
}
}
JSON
run_expect_success valid-status-server-dry-run \
"${KUBECTL}" patch swblockvolume phase47-returned -n "${NAMESPACE}" \
--subresource=status --type=merge --patch-file "${ARTIFACT_DIR}/valid-status-patch.json" \
--dry-run=server -o yaml --as "${SA_USER}"
write_summary "valid_returned_replica_status_server_dry_run=true"
run_expect_failure snake-status-server-dry-run \
"${KUBECTL}" patch swblockvolume phase47-returned -n "${NAMESPACE}" \
--subresource=status --type=merge --patch-file "${ARTIFACT_DIR}/snake-status-patch.json" \
--dry-run=server -o yaml --as "${SA_USER}"
write_summary "snake_case_action_rejected=true"
run_expect_failure bad-mode-status-server-dry-run \
"${KUBECTL}" patch swblockvolume phase47-returned -n "${NAMESPACE}" \
--subresource=status --type=merge --patch-file "${ARTIFACT_DIR}/bad-mode-status-patch.json" \
--dry-run=server -o yaml --as "${SA_USER}"
write_summary "unsupported_action_mode_rejected=true"
run_expect_failure main-patch-denied \
"${KUBECTL}" patch swblockvolume phase47-returned -n "${NAMESPACE}" \
--type=merge -p '{"metadata":{"labels":{"bad":"true"}}}' \
--dry-run=server -o yaml --as "${SA_USER}"
write_summary "main_object_patch_rejected=true"
run_expect_success status-not-mutated "${KUBECTL}" get swblockvolume phase47-returned -n "${NAMESPACE}" -o jsonpath='{.status.status}'
status_value="$(cat "${ARTIFACT_DIR}/status-not-mutated.stdout.txt")"
if [ -n "${status_value}" ]; then
echo "server-side dry-run unexpectedly mutated status: ${status_value}" >&2
exit 1
fi
write_summary "server_dry_run_status_mutated=false"
write_summary "phase47_returned_replica_status_schema_rbac_status=ok"
@@ -0,0 +1,72 @@
# Runner-native Phase 47 D2 gate: live returned-replica status schema/RBAC.
name: returned-replica-status-schema-rbac-chain
timeout: 5m
env:
product_root: "/tmp/seaweed_block"
ssh_key: "C:\\work\\dev_server\\testdev_key"
topology:
nodes:
m02:
host: 192.168.1.184
user: testdev
key: "{{ ssh_key }}"
phases:
- name: status_schema_rbac_gate
actions:
- action: exec
node: m02
timeout: 4m
cmd: "rm -rf /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase47-status-schema-rbac && mkdir -p /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase47-status-schema-rbac && cd {{ product_root }} && SW_BLOCK_ARTIFACT_DIR=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase47-status-schema-rbac bash scripts/run-phase47-returned-replica-status-schema-rbac-gate.sh {{ product_root }}"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase47-status-schema-rbac/phase47-returned-replica-status-schema-rbac-summary.txt"
pattern: "^phase47_returned_replica_status_schema_rbac_status=ok$"
save_as: phase47_status_gate_ok
- action: assert_greater
actual: "{{ phase47_status_gate_ok }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase47-status-schema-rbac/phase47-returned-replica-status-schema-rbac-summary.txt"
pattern: "^valid_returned_replica_status_server_dry_run=true$"
save_as: phase47_valid_status_count
- action: assert_greater
actual: "{{ phase47_valid_status_count }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase47-status-schema-rbac/phase47-returned-replica-status-schema-rbac-summary.txt"
pattern: "^snake_case_action_rejected=true$"
save_as: phase47_snake_rejected_count
- action: assert_greater
actual: "{{ phase47_snake_rejected_count }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase47-status-schema-rbac/phase47-returned-replica-status-schema-rbac-summary.txt"
pattern: "^unsupported_action_mode_rejected=true$"
save_as: phase47_mode_rejected_count
- action: assert_greater
actual: "{{ phase47_mode_rejected_count }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase47-status-schema-rbac/phase47-returned-replica-status-schema-rbac-summary.txt"
pattern: "^operator_status_main_patch_allowed=no$"
save_as: phase47_main_patch_denied_count
- action: assert_greater
actual: "{{ phase47_main_patch_denied_count }}"
threshold: "0"
- name: collect
always: true
actions:
- action: collect_path
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase47-status-schema-rbac"
name: "remote-phases"
ignore_error: true