Documentation
¶
Overview ¶
Package ghas implements the pkg/source plugin for GitHub Advanced Security code-scanning alerts (CodeQL first). It 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.
Index ¶
- Constants
- func FindingFromAlert(repo ghclient.Repo, alert *ghclient.Alert) source.Finding
- 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
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.
Variables ¶
This section is empty.
Functions ¶
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.