Documentation
ΒΆ
Overview ΒΆ
Package opsec provides operational security features for the AegisGate gateway including secure audit logging, secret rotation, memory scrubbing, threat modeling, and runtime hardening.
The OPSEC module implements security controls recommended by NIST SP 800-53 and follows secure coding practices for Go applications handling sensitive data.
Basic Usage:
opsecManager := opsec.New()
opsecManager.EnableAudit()
opsecManager.LogAudit("session_start", map[string]string{
"user": "admin",
"ip": "192.168.1.1",
})
Features:
- Audit Logging: Thread-safe audit trail with integrity verification - Secret Rotation: Automatic or manual secret rotation with configurable periods - Memory Scrubbing: Secure memory wiping to prevent data leakage - Threat Modeling: LLM/AI-specific threat vector catalog - Runtime Hardening: ASLR checks, capability dropping, seccomp profiles
Thread Safety: All OPSEC components are thread-safe and can be safely used concurrently from multiple goroutines.
Security Considerations: - Secrets are stored in memory as base64-encoded strings - Memory scrubbing uses crypto/subtle to prevent compiler optimizations - Audit logs are integrity-protected with SHA-256 hashes - Secret rotation uses crypto/rand for cryptographic randomness
License: This package is part of the AegisGate security gateway and follows the same licensing terms as the main project.
Package opsec provides operational security features for the AegisGate gateway
Index ΒΆ
- Constants
- type AlertCallback
- type AuditEntry
- type AuditFilter
- type AuditLevel
- type ComplianceAuditLog
- func (cal *ComplianceAuditLog) ExportForCompliance(ctx context.Context, format string) ([]byte, error)
- func (cal *ComplianceAuditLog) GetRetentionPeriod() RetentionPeriod
- func (cal *ComplianceAuditLog) GetRetentionUntil() time.Time
- func (cal *ComplianceAuditLog) GetTenantID() string
- func (cal *ComplianceAuditLog) LogComplianceEvent(ctx context.Context, level AuditLevel, eventType string, message string, ...) error
- func (cal *ComplianceAuditLog) PruneOldEntries(ctx context.Context) (int, error)
- func (cal *ComplianceAuditLog) Query(ctx context.Context, filter AuditFilter) ([]*AuditEntry, error)
- func (cal *ComplianceAuditLog) RegisterAlertCallback(level AuditLevel, callback AlertCallback)
- func (cal *ComplianceAuditLog) SetRetentionPeriod(period RetentionPeriod)
- func (cal *ComplianceAuditLog) VerifyIntegrity(ctx context.Context) (bool, []string, error)
- type FileStorageBackend
- func (fs *FileStorageBackend) Close() error
- func (fs *FileStorageBackend) Delete(ctx context.Context, id string) error
- func (fs *FileStorageBackend) Query(ctx context.Context, filter AuditFilter) ([]*AuditEntry, error)
- func (fs *FileStorageBackend) Read(ctx context.Context, id string) (*AuditEntry, error)
- func (fs *FileStorageBackend) Write(ctx context.Context, entry *AuditEntry) error
- type MemoryScrubber
- func (m *MemoryScrubber) MemoryScrub() error
- func (m *MemoryScrubber) ScrubBytes(b []byte) error
- func (m *MemoryScrubber) ScrubMultiple(buffers ...[]byte) error
- func (m *MemoryScrubber) ScrubSecureString(s *string) error
- func (m *MemoryScrubber) ScrubString(s *string) error
- func (m *MemoryScrubber) SecureDelete(b []byte) error
- type OPSECConfig
- func (c *OPSECConfig) GetRotationPeriodDuration() time.Duration
- func (c *OPSECConfig) IsAuditEnabled() bool
- func (c *OPSECConfig) IsMemoryScrubbingEnabled() bool
- func (c *OPSECConfig) IsRotationEnabled() bool
- func (c *OPSECConfig) IsRuntimeHardeningEnabled() bool
- func (c *OPSECConfig) IsThreatModelingEnabled() bool
- func (c *OPSECConfig) Validate() error
- func (c *OPSECConfig) ValidateWithDefaults() error
- type OPSECManager
- func (m *OPSECManager) GetAuditLog() *SecureAuditLog
- func (m *OPSECManager) GetSecret() (string, error)
- func (m *OPSECManager) GetSecretManager() *SecretManager
- func (m *OPSECManager) Initialize() error
- func (m *OPSECManager) IsInitialized() bool
- func (m *OPSECManager) LogAudit(event string, details map[string]string) error
- func (m *OPSECManager) RotateSecret() (string, error)
- func (m *OPSECManager) ScrubBytes(data []byte)
- func (m *OPSECManager) ScrubString(s *string)
- func (m *OPSECManager) Start() error
- func (m *OPSECManager) Stop() error
- type RetentionPeriod
- type RuntimeHardening
- func (r *RuntimeHardening) AreRLimitsSet() bool
- func (r *RuntimeHardening) CanDropCapabilities() bool
- func (r *RuntimeHardening) CheckASLR() bool
- func (r *RuntimeHardening) DropCapabilities() error
- func (r *RuntimeHardening) EnableSeccomp(profile string) error
- func (r *RuntimeHardening) GenerateHardeningReport() map[string]interface{}
- func (r *RuntimeHardening) GetASLRStatus() bool
- func (r *RuntimeHardening) GetCapabilities() ([]string, error)
- func (r *RuntimeHardening) GetRLimits() (map[string]syscall.Rlimit, error)
- func (r *RuntimeHardening) GetSeccompStatus() bool
- func (r *RuntimeHardening) HasCapability(cap int) bool
- func (r *RuntimeHardening) IsHardened() bool
- func (r *RuntimeHardening) Recommendations() []string
- func (r *RuntimeHardening) SecureProcess() (map[string]bool, error)
- func (r *RuntimeHardening) SetRLimits() error
- type SecretManager
- func (s *SecretManager) Destroy()
- func (s *SecretManager) DisableSecretRotation()
- func (s *SecretManager) EnableSecretRotation()
- func (s *SecretManager) GetLastRotation() time.Time
- func (s *SecretManager) GetRotationCount() int
- func (s *SecretManager) GetRotationPeriod() time.Duration
- func (s *SecretManager) GetRotationTimeRemaining() time.Duration
- func (s *SecretManager) GetSecret() (string, error)
- func (s *SecretManager) GetSecretBytes() []byte
- func (s *SecretManager) GetSecretLength() int
- func (s *SecretManager) GetSecretRotationStatus() (bool, time.Duration)
- func (s *SecretManager) IsSecretRotationEnabled() bool
- func (s *SecretManager) IsTimeForRotation() bool
- func (s *SecretManager) RotateIfNecessary() (bool, string, error)
- func (s *SecretManager) RotateSecret() (string, error)
- func (s *SecretManager) SetRotationPeriod(d time.Duration)
- func (s *SecretManager) ValidateSecret(provided string) bool
- type SecretRotationConfig
- type SecureAuditLog
- func (a *SecureAuditLog) ClearAuditLog()
- func (a *SecureAuditLog) DisableAudit()
- func (a *SecureAuditLog) DisableLogIntegrity()
- func (a *SecureAuditLog) EnableAudit()
- func (a *SecureAuditLog) EnableLogIntegrity()
- func (a *SecureAuditLog) ExportToJSON() ([]byte, error)
- func (a *SecureAuditLog) GetAuditLog() []*AuditEntry
- func (a *SecureAuditLog) GetEntriesByLevel(level AuditLevel) []*AuditEntry
- func (a *SecureAuditLog) GetEntriesSince(since time.Time) []*AuditEntry
- func (a *SecureAuditLog) GetEntryCount() int
- func (a *SecureAuditLog) GetLastHash() string
- func (a *SecureAuditLog) ImportFromJSON(data []byte) error
- func (a *SecureAuditLog) IsAuditEnabled() bool
- func (a *SecureAuditLog) IsLogIntegrityEnabled() bool
- func (a *SecureAuditLog) LogAudit(entry *AuditEntry)
- func (a *SecureAuditLog) LogAuditWithLevel(level AuditLevel, message string, data map[string]interface{})
- func (a *SecureAuditLog) SetCallback(callback func(*AuditEntry))
- func (a *SecureAuditLog) SetMaxEntries(max int)
- func (a *SecureAuditLog) VerifyChainIntegrity() (bool, []string)
- type StorageBackend
- type ThreatCategory
- type ThreatEntry
- type ThreatModel
- type ThreatModelingEngine
- func (e *ThreatModelingEngine) AnalyzePatterns(input, output string) []ThreatEntry
- func (e *ThreatModelingEngine) Disable()
- func (e *ThreatModelingEngine) Enable()
- func (e *ThreatModelingEngine) GenerateReport() (map[string]interface{}, error)
- func (e *ThreatModelingEngine) GetActiveModel() *ThreatModel
- func (e *ThreatModelingEngine) GetAllThreats() []ThreatEntry
- func (e *ThreatModelingEngine) GetMitigationStrategy(threatID string) (string, []string, bool)
- func (e *ThreatModelingEngine) GetThreatByID(id string) (ThreatEntry, bool)
- func (e *ThreatModelingEngine) GetThreatsByCategory(category ThreatCategory) []ThreatEntry
- func (e *ThreatModelingEngine) GetThreatsByVector(vector ThreatVector) []ThreatEntry
- func (e *ThreatModelingEngine) IsEnabled() bool
- func (e *ThreatModelingEngine) LoadThreatModel(model *ThreatModel)
- func (e *ThreatModelingEngine) RegisterThreat(threat ThreatEntry) error
- type ThreatVector
Constants ΒΆ
const Version = "1.0.0"
Version holds the current OPSEC module version
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type AlertCallback ΒΆ
type AlertCallback func(ctx context.Context, entry *AuditEntry) error
AlertCallback is a function called when a specific audit level is triggered
type AuditEntry ΒΆ
type AuditEntry struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
Level AuditLevel `json:"level"`
EventType string `json:"event_type"`
Message string `json:"message"`
Data map[string]interface{} `json:"data,omitempty"`
Source string `json:"source"`
Hash string `json:"hash,omitempty"`
PreviousHash string `json:"previous_hash,omitempty"`
ComplianceTags []string `json:"compliance_tags,omitempty"`
TenantID string `json:"tenant_id,omitempty"`
}
AuditEntry represents a single audit log entry
type AuditFilter ΒΆ
type AuditFilter struct {
StartTime time.Time
EndTime time.Time
Levels []AuditLevel
EventTypes []string
Compliance []string // HIPAA, PCI-DSS, SOC2
TenantID string
Source string
SearchText string
Limit int
Offset int
}
AuditFilter defines criteria for querying audit logs
type AuditLevel ΒΆ
type AuditLevel int
AuditLevel represents the severity level of an audit entry
const ( AuditLevelInfo AuditLevel = iota // Informational events AuditLevelWarning // Warning events AuditLevelError // Error events AuditLevelCritical // Critical events AuditLevelAlert // Alert events )
func (AuditLevel) String ΒΆ
func (al AuditLevel) String() string
String returns the string representation of the audit level
type ComplianceAuditLog ΒΆ
type ComplianceAuditLog struct {
*SecureAuditLog
// contains filtered or unexported fields
}
ComplianceAuditLog extends SecureAuditLog with compliance-specific features
func NewComplianceAuditLog ΒΆ
func NewComplianceAuditLog(retention RetentionPeriod, storage StorageBackend, tenantID string) *ComplianceAuditLog
NewComplianceAuditLog creates a new compliance-aware audit log
func (*ComplianceAuditLog) ExportForCompliance ΒΆ
func (cal *ComplianceAuditLog) ExportForCompliance(ctx context.Context, format string) ([]byte, error)
ExportForCompliance exports audit logs in a tamper-evident format
func (*ComplianceAuditLog) GetRetentionPeriod ΒΆ
func (cal *ComplianceAuditLog) GetRetentionPeriod() RetentionPeriod
GetRetentionPeriod returns the current retention period
func (*ComplianceAuditLog) GetRetentionUntil ΒΆ
func (cal *ComplianceAuditLog) GetRetentionUntil() time.Time
GetRetentionUntil returns the date until which entries are retained
func (*ComplianceAuditLog) GetTenantID ΒΆ
func (cal *ComplianceAuditLog) GetTenantID() string
GetTenantID returns the tenant ID for this audit log
func (*ComplianceAuditLog) LogComplianceEvent ΒΆ
func (cal *ComplianceAuditLog) LogComplianceEvent( ctx context.Context, level AuditLevel, eventType string, message string, complianceTags []string, data map[string]interface{}, ) error
LogComplianceEvent logs an event with compliance tags
func (*ComplianceAuditLog) PruneOldEntries ΒΆ
func (cal *ComplianceAuditLog) PruneOldEntries(ctx context.Context) (int, error)
PruneOldEntries removes entries older than the retention period
func (*ComplianceAuditLog) Query ΒΆ
func (cal *ComplianceAuditLog) Query(ctx context.Context, filter AuditFilter) ([]*AuditEntry, error)
Query retrieves audit entries matching the filter
func (*ComplianceAuditLog) RegisterAlertCallback ΒΆ
func (cal *ComplianceAuditLog) RegisterAlertCallback(level AuditLevel, callback AlertCallback)
RegisterAlertCallback registers a callback for a specific audit level
func (*ComplianceAuditLog) SetRetentionPeriod ΒΆ
func (cal *ComplianceAuditLog) SetRetentionPeriod(period RetentionPeriod)
SetRetentionPeriod sets the retention period for audit logs
func (*ComplianceAuditLog) VerifyIntegrity ΒΆ
VerifyIntegrity verifies the integrity of all audit entries
type FileStorageBackend ΒΆ
type FileStorageBackend struct {
// contains filtered or unexported fields
}
FileStorageBackend provides filesystem-based persistent storage
func NewFileStorageBackend ΒΆ
func NewFileStorageBackend(basePath string, maxFileSize int64) (*FileStorageBackend, error)
NewFileStorageBackend creates a new file-based storage backend
func (*FileStorageBackend) Close ΒΆ
func (fs *FileStorageBackend) Close() error
Close closes the storage backend
func (*FileStorageBackend) Delete ΒΆ
func (fs *FileStorageBackend) Delete(ctx context.Context, id string) error
Delete removes an audit entry from storage
func (*FileStorageBackend) Query ΒΆ
func (fs *FileStorageBackend) Query(ctx context.Context, filter AuditFilter) ([]*AuditEntry, error)
Query retrieves audit entries matching the filter
func (*FileStorageBackend) Read ΒΆ
func (fs *FileStorageBackend) Read(ctx context.Context, id string) (*AuditEntry, error)
Read retrieves an audit entry from storage
func (*FileStorageBackend) Write ΒΆ
func (fs *FileStorageBackend) Write(ctx context.Context, entry *AuditEntry) error
Write persists an audit entry to storage
type MemoryScrubber ΒΆ
type MemoryScrubber struct {
// contains filtered or unexported fields
}
MemoryScrubber provides secure memory wiping capabilities
func NewMemoryScrubber ΒΆ
func NewMemoryScrubber() *MemoryScrubber
NewMemoryScrubber creates a new memory scrubber instance
func (*MemoryScrubber) MemoryScrub ΒΆ
func (m *MemoryScrubber) MemoryScrub() error
MemoryScrub is the legacy method retained for compatibility It wipes all sensitive data in the OPSEC system
func (*MemoryScrubber) ScrubBytes ΒΆ
func (m *MemoryScrubber) ScrubBytes(b []byte) error
ScrubBytes securely wipes a byte slice from memory
func (*MemoryScrubber) ScrubMultiple ΒΆ
func (m *MemoryScrubber) ScrubMultiple(buffers ...[]byte) error
ScrubMultiple securely wipes multiple byte slices
func (*MemoryScrubber) ScrubSecureString ΒΆ
func (m *MemoryScrubber) ScrubSecureString(s *string) error
ScrubSecureString uses runtime.KeepAlive for robust scrubbing This implementation avoids unsafe package to satisfy go vetlinting
func (*MemoryScrubber) ScrubString ΒΆ
func (m *MemoryScrubber) ScrubString(s *string) error
ScrubString securely wipes a string from memory Note: In Go, strings are immutable, so this converts to []byte first
func (*MemoryScrubber) SecureDelete ΒΆ
func (m *MemoryScrubber) SecureDelete(b []byte) error
SecureDelete implements secure deletion with multiple passes Pass 1: zeros, Pass 2: ones, Pass 3: random data, Pass 4: zeros
type OPSECConfig ΒΆ
type OPSECConfig struct {
// Audit configuration
AuditEnabled bool `json:"audit_enabled"`
AuditMaxEntries int `json:"audit_max_entries"`
LogIntegrity bool `json:"log_integrity"`
// Secret rotation configuration
RotationEnabled bool `json:"rotation_enabled"`
RotationPeriod time.Duration `json:"rotation_period"`
SecretLength int `json:"secret_length"`
// Memory scrubbing configuration
MemoryScrubbing bool `json:"memory_scrubbing"`
// Runtime hardening configuration
RuntimeHardening bool `json:"runtime_hardening"`
DropCapabilities bool `json:"drop_capabilities"`
// Threat modeling configuration
ThreatModeling bool `json:"threat_modeling"`
}
OPSECConfig contains all configuration options for the OPSEC module
func DefaultOPSECConfig ΒΆ
func DefaultOPSECConfig() OPSECConfig
DefaultOPSECConfig returns a configuration with secure defaults
func HighSecurityConfig ΒΆ
func HighSecurityConfig() OPSECConfig
HighSecurityConfig creates a configuration with maximum security (may have performance impact)
func MinimalConfig ΒΆ
func MinimalConfig() OPSECConfig
MinimalConfig creates a configuration with minimal security features (useful for development/testing only)
func NewConfig ΒΆ
func NewConfig() OPSECConfig
NewConfig creates a new configuration with all features enabled
func (*OPSECConfig) GetRotationPeriodDuration ΒΆ
func (c *OPSECConfig) GetRotationPeriodDuration() time.Duration
GetRotationPeriodDuration returns the rotation period as a time.Duration
func (*OPSECConfig) IsAuditEnabled ΒΆ
func (c *OPSECConfig) IsAuditEnabled() bool
IsAuditEnabled returns whether audit logging is enabled
func (*OPSECConfig) IsMemoryScrubbingEnabled ΒΆ
func (c *OPSECConfig) IsMemoryScrubbingEnabled() bool
IsMemoryScrubbingEnabled returns whether memory scrubbing is enabled
func (*OPSECConfig) IsRotationEnabled ΒΆ
func (c *OPSECConfig) IsRotationEnabled() bool
IsRotationEnabled returns whether secret rotation is enabled
func (*OPSECConfig) IsRuntimeHardeningEnabled ΒΆ
func (c *OPSECConfig) IsRuntimeHardeningEnabled() bool
IsRuntimeHardeningEnabled returns whether runtime hardening is enabled
func (*OPSECConfig) IsThreatModelingEnabled ΒΆ
func (c *OPSECConfig) IsThreatModelingEnabled() bool
IsThreatModelingEnabled returns whether threat modeling is enabled
func (*OPSECConfig) Validate ΒΆ
func (c *OPSECConfig) Validate() error
Validate checks that the configuration is valid
func (*OPSECConfig) ValidateWithDefaults ΒΆ
func (c *OPSECConfig) ValidateWithDefaults() error
ValidateWithDefaults validates the config and applies defaults where needed
type OPSECManager ΒΆ
type OPSECManager struct {
// contains filtered or unexported fields
}
OPSECManager is the operational security manager
func NewWithConfig ΒΆ
func NewWithConfig(config *OPSECConfig) *OPSECManager
NewWithConfig creates a new OPSEC manager with the specified configuration
func (*OPSECManager) GetAuditLog ΒΆ
func (m *OPSECManager) GetAuditLog() *SecureAuditLog
GetAuditLog returns the secure audit log
func (*OPSECManager) GetSecret ΒΆ
func (m *OPSECManager) GetSecret() (string, error)
GetSecret retrieves the current secret
func (*OPSECManager) GetSecretManager ΒΆ
func (m *OPSECManager) GetSecretManager() *SecretManager
GetSecretManager returns the secret manager
func (*OPSECManager) Initialize ΒΆ
func (m *OPSECManager) Initialize() error
Initialize prepares the OPSEC manager for use
func (*OPSECManager) IsInitialized ΒΆ
func (m *OPSECManager) IsInitialized() bool
IsInitialized returns whether the manager has been initialized
func (*OPSECManager) LogAudit ΒΆ
func (m *OPSECManager) LogAudit(event string, details map[string]string) error
LogAudit logs an audit event
func (*OPSECManager) RotateSecret ΒΆ
func (m *OPSECManager) RotateSecret() (string, error)
RotateSecret rotates to a new secret
func (*OPSECManager) ScrubBytes ΒΆ
func (m *OPSECManager) ScrubBytes(data []byte)
ScrubBytes securely clears memory
func (*OPSECManager) ScrubString ΒΆ
func (m *OPSECManager) ScrubString(s *string)
ScrubString securely clears a string from memory
type RetentionPeriod ΒΆ
type RetentionPeriod int
RetentionPeriod represents the configurable retention period
const ( Retention90Days RetentionPeriod = 90 Retention1Year RetentionPeriod = 365 Retention3Years RetentionPeriod = 365 * 3 Retention5Years RetentionPeriod = 365 * 5 Retention7Years RetentionPeriod = 365 * 7 // SOC2/HIPAA requirement Retention10Years RetentionPeriod = 365 * 10 RetentionForever RetentionPeriod = -1 )
type RuntimeHardening ΒΆ
type RuntimeHardening struct {
// contains filtered or unexported fields
}
RuntimeHardening provides security hardening for the running process
func NewRuntimeHardening ΒΆ
func NewRuntimeHardening() *RuntimeHardening
NewRuntimeHardening creates a new runtime hardening manager
func (*RuntimeHardening) AreRLimitsSet ΒΆ
func (r *RuntimeHardening) AreRLimitsSet() bool
AreRLimitsSet returns whether resource limits have been set
func (*RuntimeHardening) CanDropCapabilities ΒΆ
func (r *RuntimeHardening) CanDropCapabilities() bool
CanDropCapabilities returns whether the process can drop capabilities
func (*RuntimeHardening) CheckASLR ΒΆ
func (r *RuntimeHardening) CheckASLR() bool
CheckASLR verifies that ASLR is enabled on the system On Linux/Unix: checks /proc/sys/kernel/randomize_va_space Note: On non-Linux systems, this assumes ASLR is enabled by default
func (*RuntimeHardening) DropCapabilities ΒΆ
func (r *RuntimeHardening) DropCapabilities() error
DropCapabilities attempts to drop unnecessary process capabilities This is a Linux-specific implementation
func (*RuntimeHardening) EnableSeccomp ΒΆ
func (r *RuntimeHardening) EnableSeccomp(profile string) error
EnableSeccomp stub for setting up seccomp BPF filters In production, this would: 1. Load a seccomp policy 2. Allow only necessary syscalls 3. Kill/Trap on forbidden syscalls
func (*RuntimeHardening) GenerateHardeningReport ΒΆ
func (r *RuntimeHardening) GenerateHardeningReport() map[string]interface{}
GenerateHardeningReport creates a report of current hardening status
func (*RuntimeHardening) GetASLRStatus ΒΆ
func (r *RuntimeHardening) GetASLRStatus() bool
GetASLRStatus returns the current ASLR status
func (*RuntimeHardening) GetCapabilities ΒΆ
func (r *RuntimeHardening) GetCapabilities() ([]string, error)
GetCapabilities returns current process capabilities Stub implementation
func (*RuntimeHardening) GetRLimits ΒΆ
func (r *RuntimeHardening) GetRLimits() (map[string]syscall.Rlimit, error)
GetRLimits returns current resource limits
func (*RuntimeHardening) GetSeccompStatus ΒΆ
func (r *RuntimeHardening) GetSeccompStatus() bool
GetSeccompStatus returns whether seccomp is enabled
func (*RuntimeHardening) HasCapability ΒΆ
func (r *RuntimeHardening) HasCapability(cap int) bool
HasCapability checks if the process has a specific capability Stub implementation
func (*RuntimeHardening) IsHardened ΒΆ
func (r *RuntimeHardening) IsHardened() bool
IsHardened returns true if all critical hardening measures are applied
func (*RuntimeHardening) Recommendations ΒΆ
func (r *RuntimeHardening) Recommendations() []string
Recommendations returns a list of recommended hardening steps
func (*RuntimeHardening) SecureProcess ΒΆ
func (r *RuntimeHardening) SecureProcess() (map[string]bool, error)
SecureProcess applies all available runtime hardening measures Returns a report of what was successfully applied
func (*RuntimeHardening) SetRLimits ΒΆ
func (r *RuntimeHardening) SetRLimits() error
SetRLimits sets resource limits to prevent DoS attacks
type SecretManager ΒΆ
type SecretManager struct {
// contains filtered or unexported fields
}
SecretManager handles secure secret generation, storage, and rotation
func NewSecretManager ΒΆ
func NewSecretManager(config SecretRotationConfig) *SecretManager
NewSecretManager creates a new secret manager with the given configuration
func (*SecretManager) Destroy ΒΆ
func (s *SecretManager) Destroy()
Destroy securely wipes all secrets and resets state This should be called on shutdown or when secrets are no longer needed
func (*SecretManager) DisableSecretRotation ΒΆ
func (s *SecretManager) DisableSecretRotation()
DisableSecretRotation disables automatic secret rotation
func (*SecretManager) EnableSecretRotation ΒΆ
func (s *SecretManager) EnableSecretRotation()
EnableSecretRotation enables automatic secret rotation
func (*SecretManager) GetLastRotation ΒΆ
func (s *SecretManager) GetLastRotation() time.Time
GetLastRotation returns the time of last rotation
func (*SecretManager) GetRotationCount ΒΆ
func (s *SecretManager) GetRotationCount() int
GetRotationCount returns the number of rotations performed
func (*SecretManager) GetRotationPeriod ΒΆ
func (s *SecretManager) GetRotationPeriod() time.Duration
GetRotationPeriod returns the rotation period
func (*SecretManager) GetRotationTimeRemaining ΒΆ
func (s *SecretManager) GetRotationTimeRemaining() time.Duration
GetRotationTimeRemaining returns time until next rotation Returns 0 if rotation is disabled or overdue
func (*SecretManager) GetSecret ΒΆ
func (s *SecretManager) GetSecret() (string, error)
GetSecret returns the current secret (base64 encoded) Automatically rotates if enabled and rotation period has passed
func (*SecretManager) GetSecretBytes ΒΆ
func (s *SecretManager) GetSecretBytes() []byte
GetSecretBytes returns the raw secret bytes (careful with this!) Caller is responsible for wiping the returned slice
func (*SecretManager) GetSecretLength ΒΆ
func (s *SecretManager) GetSecretLength() int
GetSecretLength returns the configured secret length
func (*SecretManager) GetSecretRotationStatus ΒΆ
func (s *SecretManager) GetSecretRotationStatus() (bool, time.Duration)
GetSecretRotationStatus returns current status
func (*SecretManager) IsSecretRotationEnabled ΒΆ
func (s *SecretManager) IsSecretRotationEnabled() bool
IsSecretRotationEnabled returns whether rotation is enabled
func (*SecretManager) IsTimeForRotation ΒΆ
func (s *SecretManager) IsTimeForRotation() bool
IsTimeForRotation checks if rotation is due
func (*SecretManager) RotateIfNecessary ΒΆ
func (s *SecretManager) RotateIfNecessary() (bool, string, error)
RotateIfNecessary rotates the secret if it's time Returns (rotated bool, newSecret string, error)
func (*SecretManager) RotateSecret ΒΆ
func (s *SecretManager) RotateSecret() (string, error)
RotateSecret manually rotates the secret Returns the new secret (base64 encoded) or error
func (*SecretManager) SetRotationPeriod ΒΆ
func (s *SecretManager) SetRotationPeriod(d time.Duration)
SetRotationPeriod sets the rotation period
func (*SecretManager) ValidateSecret ΒΆ
func (s *SecretManager) ValidateSecret(provided string) bool
ValidateSecret checks if a provided secret matches the current secret This is used for authentication/verification purposes
type SecretRotationConfig ΒΆ
SecretRotationConfig configures secret rotation behavior
func DefaultSecretRotationConfig ΒΆ
func DefaultSecretRotationConfig() SecretRotationConfig
DefaultSecretRotationConfig returns default configuration
type SecureAuditLog ΒΆ
type SecureAuditLog struct {
Entries []*AuditEntry
LastHash string
Count int
// contains filtered or unexported fields
}
SecureAuditLog provides an in-memory audit log with hash chain integrity
func NewSecureAuditLog ΒΆ
func NewSecureAuditLog() *SecureAuditLog
NewSecureAuditLog creates a new secure audit log
func (*SecureAuditLog) ClearAuditLog ΒΆ
func (a *SecureAuditLog) ClearAuditLog()
ClearAuditLog clears all audit entries
func (*SecureAuditLog) DisableAudit ΒΆ
func (a *SecureAuditLog) DisableAudit()
DisableAudit disables audit logging
func (*SecureAuditLog) DisableLogIntegrity ΒΆ
func (a *SecureAuditLog) DisableLogIntegrity()
DisableLogIntegrity disables log integrity checking
func (*SecureAuditLog) EnableAudit ΒΆ
func (a *SecureAuditLog) EnableAudit()
EnableAudit enables audit logging
func (*SecureAuditLog) EnableLogIntegrity ΒΆ
func (a *SecureAuditLog) EnableLogIntegrity()
EnableLogIntegrity enables log integrity checking
func (*SecureAuditLog) ExportToJSON ΒΆ
func (a *SecureAuditLog) ExportToJSON() ([]byte, error)
ExportToJSON exports the audit log to JSON
func (*SecureAuditLog) GetAuditLog ΒΆ
func (a *SecureAuditLog) GetAuditLog() []*AuditEntry
GetAuditLog returns all audit entries
func (*SecureAuditLog) GetEntriesByLevel ΒΆ
func (a *SecureAuditLog) GetEntriesByLevel(level AuditLevel) []*AuditEntry
GetEntriesByLevel returns all entries matching the specified level
func (*SecureAuditLog) GetEntriesSince ΒΆ
func (a *SecureAuditLog) GetEntriesSince(since time.Time) []*AuditEntry
GetEntriesSince returns all entries since the specified time
func (*SecureAuditLog) GetEntryCount ΒΆ
func (a *SecureAuditLog) GetEntryCount() int
GetEntryCount returns the total number of entries
func (*SecureAuditLog) GetLastHash ΒΆ
func (a *SecureAuditLog) GetLastHash() string
GetLastHash returns the last hash in the chain
func (*SecureAuditLog) ImportFromJSON ΒΆ
func (a *SecureAuditLog) ImportFromJSON(data []byte) error
ImportFromJSON imports audit log from JSON
func (*SecureAuditLog) IsAuditEnabled ΒΆ
func (a *SecureAuditLog) IsAuditEnabled() bool
IsAuditEnabled returns true if audit logging is enabled
func (*SecureAuditLog) IsLogIntegrityEnabled ΒΆ
func (a *SecureAuditLog) IsLogIntegrityEnabled() bool
IsLogIntegrityEnabled returns true if log integrity is enabled
func (*SecureAuditLog) LogAudit ΒΆ
func (a *SecureAuditLog) LogAudit(entry *AuditEntry)
LogAudit logs an audit entry
func (*SecureAuditLog) LogAuditWithLevel ΒΆ
func (a *SecureAuditLog) LogAuditWithLevel(level AuditLevel, message string, data map[string]interface{})
LogAuditWithLevel logs an audit entry with a specific level
func (*SecureAuditLog) SetCallback ΒΆ
func (a *SecureAuditLog) SetCallback(callback func(*AuditEntry))
SetCallback sets the callback function for audit entries
func (*SecureAuditLog) SetMaxEntries ΒΆ
func (a *SecureAuditLog) SetMaxEntries(max int)
SetMaxEntries sets the maximum number of entries to keep
func (*SecureAuditLog) VerifyChainIntegrity ΒΆ
func (a *SecureAuditLog) VerifyChainIntegrity() (bool, []string)
VerifyChainIntegrity verifies the integrity of the audit log chain
type StorageBackend ΒΆ
type StorageBackend interface {
Write(ctx context.Context, entry *AuditEntry) error
Read(ctx context.Context, id string) (*AuditEntry, error)
Query(ctx context.Context, filter AuditFilter) ([]*AuditEntry, error)
Delete(ctx context.Context, id string) error
Close() error
}
StorageBackend defines the interface for persistent audit storage
type ThreatCategory ΒΆ
type ThreatCategory int
ThreatCategory represents the severity of a threat
const ( ThreatCategoryLow ThreatCategory = 1 ThreatCategoryMedium ThreatCategory = 2 ThreatCategoryHigh ThreatCategory = 3 ThreatCategoryCritical ThreatCategory = 4 )
func (ThreatCategory) String ΒΆ
func (tc ThreatCategory) String() string
type ThreatEntry ΒΆ
type ThreatEntry struct {
ID string `json:"id"`
Name string `json:"name"`
Vector ThreatVector `json:"vector"`
Category ThreatCategory `json:"category"`
Description string `json:"description"`
Indicators []string `json:"indicators"`
Mitigation string `json:"mitigation"`
Implementation []string `json:"implementation"`
References []string `json:"references"`
OWASPCategory string `json:"owasp_category,omitempty"`
}
ThreatEntry represents a cataloged threat with mitigation strategies
type ThreatModel ΒΆ
type ThreatModel struct {
Name string `json:"name"`
Description string `json:"description"`
Scope string `json:"scope"`
Threats []ThreatEntry `json:"threats"`
Assumptions []string `json:"assumptions"`
}
ThreatModel represents a complete threat model for a system
func CreateDefaultThreatModel ΒΆ
func CreateDefaultThreatModel() *ThreatModel
CreateDefaultThreatModel returns a default threat model for LLM gateways
type ThreatModelingEngine ΒΆ
type ThreatModelingEngine struct {
// contains filtered or unexported fields
}
ThreatModelingEngine manages threat models and threat catalog
func NewThreatModelingEngine ΒΆ
func NewThreatModelingEngine() *ThreatModelingEngine
NewThreatModelingEngine creates a new threat modeling engine
func (*ThreatModelingEngine) AnalyzePatterns ΒΆ
func (e *ThreatModelingEngine) AnalyzePatterns(input, output string) []ThreatEntry
AnalyzePatterns analyzes input/output patterns against threat indicators
func (*ThreatModelingEngine) Disable ΒΆ
func (e *ThreatModelingEngine) Disable()
Disable disables threat modeling
func (*ThreatModelingEngine) Enable ΒΆ
func (e *ThreatModelingEngine) Enable()
Enable enables threat modeling
func (*ThreatModelingEngine) GenerateReport ΒΆ
func (e *ThreatModelingEngine) GenerateReport() (map[string]interface{}, error)
GenerateReport creates a JSON report of the threat model
func (*ThreatModelingEngine) GetActiveModel ΒΆ
func (e *ThreatModelingEngine) GetActiveModel() *ThreatModel
GetActiveModel returns the currently loaded threat model
func (*ThreatModelingEngine) GetAllThreats ΒΆ
func (e *ThreatModelingEngine) GetAllThreats() []ThreatEntry
GetAllThreats returns the complete threat catalog
func (*ThreatModelingEngine) GetMitigationStrategy ΒΆ
func (e *ThreatModelingEngine) GetMitigationStrategy(threatID string) (string, []string, bool)
GetMitigationStrategy returns mitigation details for a threat
func (*ThreatModelingEngine) GetThreatByID ΒΆ
func (e *ThreatModelingEngine) GetThreatByID(id string) (ThreatEntry, bool)
GetThreatByID retrieves a threat by its ID
func (*ThreatModelingEngine) GetThreatsByCategory ΒΆ
func (e *ThreatModelingEngine) GetThreatsByCategory(category ThreatCategory) []ThreatEntry
GetThreatsByCategory returns all threats in a category
func (*ThreatModelingEngine) GetThreatsByVector ΒΆ
func (e *ThreatModelingEngine) GetThreatsByVector(vector ThreatVector) []ThreatEntry
GetThreatsByVector returns all threats of a specific vector
func (*ThreatModelingEngine) IsEnabled ΒΆ
func (e *ThreatModelingEngine) IsEnabled() bool
IsEnabled returns whether threat modeling is enabled
func (*ThreatModelingEngine) LoadThreatModel ΒΆ
func (e *ThreatModelingEngine) LoadThreatModel(model *ThreatModel)
LoadThreatModel sets the active threat model
func (*ThreatModelingEngine) RegisterThreat ΒΆ
func (e *ThreatModelingEngine) RegisterThreat(threat ThreatEntry) error
RegisterThreat adds a new threat to the catalog
type ThreatVector ΒΆ
type ThreatVector string
ThreatVector represents a type of security threat
const ( ThreatVectorPromptInjection ThreatVector = "prompt_injection" ThreatVectorDataExfiltration ThreatVector = "data_exfiltration" ThreatVectorModelTheft ThreatVector = "model_theft" ThreatVectorTrainingPoisoning ThreatVector = "training_poisoning" ThreatVectorAdversarialInput ThreatVector = "adversarial_input" ThreatVectorShadowAI ThreatVector = "shadow_ai" ThreatVectorSupplyChain ThreatVector = "supply_chain" ThreatVectorPrivilegeEscalation ThreatVector = "privilege_escalation" ThreatVectorDoS ThreatVector = "denial_of_service" ThreatVectorSideChannel ThreatVector = "side_channel" )