Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Cap unified audit list limits

rcourtmanac4d566d696d
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index e7d435e7cf..ab48f8d5e4 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -92,6 +92,9 @@ and export audit reads alongside the enterprise audit surface. That read path
belongs to the API and unified-resource contracts, not to lifecycle ownership,
so the agent-install and registration lane stays focused on fleet continuity
instead of adopting execution-history persistence as a side effect.
+Those unified audit list endpoints also clamp oversized `limit` requests to
+the governed maximum, so audit history stays bounded even when callers ask
+for arbitrarily large pages.
The same shared API runtime now also exposes dedicated unified-resource
capability, relationship, and timeline reads through
`internal/api/resources.go`, but those query surfaces remain owned by the API
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 2b4440c9bd..73345f2e07 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -140,6 +140,10 @@ The same API contract now also owns the dedicated frontend resource facet
client in `frontend-modern/src/api/resources.ts`, which fetches the governed
capability, relationship, and timeline surfaces from `internal/api/resources.go`
instead of teaching the drawer or list views to reconstruct them inline.
+The unified action, lifecycle, and export audit reads now also clamp oversized
+`limit` requests to the governed maximum of `1000`, so the control-plane audit
+surface stays bounded even when callers ask for arbitrarily large history
+pages.
Those relationship and timeline payloads now also carry `lastSeenAt` freshness
and optional metadata through the same owned contract, so the drawer can
preserve provenance without inventing a separate graph-detail schema.
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index cb04ecea96..4b7d0a77cb 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -115,6 +115,9 @@ as adjacent governed API ownership rather than timeline-store ownership. The
storage and recovery lanes still own their own persistence and query
contracts, while the control-plane execution trail remains governed by the
unified-resource and audit contracts.
+Those unified audit list endpoints also clamp oversized `limit` requests to
+the governed maximum, so adjacent recovery and storage workflows do not turn
+bounded history reads into unbounded collection scans.
The same shared API runtime now also exposes dedicated
`/api/resources/{id}/capabilities`, `/api/resources/{id}/relationships`, and
`/api/resources/{id}/timeline` reads, but storage and recovery must continue
diff --git a/internal/api/activity_audit_handlers.go b/internal/api/activity_audit_handlers.go
index 12f29edacf..885659beca 100644
--- a/internal/api/activity_audit_handlers.go
+++ b/internal/api/activity_audit_handlers.go
@@ -21,6 +21,8 @@ var validAuditEventID = regexp.MustCompile(`^[a-zA-Z0-9\-]+$`)
var resolveWebhookIPs = net.DefaultResolver.LookupIPAddr
+const maxUnifiedAuditLimit = 1000
+
// AuditHandlers provides HTTP handlers for audit log endpoints.
type AuditHandlers struct {
resourceStoreProvider func(orgID string) (unifiedresources.ResourceStore, error)
@@ -624,6 +626,9 @@ func parseAuditLimit(raw string, defaultLimit int) int {
if limit <= 0 {
return defaultLimit
}
+ if limit > maxUnifiedAuditLimit {
+ return maxUnifiedAuditLimit
+ }
return limit
}
diff --git a/internal/api/audit_handlers_test.go b/internal/api/audit_handlers_test.go
index 590896efd9..810e9ae21c 100644
--- a/internal/api/audit_handlers_test.go
+++ b/internal/api/audit_handlers_test.go
@@ -820,3 +820,45 @@ func TestHandleListUnifiedExportAudits(t *testing.T) {
t.Fatalf("unexpected export audit id: %q", payload.Audits[0].ID)
}
}
+
+func TestParseAuditLimitCapsOversizedRequests(t *testing.T) {
+ cases := []struct {
+ name string
+ raw string
+ defaultLimit int
+ want int
+ }{
+ {
+ name: "uses default when blank",
+ raw: "",
+ defaultLimit: 100,
+ want: 100,
+ },
+ {
+ name: "caps oversized requests",
+ raw: "5000",
+ defaultLimit: 100,
+ want: 1000,
+ },
+ {
+ name: "preserves valid request below cap",
+ raw: "250",
+ defaultLimit: 100,
+ want: 250,
+ },
+ {
+ name: "rejects non-positive input",
+ raw: "0",
+ defaultLimit: 100,
+ want: 100,
+ },
+ }
+
+ for _, tt := range cases {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := parseAuditLimit(tt.raw, tt.defaultLimit); got != tt.want {
+ t.Fatalf("parseAuditLimit(%q, %d) = %d, want %d", tt.raw, tt.defaultLimit, got, tt.want)
+ }
+ })
+ }
+}
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 0094b48cc7..fda069a046 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -4069,6 +4069,15 @@ func TestContract_UnifiedExportAuditsJSONSnapshot(t *testing.T) {
assertJSONSnapshot(t, got, want)
}
+func TestContract_UnifiedAuditLimitCapsOversizedRequests(t *testing.T) {
+ if got := parseAuditLimit("5000", 100); got != 1000 {
+ t.Fatalf("parseAuditLimit oversized request = %d, want 1000", got)
+ }
+ if got := parseAuditLimit("250", 100); got != 250 {
+ t.Fatalf("parseAuditLimit normal request = %d, want 250", got)
+ }
+}
+
func mustStreamEvent(t *testing.T, eventType string, data interface{}) chat.StreamEvent {
t.Helper()