5.2 KiB
id, name, status, depends_on, scope, risk, impact, level
| id | name | status | depends_on | scope | risk | impact | level | ||
|---|---|---|---|---|---|---|---|---|---|
| axum-http-router-scaffold | Axum HTTP router scaffold with auth middleware and stealth handoff | completed |
|
moderate | low | component | implementation |
Description
Create an axum HTTP router scaffold behind the http feature flag, with auth middleware that extracts Authorization: Bearer <token> and calls IdentityProvider::resolve_from_token(), and a stealth mode handoff that replaces send_fake_nginx_404 with routing detected HTTP traffic to the axum router.
Per the integration plan section 2.7 and research/phase2/tls-transport.md:
This task creates the structural scaffold for HTTP — auth middleware and stealth handoff only. No operational routes (no POST /v1/{namespace}/{op} handlers). The question of how HTTP paths map to operation invocations is intentionally deferred to Phase 5.
Key components:
- Auth middleware: Extract
Authorization: Bearer <token>from HTTP request headers. CallIdentityProvider::resolve_from_token(). Attach resolvedIdentityto request extensions. Reject with 401 if token is missing or invalid. Both AuthTokens (Ed25519 signed) and API keys (hash-verified) go through this path. - Stealth handoff: When
ListenerConfig::Http { stealth: true }, replacesend_fake_nginx_404with routing the detected-HTTPBufReader<TlsStream>to the axum router. The existingProtocolDetectionenum already hasSshvsHttp— theHttppath currently sends a fake 404 and disconnects. - Default 404 handler: Any unmatched route returns 404. No
/v1/*routes are registered yet. - Dependency: Add
axumdependency behindhttpfeature flag inCargo.toml.
Current state:
stealth.rshasdetect_protocol()returningProtocolDetection::SshorProtocolDetection::Httpsend_fake_nginx_404()currently sends a fake nginx 404 response- No
axumdependency exists yet IdentityProvider::resolve_from_token()exists (will be extended with API keys by task 2.6)
Acceptance Criteria
axumdependency added toCargo.tomlbehindhttpfeature flagcrates/alknet-core/src/http/module created (behindhttpfeature flag)- Auth middleware function: extracts
Authorization: Bearer <token>, callsIdentityProvider::resolve_from_token(), attachesIdentityto axum request extensions, returns 401 on missing/invalid token - Auth middleware supports both AuthTokens and API keys (via
resolve_from_token()which dispatches based on format/prefix) - Stealth handoff:
stealth.rssend_fake_nginx_404replaced with axum router handoff whenhttpfeature is enabled. Whenhttpfeature is disabled, the fake 404 behavior remains. - Default 404 handler for unmatched routes (returns
404 Not Found) - Axum
Routerscaffold constructed with auth middleware layer and default 404 fallback HttpInterfacestruct from task 1 (stream/message interface split) gets its internalRouterreference andIdentityProviderwiredhttpfeature flag inCargo.tomlcorrectly gates theaxumdependency andhttpmodule- Unit test: auth middleware extracts bearer token from
Authorizationheader - Unit test: auth middleware returns 401 for missing token
- Unit test: auth middleware returns 401 for invalid token
- Unit test: auth middleware attaches
Identityto request extensions on valid token - Integration test: stealth mode detection routes HTTP traffic to axum (not fake 404)
- All existing server/stealth tests continue to pass (no behavioral change when
httpfeature is disabled)
References
- docs/research/integration-plan.md — Phase 2.7
- docs/research/phase2/tls-transport.md — Axum integration, stealth handoff, auth middleware
- crates/alknet-core/src/server/stealth.rs — Current ProtocolDetection, send_fake_nginx_404
- crates/alknet-core/src/auth/identity.rs — IdentityProvider::resolve_from_token()
Notes
The integration plan explicitly states: "No operational routes yet — the question of how HTTP paths map to operation invocations depends on the from_openapi / spec-generation work and is deferred to Phase 5." This task is a scaffold: auth middleware, stealth handoff, default 404. Full route registrations come later.
For the stealth handoff, consider a compile-time approach: the
httpfeature flag determines whethersend_fake_nginx_404or the axum handoff is used. Whenhttpis disabled, the existing fake 404 behavior should remain unchanged.
The axum router is created per-server (not per-request). It holds references to the
IdentityProviderandOperationEnv/OperationRegistry.
send_fake_nginx_404should NOT be deleted — just conditionally bypassed when thehttpfeature is enabled and aListenerConfig::Httplistener is configured.
Summary
Added http feature flag with axum/hyper/hyper-util/tower dependencies. Created http module: auth middleware extracts Bearer token, calls resolve_from_token, attaches Identity to extensions; router scaffold with default 404 fallback, no operational routes. Stealth handoff routes ProtocolDetection::Http to axum when http feature enabled; fake nginx 404 preserved when disabled. HttpInterface gains build_router() method.