Documentation
¶
Overview ¶
Package remediation defines the contract for turning a promoted finding's remediation suggestion into an explicitly approved provider action.
Discovery observes; remediation acts. The two are separate host capabilities, and nothing in this package travels through discovery collections, graph contributions, or the reasoning outbox.
Lifecycle ¶
- Reasoning validates up to MaxSuggestions Suggestion values per finding. A suggestion names a desired outcome (Intent) and one target entity, never a plugin, payload, or command.
- The host hydrates each suggestion into a Proposal bound to the finding, analysis, graph revision, canonical target identity, and evidence. Proposal IDs are content digests, so a proposal cannot be altered without changing its ID.
- Registry.Candidates lists every registered provider action that can implement the proposal's intent for its target kind, identity scheme, and authority. The user picks one.
- Executor.Plan resolves current provider state into a Plan with a digest of the desired state. Advisory-only actions stop here.
- Executor.Prepare has the provider check every intended write (for Kubernetes, with admission dry-run) and capture bounded canonical ProviderState for later comparison.
- Executor.Execute requires an approval string equal to the exact plan ID and a recorded successful preparation for that plan. Providers re-read the prepared observations and fail if they changed.
- Executor.Verify re-reads the declared configuration.
Safety model ¶
- Nothing executes without explicit approval of one prepared plan. Reasoning, finding persistence, discovery, candidate enumeration, planning, and preparation never apply a proposal.
- Plan, preparation, and execution result IDs are digests of their content and are rechecked at every step, so a provider or caller cannot substitute a different plan, preparation, or result.
- The target is checked against the current graph before planning, preparation, and execution. A target that is gone, has changed kind, or has conflicting kinds stops the action. The finding's graph revision is audit context, not an execution lock, so unrelated graph churn does not block remediation.
- Execution is single-flight per plan: concurrent approvals wait for the first, and a successful result is returned again instead of re-running.
- A satisfied Verification proves the declared configuration is present. It does not prove controller acceptance, dataplane rollout, or effective enforcement.
- Preparations and execution state are held in memory by one Executor. A restart requires preparing again, and replicas do not coordinate.
- Provider credentials and permissions stay in host configuration and never appear in suggestions, proposals, or plans.
The HTTP surface for this lifecycle is in pkg/api. Its routes are always registered but return 503 unless live discovery runs on a loopback listener. See https://agent-shield.dev/docs/architecture/remediation/ and https://agent-shield.dev/docs/operations/security/.
Index ¶
- Constants
- type Action
- type AdvisoryOnlyError
- type Candidate
- type Descriptor
- type ExecutionResult
- type Executor
- func (executor *Executor) Candidates(proposal Proposal) ([]Candidate, error)
- func (executor *Executor) Execute(ctx context.Context, proposal Proposal, plan Plan, preparation Preparation, ...) (ExecutionResult, error)
- func (executor *Executor) Plan(ctx context.Context, proposal Proposal, providerID string, selection ...string) (Plan, error)
- func (executor *Executor) Prepare(ctx context.Context, proposal Proposal, plan Plan) (Preparation, error)
- func (executor *Executor) Verify(ctx context.Context, proposal Proposal, plan Plan) (Verification, error)
- type GraphSourceFunc
- type GraphView
- type IneligibleTargetError
- type Intent
- type Mode
- type Plan
- type Preparation
- type Proposal
- type Provider
- type ProviderState
- type Registration
- type Registry
- type Suggestion
- type Target
- type Verification
Constants ¶
const ( MaxSupportingIDs = 100 MaxSuggestions = 8 )
Bounds on model-supplied remediation content.
const ( MaxProviderStateEntries = 16 MaxProviderStateBytes = 256 * 1024 MaxProviderStateValue = 64 * 1024 MaxProviderStateKey = 128 )
Bounds on provider-owned state carried by preparations and results.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
ID string
Intent Intent
TargetKind string
Scheme graph.IdentityScheme
AuthorityID string
Mode Mode
}
Action is one remediation a provider can perform: an intent for targets of one kind, identity scheme, and authority. ID has the form "mechanism/vN".
type AdvisoryOnlyError ¶
AdvisoryOnlyError is returned when an advisory-only plan is prepared, executed, or verified.
func (*AdvisoryOnlyError) Error ¶
func (err *AdvisoryOnlyError) Error() string
Error implements error.
type Candidate ¶
type Candidate struct {
ProviderID string `json:"providerId"`
SourceID string `json:"sourceId"`
ActionID string `json:"actionId"`
Mode Mode `json:"mode"`
}
Candidate is one eligible provider action for a proposal.
type Descriptor ¶
type Descriptor struct {
Actions []Action
}
Descriptor lists a provider's actions.
type ExecutionResult ¶
type ExecutionResult struct {
ID string `json:"id"`
PlanID string `json:"planId"`
ProposalID string `json:"proposalId"`
ProviderID string `json:"providerId"`
SourceID string `json:"sourceId"`
ActionID string `json:"actionId"`
PreparationID string `json:"preparationId"`
Successful bool `json:"successful"`
ProviderState []ProviderState `json:"providerState,omitempty"`
}
ExecutionResult records the outcome of executing one prepared plan.
func NewExecutionResult ¶
func NewExecutionResult(plan Plan, preparation Preparation, successful bool, providerState []ProviderState) (ExecutionResult, error)
NewExecutionResult validates that preparation belongs to plan and derives the result ID.
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor enforces the remediation lifecycle around registered providers. Successful preparations and execution results are kept in memory, keyed by plan ID, and are lost on restart.
func NewExecutor ¶
func NewExecutor(registry *Registry, graphSource GraphSourceFunc) (*Executor, error)
NewExecutor returns an executor over registry that checks targets against graphSource.
func (*Executor) Candidates ¶
Candidates returns the registry's candidates for proposal.
func (*Executor) Execute ¶
func (executor *Executor) Execute(ctx context.Context, proposal Proposal, plan Plan, preparation Preparation, approval string) (ExecutionResult, error)
Execute runs a prepared plan. approval must equal plan.ID: approving a proposal or a finding is not enough, the user must approve the exact plan they were shown. preparation must be the one recorded by Executor.Prepare.
Execution is single-flight per plan. A concurrent call waits for the in-flight one, then returns its successful result or, if it failed, tries again. A successful execution consumes the recorded preparation. The target is checked against the current graph immediately before the provider is called.
func (*Executor) Plan ¶
func (executor *Executor) Plan(ctx context.Context, proposal Proposal, providerID string, selection ...string) (Plan, error)
Plan selects a provider action (see Registry.Provider), checks the target against the current graph, and returns the provider's plan after verifying it matches the proposal and selection. Planning never writes.
func (*Executor) Prepare ¶
func (executor *Executor) Prepare(ctx context.Context, proposal Proposal, plan Plan) (Preparation, error)
Prepare rechecks the plan and target, asks the provider to prepare it, and records a successful preparation as the only one Executor.Execute will accept for that plan. Preparing again replaces it.
type GraphSourceFunc ¶
GraphSourceFunc reads the current graph for target applicability checks.
type IneligibleTargetError ¶
IneligibleTargetError lets a provider report that a proposal's target cannot take its action, as distinct from a transient failure.
func (*IneligibleTargetError) Error ¶
func (err *IneligibleTargetError) Error() string
Error implements error.
type Intent ¶
type Intent string
Intent is a closed vocabulary of desired security outcomes. It describes what should become true, not how a provider achieves it.
const ( IntentNetworkDeclareIngressIsolation Intent = "network.declare-ingress-isolation" IntentTransportRequireMutualTLS Intent = "transport.require-mutual-tls" IntentGatewayPreventRouteDelivery Intent = "gateway.prevent-route-delivery" )
Supported intents. Network and transport intents declare provider configuration; gateway.prevent-route-delivery is advisory-only.
type Mode ¶
type Mode string
Mode says whether an action can change provider state.
Action modes. Advisory-only actions can be planned but never prepared, executed, or verified.
type Plan ¶
type Plan struct {
ID string `json:"id"`
ProposalID string `json:"proposalId"`
ProviderID string `json:"providerId"`
SourceID string `json:"sourceId"`
ActionID string `json:"actionId"`
Mode Mode `json:"mode"`
GraphRevision uint64 `json:"graphRevision"`
DesiredSHA256 string `json:"desiredSha256"`
Advisory string `json:"advisory,omitempty"`
}
Plan is a provider's deterministic answer for one proposal and selected action: DesiredSHA256 digests the content it would declare. ID is a content digest and is the value a user approves.
type Preparation ¶
type Preparation struct {
ID string `json:"id"`
PlanID string `json:"planId"`
ProposalID string `json:"proposalId"`
ProviderID string `json:"providerId"`
SourceID string `json:"sourceId"`
ActionID string `json:"actionId"`
GraphRevision uint64 `json:"graphRevision"`
Successful bool `json:"successful"`
ProviderState []ProviderState `json:"providerState,omitempty"`
}
Preparation is a provider's pre-execution check of a plan. ProviderState holds the bounded, canonically encoded observations execution will compare against. Only a successful preparation can be executed.
func NewPreparation ¶
func NewPreparation(plan Plan, successful bool, providerState []ProviderState) (Preparation, error)
NewPreparation canonicalizes providerState and derives the preparation ID.
type Proposal ¶
type Proposal struct {
ID string `json:"id"`
FindingID string `json:"findingId"`
AnalysisID string `json:"analysisId"`
GraphRevision uint64 `json:"graphRevision"`
Intent Intent `json:"intent"`
Target Target `json:"target"`
SupportingIDs []string `json:"supportingIds"`
EvidenceIDs []string `json:"evidenceIds"`
}
Proposal is a host-hydrated, server-owned suggestion bound to its finding, analysis, graph revision, target, and evidence. The API never accepts a proposal from a client.
func NewProposal ¶
func NewProposal(findingID, analysisID string, graphRevision uint64, suggestion Suggestion, target Target, evidenceIDs []string) (Proposal, error)
NewProposal canonicalizes supporting and evidence IDs and derives the proposal ID from content. evidenceIDs must be a non-empty subset of the suggestion's supporting IDs.
type Provider ¶
type Provider interface {
RemediationDescriptor() Descriptor
Plan(context.Context, Proposal, string) (Plan, error)
Prepare(context.Context, Proposal, Plan) (Preparation, error)
Execute(context.Context, Proposal, Plan, Preparation) (ExecutionResult, error)
Verify(context.Context, Proposal, Plan, ExecutionResult) (Verification, error)
}
Provider implements remediation actions for one configured source.
Plan must be deterministic for the same proposal and provider state. Prepare must validate every intended write without persisting it. Execute must re-read the prepared observations, refuse to write when they changed, and roll back partial writes where it can. Verify re-reads the declared configuration. Every returned value must be built with this package's constructors so its content-derived ID matches.
type ProviderState ¶
type ProviderState struct {
Key string `json:"key"`
Current json.RawMessage `json:"current,omitempty"`
Prepared json.RawMessage `json:"prepared,omitempty"`
}
ProviderState is one provider-owned observation. Current is what the provider read; Prepared is what it validated for writing. Values must be canonical JSON so content-derived IDs are stable.
type Registration ¶
Registration binds a provider to host-attested provider and source IDs. The host, not the provider, decides these IDs.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry indexes provider actions by what they can act on. It is immutable after construction.
func NewRegistry ¶
func NewRegistry(registrations ...Registration) (*Registry, error)
NewRegistry validates and indexes every registration's actions. A (provider, source, action) triple must be unique.
func (*Registry) Candidates ¶
Candidates returns every action matching the proposal's intent and target kind, identity scheme, and authority, sorted by provider, source, and action. Alternatives from different plugins or clusters are all returned; the user chooses.
func (*Registry) Provider ¶
func (registry *Registry) Provider(proposal Proposal, providerID string, selection ...string) (Provider, Action, error)
Provider resolves a selection to an eligible provider and action. selection is either (actionID) or (sourceID, actionID). With no selection at all, it succeeds only when exactly one candidate exists; with a provider and action but no source, only when the source is unambiguous.
type Suggestion ¶
type Suggestion struct {
Intent Intent `json:"intent"`
TargetEntityIDs []string `json:"targetEntityIds"`
SupportingIDs []string `json:"supportingIds"`
}
Suggestion is a model-proposed outcome for one target entity, grounded by SupportingIDs from the analyzed packet. It contains no provider payload.
func (Suggestion) Validate ¶
func (suggestion Suggestion) Validate() error
Validate checks the suggestion's own shape: a supported intent, exactly one target, and 1-MaxSupportingIDs unique, non-empty supporting IDs. Grounding against the packet is checked by pkg/reasoning.
type Target ¶
type Target struct {
EntityID string `json:"entityId"`
Identity graph.IdentityClaim `json:"identity"`
Kind string `json:"kind"`
}
Target is the canonical identity of the entity a proposal acts on. Providers match actions by kind, identity scheme, and authority.
type Verification ¶
type Verification struct {
PlanID string `json:"planId"`
ProviderID string `json:"providerId"`
SourceID string `json:"sourceId"`
ActionID string `json:"actionId"`
ExecutionResultID string `json:"executionResultId"`
Satisfied bool `json:"satisfied"`
}
Verification reports whether the provider declaration recorded by an execution is still present. Satisfied does not prove effective enforcement.