Skip to content

Audit trail and dashboards

Leash records what agents do in two places:

  • AgentRun: one object per agent pod, with running totals. Good for kubectl, scripts and a quick “what did this agent just do?”.
  • Audit log: one JSON line per decision, from the gateway and the operator. Good for Loki, search, alerting and long-term retention.

Both come from the gateway, so they cover what agents do through it: model calls, and MCP calls. Egress that the network policy blocks never reaches the gateway; Cilium Hubble is the place to see those drops.

AgentRun

Terminal window
$ kubectl -n agents get arun
NAME POLICY POD PHASE TOKENS MODEL CALLS TOOL CALLS DENIED LAST ACTIVITY
claude-agent-7d9f8b6c4d-x2lqp claude-agent claude-agent-7d9f8b6c4d-x2lqp Running 48210 37 12 2 40s
claude-agent-7d9f8b6c4d-9wq4c claude-agent claude-agent-7d9f8b6c4d-9wq4c Completed 102344 81 30 0 3h
status:
phase: Running
startedAt: "2026-11-28T09:02:11Z"
lastActivity: "2026-11-28T11:40:52Z"
tokens: {input: 41020, output: 7190, total: 48210}
modelCalls: 37
toolCalls: 12
denied: 2 # every refused call: off-policy model or tool, spent budget, denied approval
approvals: {requested: 1, approved: 1}
models: # most tokens first, at most 20
- {name: claude-sonnet-4-5, calls: 37, inputTokens: 41020, outputTokens: 7190}
tools: # most calls first, at most 50
- {server: github, name: get_issue, calls: 9}
- {server: github, name: delete_repo, denied: 1}
lastDenial:
time: "2026-11-28T10:15:03Z"
kind: mcp
target: github/delete_repo
reason: tool "delete_repo" is denied by AgentPolicy claude-agent
  • The gateway creates the run on an agent’s first call and updates it every --usage-flush-interval (15s by default). It is named after the pod, labelled leash.simplyzee.dev/policy=<policy>, and lives in the pod’s namespace.
  • The operator marks it Completed (with endedAt) once the pod is deleted or finished, and deletes it after --agentrun-retention (7 days by default; chart value audit.runRetention).
  • Counts survive a gateway restart: the gateway picks up from the stored run.
  • A new pod with the same name (a StatefulSet restart, say) gets a fresh run.

Audit log

Each line is one JSON object on stdout with "type":"leash.audit", separate from the components’ ordinary logs:

{"ts":"2026-11-28T10:15:03Z","type":"leash.audit","source":"gateway","action":"mcp.call","decision":"denied","namespace":"agents","policy":"claude-agent","pod":"claude-agent-7d9f8b6c4d-x2lqp","pod_uid":"5b1c…","server":"github","tool":"delete_repo","reason":"tool \"delete_repo\" is denied by AgentPolicy claude-agent"}
{"ts":"2026-11-28T10:16:40Z","type":"leash.audit","source":"operator","action":"policy.freeze","namespace":"agents","policy":"claude-agent","reason":"kill switch engaged: all egress denied"}
action decision values Extra fields
model.call allowed, denied, budget_exhausted provider, model, reason
model.usage (none) provider, model, input_tokens, output_tokens
mcp.call allowed, denied, approval_requested, approved, approval_denied, approval_error server, tool, reason
mcp.access denied (server not allowed by the policy) server, reason
policy.freeze, policy.unfreeze (none) reason

Tool arguments are never logged: they can hold secrets. A held call’s arguments are in its ToolApproval.

Turn the log off with --audit-log=false on either binary (chart value audit.log).

Shipping to Loki

Any collector that tails container logs works. With Grafana Alloy:

discovery.kubernetes "pods" {
role = "pod"
namespaces { names = ["leash-system"] }
}
discovery.relabel "leash" {
targets = discovery.kubernetes.pods.targets
rule {
source_labels = ["__meta_kubernetes_namespace"]
target_label = "namespace"
}
rule {
source_labels = ["__meta_kubernetes_pod_label_app_kubernetes_io_name"]
target_label = "app"
}
}
loki.source.kubernetes "leash" {
targets = discovery.relabel.leash.output
forward_to = [loki.write.default.receiver]
}
loki.write "default" {
endpoint { url = "http://loki-gateway.monitoring.svc/loki/api/v1/push" }
}

Leave namespace, policy and pod in the log line rather than promoting them to Loki labels: agent pods come and go, and per-pod labels make Loki slow. Query them with | json instead:

{namespace="leash-system"} |= "leash.audit" | json | type="leash.audit" | decision="denied"

Grafana dashboard

The dashboard uses the gateway’s Prometheus metrics and the audit log in Loki: requests, refusals, tokens by model and policy, top tools, the agents with the most refusals, refusal and kill-switch logs, and the full audit trail. Freezes show up as annotations on every graph.

With the Grafana sidecar (as in kube-prometheus-stack):

Terminal window
helm upgrade leash oci://ghcr.io/simplyzee/charts/leash -n leash-system --reuse-values \
--set audit.grafanaDashboard.enabled=true \
--set audit.grafanaDashboard.namespace=monitoring

Or import charts/leash/files/grafana-dashboard.json by hand. Pick your Prometheus and Loki data sources at the top; if your Leash logs aren’t under {namespace="leash-system"}, change the Leash log stream box. The dashboard is generated by hack/dashboard/build.py.

Prometheus needs to scrape the gateway’s metrics on port 9090: add a ServiceMonitor or PodMonitor, or set gateway.podAnnotations to whatever your Prometheus discovers (prometheus.io/scrape: "true", prometheus.io/port: "9090").