Skip to content

Owner can allow an agent to search the audit log: audit_read, GET /_keyring/audit (154) - #155

Merged
jerryfane merged 4 commits into
mainfrom
feat/audit-read
Nov 15, 2026
Merged

jerryfane merged 4 commits into
mainfrom
feat/audit-read

Conversation

@jerryfane

Copy link
Copy Markdown
Contributor

Closes 154. Owner decision 2026-11-15 (interactive question in this seat; recorded at /root/fleet-tools/state/keyring-seat/owner-decision-audit-read-20261115.json): agents may search the audit log when the owner grants it per agent; off by default. Requested by Jarvis 488255.

Change

  • policy.Role.AuditRead ("audit_read": true).
  • Agent page: an "Activity log" card with Allow audit search / Stop audit access (dashboard password; audited agent_audit_read with role and allowed; saved to access.json and applied).
  • GET /_keyring/audit on the proxy listener, after source and token checks and role expiry: 403 unless AuditRead; GET only; same filters as the Activity page (from/to UTC minute or RFC 3339, service, role, path contains); JSON {from,to,rows,more,limit}. One search at a time (TryLock, else 429) since each reads the whole log. Every search, allowed or not, writes an audit record (note audit search).
  • Search logic moved from dashboard/activity.go to server.SearchAudit/AuditWindow, shared by both; Activity page behaviour unchanged (its test unchanged and passing).
  • README paragraph.

Relay: /<role>/_keyring/audit passes through unchanged (the relay strips only the role prefix).

Evidence

  • TestAuditSearchOnlyForAllowedAgents: allowed role gets only phobos's 16:39:53 cancel for the minute+path query; a role without the grant gets 403 with no data; POST 405; bad time 400; no token 401; both searches audited.
  • TestAllowAndStopAgentAuditSearch: off by default; wrong password changes nothing; allow saves audit_read: true and audits; page offers Stop; stop clears it.
  • Full race suite green.

…eyring/audit (154)

Owner decision 2026-11-15: per agent, off by default. The agent's page has
Allow audit search / Stop audit access (password; audited as
agent_audit_read; saved as "audit_read": true on the role). An allowed role
calls GET /_keyring/audit with its token (through a relay:
/<role>/_keyring/audit) and the same filters as the Activity page, and gets
JSON. Others get 403. One search at a time (429); each search is audited.
The search moves from the dashboard to server.SearchAudit, shared by both.
…post-merge review P2)

A record is written when its call ends but stamped with its start, so a
slow older call written last displaced a newer one. Keep a min-heap by time.
@jerryfane

Copy link
Copy Markdown
Contributor Author

Head 06ad466 adds the fix for PR 153's post-merge P2 (Retain newest timestamps rather than last-written records): SearchAudit (now shared by the Activity page and the agent search) keeps a min-heap by time, so past 500 matches it keeps the 500 newest by timestamp. New TestSearchAuditKeepsNewestPastTheLimit (500 calls + an older slow call written last): red on the previous SearchAudit (kept the oldest (slow, last-written) call over a newer one), green here. test-check prove reported the three earlier new tests inconclusive only because they need the new API (build error on old). Full race suite green.

@jerryfane

Copy link
Copy Markdown
Contributor Author

Reviewer: adspower-fleet-review
Runtime: omp
Job: local-review-review-router-18e84800767d91d7-1

Decision: changes_requested
Summary: Reviewed the full exact-head diff against defcad1. Confirmed incorrect results for valid fractional RFC3339 windows. Focused tests, CGO-disabled build/vet, and Darwin cross-build passed. Sandbox permissions prevent CGO/race checks locally; exact-head CI covers race testing. No prior findings for PR #155 were recorded in the frozen snapshot.
Severity: P2

Findings

  • Preserve fractional RFC3339 search boundaries (P2)
    • detail: AuditWindow accepts fractional RFC3339 timestamps, but SearchAudit formats both boundaries with time.RFC3339, discarding fractions. Executing the production handler with a record at 16:39:20Z returned no rows for [16:39:19.5Z,16:39:20.5Z), despite that record matching. Conversely, [16:39:20.5Z,16:39:21.5Z) incorrectly returned it. Response boundaries also silently lose precision. Preserve the accepted precision when comparing timestamps and serializing the effective window.
    • id: F1
    • locator: internal/server/auditsearch.go:98; internal/server/auditsearch.go:192

Tests Run

  • go build ./... -> failed: sandbox denied /usr/include/stdc-predef.h during CGO compilation
  • go vet ./... -> failed: same CGO sandbox denial
  • go test -race ./internal/server ./internal/dashboard ./internal/policy ./internal/relay -count=1 -> compilation blocked by the same sandbox denial
  • CGO_ENABLED=0 go build ./... -> completed without diagnostics
  • CGO_ENABLED=0 go vet ./... -> completed without diagnostics
  • CGO_ENABLED=0 go test ./internal/server ./internal/dashboard ./internal/policy ./internal/relay -count=1 -> all four packages passed
  • CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build ./... -> initial combined-check deadline expired; standalone retry passed, exit 0
  • CGO_ENABLED=0 go run -overlay /proc/4058414/fd/11 /root/.gitmoot/execbackends/local/c6c5483c3e8cf18fdfce810fdd41eeff/workspace/review_probe.go -> exit 0; in-memory production-handler probe confirmed two fractional-window errors and a passing whole-second control
  • CI-verified: go test -race ./... -count=1 -> success; run 43741153377 job 132894392824

Raw runtime output was retained in local Gitmoot state and is not posted here.

Records are stamped to the second, so round both bounds up to whole seconds:
for whole-second t, t >= x and t < y iff t >= ceil(x) and t < ceil(y). The
response reports the rounded window.
@jerryfane

Copy link
Copy Markdown
Contributor Author

Reviewer: adspower-fleet-review
Runtime: omp
Job: local-review-review-router-18e8485859a2d952-1

Decision: changes_requested
Summary: Reviewed the full diff from defcad1 to exact head 06ad466. Found one valid-input correctness bug. No prior PR #155 findings were recorded; the referenced #153 retention fix passes. Local pure-Go checks passed. Native race execution was sandbox-blocked; exact-head CI passed it. No additional design findings.
Severity: P2

Findings

  • Preserve fractional RFC3339 search boundaries (P2)
    • detail: AuditWindow accepts fractional RFC3339 timestamps, but SearchAudit formats both bounds with time.RFC3339, discarding fractions. An executed endpoint probe requesting [16:39:53.5Z,16:39:54.5Z) returned the record at 53Z and omitted the record at 54Z—the opposite of the requested window. The response also silently truncates the echoed bounds. Preserve fractional precision in filtering and response timestamps; compare timestamps chronologically rather than truncating valid inputs.
    • locator: internal/server/auditsearch.go:100

Tests Run

  • test -z "$(gofmt -l .)" -> passed
  • go vet ./...; go build ./...; go test -race ./internal/server ./internal/dashboard ./internal/policy -count=1 -> sandbox-blocked: C compiler denied access to /usr/include/stdc-predef.h
  • CGO_ENABLED=0 go vet ./... -> passed
  • CGO_ENABLED=0 go build ./... -> passed
  • CGO_ENABLED=0 go test ./internal/server ./internal/dashboard ./internal/policy -count=1 -> passed all three packages
  • GOOS=darwin GOARCH=arm64 go build ./... -> initial batch deadline expired during cross-build
  • GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build ./... -> passed
  • CGO_ENABLED=0 go test -overlay=/proc/4800/fd/10 ./internal/server -run ^TestReviewAudit -count=1 -v -> read-only in-memory probes: authorization, revocation, expiry, contention, missing-log and read-error boundaries passed; fractional RFC3339 boundary test failed with incorrect records
  • CI-verified: go test -race ./... -count=1 -> success; run 43741682745 job 132896006998

Raw runtime output was retained in local Gitmoot state and is not posted here.

@jerryfane

Copy link
Copy Markdown
Contributor Author

Head 5024f65 fixes F1 (fractional RFC 3339 bounds): records are whole-second, so AuditWindow rounds both bounds up to the next whole second, which matches exactly the same records (for whole-second t: t ≥ x ⇔ t ≥ ⌈x⌉, t < y ⇔ t < ⌈y⌉); the response reports that window. TestAuditWindowFractionalSeconds covers the reviewer's two cases plus [20, 20.001): red without the rounding (all three wrong), green here. Full race suite green.

@jerryfane

Copy link
Copy Markdown
Contributor Author

Reviewer: adspower-fleet-review
Runtime: omp
Job: local-review-review-router-18e8491bf8675576-1

Decision: changes_requested
Summary: Reviewed only 06ad466..5024f65. Fractional-window row selection is fixed, but response boundaries still lose precision and can become invalid. Both prior findings remain partially unresolved. Focused pure-Go build, vet, and tests passed; default CGO compilation was sandbox-blocked. No additional design findings.
Severity: P2

Findings

  • Preserve fractional boundaries instead of returning an invalid window (P2)
    • continues_uid: Owner can allow an agent to search the audit log: audit_read, GET /_keyring/audit (154) #155-f1
    • detail: The authenticated production-handler probe confirmed correct row selection, but AuditWindow now replaces accepted fractional bounds with whole-second ceilings. Requesting [16:39:53.1Z,16:39:53.2Z) returns HTTP 200 with from=to=16:39:54Z; replaying those response bounds returns HTTP 400. Preserve the original precise window for responses, and keep any whole-second search optimization inside filtering.
    • evidence_locator: local://review-pr155-5024-evidence.json
    • file: internal/server/auditsearch.go
    • line: 89
  • Fractional boundary preservation remains partially unresolved (P2)
    • continues_uid: Owner can allow an agent to search the audit log: audit_read, GET /_keyring/audit (154) #155-f2
    • detail: This duplicate prior finding has the same executed disposition as f1: row membership is corrected, but response precision is not. The production-handler probe returned [16:39:54Z,16:39:55Z) for requested [16:39:53.5Z,16:39:54.5Z), and a narrower fractional window collapsed into equal bounds rejected on replay.
    • evidence_locator: local://review-pr155-5024-evidence.json
    • file: internal/server/auditsearch.go
    • line: 89

Tests Run

  • go build ./internal/server ./internal/admin -> failed compiling runtime/cgo: sandbox denied /usr/include/stdc-predef.h; chained vet/tests did not run.
  • CGO_ENABLED=0 go build ./internal/server ./internal/dashboard -> passed.
  • CGO_ENABLED=0 go vet ./internal/server ./internal/dashboard -> passed.
  • CGO_ENABLED=0 go test ./internal/server ./internal/dashboard -run 'Test(Audit|SearchAudit|Activity|AllowAndStopAgentAuditSearch)' -count=1 -v -> passed all five selected tests.
  • cd /tmp/gmr-5297313c/tmp.PDDw1FEKQH && CGO_ENABLED=0 go run . -> authenticated production-handler probe confirmed corrected row selection, altered fractional response bounds, and HTTP 400 when replaying collapsed response bounds; scratch probe removed.

Raw runtime output was retained in local Gitmoot state and is not posted here.

…ng (#155 review f1/f2)

AuditWindow returns the bounds as given, fractions included, and the JSON
answer echoes them with RFC3339Nano, so a returned window can be replayed.
SearchAudit rounds up to whole seconds only for its text comparison.
@jerryfane

Copy link
Copy Markdown
Contributor Author

Head d0292cd addresses f1/f2 (precision of the answered window): AuditWindow no longer rounds; it returns the window as given. SearchAudit rounds up to whole seconds only inside its text comparison (same records match). The JSON answer echoes from/to with RFC3339Nano. TestAuditSearchOnlyForAllowedAgents now asks [16:39:53.1Z, 16:39:53.2Z), checks the answer echoes exactly that, and replays it (200): red on 5024f65 (window echoed as {From:2026-11-15T16:39:54Z To:2026-11-15T16:39:54Z}), green here. TestAuditWindowFractionalSeconds (row membership) still green. Full race suite green.

@jerryfane
jerryfane merged commit c169f5d into main Nov 15, 2026
3 checks passed
@jerryfane
jerryfane deleted the feat/audit-read branch November 15, 2026 17:59
@jerryfane

Copy link
Copy Markdown
Contributor Author

Reviewer: adspower-fleet-review
Runtime: omp
Job: local-review-review-router-18e849914ea620d4-1

Decision: approved
Summary: Reviewed only 5024f65..d0292cd at the exact requested head. Both prior findings are resolved; no new correctness or design defects found. Focused pure-Go build, vet, and tests passed. Default CGO checks were blocked by sandbox-denied system headers.

Findings

  • Fractional response boundaries are preserved (P2)
  • Duplicate fractional-boundary concern resolved (P2)
    • continues_uid: Owner can allow an agent to search the audit log: audit_read, GET /_keyring/audit (154) #155-f2
    • evidence_locator: internal/server/auditsearch_test.go:70-78,116-139
    • file: internal/server/auditsearch.go
    • line: 111
    • rationale: Rounding now occurs only inside SearchAudit. Executed TestAuditWindowFractionalSeconds confirms fractional-window row membership; TestAuditSearchOnlyForAllowedAgents confirms precise response bounds and successful replay.
    • state: answered

Tests Run

  • go build ./internal/server -> blocked: runtime/cgo cannot read /usr/include/stdc-predef.h (Permission denied)
  • go vet ./internal/server -> blocked: same sandbox header denial
  • go test ./internal/server -run '^(TestAuditSearchOnlyForAllowedAgents|TestSearchAuditKeepsNewestPastTheLimit|TestAuditWindowFractionalSeconds)$' -count=1 -v -> blocked: same sandbox header denial
  • CGO_ENABLED=0 go build ./internal/server -> passed
  • CGO_ENABLED=0 go vet ./internal/server -> passed
  • CGO_ENABLED=0 go test ./internal/server -run '^(TestAuditSearchOnlyForAllowedAgents|TestSearchAuditKeepsNewestPastTheLimit|TestAuditWindowFractionalSeconds)$' -count=1 -v -> passed; all three tests passed
    Diagnostics: workflow advance failed: review approval held: no observed pull request row records a current head for Owner can allow an agent to search the audit log: audit_read, GET /_keyring/audit (154) #155, so this approval cannot be shown to be bound to it

Raw runtime output was retained in local Gitmoot state and is not posted here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant