@skyhook-io/radar-app 1.22.2 → 1.23.1

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.
Files changed (228) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +49 -13
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/api/agentSandbox.ts +259 -0
  6. package/src/api/client.autoPromConnect.test.tsx +43 -0
  7. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  8. package/src/api/client.ts +151 -27
  9. package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
  10. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  11. package/src/api/diagnose.ts +4 -0
  12. package/src/api/kagent.test.ts +82 -0
  13. package/src/api/kagent.ts +230 -0
  14. package/src/api/poll.ts +78 -0
  15. package/src/api/prometheusCharts.ts +5 -0
  16. package/src/api/radarFeatures.test.ts +9 -0
  17. package/src/api/radarFeatures.ts +16 -0
  18. package/src/api/substrateWorkspace.test.ts +72 -0
  19. package/src/api/substrateWorkspace.ts +1394 -0
  20. package/src/api/vulnerabilities.ts +207 -9
  21. package/src/api/workloadSource.test.tsx +315 -0
  22. package/src/api/workloadSource.ts +128 -12
  23. package/src/components/CloudConnectFlow.tsx +46 -7
  24. package/src/components/CloudFunnelButton.test.tsx +193 -7
  25. package/src/components/CloudFunnelButton.tsx +128 -32
  26. package/src/components/SelfManagedStart.tsx +12 -2
  27. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  28. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  29. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  30. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  31. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  32. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  33. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  34. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  35. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  36. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  37. package/src/components/agentsandbox/data.ts +135 -0
  38. package/src/components/agentsandbox/host.test.ts +27 -0
  39. package/src/components/agentsandbox/host.tsx +85 -0
  40. package/src/components/agentsandbox/labels.test.ts +42 -0
  41. package/src/components/agentsandbox/labels.ts +146 -0
  42. package/src/components/agentsandbox/listFilters.ts +85 -0
  43. package/src/components/agentsandbox/lists.ts +52 -0
  44. package/src/components/agentsandbox/routes.ts +23 -0
  45. package/src/components/agentsandbox/shared.tsx +321 -0
  46. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  47. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  48. package/src/components/agentsandbox/workspace.tsx +258 -0
  49. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  50. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  51. package/src/components/applications/ApplicationsView.tsx +156 -3
  52. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  53. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  54. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  55. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  56. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  57. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  58. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  59. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  60. package/src/components/cloudHints/cloudHints.ts +131 -0
  61. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  62. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  63. package/src/components/cloudHints/cloudLinks.ts +31 -0
  64. package/src/components/cloudHints/hintStorage.ts +28 -0
  65. package/src/components/cnpg/CNPGView.tsx +4 -7
  66. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  67. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  68. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  69. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  70. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  71. package/src/components/helm/HelmDrawerRouting.test.tsx +34 -1
  72. package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
  73. package/src/components/helm/HelmView.tsx +4 -3
  74. package/src/components/helm/ObservedHelmNotice.tsx +39 -17
  75. package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
  76. package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
  77. package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
  78. package/src/components/home/HomeAgentBlock.tsx +2 -0
  79. package/src/components/home/HomeView.tsx +3 -3
  80. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  81. package/src/components/home/MCPSetupDialog.tsx +6 -2
  82. package/src/components/home/McpCloudLine.test.tsx +162 -0
  83. package/src/components/home/McpCloudLine.tsx +95 -0
  84. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  85. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  86. package/src/components/home/mcpToolCatalog.ts +4 -4
  87. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  88. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  89. package/src/components/issues/IssuesPane.tsx +181 -23
  90. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  91. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  92. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  93. package/src/components/issues/sinceLastVisit.ts +439 -0
  94. package/src/components/issues/uncheckedSources.test.ts +8 -0
  95. package/src/components/issues/uncheckedSources.ts +3 -0
  96. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  97. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  98. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  99. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  100. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  101. package/src/components/kagent/KagentLists.tsx +412 -0
  102. package/src/components/kagent/KagentOverview.tsx +234 -0
  103. package/src/components/kagent/KagentPages.tsx +690 -0
  104. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  105. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  106. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  107. package/src/components/kagent/KagentView.tsx +109 -0
  108. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  109. package/src/components/kagent/host.tsx +144 -0
  110. package/src/components/kagent/routes.ts +31 -0
  111. package/src/components/kagent/shared.tsx +336 -0
  112. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  113. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  114. package/src/components/kagent/workspace.fixtures.ts +108 -0
  115. package/src/components/kagent/workspaceRoute.ts +18 -0
  116. package/src/components/nudges/activeNudges.test.ts +39 -0
  117. package/src/components/nudges/activeNudges.ts +76 -0
  118. package/src/components/poll/OssPoll.tsx +871 -0
  119. package/src/components/poll/mount.test.ts +12 -0
  120. package/src/components/poll/pollCloud.test.ts +23 -0
  121. package/src/components/poll/pollCloud.ts +6 -0
  122. package/src/components/poll/pollDefinition.ts +93 -0
  123. package/src/components/poll/pollFlow.test.ts +140 -0
  124. package/src/components/poll/pollFlow.ts +137 -0
  125. package/src/components/poll/pollSender.test.ts +137 -0
  126. package/src/components/poll/pollSender.ts +76 -0
  127. package/src/components/poll/pollStorage.test.ts +53 -0
  128. package/src/components/poll/pollStorage.ts +77 -0
  129. package/src/components/poll/round.json +350 -0
  130. package/src/components/product-hunt/ProductHuntNotice.tsx +2 -0
  131. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  132. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  133. package/src/components/resource/PrometheusCharts.tsx +10 -1
  134. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  135. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  136. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  137. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  138. package/src/components/resources/ImageFilesystemModal.test.tsx +21 -1
  139. package/src/components/resources/ImageFilesystemModal.tsx +42 -3
  140. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  141. package/src/components/resources/ResourcesView.tsx +24 -11
  142. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  143. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  144. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  145. package/src/components/settings/SettingsDialog.tsx +84 -16
  146. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  147. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  148. package/src/components/settings/SubstrateSettings.tsx +544 -0
  149. package/src/components/settings/settings-state.test.ts +21 -3
  150. package/src/components/settings/settings-state.ts +13 -3
  151. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  152. package/src/components/share/ShareLinkButton.tsx +391 -0
  153. package/src/components/share/openShareInCloud.test.ts +29 -0
  154. package/src/components/share/openShareInCloud.ts +10 -0
  155. package/src/components/share/shareLink.test.ts +129 -0
  156. package/src/components/share/shareLink.ts +175 -0
  157. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  158. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  159. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  160. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  161. package/src/components/substrate/SubstrateActors.tsx +612 -0
  162. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  163. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  164. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  165. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  166. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  167. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  168. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  169. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  170. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  171. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  172. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  173. package/src/components/substrate/SubstrateView.tsx +173 -0
  174. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  175. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  176. package/src/components/substrate/attention.ts +81 -0
  177. package/src/components/substrate/contextPin.tsx +69 -0
  178. package/src/components/substrate/host.tsx +83 -0
  179. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  180. package/src/components/substrate/readings.test.ts +484 -0
  181. package/src/components/substrate/readings.ts +997 -0
  182. package/src/components/substrate/routes.ts +103 -0
  183. package/src/components/substrate/shared.tsx +426 -0
  184. package/src/components/substrate/substrate.fixtures.ts +325 -0
  185. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  186. package/src/components/substrate/workspaceRoute.ts +23 -0
  187. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  188. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  189. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  190. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  191. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  192. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  193. package/src/components/traffic/TrafficGraph.tsx +17 -14
  194. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  195. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  196. package/src/components/traffic/TrafficView.tsx +26 -56
  197. package/src/components/traffic/trafficFilters.test.ts +61 -1
  198. package/src/components/traffic/trafficFilters.ts +68 -8
  199. package/src/components/ui/UpdateNotification.tsx +2 -0
  200. package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
  201. package/src/components/velero/VeleroOverview.tsx +2 -2
  202. package/src/components/velero/VeleroView.tsx +3 -6
  203. package/src/components/vulnerabilities/columns.tsx +132 -0
  204. package/src/components/vulnerabilities/filters.tsx +317 -0
  205. package/src/components/vulnerabilities/owner.test.ts +54 -0
  206. package/src/components/vulnerabilities/owner.tsx +163 -0
  207. package/src/components/vulnerabilities/parts.test.ts +126 -12
  208. package/src/components/vulnerabilities/parts.tsx +612 -52
  209. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  210. package/src/components/vulnerabilities/traffic.tsx +40 -0
  211. package/src/components/whats-new/WhatsNew.tsx +2 -0
  212. package/src/components/whats-new/releaseNotes.ts +75 -1
  213. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  214. package/src/components/workload/WorkloadView.tsx +52 -13
  215. package/src/components/workspace/layout.tsx +13 -7
  216. package/src/components/workspace/sidebar.test.ts +48 -0
  217. package/src/components/workspace/sidebar.ts +73 -3
  218. package/src/components/workspace/table.ts +2 -1
  219. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  220. package/src/contexts/RegistryAccessMode.tsx +25 -0
  221. package/src/integrations/resourceHost.ts +12 -6
  222. package/src/integrations/resourceHosts.test.tsx +27 -1
  223. package/src/integrations/resourceHosts.tsx +15 -7
  224. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  225. package/src/integrations/sidebarWorkspaces.ts +41 -0
  226. package/src/integrations/workspaceRoute.ts +1 -1
  227. package/src/integrations/workspaceRoutes.ts +7 -1
  228. package/src/integrations/workspaceScreens.tsx +6 -0
@@ -1,14 +1,27 @@
1
+ import { createContext, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from 'react'
2
+ import type { ReactNode } from 'react'
3
+ import { createPortal } from 'react-dom'
1
4
  import { clsx } from 'clsx'
2
- import { Globe } from 'lucide-react'
5
+ import { Flame, Globe, ShieldAlert } from 'lucide-react'
3
6
  import type { LucideIcon } from 'lucide-react'
4
- import { WithTooltip } from '../ui/Tooltip'
5
- import { CertaintyGlyph, gapReasonText, VULN_SEVERITY_BADGE, VULN_SEVERITY_BAR, VULN_SEVERITY_TEXT, type Certainty } from '@skyhook-io/k8s-ui'
7
+ import { Tooltip, WithTooltip } from '../ui/Tooltip'
8
+ import { Badge } from '@skyhook-io/k8s-ui/components/ui/Badge'
9
+ import { CertaintyGlyph, gapReasonText, VULN_SEVERITY_BAR, VULN_SEVERITY_TEXT, type Certainty } from '@skyhook-io/k8s-ui'
6
10
  import { SEVERITY_TEXT } from '@skyhook-io/k8s-ui/utils/badge-colors'
11
+ import { TRANSITION_MENU, overlayExitMs, overlayTransitionStyle } from '@skyhook-io/k8s-ui/utils/animation'
12
+ import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
7
13
  import type {
8
14
  ExposedWorkload,
15
+ RiskyWorkload,
16
+ VulnerabilityRiskFactor,
17
+ VulnerabilityRiskSetting,
9
18
  VulnerabilitiesResponse,
10
19
  VulnerabilityCounts,
20
+ VulnerabilityEPSS,
21
+ VulnerabilityFeedStatus,
11
22
  VulnerabilityGap,
23
+ VulnerabilityIntel,
24
+ VulnerabilityKEV,
12
25
  VulnerabilityRoute,
13
26
  VulnerabilitySeverity,
14
27
  VulnerabilityWorkloadRef,
@@ -23,6 +36,25 @@ export const SEVERITIES: { key: VulnerabilitySeverity; label: string; letter: st
23
36
 
24
37
  const upper = (s: VulnerabilitySeverity) => s.toUpperCase()
25
38
 
39
+ const InRowSummaryContext = createContext(false)
40
+
41
+ /**
42
+ * Marks a row's summary: the content beside its toggle, which the toggle
43
+ * takes its name from. A tooltip's trigger there doesn't take focus, which
44
+ * would add a Tab stop for every tip in every row, nor carry its tip as a
45
+ * label, which would become part of the toggle's name. The tip still shows
46
+ * on hover.
47
+ */
48
+ export function InRowSummary({ children }: { children: ReactNode }) {
49
+ return <InRowSummaryContext.Provider value>{children}</InRowSummaryContext.Provider>
50
+ }
51
+
52
+ /** A tooltip trigger's focus and label: none in a row's summary, where its text alone counts. */
53
+ export function useTipTarget(label?: string): { tabIndex?: number; 'aria-label'?: string } {
54
+ if (useContext(InRowSummaryContext)) return {}
55
+ return label ? { tabIndex: 0, 'aria-label': label } : { tabIndex: 0 }
56
+ }
57
+
26
58
  export function totalFindings(c: VulnerabilityCounts): number {
27
59
  return c.critical + c.high + c.medium + c.low + c.unknown
28
60
  }
@@ -52,13 +84,18 @@ export function imageParts(ref: string): { name: string; path: string } {
52
84
  return slash < 0 ? { name: bare, path: '' } : { name: bare.slice(slash + 1), path: bare.slice(0, slash) }
53
85
  }
54
86
 
55
- /** An image's name and tag, with the full reference on hover. */
56
- export function ImageName({ image, className }: { image: string; className?: string }) {
87
+ /**
88
+ * An image's name and tag, with the full reference on hover, and the
89
+ * scanned digest under it when there is one: rows leave the digest out.
90
+ */
91
+ export function ImageName({ image, digest, className }: { image: string; digest?: string; className?: string }) {
57
92
  const { name } = imageParts(image)
93
+ const label = <span className={clsx('truncate font-mono', className)}>{name}</span>
94
+ if (!digest || image.includes(digest)) return <WithTooltip tip={image}>{label}</WithTooltip>
58
95
  return (
59
- <WithTooltip tip={image}>
60
- <span className={clsx('truncate font-mono', className)}>{name}</span>
61
- </WithTooltip>
96
+ <Tooltip content={<span className="flex flex-col gap-0.5"><span>{image}</span><span className="opacity-80">{digest}</span></span>} delay={300}>
97
+ {label}
98
+ </Tooltip>
62
99
  )
63
100
  }
64
101
 
@@ -83,11 +120,15 @@ export function SeverityCounts({ counts }: { counts: VulnerabilityCounts }) {
83
120
  )
84
121
  }
85
122
 
86
- // fromScore: the scanner gave no severity; Radar rated the CVSS score.
87
- export function SeverityBadge({ severity, fromScore, score }: { severity: VulnerabilitySeverity; fromScore?: boolean; score?: number }) {
123
+ /**
124
+ * A severity in a table cell: its word in the severity's colour, no pill,
125
+ * so the colour that decides priority stands out from the marks around it.
126
+ * fromScore: the scanner gave no severity; Radar rated the CVSS score.
127
+ */
128
+ export function SeverityText({ severity, fromScore, score }: { severity: VulnerabilitySeverity; fromScore?: boolean; score?: number }) {
88
129
  const label = SEVERITIES.find((s) => s.key === severity)?.label ?? 'Unknown'
89
- const badge = <span className={clsx('badge-sm w-fit justify-self-start border', VULN_SEVERITY_BADGE[upper(severity)])}>{label}</span>
90
- return fromScore ? <WithTooltip tip={`Trivy gave no severity; rated from its CVSS score${score !== undefined ? ` (${score.toFixed(1)})` : ''}`}>{badge}</WithTooltip> : badge
130
+ const text = <span className={clsx('w-fit justify-self-start text-xs font-medium', VULN_SEVERITY_TEXT[upper(severity)], fromScore && 'underline decoration-dotted underline-offset-2')}>{label}</span>
131
+ return fromScore ? <WithTooltip tip={`Trivy gave no severity; rated from its CVSS score${score !== undefined ? ` (${score.toFixed(1)})` : ''}`}>{text}</WithTooltip> : text
91
132
  }
92
133
 
93
134
  /**
@@ -198,39 +239,34 @@ export function ExposedMark({ exposed, tip }: { exposed?: ExposedWorkload; tip?:
198
239
  )
199
240
  }
200
241
 
242
+ const workloadKey = (w: VulnerabilityWorkloadRef) => `${w.group}/${w.kind}/${w.namespace}/${w.name}`
243
+
244
+ /** The distinct workloads in a list of workload containers. */
245
+ export function distinctWorkloads(workloads: VulnerabilityWorkloadRef[]): VulnerabilityWorkloadRef[] {
246
+ return [...new Map(workloads.map((w) => [workloadKey(w), w])).values()]
247
+ }
248
+
201
249
  /**
202
- * Up to `shown` distinct workload names for a collapsed row, exposed ones
203
- * first, and how many more names there are.
250
+ * The names behind a row's workload count, for its tooltip: "web, worker
251
+ * and 4 more, in 2 namespaces". total is how many workloads the row counts,
252
+ * when the list is capped; capped says the list is cut short with no total.
253
+ * first names the workloads to lead with, so the row's exposure and risk
254
+ * badge each have a name in the list.
204
255
  */
205
- export function summaryNames(workloads: VulnerabilityWorkloadRef[], exposure?: ExposureLookup, shown = 2): { names: { name: string; exposed?: ExposedWorkload }[]; rest: number } {
206
- const byName = new Map<string, ExposedWorkload | undefined>()
207
- for (const w of workloads) {
208
- const exposed = routesFor(exposure, w)
209
- if (!byName.has(w.name) || (exposed && !byName.get(w.name))) byName.set(w.name, exposed)
256
+ export function workloadNamesTip(workloads: VulnerabilityWorkloadRef[], { total, capped = false, listed = 6, first = [] }: { total?: number; capped?: boolean; listed?: number; first?: ((w: VulnerabilityWorkloadRef) => boolean)[] } = {}): string | undefined {
257
+ const distinct = distinctWorkloads(workloads)
258
+ if (distinct.length === 0) return undefined
259
+ const rank = (w: VulnerabilityWorkloadRef) => {
260
+ const i = first.findIndex((f) => f(w))
261
+ return i < 0 ? first.length : i
210
262
  }
211
- const all = [...byName].map(([name, exposed]) => ({ name, exposed }))
212
- const ordered = [...all.filter((n) => n.exposed), ...all.filter((n) => !n.exposed)]
213
- return { names: ordered.slice(0, shown), rest: Math.max(0, ordered.length - shown) }
214
- }
215
-
216
- /** "checkout, worker +4" for a list of workloads, each named once, exposed ones first with the mark. */
217
- export function WorkloadSummary({ workloads, exposure, suffix }: { workloads: VulnerabilityWorkloadRef[]; exposure?: ExposureLookup; suffix?: string }) {
218
- const { names, rest } = summaryNames(workloads, exposure)
219
- return (
220
- <span className="flex min-w-0 items-baseline text-theme-text-secondary">
221
- <span className="truncate">
222
- {names.map((n, i) => (
223
- <span key={n.name}>
224
- {i > 0 && ', '}
225
- {n.exposed && <span className="mr-1 inline-flex align-[-1px]"><ExposedMark exposed={n.exposed} /></span>}
226
- {n.name}
227
- </span>
228
- ))}
229
- {rest > 0 && ` +${rest}`}
230
- {suffix}
231
- </span>
232
- </span>
233
- )
263
+ const all = distinct.map((w, i) => ({ w, i })).sort((a, b) => rank(a.w) - rank(b.w) || a.i - b.i).map(({ w }) => w)
264
+ const names = all.slice(0, listed).map((w) => w.name)
265
+ const more = (total ?? all.length) - names.length
266
+ const named = more > 0 ? `${names.join(', ')} and ${more} more` : capped ? `${names.join(', ')} and more` : listWords(names)
267
+ const namespaces = distinctNamespaces(all)
268
+ const partial = capped || (total !== undefined && total > all.length)
269
+ return `${named}, in ${partial ? 'at least ' : ''}${namespaces} ${namespaces === 1 ? 'namespace' : 'namespaces'}`
234
270
  }
235
271
 
236
272
  /**
@@ -248,28 +284,26 @@ export function exposedCountTip(exposed: ExposedWorkload[], exposedTotal: number
248
284
  }
249
285
 
250
286
  /**
251
- * "3 exposed" with the mark, under a row's workload count ("1 exposed
252
- * workload" where the row counts containers);
253
- * "Exposure unknown" when none is known exposed but some may be; nothing
254
- * otherwise.
287
+ * "3 exposed" with the mark, after a row's workload count; "exposure
288
+ * unknown" when none is known exposed but some may be; nothing otherwise.
289
+ * workloads is the count beside it when exact, for the tooltip's "N of M".
255
290
  */
256
291
  export function ExposedCount({ exposed, total, workloads, unknown }: { exposed?: ExposedWorkload[]; total?: number; workloads?: number; unknown?: boolean }) {
257
292
  const Icon = EXPOSURE.icon
293
+ const tip = total ? exposedCountTip(exposed ?? [], total, workloads) : `${EXPOSURE.unknown}. ${EXPOSURE.unknownTip}`
294
+ const target = useTipTarget(tip)
258
295
  if (!total) {
259
296
  if (!unknown) return null
260
297
  return (
261
298
  <WithTooltip tip={EXPOSURE.unknownTip}>
262
- <span className="whitespace-nowrap text-xs text-theme-text-tertiary">{EXPOSURE.unknown}</span>
299
+ <span className="whitespace-nowrap text-xs text-theme-text-tertiary" {...target}>{EXPOSURE.unknown.toLowerCase()}</span>
263
300
  </WithTooltip>
264
301
  )
265
302
  }
266
- const tip = exposedCountTip(exposed ?? [], total, workloads)
267
- // Under a workload count the total is already on screen, so the line
268
- // says only how many are exposed; the tooltip says "N of M".
269
- const text = workloads === undefined ? `${total} exposed ${total === 1 ? 'workload' : 'workloads'}` : `${total} exposed`
303
+ const text = `${total} exposed`
270
304
  return (
271
305
  <WithTooltip tip={tip}>
272
- <span className="inline-flex items-center gap-1 whitespace-nowrap text-xs text-theme-text-secondary" aria-label={tip}>
306
+ <span className="inline-flex items-center gap-1 whitespace-nowrap text-xs text-theme-text-secondary" {...target}>
273
307
  <Icon className="h-3 w-3 shrink-0" aria-hidden />
274
308
  {text}
275
309
  </span>
@@ -277,6 +311,383 @@ export function ExposedCount({ exposed, total, workloads, unknown }: { exposed?:
277
311
  )
278
312
  }
279
313
 
314
+ /**
315
+ * The words for risky Pod settings, in one place; the CSV uses the same
316
+ * labels (TestRiskLabelsMatchTheScreen). They follow the Best practices
317
+ * checks (Privileged container, Run as non-root, Host network/PID/IPC,
318
+ * sensitive host path, runtime socket, privilege escalation, capabilities)
319
+ * and claim no more than the Pod spec shows: with no UID set, the image's
320
+ * USER decides, which Radar doesn't read, so the word is "may". Listed
321
+ * most serious first: the order the risk filter and the risk badge use.
322
+ */
323
+ export const RISK_FACTORS: Record<VulnerabilityRiskFactor, { label: string; tip: string }> = {
324
+ privileged: { label: 'Privileged', tip: 'Privileged mode gives a container every host capability, so compromising it reaches the node.' },
325
+ hostAccess: { label: 'Host access', tip: "Sharing the host's network, PID or IPC namespace, or mounting the container runtime socket or a sensitive host path, lets a compromised container reach the node." },
326
+ runsAsRoot: { label: 'Runs as root', tip: 'runAsUser is 0: a compromised process is root in its container.' },
327
+ mayRunAsRoot: { label: 'May run as root', tip: "Nothing in the Pod spec rules root out (runAsNonRoot, or a non-root runAsUser), so the image's USER decides. Radar doesn't read the image's USER." },
328
+ dangerousCapabilities: { label: 'Dangerous capabilities', tip: 'Added capabilities such as SYS_ADMIN, NET_ADMIN or ALL give near-root powers; NET_RAW, SYS_PTRACE, MKNOD and DAC_OVERRIDE allow packet spoofing, process injection or device access. The same lists the capability checks use.' },
329
+ privilegeEscalation: { label: 'Allows privilege escalation', tip: "allowPrivilegeEscalation isn't set to false, so a process can gain more privileges than its parent, through a setuid binary for example. Most specs leave it unset." },
330
+ hostPort: { label: 'Host port', tip: "A container binds a port on the node's own address, so it answers there without a Service. The Exposed mark doesn't count host ports." },
331
+ }
332
+
333
+ export const RISK_ORDER = Object.keys(RISK_FACTORS) as VulnerabilityRiskFactor[]
334
+
335
+ /**
336
+ * The factors that always bring up the risk badge. The others are common,
337
+ * so they bring it up only while the risk filter selects them, and
338
+ * otherwise count in its "+N".
339
+ */
340
+ export const SERIOUS_RISKS: VulnerabilityRiskFactor[] = ['privileged', 'hostAccess', 'runsAsRoot']
341
+
342
+ /** The answer's risky workloads by group/kind/namespace/name; any container of one matches. */
343
+ export type RiskLookup = Map<string, RiskyWorkload>
344
+
345
+ type RiskKey = WorkloadKey & { group: string }
346
+
347
+ const riskKey = (w: RiskKey) => `${w.group}/${exposureKey(w)}`
348
+
349
+ export function riskLookup(podRisk: VulnerabilitiesResponse['podRisk']): RiskLookup {
350
+ return new Map((podRisk?.workloads ?? []).map((w) => [riskKey(w), w]))
351
+ }
352
+
353
+ /**
354
+ * The view's risk lookup, so a workload name anywhere in the tables can carry
355
+ * its marks, the factors the risk filter selects, which show as marks too,
356
+ * and how to open a workload the risk badge's popover names.
357
+ */
358
+ export const RiskContext = createContext<{ lookup: RiskLookup; selected: ReadonlySet<VulnerabilityRiskFactor>; onOpen?: (w: RiskKey) => void } | undefined>(undefined)
359
+
360
+ export function useWorkloadRisk(w: RiskKey): RiskyWorkload | undefined {
361
+ return useContext(RiskContext)?.lookup.get(riskKey(w))
362
+ }
363
+
364
+ /** The risk badge's words: its lead factor and how many more, or null for no badge. */
365
+ export function riskBadgeLabel(factors: VulnerabilityRiskFactor[] | undefined, selected?: ReadonlySet<VulnerabilityRiskFactor>): string | null {
366
+ const present = RISK_ORDER.filter((f) => factors?.includes(f))
367
+ const lead = present.find((f) => SERIOUS_RISKS.includes(f) || selected?.has(f))
368
+ if (!lead) return null
369
+ return present.length > 1 ? `${RISK_FACTORS[lead].label} +${present.length - 1}` : RISK_FACTORS[lead].label
370
+ }
371
+
372
+ /** The risk badge's name: "Privileged and 5 more risky settings", or null for no badge. */
373
+ export function riskBadgeSummary(factors: VulnerabilityRiskFactor[] | undefined, selected?: ReadonlySet<VulnerabilityRiskFactor>): string | null {
374
+ const present = RISK_ORDER.filter((f) => factors?.includes(f))
375
+ const lead = present.find((f) => SERIOUS_RISKS.includes(f) || selected?.has(f))
376
+ if (!lead) return null
377
+ const more = present.length - 1
378
+ return more > 0 ? `${RISK_FACTORS[lead].label} and ${more} more risky ${more === 1 ? 'setting' : 'settings'}` : RISK_FACTORS[lead].label
379
+ }
380
+
381
+ /**
382
+ * A factor's name in the risk popover, and one short line on why it matters.
383
+ * The longer explanations stay with the risk filter and the docs.
384
+ */
385
+ export const RISK_WHY: Record<VulnerabilityRiskFactor, { label: string; why: string }> = {
386
+ privileged: { label: 'Privileged', why: 'Full access to the node if compromised' },
387
+ hostAccess: { label: 'Host access', why: "Shares the node's network, processes or files" },
388
+ runsAsRoot: { label: 'Runs as root', why: 'Root inside the container' },
389
+ mayRunAsRoot: { label: 'May run as root', why: 'No user set, so the image decides' },
390
+ dangerousCapabilities: { label: 'Dangerous capabilities', why: 'Kernel powers beyond the default set' },
391
+ privilegeEscalation: { label: 'Privilege escalation', why: 'A process can gain more privileges' },
392
+ hostPort: { label: 'Host port', why: 'Listens directly on a node port' },
393
+ }
394
+
395
+ // What the factor itself states, whatever the workload: each factor's rule
396
+ // (pkg/audit PodRisks) admits only this setting.
397
+ const RISK_RULE: Partial<Record<VulnerabilityRiskFactor, string>> = {
398
+ runsAsRoot: 'runAsUser 0',
399
+ mayRunAsRoot: 'runAsNonRoot not set',
400
+ privilegeEscalation: 'not disabled',
401
+ }
402
+
403
+ const HOST_NAMESPACES: Record<string, string> = { hostNetwork: 'hostNetwork', hostPID: 'hostPID', hostIPC: 'hostIPC' }
404
+
405
+ // The key setting in one of the checks' messages, such as "Volume "x" mounts
406
+ // sensitive host path /etc" → "hostPath /etc"; null where there is none.
407
+ function settingKey(s: VulnerabilityRiskSetting): string | null {
408
+ switch (s.factor) {
409
+ case 'hostAccess': {
410
+ if (s.check && HOST_NAMESPACES[s.check]) return HOST_NAMESPACES[s.check]
411
+ if (/root filesystem/.test(s.message)) return 'hostPath /'
412
+ const path = s.message.match(/\s(\/\S*)$/)?.[1]
413
+ return path ? `hostPath ${path}` : null
414
+ }
415
+ case 'dangerousCapabilities':
416
+ return s.message.match(/capability (\S+)$/)?.[1] ?? null
417
+ case 'hostPort':
418
+ return s.message.match(/host port (\d+)/)?.[1] ?? null
419
+ default:
420
+ return null
421
+ }
422
+ }
423
+
424
+ const MAX_EVIDENCE = 3
425
+
426
+ /**
427
+ * The specific settings behind a factor on these workloads, short: "hostNetwork,
428
+ * hostPID", "SYS_ADMIN", "9100". Read from the settings the answer carries,
429
+ * which come only for the serious factors and the ones the risk filter
430
+ * selects; a factor whose rule admits one setting says it without them.
431
+ * Empty for Privileged, whose evidence is the workloads, and where nothing
432
+ * specific is known.
433
+ */
434
+ export function riskEvidence(factor: VulnerabilityRiskFactor, workloads: RiskyWorkload[]): string[] {
435
+ if (RISK_RULE[factor]) return [RISK_RULE[factor]!]
436
+ const keys = workloads.flatMap((w) => w.settings.filter((s) => s.factor === factor).map(settingKey))
437
+ const distinct = [...new Set(keys.filter((k): k is string => !!k))]
438
+ return distinct.length > MAX_EVIDENCE ? [...distinct.slice(0, MAX_EVIDENCE), `+${distinct.length - MAX_EVIDENCE} more`] : distinct
439
+ }
440
+
441
+ export interface RiskEntry {
442
+ factor: VulnerabilityRiskFactor
443
+ label: string
444
+ why: string
445
+ serious: boolean
446
+ /** The settings behind it, short; see riskEvidence. */
447
+ evidence: string[]
448
+ /** The workloads to name with it, carrying the factor; empty when the popover is one workload's and its settings say enough. */
449
+ workloads: RiskyWorkload[]
450
+ }
451
+
452
+ /**
453
+ * The risk popover's entries: one per factor, serious first, then the
454
+ * others in RISK_ORDER. own: the popover is one workload's, so it names
455
+ * the workload only where nothing else says what was found.
456
+ */
457
+ export function riskEntries(factors: VulnerabilityRiskFactor[] | undefined, workloads: RiskyWorkload[], own = false): RiskEntry[] {
458
+ const present = RISK_ORDER.filter((f) => factors?.includes(f))
459
+ const ordered = [...present.filter((f) => SERIOUS_RISKS.includes(f)), ...present.filter((f) => !SERIOUS_RISKS.includes(f))]
460
+ return ordered.map((f) => {
461
+ const carrying = workloads.filter((w) => w.factors.includes(f))
462
+ const evidence = f === 'privileged' ? [] : riskEvidence(f, carrying)
463
+ const named = f === 'privileged' || evidence.length === 0 || !own
464
+ return { factor: f, ...RISK_WHY[f], serious: SERIOUS_RISKS.includes(f), evidence, workloads: named ? carrying : [] }
465
+ })
466
+ }
467
+
468
+ const POPOVER_WIDTH = 288
469
+
470
+ /**
471
+ * A row's or workload's risk factors as one small gray badge: the most
472
+ * serious factor and a count of the rest, "Privileged +2". Only a serious
473
+ * factor, or one the risk filter selects, brings it up: the common ones
474
+ * alone would put it on nearly every row. It is a button: a click opens a
475
+ * popover with every factor, what was found and why it matters, each
476
+ * workload named a link to it. workloads are the risky workloads behind the
477
+ * badge; own marks a workload's own badge.
478
+ */
479
+ export function RiskBadge({ factors, workloads = [], own = false, className }: { factors?: VulnerabilityRiskFactor[]; workloads?: RiskyWorkload[]; own?: boolean; className?: string }) {
480
+ const risk = useContext(RiskContext)
481
+ const label = riskBadgeLabel(factors, risk?.selected)
482
+ const summary = riskBadgeSummary(factors, risk?.selected)
483
+ const [open, setOpen] = useState(false)
484
+ const { shouldRender, isOpen } = useAnimatedUnmount(open, overlayExitMs('menu'))
485
+ const buttonRef = useRef<HTMLButtonElement | null>(null)
486
+ const panelRef = useRef<HTMLDivElement | null>(null)
487
+ const [anchor, setAnchor] = useState<{ left: number; top: number } | null>(null)
488
+ const panelId = useId()
489
+
490
+ const placed = anchor !== null
491
+
492
+ const close = (refocus = true) => {
493
+ setOpen(false)
494
+ if (refocus) buttonRef.current?.focus()
495
+ }
496
+
497
+ // Runs again once the popover is drawn (placed), to measure its height.
498
+ useLayoutEffect(() => {
499
+ if (!open) return
500
+ const place = () => {
501
+ const r = buttonRef.current?.getBoundingClientRect()
502
+ if (!r) return
503
+ const height = panelRef.current?.offsetHeight ?? 0
504
+ const below = r.bottom + 4
505
+ // Above the badge when it wouldn't fit below, as near a page's end.
506
+ const top = height > 0 && below + height > window.innerHeight - 8 && r.top - 4 - height >= 8 ? r.top - 4 - height : below
507
+ setAnchor({ left: Math.max(8, Math.min(r.left, window.innerWidth - POPOVER_WIDTH - 8)), top })
508
+ }
509
+ place()
510
+ window.addEventListener('scroll', place, true)
511
+ window.addEventListener('resize', place)
512
+ return () => {
513
+ window.removeEventListener('scroll', place, true)
514
+ window.removeEventListener('resize', place)
515
+ }
516
+ }, [open, shouldRender, placed])
517
+
518
+ useEffect(() => {
519
+ if (open && placed && shouldRender) panelRef.current?.focus()
520
+ }, [open, placed, shouldRender])
521
+
522
+ useEffect(() => {
523
+ if (!open) return
524
+ const onDown = (e: PointerEvent) => {
525
+ const t = e.target as Node
526
+ if (buttonRef.current?.contains(t) || panelRef.current?.contains(t)) return
527
+ // Focus in the popover goes back to the badge; a control clicked
528
+ // outside takes it next, as a click does.
529
+ close(!!panelRef.current?.contains(document.activeElement))
530
+ }
531
+ const onKey = (e: KeyboardEvent) => {
532
+ if (e.key !== 'Escape') return
533
+ e.stopPropagation()
534
+ close()
535
+ }
536
+ window.addEventListener('pointerdown', onDown)
537
+ window.addEventListener('keydown', onKey)
538
+ return () => {
539
+ window.removeEventListener('pointerdown', onDown)
540
+ window.removeEventListener('keydown', onKey)
541
+ }
542
+ }, [open])
543
+
544
+ if (!label) return null
545
+ const entries = riskEntries(factors, workloads, own)
546
+
547
+ // Drawn at the end of the page, so tabbing past either end of it goes
548
+ // back to the badge rather than to the end of the document.
549
+ const onPanelKey = (e: React.KeyboardEvent) => {
550
+ if (e.key !== 'Tab') return
551
+ const focusable = Array.from(panelRef.current?.querySelectorAll<HTMLElement>('button:not([disabled])') ?? [])
552
+ const active = document.activeElement
553
+ const leaving = e.shiftKey ? active === panelRef.current || active === focusable[0] : focusable.length === 0 || active === focusable[focusable.length - 1]
554
+ if (leaving) {
555
+ e.preventDefault()
556
+ close()
557
+ }
558
+ }
559
+
560
+ const openWorkload = (w: RiskyWorkload) => {
561
+ close()
562
+ risk?.onOpen?.(w)
563
+ }
564
+
565
+ return (
566
+ <>
567
+ <button
568
+ ref={buttonRef}
569
+ type="button"
570
+ data-risk-badge
571
+ aria-haspopup="dialog"
572
+ aria-expanded={open}
573
+ aria-controls={shouldRender ? panelId : undefined}
574
+ aria-label={summary ?? undefined}
575
+ onClick={() => setOpen((o) => !o)}
576
+ className={clsx('inline-flex h-4 shrink-0 items-center rounded font-sans focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-theme-text-primary/20', className)}
577
+ >
578
+ <Badge severity="neutral" size="sm" className={clsx('whitespace-nowrap py-0 leading-4 transition-colors hover:text-theme-text-primary', open && 'text-theme-text-primary')}>
579
+ <ShieldAlert className="h-3 w-3" aria-hidden />
580
+ {label}
581
+ </Badge>
582
+ </button>
583
+ {shouldRender && anchor && createPortal(
584
+ <div
585
+ ref={panelRef}
586
+ id={panelId}
587
+ role="dialog"
588
+ aria-label="Risky settings"
589
+ tabIndex={-1}
590
+ inert={!open}
591
+ onKeyDown={onPanelKey}
592
+ style={{ position: 'fixed', left: anchor.left, top: anchor.top, width: POPOVER_WIDTH, ...overlayTransitionStyle(isOpen, 'menu') }}
593
+ className={clsx(
594
+ 'z-50 origin-top-left rounded-md border border-theme-border bg-theme-surface p-3 text-xs shadow-theme-lg focus:outline-none',
595
+ TRANSITION_MENU,
596
+ isOpen ? 'opacity-100 translate-y-0 scale-100' : 'opacity-0 -translate-y-1 scale-[0.97]',
597
+ !open && 'pointer-events-none',
598
+ )}
599
+ >
600
+ <ul className="flex flex-col gap-2">
601
+ {entries.map((e) => (
602
+ <li key={e.factor} data-risk-factor={e.factor} className="flex flex-col gap-0.5">
603
+ <span className={e.serious ? 'text-theme-text-primary' : 'text-theme-text-secondary'}>
604
+ <span className="font-medium">{e.label}</span>
605
+ {(e.evidence.length > 0 || e.workloads.length > 0) && ': '}
606
+ {e.evidence.join(', ')}
607
+ {e.workloads.length > 0 && (
608
+ <>
609
+ {e.evidence.length > 0 && ' in '}
610
+ {risk?.onOpen ? (
611
+ <button type="button" onClick={() => openWorkload(e.workloads[0])} className="text-accent-text hover:underline">{e.workloads[0].name}</button>
612
+ ) : e.workloads[0].name}
613
+ {e.workloads.length > 1 && <span className="text-theme-text-tertiary">{` +${e.workloads.length - 1} more`}</span>}
614
+ </>
615
+ )}
616
+ </span>
617
+ <span className="text-theme-text-tertiary">{e.why}</span>
618
+ </li>
619
+ ))}
620
+ </ul>
621
+ </div>,
622
+ document.body,
623
+ )}
624
+ </>
625
+ )
626
+ }
627
+
628
+ /** A workload's own risk badge, from the view's lookup. */
629
+ export function WorkloadRiskBadge({ workload, className }: { workload: RiskKey; className?: string }) {
630
+ const risk = useWorkloadRisk(workload)
631
+ return risk ? <RiskBadge factors={risk.factors} workloads={[risk]} own className={className} /> : null
632
+ }
633
+
634
+ /** A row's risk badge: its factors, and the risky workloads among those it lists. */
635
+ export function RowRiskBadge({ factors, workloads, className }: { factors?: VulnerabilityRiskFactor[]; workloads: VulnerabilityWorkloadRef[]; className?: string }) {
636
+ const lookup = useContext(RiskContext)?.lookup
637
+ const risky = distinctWorkloads(workloads).map((w) => lookup?.get(riskKey(w))).filter((w): w is RiskyWorkload => !!w)
638
+ return <RiskBadge factors={factors} workloads={risky} className={className} />
639
+ }
640
+
641
+ /**
642
+ * A row's workloads on one line: how many and how many of them are
643
+ * exposed, "6 · 4 exposed". The names are on the count's tooltip, exposed
644
+ * and badged workloads first, and in the expanded row. total is the row's
645
+ * workload count; without one the count is read from the listed workloads,
646
+ * a floor when capped.
647
+ */
648
+ export function WorkloadsCell({ workloads, total, capped = false, exposed, exposedTotal, exposureUnknown }: {
649
+ workloads: VulnerabilityWorkloadRef[]
650
+ total?: number
651
+ capped?: boolean
652
+ exposed?: ExposedWorkload[]
653
+ exposedTotal?: number
654
+ exposureUnknown?: boolean
655
+ }) {
656
+ const risk = useContext(RiskContext)
657
+ const exposedLookup = exposureLookup(exposed)
658
+ const names = workloadNamesTip(workloads, {
659
+ total,
660
+ capped,
661
+ first: [
662
+ (w) => !!routesFor(exposedLookup, w),
663
+ (w) => !!risk && riskBadgeLabel(risk.lookup.get(riskKey(w))?.factors, risk.selected) !== null,
664
+ ],
665
+ })
666
+ const atLeast = total === undefined && capped
667
+ const count = total ?? distinctWorkloads(workloads).length
668
+ const exposure = !!exposedTotal || !!exposureUnknown
669
+ const shown = `${atLeast ? '≥ ' : ''}${count}`
670
+ const target = useTipTarget(`${atLeast ? 'At least ' : ''}${count} ${count === 1 ? 'workload' : 'workloads'}: ${names}`)
671
+ return (
672
+ <span className="flex min-w-0 items-center gap-1.5 whitespace-nowrap text-xs">
673
+ <WithTooltip tip={names}>
674
+ <span
675
+ className={clsx('font-mono font-medium tabular-nums text-theme-text-primary', names && 'underline decoration-dotted underline-offset-2')}
676
+ {...(names ? target : {})}
677
+ >
678
+ {shown}
679
+ </span>
680
+ </WithTooltip>
681
+ {exposure && (
682
+ <>
683
+ <span aria-hidden className="text-theme-text-tertiary">·</span>
684
+ <ExposedCount exposed={exposed} total={exposedTotal} workloads={atLeast ? undefined : count} unknown={exposureUnknown} />
685
+ </>
686
+ )}
687
+ </span>
688
+ )
689
+ }
690
+
280
691
  /** Whether an exposure gap covers this namespace, so its routes are unknown. */
281
692
  export function exposureUnknownIn(gaps: VulnerabilityGap[] | undefined, namespace: string): boolean {
282
693
  return (gaps ?? []).some((g) => {
@@ -483,3 +894,152 @@ export function uncheckedRoutesSentence(unchecked: { kind: string; group?: strin
483
894
  const names = [...new Set(unchecked.map((k) => UNCHECKED_NAMES[`${k.group ?? ''}/${k.kind}`] ?? pluralKind(k.kind)))]
484
895
  return `This cluster has ${listWords(names)}, which Radar doesn't follow yet, so workloads they route to aren't marked.`
485
896
  }
897
+
898
+ // CISA's Known Exploited Vulnerabilities catalog and FIRST's EPSS, as the
899
+ // page and the CSV name them.
900
+ export const KEV = {
901
+ icon: Flame as LucideIcon,
902
+ chip: 'Known exploited',
903
+ badge: 'KEV',
904
+ chipTip: "Only CVEs in CISA's Known Exploited Vulnerabilities catalog (KEV): exploited in the wild. US federal agencies must fix these by the catalog's due date (BOD 22-01).",
905
+ countTip: "The count comes from Trivy's findings, so it can miss some.",
906
+ noData: 'no data',
907
+ loading: 'Loading KEV data',
908
+ notApplied: "The Known exploited filter can't be applied, so every row is listed.",
909
+ noCatalog: 'This Radar has no data on known exploited CVEs.',
910
+ downloadBlocked: "The Known exploited filter can't be applied, so the file would list every row. Remove the filter to download them all.",
911
+ }
912
+
913
+ /** A feed's copy is usable: entries missing from it are not listed. */
914
+ export function feedReady(feed?: VulnerabilityFeedStatus): boolean {
915
+ return feed?.state === 'ready'
916
+ }
917
+
918
+ function dateLabel(iso: string): string {
919
+ const d = new Date(`${iso}T00:00:00Z`)
920
+ return Number.isNaN(d.getTime()) ? iso : d.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric', timeZone: 'UTC' })
921
+ }
922
+
923
+ export function kevTip(kev: VulnerabilityKEV): string {
924
+ return [
925
+ "In CISA's Known Exploited Vulnerabilities catalog.",
926
+ `Added ${dateLabel(kev.dateAdded)}.`,
927
+ `Federal due date ${dateLabel(kev.dueDate)}.`,
928
+ kev.ransomwareUse === 'known' ? 'Known to be used in ransomware campaigns.' : 'Ransomware use: not known.',
929
+ kev.requiredAction ? `Required action: ${kev.requiredAction}` : '',
930
+ ].filter(Boolean).join(' ')
931
+ }
932
+
933
+ /** The KEV mark on a CVE; absence gets none, and the page says when the catalog is missing. */
934
+ export function KevBadge({ kev }: { kev?: VulnerabilityKEV }) {
935
+ const target = useTipTarget(kev && `Known exploited. ${kevTip(kev)}`)
936
+ if (!kev) return null
937
+ // The tooltip's wrapper is the flex item on a name's line: it keeps its width.
938
+ return (
939
+ <Tooltip content={kevTip(kev)} delay={300} wrapperClassName="h-4 shrink-0">
940
+ <span className="inline-flex h-4 shrink-0 items-center" {...target}>
941
+ <Badge severity="error" size="sm" className="whitespace-nowrap py-0 leading-4">{KEV.badge}{kev.ransomwareUse === 'known' ? ' · ransomware' : ''}</Badge>
942
+ </span>
943
+ </Tooltip>
944
+ )
945
+ }
946
+
947
+ /** How many of a row's CVEs KEV lists, as a mark beside its counts. */
948
+ export function KevCount({ count, what = 'of these CVEs' }: { count?: number; what?: string }) {
949
+ const tip = `${count} ${what} ${count === 1 ? 'is' : 'are'} in CISA's Known Exploited Vulnerabilities catalog.`
950
+ const target = useTipTarget(tip)
951
+ if (!count) return null
952
+ return (
953
+ <Tooltip content={tip} delay={300} wrapperClassName="h-4 shrink-0">
954
+ <span className="inline-flex h-4 shrink-0 items-center" {...target}>
955
+ <Badge severity="error" size="sm" className="whitespace-nowrap py-0 leading-4">{count} {KEV.badge}</Badge>
956
+ </span>
957
+ </Tooltip>
958
+ )
959
+ }
960
+
961
+ function ordinal(n: number): string {
962
+ const v = n % 100
963
+ const suffix = v >= 11 && v <= 13 ? 'th' : ['th', 'st', 'nd', 'rd'][n % 10] ?? 'th'
964
+ return `${n}${suffix}`
965
+ }
966
+
967
+ /** EPSS as a percent with its percentile; "?" when the scores couldn't be loaded. */
968
+ export function EpssValue({ epss, feed }: { epss?: VulnerabilityEPSS; feed?: VulnerabilityFeedStatus }) {
969
+ const pct = (epss?.score ?? 0) * 100
970
+ const label = pct >= 10 ? `${pct.toFixed(0)}%` : pct >= 1 ? `${pct.toFixed(1)}%` : `${pct.toFixed(2)}%`
971
+ const tip = epss && `EPSS by FIRST: a ${label} chance of exploitation activity in the next 30 days, scored at or above ${Math.floor(epss.percentile * 100)}% of CVEs.`
972
+ const scored = useTipTarget(tip)
973
+ const unscored = useTipTarget()
974
+ if (!feedReady(feed)) {
975
+ return <WithTooltip tip={feedNote('EPSS', feed) ?? undefined}><span className="text-theme-text-tertiary" {...unscored}>?</span></WithTooltip>
976
+ }
977
+ if (!epss) return <WithTooltip tip="FIRST scores CVE IDs only, and not this one."><span className="text-theme-text-tertiary" {...unscored}>—</span></WithTooltip>
978
+ const percentile = ordinal(Math.min(99, Math.floor(epss.percentile * 100)))
979
+ return (
980
+ <WithTooltip tip={tip}>
981
+ <span className="flex flex-col items-end tabular-nums" {...scored}>
982
+ <span className="text-theme-text-primary">{label}</span>
983
+ <span className="text-[11px] text-theme-text-tertiary">{percentile} pct</span>
984
+ </span>
985
+ </WithTooltip>
986
+ )
987
+ }
988
+
989
+ /** What a feed that isn't ready means for the page, or null when it is ready or turned off. */
990
+ export function feedNote(name: 'KEV' | 'EPSS', feed?: VulnerabilityFeedStatus): string | null {
991
+ const what = name === 'KEV' ? "CISA's Known Exploited Vulnerabilities catalog" : "FIRST's EPSS scores"
992
+ if (!feed) return null
993
+ switch (feed.state) {
994
+ case 'ready':
995
+ return feed.stale ? `${name} data may be out of date: Radar Cloud couldn't refresh ${what}${feed.error ? ` (${feed.error})` : ''}.` : null
996
+ case 'loading':
997
+ return `Radar is loading ${what} from Radar Cloud.`
998
+ default:
999
+ return noFeedNote(name, what, feed)
1000
+ }
1001
+ }
1002
+
1003
+ // Without a feed the page is complete without it, so the note says why
1004
+ // calmly, not that something failed. Radar's copy comes from Radar Cloud,
1005
+ // so the setting to change, when there is one, is Radar Cloud's.
1006
+ function noFeedNote(name: 'KEV' | 'EPSS', what: string, feed: VulnerabilityFeedStatus): string {
1007
+ const setting = name === 'KEV' ? 'HUB_KEV_FEED' : 'HUB_EPSS_FEED'
1008
+ if (feed.state === 'disabled' && feed.downloadsOff) return `Feed downloads are turned off on this Radar Cloud, so it has no copy of ${what}. Its administrator can set ${setting} to a file.`
1009
+ if (feed.state === 'disabled') return `${name} is turned off on this Radar Cloud (${setting}).`
1010
+ return `${what} isn't available from Radar Cloud right now${feed.error ? ` (${feed.error})` : ''}. Radar asks again within the hour.`
1011
+ }
1012
+
1013
+ /**
1014
+ * Which copy of the feeds Radar holds and when Radar Cloud last checked it,
1015
+ * for the Known exploited chip's tooltip: "Radar Cloud's CISA catalog
1016
+ * 2026.11.20, checked 3m ago. EPSS scores from 2026-11-22." A stale copy
1017
+ * says why it is stale.
1018
+ */
1019
+ export function feedStatusText(intel: VulnerabilityIntel, age: (iso: string) => string): string {
1020
+ const parts: string[] = []
1021
+ const kev = intel.kev
1022
+ if (kev.state === 'ready') {
1023
+ const checked = kev.checkedAt ?? kev.loadedAt
1024
+ parts.push(`Radar Cloud's CISA catalog ${kev.version ?? 'loaded'}${checked ? `, checked ${age(checked)}` : ''}.`)
1025
+ if (kev.stale) parts.push(`Out of date: Radar Cloud couldn't refresh it${kev.error ? ` (${kev.error})` : ''}.`)
1026
+ }
1027
+ const epss = intel.epss
1028
+ if (epss.state === 'ready' && epss.version) parts.push(`EPSS scores from ${epss.version}.`)
1029
+ return parts.join(' ')
1030
+ }
1031
+
1032
+ /**
1033
+ * The page's notes about the feeds, for the coverage line: loading, and a
1034
+ * copy that couldn't be refreshed. A feed this Radar doesn't have gets no
1035
+ * note here; the Known exploited chip says so calmly, and EPSS is simply
1036
+ * not offered.
1037
+ */
1038
+ export function intelNotes(intel?: VulnerabilityIntel): { label: string; tip: string; warn: boolean }[] {
1039
+ if (!intel) return []
1040
+ const out: { label: string; tip: string; warn: boolean }[] = []
1041
+ if (intel.kev.state === 'loading') out.push({ label: KEV.loading, tip: feedNote('KEV', intel.kev) ?? '', warn: false })
1042
+ if (intel.kev.state === 'ready' && intel.kev.stale) out.push({ label: 'KEV data may be out of date', tip: feedNote('KEV', intel.kev) ?? '', warn: true })
1043
+ if (intel.epss.state === 'ready' && intel.epss.stale) out.push({ label: 'EPSS data may be out of date', tip: feedNote('EPSS', intel.epss) ?? '', warn: true })
1044
+ return out
1045
+ }