Documentation
¶
Overview ¶
Package ghas implements the pkg/source plugins for GitHub Advanced Security.
The code-scanning source ("ghas", Handler) consumes code_scanning_alert webhook deliveries, fetches the full alert for rule help and location detail, and normalizes it into a source.Finding. CWE identifiers from CodeQL rule tags become the advisory categorization.
The secret-scanning source ("ghas-secrets", Secrets) consumes secret_scanning_alert deliveries. Its findings carry the secret category, accumulate on "secret:<secret type>", and never carry the secret value: the delivery is read only for the alert number, and the alert is re-fetched with GitHub's hide_secret option.
Index ¶
- Constants
- func FindingFromAlert(repo ghclient.Repo, alert *ghclient.Alert) source.Finding
- func FindingFromSecretAlert(repo ghclient.Repo, alert *ghclient.SecretAlert) (source.Finding, error)
- func SecretResolution(reason string) string
- type AlertDismisser
- type AlertEnumerator
- type AlertGetter
- type Handler
- func (h *Handler) Findings(ctx context.Context, event string, payload []byte) ([]source.Finding, error)
- func (h *Handler) ID() string
- func (h *Handler) List(ctx context.Context, repos []string, yield func(source.Finding) bool) (complete bool, err error)
- func (h *Handler) Resolve(ctx context.Context, alerts []source.AlertRef, v source.Verdict) error
- type SecretAlertEnumerator
- type SecretAlertGetter
- type SecretAlertResolver
- type Secrets
- func (s *Secrets) Findings(ctx context.Context, event string, payload []byte) ([]source.Finding, error)
- func (s *Secrets) ID() string
- func (s *Secrets) List(ctx context.Context, repos []string, yield func(source.Finding) bool) (complete bool, err error)
- func (s *Secrets) Resolve(ctx context.Context, alerts []source.AlertRef, v source.Verdict) error
Constants ¶
const EventType = "code_scanning_alert"
EventType is the webhook event this source consumes.
const ID = "ghas"
ID is the source identifier stamped into the security-source label.
const SecretsEventType = "secret_scanning_alert"
SecretsEventType is the webhook event the secret-scanning source consumes.
const SecretsID = "ghas-secrets"
SecretsID is the secret-scanning source identifier.
Variables ¶
This section is empty.
Functions ¶
func FindingFromAlert ¶ added in v0.10.0
FindingFromAlert normalizes one code-scanning alert into the source-agnostic finding shape. Both the webhook path and the backfill lister use it.
func FindingFromSecretAlert ¶ added in v0.15.0
func FindingFromSecretAlert(repo ghclient.Repo, alert *ghclient.SecretAlert) (source.Finding, error)
FindingFromSecretAlert normalizes one secret-scanning alert. Both the webhook path and the backfill lister use it. Nothing it reads can hold the secret value: ghclient.SecretAlert has no field for one.
func SecretResolution ¶ added in v0.15.0
SecretResolution maps a canonical verdict reason onto a secret-scanning resolution. Anything else, including empty, is a false positive: that is what an "ignore" verdict means by default.
Types ¶
type AlertDismisser ¶ added in v0.8.0
type AlertDismisser interface {
DismissAlert(ctx context.Context, repo ghclient.Repo, number int, reason, comment string) error
}
AlertDismisser closes a code-scanning alert on the forge. It is the write-back half of the source, used when the investigation returns "ignore".
type AlertEnumerator ¶ added in v0.10.0
type AlertEnumerator interface {
Enumerate(
ctx context.Context, repos []string, yield func(ghclient.Repo, *ghclient.Alert) bool,
) (complete bool, err error)
}
AlertEnumerator walks the open code-scanning alerts the credential can reach: an installation fan-out for an App, an explicit repository list for a PAT (ghclient.AppAlertEnumerator / PATAlertEnumerator). The repos it receives are only a scope hint for skipping whole installations. The Handler applies the authoritative per-repository filter.
type AlertGetter ¶
type AlertGetter interface {
GetAlert(ctx context.Context, repo ghclient.Repo, number int) (*ghclient.Alert, error)
}
AlertGetter fetches the full code-scanning alert; the webhook payload carries a summary, but the rule help markdown only comes from the API.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the GHAS source plugin. New builds the ingest handler, NewResolver the verdict write-back, and NewLister the backfill listing. They are separate constructors because the repository comes from the payload on ingest, from the finding on write-back, and is the credential's whole scope for a backfill.
func New ¶
func New(alerts AlertGetter) *Handler
New builds the ingest handler around an alert fetcher (typically an adapter that resolves the right installation client per repository).
func NewLister ¶ added in v0.10.0
func NewLister(e AlertEnumerator) *Handler
NewLister builds a handler for the backfill path, enumerating open alerts through e.
func NewResolver ¶ added in v0.8.0
func NewResolver(d AlertDismisser, repo ghclient.Repo) *Handler
NewResolver builds a handler for the write-back path, dismissing alerts on repo. A zero repo means the finding has no repository, so there is nothing on GitHub to dismiss and Resolve does nothing.
func (*Handler) Findings ¶
func (h *Handler) Findings(ctx context.Context, event string, payload []byte) ([]source.Finding, error)
Findings implements source.Handler: it normalizes one delivery, fetching the full alert from the API.
func (*Handler) List ¶ added in v0.10.0
func (h *Handler) List( ctx context.Context, repos []string, yield func(source.Finding) bool, ) (complete bool, err error)
List implements source.Lister: it walks the enumerator's open alerts, keeps the ones matching the repository filter, and yields each as a finding. complete is false when the walk ended early: the caller's yield stopped it or the enumerator's page budget ran out.
func (*Handler) Resolve ¶ added in v0.8.0
Resolve implements source.Resolver: it dismisses every code-scanning alert it is handed. The caller groups alerts by source and passes only this handler's own, so a GHAS alert id is always a decimal alert number. An id that is not is corrupt state and is reported as an error, not skipped as another tool's identifier.
type SecretAlertEnumerator ¶ added in v0.15.0
type SecretAlertEnumerator interface {
Enumerate(
ctx context.Context, repos []string, yield func(ghclient.Repo, *ghclient.SecretAlert) bool,
) (complete bool, err error)
}
SecretAlertEnumerator walks the open secret-scanning alerts the credential can reach (ghclient.AppSecretAlertEnumerator or PATSecretAlertEnumerator), with AlertEnumerator's contract.
type SecretAlertGetter ¶ added in v0.15.0
type SecretAlertGetter interface {
GetSecretAlert(ctx context.Context, repo ghclient.Repo, number int) (*ghclient.SecretAlert, error)
}
SecretAlertGetter fetches the full secret-scanning alert. The webhook payload carries the secret in plain text, so the source never reads the alert from the payload: it re-fetches it with the secret hidden.
type SecretAlertResolver ¶ added in v0.15.0
type SecretAlertResolver interface {
ResolveSecretAlert(ctx context.Context, repo ghclient.Repo, number int, resolution, comment string) error
}
SecretAlertResolver closes a secret-scanning alert on the forge.
type Secrets ¶ added in v0.15.0
type Secrets struct {
// contains filtered or unexported fields
}
Secrets is the GitHub secret-scanning source plugin. Like Handler, each constructor builds one role: ingest, write-back, or backfill listing.
func NewSecrets ¶ added in v0.15.0
func NewSecrets(alerts SecretAlertGetter) *Secrets
NewSecrets builds the ingest handler around a secret-alert fetcher.
func NewSecretsLister ¶ added in v0.15.0
func NewSecretsLister(e SecretAlertEnumerator) *Secrets
NewSecretsLister builds the backfill handler over e.
func NewSecretsResolver ¶ added in v0.15.0
func NewSecretsResolver(r SecretAlertResolver, repo ghclient.Repo) *Secrets
NewSecretsResolver builds the write-back handler, resolving alerts on repo. A zero repo leaves nothing on GitHub to resolve.
func (*Secrets) Findings ¶ added in v0.15.0
func (s *Secrets) Findings(ctx context.Context, event string, payload []byte) ([]source.Finding, error)
Findings implements source.Handler. The delivery is decoded only for the action, alert number and repository; the alert itself (minus its secret) comes from the API.