@skyhook-io/radar-app 1.22.1 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/App.tsx +131 -38
- package/src/RadarApp.basename.test.tsx +177 -0
- package/src/RadarApp.settings.test.tsx +33 -0
- package/src/RadarApp.tsx +5 -0
- package/src/api/agentSandbox.ts +259 -0
- package/src/api/client.autoPromConnect.test.tsx +43 -0
- package/src/api/client.metricsRelayCheck.test.tsx +134 -0
- package/src/api/client.ts +128 -25
- package/src/api/cloudInstallDiscover.test.tsx +76 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/kagent.test.ts +82 -0
- package/src/api/kagent.ts +230 -0
- package/src/api/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +13 -0
- package/src/api/substrateWorkspace.test.ts +72 -0
- package/src/api/substrateWorkspace.ts +1394 -0
- package/src/api/vulnerabilities.ts +207 -9
- package/src/api/workloadSource.test.tsx +1172 -0
- package/src/api/workloadSource.ts +408 -0
- package/src/components/APIUnreachableBanner.test.tsx +19 -0
- package/src/components/APIUnreachableBanner.tsx +20 -0
- package/src/components/CloudConnectFlow.tsx +46 -7
- package/src/components/CloudFunnelButton.test.tsx +193 -7
- package/src/components/CloudFunnelButton.tsx +127 -32
- package/src/components/ConnectionErrorView.test.tsx +63 -2
- package/src/components/ConnectionErrorView.tsx +88 -68
- package/src/components/SelfManagedStart.tsx +12 -2
- package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
- package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
- package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
- package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
- package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
- package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
- package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
- package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
- package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
- package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
- package/src/components/agentsandbox/data.ts +135 -0
- package/src/components/agentsandbox/host.test.ts +27 -0
- package/src/components/agentsandbox/host.tsx +85 -0
- package/src/components/agentsandbox/labels.test.ts +42 -0
- package/src/components/agentsandbox/labels.ts +146 -0
- package/src/components/agentsandbox/listFilters.ts +85 -0
- package/src/components/agentsandbox/lists.ts +52 -0
- package/src/components/agentsandbox/routes.ts +23 -0
- package/src/components/agentsandbox/shared.tsx +321 -0
- package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
- package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
- package/src/components/agentsandbox/workspace.tsx +258 -0
- package/src/components/agentsandbox/workspaceRoute.ts +18 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
- package/src/components/applications/ApplicationsView.tsx +156 -3
- package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
- package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
- package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
- package/src/components/audit/VulnerabilitiesView.tsx +639 -199
- package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
- package/src/components/cloudHints/CloudHintLink.tsx +29 -0
- package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
- package/src/components/cloudHints/cloudHints.test.ts +126 -0
- package/src/components/cloudHints/cloudHints.ts +131 -0
- package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
- package/src/components/cloudHints/cloudLinks.test.ts +52 -0
- package/src/components/cloudHints/cloudLinks.ts +31 -0
- package/src/components/cloudHints/hintStorage.ts +28 -0
- package/src/components/cnpg/CNPGView.tsx +4 -7
- package/src/components/diagnose/ActivityTurn.tsx +6 -4
- package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
- package/src/components/diagnose/AssessmentCard.tsx +1 -2
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
- package/src/components/diagnose/DiagnoseContext.tsx +7 -0
- package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
- package/src/components/diagnose/Home.test.tsx +6 -0
- package/src/components/diagnose/Home.tsx +10 -3
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
- package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
- package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
- package/src/components/diagnose/InvestigationView.tsx +120 -23
- package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
- package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
- package/src/components/diagnose/investigationState.ts +9 -0
- package/src/components/diagnose/parts.test.tsx +11 -3
- package/src/components/diagnose/toolCallLabel.ts +3 -0
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
- package/src/components/home/ActivitySummary.tsx +3 -8
- package/src/components/home/ClusterHealthCard.tsx +91 -17
- package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
- package/src/components/home/HomeAgentBlock.tsx +2 -0
- package/src/components/home/HomeView.tsx +9 -29
- package/src/components/home/MCPSetupDialog.test.tsx +9 -0
- package/src/components/home/MCPSetupDialog.tsx +6 -2
- package/src/components/home/McpCloudLine.test.tsx +162 -0
- package/src/components/home/McpCloudLine.tsx +95 -0
- package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
- package/src/components/home/TopologyPreview.test.tsx +31 -30
- package/src/components/home/TopologyPreview.tsx +19 -28
- package/src/components/home/mcpToolCatalog.test.ts +10 -0
- package/src/components/home/mcpToolCatalog.ts +7 -7
- package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
- package/src/components/issues/IssuesPane.render.test.tsx +36 -1
- package/src/components/issues/IssuesPane.tsx +181 -23
- package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
- package/src/components/issues/SinceLastVisitRow.tsx +71 -0
- package/src/components/issues/sinceLastVisit.test.ts +266 -0
- package/src/components/issues/sinceLastVisit.ts +439 -0
- package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
- package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
- package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
- package/src/components/kagent/KagentAgentSessions.tsx +124 -0
- package/src/components/kagent/KagentDetailPage.tsx +106 -0
- package/src/components/kagent/KagentLists.tsx +412 -0
- package/src/components/kagent/KagentOverview.tsx +234 -0
- package/src/components/kagent/KagentPages.tsx +690 -0
- package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
- package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
- package/src/components/kagent/KagentSidebar.test.tsx +112 -0
- package/src/components/kagent/KagentView.tsx +109 -0
- package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
- package/src/components/kagent/host.tsx +144 -0
- package/src/components/kagent/routes.ts +31 -0
- package/src/components/kagent/shared.tsx +336 -0
- package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
- package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
- package/src/components/kagent/workspace.fixtures.ts +108 -0
- package/src/components/kagent/workspaceRoute.ts +18 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
- package/src/components/resource/MetricsNotConnected.tsx +10 -7
- package/src/components/resource/PrometheusCharts.tsx +10 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
- package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
- package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
- package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
- package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +2 -6
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
- package/src/components/resources/renderers/PodRenderer.tsx +8 -2
- package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
- package/src/components/resources/renderers/WorkloadRenderer.tsx +4 -1
- package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
- package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
- package/src/components/settings/SettingsDialog.tsx +84 -16
- package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
- package/src/components/settings/SubstrateSettings.test.tsx +131 -0
- package/src/components/settings/SubstrateSettings.tsx +544 -0
- package/src/components/settings/settings-state.test.ts +21 -3
- package/src/components/settings/settings-state.ts +13 -3
- package/src/components/share/ShareLinkButton.test.tsx +360 -0
- package/src/components/share/ShareLinkButton.tsx +391 -0
- package/src/components/share/openShareInCloud.test.ts +29 -0
- package/src/components/share/openShareInCloud.ts +10 -0
- package/src/components/share/shareLink.test.ts +129 -0
- package/src/components/share/shareLink.ts +175 -0
- package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
- package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
- package/src/components/substrate/SubstrateActorPage.tsx +384 -0
- package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
- package/src/components/substrate/SubstrateActors.tsx +612 -0
- package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
- package/src/components/substrate/SubstrateConnect.tsx +88 -0
- package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
- package/src/components/substrate/SubstrateOverview.tsx +575 -0
- package/src/components/substrate/SubstratePages.test.tsx +478 -0
- package/src/components/substrate/SubstratePool.test.tsx +462 -0
- package/src/components/substrate/SubstratePoolPage.tsx +95 -0
- package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
- package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
- package/src/components/substrate/SubstrateStateBar.tsx +63 -0
- package/src/components/substrate/SubstrateTemplates.tsx +376 -0
- package/src/components/substrate/SubstrateView.tsx +173 -0
- package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
- package/src/components/substrate/SubstrateWorkers.tsx +389 -0
- package/src/components/substrate/attention.ts +81 -0
- package/src/components/substrate/contextPin.tsx +69 -0
- package/src/components/substrate/host.tsx +83 -0
- package/src/components/substrate/kubectlTarget.test.tsx +77 -0
- package/src/components/substrate/readings.test.ts +484 -0
- package/src/components/substrate/readings.ts +997 -0
- package/src/components/substrate/routes.ts +103 -0
- package/src/components/substrate/shared.tsx +426 -0
- package/src/components/substrate/substrate.fixtures.ts +325 -0
- package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
- package/src/components/substrate/workspaceRoute.ts +23 -0
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
- package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
- package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -5
- package/src/components/traffic/TrafficGraph.test.tsx +26 -0
- package/src/components/traffic/TrafficGraph.tsx +17 -14
- package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
- package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
- package/src/components/traffic/TrafficView.tsx +26 -56
- package/src/components/traffic/trafficFilters.test.ts +61 -1
- package/src/components/traffic/trafficFilters.ts +68 -8
- package/src/components/velero/VeleroOverview.tsx +2 -2
- package/src/components/velero/VeleroView.tsx +3 -6
- package/src/components/vulnerabilities/columns.tsx +132 -0
- package/src/components/vulnerabilities/filters.tsx +317 -0
- package/src/components/vulnerabilities/owner.test.ts +54 -0
- package/src/components/vulnerabilities/owner.tsx +163 -0
- package/src/components/vulnerabilities/parts.test.ts +126 -12
- package/src/components/vulnerabilities/parts.tsx +612 -52
- package/src/components/vulnerabilities/traffic.test.tsx +65 -0
- package/src/components/vulnerabilities/traffic.tsx +40 -0
- package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
- package/src/components/workload/WorkloadView.tsx +119 -14
- package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
- package/src/components/workspace/layout.tsx +13 -7
- package/src/components/workspace/sidebar.test.ts +48 -0
- package/src/components/workspace/sidebar.ts +73 -3
- package/src/components/workspace/table.ts +2 -1
- package/src/context/ConnectionContext.tsx +24 -5
- package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
- package/src/context/ConnectionProvider.handover.test.tsx +94 -0
- package/src/context/DiagnoseCustomization.tsx +20 -2
- package/src/contexts/RegistryAccessMode.test.tsx +51 -0
- package/src/contexts/RegistryAccessMode.tsx +25 -0
- package/src/hooks/useEventSource.test.tsx +275 -4
- package/src/hooks/useEventSource.ts +278 -51
- package/src/index.ts +1 -0
- package/src/integrations/resourceHost.ts +12 -6
- package/src/integrations/resourceHosts.test.tsx +27 -1
- package/src/integrations/resourceHosts.tsx +15 -7
- package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
- package/src/integrations/sidebarWorkspaces.ts +41 -0
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.ts +7 -1
- package/src/integrations/workspaceScreens.tsx +6 -0
- package/src/utils/navigation.test.ts +1 -6
- package/src/utils/navigation.ts +9 -44
- package/src/utils/network-policy-navigation.test.ts +21 -36
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { clsx } from 'clsx'
|
|
3
|
+
import { CalendarX } from 'lucide-react'
|
|
4
|
+
import { WithTooltip } from '../ui/Tooltip'
|
|
5
|
+
import type { VulnerabilitiesResponse, VulnerabilityView } from '../../api/vulnerabilities'
|
|
6
|
+
|
|
7
|
+
/** A table column that is off until someone turns it on, from the page's
|
|
8
|
+
* menu ("Show <label>"). */
|
|
9
|
+
export interface OptionalColumn {
|
|
10
|
+
key: string
|
|
11
|
+
label: string
|
|
12
|
+
/** Says what the column holds: the column head's tooltip. */
|
|
13
|
+
tip: string
|
|
14
|
+
/** Track width in the table's grid. */
|
|
15
|
+
track: string
|
|
16
|
+
/** Whether any row of the answer has a value for it. A column with none
|
|
17
|
+
* (an older Radar, an older Trivy, a report that leaves the field out)
|
|
18
|
+
* isn't offered or drawn, so it never shows as a column of dashes. */
|
|
19
|
+
hasData: (data: VulnerabilitiesResponse) => boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Each view's optional columns, in the order they appear. Every value is also
|
|
23
|
+
// in that view's CSV, whatever is shown. An entry with no track isn't a grid
|
|
24
|
+
// column of the view's table (Package URL sits in an expanded image).
|
|
25
|
+
export const OPTIONAL_COLUMNS: Partial<Record<VulnerabilityView, OptionalColumn[]>> = {
|
|
26
|
+
image: [
|
|
27
|
+
{ key: 'image.os', label: 'OS', tip: "The image's OS release, as Trivy reports it.", track: 'minmax(140px,0.8fr)', hasData: (d) => !!d.images?.some((i) => i.os) },
|
|
28
|
+
{ key: 'image.scanner', label: 'Scanner', tip: "The scanner and version that wrote the image's newest report.", track: '112px', hasData: (d) => !!d.images?.some((i) => i.scanner) },
|
|
29
|
+
{ key: 'image.packageUrl', label: 'Package URL', tip: "The package URL (purl) Trivy reports for each finding, in an expanded image's findings.", track: '', hasData: (d) => !!d.images?.some((i) => i.findings.some((f) => f.packageUrl)) },
|
|
30
|
+
],
|
|
31
|
+
cve: [
|
|
32
|
+
{ key: 'cve.epss', label: 'EPSS', tip: 'EPSS by FIRST: the chance of exploitation activity in the next 30 days, and its percentile among scored CVEs.', track: '64px', hasData: (d) => d.intel?.epss.state === 'ready' && !!d.cves?.some((c) => c.epss) },
|
|
33
|
+
{ key: 'cve.published', label: 'Published', tip: "When the CVE was published, from Trivy's database. Not when it was found in this cluster.", track: '92px', hasData: (d) => !!d.cves?.some((c) => c.publishedAt) },
|
|
34
|
+
{ key: 'cve.age', label: 'Age', tip: 'Days since the CVE was published, not since it was found in this cluster.', track: '76px', hasData: (d) => !!d.cves?.some((c) => c.publishedAt) },
|
|
35
|
+
],
|
|
36
|
+
workload: [
|
|
37
|
+
{ key: 'workload.owner', label: 'Owner', tip: 'The Helm release, or the Argo CD or Flux app and its repository, that deploys the workload, and its team from the team label on the workload or its namespace. Blank when Radar found none of these, and Not checked when your access kept Radar from looking everywhere. It names the app, not the file that sets the image tag.', track: 'minmax(160px,1fr)', hasData: (d) => !!d.ownership },
|
|
38
|
+
],
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const STORAGE_KEY = 'radar-vulnerability-columns'
|
|
42
|
+
|
|
43
|
+
function readShown(): Set<string> {
|
|
44
|
+
try {
|
|
45
|
+
const parsed: unknown = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '[]')
|
|
46
|
+
return new Set(Array.isArray(parsed) ? parsed.filter((k): k is string => typeof k === 'string') : [])
|
|
47
|
+
} catch {
|
|
48
|
+
return new Set()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The optional columns this browser shows, across views; none by default. */
|
|
53
|
+
export function useOptionalColumns() {
|
|
54
|
+
const [shown, setShown] = useState(readShown)
|
|
55
|
+
const toggle = (key: string) => {
|
|
56
|
+
const next = new Set(shown)
|
|
57
|
+
if (next.has(key)) next.delete(key)
|
|
58
|
+
else next.add(key)
|
|
59
|
+
setShown(next)
|
|
60
|
+
try {
|
|
61
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify([...next]))
|
|
62
|
+
} catch {
|
|
63
|
+
// Private windows and blocked storage: the choice lasts this visit.
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { shown, toggle }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The view's optional columns this answer has data for. */
|
|
70
|
+
export function availableColumns(view: VulnerabilityView, data: VulnerabilitiesResponse): OptionalColumn[] {
|
|
71
|
+
return (OPTIONAL_COLUMNS[view] ?? []).filter((c) => c.hasData(data))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The view's optional columns, each with whether it is drawn: on in this
|
|
75
|
+
* browser, and with data in this answer. */
|
|
76
|
+
export function columnsFor(view: VulnerabilityView, shown: ReadonlySet<string>, data: VulnerabilitiesResponse): Record<string, boolean> {
|
|
77
|
+
return Object.fromEntries((OPTIONAL_COLUMNS[view] ?? []).map((c) => [c.key.split('.')[1], shown.has(c.key) && c.hasData(data)]))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A column head with its tooltip, underlined to show there is one. */
|
|
81
|
+
export function OptionalHead({ column, align }: { column?: OptionalColumn; align?: 'right' }) {
|
|
82
|
+
if (!column) return null
|
|
83
|
+
return (
|
|
84
|
+
<WithTooltip tip={column.tip}>
|
|
85
|
+
<span className={clsx('underline decoration-dotted underline-offset-2', align === 'right' && 'text-right')}>{column.label}</span>
|
|
86
|
+
</WithTooltip>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function optionalColumn(view: VulnerabilityView, name: string): OptionalColumn | undefined {
|
|
91
|
+
return OPTIONAL_COLUMNS[view]?.find((c) => c.key === `${view}.${name}`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Whole days since a timestamp, never negative. */
|
|
95
|
+
export function daysSince(iso: string, now = Date.now()): number | undefined {
|
|
96
|
+
const t = Date.parse(iso)
|
|
97
|
+
return Number.isFinite(t) ? Math.max(0, Math.floor((now - t) / 86_400_000)) : undefined
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A timestamp's calendar date, as YYYY-MM-DD in UTC. */
|
|
101
|
+
export function isoDate(iso: string): string {
|
|
102
|
+
const t = Date.parse(iso)
|
|
103
|
+
return Number.isFinite(t) ? new Date(t).toISOString().slice(0, 10) : iso
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* An image's OS as quiet text, "debian 10.9 · end of life", the end-of-life
|
|
108
|
+
* part only when Trivy says so. lead puts a separator before it, for the
|
|
109
|
+
* image name's line.
|
|
110
|
+
*/
|
|
111
|
+
export function OsLabel({ os, endOfLife, lead = false, className }: { os?: string; endOfLife?: boolean; lead?: boolean; className?: string }) {
|
|
112
|
+
if (!os && !endOfLife) return null
|
|
113
|
+
return (
|
|
114
|
+
<span className={clsx('flex min-w-0 items-baseline gap-1.5 whitespace-nowrap text-xs text-theme-text-tertiary', className)}>
|
|
115
|
+
{os && <span className="min-w-0 truncate font-mono">{lead && <span aria-hidden>· </span>}{os}</span>}
|
|
116
|
+
{endOfLife && <EndOfLifeNote lead={lead || !!os} />}
|
|
117
|
+
</span>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Trivy's end-of-life word for an OS: gray, with a mark, never a status colour. */
|
|
122
|
+
export function EndOfLifeNote({ lead = false }: { lead?: boolean }) {
|
|
123
|
+
return (
|
|
124
|
+
<WithTooltip tip="Trivy reports this OS release as end of life.">
|
|
125
|
+
<span className="inline-flex shrink-0 items-baseline gap-1 font-sans text-xs text-theme-text-tertiary">
|
|
126
|
+
{lead && <span aria-hidden>·</span>}
|
|
127
|
+
<CalendarX className="h-3 w-3 self-center" aria-hidden />
|
|
128
|
+
end of life
|
|
129
|
+
</span>
|
|
130
|
+
</WithTooltip>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { createPortal } from 'react-dom'
|
|
4
|
+
import { clsx } from 'clsx'
|
|
5
|
+
import { ChevronDown, X } from 'lucide-react'
|
|
6
|
+
import { MultiSelectPicker } from '@skyhook-io/k8s-ui/components/ui/MultiSelectPicker'
|
|
7
|
+
import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
|
|
8
|
+
import { TRANSITION_MENU, overlayExitMs, overlayTransitionStyle } from '@skyhook-io/k8s-ui/utils/animation'
|
|
9
|
+
import type { VulnerabilityRiskFactor, VulnerabilitySeverity } from '../../api/vulnerabilities'
|
|
10
|
+
import { RISK_FACTORS, RISK_ORDER, SEVERITIES } from './parts'
|
|
11
|
+
|
|
12
|
+
/** Severities as the filter offers them, unrated last. */
|
|
13
|
+
export const SEVERITY_FILTERS: { key: VulnerabilitySeverity; label: string }[] = [...SEVERITIES.map(({ key, label }) => ({ key, label })), { key: 'unknown', label: 'Unrated' }]
|
|
14
|
+
|
|
15
|
+
/** "Severity" with none selected, the severity's name for one, "Severity: 2" for more. */
|
|
16
|
+
export function severityFilterLabel(selected: VulnerabilitySeverity[]): string {
|
|
17
|
+
const chosen = SEVERITY_FILTERS.filter((s) => selected.includes(s.key))
|
|
18
|
+
if (chosen.length === 0) return 'Severity'
|
|
19
|
+
if (chosen.length === 1) return chosen[0].label
|
|
20
|
+
return `Severity: ${chosen.length}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** "More filters", or "More filters · 2" when two of its filters are on. */
|
|
24
|
+
export function moreFiltersLabel(on: number): string {
|
|
25
|
+
return on > 0 ? `More filters · ${on}` : 'More filters'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ENABLED = 'input:not([disabled]), button:not([disabled])'
|
|
29
|
+
const FOCUSABLE = 'button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])'
|
|
30
|
+
|
|
31
|
+
// A checkbox first: a disabled Clear all can't take focus.
|
|
32
|
+
const firstControl = (panel: HTMLElement | null) => panel?.querySelector<HTMLElement>('input:not([disabled])') ?? panel?.querySelector<HTMLElement>(ENABLED) ?? null
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A chip that opens a panel of filters below it, in the popover the
|
|
36
|
+
* timeline's Kinds filter uses. The panel takes focus when it opens and
|
|
37
|
+
* gives it back to the chip on Escape, Done, or tabbing past either end,
|
|
38
|
+
* since it is drawn at the end of the page rather than after the chip.
|
|
39
|
+
* A change made in the panel can take away the control that had focus:
|
|
40
|
+
* Clear all disables itself, and a filter offered only while on drops out
|
|
41
|
+
* once off. Focus then goes to the panel's first checkbox, or, when the
|
|
42
|
+
* chip itself goes, to the control before it, rather than to the page.
|
|
43
|
+
*/
|
|
44
|
+
function FilterDropdown({ label, active, panelLabel, width = 272, children }: {
|
|
45
|
+
label: string
|
|
46
|
+
active: boolean
|
|
47
|
+
panelLabel: string
|
|
48
|
+
width?: number
|
|
49
|
+
children: (close: () => void) => ReactNode
|
|
50
|
+
}) {
|
|
51
|
+
const [open, setOpen] = useState(false)
|
|
52
|
+
const { shouldRender, isOpen } = useAnimatedUnmount(open, overlayExitMs('menu'))
|
|
53
|
+
const rootRef = useRef<HTMLDivElement | null>(null)
|
|
54
|
+
const buttonRef = useRef<HTMLButtonElement | null>(null)
|
|
55
|
+
const panelRef = useRef<HTMLDivElement | null>(null)
|
|
56
|
+
const [anchor, setAnchor] = useState<{ left: number; top: number } | null>(null)
|
|
57
|
+
const panelId = useId()
|
|
58
|
+
const triggerId = `${panelId}-trigger`
|
|
59
|
+
|
|
60
|
+
// By id, not the ref: the panel's Done button gets this during render.
|
|
61
|
+
const close = () => {
|
|
62
|
+
setOpen(false)
|
|
63
|
+
document.getElementById(triggerId)?.focus()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
useLayoutEffect(() => {
|
|
67
|
+
if (!open) return
|
|
68
|
+
const place = () => {
|
|
69
|
+
const r = rootRef.current?.getBoundingClientRect()
|
|
70
|
+
if (r) setAnchor({ left: Math.max(8, Math.min(r.left, window.innerWidth - width - 8)), top: r.bottom + 4 })
|
|
71
|
+
}
|
|
72
|
+
place()
|
|
73
|
+
window.addEventListener('scroll', place, true)
|
|
74
|
+
window.addEventListener('resize', place)
|
|
75
|
+
return () => {
|
|
76
|
+
window.removeEventListener('scroll', place, true)
|
|
77
|
+
window.removeEventListener('resize', place)
|
|
78
|
+
}
|
|
79
|
+
}, [open, width])
|
|
80
|
+
|
|
81
|
+
const placed = anchor !== null
|
|
82
|
+
// On a reopen after the exit finished, the panel mounts a render after
|
|
83
|
+
// open turns true, so this waits for shouldRender too.
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!open || !placed || !shouldRender) return
|
|
86
|
+
firstControl(panelRef.current)?.focus()
|
|
87
|
+
}, [open, placed, shouldRender])
|
|
88
|
+
|
|
89
|
+
const focusInPanel = useRef(false)
|
|
90
|
+
useLayoutEffect(() => {
|
|
91
|
+
if (!open) focusInPanel.current = false
|
|
92
|
+
const panel = panelRef.current
|
|
93
|
+
if (!open || !panel || !focusInPanel.current) return
|
|
94
|
+
const active = document.activeElement
|
|
95
|
+
const lost = !active || active === document.body || (panel.contains(active) && active.matches(':disabled'))
|
|
96
|
+
if (lost) (firstControl(panel) ?? buttonRef.current)?.focus()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
useLayoutEffect(() => {
|
|
100
|
+
const root = rootRef.current
|
|
101
|
+
return () => {
|
|
102
|
+
if (!root || !(focusInPanel.current || root.contains(document.activeElement))) return
|
|
103
|
+
const row = Array.from(root.parentElement?.querySelectorAll<HTMLElement>(FOCUSABLE) ?? []).filter((el) => !root.contains(el))
|
|
104
|
+
const before = row.filter((el) => root.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING)
|
|
105
|
+
;(before.at(-1) ?? row[0])?.focus()
|
|
106
|
+
}
|
|
107
|
+
}, [])
|
|
108
|
+
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (!open) return
|
|
111
|
+
const onDown = (e: PointerEvent) => {
|
|
112
|
+
const t = e.target as Node
|
|
113
|
+
if (rootRef.current?.contains(t) || panelRef.current?.contains(t)) return
|
|
114
|
+
setOpen(false)
|
|
115
|
+
}
|
|
116
|
+
const onKey = (e: KeyboardEvent) => {
|
|
117
|
+
if (e.key === 'Escape') {
|
|
118
|
+
e.stopPropagation()
|
|
119
|
+
setOpen(false)
|
|
120
|
+
buttonRef.current?.focus()
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
window.addEventListener('pointerdown', onDown)
|
|
124
|
+
window.addEventListener('keydown', onKey)
|
|
125
|
+
return () => {
|
|
126
|
+
window.removeEventListener('pointerdown', onDown)
|
|
127
|
+
window.removeEventListener('keydown', onKey)
|
|
128
|
+
}
|
|
129
|
+
}, [open])
|
|
130
|
+
|
|
131
|
+
const onPanelKey = (e: React.KeyboardEvent) => {
|
|
132
|
+
if (e.key !== 'Tab') return
|
|
133
|
+
const focusable = Array.from(panelRef.current?.querySelectorAll<HTMLElement>(ENABLED) ?? [])
|
|
134
|
+
const edge = e.shiftKey ? focusable[0] : focusable[focusable.length - 1]
|
|
135
|
+
if (document.activeElement === edge) {
|
|
136
|
+
e.preventDefault()
|
|
137
|
+
close()
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div ref={rootRef} className="relative shrink-0">
|
|
143
|
+
<button
|
|
144
|
+
ref={buttonRef}
|
|
145
|
+
id={triggerId}
|
|
146
|
+
type="button"
|
|
147
|
+
aria-haspopup="dialog"
|
|
148
|
+
aria-expanded={open}
|
|
149
|
+
aria-controls={shouldRender ? panelId : undefined}
|
|
150
|
+
onClick={() => setOpen((o) => !o)}
|
|
151
|
+
// The look of the chips beside it (FilterPill), with a chevron.
|
|
152
|
+
className={clsx(
|
|
153
|
+
'inline-flex items-center gap-1.5 whitespace-nowrap rounded-md border px-2.5 py-1 text-xs font-medium transition-colors',
|
|
154
|
+
'focus-visible:ring-2 focus-visible:ring-theme-text-primary/20 focus-visible:outline-none',
|
|
155
|
+
active || open
|
|
156
|
+
? 'bg-theme-text-primary/10 border-theme-text-primary/25 text-theme-text-primary'
|
|
157
|
+
: 'border-theme-border-light text-theme-text-secondary hover:border-theme-border hover:text-theme-text-primary hover:bg-theme-hover/50',
|
|
158
|
+
)}
|
|
159
|
+
>
|
|
160
|
+
<span>{label}</span>
|
|
161
|
+
<ChevronDown className="h-3.5 w-3.5 text-theme-text-tertiary" aria-hidden />
|
|
162
|
+
</button>
|
|
163
|
+
|
|
164
|
+
{shouldRender && anchor && createPortal(
|
|
165
|
+
<div
|
|
166
|
+
ref={panelRef}
|
|
167
|
+
id={panelId}
|
|
168
|
+
role="dialog"
|
|
169
|
+
aria-label={panelLabel}
|
|
170
|
+
inert={!open}
|
|
171
|
+
onKeyDown={onPanelKey}
|
|
172
|
+
onFocus={() => { focusInPanel.current = true }}
|
|
173
|
+
// Null when focus goes to nothing, as when its control is removed.
|
|
174
|
+
onBlur={(e) => { if (e.relatedTarget && !e.currentTarget.contains(e.relatedTarget)) focusInPanel.current = false }}
|
|
175
|
+
style={{ position: 'fixed', left: anchor.left, top: anchor.top, width, ...overlayTransitionStyle(isOpen, 'menu') }}
|
|
176
|
+
className={clsx(
|
|
177
|
+
'z-50 origin-top-left rounded-md border border-theme-border bg-theme-surface shadow-theme-lg',
|
|
178
|
+
TRANSITION_MENU,
|
|
179
|
+
isOpen ? 'opacity-100 translate-y-0 scale-100' : 'opacity-0 -translate-y-1 scale-[0.97]',
|
|
180
|
+
!open && 'pointer-events-none',
|
|
181
|
+
)}
|
|
182
|
+
>
|
|
183
|
+
{children(close)}
|
|
184
|
+
</div>,
|
|
185
|
+
document.body,
|
|
186
|
+
)}
|
|
187
|
+
</div>
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const countMeta = (n: number | undefined) => <span className="shrink-0 text-xs tabular-nums text-theme-text-tertiary">({n ?? 0})</span>
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The severity filter: one chip that opens a checklist of the five
|
|
195
|
+
* severities, each with its finding count in scope. A row is kept when it
|
|
196
|
+
* has a finding at any selected severity.
|
|
197
|
+
*/
|
|
198
|
+
export function SeverityFilter({ counts, selected, onChange }: {
|
|
199
|
+
counts: Record<VulnerabilitySeverity, number>
|
|
200
|
+
selected: VulnerabilitySeverity[]
|
|
201
|
+
onChange: (next: VulnerabilitySeverity[]) => void
|
|
202
|
+
}) {
|
|
203
|
+
const [search, setSearch] = useState('')
|
|
204
|
+
const byLabel = useMemo(() => new Map(SEVERITY_FILTERS.map((s) => [s.label, s.key])), [])
|
|
205
|
+
const selectedLabels = useMemo(() => new Set(SEVERITY_FILTERS.filter((s) => selected.includes(s.key)).map((s) => s.label)), [selected])
|
|
206
|
+
const commit = (labels: Iterable<string>) => {
|
|
207
|
+
const chosen = new Set([...labels].map((l) => byLabel.get(l)))
|
|
208
|
+
onChange(SEVERITY_FILTERS.filter((s) => chosen.has(s.key)).map((s) => s.key))
|
|
209
|
+
}
|
|
210
|
+
return (
|
|
211
|
+
<FilterDropdown label={severityFilterLabel(selected)} active={selected.length > 0} panelLabel="Severity" width={232}>
|
|
212
|
+
{(close) => (
|
|
213
|
+
<MultiSelectPicker
|
|
214
|
+
items={SEVERITY_FILTERS.map((s) => s.label)}
|
|
215
|
+
selected={selectedLabels}
|
|
216
|
+
onSelectionChange={commit}
|
|
217
|
+
onClearAll={() => onChange([])}
|
|
218
|
+
onDone={close}
|
|
219
|
+
search={search}
|
|
220
|
+
onSearchChange={setSearch}
|
|
221
|
+
searchPlaceholder="Filter severities"
|
|
222
|
+
summaryEmptyLabel="Any severity"
|
|
223
|
+
noItemsLabel="No severities."
|
|
224
|
+
clearAllDisabled={selected.length === 0}
|
|
225
|
+
clearAllAriaLabel="Clear severities"
|
|
226
|
+
searchThreshold={SEVERITY_FILTERS.length}
|
|
227
|
+
renderItemMeta={(label) => {
|
|
228
|
+
const key = byLabel.get(label)
|
|
229
|
+
return key ? countMeta(counts[key]) : null
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
)}
|
|
233
|
+
</FilterDropdown>
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function CheckRow({ label, count, description, checked, onChange }: { label: string; count?: number; description?: string; checked: boolean; onChange: () => void }) {
|
|
238
|
+
return (
|
|
239
|
+
<li className="hover:bg-theme-hover">
|
|
240
|
+
<label className="flex cursor-pointer items-start gap-2 px-3 py-1.5 text-sm text-theme-text-primary">
|
|
241
|
+
<input type="checkbox" checked={checked} onChange={onChange} className="mt-1 shrink-0 accent-current" />
|
|
242
|
+
<span className="flex min-w-0 flex-col">
|
|
243
|
+
<span className="flex items-baseline gap-2">
|
|
244
|
+
<span className="truncate">{label}</span>
|
|
245
|
+
{count !== undefined && countMeta(count)}
|
|
246
|
+
</span>
|
|
247
|
+
{description && <span className="text-xs text-theme-text-tertiary">{description}</span>}
|
|
248
|
+
</span>
|
|
249
|
+
</label>
|
|
250
|
+
</li>
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The filters most views need less often, behind one chip: Fix available,
|
|
256
|
+
* OS end of life, and the risk factors checklist. Each is passed only when
|
|
257
|
+
* the view and the answer can apply it; with none to offer there is no chip.
|
|
258
|
+
* The chip counts the filters it holds that are on, the risk factors as one;
|
|
259
|
+
* the serious three alone don't count, since the Serious risk chip shows them.
|
|
260
|
+
*/
|
|
261
|
+
export function MoreFilters({ fixable, endOfLife, risk, onClearAll }: {
|
|
262
|
+
fixable?: { on: boolean; onToggle: () => void }
|
|
263
|
+
endOfLife?: { on: boolean; count: number; onToggle: () => void }
|
|
264
|
+
risk?: { counts: Record<VulnerabilityRiskFactor, number>; selected: VulnerabilityRiskFactor[]; seriousOnly: boolean; onChange: (next: VulnerabilityRiskFactor[]) => void }
|
|
265
|
+
/** Turns every filter here off in one change. */
|
|
266
|
+
onClearAll: () => void
|
|
267
|
+
}) {
|
|
268
|
+
if (!fixable && !endOfLife && !risk) return null
|
|
269
|
+
const on = (fixable?.on ? 1 : 0) + (endOfLife?.on ? 1 : 0) + (risk && risk.selected.length > 0 && !risk.seriousOnly ? 1 : 0)
|
|
270
|
+
const anyChecked = !!fixable?.on || !!endOfLife?.on || (risk?.selected.length ?? 0) > 0
|
|
271
|
+
const toggleRisk = (f: VulnerabilityRiskFactor) => {
|
|
272
|
+
if (!risk) return
|
|
273
|
+
const next = new Set(risk.selected)
|
|
274
|
+
if (next.has(f)) next.delete(f)
|
|
275
|
+
else next.add(f)
|
|
276
|
+
risk.onChange(RISK_ORDER.filter((x) => next.has(x)))
|
|
277
|
+
}
|
|
278
|
+
return (
|
|
279
|
+
<FilterDropdown label={moreFiltersLabel(on)} active={on > 0} panelLabel="More filters" width={296}>
|
|
280
|
+
{(close) => (
|
|
281
|
+
<>
|
|
282
|
+
{(fixable || endOfLife) && (
|
|
283
|
+
<ul className="py-1">
|
|
284
|
+
{fixable && <CheckRow label="Fix available" description="Only findings the scanner lists a fixed release for." checked={fixable.on} onChange={fixable.onToggle} />}
|
|
285
|
+
{endOfLife && <CheckRow label="OS end of life" count={endOfLife.count} description="Only images whose OS release Trivy reports as end of life. Images not scanned yet stay listed: their OS is unknown." checked={endOfLife.on} onChange={endOfLife.onToggle} />}
|
|
286
|
+
</ul>
|
|
287
|
+
)}
|
|
288
|
+
{risk && (
|
|
289
|
+
<div className={clsx((fixable || endOfLife) && 'border-t border-theme-border')}>
|
|
290
|
+
<p className="px-3 pb-0.5 pt-2 text-[11px] font-semibold uppercase tracking-wider text-theme-text-tertiary">Risk factors</p>
|
|
291
|
+
<ul className="max-h-80 overflow-y-auto pb-1">
|
|
292
|
+
{RISK_ORDER.map((f) => (
|
|
293
|
+
<CheckRow key={f} label={RISK_FACTORS[f].label} count={risk.counts[f]} checked={risk.selected.includes(f)} onChange={() => toggleRisk(f)} />
|
|
294
|
+
))}
|
|
295
|
+
</ul>
|
|
296
|
+
</div>
|
|
297
|
+
)}
|
|
298
|
+
<div className="flex items-center justify-between border-t border-theme-border px-2 py-1.5 text-xs text-theme-text-secondary">
|
|
299
|
+
<button
|
|
300
|
+
type="button"
|
|
301
|
+
onClick={anyChecked ? onClearAll : undefined}
|
|
302
|
+
disabled={!anyChecked}
|
|
303
|
+
aria-label="Clear more filters"
|
|
304
|
+
className="flex items-center gap-1 rounded px-1.5 py-0.5 hover:bg-theme-hover disabled:opacity-50 disabled:hover:bg-transparent"
|
|
305
|
+
>
|
|
306
|
+
<X className="h-3 w-3" aria-hidden />
|
|
307
|
+
Clear all
|
|
308
|
+
</button>
|
|
309
|
+
<button type="button" onClick={close} className="rounded bg-theme-elevated px-2 py-0.5 text-[11px] text-theme-text-primary hover:bg-theme-hover">
|
|
310
|
+
Done
|
|
311
|
+
</button>
|
|
312
|
+
</div>
|
|
313
|
+
</>
|
|
314
|
+
)}
|
|
315
|
+
</FilterDropdown>
|
|
316
|
+
)
|
|
317
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { ownerLookup, type VulnerabilityWorkloadOwner } from '../../api/vulnerabilities'
|
|
3
|
+
import { managerLabel, ownerTip, shortRepo, uncheckedReadsText } from './owner'
|
|
4
|
+
|
|
5
|
+
const helm: VulnerabilityWorkloadOwner = {
|
|
6
|
+
kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'web',
|
|
7
|
+
manager: { tool: 'helm', kind: 'HelmRelease', namespace: 'shop', name: 'web', chart: 'web-1.2.0' },
|
|
8
|
+
team: 'payments', teamFrom: 'workload',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('owner', () => {
|
|
12
|
+
it('finds a workload by its identity, whatever its container', () => {
|
|
13
|
+
const find = ownerLookup([helm])
|
|
14
|
+
expect(find({ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'web' })).toBe(helm)
|
|
15
|
+
expect(find({ kind: 'Deployment', group: 'apps', namespace: 'other', name: 'web' })).toBeUndefined()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('shortens repository addresses for a cell', () => {
|
|
19
|
+
expect(shortRepo('https://github.com/acme/deploy.git')).toBe('github.com/acme/deploy')
|
|
20
|
+
expect(shortRepo('git@github.com:acme/deploy.git')).toBe('github.com/acme/deploy')
|
|
21
|
+
expect(shortRepo('ssh://git@github.com/acme/fleet')).toBe('git@github.com/acme/fleet')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('says what Radar knows and nothing when it knows nothing', () => {
|
|
25
|
+
expect(ownerTip(helm)).toBe('Deployed by Helm release shop/web, chart web-1.2.0. Team payments.')
|
|
26
|
+
expect(ownerTip({ ...helm, manager: { tool: 'argocd', kind: 'Application', group: 'argoproj.io', namespace: 'argocd', name: 'shop', sources: [{ repo: 'https://github.com/acme/deploy.git', path: 'apps' }] }, team: undefined }))
|
|
27
|
+
.toBe('Deployed by Argo CD Application argocd/shop, from github.com/acme/deploy (apps).')
|
|
28
|
+
expect(ownerTip({ ...helm, team: undefined, manager: { tool: 'argocd', kind: 'Application', group: 'argoproj.io', namespace: 'argocd', name: 'shop', shared: true, sources: [{ repo: 'https://charts.example.com' }, { repo: 'https://github.com/acme/deploy.git', path: 'apps' }] } }))
|
|
29
|
+
.toBe('Deployed by Argo CD Application argocd/shop, from charts.example.com, github.com/acme/deploy (apps). More than one Argo CD or Flux object manages it.')
|
|
30
|
+
expect(ownerTip({ ...helm, manager: undefined, team: undefined, managerUnknown: true })).toBe("Radar couldn't tell what deploys it.")
|
|
31
|
+
expect(ownerTip(undefined)).toBeUndefined()
|
|
32
|
+
expect(managerLabel({ tool: 'fluxcd', kind: 'Kustomization', namespace: 'f', name: 'x' })).toBe('Flux Kustomization')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('says when the viewer\'s access kept Radar from checking, not that nothing was found', () => {
|
|
36
|
+
const unchecked = { ...helm, manager: undefined, team: undefined, managerUnknown: true, managerUnchecked: true }
|
|
37
|
+
expect(ownerTip(unchecked)).toBe("Radar couldn't check what deploys it with your access.")
|
|
38
|
+
expect(uncheckedReadsText([
|
|
39
|
+
{ kind: 'Application', group: 'argoproj.io', partial: true },
|
|
40
|
+
{ kind: 'Kustomization', group: 'kustomize.toolkit.fluxcd.io', partial: true },
|
|
41
|
+
{ kind: 'HelmRelease', group: 'helm.toolkit.fluxcd.io', partial: true },
|
|
42
|
+
{ kind: 'Namespace' },
|
|
43
|
+
])).toBe("With your access, Radar couldn't read Argo CD Applications, Flux Kustomizations or Flux HelmReleases outside your namespaces. It also couldn't read namespaces, where a team label may be.")
|
|
44
|
+
expect(uncheckedReadsText([{ kind: 'Application', group: 'argoproj.io' }])).toBe("With your access, Radar couldn't read Argo CD Applications.")
|
|
45
|
+
expect(uncheckedReadsText([])).toBeUndefined()
|
|
46
|
+
expect(uncheckedReadsText(undefined)).toBeUndefined()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('never uses an em dash in its copy', () => {
|
|
50
|
+
expect(ownerTip(helm)).not.toContain('—')
|
|
51
|
+
expect(ownerTip({ ...helm, manager: undefined, managerUnknown: true, managerUnchecked: true })).not.toContain('—')
|
|
52
|
+
expect(uncheckedReadsText([{ kind: 'Application', group: 'argoproj.io', partial: true }, { kind: 'Namespace' }])).not.toContain('—')
|
|
53
|
+
})
|
|
54
|
+
})
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { createContext, useContext, type ReactNode } from 'react'
|
|
2
|
+
import { Tooltip } from '@skyhook-io/k8s-ui/components/ui/Tooltip'
|
|
3
|
+
import { WithTooltip } from '../ui/Tooltip'
|
|
4
|
+
import {
|
|
5
|
+
ownerLookup,
|
|
6
|
+
type OwnerLookup,
|
|
7
|
+
type VulnerabilitiesResponse,
|
|
8
|
+
type VulnerabilityOwnerManager,
|
|
9
|
+
type VulnerabilityOwnerRead,
|
|
10
|
+
type VulnerabilityWorkloadOwner,
|
|
11
|
+
} from '../../api/vulnerabilities'
|
|
12
|
+
|
|
13
|
+
/** The answer's owners, for any workload link on the page; absent from an older Radar. */
|
|
14
|
+
export interface OwnerInfo {
|
|
15
|
+
find: OwnerLookup
|
|
16
|
+
teamLabel: string
|
|
17
|
+
unavailable?: string
|
|
18
|
+
unchecked?: VulnerabilityOwnerRead[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const OwnerContext = createContext<OwnerInfo | undefined>(undefined)
|
|
22
|
+
|
|
23
|
+
export function ownerInfo(data: VulnerabilitiesResponse | undefined): OwnerInfo | undefined {
|
|
24
|
+
if (!data?.ownership) return undefined
|
|
25
|
+
return { find: ownerLookup(data.owners), teamLabel: data.ownership.teamLabel, unavailable: data.ownership.unavailable, unchecked: data.ownership.unchecked }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function OwnerProvider({ info, children }: { info: OwnerInfo | undefined; children: ReactNode }) {
|
|
29
|
+
return <OwnerContext.Provider value={info}>{children}</OwnerContext.Provider>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function useOwners(): OwnerInfo | undefined {
|
|
33
|
+
return useContext(OwnerContext)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const TOOL_LABEL: Record<VulnerabilityOwnerManager['tool'], string> = { helm: 'Helm release', argocd: 'Argo CD', fluxcd: 'Flux' }
|
|
37
|
+
|
|
38
|
+
export function managerLabel(m: VulnerabilityOwnerManager): string {
|
|
39
|
+
if (m.tool === 'fluxcd') return m.kind === 'Kustomization' ? 'Flux Kustomization' : 'Flux HelmRelease'
|
|
40
|
+
if (m.tool === 'argocd') return 'Argo CD Application'
|
|
41
|
+
return TOOL_LABEL[m.tool]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function readName(r: VulnerabilityOwnerRead): string {
|
|
45
|
+
if (r.group === 'argoproj.io' && r.kind === 'Application') return 'Argo CD Applications'
|
|
46
|
+
if (r.group?.endsWith('.toolkit.fluxcd.io')) return `Flux ${r.kind}s`
|
|
47
|
+
return `${r.kind} objects`
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function orList(items: string[]): string {
|
|
51
|
+
return items.length <= 1 ? items.join('') : `${items.slice(0, -1).join(', ')} or ${items.at(-1)}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Which reads the caller's access kept Radar from, in a sentence or two; undefined when none. */
|
|
55
|
+
export function uncheckedReadsText(reads: VulnerabilityOwnerRead[] | undefined): string | undefined {
|
|
56
|
+
if (!reads?.length) return undefined
|
|
57
|
+
const isNamespace = (r: VulnerabilityOwnerRead) => r.kind === 'Namespace' && !r.group
|
|
58
|
+
const managers = reads.filter((r) => !isNamespace(r))
|
|
59
|
+
const full = managers.filter((r) => !r.partial).map(readName)
|
|
60
|
+
const partial = managers.filter((r) => r.partial).map(readName)
|
|
61
|
+
const missing: string[] = []
|
|
62
|
+
if (full.length) missing.push(orList(full))
|
|
63
|
+
if (partial.length) missing.push(`${orList(partial)} outside your namespaces`)
|
|
64
|
+
if (reads.some(isNamespace)) missing.push('namespaces, where a team label may be')
|
|
65
|
+
return missing.map((m, i) => `${i === 0 ? "With your access, Radar couldn't read" : "It also couldn't read"} ${m}.`).join(' ')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A repository address without its scheme or .git, for a narrow cell. */
|
|
69
|
+
export function shortRepo(repo: string): string {
|
|
70
|
+
return repo.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '').replace(/^git@([^:]+):/, '$1/').replace(/\.git$/, '')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const UNCHECKED_LINE = "Radar couldn't check what deploys it with your access"
|
|
74
|
+
|
|
75
|
+
/** The owner's detail lines, for a tooltip. */
|
|
76
|
+
function OwnerDetail({ owner, teamLabel, unchecked }: { owner: VulnerabilityWorkloadOwner; teamLabel: string; unchecked?: VulnerabilityOwnerRead[] }) {
|
|
77
|
+
const m = owner.manager
|
|
78
|
+
return (
|
|
79
|
+
<span className="flex flex-col gap-1 text-left">
|
|
80
|
+
{m && (
|
|
81
|
+
<>
|
|
82
|
+
<span>{managerLabel(m)} <span className="font-mono">{m.namespace}/{m.name}</span></span>
|
|
83
|
+
{m.chart && <span>Chart <span className="font-mono">{m.chart}</span></span>}
|
|
84
|
+
{(m.sources ?? []).map((s) => (
|
|
85
|
+
<span key={`${s.repo}/${s.path ?? ''}`} className="break-all font-mono">{s.repo}{s.path ? ` (${s.path})` : ''}{s.chart ? `, chart ${s.chart}` : ''}</span>
|
|
86
|
+
))}
|
|
87
|
+
{m.tool === 'helm' && <span>Helm records no source repository.</span>}
|
|
88
|
+
{m.shared && <span>More than one Argo CD or Flux object manages it, or what runs it; this is the one Radar leads with.</span>}
|
|
89
|
+
</>
|
|
90
|
+
)}
|
|
91
|
+
{!m && owner.managerUnchecked && <span>{`${UNCHECKED_LINE}.`} {uncheckedReadsText(unchecked)}</span>}
|
|
92
|
+
{!m && owner.managerUnknown && !owner.managerUnchecked && <span>Radar couldn't tell what deploys it: the evidence disagrees or couldn't all be read.</span>}
|
|
93
|
+
{owner.team && <span>Team <span className="font-mono">{owner.team}</span>, from the {owner.teamFrom === 'namespace' ? "namespace's" : "workload's"} <span className="font-mono">{teamLabel}</span> label</span>}
|
|
94
|
+
{m && <span className="text-theme-text-tertiary">This is the app that deploys it. The image tag may be set by CI, an override or a values file.</span>}
|
|
95
|
+
</span>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The Owner column of By workload. Empty when Radar found nothing, never a guess. */
|
|
100
|
+
const TEAM_NOT_CHECKED = "Its namespace's team label couldn't be checked with your access."
|
|
101
|
+
|
|
102
|
+
export function OwnerCell({ workload }: { workload: { kind: string; group?: string; namespace: string; name: string } }) {
|
|
103
|
+
const info = useOwners()
|
|
104
|
+
if (!info) return <span />
|
|
105
|
+
if (info.unavailable) {
|
|
106
|
+
return (
|
|
107
|
+
<WithTooltip tip="Radar couldn't read owners for this answer: it is still loading the cluster or its connection changed. Try again shortly.">
|
|
108
|
+
<span className="text-xs text-theme-text-tertiary">Unknown</span>
|
|
109
|
+
</WithTooltip>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
const owner = info.find(workload)
|
|
113
|
+
// A namespace the viewer can't read may carry a team label: a missing team
|
|
114
|
+
// there is not checked, not none.
|
|
115
|
+
const teamUnchecked = !owner?.team && !!info.unchecked?.some((u) => u.kind === 'Namespace' && !u.group)
|
|
116
|
+
if (!owner) {
|
|
117
|
+
return teamUnchecked ? (
|
|
118
|
+
<WithTooltip tip={TEAM_NOT_CHECKED}>
|
|
119
|
+
<span className="text-xs text-theme-text-tertiary">team not checked</span>
|
|
120
|
+
</WithTooltip>
|
|
121
|
+
) : <span />
|
|
122
|
+
}
|
|
123
|
+
const m = owner.manager
|
|
124
|
+
const repo = m?.sources?.[0]?.repo
|
|
125
|
+
return (
|
|
126
|
+
<Tooltip content={<OwnerDetail owner={owner} teamLabel={info.teamLabel} unchecked={info.unchecked} />}>
|
|
127
|
+
<span className="flex min-w-0 flex-col text-xs">
|
|
128
|
+
{m ? (
|
|
129
|
+
<>
|
|
130
|
+
<span className="truncate text-theme-text-primary">{m.name}</span>
|
|
131
|
+
<span className="truncate text-theme-text-tertiary">
|
|
132
|
+
{m.tool === 'helm' ? (m.chart ? `Helm · ${m.chart}` : 'Helm release') : repo ? `${TOOL_LABEL[m.tool]} · ${shortRepo(repo)}` : managerLabel(m)}
|
|
133
|
+
</span>
|
|
134
|
+
</>
|
|
135
|
+
) : owner.managerUnchecked ? (
|
|
136
|
+
<span className="text-theme-text-tertiary">Not checked</span>
|
|
137
|
+
) : owner.managerUnknown ? (
|
|
138
|
+
<span className="text-theme-text-tertiary">Unknown</span>
|
|
139
|
+
) : null}
|
|
140
|
+
{owner.team && <span className="truncate text-theme-text-secondary">team: {owner.team}</span>}
|
|
141
|
+
{teamUnchecked && <span className="truncate text-theme-text-tertiary">team not checked</span>}
|
|
142
|
+
</span>
|
|
143
|
+
</Tooltip>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** One line for a workload link's tooltip, or undefined when nothing is known. */
|
|
148
|
+
export function ownerTip(owner: VulnerabilityWorkloadOwner | undefined): string | undefined {
|
|
149
|
+
if (!owner) return undefined
|
|
150
|
+
const parts: string[] = []
|
|
151
|
+
const m = owner.manager
|
|
152
|
+
if (m) {
|
|
153
|
+
const from = (m.sources ?? []).map((s) => `${shortRepo(s.repo)}${s.path ? ` (${s.path})` : ''}`).join(', ')
|
|
154
|
+
parts.push(`Deployed by ${managerLabel(m)} ${m.namespace}/${m.name}${m.chart ? `, chart ${m.chart}` : ''}${from ? `, from ${from}` : ''}`)
|
|
155
|
+
if (m.shared) parts.push('More than one Argo CD or Flux object manages it')
|
|
156
|
+
} else if (owner.managerUnchecked) {
|
|
157
|
+
parts.push(UNCHECKED_LINE)
|
|
158
|
+
} else if (owner.managerUnknown) {
|
|
159
|
+
parts.push("Radar couldn't tell what deploys it")
|
|
160
|
+
}
|
|
161
|
+
if (owner.team) parts.push(`Team ${owner.team}`)
|
|
162
|
+
return parts.length ? `${parts.join('. ')}.` : undefined
|
|
163
|
+
}
|