Documentation
¶
Index ¶
- func BearerAuth(store *TokenStore) func(http.Handler) http.Handler
- func ClientTLSConfig(caFile, certFile, keyFile string) (*tls.Config, error)
- func GenerateToken() (string, error)
- func HashToken(token string) string
- func LoadCAPool(path string) (*x509.CertPool, error)
- func RequireRole(min Role) func(http.Handler) http.Handler
- func RequireRoleHandler(min Role, h http.HandlerFunc) http.HandlerFunc
- func ServerTLSConfig(certFile, keyFile, clientCAFile string) (*tls.Config, error)
- func WithIdentity(ctx context.Context, id Identity) context.Context
- type Identity
- type Role
- type TokenStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BearerAuth ¶
func BearerAuth(store *TokenStore) func(http.Handler) http.Handler
middleware that authenticates requests via the "Authorization: Bearer <token>" header against the given TokenStore. invalid or missing credentials produce a 401 Unauthorized
func ClientTLSConfig ¶
caFile is the CA bundle used to verify server certificates. empty means the system roots. certFile/keyFile, when set, are presented to servers that require client certificates (mTLS). All-empty input yields a nil config, resulting in plain HTTP
func GenerateToken ¶
GenerateToken mints a new random bearer token of the form "ph_<43 base64url chars>"
func LoadCAPool ¶
reads PEM-encoded certificates into a verification pool
func RequireRole ¶
middleware enforcing a minimum role. must run after BearerAuth: requests without an authenticated identity are rejected with 401 Unauthorized, authenticated but insufficient roles get 403 Forbidden.
func RequireRoleHandler ¶
func RequireRoleHandler(min Role, h http.HandlerFunc) http.HandlerFunc
per-route form of RequireRole for routers that attach authorization to individual handler
(chi cannot mount the same Route path inside two middleware-scoped groups, so the manager API wraps each handler instead :/)
func ServerTLSConfig ¶
certFile/keyFile are the server's own certificate pair (both or neither, an empty pair yields a nil config, resulting in plain HTTP). When clientCAFile is set, clients must present a certificate signed by that CA (mTLS). without it the server accepts any client (TLS w/o client auth)
Types ¶
type Role ¶
type Role string
the authorization role attached to a token
admin: read & write access; viewer: read-only access
type TokenStore ¶
type TokenStore struct {
// contains filtered or unexported fields
}
holds parsed token records for verification tokens themselves are never stored, only their SHA-256 hashes
func LoadTokenFile ¶
func LoadTokenFile(path string) (*TokenStore, error)
func ParseTokenFile ¶
func ParseTokenFile(data []byte) (*TokenStore, error)
validates and parses token file contents (YAML):
- user: bipkis role: admin token_hash: "sha256:<64 hex chars>"
- user: bopkis role: viewer token_hash: "sha256:..."