auth¶
Package auth provides JWT authentication, password hashing, the RBAC permission model, and login rate limiting for the control plane (ADR 0008).
Index¶
- Variables
- func HashPassword(password string) (string, error)
- func MintUserToken(secret string, ttl time.Duration, user User) (string, error)
- func VerifyPassword(hash, password string) bool
- type AgentIdentity
- type Authenticator
- type Credentials
- type JWTAuthenticator
- func NewJWTAuthenticator(store UserStore, secret string, ttl time.Duration) *JWTAuthenticator
- func (a *JWTAuthenticator) Authenticate(_ context.Context, token string) (*User, error)
- func (a *JWTAuthenticator) AuthenticateAgent(token string) (*AgentIdentity, error)
- func (a *JWTAuthenticator) IssueAgentToken(id AgentIdentity, ttl time.Duration) (string, error)
- func (a *JWTAuthenticator) IssueToken(ctx context.Context, creds Credentials) (string, error)
- type Permission
- type RateLimiter
- func NewRateLimiter(limit int, window time.Duration) *RateLimiter
- func (r *RateLimiter) Allow(key string) bool
- func (r *RateLimiter) Blocked(key string) bool
- type User
- func (u *User) HasPermission(action, resource string) bool
- type UserStore
Variables¶
ErrInvalidCredentials is returned when a username/password pair is rejected.
ErrInvalidToken is returned when a token is malformed, expired, or unsigned by us.
func HashPassword¶
HashPassword hashes a plaintext password with bcrypt.
func MintUserToken¶
MintUserToken signs a user JWT directly, without checking credentials against a store. It is for trusted in-process callers only โ notably `leoflow dev`, which runs its own control plane and must register DAGs without a login round-trip. The token validates under Authenticate using the same secret.
func VerifyPassword¶
VerifyPassword reports whether password matches the stored bcrypt hash.
type AgentIdentity¶
AgentIdentity is the task instance a verified agent token represents.
type AgentIdentity struct {
TaskInstanceID string
TenantID string
DagID string
RunID string
TaskID string
TryNumber int
}
type Authenticator¶
Authenticator issues and validates authentication tokens. The MVP ships a JWT implementation; the interface keeps OIDC/LDAP pluggable (ADR 0008).
type Authenticator interface {
Authenticate(ctx context.Context, token string) (*User, error)
IssueToken(ctx context.Context, creds Credentials) (string, error)
}
type Credentials¶
Credentials are the inputs to token issuance.
type JWTAuthenticator¶
JWTAuthenticator issues and validates HS256 JWTs against a UserStore.
func NewJWTAuthenticator¶
NewJWTAuthenticator builds a JWTAuthenticator with the given user store, HS256 secret, and token lifetime.
func (*JWTAuthenticator) Authenticate¶
Authenticate validates a bearer token and reconstructs the user from its claims.
func (*JWTAuthenticator) AuthenticateAgent¶
AuthenticateAgent validates an agent bearer token and returns the task instance it identifies.
func (*JWTAuthenticator) IssueAgentToken¶
IssueAgentToken mints a signed token that identifies a single task instance, valid for the given TTL. The control plane passes it to the worker pod.
func (*JWTAuthenticator) IssueToken¶
IssueToken validates the credentials against the store and returns a signed JWT.
type Permission¶
Permission is an action on a resource (e.g. {Action: "read", Resource: "dag"}).
type RateLimiter¶
RateLimiter is a per-key fixed-window limiter used to throttle failed logins per client IP (ADR 0008).
func NewRateLimiter¶
NewRateLimiter builds a limiter allowing limit events per window per key.
func (*RateLimiter) Allow¶
Allow records an event for key and reports whether it is within the limit.
func (*RateLimiter) Blocked¶
Blocked reports whether key has already reached its limit in the current window, WITHOUT recording an attempt (a peek). The login handler uses it to reject an over-limit caller up front while calling Allow only for actual failures โ so a successful login never consumes the budget and a user who mistypes a few times is not locked out the moment they finally get it right.
type User¶
User is an authenticated principal with its tenant, roles, and permissions.
func (*User) HasPermission¶
HasPermission reports whether the user may perform action on resource. The admin role, or an admin action / wildcard resource permission, grants access.
type UserStore¶
UserStore loads users for authentication. storage implements it.
type UserStore interface {
FindUserByLogin(ctx context.Context, tenant, username string) (user *User, passwordHash string, err error)
}
Generated by gomarkdoc