Documentation
¶
Index ¶
- Constants
- func GetDefaultAuditLogPath() string
- func GetDefaultAuditSigningKeyPath() string
- func IsCommandSanitizationError(err error) bool
- func IsValidationError(err error) bool
- func MaskSecrets(input string, values ...string) string
- func ParseDuration(s string) (time.Duration, error)
- type AuditEvent
- type AuditLogger
- func (l *AuditLogger) Close() error
- func (l *AuditLogger) ExportEventsToJSON(events []AuditEvent, filePath string) error
- func (l *AuditLogger) LogDriftDetected(ctx context.Context, actor, cluster string, ...) error
- func (l *AuditLogger) LogEvent(ctx context.Context, event AuditEvent) error
- func (l *AuditLogger) LogInputRejected(ctx context.Context, actor, inputType, reason string) error
- func (l *AuditLogger) LogKeyAccessed(ctx context.Context, actor, keyType, resource string, success bool) error
- func (l *AuditLogger) LogKeyExpired(ctx context.Context, actor, cluster, keyType, keyFingerprint string, ...) error
- func (l *AuditLogger) LogKeyGenerated(ctx context.Context, actor, keyType, resource string) error
- func (l *AuditLogger) LogKeyRevocationFailed(ctx context.Context, actor, cluster, keyFingerprint, reason string) error
- func (l *AuditLogger) LogKeyRevoked(ctx context.Context, actor, cluster, keyFingerprint, revokedUser string, ...) error
- func (l *AuditLogger) LogKeyRotated(ctx context.Context, actor, keyType, resource string) error
- func (l *AuditLogger) LogSecretDecrypted(ctx context.Context, actor, cluster, manifestPath string, success bool) error
- func (l *AuditLogger) LogSecretsSync(ctx context.Context, actor, cluster string, ...) error
- func (l *AuditLogger) LogSecretsSyncFailed(ctx context.Context, actor, cluster, reason string) error
- func (l *AuditLogger) LogSecretsValidated(ctx context.Context, actor, cluster string) error
- func (l *AuditLogger) LogTemplateValidationFailed(ctx context.Context, actor, templateName, reason string) error
- func (l *AuditLogger) LogValidationFailed(ctx context.Context, actor, resource, reason string, ...) error
- func (l *AuditLogger) QueryEvents(ctx context.Context, filter EventFilter) ([]AuditEvent, error)
- func (l *AuditLogger) QueryEventsSince(ctx context.Context, since time.Duration, eventType string) ([]AuditEvent, error)
- func (l *AuditLogger) VerifyIntegrity() error
- type AuditLoggerConfig
- type CommandRunner
- type CommandSanitizationError
- type CommandSanitizer
- type CredentialMasker
- type DefaultCommandRunner
- type DefaultCommandSanitizer
- type DefaultCredentialMasker
- type DefaultInputValidator
- func (v *DefaultInputValidator) SanitizeShellInput(input string) (string, error)
- func (v *DefaultInputValidator) SetActor(actor string)
- func (v *DefaultInputValidator) SetAuditLogger(logger *AuditLogger)
- func (v *DefaultInputValidator) ValidateEnvironmentVariable(name, value string) error
- func (v *DefaultInputValidator) ValidatePath(path string) error
- func (v *DefaultInputValidator) ValidateURL(urlStr string) error
- type EventFilter
- type InputValidator
- type ValidationError
Constants ¶
const ( // MaxLogSize is the maximum size of a log file before rotation (100MB) MaxLogSize = 100 * 1024 * 1024 // LogRetentionDays is the number of days to retain rotated logs LogRetentionDays = 30 )
Variables ¶
This section is empty.
Functions ¶
func GetDefaultAuditLogPath ¶
func GetDefaultAuditLogPath() string
GetDefaultAuditLogPath returns the default audit log path
func GetDefaultAuditSigningKeyPath ¶
func GetDefaultAuditSigningKeyPath() string
GetDefaultAuditSigningKeyPath returns the default audit signing key path.
func IsCommandSanitizationError ¶
IsCommandSanitizationError checks if an error is a CommandSanitizationError
func IsValidationError ¶
IsValidationError checks if an error is a ValidationError
func MaskSecrets ¶
MaskSecrets applies repository-standard pattern masking and then masks the exact values supplied by the caller. It is used at boundaries where generated or profile credentials may appear in otherwise unstructured errors and output.
Types ¶
type AuditEvent ¶
type AuditEvent struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
EventType string `json:"event_type"`
Actor string `json:"actor"`
Resource string `json:"resource"`
Action string `json:"action"`
Result string `json:"result"`
Details map[string]interface{} `json:"details,omitempty"`
CorrelationID string `json:"correlation_id,omitempty"`
Signature string `json:"signature"`
}
AuditEvent represents a security-relevant event with integrity protection
type AuditLogger ¶
type AuditLogger struct {
// contains filtered or unexported fields
}
AuditLogger provides tamper-evident audit logging for security events
func NewAuditLogger ¶
func NewAuditLogger(config AuditLoggerConfig) (*AuditLogger, error)
NewAuditLogger creates a new audit logger with HMAC integrity protection
func NewDefaultAuditLogger ¶
func NewDefaultAuditLogger() (*AuditLogger, error)
NewDefaultAuditLogger creates an audit logger with default settings
func (*AuditLogger) ExportEventsToJSON ¶
func (l *AuditLogger) ExportEventsToJSON(events []AuditEvent, filePath string) error
ExportEventsToJSON exports audit events to a JSON file
func (*AuditLogger) LogDriftDetected ¶
func (l *AuditLogger) LogDriftDetected(ctx context.Context, actor, cluster string, driftCount, missingCount, orphanedCount int) error
LogDriftDetected logs a secrets drift detection event
func (*AuditLogger) LogEvent ¶
func (l *AuditLogger) LogEvent(ctx context.Context, event AuditEvent) error
LogEvent logs a security event with HMAC signature
func (*AuditLogger) LogInputRejected ¶
func (l *AuditLogger) LogInputRejected(ctx context.Context, actor, inputType, reason string) error
LogInputRejected logs a rejected input event
func (*AuditLogger) LogKeyAccessed ¶
func (l *AuditLogger) LogKeyAccessed(ctx context.Context, actor, keyType, resource string, success bool) error
LogKeyAccessed logs a key access event
func (*AuditLogger) LogKeyExpired ¶
func (l *AuditLogger) LogKeyExpired(ctx context.Context, actor, cluster, keyType, keyFingerprint string, daysRemaining int) error
LogKeyExpired logs a key expiration warning or error event
func (*AuditLogger) LogKeyGenerated ¶
func (l *AuditLogger) LogKeyGenerated(ctx context.Context, actor, keyType, resource string) error
LogKeyGenerated logs a key generation event
func (*AuditLogger) LogKeyRevocationFailed ¶
func (l *AuditLogger) LogKeyRevocationFailed(ctx context.Context, actor, cluster, keyFingerprint, reason string) error
LogKeyRevocationFailed logs a failed key revocation event
func (*AuditLogger) LogKeyRevoked ¶
func (l *AuditLogger) LogKeyRevoked(ctx context.Context, actor, cluster, keyFingerprint, revokedUser string, filesReencrypted int) error
LogKeyRevoked logs a key revocation event
func (*AuditLogger) LogKeyRotated ¶
func (l *AuditLogger) LogKeyRotated(ctx context.Context, actor, keyType, resource string) error
LogKeyRotated logs a key rotation event
func (*AuditLogger) LogSecretDecrypted ¶
func (l *AuditLogger) LogSecretDecrypted(ctx context.Context, actor, cluster, manifestPath string, success bool) error
LogSecretDecrypted logs a secret decryption event
func (*AuditLogger) LogSecretsSync ¶
func (l *AuditLogger) LogSecretsSync(ctx context.Context, actor, cluster string, filesCreated, filesUpdated, filesUnchanged int) error
LogSecretsSync logs a secrets synchronization event
func (*AuditLogger) LogSecretsSyncFailed ¶
func (l *AuditLogger) LogSecretsSyncFailed(ctx context.Context, actor, cluster, reason string) error
LogSecretsSyncFailed logs a failed secrets synchronization event
func (*AuditLogger) LogSecretsValidated ¶
func (l *AuditLogger) LogSecretsValidated(ctx context.Context, actor, cluster string) error
LogSecretsValidated logs a successful secrets validation event (no drift)
func (*AuditLogger) LogTemplateValidationFailed ¶
func (l *AuditLogger) LogTemplateValidationFailed(ctx context.Context, actor, templateName, reason string) error
LogTemplateValidationFailed logs a template validation failure
func (*AuditLogger) LogValidationFailed ¶
func (l *AuditLogger) LogValidationFailed(ctx context.Context, actor, resource, reason string, details map[string]interface{}) error
LogValidationFailed logs a validation failure event
func (*AuditLogger) QueryEvents ¶
func (l *AuditLogger) QueryEvents(ctx context.Context, filter EventFilter) ([]AuditEvent, error)
QueryEvents retrieves audit log entries based on filter
func (*AuditLogger) QueryEventsSince ¶
func (l *AuditLogger) QueryEventsSince(ctx context.Context, since time.Duration, eventType string) ([]AuditEvent, error)
QueryEventsSince retrieves audit log entries since a given duration duration examples: "24h", "7d", "30m"
func (*AuditLogger) VerifyIntegrity ¶
func (l *AuditLogger) VerifyIntegrity() error
VerifyIntegrity verifies the integrity of all audit log entries
type AuditLoggerConfig ¶
type AuditLoggerConfig struct {
LogPath string
SigningKey []byte
SigningKeyPath string
Enabled bool
}
AuditLoggerConfig represents configuration for audit logger
type CommandRunner ¶
type CommandRunner interface {
PrepareCommand(name string, args ...string) (*exec.Cmd, error)
PrepareCommandContext(ctx context.Context, name string, args ...string) (*exec.Cmd, error)
}
CommandRunner centralizes sanitized external command construction.
func GetDefaultCommandRunner ¶
func GetDefaultCommandRunner() CommandRunner
GetDefaultCommandRunner returns the process-wide default command runner.
type CommandSanitizationError ¶
CommandSanitizationError represents a command sanitization error
func (*CommandSanitizationError) Error ¶
func (e *CommandSanitizationError) Error() string
Error implements the error interface
type CommandSanitizer ¶
type CommandSanitizer interface {
SanitizeCommand(cmd string, args []string) (*exec.Cmd, error)
ValidateEditor(editor string) error
SanitizeGitArgs(args []string) ([]string, error)
}
CommandSanitizer prevents command injection in external command execution
type CredentialMasker ¶
type CredentialMasker interface {
MaskString(input string) string
MaskBytes(input []byte) []byte
RegisterPattern(name string, pattern *regexp.Regexp)
GetMaskedCount() int
}
CredentialMasker detects and masks credentials in all output streams
type DefaultCommandRunner ¶
type DefaultCommandRunner struct {
// contains filtered or unexported fields
}
DefaultCommandRunner prepares sanitized commands using a CommandSanitizer.
func NewCommandRunner ¶
func NewCommandRunner(sanitizer CommandSanitizer) *DefaultCommandRunner
NewCommandRunner creates a command runner backed by the provided sanitizer.
func (*DefaultCommandRunner) PrepareCommand ¶
PrepareCommand returns a sanitized exec.Cmd without a bound context.
func (*DefaultCommandRunner) PrepareCommandContext ¶
func (r *DefaultCommandRunner) PrepareCommandContext(ctx context.Context, name string, args ...string) (*exec.Cmd, error)
PrepareCommandContext returns a sanitized exec.Cmd bound to ctx.
type DefaultCommandSanitizer ¶
type DefaultCommandSanitizer struct {
// contains filtered or unexported fields
}
DefaultCommandSanitizer implements CommandSanitizer interface
func NewDefaultCommandSanitizer ¶
func NewDefaultCommandSanitizer() *DefaultCommandSanitizer
NewDefaultCommandSanitizer creates a new command sanitizer with default settings
func (*DefaultCommandSanitizer) SanitizeCommand ¶
SanitizeCommand creates a safe exec.Cmd using parameterized execution Requirements: 1.3, 1.4
This function prevents command injection by: 1. Rejecting command names with shell metacharacters 2. Using exec.Command with separate arguments instead of shell invocation 3. Never using sh -c or bash -c with user input
func (*DefaultCommandSanitizer) SanitizeGitArgs ¶
func (s *DefaultCommandSanitizer) SanitizeGitArgs(args []string) ([]string, error)
SanitizeGitArgs sanitizes arguments for Git commands Requirements: 1.3, 1.4
This function escapes special characters in Git arguments to prevent command injection through Git operations.
func (*DefaultCommandSanitizer) ValidateEditor ¶
func (s *DefaultCommandSanitizer) ValidateEditor(editor string) error
ValidateEditor validates an editor command against the safe editors whitelist Requirements: 1.1, 1.2
This function ensures that only known-safe editors can be used, preventing command injection through the EDITOR environment variable.
type DefaultCredentialMasker ¶
type DefaultCredentialMasker struct {
// contains filtered or unexported fields
}
DefaultCredentialMasker implements CredentialMasker interface
func NewDefaultCredentialMasker ¶
func NewDefaultCredentialMasker() *DefaultCredentialMasker
NewDefaultCredentialMasker creates a new credential masker with default patterns
func (*DefaultCredentialMasker) GetMaskedCount ¶
func (m *DefaultCredentialMasker) GetMaskedCount() int
GetMaskedCount returns the number of credentials that have been masked Requirements: 3.7
This function provides visibility into how many credentials have been masked, which can be useful for security auditing and monitoring.
func (*DefaultCredentialMasker) MaskBytes ¶
func (m *DefaultCredentialMasker) MaskBytes(input []byte) []byte
MaskBytes masks credentials in a byte slice Requirements: 3.1, 3.2, 3.3, 3.4, 3.5
This function converts the byte slice to a string, masks credentials, and converts back to bytes.
func (*DefaultCredentialMasker) MaskString ¶
func (m *DefaultCredentialMasker) MaskString(input string) string
MaskString masks credentials in a string Requirements: 3.1, 3.2, 3.3, 3.4, 3.5
This function scans the input string for credential patterns and replaces them with masked versions. For debugging purposes, it preserves the first 4 and last 4 characters of certain credential types (like AWS keys).
func (*DefaultCredentialMasker) RegisterPattern ¶
func (m *DefaultCredentialMasker) RegisterPattern(name string, pattern *regexp.Regexp)
RegisterPattern registers a custom credential pattern Requirements: 3.8
This function allows adding custom patterns for credential detection. The pattern should be a compiled regular expression that matches the credential format.
type DefaultInputValidator ¶
type DefaultInputValidator struct {
// contains filtered or unexported fields
}
DefaultInputValidator implements InputValidator interface
func NewDefaultInputValidator ¶
func NewDefaultInputValidator() *DefaultInputValidator
NewDefaultInputValidator creates a new input validator with default settings
func (*DefaultInputValidator) SanitizeShellInput ¶
func (v *DefaultInputValidator) SanitizeShellInput(input string) (string, error)
SanitizeShellInput escapes shell metacharacters in user input Requirements: 1.2, 1.3
func (*DefaultInputValidator) SetActor ¶
func (v *DefaultInputValidator) SetActor(actor string)
SetActor sets the actor (user/system) performing the validation
func (*DefaultInputValidator) SetAuditLogger ¶
func (v *DefaultInputValidator) SetAuditLogger(logger *AuditLogger)
SetAuditLogger sets the audit logger for logging rejected inputs
func (*DefaultInputValidator) ValidateEnvironmentVariable ¶
func (v *DefaultInputValidator) ValidateEnvironmentVariable(name, value string) error
ValidateEnvironmentVariable validates environment variable names and values Requirements: 1.1, 1.2
func (*DefaultInputValidator) ValidatePath ¶
func (v *DefaultInputValidator) ValidatePath(path string) error
ValidatePath validates a file path to prevent path traversal attacks Requirements: 1.8, 6.3
func (*DefaultInputValidator) ValidateURL ¶
func (v *DefaultInputValidator) ValidateURL(urlStr string) error
ValidateURL validates a URL to ensure it uses HTTPS for external URLs Requirements: 6.6
type EventFilter ¶
type EventFilter struct {
StartTime time.Time
EndTime time.Time
EventType string
Actor string
Resource string
Action string
Result string
CorrelationID string
Limit int
}
EventFilter represents filters for querying audit logs
type InputValidator ¶
type InputValidator interface {
ValidatePath(path string) error
ValidateURL(urlStr string) error
ValidateEnvironmentVariable(name, value string) error
SanitizeShellInput(input string) (string, error)
SetAuditLogger(logger *AuditLogger)
SetActor(actor string)
}
InputValidator validates and sanitizes user-controlled input to prevent injection attacks
type ValidationError ¶
ValidationError represents a validation error with context
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface