Skip to content

Authenticate and authorize mecfeed-serve feed clients (#4, auth slice) - #26

Merged
fastrevmd-lab merged 13 commits into
mainfrom
feat/serve-client-auth
Oct 26, 2026
Merged

fastrevmd-lab merged 13 commits into
mainfrom
feat/serve-client-auth

Conversation

@fastrevmd-lab

Copy link
Copy Markdown
Member

Summary

This is the auth slice of #4. mecfeed-serve now requires every feed client to prove an identity, and limits each client to the feeds it is listed for.

Before this PR, any host inside --allow-cidr could read every feed, including a host spoofing an address in an allowed range. Feeds reveal what the operator blocks, so any of those hosts learned the block list. Serve now fails closed: it starts only with --clients-file, or with an explicit --allow-anonymous-feeds.

Design: docs/superpowers/specs/2026-10-26-serve-client-auth-design.md. Plan: docs/superpowers/plans/2026-10-26-serve-client-auth.md.

Refs #4. The limits, access-log and assurance slices follow as separate PRs.

Squash-merge this PR. Intermediate commits are not deployable. After the first commit, for example, the units do not yet pass --clients-file.

Changes

  • Client list (clients.rs).
    • --clients-file is a strict JSON list, with deny_unknown_fields and version: 1.
    • A client authenticates by HTTP Basic, by a pinned client certificate, or by either.
    • Each client is allowed only its listed <format>/<kind> feeds.
    • Startup refuses, with a message naming the field:
      • bad names, hex or feeds
      • a duplicate name, feed or certificate pin
      • a certificate client without --client-ca
    • The file is read through the no-symlink, regular-file opener and capped at 1 MiB.
  • Basic.
    • Passwords are generated (32 random bytes, base64url) and only their SHA-256 is stored. They are compared with subtle, against a dummy hash for an unknown user.
    • A header over 1 KiB, bad base64, invalid UTF-8, or no : counts as no credentials.
  • Responses and logs.
    • 401 carries WWW-Authenticate: Basic realm="mecfeed", charset="UTF-8".
    • 403 means the feed is not in the client's list.
    • Auth runs before the format and kind are parsed, so a 401 reveals nothing about which feeds exist. /healthz stays CIDR-only.
    • Each 401 and 403 logs the client IP, the matched client name and a reason (no-credentials, unknown-user, bad-password, cert-not-listed, feed-not-allowed). The header and the password are never logged.
  • Client-certificate TLS (tls.rs).
    • With --client-ca, the server uses WebPkiClientVerifier with allow_unauthenticated(). A client may present no certificate, but a certificate that fails the chain fails the handshake.
    • A wrapping acceptor hashes the leaf certificate once per connection and attaches PeerCert to every request on that connection.
  • Helpers. --generate-basic-password prints the password on stdout and basic_sha256: <hex> on stderr. --print-cert-fingerprint <pem> prints the certificate's fingerprint. Neither needs the serving flags.
  • Packaging.
    • The systemd unit loads clients.json with LoadCredential= and passes --clients-file.
    • The installer creates an empty starter list (0640 root:root) with link(2), so it never overwrites an existing file.
    • The ExecStart drop-in warning accepts --clients-file or --allow-anonymous-feeds.
    • verify-packaging pins the new unit lines, and the smoke tests cover the starter file and the warning.
  • Docker and CI. The image ENTRYPOINT passes --clients-file /etc/mecfeed-serve/clients.json, and the CI argv check pins it.
  • Docs. docs/operations.md gains a "Client authentication" section covering:
    • the file format and rules
    • adding a Basic client
    • PAN-OS EDL, SRX Basic (25.2R1+) and SRX mTLS setup
    • rotation
    • upgrading on systemd/LXC and Docker
    • Docker anonymous mode, which needs an --entrypoint override
  • Dependencies. subtle, tokio-rustls (default-features = false) and tower were already in Cargo.lock, which gains only two dependency-edge lines. There is no new [[package]] and no aws-lc-rs.

Breaking. After upgrading, serve starts with the empty list, and every feed answers 401 until clients are added. Re-run the installer with MECFEEDMCP_FORCE_UNIT=1.

Verification

cargo fmt --all -- --check                                                    # ok
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings # ok
cargo test --workspace --locked        # all pass: serve 54, core 44, mcp 50+4+4
cargo audit                                                                   # clean
cargo deny check                                                              # advisories, bans, licenses, sources ok
shellcheck -x packaging/lxc/install.sh packaging/tests/package-smoke.sh scripts/verify-packaging.sh  # clean
scripts/verify-packaging.sh && scripts/build-package.sh                       # ok, incl. package smoke
grep -c 'name = "aws-lc-rs"' Cargo.lock                                       # 0
docker build -f Dockerfile.serve . && docker create … --listen 0.0.0.0:9443   # argv keeps --clients-file
  • Router tests (tower oneshot):
    • no credentials, an unknown user, a wrong password, and HEAD without credentials all give 401
    • an unlisted feed gives 403
    • the right password gives 200 and keeps the ETag
    • /healthz is open
    • anonymous mode serves as before
    • the body and logs never contain the password
    • a table of 7 path variants (trailing slash, //, %2F, case, query, %61) never returns 200 without credentials
  • TLS tests use a real server on an ephemeral port, rcgen CAs and a tokio-rustls client:
    • a pinned certificate gives 200
    • a certificate the CA signed but that is not listed gives 401
    • a certificate from another CA fails the handshake on a server that serves the pinned certificate
    • no certificate with good Basic gives 200
  • Loader tests. The loader refuses a symlink, a missing file and a file over 1 MiB, and each error names the path. A file of exactly 1 MiB loads.
  • Bypass probe. The final review sent 14 path variants through every method, with and without credentials, from a throwaway copy. Nothing reached the feed handler without passing auth.

Each commit had a task review and a Codex gate (codex exec review --commit). Codex found three real problems, all fixed:

  • a duplicate cert_sha256 gave order-dependent authorization
  • Docker anonymous mode was impossible, now documented
  • a doc gap

An Opus whole-branch review had one Important finding, also fixed: the loader had no tests and its errors left out the path.

Checklist

  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings passes
  • cargo build --workspace --locked and cargo test --workspace --locked pass
  • Tests added or updated for this change, and they fail against the old code. The old router served 200 on every feed.
  • cargo audit --deny warnings and cargo deny check licenses bans sources are clean
  • This touches mecfeed-serve feed serving. It adds an authentication and authorization gate in front of the unchanged snapshot handler, and it fails closed. Nothing on the publish side changes, and the prepare → approve → apply control is untouched.
  • Fixtures are synthetic: rcgen certificates, test-only passwords, and placeholder hashes in the docs
  • No new telemetry, analytics, or outbound network call
  • Deterministic code decides; no model output is involved

Anything you're unsure about

  • Not verified on live firewalls. The PAN-OS EDL and SRX steps follow vendor documentation. The live pulls by panosvm and vsrx-ci are P4: end-to-end lab validation with PAN-OS and SRX #5, which is next.
  • Left out on purpose:
    • The client-name lookup is not constant-time. Names are device hostnames, not secrets, and the dummy-hash compare hides whether a password was wrong.
    • /feeds/%FF/address gets 400 from path extraction instead of 401. It reveals nothing about which feeds exist.
    • Denial logs are not rate-limited. That belongs to the limits slice of P3: mecfeed-serve — hardened read-only feed web server (Rust, rustls) #4.
  • No FIFO test for the client list. open_regular's own tests cover FIFOs. std::process is banned outside *_test.rs, and no fifo crate was added.
  • Hot reload is not supported. A client-list change needs a restart.
  • Still open from Close the snapshot-signing follow-ups from #24 #25: the installer's egress check reads only the base unit for IPAddressDeny, so it misses a drop-in that changes it.

🤖 Generated with Claude Code

fastrevmd-lab and others added 13 commits October 26, 2026 09:42
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gerprint helpers

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
authorize() takes the first client whose pin matches, so a shared
cert_sha256 made a certificate's feeds depend on file order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The image's ENTRYPOINT always passes --clients-file, which clap refuses
alongside --allow-anonymous-feeds, so anonymous mode needs an entrypoint
override. Kept fail-closed rather than letting the opt-out win silently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/mecfeed-serve/src/clients.rs Dismissed
Comment thread crates/mecfeed-serve/src/clients.rs Dismissed
Comment thread crates/mecfeed-serve/src/clients.rs Dismissed
Comment thread crates/mecfeed-serve/src/clients.rs Dismissed
Comment thread crates/mecfeed-serve/src/clients.rs Dismissed
Comment thread crates/mecfeed-serve/src/main.rs Dismissed
Comment thread crates/mecfeed-serve/src/main.rs Dismissed
Comment thread crates/mecfeed-serve/src/main.rs Dismissed
Comment thread crates/mecfeed-serve/src/main.rs Dismissed
Comment thread crates/mecfeed-serve/src/main.rs Dismissed
@fastrevmd-lab
fastrevmd-lab merged commit 11692f9 into main Oct 26, 2026
12 checks passed
@fastrevmd-lab
fastrevmd-lab deleted the feat/serve-client-auth branch October 26, 2026 16:25
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.

2 participants