Documentation
¶
Index ¶
- Variables
- func AddMetadata(ctx context.Context, key string, value interface{}) context.Context
- func GetMetadata(ctx context.Context) map[string]interface{}
- func GetRequestID(ctx context.Context) string
- func GetToken(ctx context.Context) (string, bool)
- func IsPermissionDenied(err error) bool
- func NewPermissionError(path string, op Operation, userID string, reason string) error
- func SavePolicy(policy *PolicyFile, w io.Writer, format PolicyFormat) error
- func SavePolicyToFile(policy *PolicyFile, filename string, format PolicyFormat) error
- func WithIdentity(ctx context.Context, identity *Identity) context.Context
- func WithMetadata(ctx context.Context, metadata map[string]interface{}) context.Context
- func WithRequestID(ctx context.Context, requestID string) context.Context
- func WithToken(ctx context.Context, token string) context.Context
- func WithUser(ctx context.Context, userID string) context.Context
- func WithUserAndGroups(ctx context.Context, userID string, groups []string) context.Context
- func WithUserGroupsAndRoles(ctx context.Context, userID string, groups, roles []string) context.Context
- type ACL
- type ACLEntry
- type APIKeyAuthenticator
- type AbsAdapter
- func (a *AbsAdapter) Chdir(dir string) error
- func (a *AbsAdapter) Chmod(name string, mode os.FileMode) error
- func (a *AbsAdapter) Chown(name string, uid, gid int) error
- func (a *AbsAdapter) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (a *AbsAdapter) Create(name string) (absfs.File, error)
- func (a *AbsAdapter) Getwd() (string, error)
- func (a *AbsAdapter) Lchown(name string, uid, gid int) error
- func (a *AbsAdapter) Lstat(name string) (os.FileInfo, error)
- func (a *AbsAdapter) Mkdir(name string, perm os.FileMode) error
- func (a *AbsAdapter) MkdirAll(name string, perm os.FileMode) error
- func (a *AbsAdapter) Open(name string) (absfs.File, error)
- func (a *AbsAdapter) OpenFile(name string, flag int, perm os.FileMode) (absfs.File, error)
- func (a *AbsAdapter) PermFS() *PermFS
- func (a *AbsAdapter) ReadDir(name string) ([]fs.DirEntry, error)
- func (a *AbsAdapter) ReadFile(name string) ([]byte, error)
- func (a *AbsAdapter) Readlink(name string) (string, error)
- func (a *AbsAdapter) Remove(name string) error
- func (a *AbsAdapter) RemoveAll(path string) error
- func (a *AbsAdapter) Rename(oldpath, newpath string) error
- func (a *AbsAdapter) SetContext(ctx context.Context)
- func (a *AbsAdapter) SetIdentity(identity *Identity)
- func (a *AbsAdapter) Stat(name string) (os.FileInfo, error)
- func (a *AbsAdapter) Sub(dir string) (fs.FS, error)
- func (a *AbsAdapter) Symlink(oldname, newname string) error
- func (a *AbsAdapter) TempDir() string
- func (a *AbsAdapter) Truncate(name string, size int64) error
- type AndCondition
- type AuditConfig
- type AuditEvent
- type AuditHandler
- type AuditLevel
- type AuditLogger
- type AuditMetrics
- type AuditResult
- type AuditStats
- type Authenticator
- type CacheEntry
- type CacheKey
- type CacheStats
- type ChainAuthenticator
- type Condition
- type Config
- type CustomConditionFunc
- type Effect
- type EvaluationContext
- type Evaluator
- func (e *Evaluator) CanAccessMetadata(identity *Identity, path string) bool
- func (e *Evaluator) CanDelete(identity *Identity, path string) bool
- func (e *Evaluator) CanExecute(identity *Identity, path string) bool
- func (e *Evaluator) CanRead(identity *Identity, path string) bool
- func (e *Evaluator) CanWrite(identity *Identity, path string) bool
- func (e *Evaluator) ClearCache()
- func (e *Evaluator) Evaluate(ctx *EvaluationContext) (bool, error)
- func (e *Evaluator) GetCacheStats() *CacheStats
- func (e *Evaluator) GetEffectivePermissions(identity *Identity, path string) Operation
- func (e *Evaluator) GetMatchingEntries(ctx *EvaluationContext) []ACLEntry
- func (e *Evaluator) InvalidateCache(userID string, pathPrefix string)
- func (e *Evaluator) IsAdmin(identity *Identity, path string) bool
- type File
- type FileSystem
- type FuncAuthenticator
- type FuncCondition
- type HeaderAuthenticator
- type HourRange
- type IPCondition
- type Identity
- type MetadataCondition
- type NotCondition
- type Operation
- type OperationSet
- type OrCondition
- type PathAccessStat
- type PatternCache
- type PatternMatcher
- type PerformanceConfig
- type PermFS
- func (pfs *PermFS) AddRule(entry ACLEntry) error
- func (pfs *PermFS) Chmod(ctx context.Context, name string, mode os.FileMode) error
- func (pfs *PermFS) Chown(ctx context.Context, name string, uid, gid int) error
- func (pfs *PermFS) Chtimes(ctx context.Context, name string, atime, mtime time.Time) error
- func (pfs *PermFS) ClearCache()
- func (pfs *PermFS) Close() error
- func (pfs *PermFS) GetAuditMetrics() *AuditMetrics
- func (pfs *PermFS) GetAuditStats() AuditStats
- func (pfs *PermFS) GetCacheStats() *CacheStats
- func (pfs *PermFS) GetEffectiveRules(path string) []ACLEntry
- func (pfs *PermFS) GetPermissions(ctx context.Context, path string) (Operation, error)
- func (pfs *PermFS) InvalidateCache(userID string, pathPrefix string)
- func (pfs *PermFS) Lstat(ctx context.Context, name string) (os.FileInfo, error)
- func (pfs *PermFS) Mkdir(ctx context.Context, name string, perm os.FileMode) error
- func (pfs *PermFS) MkdirAll(ctx context.Context, name string, perm os.FileMode) error
- func (pfs *PermFS) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (File, error)
- func (pfs *PermFS) ReadDir(ctx context.Context, name string) ([]os.FileInfo, error)
- func (pfs *PermFS) Remove(ctx context.Context, name string) error
- func (pfs *PermFS) RemoveAll(ctx context.Context, name string) error
- func (pfs *PermFS) RemoveRule(entry ACLEntry) error
- func (pfs *PermFS) Rename(ctx context.Context, oldname, newname string) error
- func (pfs *PermFS) Stat(ctx context.Context, name string) (os.FileInfo, error)
- func (pfs *PermFS) TestPermission(identity *Identity, path string, op Operation) (bool, *PermissionTestResult)
- type PermissionCache
- func (pc *PermissionCache) Clear()
- func (pc *PermissionCache) Disable()
- func (pc *PermissionCache) Enable()
- func (pc *PermissionCache) Get(key CacheKey) (allowed bool, found bool)
- func (pc *PermissionCache) Invalidate(userID string, pathPrefix string)
- func (pc *PermissionCache) IsEnabled() bool
- func (pc *PermissionCache) Set(key CacheKey, allowed bool)
- func (pc *PermissionCache) Stats() CacheStats
- type PermissionError
- type PermissionTestResult
- type PolicyEntryExport
- type PolicyFile
- type PolicyFormat
- type RuleConflict
- type StaticAuthenticator
- type Subject
- type SubjectExport
- type SubjectType
- type TimeCondition
- type TokenAuthenticator
- type UserDenialStat
- type ValidationError
- type ValidationResult
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPermissionDenied is returned when a permission check fails ErrPermissionDenied = errors.New("permission denied") // ErrNoIdentity is returned when no identity is found in context ErrNoIdentity = errors.New("no identity in context") // ErrInvalidPattern is returned when a path pattern is invalid ErrInvalidPattern = errors.New("invalid path pattern") // ErrInvalidConfig is returned when configuration is invalid ErrInvalidConfig = errors.New("invalid configuration") )
var ( Read = OperationRead Write = OperationWrite Execute = OperationExecute Delete = OperationDelete Metadata = OperationMetadata Admin = OperationAdmin ReadWrite = OperationRead | OperationWrite All = OperationAll )
Common permission combinations
var ( Allow = EffectAllow Deny = EffectDeny )
Functions ¶
func AddMetadata ¶
AddMetadata adds a key-value pair to the context metadata
func GetMetadata ¶
GetMetadata extracts metadata from the context
func GetRequestID ¶
GetRequestID retrieves the request ID from the context
func IsPermissionDenied ¶
IsPermissionDenied checks if an error is a permission denial
func NewPermissionError ¶
NewPermissionError creates a new permission error
func SavePolicy ¶
func SavePolicy(policy *PolicyFile, w io.Writer, format PolicyFormat) error
SavePolicy saves a policy to a writer
func SavePolicyToFile ¶
func SavePolicyToFile(policy *PolicyFile, filename string, format PolicyFormat) error
SavePolicyToFile saves a policy to a file
func WithIdentity ¶
WithIdentity returns a new context with the given identity
func WithMetadata ¶
WithMetadata returns a new context with additional metadata
func WithRequestID ¶
WithRequestID adds a request ID to the context
func WithToken ¶
WithToken returns a new context with an authentication token The token can be used by authenticators to extract identity
func WithUserAndGroups ¶
WithUserAndGroups returns a new context with a user identity including groups
Types ¶
type ACL ¶
type ACL struct {
// Entries is the list of ACL rules
Entries []ACLEntry
// Default is the default effect when no rules match
Default Effect
}
ACL represents a complete access control list
func ImportPolicy ¶
func ImportPolicy(policy *PolicyFile) (ACL, error)
ImportPolicy imports a policy file into an ACL
func OptimizeACL ¶
OptimizeACL optimizes an ACL by removing redundant rules
type ACLEntry ¶
type ACLEntry struct {
// Subject specifies who this rule applies to
Subject Subject
// PathPattern is a glob pattern matching filesystem paths
PathPattern string
// Permissions specifies which operations are allowed/denied
Permissions Operation
// Effect specifies whether to allow or deny access
Effect Effect
// Priority is used for conflict resolution (higher priority wins)
Priority int
// Conditions are optional conditions that must be satisfied
Conditions []Condition
}
ACLEntry represents a single access control rule
func (ACLEntry) Applies ¶
Applies checks if this entry's permissions apply to the requested operation
func (ACLEntry) Matches ¶
func (e ACLEntry) Matches(ctx *EvaluationContext) bool
Matches checks if this entry applies to the given context
type APIKeyAuthenticator ¶
type APIKeyAuthenticator struct {
// contains filtered or unexported fields
}
APIKeyAuthenticator authenticates using API keys
func NewAPIKeyAuthenticator ¶
func NewAPIKeyAuthenticator() *APIKeyAuthenticator
NewAPIKeyAuthenticator creates a new API key authenticator
func (*APIKeyAuthenticator) AddAPIKey ¶
func (aka *APIKeyAuthenticator) AddAPIKey(apiKey string, identity *Identity)
AddAPIKey adds an API key
func (*APIKeyAuthenticator) Authenticate ¶
func (aka *APIKeyAuthenticator) Authenticate(ctx context.Context) (*Identity, error)
Authenticate extracts identity from context using API key
func (*APIKeyAuthenticator) AuthenticateToken ¶
func (aka *APIKeyAuthenticator) AuthenticateToken(apiKey string) (*Identity, error)
AuthenticateToken validates an API key
type AbsAdapter ¶
type AbsAdapter struct {
// contains filtered or unexported fields
}
AbsAdapter wraps a PermFS to implement absfs.FileSystem interface. It stores a context internally which is used for all permission checks. The context can be updated via SetContext or SetIdentity methods.
func NewAbsAdapter ¶
func NewAbsAdapter(pfs *PermFS, identity *Identity) *AbsAdapter
NewAbsAdapter creates a new absfs.FileSystem compatible wrapper around PermFS. The provided identity will be used for all permission checks. If identity is nil, all operations will fail with ErrNoIdentity until an identity is set.
func NewAbsAdapterWithContext ¶
func NewAbsAdapterWithContext(pfs *PermFS, ctx context.Context) *AbsAdapter
NewAbsAdapterWithContext creates a new absfs.FileSystem compatible wrapper using the provided context for permission checks.
func (*AbsAdapter) Chdir ¶
func (a *AbsAdapter) Chdir(dir string) error
Chdir changes the current working directory.
func (*AbsAdapter) Chmod ¶
func (a *AbsAdapter) Chmod(name string, mode os.FileMode) error
Chmod changes the mode of the named file.
func (*AbsAdapter) Chown ¶
func (a *AbsAdapter) Chown(name string, uid, gid int) error
Chown changes the numeric uid and gid of the named file.
func (*AbsAdapter) Create ¶
func (a *AbsAdapter) Create(name string) (absfs.File, error)
Create creates or truncates the named file.
func (*AbsAdapter) Getwd ¶
func (a *AbsAdapter) Getwd() (string, error)
Getwd returns the current working directory.
func (*AbsAdapter) Lchown ¶
func (a *AbsAdapter) Lchown(name string, uid, gid int) error
Lchown changes the numeric uid and gid of the named file without following symlinks. Note: This delegates to Chown as the underlying filesystem may not support Lchown.
func (*AbsAdapter) Lstat ¶
func (a *AbsAdapter) Lstat(name string) (os.FileInfo, error)
Lstat returns file info without following symlinks.
func (*AbsAdapter) Mkdir ¶
func (a *AbsAdapter) Mkdir(name string, perm os.FileMode) error
Mkdir creates a directory.
func (*AbsAdapter) MkdirAll ¶
func (a *AbsAdapter) MkdirAll(name string, perm os.FileMode) error
MkdirAll creates a directory and all parent directories.
func (*AbsAdapter) Open ¶
func (a *AbsAdapter) Open(name string) (absfs.File, error)
Open opens the named file for reading.
func (*AbsAdapter) PermFS ¶
func (a *AbsAdapter) PermFS() *PermFS
PermFS returns the underlying PermFS instance.
func (*AbsAdapter) ReadDir ¶
func (a *AbsAdapter) ReadDir(name string) ([]fs.DirEntry, error)
ReadDir reads the named directory and returns directory entries.
func (*AbsAdapter) ReadFile ¶
func (a *AbsAdapter) ReadFile(name string) ([]byte, error)
ReadFile reads the named file and returns its contents.
func (*AbsAdapter) Readlink ¶
func (a *AbsAdapter) Readlink(name string) (string, error)
Readlink returns the destination of the named symbolic link.
func (*AbsAdapter) Remove ¶
func (a *AbsAdapter) Remove(name string) error
Remove removes a file or empty directory.
func (*AbsAdapter) RemoveAll ¶
func (a *AbsAdapter) RemoveAll(path string) error
RemoveAll removes path and any children it contains.
func (*AbsAdapter) Rename ¶
func (a *AbsAdapter) Rename(oldpath, newpath string) error
Rename renames (moves) a file.
func (*AbsAdapter) SetContext ¶
func (a *AbsAdapter) SetContext(ctx context.Context)
SetContext updates the context used for permission checking. This is useful when the identity needs to change during the adapter's lifetime.
func (*AbsAdapter) SetIdentity ¶
func (a *AbsAdapter) SetIdentity(identity *Identity)
SetIdentity updates the identity used for permission checking. This creates a new context with the provided identity.
func (*AbsAdapter) Stat ¶
func (a *AbsAdapter) Stat(name string) (os.FileInfo, error)
Stat returns file information.
func (*AbsAdapter) Sub ¶
func (a *AbsAdapter) Sub(dir string) (fs.FS, error)
Sub returns a filesystem rooted at dir.
func (*AbsAdapter) Symlink ¶
func (a *AbsAdapter) Symlink(oldname, newname string) error
Symlink creates newname as a symbolic link to oldname.
func (*AbsAdapter) TempDir ¶
func (a *AbsAdapter) TempDir() string
TempDir returns the default directory for temporary files.
type AndCondition ¶
type AndCondition struct {
Conditions []Condition
}
AndCondition requires all sub-conditions to be true
func (*AndCondition) Evaluate ¶
func (ac *AndCondition) Evaluate(ctx *EvaluationContext) bool
Evaluate checks if all conditions are satisfied
func (*AndCondition) String ¶
func (ac *AndCondition) String() string
String returns a string representation
type AuditConfig ¶
type AuditConfig struct {
// Enabled enables audit logging
Enabled bool
// Writer is where audit logs are written (defaults to os.Stdout)
Writer io.Writer
// Level controls what events are logged
Level *AuditLevel
// Async enables asynchronous logging
Async bool
// BufferSize is the size of the async buffer (default: 1000)
BufferSize int
// Handler is an optional custom event handler
Handler AuditHandler
}
AuditConfig contains audit logging configuration (Phase 3)
type AuditEvent ¶
type AuditEvent struct {
// Timestamp is when the event occurred
Timestamp time.Time `json:"timestamp"`
// RequestID is a unique identifier for the request
RequestID string `json:"request_id,omitempty"`
// UserID is the user who attempted the operation
UserID string `json:"user_id"`
// Groups are the groups the user belongs to
Groups []string `json:"groups,omitempty"`
// Roles are the roles assigned to the user
Roles []string `json:"roles,omitempty"`
// Operation is the filesystem operation attempted
Operation string `json:"operation"`
// Path is the filesystem path accessed
Path string `json:"path"`
// Result is whether access was allowed or denied
Result AuditResult `json:"result"`
// Reason provides additional context for the result
Reason string `json:"reason,omitempty"`
// Duration is how long the permission check took
Duration time.Duration `json:"duration_ms"`
// Metadata contains additional context information
Metadata map[string]interface{} `json:"metadata,omitempty"`
// SourceIP is the IP address of the request (if available)
SourceIP string `json:"source_ip,omitempty"`
}
AuditEvent represents a single audit log entry
type AuditHandler ¶
type AuditHandler func(event *AuditEvent)
AuditHandler is a function that processes audit events
type AuditLevel ¶
type AuditLevel int
AuditLevel defines the verbosity of audit logging
const ( // AuditLevelNone disables audit logging AuditLevelNone AuditLevel = iota // AuditLevelDenied logs only denied access attempts AuditLevelDenied // AuditLevelAll logs all access attempts AuditLevelAll )
type AuditLogger ¶
type AuditLogger struct {
// contains filtered or unexported fields
}
AuditLogger handles audit logging
func NewAuditLogger ¶
func NewAuditLogger(config AuditConfig) *AuditLogger
NewAuditLogger creates a new audit logger
func (*AuditLogger) GetMetrics ¶
func (al *AuditLogger) GetMetrics() *AuditMetrics
GetMetrics returns audit metrics
type AuditMetrics ¶
type AuditMetrics struct {
// contains filtered or unexported fields
}
AuditMetrics tracks audit logging statistics
func NewAuditMetrics ¶
func NewAuditMetrics() *AuditMetrics
NewAuditMetrics creates a new metrics tracker
func (*AuditMetrics) GetStats ¶
func (am *AuditMetrics) GetStats() AuditStats
GetStats returns current metrics
func (*AuditMetrics) GetTopAccessedPaths ¶
func (am *AuditMetrics) GetTopAccessedPaths(limit int) []PathAccessStat
GetTopAccessedPaths returns most accessed paths
func (*AuditMetrics) GetTopDeniedUsers ¶
func (am *AuditMetrics) GetTopDeniedUsers(limit int) []UserDenialStat
GetTopDeniedUsers returns users with most denials
func (*AuditMetrics) IncrementDropped ¶
func (am *AuditMetrics) IncrementDropped()
IncrementDropped increments the dropped events counter
func (*AuditMetrics) RecordEvent ¶
func (am *AuditMetrics) RecordEvent(event *AuditEvent)
RecordEvent records metrics for an audit event
type AuditResult ¶
type AuditResult string
AuditResult represents the result of an access attempt
const ( // AuditResultAllowed indicates access was granted AuditResultAllowed AuditResult = "allowed" // AuditResultDenied indicates access was denied AuditResultDenied AuditResult = "denied" // AuditResultError indicates an error occurred AuditResultError AuditResult = "error" )
type AuditStats ¶
type AuditStats struct {
TotalEvents uint64
AllowedEvents uint64
DeniedEvents uint64
ErrorEvents uint64
DroppedEvents uint64
AverageDuration time.Duration
}
AuditStats contains audit statistics
type Authenticator ¶
type Authenticator interface {
// Authenticate extracts and validates identity from the context
Authenticate(ctx context.Context) (*Identity, error)
}
Authenticator is an interface for extracting identity from a context or token
type CacheEntry ¶
type CacheEntry struct {
Key CacheKey
Allowed bool
ExpiresAt time.Time
// contains filtered or unexported fields
}
CacheEntry represents a cached permission evaluation result
func (*CacheEntry) IsExpired ¶
func (ce *CacheEntry) IsExpired() bool
IsExpired checks if the cache entry has expired
type CacheStats ¶
type CacheStats struct {
Size int
MaxSize int
Hits uint64
Misses uint64
Evictions uint64
HitRate float64
}
CacheStats contains cache statistics
type ChainAuthenticator ¶
type ChainAuthenticator struct {
// contains filtered or unexported fields
}
ChainAuthenticator tries multiple authenticators in order
func NewChainAuthenticator ¶
func NewChainAuthenticator(authenticators ...Authenticator) *ChainAuthenticator
NewChainAuthenticator creates a new chain authenticator
func (*ChainAuthenticator) Authenticate ¶
func (ca *ChainAuthenticator) Authenticate(ctx context.Context) (*Identity, error)
Authenticate tries each authenticator in order
type Condition ¶
type Condition interface {
// Evaluate checks if the condition is satisfied
Evaluate(ctx *EvaluationContext) bool
// String returns a string representation of the condition
String() string
}
Condition represents a conditional check that must pass for an ACL entry to apply
type Config ¶
type Config struct {
// ACL is the access control list
ACL ACL
// Audit configuration (placeholder for Phase 3)
Audit AuditConfig
// Performance configuration (placeholder for Phase 2)
Performance PerformanceConfig
}
Config contains configuration for a permission filesystem
type CustomConditionFunc ¶
type CustomConditionFunc func(ctx *EvaluationContext) bool
CustomConditionFunc is a function type for custom conditions
type EvaluationContext ¶
type EvaluationContext struct {
// Identity contains user, group, and role information
Identity *Identity
// Path is the filesystem path being accessed
Path string
// Operation is the operation being attempted
Operation Operation
// Metadata contains additional context information
Metadata map[string]interface{}
}
EvaluationContext contains information needed to evaluate permissions
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator evaluates permissions based on ACL rules
func NewEvaluator ¶
NewEvaluator creates a new permission evaluator
func NewEvaluatorWithCache ¶
func NewEvaluatorWithCache(acl ACL, cache *PermissionCache, patternCache *PatternCache) *Evaluator
NewEvaluatorWithCache creates a new evaluator with caching enabled
func (*Evaluator) CanAccessMetadata ¶
CanAccessMetadata checks if the identity can access metadata for the path
func (*Evaluator) CanExecute ¶
CanExecute checks if the identity can execute the path
func (*Evaluator) ClearCache ¶
func (e *Evaluator) ClearCache()
ClearCache clears the permission cache
func (*Evaluator) Evaluate ¶
func (e *Evaluator) Evaluate(ctx *EvaluationContext) (bool, error)
Evaluate checks if the given operation is allowed for the context
func (*Evaluator) GetCacheStats ¶
func (e *Evaluator) GetCacheStats() *CacheStats
GetCacheStats returns cache statistics
func (*Evaluator) GetEffectivePermissions ¶
GetEffectivePermissions returns the effective permissions for a path and identity
func (*Evaluator) GetMatchingEntries ¶
func (e *Evaluator) GetMatchingEntries(ctx *EvaluationContext) []ACLEntry
GetMatchingEntries returns all ACL entries that match the given context
func (*Evaluator) InvalidateCache ¶
InvalidateCache invalidates cache entries for a user and/or path prefix
type File ¶
type File interface {
fs.File
// Write writes data to the file
Write(p []byte) (n int, err error)
// WriteAt writes data at the specified offset
WriteAt(p []byte, off int64) (n int, err error)
// Read reads data from the file
Read(p []byte) (n int, err error)
// ReadAt reads data from the specified offset
ReadAt(p []byte, off int64) (n int, err error)
// Seek sets the offset for the next Read or Write
Seek(offset int64, whence int) (int64, error)
// Sync commits the current contents of the file
Sync() error
// Truncate changes the size of the file
Truncate(size int64) error
}
File is the interface for file operations
type FileSystem ¶
type FileSystem interface {
// OpenFile opens a file with the specified flag and perm
OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (File, error)
// Mkdir creates a directory
Mkdir(ctx context.Context, name string, perm os.FileMode) error
// MkdirAll creates a directory and all parent directories
MkdirAll(ctx context.Context, name string, perm os.FileMode) error
// Remove removes a file or directory
Remove(ctx context.Context, name string) error
// RemoveAll removes a path and any children it contains
RemoveAll(ctx context.Context, name string) error
// Rename renames (moves) a file
Rename(ctx context.Context, oldname, newname string) error
// Stat returns file info
Stat(ctx context.Context, name string) (os.FileInfo, error)
// Lstat returns file info without following symlinks
Lstat(ctx context.Context, name string) (os.FileInfo, error)
// ReadDir reads the directory and returns file info
ReadDir(ctx context.Context, name string) ([]os.FileInfo, error)
// Chmod changes the mode of the file
Chmod(ctx context.Context, name string, mode os.FileMode) error
// Chown changes the owner and group of the file
Chown(ctx context.Context, name string, uid, gid int) error
// Chtimes changes the access and modification times
Chtimes(ctx context.Context, name string, atime, mtime time.Time) error
}
FileSystem is the interface that permfs wraps This matches the absfs.FileSystem interface
type FuncAuthenticator ¶
FuncAuthenticator wraps a function as an Authenticator
func (FuncAuthenticator) Authenticate ¶
func (fa FuncAuthenticator) Authenticate(ctx context.Context) (*Identity, error)
Authenticate calls the wrapped function
type FuncCondition ¶
type FuncCondition struct {
Name string
Func CustomConditionFunc
}
FuncCondition wraps a function as a Condition
func NewFuncCondition ¶
func NewFuncCondition(name string, fn CustomConditionFunc) *FuncCondition
NewFuncCondition creates a new function-based condition
func (*FuncCondition) Evaluate ¶
func (fc *FuncCondition) Evaluate(ctx *EvaluationContext) bool
Evaluate executes the custom function
func (*FuncCondition) String ¶
func (fc *FuncCondition) String() string
String returns a string representation
type HeaderAuthenticator ¶
type HeaderAuthenticator struct {
// contains filtered or unexported fields
}
HeaderAuthenticator extracts identity from HTTP-style headers in metadata
func NewHeaderAuthenticator ¶
func NewHeaderAuthenticator(userHeader, groupsHeader, rolesHeader string) *HeaderAuthenticator
NewHeaderAuthenticator creates a new header authenticator
func (*HeaderAuthenticator) Authenticate ¶
func (ha *HeaderAuthenticator) Authenticate(ctx context.Context) (*Identity, error)
Authenticate extracts identity from headers in metadata
type IPCondition ¶
type IPCondition struct {
// AllowedNetworks contains allowed CIDR ranges
AllowedNetworks []*net.IPNet
// DeniedNetworks contains explicitly denied CIDR ranges (takes precedence)
DeniedNetworks []*net.IPNet
}
IPCondition checks if the request comes from an allowed IP address or network
func NewIPCondition ¶
func NewIPCondition(allowedCIDRs, deniedCIDRs []string) (*IPCondition, error)
NewIPCondition creates a new IP condition from CIDR strings
func (*IPCondition) Evaluate ¶
func (ic *IPCondition) Evaluate(ctx *EvaluationContext) bool
Evaluate checks if the source IP satisfies the condition
func (*IPCondition) String ¶
func (ic *IPCondition) String() string
String returns a string representation
type Identity ¶
type Identity struct {
// UserID is the unique identifier for the user
UserID string
// Groups is a list of groups the user belongs to
Groups []string
// Roles is a list of roles assigned to the user
Roles []string
// Metadata contains additional identity information
Metadata map[string]string
}
Identity represents a user's identity and group memberships
func GetIdentity ¶
GetIdentity extracts the identity from the context
type MetadataCondition ¶
type MetadataCondition struct {
// Key is the metadata key to check
Key string
// Values are allowed values (any match allows access)
Values []string
// CaseSensitive determines if value comparison is case sensitive
CaseSensitive bool
}
MetadataCondition checks metadata key-value pairs
func (*MetadataCondition) Evaluate ¶
func (mc *MetadataCondition) Evaluate(ctx *EvaluationContext) bool
Evaluate checks if metadata satisfies the condition
func (*MetadataCondition) String ¶
func (mc *MetadataCondition) String() string
String returns a string representation
type NotCondition ¶
type NotCondition struct {
Condition Condition
}
NotCondition inverts a condition
func (*NotCondition) Evaluate ¶
func (nc *NotCondition) Evaluate(ctx *EvaluationContext) bool
Evaluate inverts the result of the wrapped condition
func (*NotCondition) String ¶
func (nc *NotCondition) String() string
String returns a string representation
type Operation ¶
type Operation uint32
Operation represents a filesystem operation type
const ( // OperationRead allows opening files for reading and listing directories OperationRead Operation = 1 << iota // OperationWrite allows creating, modifying, or appending to files OperationWrite // OperationExecute allows executing files OperationExecute // OperationDelete allows removing files or directories OperationDelete // OperationMetadata allows reading/modifying file attributes, permissions, timestamps OperationMetadata // OperationAdmin allows full control including permission changes OperationAdmin // OperationAll grants all permissions OperationAll Operation = OperationRead | OperationWrite | OperationExecute | OperationDelete | OperationMetadata | OperationAdmin )
type OperationSet ¶
type OperationSet = Operation
OperationSet is an alias for Operation (for backwards compatibility with API examples)
type OrCondition ¶
type OrCondition struct {
Conditions []Condition
}
OrCondition requires at least one sub-condition to be true
func (*OrCondition) Evaluate ¶
func (oc *OrCondition) Evaluate(ctx *EvaluationContext) bool
Evaluate checks if any condition is satisfied
func (*OrCondition) String ¶
func (oc *OrCondition) String() string
String returns a string representation
type PathAccessStat ¶
PathAccessStat tracks access count for a path
type PatternCache ¶
type PatternCache struct {
// contains filtered or unexported fields
}
PatternCache caches compiled path patterns
func NewPatternCache ¶
func NewPatternCache() *PatternCache
NewPatternCache creates a new pattern cache
func (*PatternCache) Get ¶
func (pc *PatternCache) Get(pattern string) (*PatternMatcher, bool)
Get retrieves a cached pattern matcher
func (*PatternCache) GetOrCreate ¶
func (pc *PatternCache) GetOrCreate(pattern string) (*PatternMatcher, error)
GetOrCreate gets a cached pattern or creates a new one
func (*PatternCache) Set ¶
func (pc *PatternCache) Set(pattern string, matcher *PatternMatcher)
Set stores a pattern matcher in the cache
func (*PatternCache) Size ¶
func (pc *PatternCache) Size() int
Size returns the number of cached patterns
type PatternMatcher ¶
type PatternMatcher struct {
// contains filtered or unexported fields
}
PatternMatcher provides compiled pattern matching
func NewPatternMatcher ¶
func NewPatternMatcher(pattern string) (*PatternMatcher, error)
NewPatternMatcher creates a new pattern matcher
func (*PatternMatcher) Match ¶
func (pm *PatternMatcher) Match(pathStr string) (bool, error)
Match checks if a path matches the pattern
func (*PatternMatcher) Pattern ¶
func (pm *PatternMatcher) Pattern() string
Pattern returns the original pattern string
type PerformanceConfig ¶
type PerformanceConfig struct {
// CacheEnabled enables permission result caching
CacheEnabled bool
// CacheTTL is the time-to-live for cache entries
CacheTTL time.Duration
// CacheMaxSize is the maximum number of entries in the cache
CacheMaxSize int
// PatternCacheEnabled enables pattern compilation caching
PatternCacheEnabled bool
}
PerformanceConfig contains performance optimization settings (Phase 2)
type PermFS ¶
type PermFS struct {
// contains filtered or unexported fields
}
PermFS wraps a FileSystem with permission checking
func New ¶
func New(base FileSystem, config Config) (*PermFS, error)
New creates a new permission filesystem
func NewPermFSWithAuthenticator ¶
func NewPermFSWithAuthenticator(base FileSystem, config Config, auth Authenticator) (*PermFS, error)
NewPermFSWithAuthenticator creates a new PermFS with an authenticator
func (*PermFS) Chtimes ¶
Chtimes changes file access and modification times with permission checking
func (*PermFS) GetAuditMetrics ¶
func (pfs *PermFS) GetAuditMetrics() *AuditMetrics
GetAuditMetrics returns the audit metrics object
func (*PermFS) GetAuditStats ¶
func (pfs *PermFS) GetAuditStats() AuditStats
GetAuditStats returns audit statistics
func (*PermFS) GetCacheStats ¶
func (pfs *PermFS) GetCacheStats() *CacheStats
GetCacheStats returns cache statistics
func (*PermFS) GetEffectiveRules ¶
GetEffectiveRules returns all ACL entries that apply to a path
func (*PermFS) GetPermissions ¶
GetPermissions returns the effective permissions for a path and identity
func (*PermFS) InvalidateCache ¶
InvalidateCache invalidates cache entries for a user and/or path prefix
func (*PermFS) OpenFile ¶
func (pfs *PermFS) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (File, error)
OpenFile opens a file with permission checking
func (*PermFS) ReadDir ¶
ReadDir reads a directory with permission checking (context-based, returns []os.FileInfo) This method implements the internal FileSystem interface
func (*PermFS) RemoveRule ¶
RemoveRule removes an ACL entry by matching all fields
func (*PermFS) TestPermission ¶
func (pfs *PermFS) TestPermission(identity *Identity, path string, op Operation) (bool, *PermissionTestResult)
TestPermission simulates a permission check without actually performing it
type PermissionCache ¶
type PermissionCache struct {
// contains filtered or unexported fields
}
PermissionCache provides LRU caching for permission evaluations
func NewPermissionCache ¶
func NewPermissionCache(maxSize int, ttl time.Duration) *PermissionCache
NewPermissionCache creates a new permission cache
func (*PermissionCache) Clear ¶
func (pc *PermissionCache) Clear()
Clear removes all entries from the cache
func (*PermissionCache) Get ¶
func (pc *PermissionCache) Get(key CacheKey) (allowed bool, found bool)
Get retrieves a cached permission result
func (*PermissionCache) Invalidate ¶
func (pc *PermissionCache) Invalidate(userID string, pathPrefix string)
Invalidate removes entries matching a pattern
func (*PermissionCache) IsEnabled ¶
func (pc *PermissionCache) IsEnabled() bool
IsEnabled returns whether the cache is enabled
func (*PermissionCache) Set ¶
func (pc *PermissionCache) Set(key CacheKey, allowed bool)
Set stores a permission result in the cache
func (*PermissionCache) Stats ¶
func (pc *PermissionCache) Stats() CacheStats
Stats returns cache statistics
type PermissionError ¶
type PermissionError struct {
// Path is the filesystem path that was denied
Path string
// Operation is the operation that was denied
Operation Operation
// UserID is the user who was denied
UserID string
// Reason provides additional context for the denial
Reason string
}
PermissionError represents a permission denial with additional context
func (*PermissionError) Error ¶
func (e *PermissionError) Error() string
Error implements the error interface
func (*PermissionError) Unwrap ¶
func (e *PermissionError) Unwrap() error
Unwrap returns the underlying error
type PermissionTestResult ¶
type PermissionTestResult struct {
Allowed bool
MatchingEntries []ACLEntry
Path string
Operation Operation
Identity *Identity
}
PermissionTestResult contains the result of a permission test
func (*PermissionTestResult) Explain ¶
func (ptr *PermissionTestResult) Explain() string
Explain returns a human-readable explanation of the permission decision
type PolicyEntryExport ¶
type PolicyEntryExport struct {
Subject SubjectExport `json:"subject" yaml:"subject"`
PathPattern string `json:"path_pattern" yaml:"path_pattern"`
Permissions []string `json:"permissions" yaml:"permissions"`
Effect string `json:"effect" yaml:"effect"`
Priority int `json:"priority" yaml:"priority"`
}
PolicyEntryExport represents a serializable ACL entry
type PolicyFile ¶
type PolicyFile struct {
Version string `json:"version" yaml:"version"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Default string `json:"default" yaml:"default"`
Entries []PolicyEntryExport `json:"entries" yaml:"entries"`
}
PolicyFile represents a serializable policy
func ExportPolicy ¶
func ExportPolicy(acl ACL, description string) *PolicyFile
ExportPolicy exports an ACL to a policy file format
func LoadPolicy ¶
func LoadPolicy(r io.Reader, format PolicyFormat) (*PolicyFile, error)
LoadPolicy loads a policy from a reader
func LoadPolicyFromFile ¶
func LoadPolicyFromFile(filename string, format PolicyFormat) (*PolicyFile, error)
LoadPolicyFromFile loads a policy from a file
type PolicyFormat ¶
type PolicyFormat int
PolicyFormat represents the format of a policy file
const ( // PolicyFormatJSON represents JSON format PolicyFormatJSON PolicyFormat = iota // PolicyFormatYAML represents YAML format PolicyFormatYAML )
type RuleConflict ¶
RuleConflict represents a potential conflict between two rules
func FindConflictingRules ¶
func FindConflictingRules(acl ACL) []RuleConflict
FindConflictingRules finds rules that might conflict with each other
type StaticAuthenticator ¶
type StaticAuthenticator struct {
// contains filtered or unexported fields
}
StaticAuthenticator provides a simple static user mapping
func NewStaticAuthenticator ¶
func NewStaticAuthenticator() *StaticAuthenticator
NewStaticAuthenticator creates a new static authenticator
func (*StaticAuthenticator) AddUser ¶
func (sa *StaticAuthenticator) AddUser(userID string, groups, roles []string)
AddUser adds a user to the static authenticator
func (*StaticAuthenticator) Authenticate ¶
func (sa *StaticAuthenticator) Authenticate(ctx context.Context) (*Identity, error)
Authenticate extracts identity from context
func (*StaticAuthenticator) AuthenticateToken ¶
func (sa *StaticAuthenticator) AuthenticateToken(token string) (*Identity, error)
AuthenticateToken authenticates a token (simple user ID lookup)
type Subject ¶
type Subject struct {
Type SubjectType
ID string
}
Subject represents who an ACL entry applies to
type SubjectExport ¶
SubjectExport represents a serializable subject
type SubjectType ¶
type SubjectType int
SubjectType represents the type of subject in an ACL entry
const ( // SubjectTypeUser represents a specific user SubjectTypeUser SubjectType = iota // SubjectTypeGroup represents a group of users SubjectTypeGroup // SubjectTypeRole represents a role SubjectTypeRole // SubjectTypeEveryone represents all users (wildcard) SubjectTypeEveryone )
func (SubjectType) String ¶
func (st SubjectType) String() string
String returns a string representation of the subject type
type TimeCondition ¶
type TimeCondition struct {
// AllowedHours contains allowed hour ranges (0-23)
AllowedHours []HourRange
// AllowedDays contains allowed days of week (0=Sunday, 6=Saturday)
AllowedDays []time.Weekday
// Timezone for time evaluation (nil uses UTC)
Timezone *time.Location
}
TimeCondition checks if the current time falls within allowed time ranges
func NewBusinessHoursCondition ¶
func NewBusinessHoursCondition() *TimeCondition
NewBusinessHoursCondition creates a condition for standard business hours (9am-5pm, weekdays)
func (*TimeCondition) Evaluate ¶
func (tc *TimeCondition) Evaluate(ctx *EvaluationContext) bool
Evaluate checks if the current time satisfies the condition
func (*TimeCondition) String ¶
func (tc *TimeCondition) String() string
String returns a string representation
type TokenAuthenticator ¶
type TokenAuthenticator interface {
// AuthenticateToken validates a token and returns the identity
AuthenticateToken(token string) (*Identity, error)
}
TokenAuthenticator extracts identity from a token string
type UserDenialStat ¶
UserDenialStat tracks denial count for a user
type ValidationError ¶
ValidationError represents a validation error
func (*ValidationError) Error ¶
func (ve *ValidationError) Error() string
Error implements the error interface
type ValidationResult ¶
type ValidationResult struct {
Valid bool
Errors []ValidationError
}
ValidationResult contains the result of validation
func ValidateACL ¶
func ValidateACL(acl ACL) ValidationResult
ValidateACL validates an ACL configuration
func ValidateACLEntry ¶
func ValidateACLEntry(entry ACLEntry) ValidationResult
ValidateACLEntry validates a single ACL entry
func (*ValidationResult) AddError ¶
func (vr *ValidationResult) AddError(field, message string)
AddError adds an error to the validation result