config

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultEdgeWorkerPoolSize         = 5
	DefaultEdgeWorkerPoolCapacity     = 100
	DefaultEdgeBatchSize              = 500
	DefaultEdgeBatchSizeSmall         = DefaultEdgeBatchSize / 5
	DefaultEdgeBatchSizeClusterImpact = 10

	DefaultVertexBatchSize      = 500
	DefaultVertexBatchSizeSmall = DefaultVertexBatchSize / 5

	DefaultStopOnError = false

	DefaultLargeClusterOptimizations = true
)
View Source
const (
	CollectorTypeFile   = "file-collector"
	CollectorTypeK8sAPI = "live-k8s-api-collector"
)
View Source
const (
	DefaultK8sAPIPageSize           int64 = 500
	DefaultK8sAPIPageBufferSize     int32 = 10
	DefaultK8sAPIRateLimitPerSecond int   = 100
	DefaultK8sAPINonInteractive     bool  = false
	DefaultArchiveNoCompress        bool  = false

	CollectorLiveRate              = "collector.live.rate_limit_per_second"
	CollectorLivePageSize          = "collector.live.page_size"
	CollectorLivePageBufferSize    = "collector.live.page_buffer_size"
	CollectorNonInteractive        = "collector.non_interactive"
	CollectorFileArchiveNoCompress = "collector.file.archive.no_compress"
	CollectorFileDirectory         = "collector.file.directory"
)
View Source
const (
	DefaultConfigType  = "yaml"
	DefaultClusterName = "unknown"
	DefaultConfigName  = "kubehound"

	GlobalDebug = "debug"
)
View Source
const (
	DynamicRunID       = "dynamic.run_id"
	DynamicClusterName = "dynamic.cluster_name"
)
View Source
const (
	DefaultIngestorAPIEndpoint = "127.0.0.1:9000"
	DefaultIngestorAPIInsecure = false
	DefaultBucketName          = "" // we want to let it empty because we can easily abort if it's not configured
	DefaultTempDir             = "/tmp/kubehound"
	DefaultArchiveName         = "archive.tar.gz"
	DefaultMaxArchiveSize      = int64(2 << 30) // 2GB

	IngestorAPIEndpoint    = "ingestor.api.endpoint"
	IngestorAPIInsecure    = "ingestor.api.insecure"
	IngestorMaxArchiveSize = "ingestor.max_archive_size"
	IngestorTempDir        = "ingestor.temp_dir"
	IngestorArchiveName    = "ingestor.archive_name"

	IngestorBlobBucketURL = "ingestor.blob.bucket_url"
	IngestorBlobRegion    = "ingestor.blob.region"
)
View Source
const (
	DefaultJanusGraphUrl = "ws://localhost:8182/gremlin"

	JanusGraphUrl    = "janusgraph.url"
	JanusGrapTimeout = "janusgraph.connection_timeout"
)
View Source
const (
	DefaultMongoUrl = "mongodb://localhost:27017"

	MongoUrl               = "mongodb.url"
	MongoConnectionTimeout = "mongodb.connection_timeout"
)
View Source
const (
	DefaultRetry             int           = 10 // number of tries before failing
	DefaultRetryDelay        time.Duration = 10 * time.Second
	DefaultConnectionTimeout time.Duration = 30 * time.Second
)
View Source
const (
	DefaultProfilerPeriod       time.Duration = 60 * time.Second
	DefaultProfilerCPUDuration  time.Duration = 15 * time.Second
	DefaultTelemetryStatsdUrl                 = "" // 127.0.0.1:8225
	DefaultTelemetryProfilerUrl               = "" // 127.0.0.1:8226

	TelemetryStatsdUrl           = "telemetry.statsd.url"
	TelemetryTracerUrl           = "telemetry.tracer.url"
	TelemetryEnabled             = "telemetry.enabled"
	TelemetryProfilerCPUDuration = "telemetry.profiler.cpu_duration"
	TelemetryProfilerPeriod      = "telemetry.profiler.period"
)

Variables

View Source
var (
	BuildVersion string // This should be overwritten by the go build -X flags
	BuildBranch  string // This should be overwritten by the go build -X flags
	BuildArch    string // This should be overwritten by the go build -X flags
	BuildOs      string // This should be overwritten by the go build -X flags
)

Functions

func GetClusterName added in v1.3.1

func GetClusterName(ctx context.Context) (string, error)

func IsCI

func IsCI() bool

IsCI determines whether the application is running within a CI action

func SetDefaultValues

func SetDefaultValues(ctx context.Context, v *viper.Viper)

SetDefaultValues loads the default value from the different modules

func SetEnvOverrides added in v1.2.0

func SetEnvOverrides(ctx context.Context, c *viper.Viper)

SetEnvOverrides enables environment variable overrides for the config.

func SetLocalConfig added in v1.4.0

func SetLocalConfig(ctx context.Context, v *viper.Viper)

Load local config file if it exists, check for local file in current dir or in $HOME/.config/ Not returning any error as it is not mandatory to have a local config file

Types

type BlobConfig added in v1.3.1

type BlobConfig struct {
	BucketUrl string `mapstructure:"bucket_url"` // Bucket to use to push k8s resources (e.g.: s3://<your_bucket>)
	Region    string `mapstructure:"region"`     // Region to use for the bucket (only for s3)
}

type BuilderConfig

type BuilderConfig struct {
	Vertex      VertexBuilderConfig `mapstructure:"vertex"`        // Vertex builder config
	Edge        EdgeBuilderConfig   `mapstructure:"edge"`          // Edge builder config
	StopOnError bool                `mapstructure:"stop_on_error"` // Stop the building of the graph on error
}

type ClusterInfo added in v1.3.1

type ClusterInfo struct {
	Name string
}

ClusterInfo encapsulates the target cluster information for the current run.

func NewClusterInfo added in v1.3.1

func NewClusterInfo(ctx context.Context) (*ClusterInfo, error)

type CollectorConfig

type CollectorConfig struct {
	Type           string                 `mapstructure:"type"`            // Collector type
	File           *FileCollectorConfig   `mapstructure:"file"`            // File collector specific configuration
	Live           *K8SAPICollectorConfig `mapstructure:"live"`            // File collector specific configuration
	NonInteractive bool                   `mapstructure:"non_interactive"` // Skip confirmation
}

CollectorConfig configures collector specific parameters.

type DynamicConfig added in v1.2.0

type DynamicConfig struct {
	RunID       *RunID `mapstructure:"run_id"`
	ClusterName string `mapstructure:"cluster_name"`
	Service     string `mapstructure:"service"`
	// contains filtered or unexported fields
}

DynamicConfig represent application configuration that can be updated at runtime.

func (*DynamicConfig) HealthCheck added in v1.5.0

func (d *DynamicConfig) HealthCheck() error

type DynamicOption added in v1.2.0

type DynamicOption func() (func(*DynamicConfig), error)

DynamicOption is a functional option for configuring the dynamic config.

func WithClusterName added in v1.2.0

func WithClusterName(cluster string) DynamicOption

WithClusterName is a functional option for configuring the cluster name.

func WithRunID added in v1.3.1

func WithRunID(runID string) DynamicOption

WithRunID is a functional option for configuring the runID (using in KHaaS).

type EdgeBuilderConfig

type EdgeBuilderConfig struct {
	LargeClusterOptimizations bool `mapstructure:"large_cluster_optimizations"`
	WorkerPoolSize            int  `mapstructure:"worker_pool_size"`          // Number of workers for the edge builder worker pool
	WorkerPoolCapacity        int  `mapstructure:"worker_pool_capacity"`      // Work item capacity for the edge builder worker pool
	BatchSize                 int  `mapstructure:"batch_size"`                // Batch size for inserts
	BatchSizeSmall            int  `mapstructure:"batch_size_small"`          // Batch size for expensive inserts
	BatchSizeClusterImpact    int  `mapstructure:"batch_size_cluster_impact"` // Batch size for inserts impacting entire cluster e.g POD_PATCH
}

EdgeBuilderConfig configures edge builder parameters.

type FileArchiveConfig added in v1.3.1

type FileArchiveConfig struct {
	ArchiveName string `mapstructure:"archive_name"` // Name of the output archive
	NoCompress  bool   `mapstructure:"no_compress"`  // Disable compression for the dumped data (generates a tar.gz file)
}

type FileCollectorConfig

type FileCollectorConfig struct {
	Directory string             `mapstructure:"directory"` // Base directory holding the K8s data JSON files
	Archive   *FileArchiveConfig `mapstructure:"archive"`   // Archive configuration
}

FileCollectorConfig configures the file collector.

type IngestorAPIConfig added in v1.3.1

type IngestorAPIConfig struct {
	Endpoint string `mapstructure:"endpoint"`
	Insecure bool   `mapstructure:"insecure" validate:"omitempty,boolean"`
}

type IngestorConfig added in v1.3.1

type IngestorConfig struct {
	API            IngestorAPIConfig `mapstructure:"api"`
	Blob           *BlobConfig       `mapstructure:"blob"`
	TempDir        string            `mapstructure:"temp_dir"`
	ArchiveName    string            `mapstructure:"archive_name"`
	MaxArchiveSize int64             `mapstructure:"max_archive_size"`
}

type JanusGraphConfig

type JanusGraphConfig struct {
	URL               string        `mapstructure:"url"` // JanusGraph specific configuration
	ConnectionTimeout time.Duration `mapstructure:"connection_timeout"`
}

JanusGraphConfig configures JanusGraph specific parameters.

type K8SAPICollectorConfig

type K8SAPICollectorConfig struct {
	PageSize           int64 `mapstructure:"page_size"`             // Number of entry being retrieving by each call on the API (same for all Kubernetes entry types)
	PageBufferSize     int32 `mapstructure:"page_buffer_size"`      // Number of pages to buffer
	RateLimitPerSecond int   `mapstructure:"rate_limit_per_second"` // Rate limiting per second across all calls (same for all kubernetes entry types) against the Kubernetes API
}

K8SAPICollectorConfig configures the K8sAPI collector.

type KubehoundConfig

type KubehoundConfig struct {
	Debug      bool             `mapstructure:"debug"`      // Debug mode
	Collector  CollectorConfig  `mapstructure:"collector"`  // Collector configuration
	MongoDB    MongoDBConfig    `mapstructure:"mongodb"`    // MongoDB configuration
	JanusGraph JanusGraphConfig `mapstructure:"janusgraph"` // JanusGraph configuration
	Storage    StorageConfig    `mapstructure:"storage"`    // Global param for all storage provider
	Telemetry  TelemetryConfig  `mapstructure:"telemetry"`  // telemetry configuration, contains statsd and other sub structures
	Builder    BuilderConfig    `mapstructure:"builder"`    // Graph builder  configuration
	Ingestor   IngestorConfig   `mapstructure:"ingestor"`   // Ingestor configuration
	Dynamic    DynamicConfig    `mapstructure:"dynamic"`    // Dynamic (i.e runtime generated) configuration
}

KubehoundConfig defines the top-level application configuration for KubeHound.

func MustLoadConfig

func MustLoadConfig(ctx context.Context, configPath string) *KubehoundConfig

MustLoadConfig loads the application configuration from the provided path, treating all errors as fatal.

func MustLoadEmbedConfig

func MustLoadEmbedConfig(ctx context.Context) *KubehoundConfig

MustLoadEmbedConfig loads the embedded default application configuration, treating all errors as fatal.

func MustLoadInlineConfig added in v1.3.1

func MustLoadInlineConfig(ctx context.Context) *KubehoundConfig

MustLoadConfig loads the application configuration from the provided path, treating all errors as fatal.

func NewConfig

func NewConfig(ctx context.Context, v *viper.Viper, configPath string) (*KubehoundConfig, error)

NewConfig creates a new config instance from the provided file using viper.

func NewEmbedConfig

func NewEmbedConfig(ctx context.Context, v *viper.Viper, configPath string) (*KubehoundConfig, error)

NewEmbedConfig creates a new config instance from an embedded config file using viper.

func NewInlineConfig added in v1.3.1

func NewInlineConfig(ctx context.Context, v *viper.Viper) (*KubehoundConfig, error)

NewConfig creates a new config instance from the provided file using viper.

func NewKubehoundConfig added in v1.3.1

func NewKubehoundConfig(ctx context.Context, configPath string, inLine bool) *KubehoundConfig

func (*KubehoundConfig) ComputeDynamic added in v1.2.0

func (kc *KubehoundConfig) ComputeDynamic(opts ...DynamicOption) error

ComputeDynamic sets the dynamic components of the config from the provided options.

type MongoDBConfig

type MongoDBConfig struct {
	URL               string        `mapstructure:"url"` // Mongodb specific configuration
	ConnectionTimeout time.Duration `mapstructure:"connection_timeout"`
}

MongoDBConfig configures mongodb specific parameters.

type ProfilerConfig

type ProfilerConfig struct {
	Period      time.Duration `mapstructure:"period"`
	CPUDuration time.Duration `mapstructure:"cpu_duration"`
}

ProfilerConfig configures profiler specific parameters.

type RunID added in v1.2.0

type RunID struct {
	// contains filtered or unexported fields
}

RunID represents a unique ID for each KubeHound run.

func LoadRunID added in v1.3.1

func LoadRunID(runid string) (*RunID, error)

func NewRunID added in v1.2.0

func NewRunID() *RunID

NewRunID creates a new RunID instance.

func (RunID) String added in v1.2.0

func (r RunID) String() string

String returns the string representation of the run id. NOTE: this is lowercased to ensure consistency with Datadog (where tags are automatically lower cased)

func (RunID) Timestamp added in v1.2.0

func (r RunID) Timestamp() time.Time

Timestamp returns the timestamp embedded within the run id.

type StatsdConfig

type StatsdConfig struct {
	URL string `mapstructure:"url"` // Statsd endpoint URL
}

StatsdConfig configures statsd specific parameters.

type StorageConfig

type StorageConfig struct {
	Retry      int           `mapstructure:"retry"`
	RetryDelay time.Duration `mapstructure:"retry_delay"`
	Wipe       bool          `mapstructure:"wipe"`
}

type TelemetryConfig

type TelemetryConfig struct {
	Enabled  bool              `mapstructure:"enabled"`  // Whether or not to enable Datadog telemetry
	Tags     map[string]string `mapstructure:"tags"`     // Free form tags to be added to all telemetry
	Statsd   StatsdConfig      `mapstructure:"statsd"`   // Statsd configuration (for metrics)
	Tracer   TracerConfig      `mapstructure:"tracer"`   // Tracer configuration (for APM)
	Profiler ProfilerConfig    `mapstructure:"profiler"` // Profiler configuration
}

type TracerConfig

type TracerConfig struct {
	URL string `mapstructure:"url"` // Tracer endpoint URL
}

TracerConfig configures tracer specific parameters.

type VertexBuilderConfig

type VertexBuilderConfig struct {
	BatchSize      int `mapstructure:"batch_size"`       // Batch size for inserts
	BatchSizeSmall int `mapstructure:"batch_size_small"` // Batch size for expensive inserts

}

VertexBuilderConfig configures vertex builder parameters.

Jump to

Keyboard shortcuts

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