Documentation
¶
Overview ¶
Package auth holds the access token, sessions and the login rate limiter.
Index ¶
Constants ¶
const SessionTTL = 12 * time.Hour
Variables ¶
This section is empty.
Functions ¶
func EnsureToken ¶
EnsureToken creates the token on first launch using file-locking semantics. The plain token is returned only when it was just created; it is never stored. Exclusive creation is enforced via os.Link (or fallback exclusive open on unsupported filesystems). Concurrent launches will have at most one succeed. A token path that already exists, even as a symbolic link, is never followed nor replaced here: LoadVerifier then refuses the link.
func GenerateToken ¶
GenerateToken returns 32 random bytes as unpadded base64url (43 characters).
func ResetToken ¶
ResetToken generates a new token and replaces the stored digest atomically. It performs a best-effort fsync of the dataDir for durability. rename(2) replaces a symbolic link at the token path without following it.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter counts failures per key over a sliding window.
func (*Limiter) Refund ¶ added in v0.1.2
Refund gives back the attempt Take counted at at (a good token).
func (*Limiter) Take ¶ added in v0.1.2
Take checks and counts an attempt in one step (v0.1.2, audit: checked before the body, counted after it, a burst got 40 tokens checked instead of 5). ok false: the limit is reached, nothing is counted. The attempt counts as a failure until Refund gives it back.
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier holds the SHA-256 digest of the access token for constant-time verification.
func LoadVerifier ¶
LoadVerifier reads the stored SHA-256 digest from dataDir/token.sha256. It returns an error if the file is missing, unreadable, corrupted, or a symbolic link (O_NOFOLLOW: a link could point to a digest someone else chose).