Skip to content

fix(server): make CLI slice flags override environment - #2626

Open
paul-nicolas wants to merge 1 commit into
mainfrom
codex/EN-3396-slice-flag-precedence
Open

paul-nicolas wants to merge 1 commit into
mainfrom
codex/EN-3396-slice-flag-precedence

Conversation

@paul-nicolas

Copy link
Copy Markdown
Contributor

What changed

  • Make explicit CLI slice flags replace environment slices when Ledger starts through service.Execute.
  • Preserve repeated CLI slice flags as append operations, and document the precedence rule.
  • Add a subprocess regression for auth issuers, both Raft queue slices, and a scalar control.

Why

An explicit --auth-issuers currently retains issuers supplied only by AUTH_ISSUERS; valid three-entry CLI Raft queues are appended to three-entry environment queues and rejected at startup. Ticket.

Product / operational motivation

Need: operators can narrow trusted issuers and override Raft queue configuration explicitly. Current limitation: early environment binding makes pflag append the first CLI slice. Requirement: explicit CLI slice values take precedence over environment values, while repeated CLI occurrences append. Evidence: the ticket, docs/ops/deployment.md, and the subprocess regression. Durable repository evidence: docs/ops/deployment.md and the configuration startup audit contract.

Technical decision

Decision: wrap slice flag values only on the production service.Execute command, replacing an environment-sourced first value when Cobra sets the first CLI occurrence. Why proportionate: it preserves the pinned go-libs binder and pflag behavior, including repeated CLI values. Alternatives: changing go-libs would require a separate dependency release; leaving current behavior violates the documented precedence and can trust unwanted issuers.

Risk

LOW — startup configuration only; no persisted state, Raft apply, or API wire change.

Validation

  • bash scripts/agent-check
  • nix develop --command bash scripts/agent-just pre-commit
  • Focused go test -race ./cmd/server for the subprocess regression and adjacent environment tests
  • Focused go test ./internal/bootstrap issuer tests
  • Full CI and Docker suites: deferred to PR CI

Architecture / behavior impact

Server startup configuration precedence is now consistent for scalar and slice flags. No persisted-state, FSM, Raft protocol, or API wire change.

Review focus

Check NewServiceRootCommand and the first CLI occurrence behavior against the pinned go-libs binder and pflag slice semantics.

Known concerns

None.

@NumaryBot NumaryBot added risk: medium NumaryBot classified this pull request as medium risk. bot-reviewed NumaryBot completed its review workflow for the current head. draft-reviewed NumaryBot reviewed this draft, but published no readiness signal. labels Nov 23, 2026

@shipfox-ai shipfox-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipfox review

No issues found across 6 files. This pull request looks good to go.

The change wraps slice flag values on the production service.Execute command so a first CLI occurrence can replace environment-bound values, then switches main to use that command. The replacement detection is text-based and fails for string-slice environment values containing whitespace.

Reviewed 082cc6c89a009044d878e52b80fb6a0edd3add52...d24fef4f1339c3afa0773be393fa8da314662e03.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@paul-nicolas
paul-nicolas marked this pull request as ready for review November 24, 2026 08:17
@strix-security

strix-security Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: Wraps slice flags on the ledger server root command so an explicit CLI value (such as --auth-issuers or the Raft transport queue flags) replaces an environment-provided slice instead of being appended to it, adds a subprocess regression test, and documents the precedence rule.

Review summary

Reviewed the new installSlicePrecedence wrapper in cmd/server/server.go, its switch into production startup from main.go, and the added subprocess regression, tracing how environment binding done by service.Execute interacts with the wrapper's env-origin detection. No security vulnerabilities were confirmed: the effective trusted-issuer set can only be narrowed, never widened, by the new code; every input to the changed logic is process environment or argv, which the deploying operator already controls; and no trust boundary is crossed.

Ruled out (4)
  • Can an environment-supplied issuer slice survive an explicit CLI slice, or can the wrapper leave a security-relevant slice flag (root flags, persistent flags,…
    The only slice flags in the command tree are stringSlice/intSlice flags on the single run subcommand, the root registers no flags or persistent flags, and the wrapper can only replace entries, so any gap fails closed rather than widening trust.
  • Does an explicit --auth-issuers still merge an environment-supplied singular AUTH_ISSUER into the trusted issuer set, defeating issuer narrowing?
    The singular and plural issuer flags are distinct flags whose documented semantics are a union, the PR's rule is per-flag for slices, and anyone able to set AUTH_ISSUER already controls the same process configuration as whoever writes the command line, so no trust boundary is crossed.
  • Can the env-equality heuristic misclassify a CLI value and drop a configured issuer?
    A first CLI value that happens to equal the environment value makes a later occurrence replace instead of append, which only removes issuers from the trusted set (fail-closed availability edge case) and has no attacker-controlled input.
  • Does the new startup configuration change let a value override the --join seed address or cluster secret and redirect which peers this node trusts?
    Only stringSlice/intSlice flags gained the replace-on-first-CLI-occurrence behavior, so --join, --cluster-secret and the TLS mode keep their existing precedence and the peer-discovery path is unchanged by this PR.

Review 1 on this PR · d24fef4 · requested Nov 24 08:17 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@NumaryBot NumaryBot added review-approved The DINESH review gate is satisfied for the current head. and removed draft-reviewed NumaryBot reviewed this draft, but published no readiness signal. labels Nov 24, 2026

@NumaryBot NumaryBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The required automated review completed with no remaining findings.

@gfyrag gfyrag left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paul-nicolas, please move this slice flag precedence fix into go-libs' service.Execute environment binder. The shared binder calls FlagSet.Set before Cobra parses CLI arguments, so pflag appends CLI slice values to values already supplied by the environment. The wrapper in cmd/server/server.go handles only Ledger's stringSlice and intSlice flags and duplicates the binder's environment-name and normalization rules. Please fix the precedence at the source in go-libs, cover environment-only, first CLI override, and repeated CLI occurrences there, then update Ledger to that release and remove the local wrapper. This will make the same precedence rule apply consistently to other services and slice types.

@NumaryBot NumaryBot added human-reviewed A human submitted a decisive review for the current head. and removed review-approved The DINESH review gate is satisfied for the current head. labels Nov 24, 2026

@flemzord flemzord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed d24fef4f1339c3afa0773be393fa8da314662e03 against the pinned go-libs/v5 v5.10.0 binder. The wrapper matches its environment-name and string-slice normalization rules, and nix develop --command go test -race ./cmd/server -run '^TestSliceFlagPrecedenceThroughServiceExecute$' -count=1 passed on this head.

Approval remains withheld while the existing maintainer request to implement precedence in the shared service.Execute binder is outstanding. No additional confirmed correctness finding or duplicate inline comment.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-reviewed NumaryBot completed its review workflow for the current head. human-reviewed A human submitted a decisive review for the current head. risk: medium NumaryBot classified this pull request as medium risk.

Development

Successfully merging this pull request may close these issues.

5 participants