config

package
v0.28.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config validates and sanitizes values that reach the daemon from untrusted sources, most importantly the shell commands attached to jobs.

Index

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 NewSanitizer

func NewSanitizer() *Sanitizer

NewSanitizer creates a new input sanitizer

func (*Sanitizer) SanitizeHTML

func (s *Sanitizer) SanitizeHTML(input string) string

SanitizeHTML performs HTML escaping to prevent XSS

func (*Sanitizer) SanitizeString

func (s *Sanitizer) SanitizeString(input string, maxLength int) (string, error)

SanitizeString performs basic string sanitization

func (*Sanitizer) ValidateCommand

func (s *Sanitizer) ValidateCommand(command string) error

ValidateCommand validates command strings for shell execution

func (*Sanitizer) ValidateCronExpression

func (s *Sanitizer) ValidateCronExpression(expr string) error

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

func (s *Sanitizer) ValidateDockerImage(image string) error

ValidateDockerImage validates Docker image names

func (*Sanitizer) ValidateEmailList

func (s *Sanitizer) ValidateEmailList(emails string) error

ValidateEmailList validates a comma-separated list of email addresses

func (*Sanitizer) ValidateEnvironmentVar

func (s *Sanitizer) ValidateEnvironmentVar(name, value string) error

ValidateEnvironmentVar validates environment variable names and values

func (*Sanitizer) ValidateJobName

func (s *Sanitizer) ValidateJobName(name string) error

ValidateJobName validates job names for safety

func (*Sanitizer) ValidatePath

func (s *Sanitizer) ValidatePath(path, allowedBasePath string) error

ValidatePath validates file paths to prevent traversal attacks

func (*Sanitizer) ValidateURL

func (s *Sanitizer) ValidateURL(rawURL string) error

ValidateURL validates URLs to prevent SSRF and other attacks

type ValidationError

type ValidationError struct {
	Field   string
	Value   any
	Message string
}

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) AddError

func (v *Validator) AddError(field string, value any, message string)

AddError adds a validation error

func (*Validator) Errors

func (v *Validator) Errors() ValidationErrors

Errors returns all validation errors

func (*Validator) HasErrors

func (v *Validator) HasErrors() bool

HasErrors returns true if there are validation errors

func (*Validator) ValidateCronExpression

func (v *Validator) ValidateCronExpression(field, value string)

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

func (v *Validator) ValidateEmail(field, value string)

ValidateEmail validates that a string is a valid email

func (*Validator) ValidateEnum

func (v *Validator) ValidateEnum(field string, value string, allowed []string)

ValidateEnum validates that a value is in a list of allowed values

func (*Validator) ValidateMaxLength

func (v *Validator) ValidateMaxLength(field string, value string, maxLength int)

ValidateMaxLength validates maximum string length

func (*Validator) ValidateMinLength

func (v *Validator) ValidateMinLength(field string, value string, minLength int)

ValidateMinLength validates minimum string length

func (*Validator) ValidatePath

func (v *Validator) ValidatePath(field, value string)

ValidatePath validates that a path exists or can be created

func (*Validator) ValidatePositive

func (v *Validator) ValidatePositive(field string, value int)

ValidatePositive validates that a number is positive

func (*Validator) ValidateRange

func (v *Validator) ValidateRange(field string, value int, minVal, maxVal int)

ValidateRange validates that a number is within range

func (*Validator) ValidateRequired

func (v *Validator) ValidateRequired(field, value string)

ValidateRequired validates that a field is not empty

func (*Validator) ValidateURL

func (v *Validator) ValidateURL(field, value string)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL