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/hanzoai/zip/middleware) because they are the gateway subsystem's responsibility per HIP-0106.
Other subsystems mounted inside the unified cloud binary trust the gateway-minted 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-minted 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-minted via SetGatewayMinted so downstream subsystems can assert the trust boundary with gateway.AssertGatewayMinted(c).
Pass a nil verifier to only accept gateway-minted 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-minted 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 re-mints 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 mint (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.