Documentation
¶
Overview ¶
Package config resolves TokenHound configuration once per run. Layers, lowest first: defaults, the project tokenhound.yaml at the scan root (or --config), the user file <user config dir>/tokenhound/config.yaml, TOKENHOUND_* environment variables and flags. Each set leaf replaces the one below it; lists replace.
Trust tiers (AD-24): the project file may come from a hostile repository, so network.*, alerts.*, hook.* and ping are ignored from it; it may not disable verification or set timeout, its limits (up to 4x their default) and verify.timeout may only rise above the trusted value, its grade.f_threshold_usd_per_day and verify.max_concurrency may only fall below it, its durations are bounded and its fail_on may only tighten the policy (all applied after every other layer); ${NAME} references in it stay literal and its paths must stay inside the project root. Every ignored value gives a warning that names the key and never the value.
Errors and warnings never carry config values, environment values or foreign error text (AD-3). The package never imports the public tokenhound package: the public config package maps Resolved onto tokenhound.Options.
Index ¶
Constants ¶
const ( // ProjectFile is the project-tier config file at the scan root. ProjectFile = "tokenhound.yaml" // UserFile is the user-tier config file under the user config directory. UserFile = "tokenhound/config.yaml" // EnvPrefix starts every environment variable the config reads. EnvPrefix = "TOKENHOUND_" // SupportedVersion is the only config version this binary reads. SupportedVersion = 1 )
File names and limits.
const ( DefaultVerifyConcurrency = 8 DefaultVerifyTimeout = 10 * time.Second DefaultFThresholdUSD = 500 DefaultMaxFileBytes = 10 << 20 DefaultArchiveMaxBytes = 256 << 20 DefaultArchiveMaxDepth = 5 DefaultArchiveMaxEntries = 10000 DefaultDecodeMaxDepth = 3 DefaultHookMode = "block" DefaultHookOnError = "warn-allow" )
Defaults.
const ( // DetailProjectTier: the key is honoured only from the user tier. DetailProjectTier = "project_tier" // DetailFailOnLoosening: a project fail_on value would loosen the policy. DetailFailOnLoosening = "fail_on_loosening" // DetailGateLoosening: a project value would weaken the scan behind the gate // (verification off, a timeout, a lower limit or verify timeout, a higher grade // threshold or verify.max_concurrency). DetailGateLoosening = "gate_loosening" // DetailEnvReference: a ${NAME} reference in the project tier is kept as a // literal (the value is used, not ignored). DetailEnvReference = "env_reference" // DetailAbsolutePath: a project path is absolute. DetailAbsolutePath = "absolute_path" // DetailParentTraversal: a project path climbs out of the root. DetailParentTraversal = "parent_traversal" // DetailProjectLimitCap: a project limit is above what the project tier may // raise it to (4x the default, at most the schema maximum). DetailProjectLimitCap = "project_limit_cap" )
Detail codes of config warnings.
const ( FlagNoVerify = "--no-verify" FlagFailOnStatus = "--fail-on-status" FlagFailOnWarnings = "--fail-on-warnings" FlagFailOnMinDollars = "--fail-on-min-dollars" FlagTimeout = "--timeout" )
Flag names, for issues about flag values.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Alerts ¶
type Alerts struct {
SlackWebhookEnv string
TeamsWebhookEnv string
WebhookURLEnv string
OnStatuses []model.Status
Timeout time.Duration
}
Alerts is the alerts block (user tier only).
type Error ¶
type Error struct {
Issues []yamlschema.Issue
}
Error is a config that cannot be used. Each issue prints as "file:line: field: message" (or "NAME: field: message" for an environment variable or flag).
type Flags ¶
type Flags struct {
// Verify is false for --no-verify.
Verify *bool
FailOnStatus *string
FailOnWarnings *string
FailOnMinDollars *string
Timeout *string
}
Flags are the command line values that override config. A nil field is not set. String fields hold the raw flag text: lists are comma separated.
type Input ¶
type Input struct {
// Root is the project root: the scan root directory ("" means Cwd).
Root string
// ConfigFile replaces <Root>/tokenhound.yaml when set (--config); it is still
// project tier. A relative path is relative to Cwd and is displayed as given;
// relative paths inside it resolve against Root.
ConfigFile string
// Flags override everything else.
Flags Flags
// LookupEnv reads the environment (nil means os.LookupEnv).
LookupEnv func(string) (string, bool)
// UserConfigDir returns the user config directory (nil means os.UserConfigDir).
// An error skips the user tier.
UserConfigDir func() (string, error)
// ReadFile reads a config file or the CA bundle (nil means a bounded os read).
ReadFile func(string) ([]byte, error)
// Cwd resolves relative environment and flag paths ("" means os.Getwd).
Cwd string
}
Input is what Resolve reads. Every lookup is injectable so tests are hermetic.
type Limits ¶
type Limits struct {
MaxFileBytes int64
ArchiveMaxBytes int64
ArchiveMaxDepth int
ArchiveMaxEntries int
DecodeMaxDepth int
}
Limits is the limits block.
type Resolved ¶
type Resolved struct {
Verify Verify
FailOn FailOn
Timeout time.Duration
Grade Grade
Limits Limits
Network Network
Hook Hook
Alerts Alerts
Ping bool
// Paths holds the resolved absolute path of each set path key (ignore_file,
// baseline, import.gitleaks, import.trufflehog, custom_detectors) and the tier
// it came from, so later stories can apply their own tier rules (Story 1.9 drops
// verify blocks from project-tier custom detectors).
Paths map[string]Path
}
Resolved is the effective configuration.
func Defaults ¶
Defaults returns the defaults, with fail_on.warnings [timeout, file_too_large] when ci is set: a scan that was cut short, or that skipped a file because it is over limits.max_file_bytes (a key in it would go unseen), must not pass a CI gate. The project tier can only add to fail_on, never drop these (see docs/adr/0002).