Documentation
¶
Overview ¶
Package middleware ships gateway-owned middleware for the zip web framework. JWT validation + identity-header stripping live here (and NOT in github.com/zap-proto/zip/middleware) because they are the gateway subsystem's responsibility per HIP-0106.
Other subsystems mounted inside the unified cloud binary trust the gateway-written X-Org-Id header and do not re-validate JWTs themselves — re-running JWT validation per-subsystem is wasteful and risks divergent validation rules.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Auth ¶
func Auth(verifier AuthVerifier) zip.Handler
Auth validates incoming requests via verifier. When the request already carries gateway-written X-Org-Id (i.e. behind hanzoai/gateway), the verifier is bypassed and the headers are trusted. Otherwise the Authorization: Bearer <token> is verified.
On successful gateway-trust or successful in-process verification, Auth marks the request as gateway-written via SetGatewayWritten so downstream subsystems can assert the trust boundary with gateway.AssertGatewayWritten(c).
Pass a nil verifier to only accept gateway-written headers (no in-binary JWT validation).
func StripIdentityHeaders ¶
StripIdentityHeaders strips client-supplied X-Org-Id / X-User-Id / X-User-Email / X-User-IsAdmin / X-Roles / X-User-Permissions from the request before any other middleware runs. Per HIP-0026, only the gateway-written path is trusted; everything else must be stripped to prevent client spoofing.
Use this when a service runs WITHOUT a Hanzo gateway in front (rare). When deployed behind hanzoai/gateway, the gateway strips these unconditionally and rewrites from JWT — leave this middleware OFF in that topology.
Types ¶
type AuthVerifier ¶
type AuthVerifier interface {
// Verify validates the bearer token and returns the canonical
// X-* headers to write (Org / User / Email / IsAdmin / Roles).
Verify(ctx context.Context, bearer string) (Identity, error)
}
AuthVerifier is the interface Auth() consumes. The real implementation in hanzoai/iam or hanzoai/gateway-sdk satisfies it. A nil verifier on a request that has no gateway X-* headers and no Authorization bearer is rejected with 401.