action

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package action owns the human-action vocabulary and the state-machine gating behind it: which verbs exist, and what each one is allowed to do to a Finding's spec in a given phase.

It exists so the two clients that apply human actions cannot drift. The status server (internal/web) applies them as its own ServiceAccount after a SubjectAccessReview; the patchy CLI (cmd/patchy) applies them as the signed-in user's kubeconfig identity. Both call Apply, so a phase gate tightened here tightens in both places at once.

Authorization is NOT this package's job. It decides only whether an action is meaningful, never whether the caller may take it. Grants live in internal/web/authz (SubjectAccessReview) for the server, in a SelfSubjectAccessReview for the CLI, and are enforced for real by the ValidatingAdmissionPolicy that binds each custom verb to the spec field it governs.

Every verb is idempotent: re-applying one whose effect is already recorded succeeds and reports changed=false, so a double-click and a re-run of a shell loop both degrade to no-ops rather than churning the object.

Index

Constants

View Source
const (
	// VerbApprove releases the breaking-change hold and revives handed-off
	// findings.
	VerbApprove = "approve"
	// VerbRetry recovers a Failed finding to the state it failed from.
	VerbRetry = "retry"
	// VerbExpedite skips the waiting stages: the accumulation window, the
	// minimum age, and queue position.
	VerbExpedite = "expedite"
	// VerbSuspend pauses pipeline progress for a finding.
	VerbSuspend = "suspend"
	// VerbResume lifts a suspension.
	VerbResume = "resume"
	// VerbBackfill lists an integration's pre-existing open alerts (the ones
	// that predate webhook coverage) into findings. Integration-scoped.
	VerbBackfill = "backfill"
	// VerbReplay redelivers the webhook delivery log (integration-scoped
	// demo tooling).
	VerbReplay = "replay"
	// VerbReset deletes every pipeline resource in the namespace
	// (integration-scoped demo tooling).
	VerbReset = "reset"
)

Verbs the human-action surface understands. They are custom RBAC verbs: the per-finding ones on findings.patchy.bitwisemedia.uk, the integration-scoped ones on integrations.patchy.bitwisemedia.uk. The API server treats them as plain strings, so granting one confers exactly one action.

View Source
const (
	// VerbBackfillMaintained is backfill (on integrations), for maintained
	// repositories only.
	VerbBackfillMaintained = "backfill-maintained"
	// VerbApproveMaintained is approve (on findings), for findings on
	// maintained repositories only.
	VerbApproveMaintained = "approve-maintained"
	// VerbExpediteMaintained is expedite (on findings), for findings on
	// maintained repositories only.
	VerbExpediteMaintained = "expedite-maintained"
)

The maintainer verbs. Each stands in for a base verb, scoped to the repositories where the caller's linked GitHub identity is admin or maintain. Only the status server can honour them, because only it can present the GitHub link. A direct API write still needs the base verb, so a scoped grant on its own permits nothing outside the status page.

View Source
const (
	ResourceFindings     = "findings"
	ResourceIntegrations = "integrations"
)

Resources the custom verbs are checked on.

Variables

View Source
var (
	// ErrUnavailable reports that the verb is real but the finding's current
	// state has no use for it.
	ErrUnavailable = errors.New("action is not available in this phase")
	// ErrUnknownVerb reports a verb outside ActionVerbs.
	ErrUnknownVerb = errors.New("unknown action verb")
)

Errors Apply returns. Callers map them onto their own vocabulary: the status server turns ErrUnavailable into a 403 and ErrUnknownVerb into a 404; the CLI turns them into exit codes.

ActionVerbs lists the per-finding verbs in the order clients present them.

View Source
var AdminVerbs = []string{VerbReplay, VerbReset}

AdminVerbs lists the demo-tooling verbs the status page's user menu surfaces, resolved on integrations.

View Source
var IntegrationVerbs = []string{VerbBackfill, VerbReplay, VerbReset}

IntegrationVerbs lists every integration-scoped verb, in the order clients present them. All are checked on integrations.patchy.bitwisemedia.uk, the same resource the admission policy's authorizer names. That keeps the CLI/status-server SubjectAccessReviews and the server-side enforcement in agreement.

View Source
var MaintainedVerbs = []MaintainedVerb{
	{Verb: VerbBackfillMaintained, Base: VerbBackfill, Resource: ResourceIntegrations},
	{Verb: VerbApproveMaintained, Base: VerbApprove, Resource: ResourceFindings},
	{Verb: VerbExpediteMaintained, Base: VerbExpedite, Resource: ResourceFindings},
}

MaintainedVerbs lists the scoped verbs in the order clients present them.

Functions

func Apply

func Apply(f *v1alpha1.Finding, verb, user, note string, now time.Time) (changed bool, err error)

Apply records verb on f as user at time now, mutating f's spec only. A human action never writes status and never moves a phase itself. The phase-owning controller observes the spec change and performs the transition, which keeps every phase edge single-writer.

changed reports whether f was actually modified. An action whose effect is already recorded returns (false, nil): callers skip the write rather than churning resourceVersion. note is recorded on approvals and ignored by every other verb.

Callers running under conflict retry must call Apply again after every re-Get, so the gating is re-evaluated against fresh state.

func Available

func Available(f *v1alpha1.Finding, now time.Time) []string

Available reports the verbs that would actually do something to f at time now, in ActionVerbs order. It probes Apply against a copy rather than re-stating the gates, so the two can never disagree.

It answers "is there anything to do here", not "may this user do it". A caller still has to check its own grants.

Types

type MaintainedVerb added in v0.16.0

type MaintainedVerb struct {
	// Verb is the scoped RBAC verb.
	Verb string
	// Base is the verb it stands in for.
	Base string
	// Resource is where the scoped verb is granted.
	Resource string
}

MaintainedVerb maps one scoped verb onto the base verb it stands in for. The state-machine checks stay with the base verb: Apply and Available run with Base; the scoped verb only changes who may act.

func MaintainedFor added in v0.16.0

func MaintainedFor(base string) (MaintainedVerb, bool)

MaintainedFor returns the scoped verb standing in for base, if any.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL