Add per-agent log retention floor, owner-only to set or override

api/agents.ConfigOverride gains LogRetentionDays: a per-agent setting
edited on the same remote-config page as extra_file_paths, but unlike
every other field there it's central-policy metadata api/logretention
reads, never something the agent process itself sees. Any change to
it -- setting, raising, lowering, or clearing -- requires RoleOwner,
not just RoleAdmin: the whole point of the field is a floor an admin
can't move, so an admin able to freely edit it would defeat that.

api/logretention now checks the largest LogRetentionDays configured
across any agent (AgentRetentionStore, new) before every preview/delete:
a non-owner's request is rejected with a clear 403 if it would reach
into that protected window. An owner always bypasses it, matching "make
the log retention override any attempts to delete logs by anyone other
than owner role."

Verified live end-to-end: owner sets a 90-day floor on an agent, admin
is blocked deleting anything newer than that (both preview and delete),
allowed beyond it, and owner bypasses it entirely -- confirmed against
real ClickHouse data, not just the fake-backed unit tests. Also caught
and fixed a real pre-existing latent bug while verifying in-browser: a
type="number" Input's bind:value becomes an actual JS number once a
user types into it (only the initial value is a string), which broke a
bare .trim() call on the new field.
This commit is contained in:
2026-08-21 15:11:41 -07:00
parent 787def06fd
commit a20bb5d1c7
9 changed files with 368 additions and 7 deletions
+5 -2
View File
@@ -163,8 +163,11 @@ func main() {
// Same conn sqlRunner above already wraps -- logretention issues its
// own purpose-built statements against the `logs` table directly
// rather than going through sqlRunner's SELECT-only RunSQL (see
// logretention.Store's doc comment).
logRetentionHandler := logretention.NewHandler(logger, logretention.NewStore(conn), authorizer)
// logretention.Store's doc comment). Same pgPool as dashboards/agents
// above for the owner-only retention floor (logretention.
// AgentRetentionStore reads agents.ConfigOverride.LogRetentionDays
// out of the same `agents` table agentsHandler manages).
logRetentionHandler := logretention.NewHandler(logger, logretention.NewStore(conn), logretention.NewAgentRetentionStore(pgPool), authorizer)
// One shared mux, CORS applied once around the whole thing -- see
// httpserver's doc comment for why this changed from each