Skip to content

Require an explicit opt-in before serving without a secret - #35

Merged
loverustfs merged 3 commits into
mainfrom
cursor/explicit-auth-opt-in-f050
Nov 19, 2026
Merged

loverustfs merged 3 commits into
mainfrom
cursor/explicit-auth-opt-in-f050

Conversation

@loverustfs

@loverustfs loverustfs commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to merged #13. This does not change that pull request's branch. Base is current main at 36d8e950. Open pull requests #27–#33 are documentation or status wording and do not cover this authentication change.

This process still does not terminate TLS, and this pull request does not add mutual TLS or RBAC. Product security review is still pending.

What the code on main actually did, and what changes:

  • An empty shared_secret started every loopback listener with no credentials. That is no longer the default. Startup refuses unless the operator sets a secret that contains a non-whitespace character, or sets [security].allow_unauthenticated = true.
  • allow_unauthenticated accepts only literal loopback IPs (127.0.0.0/8 or ::1). The hostname localhost is not accepted and is not resolved, so a hosts-file mapping cannot widen it. The process binds that same literal address and checks the bound IP again. A wildcard or other address still refuses to listen. Setting the flag together with a usable secret is rejected. Compatibility: an opted-in config that used the name localhost no longer starts. A usable secret may still bind a hostname.
  • A whitespace-only secret is not a credential and is not unauthenticated mode. Startup refuses it, including when the opt-in is also set. The gRPC server interceptor, the gRPC client interceptor, the metrics listener, and the Raft client pool all treat whitespace-only the same way: it is not a usable secret. A secret that contains any non-whitespace character is compared exactly, including surrounding spaces.
  • A normalized key (lowercase, hyphens become underscores) fails parsing when it contains secret, password, passwd, token, credential, auth, anonymous, anon, insecure, api_key, apikey, bearer, jwt, private_key, privatekey, encryption, encrypt, tls, ssl, cert, x509, mtls, cipher, keystore, https, ca_file, or cafile, or starts with secur, including inside nested tables and arrays. The only exceptions are the direct keys [security].shared_secret and [security].allow_unauthenticated. Other unknown keys, including bloom_bits_per_key and a misspelled listen or storage key, are still ignored.

Compatibility: a deployment that already sets a non-empty shared_secret and does not set allow_unauthenticated keeps the same bearer requirement. A deployment that relied on an empty secret plus loopback, including metadbd with no security section, no longer starts until one of those two settings is chosen.

English operator docs describe these rules. Non-English locale reconciliation is left to the docs author of #36. classify_secret and SecuritySection::validate_for_startup stay in place for #38 to integrate against. This pull request does not change that author's operability work.

Tests

cargo check -p metadb-server --tests typechecked the latest commit. The tests below were not executed. No workspace test suite was run, and CI was not waited on.

  • empty_secret_on_loopback_does_not_listen
  • whitespace_secret_on_loopback_does_not_listen
  • explicit_unauthenticated_loopback_serves_without_credentials
  • security_sensitive_aliases_fail_closed_and_storage_keys_do_not (includes api_key, bearer, jwt, private_key, ca_file, encryption, anon, and bloom_bits_per_key)
  • loopback_whitespace_secret_does_not_start
  • persisted_non_loopback_advertise_without_secret_fails_closed now sets allow_unauthenticated so the saved 0.0.0.0 address is the refusal under test
  • default_empty_secret_is_rejected_before_any_listener keeps the separate not an implicit exception assertion

Existing in-process tests that start a loopback node without a secret set allow_unauthenticated = true and bind 127.0.0.1. Tests that set a real secret leave that flag false.

Limitations

  • Native TLS, mutual TLS, and RBAC are not implemented. Listeners stay plaintext.
  • The unauthenticated opt-in does not resolve names. Only literal 127.0.0.0/8 and ::1 are accepted. IPv4-mapped IPv6 addresses are not treated as loopback.
  • Unknown TOML keys outside the substring list above are still ignored.
  • Non-English guides were not updated.
  • DistributedTxRouter::with_forward_secret still stores the string it is given. Startup does not pass a whitespace-only secret into it. That helper was not otherwise changed.
  • This pull request does not include commit a48d038.
Open in Web Open in Cursor 

An empty secret no longer starts a listener, including on loopback.
Whitespace-only secrets are rejected by startup and by both bearer
interceptors. allow_unauthenticated is the loopback-only development
flag, and unknown auth-like keys are no longer ignored.

Co-authored-by: RustFS <hello@rustfs.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 19:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The restart regression fixture is rejected before reaching its intended persisted-address check, causing its assertion to fail, and the documented loopback launch command now exits at startup.

2 open issues
What changed in this PR

This PR closes the implicit unauthenticated-loopback path left by #13. Server startup now requires a usable shared secret or an explicit loopback-only opt-in; listeners remain plaintext.

Changes:

  • Add security.allow_unauthenticated, reject conflicting settings, and expand rejection of unsupported authentication keys.
  • Reject whitespace-only credentials consistently across authentication paths.
  • Update regression tests, local test fixtures, and English documentation for the new startup requirements.
File Description
docs/​guides/​en/​deployment.md Explain explicit loopback opt-in.
docs/​en/​testing.md Describe updated authentication cases.
docs/​en/​operations.md Update listener and metrics requirements.
docs/​en/​configuration.md Document security settings and validation.
docs/​en/​build-and-run.md Explain new startup requirements.
docs/​en/​architecture.md Update startup authentication flow.
crates/​metadb-server/​tests/​snapshot_status_tests.rs Opt snapshot fixtures into unauthenticated loopback.
crates/​metadb-server/​tests/​security_adversarial_regressions.rs Expect whitespace-secret startup refusal.
crates/​metadb-server/​tests/​scale_in_restart_tests.rs Opt restart fixtures into unauthenticated loopback.
crates/​metadb-server/​tests/​round2_restart_routes_tests.rs Update restart-route fixtures.
crates/​metadb-server/​tests/​round2_quota_order_tests.rs Update quota-order fixture.
crates/​metadb-server/​tests/​round2_namespace_tests.rs Update namespace startup helper.
crates/​metadb-server/​tests/​round2_name_flush_tests.rs Update name-flush fixture.
crates/​metadb-server/​tests/​round2_mixed_shard_tests.rs Update mixed-shard fixture.
crates/​metadb-server/​tests/​round2_cli_tests.rs Update CLI and metrics fixtures.
crates/​metadb-server/​tests/​round2_api_tests.rs Update API startup helper.
crates/​metadb-server/​tests/​rename_concurrency_regressions.rs Update rename-concurrency fixture.
crates/​metadb-server/​tests/​prefix_load.rs Opt local load fixture into unauthenticated loopback.
crates/​metadb-server/​tests/​join_existing_group.rs Separate authenticated and unauthenticated join fixtures.
crates/​metadb-server/​tests/​integration_tests.rs Update integration configuration.
crates/​metadb-server/​tests/​grpc_regressions.rs Preserve explicit authentication modes in fixtures.
crates/​metadb-server/​tests/​e2e_cluster_evolution_tests.rs Update cluster-evolution configuration.
crates/​metadb-server/​tests/​control_plane_claim_tests.rs Update control-plane fixture.
crates/​metadb-server/​tests/​backup_restore.rs Update backup/restore configuration.
crates/​metadb-server/​tests/​auth_fail_closed.rs Cover startup refusal and explicit opt-in.
crates/​metadb-server/​src/​stress.rs Opt stress fixtures into unauthenticated loopback.
crates/​metadb-server/​src/​metrics_http.rs Reject whitespace-only metrics secrets.
crates/​metadb-server/​src/​lib.rs Classify secrets consistently in bearer interceptors.
crates/​metadb-server/​src/​config.rs Enforce explicit authentication configuration.
crates/​metadb-raft/​src/​network.rs Filter whitespace-only Raft credentials.

Review effort: Balanced

fn reject_unauthenticated_bind(addr: &str, secret: &str) -> Result<()> {
if !secret.trim().is_empty() || is_loopback_bind(addr) {
fn reject_unauthenticated_bind(addr: &str, security: &SecuritySection) -> Result<()> {
security.validate_for_startup()?;
Comment thread docs/en/build-and-run.md Outdated
Logs use `tracing-subscriber`'s `EnvFilter`. The default filter is `info`. Override it with the standard `RUST_LOG` variable, for example `RUST_LOG=debug`.

On startup with an empty `security.shared_secret`, the process logs a warning that loopback gRPC has no authentication. The default bind is `127.0.0.1`. A wildcard or other non-loopback address with an empty, missing, or misspelled secret refuses to listen. A non-empty `[security].shared_secret` requires the same bearer on metadata, transaction, control-plane, Raft transport, and `GET /metrics`. The process does not terminate TLS. A TLS or certificate key in the config fails startup instead of serving plaintext. Keep the listener on a trusted network, or put every service behind a proxy that authenticates clients and block direct access to this process.
An empty `security.shared_secret` does not start the process. The default bind is `127.0.0.1`, and loopback is not an implicit exception. Local development without credentials sets `allow_unauthenticated = true` and keeps every listener on loopback. A wildcard or other non-loopback address still refuses to listen. A whitespace-only secret is rejected. A non-empty `[security].shared_secret` requires the same bearer on metadata, transaction, control-plane, Raft transport, and `GET /metrics`. The process does not terminate TLS. A TLS, certificate, anonymous, or insecure key in the config fails startup instead of serving plaintext. Keep an opted-in listener on a trusted network, or put every service behind a proxy that authenticates clients and block direct access to this process.
An empty secret is allowed only with the loopback opt-in. A whitespace-only
secret is rejected even then. The loopback launch examples now include that
explicit setting instead of a credential-free default.

Co-authored-by: RustFS <hello@rustfs.com>
Unauthenticated mode accepts only literal loopback IPs and rechecks the
bound address, so localhost is not trusted. The saved-address regression
opts in before asserting that refusal, and a separate test keeps the
default empty-secret error. Security-sensitive key aliases fail closed.

Co-authored-by: RustFS <hello@rustfs.com>
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.

3 participants