Documentation
¶
Overview ¶
Package authz is the principal + capability model: it maps an authenticated principal to a per-database access Level. It is deliberately neutral — it knows nothing about HOW a principal authenticated (that is package auth) or which transport carried the request — so both the auth middleware (which sets the request principal) and the HTTP handler (which enforces the level) depend only on this package, never on each other.
Index ¶
Constants ¶
const Wildcard = "*"
Wildcard is the grant subject that matches every principal, including the anonymous one.
Variables ¶
var Anonymous = &Principal{Name: "", Method: "none"}
Anonymous is the identity of an unauthenticated request on a listener that admits `none`. It holds no named grants — only wildcard (`*`) grants and open mode apply to it.
Functions ¶
Types ¶
type Level ¶
type Level int
Level is a principal's capability on one database. The zero value (None) is "no access", so an unset grant fails closed.
func ParseLevel ¶
ParseLevel maps a config level string to a Level.
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy is the compiled grant table: database → principal → Level. A named principal's effective level on a database is the max of its explicit grant and any wildcard (`*`) grant. In open mode (no auth configured anywhere) every principal gets ReadWrite on every database, preserving the pre-auth bind-to-localhost behavior until the operator configures grants.
Policy is safe for concurrent use: requests read levels while the control plane grants for a runtime-created database.
func (*Policy) Grant ¶
Grant records that principal (a name or Wildcard) has at least level on db. Re-granting keeps the highest level.
type Principal ¶
Principal is an authenticated identity. The anonymous principal has an empty Name; Method records how it authenticated ("none", "bearer", "mtls", …) for logging and audit.
func FromContext ¶
FromContext returns the principal set by the auth middleware, or Anonymous if none was set (so a handler always has a non-nil principal to reason about).
func (*Principal) IsAnonymous ¶
IsAnonymous reports whether p is the anonymous (unnamed) principal.