Documentation
¶
Overview ¶
Package authmw is xolu's authentication middleware, extracted from pkg/middleware (T-19) so external binaries — the molu hub in particular — can import authentication without pulling in the rest of the middleware package or the full server config. Its configuration type lives in pkg/authconfig; the xolu server constructs that from its full config via config.(*Config).AuthConfig().
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
AuthMiddleware creates an authentication middleware based on config
func GetAuthMethod ¶
GetAuthMethod retrieves the auth method from context
func GetSubject ¶
GetSubject retrieves the authenticated subject from context
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey type for context values
const ( // ContextKeySubject is the key for the authenticated subject ContextKeySubject ContextKey = "auth_subject" // ContextKeyAuthMethod is the key for the auth method used ContextKeyAuthMethod ContextKey = "auth_method" )
const ContextKeyTenantGrant ContextKey = "tenant_grant"
ContextKeyTenantGrant is the context key under which the auth layer stores the resolved TenantGrant for the request.
type TenantGrant ¶
type TenantGrant struct {
// Admin authorises any tenant. Set for tenant_admin tokens, admin API keys,
// and the bearer token.
Admin bool
// Tenants is the explicit set of tenant names this identity may act on.
// Ignored when Admin is true.
Tenants []string
}
TenantGrant represents the tenant authority carried by an authenticated identity under TenantAuthMode "scoped". It is the single source of the authorization decision: a request for a tenant is permitted iff the caller's grant Allows it.
A grant is produced by the auth layer from whatever the credential expresses:
- JWT: the "tenants" claim (→ Tenants) or "tenant_admin": true (→ Admin)
- API key: the matching APIKeyGrant in config
- bearer token: always Admin (the trusted-gateway credential)
The zero value is an empty grant that authorises nothing — fail-closed.
func TenantGrantFromContext ¶
func TenantGrantFromContext(ctx context.Context) (TenantGrant, bool)
TenantGrantFromContext returns the TenantGrant placed in the context by the auth middleware. The second return is false if no grant is present (e.g. auth is disabled, or the request did not pass through AuthMiddleware).
func (TenantGrant) Allows ¶
func (g TenantGrant) Allows(tenantName string) bool
Allows reports whether this grant authorises the named tenant. An admin grant allows any tenant; otherwise the name must be an exact member of Tenants. An empty, non-admin grant allows nothing.
func (TenantGrant) IsEmpty ¶
func (g TenantGrant) IsEmpty() bool
IsEmpty reports whether the grant authorises nothing (no admin, no tenants). Used to reject ungranted credentials under scoped mode before tenant resolution.