Documentation
¶
Overview ¶
Package secretscan finds the places where a daemon takes a secret as a plaintext value (a config field, a flag, an environment variable, a unit file) instead of by reference, and reports them with the denominator that makes the answer worth reading.
PRECISION OVER RECALL ¶
A name heuristic that cries wolf on `max_tokens` gets switched off, and a gate that is switched off protects nothing. So a name is judged by its WORDS (never by a substring), the last word must be the secret word, and a trailing `file`, `path`, `from` or `env` changes the CLASS instead of hiding the finding: `token_file` is a path to a secret, `password_from` is a secretsource reference, and neither is the secret itself. The committed corpus testdata/names.tsv holds the true positives and the false positives the heuristic was written against; adding a name there is how it is amended.
Index ¶
- Constants
- func ExecGit(dir string, args ...string) (string, error)
- func InlineSecret(line string) (name, value string, ok bool)
- func Tokens(name string) []string
- func URLName(scheme string) string
- func URLSecret(s string) (scheme, password string, ok bool)
- type Class
- type Clone
- type Denominator
- type Finding
- type Git
- type GoScan
- type Hit
- type OrgCount
- type Repo
- type Report
- type Staleness
- type Unread
Constants ¶
const MaxFile = 4 << 20
MaxFile bounds what is read of any one file. A bigger one is reported as unread, never skipped quietly: a scan that could not read says so.
const SecretsourcePath = "github.com/go-authn/secretsource"
SecretsourcePath is the import path of the fleet's reference resolver.
Variables ¶
This section is empty.
Functions ¶
func InlineSecret ¶
InlineSecret reads one line of a sample (toml, yaml, env file, a shell command, a JSON object) and returns the name and the value when it sets a plaintext secret to something. Comments and prose are not read.
func Tokens ¶
Tokens splits a name into lower-case words at separators and at case changes: `APIKey` is api, key; `client_secret_file` is client, secret, file.
func URLName ¶ added in v0.176.0
URLName is the name a URL-userinfo finding carries: the shape, never the password itself.
Types ¶
type Class ¶
type Class string
Class says how a secret input receives its secret.
const ( // None: the name does not denote a secret. None Class = "" // Plaintext: the value IS the secret. The class a gate refuses. Plaintext Class = "plaintext" // Path: a `*_file` style path to a file holding the secret. Path Class = "path" // Ref: a `*_from` secretsource reference (`systemd-creds:name`, ...). Ref Class = "ref" // Env: the NAME of an environment variable that holds the secret. Env Class = "env" )
type Clone ¶
type Clone struct {
Dir string `json:"dir"`
Org string `json:"org,omitempty"`
Origin string `json:"origin,omitempty"` // canonical origin URL; see Key
Read bool `json:"read"`
SkipReason string `json:"skip_reason,omitempty"`
Repo Repo `json:"repo"`
Staleness Staleness `json:"staleness"`
}
Clone is one directory under the root.
type Denominator ¶
type Denominator struct {
Seen int `json:"clones_seen"`
Read int `json:"clones_read"`
Skipped int `json:"clones_skipped"`
FilesRead int `json:"files_read"`
FilesUnread int `json:"files_unread"`
Ignored int `json:"entries_ignored"` // loose files and dot-directories: not clone candidates
GitUnreadable int `json:"git_unreadable"`
NeverFetched int `json:"never_fetched"`
Stale int `json:"stale"`
DaemonRepos int `json:"daemon_repos"`
DaemonsPlaintext int `json:"daemon_repos_with_plaintext"`
UsesSecretsource int `json:"uses_secretsource"`
}
Denominator is what the sweep covered. Every count is of something the sweep did, so that "none found" can be told from "none looked at".
type Finding ¶
type Finding struct {
Kind string `json:"kind"` // "input" (what the daemon takes) or "sample" (what a doc shows)
Source string `json:"source"` // config-field, flag, env, unit-env, unit-flag, sample, doc
Class Class `json:"class"`
Name string `json:"name"`
File string `json:"file"`
Line int `json:"line"`
PermChecked *bool `json:"perm_checked,omitempty"` // path class only; a heuristic, see ScanRepo
Placeholder bool `json:"placeholder,omitempty"` // sample class only: the value looks like a stand-in
Exposure int `json:"exposure"` // 1 doc … 4 value stored in a shipped file
}
Finding is one secret input, or one sample that shows a secret value.
type Git ¶
Git runs git in dir and returns its trimmed standard output. It is a parameter so that a test can answer for a clone that is not there; the real one never fetches, because staleness is what the LOCAL refs say.
type GoScan ¶
type GoScan struct {
Findings []Finding
Imports []string
HasMain bool // declares func main
Serves bool // listens, serves, or waits for a signal: a daemon marker
PermEvidence bool // checks a file's permissions, or goes through secretsource
}
GoScan is what one Go source file says.
type Repo ¶
type Repo struct {
Daemon bool `json:"daemon"`
Daemons []string `json:"daemons,omitempty"` // main packages that serve, and unit/plist files
GoFiles int `json:"go_files"`
FilesRead int `json:"files_read"`
Unread []Unread `json:"unread,omitempty"`
UsesSecretsource bool `json:"uses_secretsource"`
Findings []Finding `json:"findings,omitempty"` // empty unless Daemon
}
Repo is what one clone says.
func ScanRepo ¶
ScanRepo reads one clone. A clone is a daemon when it ships a systemd unit or a launchd plist, or has a main package that serves or waits for a signal in its own directory; a main that only calls into a library server is found through its unit file or not at all, which is a stated limit. Findings are kept for a daemon only, unless all is set: a client's `--token` flag is not a daemon's secret.
perm_checked on a path finding is a HEURISTIC: the package (directory) contains a `.Perm()` or `Mode()&` test, a 0o077-style mask, or imports secretsource. It says "something checks permissions here", not that this path is checked.
type Report ¶
type Report struct {
Generated time.Time `json:"generated"`
Root string `json:"root"`
Denominator Denominator `json:"denominator"`
Clones []Clone `json:"clones"`
}
Report is the whole sweep.
func (Report) Complete ¶
Complete says whether everything seen was read: no clone skipped, no file unread, no git answer missing. A sweep that is not complete is NOT READ where it is incomplete, and must not be read as clean there.
func (Report) Orgs ¶
Orgs returns the organisations that hold a plaintext secret input, with the number of such inputs, most first. An unknown org is named "(unknown)".
func (Report) Top ¶
Top returns the plaintext secret inputs of daemon clones, most exposed first: a value stored in a shipped unit, then a flag (visible to `ps`), then an environment variable or a config field. n <= 0 means all of them.
type Staleness ¶
type Staleness struct {
NeverFetched bool `json:"never_fetched"`
FetchedAt *time.Time `json:"fetched_at,omitempty"` // .git/FETCH_HEAD mtime
NoUpstream bool `json:"no_upstream"` // detached, or a branch with no tracking ref
Ahead int `json:"ahead"`
Behind int `json:"behind"`
Stale bool `json:"stale"` // never fetched, older than the limit, or behind
GitError string `json:"git_error,omitempty"`
}
Staleness says how old a clone's view of its remote is.