Skip to content

fix(command): validate listener config before committing it to main-process state (#1301) - #1302

Merged
FlorentinDUBOIS merged 3 commits into
mainfrom
fix/listener-validate-before-commit
Jul 27, 2026
Merged

FlorentinDUBOIS merged 3 commits into
mainfrom
fix/listener-validate-before-commit

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1301. An HTTPS listener whose configuration the worker cannot build (an unusable TLS version/cipher set, or an unparseable answer template) was recorded in the main process's ConfigState before the worker rejected it, reserving the address. A corrected reload was then refused with StateError::Exists and never reached the workers, so the listener stayed down until an explicit RemoveListener or a process restart — an operational trap where the natural fix-and-reload loop silently does nothing.

Approach

Two commits, following the control-plane / data-plane static-stability principle (the control plane must not record what the data plane rejected):

Part 1 — validate before commit (the fix). The main process now validates every Add{Http,Https,Tcp,Udp}Listener the way the worker builds it, reusing the worker's own construction check (HttpsListener/HttpListener::validate_config, factored out of try_new via a shared build_answers helper so master and worker cannot drift — same binary, same crypto provider), before ConfigState is mutated and fanned out. An invalid listener therefore never reserves its address and a corrected reload applies cleanly. Wired into all three master apply paths (worker_request, load_static_config, load_state); invalid listeners in the static config or a loaded state file are skipped without reserving their address (fail-open: one bad listener does not stop the others). This extends an idiom already in worker_request (the SetMetricDetail master-side pre-validation). StateError::Exists now also points at the remedy.

Part 2 — rollback safety-net (defense-in-depth). Even after validation, a committed change can be rejected worker-side. When every worker rejects it (unanimous, no timeout), the main process reverts its own ConfigState with the inverse request, so its authoritative state (replayed into restarted / upgraded workers) never permanently holds an add the whole fleet refused. Covers the non-upsert Add verbs with unambiguous inverses (listeners → RemoveListener; HTTP/HTTPS frontends → the same payload under the Remove variant); upsert verbs (AddCluster / AddBackend) and certificates are deliberately uncovered (they would need prior-value capture, kept best-effort as today). A mixed result is left as-is to avoid diverging the master from workers that accepted.

Security / protocol impact

Confined to the control-plane command-apply path (bin/src/command/, command/src/state.rs) and listener construction (lib/src/{http,https,tcp,udp}.rs). It makes the main process's authoritative ConfigState consistent with what workers actually accepted. Conservative, additive validation; no behavior change on the accepted path, no traffic-path change.

Tests

  • Master-level regression tests (bin/src/command/requests.rs): invalid listener rejected before commit, corrected reload succeeds, and compute_rollback inverse correctness. Proven red (neutering the guard fails the assertions), then green.
  • #[ignore]d e2e smoke test driving a real master over its command socket: confirms a corrected listener https add succeeds after an invalid one at the same address.

Commands run

  • cargo build --all-features --locked — ok
  • cargo +nightly fmt --all -- --check — ok
  • cargo clippy --all-targets --locked -- -D warnings — ok
  • cargo test -p sozu -p sozu-lib -p sozu-command-lib --locked — ok (771 lib + bin + command)
  • cargo test -p sozu --test listener_validate_before_commit_e2e -- --ignored — ok

Docs

Closes #1301

…ess state

An HTTPS listener whose configuration the worker cannot build (an unusable TLS
version/cipher set, or an unparseable answer template) was recorded in the main
process's ConfigState before the worker rejected it, reserving the address. A
corrected reload was then refused with StateError::Exists and never reached the
workers, so the listener stayed down until an explicit RemoveListener or a
restart.

The main process now validates every Add{Http,Https,Tcp,Udp}Listener the way the
worker builds it, reusing the worker's own construction check
(HttpsListener/HttpListener::validate_config, factored out of try_new via a
shared build_answers helper so the two cannot drift), before ConfigState is
mutated and fanned out. An invalid listener therefore never reserves its address
and a corrected reload applies cleanly. The guard is wired into all three master
apply paths (worker_request, load_static_config, load_state); invalid listeners
in the static config or a loaded state file are skipped without reserving their
address (fail-open: one bad listener does not stop the others).

StateError::Exists now points at the remedy (remove it first, or apply the
corresponding update, instead of re-adding).

Tests: master-level regression tests in bin/src/command/requests.rs (proven red
by neutering the guard, then green) plus an #[ignore]d e2e smoke test that drives
a real master over its command socket and confirms a corrected `listener https
add` succeeds after an invalid one at the same address.

Closes #1301

Signed-off-by: Florentin Dubois <[email protected]>
…hange

Defense-in-depth on top of the validate-before-commit guard (sozu#1301). Even
after validation, a request the main process commits to its ConfigState and fans
out can still be rejected worker-side. When EVERY worker it was scattered to
rejects it (a unanimous, definitive failure: no timeout, none accepted),
WorkerTask::on_finish now reverts the main process's own ConfigState with the
inverse request, so its authoritative state (the one replayed into restarted and
upgraded workers) never permanently holds an add the whole fleet refused.

Because no worker applied the change, reverting the main process alone
reconverges the fleet; there is nothing to compensate worker-side. A mixed result
(some workers accepted) is deliberately left as-is to avoid diverging the main
process from the workers that did accept.

compute_rollback covers the non-upsert Add verbs whose inverse is unambiguous
without capturing the prior value: every listener type (inverse RemoveListener)
and HTTP/HTTPS frontends (inverse is the same payload under the Remove variant).
Upsert verbs (AddCluster, AddBackend) and certificates would need the prior value
to revert correctly and are deliberately uncovered (best-effort, as today).

Tested: rollback_inverse_targets_the_same_listener_and_skips_uncovered_verbs.

Refs #1301

Signed-off-by: Florentin Dubois <[email protected]>

@FlorentinDUBOIS FlorentinDUBOIS left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated cross-review (review / review-code / guidelines / simplify / security-review + Codex, adversarially verified). Self-review on my own PR, so posted as COMMENT (GitHub blocks author approve/request-changes). Findings inline; batched into one review.

Comment thread bin/src/command/requests.rs Resolved
Comment thread bin/src/command/requests.rs Resolved
Comment thread command/src/state.rs Resolved
…InvalidInput

Addresses the cross-review findings on #1302.

- HIGH: handle_finishing_task (server.rs) passed a hard-coded timed_out=false
  into every GatheringTask::on_finish, discarding the real flag the two call
  sites pass (has_finished -> false, timeout expiry -> true). So timed_out was
  always false: the Part 2 !timed_out rollback guard was inert, and the audit
  FanoutStatus::Timeout/result branches were unreachable (a timed-out command
  was reported to the operator as "Successfully applied request to all
  workers"). Forward the real flag. New regression test
  handle_finishing_task_forwards_timed_out_flag (seen red without the fix).

- LOW: worker_request tagged both a rejected validate_listener_request and a
  rejected state.dispatch as AuditErrorCode::DispatchError. Thread the failure
  class through apply_result so operator-invalid listener config tags
  InvalidInput (same class as the set_logging_level filter check) and only a
  genuine state conflict tags DispatchError.

- NIT: soften the StateError::Exists message. It is shared by the four frontend
  kinds, which are add/remove only (no Update*Frontend request), so it no
  longer promises an update remedy some kinds lack.

Refs #1301

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 22dd7f3 into main Jul 27, 2026
40 of 41 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/listener-validate-before-commit branch July 27, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid HTTPS listener config is committed to master state before the worker rejects it, blocking a corrected reload

1 participant