34 KiB
| title | type | status | date | origin | deepened |
|---|---|---|---|---|---|
| feat: Add IP address allowlist to server | feat | active | 2026-04-15 | docs/brainstorms/2026-04-15-ip-whitelist-requirements.md | 2026-04-18 |
feat: Add IP address allowlist to server
Overview
Add configurable IP address allowlisting to the fabro server so users without network-level controls (VPN, firewall) can restrict access by client IP. The allowlist is configured via [server.ip_allowlist] in settings.toml, validated at startup (fail-closed), and enforced as request middleware after tracing but before auth. To preserve TOML compatibility for an upcoming GitHub webhook endpoint, the config shape also reserves an optional GitHub-specific webhook overlay at [server.integrations.github.webhooks.ip_allowlist] plus a reserved github_meta_hooks entry keyword for GitHub-origin webhook traffic.
Problem Frame
Some fabro users deploy on infrastructure without firewalls or VPNs. They need fabro itself to restrict which IP addresses can reach the web UI and API. (see origin: docs/brainstorms/2026-04-15-ip-whitelist-requirements.md)
Requirements Trace
- R1. Non-allowlisted IPs receive 403 before auth, for all requests (API, web UI, static assets)
- R2. No allowlist configured = all IPs allowed (current behavior)
- R3. Health check endpoint
/healthis exempt from IP filtering - R4. Support individual IPv4 and IPv6 addresses
- R5. Support CIDR notation for ranges
- R6. Detect client IP from X-Forwarded-For behind reverse proxies (X-Real-IP is not used — no positional trust model)
- R7. Proxy header trust must be explicitly configured; default uses TCP remote address
- R8. Configured via settings.toml / environment variables only
- R9. No hot-reload; read once at startup
- R10. Log rejected requests at warn level with client IP and path
- R11. Unix socket + allowlist requires trusted_proxy_count > 0 or server refuses to start
- R12. Invalid entries (malformed CIDR) cause startup failure (fail-closed)
- R13. The TOML schema must support provider-specific webhook IP allowlist overrides in integration-owned namespaces without breaking existing
[server.ip_allowlist]configs - R14. Webhook-specific entries may include the reserved keyword
github_meta_hooks, which resolves to GitHub's current webhook delivery ranges fromGET /meta - R15.
github_meta_hooksis only valid in[server.integrations.github.webhooks.ip_allowlist].entries; using it outside the GitHub webhook allowlist is a config error - R16.
[server.integrations.github.webhooks.ip_allowlist].trusted_proxy_countinherits from[server.ip_allowlist].trusted_proxy_countunless explicitly overridden - R17. GitHub webhook IP allowlist config falls back to
[server.ip_allowlist]when the GitHub-specific block or one of its fields is omitted, so webhook routes inherit the server allowlist by default
Scope Boundaries
- No web UI management
- No per-user/per-role IP rules
- No blocklist (deny-list)
- No hot-reload of IP rules
- No implicit loopback exemption
- This plan does not add the webhook endpoint itself; it only reserves the config and resolution shape needed so GitHub webhook-specific enforcement can be wired later without a TOML break
/health/diagnosticsis NOT exempt (requires auth, probes server internals)
Context & Research
Relevant Code and Patterns
- Config layer/resolved pattern:
ServerLayer(sparse,deny_unknown_fields) ->resolve_server()->ServerSettings(fully populated) inlib/crates/fabro-types/src/settings/server.rsandlib/crates/fabro-config/src/resolve/server.rs - Nested integration webhook config already exists: GitHub webhook delivery strategy already lives under
[server.integrations.github.webhooks], so a provider-specific IP allowlist fits the existing integration-owned namespace - Middleware pattern:
middleware::from_fn_with_stateused forcookie_and_demo_middlewareatlib/crates/fabro-server/src/server.rs:971 - Router structure:
/healthregistered on outer router (line 948), dispatch service_fn routes to demo/real sub-routers (line 914) - Serve paths: Three listener branches in
lib/crates/fabro-server/src/serve.rs:492— Unix, TCP+TLS, TCP plain. None currently useConnectInfo - TLS accept loop:
lib/crates/fabro-server/src/tls.rs:61capturesremote_addrbut does not inject it into requests - Auth mode resolution:
auth_modeis resolved once at startup (serve.rs:315) and passed to the router, not hot-reloaded — same pattern for IP allowlist - Test pattern:
tower::ServiceExt::oneshot()withRequest::builder()in server.rs test module (line 6561+)
External References
ipnetcrate (v2.11.0 already transitive dep) —IpNet::contains(&IpAddr)for CIDR matching- Axum
ConnectInfo<SocketAddr>viainto_make_service_with_connect_info::<SocketAddr>() - X-Forwarded-For rightmost-minus-N: the secure approach is to count N trusted proxies from the right of the comma-separated list
- GitHub
GET /metareturns service-specific IP ranges includinghooks; GitHub recommends querying it directly for current webhook source ranges
Key Technical Decisions
- Custom proxy IP extraction over
axum-client-ip: The crate'sRightmostXForwardedFortakes only the single rightmost value, not rightmost-minus-N. Since R7 specifies trusted proxy count support, a simple custom extractor is more appropriate than adding a dependency that doesn't cover the requirement - No X-Real-IP fallback: X-Real-IP has no positional trust model — any client can forge it. When
trusted_proxy_count > 0, only X-Forwarded-For is used for IP extraction. If the header is absent or has too few entries, the request is rejected (fail-closed) - Fail-closed on short X-Forwarded-For chain: If
X-Forwarded-Forhas fewer entries thantrusted_proxy_count, the request is rejected (403) rather than falling back to a potentially spoofable entry - Generic 403 response body: Use
"Access denied."(matching existingApiError::forbidden()) rather than a message that reveals the filtering mechanism - TLS ConnectInfo must use Axum newtype: The TLS accept loop must inject
axum::extract::ConnectInfo<SocketAddr>(the wrapper type), not a bareSocketAddr, or the middleware extractor will silently fail ipnetas direct dependency: Present in Cargo.lock as a transitive dependency (v2.11.0); added as a direct dependency to fabro-types, fabro-config, and fabro-server for CIDR parsing and matching[server.ip_allowlist]remains the global default scope, and GitHub webhook overrides live under[server.integrations.github.webhooks.ip_allowlist]: This matches the existing integration-owned webhook config shape and avoids inventing a parallel top-level webhook namespace- The GitHub webhook allowlist is an overlay on the global allowlist, not a separate root policy: If
[server.integrations.github.webhooks.ip_allowlist]is absent, GitHub webhook requests use[server.ip_allowlist]. If the GitHub block is present but omitsentriesortrusted_proxy_count, the omitted field inherits from[server.ip_allowlist] entriesresolves to a typed enum, not raw strings: User-provided strings parse intoIpAllowEntry, withLiteral(IpNet)for direct IP/CIDR values andGitHubMetaHooksfor the reserved keywordgithub_meta_hooksgithub_meta_hooksis GitHub-webhook-only: The reserved keyword is accepted only in[server.integrations.github.webhooks.ip_allowlist].entries, where it means "expand to GitHub's current/metahooksranges". Using it elsewhere is invalid config- GitHub meta expansion should use startup-time fetch plus cache-aware reuse: Resolve
github_meta_hooksat startup, usingGET /metaand thehooksarray. Reuse cached data on304 Not Modified; if GitHub is unavailable and there is no usable cache, fail startup - Middleware after TraceLayer, before cookie middleware: Rejected requests still get trace spans (including 403 status), but no cookie/demo processing for blocked IPs
- Health exemption inside middleware: The middleware checks the request path for
/healthrather than selectively applying to route sets, keeping router structure simple - IPv4-mapped IPv6 normalization: Convert
::ffff:x.x.x.xto IPv4 equivalent before matching, so10.0.0.0/8matches regardless of how the OS reports the address - Land the schema before the webhook route if convenient: The default-scope middleware can ship first. The GitHub-specific webhook overlay and
github_meta_hooksresolution model should land now so the later webhook feature can wire into it without a TOML migration
Open Questions
Resolved During Planning
- Which Axum ecosystem tools for IP detection? Custom implementation.
axum-client-ipdoesn't support trusted-proxy-count.ConnectInfo<SocketAddr>for TCP remote address, manual X-Forwarded-For parsing for proxy support - Config shape?
[server.ip_allowlist]is the global default scope.[server.integrations.github.webhooks.ip_allowlist]is an optional GitHub-specific overlay, which fits the existing integration-owned webhook namespace anddeny_unknown_fieldsconstraint - How should GitHub webhook origins be represented? As the reserved keyword
github_meta_hooksinside[server.integrations.github.webhooks.ip_allowlist].entries, resolved into concrete IP nets from GitHubGET /meta - Which health endpoints to exempt? Only
/health. Not/health/diagnostics(requires auth, exposes server internals) - IPv4-mapped IPv6 handling? Normalize to IPv4 before matching
- X-Forwarded-For position? Rightmost-minus-N where N =
trusted_proxy_count. If N=0, use TCP remote address (ConnectInfo)
Deferred to Implementation
- Cross-domain config validation sequencing: The Unix socket + allowlist check requires both
listenandip_allowlistto be resolved. Perform this check inresolve_server()after bothresolve_listen()andresolve_ip_allowlist()return, not inside the IP allowlist resolver itself - Whether
ipnetversion needs bumping: Currently 2.11.0 as transitive; verifycontains()API availability at implementation time
High-Level Technical Design
This illustrates the intended approach and is directional guidance for review, not implementation specification. The implementing agent should treat it as context, not code to reproduce.
Representative TOML:
[server.ip_allowlist]
entries = ["10.0.0.0/8"]
trusted_proxy_count = 1
[server.integrations.github]
strategy = "app"
app_id = "123456"
client_id = "Iv1.abc123"
slug = "fabro-app"
[server.integrations.github.webhooks]
strategy = "tailscale_funnel"
[server.integrations.github.webhooks.ip_allowlist]
entries = ["github_meta_hooks"]
# trusted_proxy_count inherits as 1 unless overridden here
Request flow with IP allowlist:
Client -> [TCP/TLS Accept] -> ConnectInfo<SocketAddr> injected
-> [TraceLayer] -> trace span created
-> [IP Allowlist] -> select active scope
- current routes: default `[server.ip_allowlist]`
- future GitHub webhook route:
`[server.integrations.github.webhooks.ip_allowlist]`
overlaid on `[server.ip_allowlist]`
if path == "/health": pass through
else: extract client IP
(ConnectInfo or X-Forwarded-For rightmost-minus-N)
normalize IPv4-mapped IPv6
check against Vec<IpNet>
if miss: warn!(...), return 403
-> [Cookie/Demo] -> parse cookies, demo header
-> [Router] -> dispatch to demo/real sub-router
-> [Auth extractor] -> per-handler auth check
Startup validation:
settings.toml -> parse [server.ip_allowlist]
-> parse optional [server.integrations.github.webhooks.ip_allowlist]
-> parse each entry string into IpAllowEntry
- IP/CIDR -> Literal(IpNet)
- `github_meta_hooks` -> GitHubMetaHooks
-> reject `github_meta_hooks` outside the GitHub webhook allowlist
-> when resolving a GitHub webhook scope containing `GitHubMetaHooks`,
call `GET /meta`, read `hooks`, parse into IpNet list
-> for GitHub webhook requests, build the effective scope by overlaying
`[server.integrations.github.webhooks.ip_allowlist]` on
`[server.ip_allowlist]`
-> if Unix socket && active scope has entries && trusted_proxy_count == 0:
error
-> resolve to IpAllowlistConfig (Arc, read-once)
-> pass to build_router_with_options
Implementation Units
- Unit 1: Config types and resolution
Goal: Define the settings.toml schema for [server.ip_allowlist] plus the GitHub webhook overlay, and wire up typed entry parsing/validation.
Requirements: R4, R5, R8, R11, R12, R13, R14, R15, R16, R17
Dependencies: None
Files:
- Modify:
lib/crates/fabro-types/src/settings/server.rs - Modify:
lib/crates/fabro-config/src/resolve/server.rs - Modify:
lib/crates/fabro-config/Cargo.toml(addipnetdirect dependency) - Modify:
lib/crates/fabro-types/Cargo.toml(addipnetfor the resolved type) - Test:
lib/crates/fabro-config/src/resolve/server.rs(inline tests)
Approach:
- Add
ServerIpAllowlistLayerfor the root[server.ip_allowlist]table withentries: Option<Vec<String>>andtrusted_proxy_count: Option<u32>. Apply#[serde(deny_unknown_fields)] - Add
ServerIpAllowlistOverrideLayerwith the same fields for provider-local webhook overlays - Add
ip_allowlist: Option<ServerIpAllowlistLayer>toServerLayer - Add
ip_allowlist: Option<ServerIpAllowlistOverrideLayer>toIntegrationWebhooksLayerso GitHub webhook config can live at[server.integrations.github.webhooks.ip_allowlist] - Add
IpAllowEntryenum withLiteral(IpNet)andGitHubMetaHooks - Add
ServerIpAllowlistSettingswithentries: Vec<IpAllowEntry>andtrusted_proxy_count: u32for the global scope - Add
ServerIpAllowlistOverrideSettingswithentries: Option<Vec<IpAllowEntry>>andtrusted_proxy_count: Option<u32>for GitHub webhook overlay settings - Default when absent: empty
entriesvec,trusted_proxy_count: 0 - Add
resolve_ip_allowlist()to parse the global scope intoServerIpAllowlistSettings - Add
resolve_ip_allowlist_override()to parse provider-local overlays intoServerIpAllowlistOverrideSettings, preserving omitted fields asNone - Extend
resolve_integrations()to parseserver.integrations.github.webhooks.ip_allowlistinto the resolved GitHub webhook settings - Reject
github_meta_hooksoutside the GitHub webhook allowlist path - Add
ip_allowlistfield toServerSettings, and extend the resolved integration webhook settings to carry the optional overlay - Perform cross-domain validation in
resolve_server()afterresolve_listen(),resolve_ip_allowlist(), andresolve_integrations()return: compute the effective GitHub webhook scope by overlaying the GitHub webhook config on the global allowlist, then check Unix socket + effective scope with non-empty entries + resolvedtrusted_proxy_count == 0→ push error
Patterns to follow:
ServerAuthLayer/ServerAuthSettingsin same file for layer/resolved struct patternIntegrationWebhooksLayer/IntegrationWebhooksSettingsin the same file for nested integration-owned configresolve_auth()inlib/crates/fabro-config/src/resolve/server.rsfor validation withResolveError
Test scenarios:
- Happy path: valid IPv4, IPv6, and CIDR entries parse correctly into
IpAllowEntry::Literal - Happy path: absent
[server.ip_allowlist]section resolves to empty entries (R2) - Happy path:
trusted_proxy_countdefaults to 0 when not specified - Happy path:
[server.integrations.github.webhooks.ip_allowlist]resolves as an optional overlay independent from the global scope - Happy path: GitHub webhook entries fall back to the global scope when the GitHub block is absent
- Happy path: GitHub webhook entries fall back to the global scope when the GitHub block omits
entries - Happy path:
server.integrations.github.webhooks.ip_allowlist.trusted_proxy_countinherits the global value when omitted - Happy path:
server.integrations.github.webhooks.ip_allowlist.trusted_proxy_countoverrides the global value when explicitly set - Happy path:
github_meta_hooksis accepted inserver.integrations.github.webhooks.ip_allowlist.entries - Error path: malformed CIDR string (e.g.,
10.0.0.0/33) produces ResolveError - Error path: unparseable address (e.g.,
not-an-ip) produces ResolveError - Error path:
github_meta_hooksin the default scope produces ResolveError - Error path:
github_meta_hooksoutside the GitHub webhook allowlist path produces ResolveError - Error path: Unix socket listener + non-empty allowlist +
trusted_proxy_count: 0produces ResolveError - Edge case: empty
entrieslist (present but empty) resolves to empty vec (equivalent to no filtering)
Verification:
-
cargo nextest run -p fabro-configpasses -
cargo nextest run -p fabro-typespasses -
Invalid config entries cause resolution errors, not panics
-
Unit 2: Effective scope resolution, entry expansion, IP matching, and client IP extraction
Goal: Create the core IP matching logic, effective scope overlay logic, dynamic entry expansion, and client IP extraction (from ConnectInfo or proxy headers).
Requirements: R4, R5, R6, R7, R14, R17
Dependencies: Unit 1 (needs ServerIpAllowlistSettings)
Files:
- Create:
lib/crates/fabro-server/src/ip_allowlist.rs - Modify:
lib/crates/fabro-server/src/lib.rs(add module declaration) - Modify:
lib/crates/fabro-server/Cargo.toml(addipnetdirect dependency) - Test:
lib/crates/fabro-server/src/ip_allowlist.rs(inline test module) - Test fixture or mock HTTP support as needed for GitHub
/metaresolution tests
Approach:
IpAllowliststruct wrappingVec<IpNet>with acontains(&IpAddr) -> boolmethod- Add a helper that computes an effective scope from the global allowlist plus an optional provider-specific overlay:
entries = override.entries.unwrap_or(global.entries.clone())trusted_proxy_count = override.trusted_proxy_count.unwrap_or(global.trusted_proxy_count)
- Add a resolution step that turns the effective scope's
Vec<IpAllowEntry>into concreteVec<IpNet>for a chosen route:Literal(IpNet)passes through directlyGitHubMetaHooksfetches GitHubGET /meta, reads thehooksarray, and parses each item asIpNet
- Use cache-aware startup fetch for
GitHubMetaHooks: sendIf-None-Matchwhen cache exists, reuse cached ranges on304, and fail startup when the source cannot be resolved and no usable cache exists - Before matching, normalize IPv4-mapped IPv6 (
::ffff:x.x.x.x→ IPv4 equivalent) usingto_canonical()or manual mapping extract_client_ip(req, trusted_proxy_count) -> Option<IpAddr>function:- If
trusted_proxy_count > 0: parseX-Forwarded-Forheader, split by comma, take the entry at zero-indexed positionlen - 1 - trusted_proxy_count(skipping N trusted proxy entries from the right to reach the client IP). IfX-Forwarded-Foris absent or has fewer entries thantrusted_proxy_count + 1, returnNone(fail-closed) - If
trusted_proxy_count == 0: extractConnectInfo<SocketAddr>from request extensions, returnaddr.ip()
- If
IpAllowlist::is_empty()method to efficiently skip checking when no allowlist is configured (R2)IpAllowlistConfigstruct containingIpAllowlist+trusted_proxy_count: u32, constructed from the effective scope for a chosen route. This is the type used as middleware state (Arc<IpAllowlistConfig>) in Units 3, 4, and the later GitHub webhook wiring step
Patterns to follow:
lib/crates/fabro-server/src/jwt_auth.rsfor module structure and inline test organization
Test scenarios:
- Happy path: IPv4 address matches an individual IPv4 entry
- Happy path: IPv4 address matches a CIDR range (e.g.,
10.1.2.3matches10.0.0.0/8) - Happy path: IPv6 address matches an IPv6 CIDR range
- Happy path: effective GitHub webhook scope falls back to global entries when the GitHub overlay is absent
- Happy path: effective GitHub webhook scope falls back to global entries when the GitHub overlay omits
entries - Happy path: effective GitHub webhook scope inherits the global
trusted_proxy_countwhen the GitHub overlay omits it - Happy path: effective GitHub webhook scope overrides
trusted_proxy_countwhen the GitHub overlay sets it - Happy path:
GitHubMetaHooksexpands to thehooksranges from a mocked/metaresponse - Happy path: cached GitHub metadata is reused on
304 Not Modified - Happy path:
extract_client_ipwithtrusted_proxy_count: 0returns ConnectInfo IP - Happy path:
extract_client_ipwithtrusted_proxy_count: 1and headerclient, proxy1returnsclient(second-from-right, skipping 1 trusted proxy) - Happy path:
extract_client_ipwithtrusted_proxy_count: 2and headerclient, proxy1, proxy2returnsclient(third-from-right, skipping 2 trusted proxies) - Edge case: IPv4-mapped IPv6 (
::ffff:10.1.2.3) matches plain IPv4 entry10.0.0.0/8 - Edge case: X-Forwarded-For with fewer entries than
trusted_proxy_count— returns None (fail-closed) - Edge case: X-Forwarded-For entries with whitespace around commas are trimmed
- Edge case: empty allowlist
is_empty()returns true - Edge case: single host IP as
/32CIDR matches exactly - Error path: GitHub
/metaresponse contains an invalid range — resolution fails closed - Error path: GitHub
/metais unavailable and there is no usable cache — startup fails - Error path: missing ConnectInfo extension when
trusted_proxy_count: 0— returns None - Error path: malformed IP in X-Forwarded-For — returns None (fail-closed)
- Error path: X-Forwarded-For absent when
trusted_proxy_count > 0— returns None (no X-Real-IP fallback)
Verification:
-
cargo nextest run -p fabro-server -- ip_allowlistpasses -
All matching and extraction edge cases covered
-
Unit 3: IP filter middleware
Goal: Create the Axum middleware function that enforces the IP allowlist on incoming requests.
Requirements: R1, R2, R3, R10
Dependencies: Unit 2 (needs IpAllowlist and extract_client_ip)
Files:
- Modify:
lib/crates/fabro-server/src/ip_allowlist.rs(add middleware function) - Test:
lib/crates/fabro-server/src/ip_allowlist.rs(middleware integration tests in inline module)
Approach:
ip_allowlist_middlewareasync function with signature compatible withmiddleware::from_fn_with_state:- State:
Arc<IpAllowlistConfig>containing theIpAllowlistandtrusted_proxy_count - If allowlist is empty: call
next.run(req).awaitimmediately (R2 — zero overhead when unconfigured) - If request path is
/health: pass through regardless (R3) - Extract client IP using
extract_client_ip() - If IP is in allowlist: pass through
- If IP is not in allowlist or extraction failed:
warn!(client_ip = %ip, path = %path, "request rejected: IP not in allowlist"), return 403 response. Log only the parsedIpAddr, not raw header values, to prevent log injection
- State:
- Return
ApiError::forbidden().into_response()(generic "Access denied." — does not reveal IP filtering as the mechanism;.into_response()needed sincefrom_fn_with_statemiddleware must returnResponse)
Patterns to follow:
cookie_and_demo_middlewareatlib/crates/fabro-server/src/server.rs:1994forfrom_fn_with_statemiddleware signature and request inspection- Logging strategy:
warn!with structured fields perdocs-internal/logging-strategy.md
Test scenarios:
- Happy path: request from allowlisted IP passes through to handler
- Happy path: request to
/healthfrom any IP passes through (R3) - Happy path: empty allowlist allows all requests (R2)
- Error path: request from non-allowlisted IP returns 403 with appropriate body
- Error path: request with no extractable IP (missing ConnectInfo, no proxy headers) returns 403
- Integration: middleware runs before auth — a blocked IP never reaches auth extractor
- Edge case: request to
/health/diagnosticsfrom non-whitelisted IP returns 403 (not exempt) - Edge case: request to
/health/(trailing slash) from non-whitelisted IP returns 403 (not exempt — exact path match only) - Edge case: static asset request from non-whitelisted IP returns 403
Verification:
-
cargo nextest run -p fabro-server -- ip_allowlistpasses -
Rejected requests logged at warn level with structured fields
-
Unit 4: Router and serve integration
Goal: Wire the default-scope IP allowlist middleware into the router and enable ConnectInfo extraction in all serve paths.
Requirements: R1, R7, R9
Dependencies: Unit 3 (needs middleware function), Unit 1 (needs resolved config)
Files:
- Modify:
lib/crates/fabro-server/src/server.rs(add middleware layer inbuild_router_with_options, updatebuild_router()convenience wrapper to pass default empty allowlist) - Modify:
lib/crates/fabro-server/src/serve.rs(read allowlist config at startup, pass to router, update TCP serve call to useinto_make_service_with_connect_info) - Modify:
lib/crates/fabro-server/src/tls.rs(injectConnectInfo<SocketAddr>into request extensions in TLS accept loop) - Test:
lib/crates/fabro-server/src/server.rs(integration tests in existing test module)
Approach:
- In
serve.rsserve_command(): resolve the default-scope IP allowlist config fromresolved_server_settingsonce at startup (likeauth_modeat line 315). Wrap inArc<IpAllowlistConfig>and pass tobuild_router_with_optionsas a separate parameter (not inRouterOptions, to keep it lightweight andCopy-compatible — mirrors howauth_modeis passed separately) - In
server.rsbuild_router_with_options(): applymiddleware::from_fn_with_state(ip_allowlist_config, ip_allowlist_middleware)as a layer AFTERtrace_layerbut BEFOREcookie_and_demo_middleware. Layer ordering (outermost to innermost): TraceLayer → IP allowlist → cookie/demo → router - In
serve.rsTCP plain path (line 519): changeaxum::serve(listener, router)toaxum::serve(listener, router.into_make_service_with_connect_info::<SocketAddr>()) - In
tls.rsaccept loop (line 78): injectaxum::extract::ConnectInfo<SocketAddr>(the Axum newtype wrapper, NOT a bareSocketAddr) as a request extension before calling the router. If the wrong type is inserted,extract_client_ipwill silently fail and all requests will be rejected - In
serve.rsUnix socket path (line 498): no ConnectInfo change needed — the startup validation (Unit 1) ensurestrusted_proxy_count > 0when using Unix socket with an allowlist, so the middleware will use proxy headers - IP allowlist config is NOT added to
AppStateorshared_settings— it is captured by the middleware closure at construction time, ensuring R9 (no hot-reload) - Do not wire
server.integrations.github.webhooks.ip_allowlisthere yet unless the GitHub webhook route already exists in the same change; the root middleware should continue to represent the global default scope for current routes
Patterns to follow:
auth_moderesolution atserve.rs:315for resolve-once-at-startup patterncookie_and_demo_middlewarelayer application atserver.rs:971for middleware wiringauth_modeparameter passing for howbuild_router_with_optionsaccepts separate config
Test scenarios:
- Happy path: full router with allowlist configured blocks non-allowlisted IP, allows allowlisted IP
- Happy path: full router without allowlist configured allows all IPs
- Happy path:
/healthaccessible from any IP when allowlist is configured - Integration: ConnectInfo extension is available in request when using TCP serve
- Integration: IP filtering works with demo mode — blocked IPs cannot access demo routes
- Integration: existing tests with non-empty allowlist must inject
ConnectInfo<SocketAddr>into request extensions viaRequest::builder().extension(ConnectInfo(...)), or fail-closed will reject all requests - Edge case: TLS path injects ConnectInfo correctly so IP filtering works over HTTPS
Verification:
-
cargo nextest run -p fabro-serverpasses (all existing tests + new integration tests) -
cargo clippy --workspace -- -D warningspasses -
cargo +nightly fmt --check --allpasses -
Unit 5: Webhook scope wiring
Goal: When the GitHub webhook endpoint is added, route those requests through the GitHub-specific overlay without changing the TOML schema.
Requirements: R1, R7, R9, R13, R14, R15, R16, R17
Dependencies: Unit 1 (typed config), Unit 2 (dynamic entry resolution), webhook endpoint implementation
Files:
- Modify:
lib/crates/fabro-server/src/server.rs - Modify:
lib/crates/fabro-server/src/github_webhooks.rsand/or webhook handler/router files added by the webhook feature - Test: GitHub webhook integration tests alongside the webhook endpoint
Approach:
- Select the active allowlist scope by route:
- normal routes use
resolved_server_settings.ip_allowlist - GitHub webhook routes compute an effective scope by overlaying
resolved_server_settings.integrations.github.webhooks.ip_allowlistonresolved_server_settings.ip_allowlist
- normal routes use
- Reuse the same middleware and
IpAllowlistConfigshape; only the chosen scope changes - If the GitHub webhook scope contains
GitHubMetaHooks, resolve it at startup the same way as any other typed entry before constructing the webhook middleware state - Keep the GitHub webhook route's HMAC verification; IP allowlisting is additive defense, not a replacement
Patterns to follow:
- Reuse the default-scope middleware wiring rather than introducing a second bespoke path
- Keep route selection explicit near the router definition so reviewers can see which requests use which scope
Test scenarios:
- Happy path: GitHub webhook request uses the global allowlist when
server.integrations.github.webhooks.ip_allowlistis absent - Happy path: GitHub webhook request uses global entries when the GitHub overlay omits
entries - Happy path: GitHub webhook request uses the inherited global
trusted_proxy_countwhen the GitHub overlay omits it - Happy path: GitHub webhook request uses the overlay
trusted_proxy_countwhen explicitly configured - Happy path:
github_meta_hooksallows a GitHub webhook request from a GitHub hook range - Error path: GitHub webhook request from a non-allowlisted IP returns 403 before webhook auth/HMAC handling
- Integration: non-webhook routes continue using the global scope even when GitHub webhook IP allowlist config is present
Verification:
- GitHub webhook integration tests pass once the endpoint exists
- Existing non-webhook allowlist tests still pass unchanged
System-Wide Impact
- Interaction graph: The default middleware sits between TraceLayer and cookie/demo middleware. It reads
ConnectInfoextensions (set byinto_make_service_with_connect_infoor manually in TLS path). The GitHub webhook-specific overlay reuses the same machinery once the GitHub webhook route exists - Error propagation: 403 responses from the middleware short-circuit the request pipeline. They appear in TraceLayer output as normal 403 responses. The middleware also emits its own
warn!log - State lifecycle risks: None — the allowlist is immutable after startup (Arc, no hot-reload). No shared mutable state
- API surface parity: The global scope applies uniformly to all current routes (except
/health). A later GitHub webhook route can opt into the reserved provider-local overlay without changing the global config surface - Integration coverage: Key scenario: full request through TCP listener → ConnectInfo injection → IP filter → handler. This must be tested via
oneshot()with manually injectedConnectInfoextensions - Unchanged invariants: Auth middleware (extractors), demo mode dispatch, SSE streaming, and existing API routes remain unchanged. The GitHub webhook endpoint is still added separately; this plan only reserves and later wires the scope it will use
Risks & Dependencies
| Risk | Mitigation |
|---|---|
into_make_service_with_connect_info changes the axum::serve return type |
Straightforward migration; Axum docs show the pattern. Test all serve paths |
TLS path ConnectInfo injection uses wrong type (bare SocketAddr instead of ConnectInfo<SocketAddr>) |
Explicitly documented constraint in Unit 4 approach; dedicated test verifies extraction works through TLS path |
| IPv4-mapped IPv6 normalization bugs | Comprehensive test coverage in Unit 2 with explicit mapped-address test cases |
| Existing tests may break if they rely on the serve signature | Tests use oneshot() against the router, not axum::serve, so they are unaffected |
github_meta_hooks makes startup depend on an external service |
Use GitHub's ETag-capable /meta endpoint with cached reuse; fail closed only when the keyword is configured and no usable data can be resolved |
| A future GitHub webhook-specific schema could force a TOML migration | Reserve [server.integrations.github.webhooks.ip_allowlist] now so the later GitHub webhook feature only consumes existing config rather than renaming it |
Sources & References
- Origin document: docs/brainstorms/2026-04-15-ip-whitelist-requirements.md
- Related code:
lib/crates/fabro-server/src/server.rs(router, middleware) - Related code:
lib/crates/fabro-server/src/serve.rs(serve paths) - Related code:
lib/crates/fabro-server/src/tls.rs(TLS accept loop) - Related code:
lib/crates/fabro-types/src/settings/server.rs(config types) - Related code:
lib/crates/fabro-config/src/resolve/server.rs(config resolution) - External: ipnet crate for CIDR matching
- External: Axum ConnectInfo
- External: GitHub REST API meta endpoint for
GET /metaand thehooksIP list - External: GitHub webhook best practices for the recommendation to allow GitHub's current webhook IPs