Documentation
¶
Overview ¶
Package config is Draugr's machine- and organization-level configuration, kept apart from the Saga on purpose.
A Saga describes an application: which repositories it has, how exposed a component is, which controls must pass. Those are facts about the software, they belong in its repository, and they are meant to differ between projects.
This file describes the machine or the organization running the scan: which build of a scanner to install, and what a control should default to before any project says otherwise. Those want to be *uniform*, and putting them in a Saga makes them diverge silently. A descriptor that can pin its own scanner version is a descriptor that can downgrade one until a finding disappears.
Index ¶
- Constants
- func CurrentKey(key string) string
- func DeepMerge(dst, src saga.ControllerSettings) saga.ControllerSettings
- func Discovered(workDir string) []string
- func Explicit(flag string) string
- func Files(explicit, workDir string) []string
- func Get(doc []byte, key string) (string, bool)
- func On(b *bool) bool
- func ProjectFile(workDir string) string
- func Set(doc []byte, key, value string) ([]byte, error)
- func Unset(doc []byte, key string) ([]byte, error)
- type CacheSettings
- type File
- type NotSetError
- type OutputSettings
- type Override
- type Problems
- type PublishSettings
- type Resolved
- type Source
- type ToolSettings
Constants ¶
const EnvVar = "DRAUGR_CONFIG"
EnvVar names a config file explicitly, which is the organization-wide lever: set it in a runner image and every pipeline picks up the same defaults with no per-repository change.
const FileName = "draugr.config.yaml"
FileName is the config a project may carry beside its Saga.
const KeysHint = "every key is listed at " + KeysURL
KeysHint closes a report of a key or value the file cannot hold.
const KeysURL = "https://draugr.dev/docs/latest/reference/cli/#draugr-config"
KeysURL is where every key of the file is documented.
Variables ¶
This section is empty.
Functions ¶
func CurrentKey ¶ added in v0.160.0
CurrentKey is a dotted key with the older `controllers` spelling of its first segment replaced by `controls`, the name the section is read under.
func DeepMerge ¶
func DeepMerge(dst, src saga.ControllerSettings) saga.ControllerSettings
DeepMerge lays src over dst, recursing into nested maps so an override replaces only the keys it names. Exported because the same rule applies when these defaults meet a Saga's.
func Discovered ¶ added in v0.160.0
Discovered lists the files that exist where Load looks when no file is named, least specific first. With a file named, these are the ones it skips.
func Explicit ¶ added in v0.154.0
Explicit is the file named by `--config`, or by DRAUGR_CONFIG when the flag is empty, or "" when neither names one. Reading and editing both resolve it here, so `config set` writes the file a scan reads.
func Files ¶ added in v0.158.1
Files lists the files Load reads, least specific first: the explicit file alone when one is named, whether or not it exists, or else each discovered file that exists.
func On ¶ added in v0.158.1
On reports whether a boolean setting is present and true. An absent one is off.
func ProjectFile ¶ added in v0.158.1
ProjectFile is where Load looks for a project's file: FileName in the working directory.
func Set ¶
Set writes key=value into a configuration document, returning the new bytes.
The document is edited as a node tree rather than decoded and re-encoded, so **comments survive**. A `config set` that silently deleted the explanation somebody wrote next to a version pin would teach people not to use it, and they would go back to hand-editing the file this command exists to keep valid.
The key is a dotted path, `tools.trivy.version`, `controls.sca.mend.policy`. Intermediate mappings are created as needed, in block style, and an empty `{}` on the way becomes one too.
A value starting with `[` or `{` is a YAML flow list or mapping, `[library]` or `{config: x}`; anything else is one scalar, so a URL or a value holding `: ` is written as typed. The rule reads only the first character, because a value whose meaning depends on whether it happens to parse is a value nobody can predict.
func Unset ¶
Unset removes a key, and any mapping it leaves empty. A key the document does not hold is a *NotSetError and no document, so the caller writes nothing.
The cleanup matters: a `controls.sca.mend` left behind as an empty mapping after its last setting is removed is not the same file as one that never mentioned mend, and the difference shows up later as a scanner block that exists and configures nothing.
A key under `controls` also removes the same key under the older `controllers`, and the other way round, because both spellings load as one section.
Types ¶
type CacheSettings ¶ added in v0.66.0
type CacheSettings struct {
// Dir enables caching and says where. Empty leaves caching off, which stays the default:
// a cache is a promise that an unchanged input has an unchanged answer, and that is a promise
// somebody should opt into.
Dir string `yaml:"dir,omitempty"`
// TTL is how long an entry stays usable. Unset leaves the built-in default; `0s` written in
// the file means no expiry, as `--cache-ttl 0` does. A pointer, so the two are told apart and
// a more specific file's `0s` overrides a less specific file's duration.
TTL *time.Duration `yaml:"ttl,omitempty"`
// ReadOnly serves entries without writing them, for a run whose results the next run should
// not trust. Layered one way: a more specific file's `false` does not clear a less specific
// file's `true`, and Resolved.Overrides reports the `false` that was outranked.
ReadOnly *bool `yaml:"readOnly,omitempty"`
// RequireDigest refuses to cache an image named only by a tag, which can be rebuilt under the
// same name. Layered one way, as ReadOnly is.
RequireDigest *bool `yaml:"requireDigest,omitempty"`
}
CacheSettings configures result caching.
type File ¶
type File struct {
// Tools pins the build of each external scanner. Provisioning rather than behavior, and
// deliberately not readable from a Saga.
Tools map[string]ToolSettings `yaml:"tools,omitempty"`
// Controls are default settings merged *underneath* the Saga's, so a project overrides only
// the keys it cares about and inherits the rest. The same name and shape as a descriptor's
// `config.controls`.
Controls map[string]saga.ControllerSettings `yaml:"controls,omitempty"`
// Controllers is the older spelling, still read so no file breaks.
//
// Deprecated: write `controls`. Folded into Controls when a file is parsed, so nothing else has
// to know both names.
Controllers map[string]saga.ControllerSettings `yaml:"controllers,omitempty"`
// Cache is where scan results are reused between runs, and for how long.
//
// Here rather than in a Saga for the same reason as Tools: a cache directory is a fact about
// a machine or a runner image, not about the application being described. Two projects on one
// runner want the same cache; one project on two runners does not want its descriptor
// naming a path that exists on only one of them.
Cache CacheSettings `yaml:"cache,omitempty"`
// Publish holds defaults for where a run is delivered.
//
// Here rather than in a Saga because an endpoint is a fact about an organization, not about
// an application: forty projects pointing at one install would otherwise repeat the URL in
// forty descriptors and change it in forty places when the host moves.
Publish PublishSettings `yaml:"publish,omitempty"`
// Output is how a report is rendered for whoever reads it here.
//
// A rendering preference belongs to a person or a machine, not to an application: an auditor
// wants the evidence on every scan they run, and a pipeline wants the same listing for every
// repository it builds. Putting either in a descriptor asserts it on everyone else who scans
// that application.
Output OutputSettings `yaml:"output,omitempty"`
}
File is a parsed configuration.
func Parse ¶
Parse decodes and validates a configuration.
Strict: an unknown key is an error rather than something ignored. A misspelled setting that is silently dropped is a setting somebody believes is in force, and this file exists to make behavior uniform, a typo that quietly opts one machine out defeats the point of having it.
A failure is a *Problems naming every key at fault in the file's own terms, rather than the Go types it decodes into, returned beside whatever of the file did decode.
type NotSetError ¶ added in v0.160.0
type NotSetError struct {
// Key is the dotted key that was asked for.
Key string
}
NotSetError is Unset's answer for a key the document does not hold.
func (*NotSetError) Error ¶ added in v0.160.0
func (e *NotSetError) Error() string
type OutputSettings ¶ added in v0.96.0
type OutputSettings struct {
// View is what a console report shows: "findings" (a row each, with what argued with the band
// under it), "actions" (a row per thing to do) or "compact" (one line each).
View string `yaml:"view,omitempty"`
// Evidence also prints what stands behind the verdict, tool provenance, what each control
// measured against, the scanned revision, what the run cost. A pointer, so a more specific
// file's `false` is a setting that overrides a less specific file's `true`.
Evidence *bool `yaml:"evidence,omitempty"`
// Top caps how many rows the fix list shows. Zero means the built-in default rather than
// "show none": a file that omits a field is not asking for an empty list.
Top int `yaml:"top,omitempty"`
// OfferInstall is whether `draugr scan` on a terminal offers to install the scanners it is
// missing before it runs. Unset means it offers; answering "never" writes false.
OfferInstall *bool `yaml:"offerInstall,omitempty"`
}
OutputSettings configures how the console renders a run. Each has a `--flag` that overrides it, except OfferInstall, which answers a question only a terminal is asked.
func (OutputSettings) Offers ¶ added in v0.154.0
func (o OutputSettings) Offers() bool
Offers reports whether a scan on a terminal may offer to install missing scanners.
type Override ¶ added in v0.158.1
type Override struct {
// Key is the dotted setting, e.g. "cache.readOnly".
Key string
// Path is the file whose value does not take effect.
Path string
// By is the less specific file whose value stays in force.
By string
}
Override is a setting a file makes that a less specific file outranks.
type Problems ¶ added in v0.158.1
type Problems struct {
// Path is the file.
Path string
// List holds one problem per line, each led by the dotted key it is about.
List []string
// Hint is where to look next, printed after the list.
Hint string
}
Problems is every reason one configuration file cannot be used, each naming the key it is about.
type PublishSettings ¶ added in v0.105.0
type PublishSettings struct {
// APIURL is where the draugr-api publisher posts when $DRAUGR_API_URL is unset.
//
// Who wrote it decides how far it is trusted, because the publisher sends its token there.
// From ~/.draugr/config.yaml, or the file --config or $DRAUGR_CONFIG names, it is the machine's
// answer. From the draugr.config.yaml in the directory being scanned, which is committed with the
// repository and changes by pull request, it is held to the rule for a url: in the Saga: used
// only on the machine's server's origin, or one $DRAUGR_API_ORIGINS lists.
//
// No token here, and there never will be. This file is committed alongside a project, and a
// credential in it is a credential in somebody's git history.
APIURL string `yaml:"apiUrl,omitempty"`
}
PublishSettings holds defaults for the publishers a run delivers to.
type Resolved ¶
Resolved is the configuration in effect, and the files it came from, nearest last.
func Load ¶
Load reads the configuration in effect.
An explicit path. `--config` or DRAUGR_CONFIG. Is used *alone*. Explicit means explicit: a runner image that names a config expects that config, not that one layered over whatever happens to be in the working directory.
Otherwise the home file is layered under the project file, so a personal default can be overridden by a repository that has an opinion. Missing files are not an error; a machine with no configuration is the normal case. Every file is read before an error is returned, so two broken files are reported together.
type Source ¶
Source records where a loaded file came from, so a reader can be told which one to edit.
type ToolSettings ¶
type ToolSettings struct {
// Version is the release to install, e.g. "0.69.3".
Version string `yaml:"version,omitempty"`
}
ToolSettings pins one external tool.