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.

Centralize frontend policy normalization

rcourtman682309bc7ccb
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index dde8744f16..465b9a4edc 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -253,6 +253,10 @@ that route through `frontend-modern/src/hooks/useUnifiedResources.ts` must
preserve canonical `policy` and `aiSafeSummary` fields so storage-bearing
resources do not silently lose their routing or redaction posture when they
cross from unified-resource ownership into storage or recovery presentation.
+That same decode path now delegates policy string and redaction normalization
+to `frontend-modern/src/utils/resourcePolicyNormalization.ts`, so storage and
+recovery surfaces do not reimplement sensitivity, routing, or redaction
+parsing locally.
That same shared `internal/api/` dependency now also assumes canonical install
payload URLs are slash-normalized before they become response fields or helper
attachments, so recovery-adjacent links and transport surfaces cannot inherit
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 7148f1e428..183ff4b21b 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -471,7 +471,11 @@ methods so change history is queryable by canonical ID and time window.
That frontend consumer rule now applies on the canonical decode path too:
`frontend-modern/src/hooks/useUnifiedResources.ts` must preserve backend-owned
policy metadata and AI-safe summaries as first-class `Resource` fields, and
-shared infrastructure consumers such as the unified resource table and detail
+it now delegates policy string and redaction normalization to the shared
+`frontend-modern/src/utils/resourcePolicyNormalization.ts` helper so the
+canonical frontend decode path does not reimplement sensitivity, routing, or
+redaction parsing locally.
+Shared infrastructure consumers such as the unified resource table and detail
drawer must present that owned metadata through shared helpers instead of
reconstructing privacy posture from display names, source types, or other
incidental runtime hints.
diff --git a/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts b/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts
index f1bbbff64b..b970fe554b 100644
--- a/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts
+++ b/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts
@@ -272,12 +272,12 @@ describe('useUnifiedResources', () => {
{
...v2Resource,
policy: {
- sensitivity: 'restricted',
+ sensitivity: ' ReStRiCtEd ',
routing: {
- scope: 'local-only',
+ scope: 'LOCAL-ONLY',
allowCloudSummary: false,
allowCloudRawSignals: false,
- redact: ['hostname', 'ip-address', 'platform-id', 'alias'],
+ redact: ['HOSTNAME', ' ip-address ', 'Platform-ID', 'ALIAS'],
},
},
aiSafeSummary: 'resource summary safe for remote AI use',
diff --git a/frontend-modern/src/hooks/useUnifiedResources.ts b/frontend-modern/src/hooks/useUnifiedResources.ts
index b7ec36cc97..ec1cafc253 100644
--- a/frontend-modern/src/hooks/useUnifiedResources.ts
+++ b/frontend-modern/src/hooks/useUnifiedResources.ts
@@ -12,10 +12,6 @@ import type {
ResourceDiscoveryTarget,
ResourceMetricsTarget,
ResourcePBSMeta,
- ResourcePolicy,
- ResourceRedactionHint,
- ResourceRoutingScope,
- ResourceSensitivity,
ResourceStatus,
ResourceStorageMeta,
ResourceRelationship,
@@ -26,6 +22,7 @@ import { logger } from '@/utils/logger';
import { eventBus } from '@/stores/events';
import { canonicalDiscoveryResourceType } from '@/utils/discoveryTarget';
import { getPreferredNormalizedPlatformId } from '@/utils/resourceIdentity';
+import { normalizeResourcePolicy } from '@/utils/resourcePolicyNormalization';
import {
resolvePlatformTypeFromSources,
resolveSourceTypeFromSources,
@@ -543,70 +540,6 @@ const metricToResourceMetric = (metric?: APIMetricValue) => {
};
};
-const resolvePolicySensitivity = (value?: string): ResourceSensitivity | undefined => {
- switch ((value || '').toLowerCase()) {
- case 'public':
- return 'public';
- case 'internal':
- return 'internal';
- case 'sensitive':
- return 'sensitive';
- case 'restricted':
- return 'restricted';
- default:
- return undefined;
- }
-};
-
-const resolvePolicyRoutingScope = (value?: string): ResourceRoutingScope | undefined => {
- switch ((value || '').toLowerCase()) {
- case 'cloud-summary':
- return 'cloud-summary';
- case 'local-first':
- return 'local-first';
- case 'local-only':
- return 'local-only';
- default:
- return undefined;
- }
-};
-
-const resolvePolicyRedactionHints = (value: unknown): ResourceRedactionHint[] | undefined => {
- if (!Array.isArray(value)) return undefined;
- const hints = value.flatMap((entry) => {
- switch ((entry || '').toString().toLowerCase()) {
- case 'hostname':
- return 'hostname';
- case 'ip-address':
- return 'ip-address';
- case 'platform-id':
- return 'platform-id';
- case 'alias':
- return 'alias';
- case 'path':
- return 'path';
- default:
- return [];
- }
- });
- return hints.length > 0 ? hints : undefined;
-};
-
-const resolvePolicy = (policy?: APIResource['policy']): ResourcePolicy | undefined => {
- const sensitivity = resolvePolicySensitivity(policy?.sensitivity);
- const scope = resolvePolicyRoutingScope(policy?.routing?.scope);
- if (!sensitivity || !scope) return undefined;
- return {
- sensitivity,
- routing: {
- scope,
- allowCloudSummary: policy?.routing?.allowCloudSummary === true,
- allowCloudRawSignals: policy?.routing?.allowCloudRawSignals === true,
- redact: resolvePolicyRedactionHints(policy?.routing?.redact),
- },
- };
-};
-
const toResource = (v2: APIResource): Resource => {
const sources = (v2.sources || []).filter(
(s): s is string => typeof s === 'string' && s.trim().length > 0,
@@ -629,7 +562,7 @@ const toResource = (v2: APIResource): Resource => {
: undefined;
const metricsTarget = resolveMetricsTarget(v2.type, v2.metricsTarget);
- const policy = resolvePolicy(v2.policy);
+ const policy = normalizeResourcePolicy(v2.policy);
const aiSafeSummary = asTrimmedString(v2.aiSafeSummary);
return {
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index f5fad952ec..064a7baa4a 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -135,6 +135,7 @@ import securityAuthPresentationSource from '@/utils/securityAuthPresentation.ts?
import resourceDetailDrawerSource from '@/components/Infrastructure/ResourceDetailDrawer.tsx?raw';
import resourceDetailMappersSource from '@/components/Infrastructure/resourceDetailMappers.ts?raw';
import unifiedResourceTableSource from '@/components/Infrastructure/UnifiedResourceTable.tsx?raw';
+import useUnifiedResourcesSource from '@/hooks/useUnifiedResources.ts?raw';
import findingsPanelSource from '@/components/AI/FindingsPanel.tsx?raw';
import exploreStatusBlockSource from '@/components/AI/Chat/ExploreStatusBlock.tsx?raw';
import aiExplorePresentationSource from '@/utils/aiExplorePresentation.ts?raw';
@@ -1821,6 +1822,11 @@ describe('frontend resource type boundaries', () => {
expect(resourceDetailDrawerSource).toContain('History');
expect(resourceDetailDrawerSource).not.toContain('healthToneClass(');
expect(resourceDetailDrawerSource).not.toContain('normalizeHealthLabel(');
+ expect(useUnifiedResourcesSource).toContain('normalizeResourcePolicy(');
+ expect(useUnifiedResourcesSource).not.toContain('const resolvePolicySensitivity =');
+ expect(useUnifiedResourcesSource).not.toContain('const resolvePolicyRoutingScope =');
+ expect(useUnifiedResourcesSource).not.toContain('const resolvePolicyRedactionHints =');
+ expect(useUnifiedResourcesSource).not.toContain('const resolvePolicy =');
expect(resourceDetailMappersSource).not.toContain('export const normalizeHealthLabel');
expect(resourceDetailMappersSource).not.toContain('export const healthToneClass');
expect(unifiedResourceTableSource).toContain('getServiceHealthSummaryPresentation');
diff --git a/frontend-modern/src/utils/__tests__/resourcePolicyNormalization.test.ts b/frontend-modern/src/utils/__tests__/resourcePolicyNormalization.test.ts
new file mode 100644
index 0000000000..77e5315556
--- /dev/null
+++ b/frontend-modern/src/utils/__tests__/resourcePolicyNormalization.test.ts
@@ -0,0 +1,45 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ normalizeResourcePolicy,
+ normalizeResourcePolicyRedactionHints,
+ normalizeResourcePolicyRoutingScope,
+ normalizeResourcePolicySensitivity,
+} from '../resourcePolicyNormalization';
+
+describe('resourcePolicyNormalization', () => {
+ it('normalizes canonical policy fields from mixed-case API payloads', () => {
+ expect(normalizeResourcePolicySensitivity(' PUBLIC ')).toBe('public');
+ expect(normalizeResourcePolicyRoutingScope('LOCAL-FIRST')).toBe('local-first');
+ expect(
+ normalizeResourcePolicyRedactionHints(['HOSTNAME', ' ip-address ', 'platform-id']),
+ ).toEqual(['hostname', 'ip-address', 'platform-id']);
+
+ expect(
+ normalizeResourcePolicy({
+ sensitivity: 'restricted',
+ routing: {
+ scope: 'Local-Only',
+ allowCloudSummary: true,
+ allowCloudRawSignals: false,
+ redact: ['alias', 'PATH'],
+ },
+ }),
+ ).toEqual({
+ sensitivity: 'restricted',
+ routing: {
+ scope: 'local-only',
+ allowCloudSummary: true,
+ allowCloudRawSignals: false,
+ redact: ['alias', 'path'],
+ },
+ });
+ });
+
+ it('rejects incomplete policy payloads', () => {
+ expect(normalizeResourcePolicySensitivity(undefined)).toBeUndefined();
+ expect(normalizeResourcePolicyRoutingScope('')).toBeUndefined();
+ expect(normalizeResourcePolicyRedactionHints([])).toBeUndefined();
+ expect(normalizeResourcePolicy({ sensitivity: 'internal' })).toBeUndefined();
+ });
+});
diff --git a/frontend-modern/src/utils/resourcePolicyNormalization.ts b/frontend-modern/src/utils/resourcePolicyNormalization.ts
new file mode 100644
index 0000000000..4d4e26a8b9
--- /dev/null
+++ b/frontend-modern/src/utils/resourcePolicyNormalization.ts
@@ -0,0 +1,89 @@
+import type {
+ ResourcePolicy,
+ ResourceRedactionHint,
+ ResourceRoutingScope,
+ ResourceSensitivity,
+} from '@/types/resource';
+
+const asTrimmedLower = (value: unknown): string => {
+ if (typeof value !== 'string') return '';
+ return value.trim().toLowerCase();
+};
+
+export const normalizeResourcePolicySensitivity = (
+ value?: unknown,
+): ResourceSensitivity | undefined => {
+ switch (asTrimmedLower(value)) {
+ case 'public':
+ return 'public';
+ case 'internal':
+ return 'internal';
+ case 'sensitive':
+ return 'sensitive';
+ case 'restricted':
+ return 'restricted';
+ default:
+ return undefined;
+ }
+};
+
+export const normalizeResourcePolicyRoutingScope = (
+ value?: unknown,
+): ResourceRoutingScope | undefined => {
+ switch (asTrimmedLower(value)) {
+ case 'cloud-summary':
+ return 'cloud-summary';
+ case 'local-first':
+ return 'local-first';
+ case 'local-only':
+ return 'local-only';
+ default:
+ return undefined;
+ }
+};
+
+export const normalizeResourcePolicyRedactionHints = (
+ value: unknown,
+): ResourceRedactionHint[] | undefined => {
+ if (!Array.isArray(value)) return undefined;
+ const hints = value.flatMap((entry) => {
+ switch (asTrimmedLower(entry)) {
+ case 'hostname':
+ return 'hostname';
+ case 'ip-address':
+ return 'ip-address';
+ case 'platform-id':
+ return 'platform-id';
+ case 'alias':
+ return 'alias';
+ case 'path':
+ return 'path';
+ default:
+ return [];
+ }
+ });
+ return hints.length > 0 ? hints : undefined;
+};
+
+export const normalizeResourcePolicy = (policy?: {
+ sensitivity?: unknown;
+ routing?: {
+ scope?: unknown;
+ allowCloudSummary?: boolean;
+ allowCloudRawSignals?: boolean;
+ redact?: unknown;
+ };
+}): ResourcePolicy | undefined => {
+ const sensitivity = normalizeResourcePolicySensitivity(policy?.sensitivity);
+ const scope = normalizeResourcePolicyRoutingScope(policy?.routing?.scope);
+ if (!sensitivity || !scope) return undefined;
+ return {
+ sensitivity,
+ routing: {
+ scope,
+ allowCloudSummary: policy?.routing?.allowCloudSummary === true,
+ allowCloudRawSignals: policy?.routing?.allowCloudRawSignals === true,
+ redact: normalizeResourcePolicyRedactionHints(policy?.routing?.redact),
+ },
+ };
+};