From 59e5a8d2210ad80b4be18f7b284dee7556eb3941 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 22 Jun 2026 11:42:32 -0700 Subject: [PATCH] phase54: gate authority executor policy --- .../templates/authority-executor.yaml | 5 + .../charts/seaweed-block/values.yaml | 11 +- seaweed-block/cmd/sw-block/main.go | 43 +++++-- seaweed-block/cmd/sw-block/main_test.go | 32 ++++- .../core/ops/authority_executor_controller.go | 43 +++++-- .../ops/authority_executor_controller_test.go | 45 +++++++ .../core/ops/kubernetes_crd_manifests_test.go | 9 ++ seaweed-block/internal/docs/current-plan.md | 25 ++++ ...ck-eligibility-mutation-target-contract.md | 115 ++++++++++++++++++ 9 files changed, 303 insertions(+), 25 deletions(-) create mode 100644 seaweed-block/internal/docs/ref/phase54-ack-eligibility-mutation-target-contract.md diff --git a/seaweed-block/charts/seaweed-block/templates/authority-executor.yaml b/seaweed-block/charts/seaweed-block/templates/authority-executor.yaml index 93639a50fd..546bf4fd99 100644 --- a/seaweed-block/charts/seaweed-block/templates/authority-executor.yaml +++ b/seaweed-block/charts/seaweed-block/templates/authority-executor.yaml @@ -32,5 +32,10 @@ spec: - "ops" - "authority-executor" - "--namespace={{ .Release.Namespace }}" + - "--allowed-mutation-class={{ .Values.authorityExecutor.execution.allowedMutationClass }}" + {{- if .Values.authorityExecutor.execution.enabled }} + - "--execution-policy" + - "--enable-execution" + {{- end }} - "--interval={{ .Values.authorityExecutor.interval }}" {{- end }} diff --git a/seaweed-block/charts/seaweed-block/values.yaml b/seaweed-block/charts/seaweed-block/values.yaml index 73153ed49c..59b1d03311 100644 --- a/seaweed-block/charts/seaweed-block/values.yaml +++ b/seaweed-block/charts/seaweed-block/values.yaml @@ -143,12 +143,15 @@ lifecycleOwner: nodeSelector: {} authorityExecutor: - # Phase 53 returned-replica authority executor skeleton. Disabled by default. - # It observes SwBlockVolume.status.executorContracts[] and keeps execution - # disabled; it has no status, finalizer, workload, storage, or Event mutation - # permissions. + # Returned-replica authority executor. Disabled by default. When created + # without execution enabled it only observes SwBlockVolume.status + # executorContracts[]; it has no status, finalizer, workload, storage, or + # Event mutation permissions. create: false interval: 30s + execution: + enabled: false + allowedMutationClass: ack_eligibility rbac: create: true nodeSelector: {} diff --git a/seaweed-block/cmd/sw-block/main.go b/seaweed-block/cmd/sw-block/main.go index 71ded4d341..776f971091 100644 --- a/seaweed-block/cmd/sw-block/main.go +++ b/seaweed-block/cmd/sw-block/main.go @@ -110,12 +110,16 @@ func runOpsAuthorityExecutor(args []string, stdout, stderr io.Writer) int { fs := flag.NewFlagSet("sw-block ops authority-executor", flag.ContinueOnError) fs.SetOutput(stderr) var ( - namespace string - enableExecution bool - interval time.Duration + namespace string + enableExecution bool + executionPolicyEnabled bool + allowedMutationClass string + interval time.Duration ) fs.StringVar(&namespace, "namespace", "default", "Kubernetes namespace containing SwBlockVolume objects") - fs.BoolVar(&enableExecution, "enable-execution", false, "enable returned-replica executor mutation; currently rejected") + fs.BoolVar(&enableExecution, "enable-execution", false, "request returned-replica executor mutation") + fs.BoolVar(&executionPolicyEnabled, "execution-policy", false, "allow authority executor to evaluate execution; still blocked until ACK mutation target exists") + fs.StringVar(&allowedMutationClass, "allowed-mutation-class", ops.AuthorityExecutorAllowedMutationAckEligibility, "only supported value is ack_eligibility") fs.DurationVar(&interval, "interval", 0, "repeat authority-executor reconciliation at this interval; 0 runs once") if err := fs.Parse(args); err != nil { return ops.VolumeStatusExitInvalid @@ -124,8 +128,16 @@ func runOpsAuthorityExecutor(args []string, stdout, stderr io.Writer) int { fmt.Fprintf(stderr, "sw-block ops authority-executor: unexpected args %s\n", strings.Join(fs.Args(), " ")) return ops.VolumeStatusExitInvalid } + if allowedMutationClass != ops.AuthorityExecutorAllowedMutationAckEligibility { + fmt.Fprintf(stderr, "sw-block ops authority-executor: unsupported mutation class %q reason=unsupported_mutation_class mutation_attempts=0 ack_eligibility_mutation_attempts=0\n", allowedMutationClass) + return ops.VolumeStatusExitInvalid + } + if enableExecution && !executionPolicyEnabled { + fmt.Fprintf(stderr, "sw-block ops authority-executor: returned-replica execution is disabled by product policy reason=%s mutation_attempts=0 ack_eligibility_mutation_attempts=0\n", ops.AuthorityExecutorBlockedPolicyDisabled) + return ops.VolumeStatusExitInvalid + } if enableExecution { - fmt.Fprintln(stderr, "sw-block ops authority-executor: returned-replica execution is disabled by product policy") + fmt.Fprintf(stderr, "sw-block ops authority-executor: ACK eligibility mutation target is not implemented reason=%s mutation_attempts=0 ack_eligibility_mutation_attempts=0\n", ops.AuthorityExecutorBlockedMutationTargetMissing) return ops.VolumeStatusExitInvalid } runOnce := func() int { @@ -135,20 +147,31 @@ func runOpsAuthorityExecutor(args []string, stdout, stderr io.Writer) int { return ops.VolumeStatusExitInvalid } result, err := (ops.AuthorityExecutorReconciler{ - Namespace: namespace, - Client: client, + Namespace: namespace, + Client: client, + ExecutionRequested: enableExecution, + ExecutionPolicyEnabled: executionPolicyEnabled, + AllowedMutationClass: allowedMutationClass, }).Reconcile(context.Background()) if err != nil { - fmt.Fprintf(stderr, "sw-block ops authority-executor: %v\n", err) + if result.BlockedReason != "" { + fmt.Fprintf(stderr, "sw-block ops authority-executor: %v reason=%s mutation_attempts=%d ack_eligibility_mutation_attempts=%d\n", + err, result.BlockedReason, result.MutationAttemptCount, result.AckEligibilityMutationAttempts) + } else { + fmt.Fprintf(stderr, "sw-block ops authority-executor: %v\n", err) + } return ops.VolumeStatusExitInvalid } - fmt.Fprintf(stdout, "authority_executor=disabled namespace=%s volumes=%d contracts=%d disabled_contracts=%d blocked_contracts=%d terminal_evidence_required=%d mutation_attempts=%d ack_eligibility_mutation_attempts=%d mutation_allowed=false\n", + fmt.Fprintf(stdout, "authority_executor=disabled namespace=%s volumes=%d contracts=%d disabled_contracts=%d blocked_contracts=%d terminal_evidence_required=%d allowed_mutation_class=%s execution_requested=%t execution_policy_enabled=%t mutation_attempts=%d ack_eligibility_mutation_attempts=%d mutation_allowed=false\n", namespace, result.VolumeCount, result.ContractCount, result.DisabledContractCount, result.BlockedContractCount, result.TerminalEvidenceRequiredCount, + allowedMutationClass, + enableExecution, + executionPolicyEnabled, result.MutationAttemptCount, result.AckEligibilityMutationAttempts) return ops.VolumeStatusExitOK @@ -1684,7 +1707,7 @@ func usage(w io.Writer) { fmt.Fprintln(w, " [--restart-persistence ephemeral|hostpath] [--state-hostpath /var/lib/sw-block] [--timeout 10s]") fmt.Fprintln(w, " sw-block ops operator-status --dry-run [--master-api |--from-bundle ] [--cleanup-summary ] [--interval 30s]") fmt.Fprintln(w, " sw-block ops lifecycle-owner [--dry-run] [--namespace ] [--interval 30s]") - fmt.Fprintln(w, " sw-block ops authority-executor [--namespace ] [--interval 30s]") + fmt.Fprintln(w, " sw-block ops authority-executor [--namespace ] [--allowed-mutation-class ack_eligibility] [--interval 30s]") } func emptyCLI(value string) string { diff --git a/seaweed-block/cmd/sw-block/main_test.go b/seaweed-block/cmd/sw-block/main_test.go index db995ce048..592a96e392 100644 --- a/seaweed-block/cmd/sw-block/main_test.go +++ b/seaweed-block/cmd/sw-block/main_test.go @@ -525,6 +525,9 @@ func TestOpsAuthorityExecutorObservesDisabledContractsWithoutMutation(t *testing "authority_executor=disabled namespace=kube-system volumes=1 contracts=1", "disabled_contracts=1", "terminal_evidence_required=1", + "allowed_mutation_class=ack_eligibility", + "execution_requested=false", + "execution_policy_enabled=false", "mutation_attempts=0", "ack_eligibility_mutation_attempts=0", "mutation_allowed=false", @@ -541,7 +544,34 @@ func TestOpsAuthorityExecutorRejectsExecutionFlag(t *testing.T) { if code != ops.VolumeStatusExitInvalid { t.Fatalf("exit=%d stderr=%s stdout=%s", code, stderr.String(), stdout.String()) } - if !strings.Contains(stderr.String(), "execution is disabled by product policy") { + if !strings.Contains(stderr.String(), "reason=executor_policy_disabled") || + !strings.Contains(stderr.String(), "mutation_attempts=0") || + !strings.Contains(stderr.String(), "ack_eligibility_mutation_attempts=0") { + t.Fatalf("stderr=%s", stderr.String()) + } +} + +func TestOpsAuthorityExecutorRejectsUnsupportedMutationClass(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"ops", "authority-executor", "--allowed-mutation-class", "rebuild_traffic"}, &stdout, &stderr) + if code != ops.VolumeStatusExitInvalid { + t.Fatalf("exit=%d stderr=%s stdout=%s", code, stderr.String(), stdout.String()) + } + if !strings.Contains(stderr.String(), "unsupported mutation class") || + !strings.Contains(stderr.String(), "reason=unsupported_mutation_class") { + t.Fatalf("stderr=%s", stderr.String()) + } +} + +func TestOpsAuthorityExecutorExecutionPolicyBlocksWhenAckTargetMissing(t *testing.T) { + var stdout, stderr bytes.Buffer + code := run([]string{"ops", "authority-executor", "--enable-execution", "--execution-policy"}, &stdout, &stderr) + if code != ops.VolumeStatusExitInvalid { + t.Fatalf("exit=%d stderr=%s stdout=%s", code, stderr.String(), stdout.String()) + } + if !strings.Contains(stderr.String(), "reason=ack_eligibility_mutation_target_missing") || + !strings.Contains(stderr.String(), "mutation_attempts=0") || + !strings.Contains(stderr.String(), "ack_eligibility_mutation_attempts=0") { t.Fatalf("stderr=%s", stderr.String()) } } diff --git a/seaweed-block/core/ops/authority_executor_controller.go b/seaweed-block/core/ops/authority_executor_controller.go index 950c474a77..d8405dff4b 100644 --- a/seaweed-block/core/ops/authority_executor_controller.go +++ b/seaweed-block/core/ops/authority_executor_controller.go @@ -5,27 +5,50 @@ import ( "fmt" ) +const ( + AuthorityExecutorAllowedMutationAckEligibility = "ack_eligibility" + AuthorityExecutorBlockedPolicyDisabled = "executor_policy_disabled" + AuthorityExecutorBlockedMutationTargetMissing = "ack_eligibility_mutation_target_missing" +) + type AuthorityExecutorClient interface { ListSwBlockVolumes(ctx context.Context, namespace string) ([]SwBlockVolumeObject, error) } type AuthorityExecutorReconciler struct { - Namespace string - Client AuthorityExecutorClient + Namespace string + Client AuthorityExecutorClient + ExecutionRequested bool + ExecutionPolicyEnabled bool + AllowedMutationClass string } type AuthorityExecutorReconcileResult struct { - VolumeCount int `json:"volumeCount"` - ContractCount int `json:"contractCount"` - DisabledContractCount int `json:"disabledContractCount"` - BlockedContractCount int `json:"blockedContractCount"` - TerminalEvidenceRequiredCount int `json:"terminalEvidenceRequiredCount"` - UnsafeExecutionContractCount int `json:"unsafeExecutionContractCount"` - MutationAttemptCount int `json:"mutationAttemptCount"` - AckEligibilityMutationAttempts int `json:"ackEligibilityMutationAttempts"` + VolumeCount int `json:"volumeCount"` + ContractCount int `json:"contractCount"` + DisabledContractCount int `json:"disabledContractCount"` + BlockedContractCount int `json:"blockedContractCount"` + TerminalEvidenceRequiredCount int `json:"terminalEvidenceRequiredCount"` + UnsafeExecutionContractCount int `json:"unsafeExecutionContractCount"` + MutationAttemptCount int `json:"mutationAttemptCount"` + AckEligibilityMutationAttempts int `json:"ackEligibilityMutationAttempts"` + BlockedReason string `json:"blockedReason,omitempty"` } func (r AuthorityExecutorReconciler) Reconcile(ctx context.Context) (AuthorityExecutorReconcileResult, error) { + allowedMutationClass := defaultString(r.AllowedMutationClass, AuthorityExecutorAllowedMutationAckEligibility) + if allowedMutationClass != AuthorityExecutorAllowedMutationAckEligibility { + result := AuthorityExecutorReconcileResult{BlockedReason: "unsupported_mutation_class"} + return result, fmt.Errorf("authority executor unsupported mutation class %q", allowedMutationClass) + } + if r.ExecutionRequested && !r.ExecutionPolicyEnabled { + result := AuthorityExecutorReconcileResult{BlockedReason: AuthorityExecutorBlockedPolicyDisabled} + return result, fmt.Errorf("authority executor execution is disabled by product policy") + } + if r.ExecutionRequested { + result := AuthorityExecutorReconcileResult{BlockedReason: AuthorityExecutorBlockedMutationTargetMissing} + return result, fmt.Errorf("authority executor ACK eligibility mutation target is not implemented") + } if r.Client == nil { return AuthorityExecutorReconcileResult{}, fmt.Errorf("authority executor client is required") } diff --git a/seaweed-block/core/ops/authority_executor_controller_test.go b/seaweed-block/core/ops/authority_executor_controller_test.go index 634bfd8b94..3383adf46d 100644 --- a/seaweed-block/core/ops/authority_executor_controller_test.go +++ b/seaweed-block/core/ops/authority_executor_controller_test.go @@ -64,6 +64,51 @@ func TestAuthorityExecutorReconcilerFailsClosedOnExecutionEnabledContract(t *tes } } +func TestAuthorityExecutorReconcilerRejectsUnsupportedMutationClass(t *testing.T) { + result, err := (AuthorityExecutorReconciler{ + Client: fakeAuthorityExecutorClient{}, + AllowedMutationClass: "rebuild_traffic", + }).Reconcile(context.Background()) + if err == nil { + t.Fatalf("expected unsupported mutation class to fail closed, result=%+v", result) + } + if result.BlockedReason != "unsupported_mutation_class" || result.MutationAttemptCount != 0 { + t.Fatalf("result=%+v", result) + } +} + +func TestAuthorityExecutorReconcilerRejectsExecutionWhenPolicyDisabled(t *testing.T) { + result, err := (AuthorityExecutorReconciler{ + Client: fakeAuthorityExecutorClient{}, + ExecutionRequested: true, + }).Reconcile(context.Background()) + if err == nil { + t.Fatalf("expected disabled policy to fail closed, result=%+v", result) + } + if result.BlockedReason != AuthorityExecutorBlockedPolicyDisabled || + result.MutationAttemptCount != 0 || + result.AckEligibilityMutationAttempts != 0 { + t.Fatalf("result=%+v", result) + } +} + +func TestAuthorityExecutorReconcilerBlocksExecutionWhenAckTargetMissing(t *testing.T) { + result, err := (AuthorityExecutorReconciler{ + Client: fakeAuthorityExecutorClient{}, + ExecutionRequested: true, + ExecutionPolicyEnabled: true, + AllowedMutationClass: AuthorityExecutorAllowedMutationAckEligibility, + }).Reconcile(context.Background()) + if err == nil { + t.Fatalf("expected missing ACK target to fail closed, result=%+v", result) + } + if result.BlockedReason != AuthorityExecutorBlockedMutationTargetMissing || + result.MutationAttemptCount != 0 || + result.AckEligibilityMutationAttempts != 0 { + t.Fatalf("result=%+v", result) + } +} + type fakeAuthorityExecutorClient struct { volumes []SwBlockVolumeObject } diff --git a/seaweed-block/core/ops/kubernetes_crd_manifests_test.go b/seaweed-block/core/ops/kubernetes_crd_manifests_test.go index e663aabec5..146d3f32cb 100644 --- a/seaweed-block/core/ops/kubernetes_crd_manifests_test.go +++ b/seaweed-block/core/ops/kubernetes_crd_manifests_test.go @@ -340,6 +340,11 @@ func TestPhase53AuthorityExecutorPackagingIsDisabledAndReadOnly(t *testing.T) { values := readYAMLMap(t, "charts/seaweed-block/values.yaml") authorityExecutor := yamlMap(t, values, "authorityExecutor") assertYAMLBool(t, authorityExecutor, "create", false) + executionValues := yamlMap(t, authorityExecutor, "execution") + assertYAMLBool(t, executionValues, "enabled", false) + if got := executionValues["allowedMutationClass"]; got != "ack_eligibility" { + t.Fatalf("authorityExecutor.execution.allowedMutationClass=%v", got) + } rbacValues := yamlMap(t, authorityExecutor, "rbac") assertYAMLBool(t, rbacValues, "create", true) @@ -351,6 +356,10 @@ func TestPhase53AuthorityExecutorPackagingIsDisabledAndReadOnly(t *testing.T) { `command: ["/usr/local/bin/sw-block"]`, `- "authority-executor"`, `- "--namespace={{ .Release.Namespace }}"`, + `- "--allowed-mutation-class={{ .Values.authorityExecutor.execution.allowedMutationClass }}"`, + `{{- if .Values.authorityExecutor.execution.enabled }}`, + `- "--execution-policy"`, + `- "--enable-execution"`, `- "--interval={{ .Values.authorityExecutor.interval }}"`, } { if !strings.Contains(deploy, want) { diff --git a/seaweed-block/internal/docs/current-plan.md b/seaweed-block/internal/docs/current-plan.md index d44567ef23..513c1c33a2 100644 --- a/seaweed-block/internal/docs/current-plan.md +++ b/seaweed-block/internal/docs/current-plan.md @@ -67,6 +67,9 @@ Out of scope: ### D1: Executor Policy and Command Gate +Status: implemented on branch. The command and Helm chart now expose the policy +gate while keeping execution disabled by default. + Add explicit command-line and Helm policy: ```text @@ -83,8 +86,20 @@ Acceptance: - unsupported mutation classes fail closed, - no RBAC expansion yet. +Current behavior: + +```text +--allowed-mutation-class accepts only ack_eligibility +--enable-execution without --execution-policy -> executor_policy_disabled +--enable-execution with --execution-policy -> ack_eligibility_mutation_target_missing +mutation_attempts remains 0 on every blocked path +``` + ### D2: Mutation Target Contract +Status: design blocker documented in +`internal/docs/ref/phase54-ack-eligibility-mutation-target-contract.md`. + Define the exact target the executor is allowed to mutate. Preferred target shape: @@ -108,6 +123,16 @@ Acceptance: - user-visible status can show who wrote it and when, - old-primary/frontend publication remains impossible from this path. +Current conclusion: + +```text +No durable narrow ACK eligibility mutation target exists yet. +SwBlockVolume status is a projection surface owned by operator-status and must +not be used as fake executor state. +``` + +Phase 54 must not proceed to D3-D7 mutation gates until the target is chosen. + ### D3: Admission/RBAC Boundary Add real Kubernetes proof for the chosen mutation target. diff --git a/seaweed-block/internal/docs/ref/phase54-ack-eligibility-mutation-target-contract.md b/seaweed-block/internal/docs/ref/phase54-ack-eligibility-mutation-target-contract.md new file mode 100644 index 0000000000..0ca9a48f5b --- /dev/null +++ b/seaweed-block/internal/docs/ref/phase54-ack-eligibility-mutation-target-contract.md @@ -0,0 +1,115 @@ +# Phase 54 ACK Eligibility Mutation Target Contract + +Status: design blocker documented. + +## Problem + +Phase 54's first intended executor mutation is deliberately narrow: + +```text +set returned replica ACK eligibility only +``` + +That mutation must not publish a frontend, start rebuild traffic, change +primary authority, perform failback, or affect another volume. + +The current codebase does not yet expose a durable, narrow ACK eligibility +mutation target for the authority executor. Existing fields such as +`ack_eligibility_known` and `ack_eligible` are projected observation/status +facts. Writing those fields directly from the executor would make status look +like product state without changing any authority-owned eligibility decision. + +## Required Target Properties + +A valid ACK eligibility target must satisfy all of these: + +- It is durable enough to survive controller restart. +- It is scoped to one volume and one replica. +- It records the executor identity and observed evidence generation. +- It is not the same broad status object owned by `operator-status`. +- It cannot publish frontend paths or change primary authority. +- It gives `operator-status` a read path to project terminal evidence: + `ack_eligibility_known=true`, `ack_eligible=true`, + `frontend_fenced_after_execution=true`, `primary_unchanged=true`, + `durable_frontier_covered=true`, and + `no_cross_volume_identity_change=true`. + +## Candidate Targets + +### Separate evidence CR + +Example shape: + +```text +SwBlockReplicaEligibility + spec.volumeRef + spec.replicaID + status.ackEligible + status.executor + status.evidenceGeneration + status.conditions +``` + +Pros: + +- Narrow RBAC and admission boundary. +- Clear owner: authority executor writes this object only. +- `operator-status` remains the owner of broad `SwBlockVolume.status`. + +Cons: + +- New CRD and lifecycle rules. +- Requires garbage-collection policy tied to SwBlockVolume/PVC lifecycle. + +### Authority-store state + +Pros: + +- Close to the authority model that will eventually consume eligibility. +- Avoids using Kubernetes status as command state. + +Cons: + +- Needs an audited write API and persistence contract. +- Harder to prove with Kubernetes RBAC/admission alone. + +### SwBlockVolume broad status + +Not recommended. + +Pros: + +- Minimal new objects. + +Cons: + +- Conflicts with `operator-status` ownership. +- Broad status patch access is too large for the authority executor. +- Risks a semantic loop where the executor writes the same surface the report + uses as proof. + +## Current Phase 54 Behavior + +Until a valid target exists, the executor must fail closed: + +```text +--enable-execution without policy -> executor_policy_disabled +--enable-execution with policy -> ack_eligibility_mutation_target_missing +unsupported mutation class -> unsupported_mutation_class +``` + +All failure paths must keep: + +```text +mutation_attempts=0 +ack_eligibility_mutation_attempts=0 +mutation_allowed=false +``` + +## Recommendation + +Prefer a separate, narrow eligibility evidence CR unless the authority-store +owner provides a concrete persisted ACK eligibility API first. + +Do not implement Phase 54 D3-D7 execution gates until D2 chooses one target and +defines its RBAC/admission boundary.