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
+12
View File
@@ -41,6 +41,18 @@ type ConfigOverride struct {
HeartbeatIntervalMS *int64 `json:"heartbeat_interval_ms,omitempty"`
JournaldUnit *string `json:"journald_unit,omitempty"`
ExtraFilePaths []string `json:"extra_file_paths,omitempty"`
// LogRetentionDays is unlike every other field above: it configures
// nothing about the agent's own runtime behavior (agent_control.proto
// has no equivalent field, and the Rust agent never reads this) --
// it's a central policy tag read only by api/logretention, which
// treats the largest LogRetentionDays configured across any agent as
// a protective floor a non-owner's age-based log deletion request
// must not reach into (see logretention.AgentRetentionStore). Stored
// here anyway, in the same desired_override JSONB column and edited
// on the same per-agent config page, because "a setting attached to
// an agent" is exactly what it conceptually is, even though nothing
// ever ships it to the agent process itself.
LogRetentionDays *int `json:"log_retention_days,omitempty"`
}
type Agent struct {