rbac is a Tier 0 module (no micro-lib dependencies). The dependency line incorrectly cited it as Tier 1. The module's own tier (4) is unchanged — it remains the auth layer above the transport infrastructure.
3.2 KiB
3.2 KiB
Changelog
All notable changes to this module will be documented in this file.
The format is based on Keep a Changelog, and this module adheres to Semantic Versioning.
0.9.0 - 2026-03-18
Added
TokenVerifierinterface — abstracts*auth.Clientfor unit-test mockability;*auth.Clientsatisfies it directly in production via itsVerifyIDTokenAndCheckRevokedmethodIdentityEnricherinterface — application-implemented; receivesuid stringandclaims map[string]any, returnsrbac.Identity; called byEnrichmentMiddlewareon every requestPermissionProviderinterface — application-implemented; receivesuidandresourcestring, returnsrbac.PermissionMask; called byAuthzMiddlewareon every requestEnrichOptfunctional option type for configuringEnrichmentMiddlewareWithTenantHeader(header string) EnrichOpt— reads a tenant ID from the named request header and attaches it to the identity viarbac.Identity.WithTenant; absent header leavesTenantIDas an empty string with no errorAuthMiddleware(verifier TokenVerifier, publicPaths []string) func(http.Handler) http.Handler— verifiesAuthorization: Bearer <token>via Firebase JWT verification and injects the verifieduidand raw claims into the request context under unexported typed keys; paths matching any pattern inpublicPathsbypass token verification (glob patterns viapath.Match,*wildcard supported); returns 401 on missing or invalid tokensEnrichmentMiddleware(enricher IdentityEnricher, opts ...EnrichOpt) func(http.Handler) http.Handler— reads the uid and claims stored byAuthMiddleware, callsenricher.Enrich, and stores the resultingrbac.Identityin context viarbac.SetInContext; returns 401 ifAuthMiddlewarehas not run upstream; returns 500 if the enricher failsAuthzMiddleware(provider PermissionProvider, resource string, required rbac.Permission) func(http.Handler) http.Handler— readsrbac.Identityfrom context viarbac.FromContext, resolves the permission mask for the identity's UID onresource, and gates the request against the required permission bit; returns 401 if no identity is in context; returns 403 if the permission check fails or the provider returns an error
Design Notes
- The three middleware functions are intentionally separate so they can be applied at different scopes:
AuthMiddlewareat the root router,EnrichmentMiddlewareon authenticated route groups, andAuthzMiddlewareper-route or per-group with different resource and permission arguments - The module is named
httpauth-firebaserather thanhttpauthbecause it imports the Firebase SDK directly; other providers (httpauth-auth0,httpauth-jwt, etc.) are separate sibling modules that all converge on the samerbac.Identityoutput contract, which means downstream handlers and business logic never depend on a specific auth provider - No logger parameter is accepted; errors are returned as plain-text HTTP responses, keeping the dependency surface to
rbacandfirebase.google.com/go/v4only