auth

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth provides authentication and authorization interfaces and implementations for CallFS. It includes API key authentication for REST endpoints and Unix socket authorization for local access.

Index

Constants

View Source
const (
	SourceAPIKeyUsers = "api_key_users"
	SourceAPIKeys     = "api_keys"
	SourceReserved    = "reserved"
)

Variables

View Source
var (
	ErrAuthenticationFailed = errors.New("authentication failed")
	ErrPermissionDenied     = errors.New("permission denied")
)

Common authentication/authorization errors

View Source
var (
	ErrInvalidSession    = errors.New("invalid session")
	ErrSessionExpired    = errors.New("session expired")
	ErrSessionKeyMissing = errors.New("session key is empty")
)

Functions

func DeriveSessionKey

func DeriveSessionKey(internalProxySecret string) ([]byte, error)

func Fingerprint

func Fingerprint(key string) string

Types

type APIKeyAuthenticator

type APIKeyAuthenticator struct {
	// contains filtered or unexported fields
}

func NewAPIKeyAuthenticator

func NewAPIKeyAuthenticator(keys []string, keyUsers map[string]string, internalProxySecret string) *APIKeyAuthenticator

func (*APIKeyAuthenticator) Authenticate

func (a *APIKeyAuthenticator) Authenticate(ctx context.Context, token string) (string, error)

func (*APIKeyAuthenticator) LegacyAliases

func (a *APIKeyAuthenticator) LegacyAliases(userID string) []string

func (*APIKeyAuthenticator) Reload

func (a *APIKeyAuthenticator) Reload(apiKeys []string, apiKeyUsers map[string]string, internalSecret string)

func (*APIKeyAuthenticator) UserForFingerprint

func (a *APIKeyAuthenticator) UserForFingerprint(fingerprint string) (string, bool)

func (*APIKeyAuthenticator) Users

func (a *APIKeyAuthenticator) Users() []UserInfo

type AdminSet

type AdminSet struct {
	// contains filtered or unexported fields
}

func NewAdminSet

func NewAdminSet(ids []string) *AdminSet

func (*AdminSet) IsAdmin

func (s *AdminSet) IsAdmin(id string) bool

func (*AdminSet) Replace

func (s *AdminSet) Replace(ids []string)

type Authenticator

type Authenticator interface {
	// Authenticate validates a token and returns the associated user ID
	Authenticate(ctx context.Context, token string) (userID string, err error)
}

Authenticator defines the interface for user authentication

type Authorizer

type Authorizer interface {
	// Authorize checks if a user has the specified permission for a path
	Authorize(ctx context.Context, userID string, path string, perm PermissionType) error

	// AuthorizeWithMetadata performs the same check as Authorize using
	// metadata the caller already fetched for path; md nil means path does
	// not exist.
	AuthorizeWithMetadata(ctx context.Context, userID string, path string, md *metadata.Metadata, perm PermissionType) error
}

Authorizer defines the interface for authorization checks

type Decision

type Decision struct {
	Allowed bool   `json:"allowed"`
	Reason  string `json:"reason"`
	Owner   string `json:"owner"`
	Type    string `json:"type"`
}

type OwnerAliases

type OwnerAliases interface {
	LegacyAliases(userID string) []string
}

UnixAuthorizer implements permission checking using app-level ownership. Authorization is based on the app user ID string (Owner field in metadata), NOT on OS-level UIDs/GIDs. App users have no relationship to OS users.

type PermissionType

type PermissionType int

PermissionType represents different permission types for authorization

const (
	ReadPerm PermissionType = iota
	WritePerm
	DeletePerm
)

type SessionClaims

type SessionClaims struct {
	UserID      string
	Fingerprint string
	IssuedAt    time.Time
	ExpiresAt   time.Time
	CSRF        string
}

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

func NewSessionManager

func NewSessionManager(key []byte, ttl time.Duration) *SessionManager

func (*SessionManager) AcceptRevocation

func (m *SessionManager) AcceptRevocation(id string, expiresAt time.Time)

func (*SessionManager) Issue

func (m *SessionManager) Issue(userID, keyFingerprint string) (string, string, time.Time, error)

func (*SessionManager) Revoke

func (m *SessionManager) Revoke(cookieValue string) error

func (*SessionManager) SetRevocationPublisher

func (m *SessionManager) SetRevocationPublisher(publisher SessionRevocationPublisher)

func (*SessionManager) Verify

func (m *SessionManager) Verify(cookieValue string) (SessionClaims, error)

type SessionRevocationPublisher

type SessionRevocationPublisher interface {
	Publish(id string, expiresAt time.Time) error
}

type UnixAuthorizer

type UnixAuthorizer struct {
	// contains filtered or unexported fields
}

func NewUnixAuthorizer

func NewUnixAuthorizer(metadataStore metadata.Store, aliases OwnerAliases) *UnixAuthorizer

func (*UnixAuthorizer) Authorize

func (a *UnixAuthorizer) Authorize(ctx context.Context, userID string, path string, perm PermissionType) error

Authorize checks if a user has the specified permission for a path

func (*UnixAuthorizer) AuthorizeWithMetadata

func (a *UnixAuthorizer) AuthorizeWithMetadata(ctx context.Context, userID string, path string, md *metadata.Metadata, perm PermissionType) error

func (*UnixAuthorizer) Explain

func (a *UnixAuthorizer) Explain(ctx context.Context, userID string, path string, perm PermissionType) (Decision, error)

func (*UnixAuthorizer) SetAdmins

func (a *UnixAuthorizer) SetAdmins(admins *AdminSet)

type UserInfo

type UserInfo struct {
	UserID         string `json:"user_id"`
	Source         string `json:"source"`
	Index          *int   `json:"index"`
	KeyHint        string `json:"key_hint"`
	KeyFingerprint string `json:"key_fingerprint"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL