Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/added-session-taint-observe-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- New opt-in `session_taint` recorder, the observe-only first slice of session taint ([#18987](https://github.com/hivecommons/hive/issues/18987)). A pattern scan checks each outgoing message alone, so it cannot see that an agent earlier read something it should not repeat in a wider audience; this adds the memory half of the answer, as a measurement only. With `session_taint.enabled: true` the hive keeps a bounded in-memory record of the coarse labels each agent session has accrued (a canary hit sets `secret`) and, when that session later asks the issue, comment, PR or review relay to write, logs and audits which rule would have held the write (`session_taint_label` and `session_taint_would_act` audit entries, plus per-rule counters). It never blocks, holds, restricts or changes any request or action, stores labels, counts and ids only (no credential or content), takes effect at restart, starts every session clean after a restart, and does nothing at all when the key is absent. `max_sessions`, `max_labels_per_session` and `max_decisions` bound the store. Enforcement is a later, separately decided phase; see `docs/design/session-taint.md` and `docs/security-model.md`.
3 changes: 3 additions & 0 deletions src/cmd/hive/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hivecommons/hive/crux"
"github.com/hivecommons/hive/crux/proxy"
cruxruntime "github.com/hivecommons/hive/crux/runtime"
"github.com/hivecommons/hive/crux/sessiontaint"
"github.com/hivecommons/hive/crux/toolapprove"
"github.com/hivecommons/hive/crux/trajectory"
"github.com/hivecommons/hive/crux/watchdog"
Expand Down Expand Up @@ -160,6 +161,8 @@ type boot struct {
dashSrv *dashboard.Server
writeback *writeback.Gate
writebackOnce sync.Once
sessionTaintOnce sync.Once
sessionTaint *sessiontaint.Observer
beadStores map[string]*beads.Store
beadStoreLoadFailures int
tokenCollector *tokens.Collector
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/hive/github_client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,15 @@ func (b *boot) applyGitHubClientDashboardHooks(client *github.Client) {
})
client.SetAgentActionHook(func(a github.AgentAction) { kickOutcomeAgentAction(kickOutcomesFor(b.cfg, b.logger), a) })
client.SetCanaryScanner(b.cfg.Ioscan.IsEnabled() && b.cfg.Ioscan.CanariesEnabled(), b.cfg.Ioscan.FailClosedAtLevel(b.cfg.ACMMLevelOrZero()), ioscan.DefaultCanaries, b.handleCanaryLeak)
// Observe-only session taint (#18987, phase 0): nil unless enabled.
client.SetSessionTaint(b.sessionTaintObserver())
}

// handleCanaryLeak records an ioscan canary leak on the audit log and as a
// critical advisory bead for the leaking agent. Shared by the GitHub client
// and the GitHub proxy scanners.
func (b *boot) handleCanaryLeak(leak ioscan.CanaryLeak) {
b.recordCanaryTaint(leak)
detail := fmt.Sprintf("rule=%s, agent=%s, source=%s", ioscan.CanaryLeakRule, leak.Agent, leak.Source)
b.dashSrv.AuditLog(leak.Agent, "ioscan_canary_leak", detail, leak.Agent)
if store, ok := b.beadStores[leak.Agent]; ok && store != nil {
Expand Down
50 changes: 50 additions & 0 deletions src/cmd/hive/session_taint_wire.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"github.com/hivecommons/hive/crux/sessiontaint"
"github.com/hivecommons/hive/pkg/ioscan"
)

// canaryTaintOrigin is the origin recorded on the `secret` label a canary hit
// sets. It is the logscrub category name of the planted marker, never the
// token itself.
const canaryTaintOrigin = "hive-canary"

// sessionTaintObserver returns the process-wide observe-only session taint
// observer (#18987, phase 0), building it on first use. It is nil unless
// `session_taint.enabled` is true, and every sessiontaint method is a no-op on
// nil, so a hive that sets nothing records nothing. The observer is shared by
// every GitHub client rebuild, so labels survive a credential re-delivery; a
// config change takes effect at the next restart.
func (b *boot) sessionTaintObserver() *sessiontaint.Observer {
b.sessionTaintOnce.Do(func() {
if b.cfg == nil {
return
}
cfg := b.cfg.SessionTaint
b.sessionTaint = sessiontaint.New(sessiontaint.Options{
Enabled: cfg.Enabled,
MaxSessions: cfg.MaxSessionsOrDefault(),
MaxLabelsPerSession: cfg.MaxLabelsPerSessionOrDefault(),
MaxDecisions: cfg.MaxDecisionsOrDefault(),
Logger: b.logger,
Audit: b.sessionTaintAudit,
})
})
return b.sessionTaint
}

// sessionTaintAudit writes one observer entry to the audit log. The detail
// carries labels and ids only.
func (b *boot) sessionTaintAudit(agent, action, detail string) {
if b.dashSrv == nil {
return
}
b.dashSrv.AuditLog(agent, action, detail, agent)
}

// recordCanaryTaint is source S3: a canary hit means the agent whose token it
// is has been exposed to a secret-shaped marker. Observe only.
func (b *boot) recordCanaryTaint(leak ioscan.CanaryLeak) {
b.sessionTaintObserver().RecordLabel(leak.Agent, sessiontaint.LabelSecret, canaryTaintOrigin, sessiontaint.SourceCanaryHit)
}
54 changes: 54 additions & 0 deletions src/cmd/hive/session_taint_wire_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"log/slog"
"testing"

"github.com/hivecommons/hive/crux/sessiontaint"
"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/ioscan"
)

func TestSessionTaintOffByDefaultRecordsNothing(t *testing.T) {
b := &boot{cfg: &config.Config{}, logger: slog.Default()}
if b.sessionTaintObserver() != nil {
t.Fatal("session taint must be off unless session_taint.enabled is set")
}
// A canary hit with the feature off is a no-op.
b.recordCanaryTaint(ioscan.CanaryLeak{Agent: "agent-a", Source: "test"})
if got := b.sessionTaintObserver().Labels("agent-a"); got != nil {
t.Errorf("labels = %v, want none", got)
}
}

func TestSessionTaintCanaryHitSetsSecretLabel(t *testing.T) {
cfg := &config.Config{}
cfg.SessionTaint.Enabled = true
b := &boot{cfg: cfg, logger: slog.Default()}
obs := b.sessionTaintObserver()
if obs == nil {
t.Fatal("expected an observer when enabled")
}
if b.sessionTaintObserver() != obs {
t.Error("the observer must be built once and shared")
}
// The token itself is never passed on or stored.
b.recordCanaryTaint(ioscan.CanaryLeak{Agent: "agent-a", Token: "HIVE-CANARY-synthetic", Source: "hive-comment:o/r"})
labels := obs.Labels("agent-a")
if len(labels) != 1 {
t.Fatalf("labels = %v, want one", labels)
}
if l := labels[0]; l.Label != sessiontaint.LabelSecret || l.Origin != canaryTaintOrigin || l.Source != sessiontaint.SourceCanaryHit {
t.Errorf("label = %+v", l)
}
}

// The config defaults and the observer's own bounds are the same numbers, so
// `enabled: true` alone gives the documented limits.
func TestSessionTaintConfigDefaultsMatchObserver(t *testing.T) {
if config.DefaultSessionTaintMaxSessions != sessiontaint.DefaultMaxSessions ||
config.DefaultSessionTaintMaxLabelsPerSession != sessiontaint.DefaultMaxLabelsPerSession ||
config.DefaultSessionTaintMaxDecisions != sessiontaint.DefaultMaxDecisions {
t.Fatal("pkg/config defaults drifted from crux/sessiontaint defaults")
}
}
Loading
Loading