Documentation
¶
Index ¶
- type AuditLogger
- type Auditor
- type InteractionHandler
- func (h *InteractionHandler) ConfirmAction(ctx context.Context, action, target, detail string, bypass bool) (bool, error)
- func (h *InteractionHandler) ReadLine(ctx context.Context) (string, error)
- func (h *InteractionHandler) ReadSingleKey(ctx context.Context) (string, error)
- func (h *InteractionHandler) SetReader(r io.Reader)
- func (h *InteractionHandler) TerminalLock()
- func (h *InteractionHandler) TerminalUnlock()
- type PathPolicy
- func (p *PathPolicy) GetPaths(writable bool) []string
- func (p *PathPolicy) LoadPaths(writable bool) error
- func (p *PathPolicy) RegisterPath(path string, writable bool)
- func (p *PathPolicy) RemovePath(path string, writable bool) error
- func (p *PathPolicy) SavePaths(ctx context.Context, writable bool) error
- func (p *PathPolicy) SetConfigFile(path string, writable bool)
- func (p *PathPolicy) ValidatePath(path string, writable bool) (string, error)
- type SecurityManager
- func (sm *SecurityManager) Authorize(ctx context.Context, label, detail, reason string, isSafe bool) (bool, error)
- func (sm *SecurityManager) ConfirmDestructiveAction(ctx context.Context, action, target, detail string) (bool, error)
- func (sm *SecurityManager) GetReadOnlyPaths() []string
- func (sm *SecurityManager) GetSafePaths() []string
- func (sm *SecurityManager) IsBypassActive() bool
- func (sm *SecurityManager) IsCommandAllowed(command string) bool
- func (sm *SecurityManager) IsPathSafe(path string) (string, error)
- func (sm *SecurityManager) IsPathWritable(path string) (string, error)
- func (sm *SecurityManager) LoadBypassState()
- func (sm *SecurityManager) LoadReadOnlyPaths() error
- func (sm *SecurityManager) LoadSafePaths() error
- func (sm *SecurityManager) LogAudit(label1, val1, label2, val2 string)
- func (sm *SecurityManager) ReadLine(ctx context.Context) (string, error)
- func (sm *SecurityManager) ReadSingleKey(ctx context.Context) (string, error)
- func (sm *SecurityManager) RegisterReadOnlyPath(path string)
- func (sm *SecurityManager) RegisterSafePath(path string)
- func (sm *SecurityManager) RemoveReadOnlyPath(path string) error
- func (sm *SecurityManager) RemoveSafePath(path string) error
- func (sm *SecurityManager) SaveBypassState(ctx context.Context)
- func (sm *SecurityManager) SaveReadOnlyPaths(ctx context.Context) error
- func (sm *SecurityManager) SaveSafePaths(ctx context.Context) error
- func (sm *SecurityManager) SetBypassActive(active bool)
- func (sm *SecurityManager) SetBypassFile(path string)
- func (sm *SecurityManager) SetCommandsLogFile(path string)
- func (sm *SecurityManager) SetInputReader(r io.Reader)
- func (sm *SecurityManager) SetReadOnlyPathsFile(path string)
- func (sm *SecurityManager) SetSafePathsFile(path string)
- func (sm *SecurityManager) TerminalLock()
- func (sm *SecurityManager) TerminalUnlock()
- type SecurityProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuditLogger ¶
AuditLogger defines the interface for security logging.
type Auditor ¶
type Auditor struct {
// contains filtered or unexported fields
}
Auditor handles security logging.
func (*Auditor) SetLogFile ¶
SetLogFile sets the path for logging executed commands.
type InteractionHandler ¶
type InteractionHandler struct {
// contains filtered or unexported fields
}
InteractionHandler manages terminal locking and user prompts.
func NewInteractionHandler ¶
func NewInteractionHandler(r io.Reader, auditor *Auditor) *InteractionHandler
NewInteractionHandler creates a new InteractionHandler.
func (*InteractionHandler) ConfirmAction ¶
func (h *InteractionHandler) ConfirmAction(ctx context.Context, action, target, detail string, bypass bool) (bool, error)
ConfirmAction prompts the user for confirmation.
func (*InteractionHandler) ReadLine ¶
func (h *InteractionHandler) ReadLine(ctx context.Context) (string, error)
ReadLine reads a line of input.
func (*InteractionHandler) ReadSingleKey ¶
func (h *InteractionHandler) ReadSingleKey(ctx context.Context) (string, error)
ReadSingleKey waits for a single key press.
func (*InteractionHandler) SetReader ¶
func (h *InteractionHandler) SetReader(r io.Reader)
SetReader updates the input reader.
func (*InteractionHandler) TerminalLock ¶
func (h *InteractionHandler) TerminalLock()
TerminalLock locks the terminal for exclusive access.
func (*InteractionHandler) TerminalUnlock ¶
func (h *InteractionHandler) TerminalUnlock()
TerminalUnlock unlocks the terminal.
type PathPolicy ¶
type PathPolicy struct {
// contains filtered or unexported fields
}
PathPolicy manages allowed boundaries and validates paths.
func (*PathPolicy) GetPaths ¶
func (p *PathPolicy) GetPaths(writable bool) []string
GetPaths returns a copy of the registered paths.
func (*PathPolicy) LoadPaths ¶
func (p *PathPolicy) LoadPaths(writable bool) error
LoadPaths reads paths from the config file.
func (*PathPolicy) RegisterPath ¶
func (p *PathPolicy) RegisterPath(path string, writable bool)
RegisterPath adds a path to the allowed boundaries.
func (*PathPolicy) RemovePath ¶
func (p *PathPolicy) RemovePath(path string, writable bool) error
RemovePath removes a path from the allowed boundaries.
func (*PathPolicy) SavePaths ¶
func (p *PathPolicy) SavePaths(ctx context.Context, writable bool) error
SavePaths writes paths to the config file.
func (*PathPolicy) SetConfigFile ¶
func (p *PathPolicy) SetConfigFile(path string, writable bool)
SetConfigFile sets the persistence file for paths.
func (*PathPolicy) ValidatePath ¶
func (p *PathPolicy) ValidatePath(path string, writable bool) (string, error)
ValidatePath checks if a path is allowed. If writable=true, it checks CWD, Temp, and SafePaths. If writable=false, it ALSO checks ReadOnlyPaths.
type SecurityManager ¶
type SecurityManager struct {
Policy *PathPolicy
Interaction *InteractionHandler
Auditor AuditLogger
// contains filtered or unexported fields
}
SecurityManager coordinates path validation, user interaction, and auditing.
func NewSecurityManager ¶
func NewSecurityManager(input io.Reader) *SecurityManager
NewSecurityManager creates a new SecurityManager.
func (*SecurityManager) Authorize ¶
func (sm *SecurityManager) Authorize(ctx context.Context, label, detail, reason string, isSafe bool) (bool, error)
Authorize prompts the user for authorization of a specific command or action.
func (*SecurityManager) ConfirmDestructiveAction ¶
func (sm *SecurityManager) ConfirmDestructiveAction(ctx context.Context, action, target, detail string) (bool, error)
ConfirmDestructiveAction prompts the user for confirmation.
func (*SecurityManager) GetReadOnlyPaths ¶
func (sm *SecurityManager) GetReadOnlyPaths() []string
GetReadOnlyPaths returns read-only paths.
func (*SecurityManager) GetSafePaths ¶
func (sm *SecurityManager) GetSafePaths() []string
GetSafePaths returns safe paths.
func (*SecurityManager) IsBypassActive ¶
func (sm *SecurityManager) IsBypassActive() bool
IsBypassActive returns the current state of bypass_confirmation.
func (*SecurityManager) IsCommandAllowed ¶
func (sm *SecurityManager) IsCommandAllowed(command string) bool
IsCommandAllowed checks if a base command is allowed for execution.
func (*SecurityManager) IsPathSafe ¶
func (sm *SecurityManager) IsPathSafe(path string) (string, error)
IsPathSafe checks if a path is safe.
func (*SecurityManager) IsPathWritable ¶
func (sm *SecurityManager) IsPathWritable(path string) (string, error)
IsPathWritable checks if a path is writable.
func (*SecurityManager) LoadBypassState ¶
func (sm *SecurityManager) LoadBypassState()
LoadBypassState reads the persistent bypass state from disk.
func (*SecurityManager) LoadReadOnlyPaths ¶
func (sm *SecurityManager) LoadReadOnlyPaths() error
LoadReadOnlyPaths loads read-only paths.
func (*SecurityManager) LoadSafePaths ¶
func (sm *SecurityManager) LoadSafePaths() error
LoadSafePaths loads safe paths.
func (*SecurityManager) LogAudit ¶
func (sm *SecurityManager) LogAudit(label1, val1, label2, val2 string)
LogAudit writes an audit entry.
func (*SecurityManager) ReadLine ¶
func (sm *SecurityManager) ReadLine(ctx context.Context) (string, error)
ReadLine reads a line.
func (*SecurityManager) ReadSingleKey ¶
func (sm *SecurityManager) ReadSingleKey(ctx context.Context) (string, error)
ReadSingleKey reads a single key.
func (*SecurityManager) RegisterReadOnlyPath ¶
func (sm *SecurityManager) RegisterReadOnlyPath(path string)
RegisterReadOnlyPath registers a read-only path.
func (*SecurityManager) RegisterSafePath ¶
func (sm *SecurityManager) RegisterSafePath(path string)
RegisterSafePath registers a safe path.
func (*SecurityManager) RemoveReadOnlyPath ¶
func (sm *SecurityManager) RemoveReadOnlyPath(path string) error
RemoveReadOnlyPath removes a read-only path.
func (*SecurityManager) RemoveSafePath ¶
func (sm *SecurityManager) RemoveSafePath(path string) error
RemoveSafePath removes a safe path.
func (*SecurityManager) SaveBypassState ¶
func (sm *SecurityManager) SaveBypassState(ctx context.Context)
SaveBypassState writes the persistent bypass state to disk.
func (*SecurityManager) SaveReadOnlyPaths ¶
func (sm *SecurityManager) SaveReadOnlyPaths(ctx context.Context) error
SaveReadOnlyPaths saves read-only paths.
func (*SecurityManager) SaveSafePaths ¶
func (sm *SecurityManager) SaveSafePaths(ctx context.Context) error
SaveSafePaths saves safe paths.
func (*SecurityManager) SetBypassActive ¶
func (sm *SecurityManager) SetBypassActive(active bool)
SetBypassActive sets the bypass state.
func (*SecurityManager) SetBypassFile ¶
func (sm *SecurityManager) SetBypassFile(path string)
SetBypassFile sets the file where persistent bypass state is stored.
func (*SecurityManager) SetCommandsLogFile ¶
func (sm *SecurityManager) SetCommandsLogFile(path string)
SetCommandsLogFile sets the commands log file.
func (*SecurityManager) SetInputReader ¶
func (sm *SecurityManager) SetInputReader(r io.Reader)
SetInputReader sets the input reader.
func (*SecurityManager) SetReadOnlyPathsFile ¶
func (sm *SecurityManager) SetReadOnlyPathsFile(path string)
SetReadOnlyPathsFile sets the read-only paths file.
func (*SecurityManager) SetSafePathsFile ¶
func (sm *SecurityManager) SetSafePathsFile(path string)
SetSafePathsFile sets the safe paths file.
func (*SecurityManager) TerminalLock ¶
func (sm *SecurityManager) TerminalLock()
TerminalLock locks the terminal.
func (*SecurityManager) TerminalUnlock ¶
func (sm *SecurityManager) TerminalUnlock()
TerminalUnlock unlocks the terminal.
type SecurityProvider ¶
type SecurityProvider interface {
IsPathSafe(path string) (string, error)
IsPathWritable(path string) (string, error)
ConfirmDestructiveAction(ctx context.Context, action, target, detail string) (bool, error)
TerminalLock()
TerminalUnlock()
IsCommandAllowed(command string) bool
}
SecurityProvider defines the interface for path validation and destructive action confirmation.