Documentation
¶
Overview ¶
Package scan runs the detector over every object of a repository and attributes what it finds to commits, paths and refs.
Index ¶
- func AnnotateLocal(results []Result, local map[string][]string)
- func Describe(r Result) string
- func Revoke(ctx context.Context, results []Result, tokens []Finding, ...) (int, error)
- func SortFindings(fs []Finding)
- type Finding
- type Location
- type Options
- type Remote
- type Result
- type Revocation
- type Rewrite
- type RunOptions
- type Stats
- type Summary
- type Unlock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnnotateLocal ¶ added in v0.2.0
AnnotateLocal marks every finding whose credential is also configured on this machine, given the sources per fingerprint.
func Revoke ¶ added in v0.2.0
func Revoke(ctx context.Context, results []Result, tokens []Finding, registry *detect.Registry) (int, error)
Revoke asks each credential's provider to revoke it, checks each one again and records the outcome on every finding of that credential in results. It returns the number of credentials the providers confirmed dead. A provider that refuses is reported in the error; the other providers' credentials are still revoked and checked.
func SortFindings ¶
func SortFindings(fs []Finding)
SortFindings orders active credentials first, then the ones nothing has rejected, then opaque material nothing can verify, then the rejected ones; within a group material that is usable as it is before passphrase-protected material, then by kind and fingerprint.
Types ¶
type Finding ¶
type Finding struct {
// Provider names the issuer of the credential: GitHub, Slack.
Provider string `json:"provider"`
Kind detect.Kind `json:"kind"`
Fingerprint string `json:"fingerprint"`
Token string `json:"-"`
// Secret is the companion material of a credential made of several
// strings, when it was found next to the token; see detect.Token.Secret.
Secret string `json:"-"`
Redacted string `json:"token"`
ChecksumVerified bool `json:"checksum_verified"`
// Attribution is what the credential's own shape says about its owner,
// such as the workspace id in a Slack token; known without --verify.
Attribution string `json:"attribution,omitempty"`
// Encrypted marks passphrase-protected material, useless without a
// passphrase that may or may not have leaked with it; see detect.Token.
Encrypted bool `json:"encrypted,omitempty"`
// Opaque marks secret material of no recognised shape, a plaintext
// Kubernetes Secret, which nothing can verify; see detect.KindInfo.
Opaque bool `json:"opaque,omitempty"`
Verification *detect.Verification `json:"verification,omitempty"`
// Revocation records what happened when patty asked the provider to revoke the credential.
Revocation Revocation `json:"revocation,omitempty"`
// Local lists where the same token is configured on this machine.
Local []string `json:"local,omitempty"`
// Unlocks lists the files in the scanned repositories the credential
// opens, when its provider correlates findings with the content around
// them: the sops files encrypted to an age identity.
Unlocks []Unlock `json:"unlocks,omitempty"`
Locations []Location `json:"locations"`
// Occurrences counts objects the token appears in, across all locations.
Occurrences int `json:"occurrences"`
}
Finding is one distinct credential and everywhere it appears.
func Merge ¶ added in v0.2.0
Merge groups the findings of all results by credential, so one that leaked into several repositories is one entry with every location and everything it unlocks. Active credentials come first.
func NewFinding ¶ added in v0.5.0
NewFinding starts the finding for a credential: provider, kind, fingerprint and redacted value, with no locations yet.
func Revocable ¶ added in v0.2.0
Revocable returns the distinct active credentials across results that their provider's revocation endpoint accepts, active ones first.
func (Finding) Active ¶ added in v0.2.0
Active reports whether the provider confirmed the credential as live.
func (Finding) Revoked ¶ added in v0.2.0
Revoked reports whether the provider confirmed the credential as dead.
func (Finding) Unverifiable ¶ added in v0.6.0
Unverifiable reports whether the credential cannot be checked against its provider, so no verdict about it will ever come.
type Location ¶
type Location struct {
Repo string `json:"repo"`
Object string `json:"object"`
ObjectType string `json:"object_type"`
Path string `json:"path,omitempty"`
Line int `json:"line"`
Commit *gitrepo.Commit `json:"commit,omitempty"`
// Refs contains the refs whose history includes the commit.
Refs []string `json:"refs,omitempty"`
// Orphaned is true when no ref reaches the commit anymore.
Orphaned bool `json:"orphaned"`
// Rewrite explains how the commit went unreachable on the server, when known.
Rewrite string `json:"rewrite,omitempty"`
}
Location is one place a token was found.
type Options ¶
type Options struct {
// Workers is the number of parallel `git cat-file` readers.
Workers int
// MaxObject skips objects larger than this many bytes.
MaxObject int64
// Ignore holds the token fingerprints and credential kinds to leave out
// of the results.
Ignore map[string]bool
// Providers is the set of credential providers to look for; nil means
// every provider patty ships with.
Providers *detect.Registry
// Verify checks each credential found against its provider's API.
Verify bool
}
Options tune a repository scan.
type Remote ¶ added in v0.13.0
type Remote struct {
Rewrites []Rewrite
// Contributors are GitHub logins, as the repository's contributors
// endpoint lists them; the scan adds the logins it reads from noreply
// author addresses itself.
Contributors []string
}
Remote is what the hosting service knows about a repository beyond its objects: the commits its activity feed reports as rewritten, and the logins of its contributors. A local repository has neither.
type Result ¶
type Result struct {
Target string `json:"target"`
Findings []Finding `json:"findings"`
Stats Stats `json:"stats"`
Notes []string `json:"notes,omitempty"`
Err error `json:"-"`
Error string `json:"error,omitempty"`
Skipped bool `json:"skipped,omitempty"`
}
Result is the outcome for one target.
type Revocation ¶ added in v0.2.0
type Revocation string
Revocation is the outcome of asking a provider to revoke a credential.
const ( // RevocationDone means the provider accepted the request and no longer honours the credential. RevocationDone Revocation = "revoked" // RevocationPending means the provider accepted the request but still // answered the follow-up check as active; GitHub processes revocations // asynchronously. RevocationPending Revocation = "pending" // RevocationUnsupported means the credential family cannot be revoked through the API. RevocationUnsupported Revocation = "unsupported" )
type Rewrite ¶
Rewrite names a commit that was fetched by SHA because a server-side ref update (force push, branch deletion) had made it unreachable.
type RunOptions ¶
type RunOptions struct {
Options
// Cache holds the mirrors of GitHub targets.
Cache *disk.Cache
// Keep leaves mirrors in the cache after the scan for faster re-runs.
Keep bool
// Auth is used for HTTPS clones; nil for anonymous.
Auth *gitrepo.Auth
// GitHub is needed for the activity feed; nil disables it.
GitHub *github.Client
// Rewrites fetches commits the activity feed reports as force-pushed or deleted.
Rewrites bool
// ActivityPages caps the activity feed pages read per type and repository.
ActivityPages int
// Parallel is the number of repositories processed at once.
Parallel int
// Progress receives phase messages; may be nil.
Progress func(target, msg string)
}
RunOptions configure a run over many targets.
type Stats ¶
type Stats struct {
Objects int `json:"objects"`
Scanned int `json:"scanned"`
Skipped int `json:"skipped_large"`
Bytes int64 `json:"bytes"`
Refs int `json:"refs"`
Orphaned int `json:"orphaned_commits"`
Rewrites int `json:"rewrites_fetched"`
Disk int64 `json:"disk_bytes,omitempty"`
Duration time.Duration `json:"-"`
}
Stats summarises one repository scan.
type Summary ¶
type Summary struct {
Repos int
Failed int
Skipped int
Tokens int
Active int
Bytes int64
Objects int
Duration time.Duration
}
Summary aggregates results for the final line of a report.
type Unlock ¶ added in v0.7.0
type Unlock struct {
Repo string `json:"repo"`
Path string `json:"path"`
// Detail is what the file says about the credential when the path
// alone does not: the names and expiry of the certificate a private
// key belongs to.
Detail string `json:"detail,omitempty"`
}
Unlock is one file a credential opens or that names it; see Finding.Unlocks.