Documentation
¶
Overview ¶
Package config validates and sanitizes values that reach the daemon from untrusted sources, most importantly the shell commands attached to jobs.
Index ¶
- type CommandValidator
- type Sanitizer
- func (s *Sanitizer) SanitizeHTML(input string) string
- func (s *Sanitizer) SanitizeString(input string, maxLength int) (string, error)
- func (s *Sanitizer) ValidateCommand(command string) error
- func (s *Sanitizer) ValidateCronExpression(expr string) error
- func (s *Sanitizer) ValidateDockerImage(image string) error
- func (s *Sanitizer) ValidateEmailList(emails string) error
- func (s *Sanitizer) ValidateEnvironmentVar(name, value string) error
- func (s *Sanitizer) ValidateJobName(name string) error
- func (s *Sanitizer) ValidatePath(path, allowedBasePath string) error
- func (s *Sanitizer) ValidateURL(rawURL string) error
- type ValidationError
- type ValidationErrors
- type Validator
- func (v *Validator) AddError(field string, value any, message string)
- func (v *Validator) Errors() ValidationErrors
- func (v *Validator) HasErrors() bool
- func (v *Validator) ValidateCronExpression(field, value string)
- func (v *Validator) ValidateEmail(field, value string)
- func (v *Validator) ValidateEnum(field string, value string, allowed []string)
- func (v *Validator) ValidateMaxLength(field string, value string, maxLength int)
- func (v *Validator) ValidateMinLength(field string, value string, minLength int)
- func (v *Validator) ValidatePath(field, value string)
- func (v *Validator) ValidatePositive(field string, value int)
- func (v *Validator) ValidateRange(field string, value int, minVal, maxVal int)
- func (v *Validator) ValidateRequired(field, value string)
- func (v *Validator) ValidateURL(field, value string)
- type Validator2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandValidator ¶
type CommandValidator struct {
// contains filtered or unexported fields
}
CommandValidator provides security validation for command arguments
func NewCommandValidator ¶
func NewCommandValidator() *CommandValidator
NewCommandValidator creates a new command validator with security rules
func (*CommandValidator) SanitizeCommand ¶
func (v *CommandValidator) SanitizeCommand(cmd string) string
SanitizeCommand removes potentially dangerous characters from a command string
func (*CommandValidator) ValidateCommandArgs ¶
func (v *CommandValidator) ValidateCommandArgs(args []string) error
ValidateCommandArgs validates command arguments for safety
func (*CommandValidator) ValidateFilePath ¶
func (v *CommandValidator) ValidateFilePath(path string) error
ValidateFilePath validates a Docker compose file path for safety
func (*CommandValidator) ValidateServiceName ¶
func (v *CommandValidator) ValidateServiceName(service string) error
ValidateServiceName validates a Docker service name for safety
type Sanitizer ¶
type Sanitizer struct {
// contains filtered or unexported fields
}
Sanitizer provides input sanitization and validation for security
func (*Sanitizer) SanitizeHTML ¶
SanitizeHTML performs HTML escaping to prevent XSS
func (*Sanitizer) SanitizeString ¶
SanitizeString performs basic string sanitization
func (*Sanitizer) ValidateCommand ¶
ValidateCommand validates command strings for shell execution
func (*Sanitizer) ValidateCronExpression ¶
ValidateCronExpression validates a cron expression using go-cron's parser. This correctly handles all formats: descriptors (@daily), @every intervals, standard cron expressions with optional seconds, month/day names (JAN, MON), and wraparound ranges (FRI-MON).
func (*Sanitizer) ValidateDockerImage ¶
ValidateDockerImage validates Docker image names
func (*Sanitizer) ValidateEmailList ¶
ValidateEmailList validates a comma-separated list of email addresses
func (*Sanitizer) ValidateEnvironmentVar ¶
ValidateEnvironmentVar validates environment variable names and values
func (*Sanitizer) ValidateJobName ¶
ValidateJobName validates job names for safety
func (*Sanitizer) ValidatePath ¶
ValidatePath validates file paths to prevent traversal attacks
func (*Sanitizer) ValidateURL ¶
ValidateURL validates URLs to prevent SSRF and other attacks
type ValidationError ¶
ValidationError represents a configuration validation error
func (ValidationError) Error ¶
func (e ValidationError) Error() string
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors represents multiple validation errors
func (ValidationErrors) Error ¶
func (e ValidationErrors) Error() string
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator provides configuration validation
func NewValidator ¶
func NewValidator() *Validator
NewValidator creates a new configuration validator
func (*Validator) Errors ¶
func (v *Validator) Errors() ValidationErrors
Errors returns all validation errors
func (*Validator) ValidateCronExpression ¶
ValidateCronExpression validates a cron expression using go-cron's parser. This handles all formats: descriptors (@daily), @every intervals, standard cron expressions with optional seconds, month/day names, and wraparound ranges.
func (*Validator) ValidateEmail ¶
ValidateEmail validates that a string is a valid email
func (*Validator) ValidateEnum ¶
ValidateEnum validates that a value is in a list of allowed values
func (*Validator) ValidateMaxLength ¶
ValidateMaxLength validates maximum string length
func (*Validator) ValidateMinLength ¶
ValidateMinLength validates minimum string length
func (*Validator) ValidatePath ¶
ValidatePath validates that a path exists or can be created
func (*Validator) ValidatePositive ¶
ValidatePositive validates that a number is positive
func (*Validator) ValidateRange ¶
ValidateRange validates that a number is within range
func (*Validator) ValidateRequired ¶
ValidateRequired validates that a field is not empty
func (*Validator) ValidateURL ¶
ValidateURL validates that a string is a valid URL
type Validator2 ¶
type Validator2 struct {
// contains filtered or unexported fields
}
Validator2 validates a whole configuration object by reflection, rather than field by field. Validate walks the exported fields of the struct it was given (recursing into nested structs), derives each field's config key from its gcfg/mapstructure tag, and reports the collected problems through a freshly built Validator. Only string, int/int64 and slice fields are inspected; other kinds are skipped. Construct with NewConfigValidator.
func NewConfigValidator ¶
func NewConfigValidator(config any) *Validator2
NewConfigValidator creates a configuration validator
func (*Validator2) Validate ¶
func (cv *Validator2) Validate() error
Validate performs validation on the configuration