Documentation
¶
Overview ¶
Package replay re-runs a recorded session: either against the current policy only (a dry run, which answers "what would this policy have done yesterday?") or against the current upstreams as well.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Diff ¶
type Diff struct {
SessionA string `json:"session_a"`
SessionB string `json:"session_b"`
Rows []Row `json:"rows"`
}
Diff is the comparison of two recorded sessions.
func Compare ¶
Compare aligns two recorded sessions and classifies every call.
The alignment is a longest-common-subsequence over the tool names, which is what makes an inserted or removed call show up as one row instead of pushing everything after it out of step.
type Entry ¶
type Entry struct {
Call *audit.Call `json:"call"`
// Was is the decision recorded at the time.
Was policy.Decision `json:"was"`
// Now is the decision the current policy reaches.
Now policy.Decision `json:"now"`
// Skipped is set when OnlyAllowed filtered the call out.
Skipped bool `json:"skipped,omitempty"`
// Sent reports whether the call was actually re-sent upstream.
Sent bool `json:"sent"`
// ResultHash is the hash of the fresh result, when the call was re-sent.
ResultHash string `json:"result_hash,omitempty"`
// Error is a failure from the fresh call.
Error string `json:"error,omitempty"`
// DurationMS is how long the fresh call took.
DurationMS int64 `json:"duration_ms,omitempty"`
}
Entry is one recorded call, re-evaluated and possibly re-sent.
func (*Entry) DecisionChanged ¶
DecisionChanged reports whether the current policy disagrees with what was recorded. This is the line "replay --dry-run" is really about.
func (*Entry) ResultChanged ¶
ResultChanged reports whether a re-sent call produced a different result than the recorded one. It is false for calls that were not re-sent, and for calls whose recorded result was truncated and cannot be compared.
type Forwarder ¶
type Forwarder interface {
ForwardJSON(ctx context.Context, tool string, args json.RawMessage) (json.RawMessage, error)
}
Forwarder sends a call to the live upstreams and returns the result as JSON, so that replay can hash it the same way the audit log did.
type Options ¶
type Options struct {
// Policy is evaluated against every recorded call. Required.
Policy *policy.Policy
// OnlyAllowed skips calls that were denied when they were recorded.
OnlyAllowed bool
// Forwarder re-sends allowed calls. Nil means a dry run.
Forwarder Forwarder
}
Options control a replay.
type Report ¶
type Report struct {
SessionID string `json:"session_id"`
Entries []*Entry `json:"entries"`
DryRun bool `json:"dry_run"`
}
Report is the outcome of a replay.
func Run ¶
Run replays the calls in order.
Budgets are simulated as the walk proceeds, so a policy that adds a budget shows up in a dry run exactly where the session would have run out.
type Row ¶
type Row struct {
Status Status `json:"status"`
A *audit.Call `json:"a,omitempty"`
B *audit.Call `json:"b,omitempty"`
Tool string `json:"tool"`
}
Row is one line of a session diff.
type Status ¶
type Status string
Status is how a pair of calls relates across two sessions.
const ( // StatusSame means same tool, same arguments, same result. StatusSame Status = "same" // StatusResult means same tool and arguments, different result. StatusResult Status = "result" // StatusArgs means same tool, different arguments. StatusArgs Status = "args" // StatusOnlyA means the call happened only in the first session. StatusOnlyA Status = "only-a" // StatusOnlyB means the call happened only in the second session. StatusOnlyB Status = "only-b" // StatusDecision means the call was allowed in one session and not the other. StatusDecision Status = "decision" )