Documentation
¶
Overview ¶
Package auth defines Admin API authentication claims and verification.
Index ¶
- Constants
- Variables
- func HasPermission(claims *Claims, permission string) bool
- func Permissions(claims *Claims, candidates ...string) []string
- func ValidatePermission(permission Permission) error
- func WithClaims(ctx context.Context, claims *Claims) context.Context
- func WithIdentityAuthentication(ctx context.Context, authentication *IdentityAuthentication) context.Context
- type AuthRevisionProvider
- type Claims
- type CompositeVerifier
- type ContextVerifier
- type ControlTicketConfig
- type ControlTicketService
- func (s *ControlTicketService) Consume(ctx context.Context, token string) (*IdentityAuthentication, error)
- func (s *ControlTicketService) Issue(ctx context.Context, authentication *IdentityAuthentication) (*IssuedControlTicket, error)
- func (s *ControlTicketService) RevalidateSession(ctx context.Context, sessionID string) (*IdentityAuthentication, error)
- type ExchangeResult
- type ExchangeViewer
- type IdentityAuthentication
- type IdentityContextVerifier
- type IssuedControlTicket
- type IssuedGrant
- type OwnerProvider
- type Permission
- type Registry
- func (r *Registry) Freeze()
- func (r *Registry) Frozen() bool
- func (r *Registry) HasCapability(claims *Claims, permission string) bool
- func (r *Registry) HasPermission(claims *Claims, permission string) bool
- func (r *Registry) HasPermissionDefinition(name string) bool
- func (r *Registry) Permissions(claims *Claims, candidates ...string) []string
- func (r *Registry) PermissionsSnapshot() []Permission
- func (r *Registry) RegisterPermission(permission Permission) error
- func (r *Registry) RegisterPermissions(permissions []Permission) error
- func (r *Registry) RegisterRole(role Role) error
- func (r *Registry) RolesSnapshot() []Role
- type Resolution
- type Resolver
- type Role
- type RoleProvider
- type StaticVerifier
- type StoredRoleProvider
- type Verifier
- type WebAuthConfig
- type WebAuthService
- func (s *WebAuthService) BurnGrant(ctx context.Context, token string) error
- func (s *WebAuthService) Exchange(ctx context.Context, token string) (*ExchangeResult, string, uint64, error)
- func (s *WebAuthService) Issue(ctx context.Context, principal storage.Principal, ...) (string, time.Time, error)
- func (s *WebAuthService) IssueGrant(ctx context.Context, principal storage.Principal, ...) (*IssuedGrant, error)
- func (s *WebAuthService) RevalidateSession(ctx context.Context, sessionID string) (*IdentityAuthentication, error)
- func (s *WebAuthService) RevokeCurrentSession(ctx context.Context, current *IdentityAuthentication) (bool, error)
- func (s *WebAuthService) SupportsCurrentSessionRevocation() bool
- func (s *WebAuthService) SupportsGrantBurn() bool
- func (s *WebAuthService) SupportsSessionLookup() bool
- func (s *WebAuthService) Verify(token string) (*Claims, error)
- func (s *WebAuthService) VerifyContext(ctx context.Context, token string) (*Claims, error)
- func (s *WebAuthService) VerifyIdentityContext(ctx context.Context, token string) (*IdentityAuthentication, error)
Constants ¶
const ( PermAdminAccess = "admin.access" PermUsersView = "users.view" PermUsersEdit = "users.edit" PermChatsView = "chats.view" PermPluginsView = "plugins.view" PermPluginsEdit = "plugins.manage" PermSettingsView = "settings.view" PermSettingsEdit = "settings.edit" PermLogsView = "logs.view" PermMetricsView = "metrics.view" )
const MaxPermissionNameLength = 128
Variables ¶
var ErrForbidden = errors.New("admin access forbidden")
var ErrInvalidToken = errors.New("invalid token")
Functions ¶
func HasPermission ¶
func Permissions ¶ added in v2.0.1
Permissions returns the sorted, unique permissions effective for claims from the supplied candidates. This keeps wildcard roles finite on the wire.
func ValidatePermission ¶ added in v2.0.1
func ValidatePermission(permission Permission) error
ValidatePermission validates one permission declaration without mutating a registry.
func WithClaims ¶ added in v2.0.1
WithClaims attaches verified claims to a request context.
func WithIdentityAuthentication ¶ added in v2.0.1
func WithIdentityAuthentication(ctx context.Context, authentication *IdentityAuthentication) context.Context
Types ¶
type AuthRevisionProvider ¶ added in v2.0.1
type AuthRevisionProvider interface {
AuthRevision(ctx context.Context, principal storage.Principal) (uint64, error)
}
AuthRevisionProvider is the single authority for a principal's effective authorization revision. Every change in any configured role or owner source must bump this revision.
type CompositeVerifier ¶ added in v2.0.1
type CompositeVerifier struct{ Verifiers []Verifier }
func (CompositeVerifier) Verify ¶ added in v2.0.1
func (v CompositeVerifier) Verify(token string) (*Claims, error)
func (CompositeVerifier) VerifyContext ¶ added in v2.0.1
func (CompositeVerifier) VerifyIdentityContext ¶ added in v2.0.1
func (v CompositeVerifier) VerifyIdentityContext(ctx context.Context, token string) (*IdentityAuthentication, error)
type ContextVerifier ¶ added in v2.0.1
ContextVerifier is an optional verifier for credentials backed by storage.
type ControlTicketConfig ¶ added in v2.0.1
type ControlTicketService ¶ added in v2.0.1
type ControlTicketService struct {
// contains filtered or unexported fields
}
func NewControlTicketService ¶ added in v2.0.1
func NewControlTicketService(config ControlTicketConfig, repository storage.ControlTicketRepository, webAuth *WebAuthService) (*ControlTicketService, error)
func (*ControlTicketService) Consume ¶ added in v2.0.1
func (s *ControlTicketService) Consume(ctx context.Context, token string) (*IdentityAuthentication, error)
func (*ControlTicketService) Issue ¶ added in v2.0.1
func (s *ControlTicketService) Issue(ctx context.Context, authentication *IdentityAuthentication) (*IssuedControlTicket, error)
func (*ControlTicketService) RevalidateSession ¶ added in v2.0.1
func (s *ControlTicketService) RevalidateSession(ctx context.Context, sessionID string) (*IdentityAuthentication, error)
type ExchangeResult ¶ added in v2.0.1
type ExchangeResult struct {
AccessToken string `json:"access_token"`
ExpiresAt time.Time `json:"expires_at"`
Viewer ExchangeViewer `json:"viewer"`
Claims Claims `json:"-"`
}
type ExchangeViewer ¶ added in v2.0.1
type IdentityAuthentication ¶ added in v2.0.1
type IdentityAuthentication struct {
Claims *Claims
Principal *storage.Principal
AuthRevision uint64
SessionID string
SessionExpiresAt time.Time
}
IdentityAuthentication is trusted principal provenance produced by a verifier. Principal is nil for authenticated legacy credentials.
func IdentityAuthenticationFromContext ¶ added in v2.0.1
func IdentityAuthenticationFromContext(ctx context.Context) (*IdentityAuthentication, bool)
type IdentityContextVerifier ¶ added in v2.0.1
type IdentityContextVerifier interface {
VerifyIdentityContext(context.Context, string) (*IdentityAuthentication, error)
}
type IssuedControlTicket ¶ added in v2.0.1
type IssuedGrant ¶ added in v2.0.1
type OwnerProvider ¶ added in v2.0.1
type OwnerProvider interface {
IsOwner(ctx context.Context, principal storage.Principal) (bool, error)
}
OwnerProvider is a trusted source of the reserved owner fact. Ordinary role providers and persisted assignments cannot grant owner.
type Permission ¶ added in v2.0.1
Permission and Role are server-owned authorization definitions.
type Registry ¶ added in v2.0.1
type Registry struct {
// contains filtered or unexported fields
}
Registry owns one server's role and permission definitions.
func NewRegistry ¶ added in v2.0.1
func NewRegistry() *Registry
NewRegistry returns a registry preloaded with the v1 built-in authorization policy.
func (*Registry) Freeze ¶ added in v2.0.1
func (r *Registry) Freeze()
Freeze makes the policy immutable before it is used for authorization.
func (*Registry) HasCapability ¶ added in v2.0.1
HasCapability accepts legacy exact grants while keeping role wildcards finite to permissions declared in this registry.
func (*Registry) HasPermission ¶ added in v2.0.1
func (*Registry) HasPermissionDefinition ¶ added in v2.0.1
func (*Registry) Permissions ¶ added in v2.0.1
func (*Registry) PermissionsSnapshot ¶ added in v2.0.1
func (r *Registry) PermissionsSnapshot() []Permission
func (*Registry) RegisterPermission ¶ added in v2.0.1
func (r *Registry) RegisterPermission(permission Permission) error
func (*Registry) RegisterPermissions ¶ added in v2.0.1
func (r *Registry) RegisterPermissions(permissions []Permission) error
RegisterPermissions validates and publishes a permission batch atomically.
func (*Registry) RegisterRole ¶ added in v2.0.1
func (*Registry) RolesSnapshot ¶ added in v2.0.1
type Resolution ¶ added in v2.0.1
Resolution keeps the new authorization revision out of the backwards- compatible public Claims struct.
type Resolver ¶ added in v2.0.1
type Resolver struct {
Registry *Registry
Providers []RoleProvider
OwnerSource OwnerProvider
RevisionSource AuthRevisionProvider
}
Resolver combines trusted role providers into deterministic claims.
type RoleProvider ¶ added in v2.0.1
type RoleProvider interface {
RolesFor(ctx context.Context, principal storage.Principal) ([]string, error)
}
RoleProvider supplies one trusted source of effective principal roles.
type StaticVerifier ¶
type StaticVerifier struct {
// contains filtered or unexported fields
}
func NewStaticVerifier ¶
func NewStaticVerifier(tokens map[string]Claims) *StaticVerifier
type StoredRoleProvider ¶ added in v2.0.1
type StoredRoleProvider struct{ Repository storage.PrincipalRepository }
StoredRoleProvider reads direct assignments from a PrincipalRepository.
func (StoredRoleProvider) AuthRevision ¶ added in v2.0.1
type WebAuthConfig ¶ added in v2.0.1
type WebAuthService ¶ added in v2.0.1
type WebAuthService struct {
// contains filtered or unexported fields
}
func NewWebAuthService ¶ added in v2.0.1
func NewWebAuthService(config WebAuthConfig, repositories storage.AdminAuthRepository, principals storage.PrincipalRepository, resolver Resolver, authorization *Registry) (*WebAuthService, error)
func (*WebAuthService) BurnGrant ¶ added in v2.0.1
func (s *WebAuthService) BurnGrant(ctx context.Context, token string) error
func (*WebAuthService) Exchange ¶ added in v2.0.1
func (s *WebAuthService) Exchange(ctx context.Context, token string) (*ExchangeResult, string, uint64, error)
func (*WebAuthService) Issue ¶ added in v2.0.1
func (s *WebAuthService) Issue(ctx context.Context, principal storage.Principal, origin storage.PlatformIdentity) (string, time.Time, error)
Issue creates a grant for a principal already authenticated by a platform adapter.
func (*WebAuthService) IssueGrant ¶ added in v2.0.1
func (s *WebAuthService) IssueGrant(ctx context.Context, principal storage.Principal, origin storage.PlatformIdentity) (*IssuedGrant, error)
func (*WebAuthService) RevalidateSession ¶ added in v2.0.1
func (s *WebAuthService) RevalidateSession(ctx context.Context, sessionID string) (*IdentityAuthentication, error)
RevalidateSession rechecks a current Admin session by its server-side ID.
func (*WebAuthService) RevokeCurrentSession ¶ added in v2.0.1
func (s *WebAuthService) RevokeCurrentSession(ctx context.Context, current *IdentityAuthentication) (bool, error)
RevokeCurrentSession revokes only the authenticated session supplied by the caller. The lookup binds the session to this service's audience; an already revoked or expired session is a successful no-op.
func (*WebAuthService) SupportsCurrentSessionRevocation ¶ added in v2.0.1
func (s *WebAuthService) SupportsCurrentSessionRevocation() bool
SupportsCurrentSessionRevocation reports whether logout can atomically revoke a session selected by its server-side identity.
func (*WebAuthService) SupportsGrantBurn ¶ added in v2.0.1
func (s *WebAuthService) SupportsGrantBurn() bool
func (*WebAuthService) SupportsSessionLookup ¶ added in v2.0.1
func (s *WebAuthService) SupportsSessionLookup() bool
func (*WebAuthService) Verify ¶ added in v2.0.1
func (s *WebAuthService) Verify(token string) (*Claims, error)
func (*WebAuthService) VerifyContext ¶ added in v2.0.1
func (*WebAuthService) VerifyIdentityContext ¶ added in v2.0.1
func (s *WebAuthService) VerifyIdentityContext(ctx context.Context, token string) (*IdentityAuthentication, error)