mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
phase38: add rejected action evidence gate
This commit is contained in:
1 parent
ec3cb84076
commit
87826c2f73
3 files changed
+118
-9
No files matched your search
@@ -157,3 +157,31 @@ func (e ManagedVolumeActionEvaluation) String() string {
|
||||
}
|
||||
return fmt.Sprintf("%s %s reason=%s missing=%s", e.ActionType, e.Decision, e.Reason, strings.Join(e.MissingFacts, ","))
|
||||
}
|
||||
|
||||
func RenderManagedVolumeActionEvaluationText(e ManagedVolumeActionEvaluation) string {
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "managed_volume_action_evaluation %s decision=%s", emptyAsDash(e.ActionType), emptyAsDash(e.Decision))
|
||||
if e.Mode != "" {
|
||||
fmt.Fprintf(&b, " mode=%s", e.Mode)
|
||||
}
|
||||
if e.SideEffectClass != "" {
|
||||
fmt.Fprintf(&b, " side_effect=%s", e.SideEffectClass)
|
||||
}
|
||||
if e.OwnerExecutor != "" {
|
||||
fmt.Fprintf(&b, " executor=%s", e.OwnerExecutor)
|
||||
}
|
||||
if e.Reason != "" {
|
||||
fmt.Fprintf(&b, " reason=%s", e.Reason)
|
||||
}
|
||||
fmt.Fprintf(&b, " mutation_allowed=%t\n", e.MutationAllowed)
|
||||
if len(e.MissingFacts) > 0 {
|
||||
fmt.Fprintf(&b, "managed_volume_action_evaluation_missing_facts %s %s\n", emptyAsDash(e.ActionType), strings.Join(e.MissingFacts, ","))
|
||||
}
|
||||
if len(e.InvariantRefs) > 0 {
|
||||
fmt.Fprintf(&b, "managed_volume_action_evaluation_invariants %s %s\n", emptyAsDash(e.ActionType), strings.Join(e.InvariantRefs, ","))
|
||||
}
|
||||
if e.EvidenceRequired != "" {
|
||||
fmt.Fprintf(&b, "managed_volume_action_evaluation_evidence_required %s %s\n", emptyAsDash(e.ActionType), e.EvidenceRequired)
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package ops
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEvaluateManagedVolumeAction_AllowsDryRunWhenFactsPresent(t *testing.T) {
|
||||
evaluation := EvaluateManagedVolumeAction(ManagedVolumeActionReinstallExternalISCSI, ManagedVolumeFacts{
|
||||
@@ -84,3 +87,76 @@ func TestEvaluateManagedVolumeAction_RejectsUnknownAction(t *testing.T) {
|
||||
t.Fatalf("reason=%s want %s", evaluation.Reason, ManagedVolumeActionRejectUnknownAction)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagedVolumeActionEvaluator_CoversEveryContractEntry(t *testing.T) {
|
||||
for _, entry := range ManagedVolumeActionContract() {
|
||||
evaluation := EvaluateManagedVolumeAction(entry.Type, factsSatisfyingActionContract(entry))
|
||||
if entry.PolicyGate == ActionPolicyDisabled {
|
||||
if evaluation.Decision != ManagedVolumeActionDecisionRejected || evaluation.Reason != ManagedVolumeActionRejectDisabled {
|
||||
t.Fatalf("disabled action %s evaluation=%+v", entry.Type, evaluation)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if evaluation.Decision != ManagedVolumeActionDecisionAllowed {
|
||||
t.Fatalf("action %s should be evaluable with satisfying facts: %+v", entry.Type, evaluation)
|
||||
}
|
||||
if evaluation.Mode != entry.Mode || evaluation.SideEffectClass != entry.SideEffectClass || evaluation.OwnerExecutor != entry.OwnerExecutor {
|
||||
t.Fatalf("action %s evaluation boundary=%+v contract=%+v", entry.Type, evaluation, entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderManagedVolumeActionEvaluationText_ShowsRejectedAction(t *testing.T) {
|
||||
text := RenderManagedVolumeActionEvaluationText(EvaluateManagedVolumeAction(ManagedVolumeActionRequestPromotion, ManagedVolumeFacts{
|
||||
Authority: &AuthorityFact{PrimaryReplica: "r1"},
|
||||
Replicas: []ReplicaFact{{
|
||||
ReplicaID: "r2",
|
||||
DurableFrontierKnown: true,
|
||||
DurableFrontierLSN: 42,
|
||||
}},
|
||||
}))
|
||||
|
||||
for _, want := range []string{
|
||||
"managed_volume_action_evaluation authority.request_promotion decision=rejected",
|
||||
"side_effect=authority_mutating",
|
||||
"executor=authority_recovery_executor",
|
||||
"reason=policy_disabled",
|
||||
"mutation_allowed=false",
|
||||
"managed_volume_action_evaluation_evidence_required authority.request_promotion promotion_readiness_evidence",
|
||||
} {
|
||||
if !strings.Contains(text, want) {
|
||||
t.Fatalf("rendered evaluation missing %q:\n%s", want, text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func factsSatisfyingActionContract(entry ManagedVolumeActionContractEntry) ManagedVolumeFacts {
|
||||
facts := ManagedVolumeFacts{
|
||||
VolumeID: "pvc-action",
|
||||
PVCName: "demo-pvc",
|
||||
ProductReason: ReasonPublishTargetLoopbackCrossNode,
|
||||
EvidenceRefs: []string{"action-evidence.txt"},
|
||||
PVC: &PVCFact{Phase: "Bound"},
|
||||
Authority: &AuthorityFact{
|
||||
PrimaryReplica: "r1",
|
||||
PublishTarget: "127.0.0.1:3260",
|
||||
},
|
||||
Replicas: []ReplicaFact{{
|
||||
ReplicaID: "r1",
|
||||
ServerID: "m02",
|
||||
KubernetesNode: "m02",
|
||||
DurableFrontierKnown: true,
|
||||
DurableFrontierLSN: 42,
|
||||
}},
|
||||
CSIStages: []CSIStageFact{{
|
||||
NodeName: "m01",
|
||||
Target: "127.0.0.1:3260",
|
||||
}},
|
||||
HostPaths: []HostPathFact{{
|
||||
Protocol: "iscsi",
|
||||
ALUAState: "0x00",
|
||||
StaleFenced: true,
|
||||
}},
|
||||
}
|
||||
return facts
|
||||
}
|
||||
@@ -122,15 +122,15 @@ server-side dry-run or live CRD status patch check
|
||||
Goal: prove unsafe or underspecified actions fail closed before any executor can
|
||||
run.
|
||||
|
||||
Status: pending.
|
||||
Status: dev-complete; QA/internal review pending.
|
||||
|
||||
Acceptance:
|
||||
|
||||
```text
|
||||
[ ] authority.request_promotion is rejected under current policy
|
||||
[ ] action with missing required facts is rejected with a stable reason
|
||||
[ ] rejected action is visible as not executable, not silently omitted
|
||||
[ ] Kubernetes RBAC remains status/events/read-only only
|
||||
[x] authority.request_promotion is rejected under current policy
|
||||
[x] action with missing required facts is rejected with a stable reason
|
||||
[x] rejected action is visible as not executable, not silently omitted
|
||||
[x] Kubernetes RBAC remains status/events/read-only only
|
||||
```
|
||||
|
||||
Verification:
|
||||
@@ -207,9 +207,14 @@ QA strict rerun or replay from clean bundle
|
||||
SwBlockVolume CRD status. The CRD schema and status DTO use camelCase fields
|
||||
(`decisionReason`, `missingFacts`, `evidenceRequired`) to avoid live schema
|
||||
rejection.
|
||||
- 60%: D4 dev-complete. The action evaluator now has a rejected-action evidence
|
||||
renderer. Unit gates prove every action contract is covered by the evaluator,
|
||||
`authority.request_promotion` stays rejected with `policy_disabled`, and the
|
||||
rendered evidence names side-effect class, executor, evidence requirement,
|
||||
and `mutation_allowed=false`.
|
||||
|
||||
## Next Step
|
||||
|
||||
Add D4 rejected-action evidence: surface a deliberately rejected
|
||||
`authority.request_promotion` decision in a replay/unit gate, prove it remains
|
||||
non-executable, and confirm the operator RBAC boundary stays status/events only.
|
||||
Add D5 dry-run action evidence for `safe_k8s.reinstall_external_iscsi`: replay a
|
||||
cross-node loopback bundle, prove the action evaluates `allowed` in dry-run
|
||||
mode, and confirm no Kubernetes/storage mutation is performed or allowed.
|
||||
Reference in new issue
Block a user