v0.9.0: vulnerabilities on the map; event counts scaled to the window

Vulnerabilities: VulnerabilityReports from operator-trivy are cached
(trimmed to the fields shown) and mapped to cards through the scanned
object in their labels. A card shows a red shield with its CRITICAL CVE
count; the details list CRITICAL and HIGH CVEs with packages, installed
and fixed versions and the advisory link, one row per CVE and image.
Counted per CVE, not per package: openssh's six subpackages had made one
CVE count six times. Kept apart from problems on purpose: on the live
cluster 22 cards have some, which would bury the "is it working" badges.

Fixes, both found on the live cluster, where they made all five current
"problems":
- a Warning event's count is cumulative since its first occurrence; four
  dex-authenticators on xeon had 38-51 probe failures over two days (one
  an hour, pods never left Ready) and were badged as a burst. The count
  is now scaled to the part of the event's lifetime the window covers.
- upmeter's smoke-mini services and pods are its synthetic test, moved
  between nodes on purpose (NoEndpoints, FailedMount while moving).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Виталий Чефанов
2026-09-25 00:50:37 +03:00
co-authored by Claude Opus 5.5
parent c563cd3a2f
commit ce6dad9a58
16 changed files with 531 additions and 22 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
name: cluster-map name: cluster-map
version: 0.8.3 version: 0.9.0
dependencies: dependencies:
- name: deckhouse_lib_helm - name: deckhouse_lib_helm
version: 1.72.24 version: 1.72.24
+6
View File
@@ -1,3 +1,9 @@
v0.9.0:
features:
- "Vulnerabilities from operator-trivy: a red shield with the number of CRITICAL CVEs on each card, and in the details every CRITICAL and HIGH CVE with its packages, installed and fixed versions and a link. A CVE counts once per card."
fixes:
- "Event counts are scaled to the 30-minute window: a cumulative count spread over days (40 probe failures in two days) no longer badges a card as a burst."
- upmeter's smoke-mini services and pods, which it moves between nodes on purpose, are not reported as problems.
v0.8.3: v0.8.3:
fixes: fixes:
- UnexpectedJob warnings (the CronJob controller's note on every manual run) are listed for information and no longer badge the CronJob. - UnexpectedJob warnings (the CronJob controller's note on every manual run) are listed for information and no longer badge the CronJob.
+8 -2
View File
@@ -26,11 +26,17 @@ Workloads managed by non-native controllers are included: Advanced DaemonSets of
A card with a problem carries a badge: yellow `!` for a warning, red `!` for an error. Namespace boxes and cards, node boxes and the tree take the colour of the worst problem inside. Sources: A card with a problem carries a badge: yellow `!` for a warning, red `!` for an error. Namespace boxes and cards, node boxes and the tree take the colour of the worst problem inside. Sources:
- **Object state**: containers in `CrashLoopBackOff`, `ImagePullBackOff` and similar, recent restarts and OOM kills, pods pending or unschedulable, workloads with no or not all replicas ready for more than 2 minutes, a stuck rollout, a CronJob whose last run failed, a Service with no ready pod, an Ingress routing to a Service that does not exist, a node that is not ready or is under memory, disk or PID pressure. - **Object state**: containers in `CrashLoopBackOff`, `ImagePullBackOff` and similar, recent restarts and OOM kills, pods pending or unschedulable, workloads with no or not all replicas ready for more than 2 minutes, a stuck rollout, a CronJob whose last run failed, a Service with no ready pod, an Ingress routing to a Service that does not exist, a node that is not ready or is under memory, disk or PID pressure.
- **Warning events** of the last 30 minutes, folded per object and reason. Scheduling, volume and back-off failures badge the card at once; any other reason needs five repeats and is listed without a badge before that, so a single failed probe during a restart does not colour the map. - **Warning events** of the last 30 minutes, folded per object and reason. Scheduling, volume and back-off failures badge the card at once; any other reason needs five repeats inside the window and is listed without a badge before that, so a single failed probe during a restart does not colour the map. An event's count is cumulative since its first occurrence, so a long-lived event is scaled to the window: 40 probe failures over two days is one an hour, not a burst.
- **Prometheus alerts** that Deckhouse mirrors into `ClusterAlert` objects. An alert is attached by its labels (`deployment`, `statefulset`, `daemonset`, `pod`, `service`, `ingress`, `node`, `namespace`); one without an object or namespace goes to the cluster list. `severity_level` 1–3 is an error, 4–6 a warning, 7–9 information. - **Prometheus alerts** that Deckhouse mirrors into `ClusterAlert` objects. An alert is attached by its labels (`deployment`, `statefulset`, `daemonset`, `pod`, `service`, `ingress`, `node`, `namespace`); one without an object or namespace goes to the cluster list. `severity_level` 1–3 is an error, 4–6 a warning, 7–9 information.
Information-level entries (a cordoned node, a single ordinary warning) are listed and never badge a card. Problems are recomputed on every map request and the open page refreshes them every minute. Information-level entries (a cordoned node, a single ordinary warning) are listed and never badge a card. Problems are recomputed on every map request and the open page refreshes them every minute.
## Vulnerabilities
With operator-trivy installed, a card whose images have CRITICAL CVEs shows a red shield with their number in the bottom-right corner. The details panel lists every CRITICAL and HIGH CVE of the workload's images: the packages it hits, the installed version and the version that fixes it, with a link to the advisory. A CVE counts once per card, however many packages and containers it is found in. Vulnerabilities are shown apart from problems: nearly every image has some, and a badge on each card would hide what is actually broken.
The data comes from the `VulnerabilityReport` objects operator-trivy writes, so only namespaces it scans appear (labelled `security-scanning.deckhouse.io/enabled`), and only the severities its `severities` setting keeps.
## Actions ## Actions
With `actions.enabled` (the default), the details panel offers: With `actions.enabled` (the default), the details panel offers:
@@ -75,7 +81,7 @@ History is kept in memory: after a pod restart the windows fill again. The statu
## Security ## Security
The web interface reads the cluster through the module's own service account (`d8:cluster-map` ClusterRole): `get`, `list`, `watch` on namespaces, pods, services, nodes, events, deployments, statefulsets, daemonsets, cronjobs, ingresses and Deckhouse `clusteralerts`, `get` and `list` on `metrics.k8s.io` pods and nodes, and `get` on `pods/log`. It never reads Secrets or ConfigMaps and has no write verbs. Changes go through [actions](#actions), which use the viewer's own identity. The web interface reads the cluster through the module's own service account (`d8:cluster-map` ClusterRole): `get`, `list`, `watch` on namespaces, pods, services, nodes, events, deployments, statefulsets, daemonsets, cronjobs, ingresses, Deckhouse `clusteralerts` and operator-trivy `vulnerabilityreports`, `get` and `list` on `metrics.k8s.io` pods and nodes, and `get` on `pods/log`. It never reads Secrets or ConfigMaps and has no write verbs. Changes go through [actions](#actions), which use the viewer's own identity.
This means **anyone admitted to the web interface sees every namespace and can read container logs**, whatever their own RBAC permissions are; what they can change is limited by their own RBAC. Restrict access with `auth.allowedUserGroups` (and optionally `auth.allowedUserEmails` and `auth.whitelistSourceRanges`). This means **anyone admitted to the web interface sees every namespace and can read container logs**, whatever their own RBAC permissions are; what they can change is limited by their own RBAC. Restrict access with `auth.allowedUserGroups` (and optionally `auth.allowedUserEmails` and `auth.whitelistSourceRanges`).
+8 -2
View File
@@ -26,11 +26,17 @@ Workload'ы под нестандартными контроллерами то
Карточка с проблемой несёт значок: жёлтый `!` — предупреждение, красный `!` — ошибка. Рамки и карточки namespace, рамки нод и дерево окрашиваются по самой серьёзной проблеме внутри. Источники: Карточка с проблемой несёт значок: жёлтый `!` — предупреждение, красный `!` — ошибка. Рамки и карточки namespace, рамки нод и дерево окрашиваются по самой серьёзной проблеме внутри. Источники:
- **Состояние объектов**: контейнеры в `CrashLoopBackOff`, `ImagePullBackOff` и подобном, недавние перезапуски и убийства за нехватку памяти, поды в ожидании или без места для запуска, workload'ы, у которых больше 2 минут не готовы все или часть реплик, застрявшая выкатка, CronJob с неудачным последним запуском, Service без готовых подов, Ingress на несуществующий Service, нода не готова или ей не хватает памяти, диска или PID. - **Состояние объектов**: контейнеры в `CrashLoopBackOff`, `ImagePullBackOff` и подобном, недавние перезапуски и убийства за нехватку памяти, поды в ожидании или без места для запуска, workload'ы, у которых больше 2 минут не готовы все или часть реплик, застрявшая выкатка, CronJob с неудачным последним запуском, Service без готовых подов, Ingress на несуществующий Service, нода не готова или ей не хватает памяти, диска или PID.
- **Warning-события** за последние 30 минут, сгруппированные по объекту и причине. Сбои планирования, томов и back-off дают значок сразу; любой другой причине нужно пять повторов, до этого она в списке без значка — одна проваленная проба во время рестарта не красит карту. - **Warning-события** за последние 30 минут, сгруппированные по объекту и причине. Сбои планирования, томов и back-off дают значок сразу; любой другой причине нужно пять повторов в пределах окна, до этого она в списке без значка — одна проваленная проба во время рестарта не красит карту. Счётчик события накапливается с первого появления, поэтому давнее событие пересчитывается на окно: 40 проваленных проб за двое суток — это раз в час, а не всплеск.
- **Алерты Prometheus**, которые Deckhouse зеркалирует в объекты `ClusterAlert`. Алерт привязывается по меткам (`deployment`, `statefulset`, `daemonset`, `pod`, `service`, `ingress`, `node`, `namespace`); алерт без объекта и namespace попадает в список кластера. `severity_level` 1–3 — ошибка, 4–6 — предупреждение, 7–9 — информация. - **Алерты Prometheus**, которые Deckhouse зеркалирует в объекты `ClusterAlert`. Алерт привязывается по меткам (`deployment`, `statefulset`, `daemonset`, `pod`, `service`, `ingress`, `node`, `namespace`); алерт без объекта и namespace попадает в список кластера. `severity_level` 1–3 — ошибка, 4–6 — предупреждение, 7–9 — информация.
Записи уровня «для сведения» (нода закрыта для новых подов, одиночное обычное предупреждение) есть в списке, но значка не дают. Проблемы пересчитываются при каждом запросе карты, открытая страница обновляет их раз в минуту. Записи уровня «для сведения» (нода закрыта для новых подов, одиночное обычное предупреждение) есть в списке, но значка не дают. Проблемы пересчитываются при каждом запросе карты, открытая страница обновляет их раз в минуту.
## Уязвимости
Если установлен operator-trivy, у карточки, в образах которой есть CVE уровня CRITICAL, в правом нижнем углу красный щит с их числом. В панели деталей — все CVE уровней CRITICAL и HIGH образов workload'а: какие пакеты затронуты, стоящая версия и версия с исправлением, ссылка на описание. Одна CVE считается на карточке один раз, в скольких бы пакетах и контейнерах она ни нашлась. Уязвимости показываются отдельно от проблем: они есть почти в каждом образе, и значок на каждой карточке скрыл бы то, что действительно сломано.
Данные берутся из объектов `VulnerabilityReport`, которые пишет operator-trivy, поэтому видны только namespace, которые он сканирует (с меткой `security-scanning.deckhouse.io/enabled`), и только уровни, оставленные его настройкой `severities`.
## Действия ## Действия
При `actions.enabled` (по умолчанию включено) в панели деталей есть: При `actions.enabled` (по умолчанию включено) в панели деталей есть:
@@ -75,7 +81,7 @@ Workload'ы под нестандартными контроллерами то
## Безопасность ## Безопасность
Веб-интерфейс читает кластер через собственную учётку модуля (ClusterRole `d8:cluster-map`): `get`, `list`, `watch` на namespaces, pods, services, nodes, events, deployments, statefulsets, daemonsets, cronjobs, ingresses и `clusteralerts` Deckhouse, `get` и `list` на pods и nodes из `metrics.k8s.io` и `get` на `pods/log`. Secret и ConfigMap он не читает, прав на запись нет. Изменения идут через [действия](#действия), которые выполняются от имени пользователя. Веб-интерфейс читает кластер через собственную учётку модуля (ClusterRole `d8:cluster-map`): `get`, `list`, `watch` на namespaces, pods, services, nodes, events, deployments, statefulsets, daemonsets, cronjobs, ingresses, `clusteralerts` Deckhouse и `vulnerabilityreports` operator-trivy, `get` и `list` на pods и nodes из `metrics.k8s.io` и `get` на `pods/log`. Secret и ConfigMap он не читает, прав на запись нет. Изменения идут через [действия](#действия), которые выполняются от имени пользователя.
Отсюда следует: **любой, кого пустили в веб-интерфейс, видит все namespace и может читать логи контейнеров** — независимо от собственных прав RBAC; изменить он может только то, что разрешает его RBAC. Ограничивайте доступ через `auth.allowedUserGroups` (а также `auth.allowedUserEmails` и `auth.whitelistSourceRanges`). Отсюда следует: **любой, кого пустили в веб-интерфейс, видит все namespace и может читать логи контейнеров** — независимо от собственных прав RBAC; изменить он может только то, что разрешает его RBAC. Ограничивайте доступ через `auth.allowedUserGroups` (а также `auth.allowedUserEmails` и `auth.whitelistSourceRanges`).
+66 -1
View File
@@ -46,6 +46,10 @@ import (
// firing Alertmanager alerts into. // firing Alertmanager alerts into.
var ClusterAlerts = schema.GroupVersionResource{Group: "deckhouse.io", Version: "v1alpha1", Resource: "clusteralerts"} var ClusterAlerts = schema.GroupVersionResource{Group: "deckhouse.io", Version: "v1alpha1", Resource: "clusteralerts"}
// VulnerabilityReports are what operator-trivy writes per scanned
// container (namespaced, owned by the workload's ReplicaSet/StatefulSet/…).
var VulnerabilityReports = schema.GroupVersionResource{Group: "aquasecurity.github.io", Version: "v1alpha1", Resource: "vulnerabilityreports"}
// Cache holds synced listers plus a client for reads that must be live // Cache holds synced listers plus a client for reads that must be live
// (YAML view, logs). // (YAML view, logs).
type Cache struct { type Cache struct {
@@ -56,6 +60,8 @@ type Cache struct {
// Alerts is nil when the ClusterAlert resource is not served (the // Alerts is nil when the ClusterAlert resource is not served (the
// prometheus module is off). // prometheus module is off).
Alerts cache.GenericLister Alerts cache.GenericLister
// VulnReports is nil when operator-trivy is not installed.
VulnReports cache.GenericLister
Namespaces corelisters.NamespaceLister Namespaces corelisters.NamespaceLister
Pods corelisters.PodLister Pods corelisters.PodLister
Services corelisters.ServiceLister Services corelisters.ServiceLister
@@ -100,12 +106,23 @@ func Start(ctx context.Context, client kubernetes.Interface, dyn dynamic.Interfa
Events: ef.Core().V1().Events().Lister(), Events: ef.Core().V1().Events().Lister(),
} }
var df dynamicinformer.DynamicSharedInformerFactory var df dynamicinformer.DynamicSharedInformerFactory
if dyn != nil && served(client, ClusterAlerts) { if dyn != nil {
df = dynamicinformer.NewDynamicSharedInformerFactory(dyn, 0) df = dynamicinformer.NewDynamicSharedInformerFactory(dyn, 0)
}
if df != nil && served(client, ClusterAlerts) {
c.Alerts = df.ForResource(ClusterAlerts).Lister() c.Alerts = df.ForResource(ClusterAlerts).Lister()
} else { } else {
slog.Info("ClusterAlert resource is not served; alerts are not shown") slog.Info("ClusterAlert resource is not served; alerts are not shown")
} }
if df != nil && served(client, VulnerabilityReports) {
inf := df.ForResource(VulnerabilityReports)
if err := inf.Informer().SetTransform(trimVulnReport); err != nil {
return nil, err
}
c.VulnReports = inf.Lister()
} else {
slog.Info("VulnerabilityReport resource is not served; vulnerabilities are not shown")
}
f.Start(ctx.Done()) f.Start(ctx.Done())
ef.Start(ctx.Done()) ef.Start(ctx.Done())
if df != nil { if df != nil {
@@ -149,6 +166,54 @@ func served(client kubernetes.Interface, gvr schema.GroupVersionResource) bool {
return false return false
} }
// vulnFields are the parts of a vulnerability entry the map shows; the
// rest (links, PURLs, dates) is dropped before caching.
var vulnFields = []string{"vulnerabilityID", "severity", "resource", "installedVersion", "fixedVersion", "title", "primaryLink", "score"}
func trimVulnReport(obj any) (any, error) {
u, ok := obj.(*unstructured.Unstructured)
if !ok {
return obj, nil
}
u.SetManagedFields(nil)
vulns, found, _ := unstructured.NestedSlice(u.Object, "report", "vulnerabilities")
if !found {
return u, nil
}
for i, v := range vulns {
m, ok := v.(map[string]any)
if !ok {
continue
}
kept := make(map[string]any, len(vulnFields))
for _, f := range vulnFields {
if x, ok := m[f]; ok {
kept[f] = x
}
}
vulns[i] = kept
}
return u, unstructured.SetNestedSlice(u.Object, vulns, "report", "vulnerabilities")
}
// VulnReportList returns the cached VulnerabilityReports, nil when off.
func (c *Cache) VulnReportList() []*unstructured.Unstructured {
if c.VulnReports == nil {
return nil
}
objs, err := c.VulnReports.List(labels.Everything())
if err != nil {
return nil
}
out := make([]*unstructured.Unstructured, 0, len(objs))
for _, o := range objs {
if u, ok := o.(*unstructured.Unstructured); ok {
out = append(out, u)
}
}
return out
}
// AlertList returns the cached ClusterAlerts, or nil when they are off. // AlertList returns the cached ClusterAlerts, or nil when they are off.
func (c *Cache) AlertList() []*unstructured.Unstructured { func (c *Cache) AlertList() []*unstructured.Unstructured {
if c.Alerts == nil { if c.Alerts == nil {
@@ -312,3 +312,22 @@ func isReady(p corev1.Pod) bool {
} }
return false return false
} }
// maxVulns bounds the details list; an old base image can carry hundreds.
const maxVulns = 300
// handleVulns lists the CRITICAL/HIGH findings of a card's images from the
// cached VulnerabilityReports.
func (s *Server) handleVulns(w http.ResponseWriter, r *http.Request) {
id := r.URL.Query().Get("id")
if !strings.HasPrefix(id, "wl/") {
http.Error(w, "id must be a workload (wl/...)", http.StatusBadRequest)
return
}
ns := strings.SplitN(id, "/", 3)[1]
pods, _ := kube.List[corev1.Pod](s.cache.Pods.Pods(ns))
writeJSON(w, map[string]any{
"available": s.cache.VulnReports != nil,
"vulns": topology.VulnsFor(s.cache.VulnReportList(), pods, id, maxVulns),
})
}
@@ -124,6 +124,7 @@ func (s *Server) Handler() http.Handler {
mux.Handle("GET /api/logs", s.api("logs", s.handleLogs)) mux.Handle("GET /api/logs", s.api("logs", s.handleLogs))
mux.Handle("GET /api/events", s.api("events", s.handleEvents)) mux.Handle("GET /api/events", s.api("events", s.handleEvents))
mux.Handle("GET /api/usage", s.api("usage", s.handleUsage)) mux.Handle("GET /api/usage", s.api("usage", s.handleUsage))
mux.Handle("GET /api/vulns", s.api("vulns", s.handleVulns))
mux.Handle("GET /api/me", s.api("me", s.handleMe)) mux.Handle("GET /api/me", s.api("me", s.handleMe))
mux.Handle("GET /api/permissions", s.api("permissions", s.handlePermissions)) mux.Handle("GET /api/permissions", s.api("permissions", s.handlePermissions))
mux.Handle("POST /api/action", s.api("action", s.handleAction)) mux.Handle("POST /api/action", s.api("action", s.handleAction))
@@ -42,6 +42,7 @@ type Node struct {
Parent string `json:"parent,omitempty"` Parent string `json:"parent,omitempty"`
Facts map[string]string `json:"facts,omitempty"` // short summary shown without a follow-up fetch Facts map[string]string `json:"facts,omitempty"` // short summary shown without a follow-up fetch
Problems []Problem `json:"problems,omitempty"` Problems []Problem `json:"problems,omitempty"`
Vulns *VulnSummary `json:"vulns,omitempty"`
} }
// Edge is a configuration or placement link between two nodes. // Edge is a configuration or placement link between two nodes.
@@ -62,6 +63,8 @@ type Graph struct {
// AlertsAvailable is false when ClusterAlerts are not served, so the UI // AlertsAvailable is false when ClusterAlerts are not served, so the UI
// can say that alerts are not part of the picture. // can say that alerts are not part of the picture.
AlertsAvailable bool `json:"alertsAvailable"` AlertsAvailable bool `json:"alertsAvailable"`
// VulnsAvailable is false when operator-trivy is not installed.
VulnsAvailable bool `json:"vulnsAvailable"`
} }
// WorkloadID is the graph ID of a workload. Traffic endpoints use the same // WorkloadID is the graph ID of a workload. Traffic endpoints use the same
@@ -179,6 +182,8 @@ func Build(c *kube.Cache, isSystem func(string) bool) (*Graph, error) {
services: services, ingresses: ingresses, nodes: hostNodes, events: events, alerts: c.AlertList(), services: services, ingresses: ingresses, nodes: hostNodes, events: events, alerts: c.AlertList(),
}) })
g.AlertsAvailable = c.Alerts != nil g.AlertsAvailable = c.Alerts != nil
attachVulns(g, c.VulnReportList(), pods)
g.VulnsAvailable = c.VulnReports != nil
sort.Slice(g.Nodes, func(i, j int) bool { return g.Nodes[i].ID < g.Nodes[j].ID }) sort.Slice(g.Nodes, func(i, j int) bool { return g.Nodes[i].ID < g.Nodes[j].ID })
sort.Slice(g.Edges, func(i, j int) bool { return g.Edges[i].ID < g.Edges[j].ID }) sort.Slice(g.Edges, func(i, j int) bool { return g.Edges[i].ID < g.Edges[j].ID })
@@ -148,8 +148,10 @@ func attachProblems(g *Graph, in problemInputs) {
cronJobProblems(s, cj) cronJobProblems(s, cj)
} }
for _, svc := range in.services { for _, svc := range in.services {
if !syntheticProbe(svc.Namespace, svc.Name) {
serviceProblems(s, svc, podsByNs[svc.Namespace]) serviceProblems(s, svc, podsByNs[svc.Namespace])
} }
}
services := map[string]bool{} services := map[string]bool{}
for _, svc := range in.services { for _, svc := range in.services {
services[svc.Namespace+"/"+svc.Name] = true services[svc.Namespace+"/"+svc.Name] = true
@@ -363,6 +365,28 @@ func EventTargetID(ref corev1.ObjectReference, podOwner map[string]string) strin
return "" return ""
} }
// eventsInWindow estimates how many occurrences of an event fell in the
// window. The event's count is cumulative since its first occurrence: 40
// probe failures over two days is one an hour, not 40 in half an hour, so
// a long-lived event is scaled by the part of its lifetime the window
// covers.
func eventsInWindow(e corev1.Event, last time.Time) int {
count := int(e.Count)
if e.Series != nil {
count = int(e.Series.Count)
}
count = max(count, 1)
first := e.FirstTimestamp.Time
if first.IsZero() {
first = e.EventTime.Time
}
span := last.Sub(first)
if first.IsZero() || span <= eventWindow {
return count
}
return max(1, int(float64(count)*float64(eventWindow)/float64(span)+0.5))
}
// eventProblems folds recent Warning events into one problem per card and // eventProblems folds recent Warning events into one problem per card and
// reason, keeping the latest message. // reason, keeping the latest message.
func eventProblems(s *problemSet, events []corev1.Event, podOwner map[string]string, live map[string]bool) { func eventProblems(s *problemSet, events []corev1.Event, podOwner map[string]string, live map[string]bool) {
@@ -376,11 +400,7 @@ func eventProblems(s *problemSet, events []corev1.Event, podOwner map[string]str
} }
id := EventTargetID(e.InvolvedObject, podOwner) id := EventTargetID(e.InvolvedObject, podOwner)
k := key{id, e.Reason} k := key{id, e.Reason}
count := int(e.Count) count := eventsInWindow(e, at)
if e.Series != nil {
count = int(e.Series.Count)
}
count = max(count, 1)
if p := folded[k]; p != nil { if p := folded[k]; p != nil {
p.Count += count p.Count += count
if stamp(at) > p.Since { if stamp(at) > p.Since {
@@ -455,8 +475,13 @@ func podsLive(pods []corev1.Pod) map[string]bool {
// lived StatefulSets and pods named upmeter-probe-* that are unschedulable // lived StatefulSets and pods named upmeter-probe-* that are unschedulable
// on purpose (it measures how fast the control plane reacts). Their // on purpose (it measures how fast the control plane reacts). Their
// FailedScheduling and NotReady are the probe working, not a problem. // FailedScheduling and NotReady are the probe working, not a problem.
//
// smoke-mini-a…e are upmeter's synthetic service: upmeter moves their pods
// between nodes on purpose, so the Service goes without endpoints and the
// pods restart as part of the test. upmeter reports that availability
// itself.
func syntheticProbe(ns, name string) bool { func syntheticProbe(ns, name string) bool {
return ns == "d8-upmeter" && strings.HasPrefix(name, "upmeter-probe-") return ns == "d8-upmeter" && (strings.HasPrefix(name, "upmeter-probe-") || strings.HasPrefix(name, "smoke-mini-"))
} }
// notReadyFrom is when a running or pending pod stopped being ready (or // notReadyFrom is when a running or pending pod stopped being ready (or
@@ -199,6 +199,36 @@ func TestRedirectIngressAndGonePods(t *testing.T) {
} }
} }
func TestEventRateAndSmokeMini(t *testing.T) {
withNow(t)
g := &Graph{Nodes: []Node{{ID: "ns/shop"}, {ID: "ns/d8-upmeter"}, {ID: "wl/shop/deployment/auth"}, {ID: "wl/shop/deployment/burst"}, {ID: "service/d8-upmeter/smoke-mini-a"}}}
attachProblems(g, problemInputs{
pods: []corev1.Pod{
{ObjectMeta: metav1.ObjectMeta{Name: "auth-5f-a", Namespace: "shop", OwnerReferences: owned("ReplicaSet", "auth-5f")}},
{ObjectMeta: metav1.ObjectMeta{Name: "burst-5f-a", Namespace: "shop", OwnerReferences: owned("ReplicaSet", "burst-5f")}},
},
services: []corev1.Service{{ObjectMeta: metav1.ObjectMeta{Name: "smoke-mini-a", Namespace: "d8-upmeter"}, Spec: corev1.ServiceSpec{Selector: map[string]string{"smoke-mini": "a"}}}},
events: []corev1.Event{
// 40 over two days: about one an hour
{Type: corev1.EventTypeWarning, Reason: "Unhealthy", Count: 40, FirstTimestamp: metav1.NewTime(t0.Add(-48 * time.Hour)), LastTimestamp: metav1.NewTime(t0.Add(-time.Minute)),
InvolvedObject: corev1.ObjectReference{Kind: "Pod", Namespace: "shop", Name: "auth-5f-a"}},
// 12 within ten minutes
{Type: corev1.EventTypeWarning, Reason: "Unhealthy", Count: 12, FirstTimestamp: metav1.NewTime(t0.Add(-10 * time.Minute)), LastTimestamp: metav1.NewTime(t0.Add(-time.Minute)),
InvolvedObject: corev1.ObjectReference{Kind: "Pod", Namespace: "shop", Name: "burst-5f-a"}},
{Type: corev1.EventTypeWarning, Reason: "FailedMount", LastTimestamp: metav1.NewTime(t0), InvolvedObject: corev1.ObjectReference{Kind: "Pod", Namespace: "d8-upmeter", Name: "smoke-mini-c-0"}},
},
})
if p := problemsOf(g, "wl/shop/deployment/auth")["Unhealthy"]; p.Severity != Info || p.Count > 2 {
t.Errorf("a slow trickle over two days must be information: %+v", p)
}
if p := problemsOf(g, "wl/shop/deployment/burst")["Unhealthy"]; p.Severity != Warning || p.Count != 12 {
t.Errorf("a burst inside the window must badge: %+v", p)
}
if len(problemsOf(g, "service/d8-upmeter/smoke-mini-a"))+len(problemsOf(g, "ns/d8-upmeter")) != 0 {
t.Error("upmeter's smoke-mini reported as a problem")
}
}
func alert(name, level string, labels map[string]string) *unstructured.Unstructured { func alert(name, level string, labels map[string]string) *unstructured.Unstructured {
l := map[string]any{} l := map[string]any{}
for k, v := range labels { for k, v := range labels {
@@ -0,0 +1,203 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package topology
import (
"sort"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
// VulnSummary is what a card shows about its images: counts of distinct
// CRITICAL and HIGH CVEs (operator-trivy keeps only those here) and how
// many of them a newer package version fixes. One CVE in six subpackages
// of openssh is one CVE.
type VulnSummary struct {
Critical int `json:"critical"`
High int `json:"high"`
FixableCritical int `json:"fixableCritical"`
Fixable int `json:"fixable"`
}
// Vuln is one finding in the details list.
type Vuln struct {
ID string `json:"id"`
Severity string `json:"severity"`
Package string `json:"package"` // comma-separated when the CVE hits several packages of one image
Installed string `json:"installed"`
Fixed string `json:"fixed,omitempty"`
Title string `json:"title,omitempty"`
Link string `json:"link,omitempty"`
Score float64 `json:"score,omitempty"`
Image string `json:"image"`
Container string `json:"container"`
}
// vulnTargetID maps a report to its card the way events are mapped: the
// report is labelled with the scanned object (a ReplicaSet, StatefulSet,
// CronJob, Job or bare Pod).
func vulnTargetID(r *unstructured.Unstructured, podOwner map[string]string) string {
l := r.GetLabels()
ref := corev1.ObjectReference{
Kind: l["trivy-operator.resource.kind"],
Name: l["trivy-operator.resource.name"],
Namespace: l["trivy-operator.resource.namespace"],
}
if ref.Namespace == "" {
ref.Namespace = r.GetNamespace()
}
return EventTargetID(ref, podOwner)
}
func reportImage(r *unstructured.Unstructured) string {
server, _, _ := unstructured.NestedString(r.Object, "report", "registry", "server")
repo, _, _ := unstructured.NestedString(r.Object, "report", "artifact", "repository")
tag, _, _ := unstructured.NestedString(r.Object, "report", "artifact", "tag")
img := repo
if server != "" {
img = server + "/" + repo
}
if tag != "" {
img += ":" + tag
}
return img
}
func reportVulns(r *unstructured.Unstructured) []Vuln {
raw, _, _ := unstructured.NestedSlice(r.Object, "report", "vulnerabilities")
image, container := reportImage(r), r.GetLabels()["trivy-operator.container.name"]
out := make([]Vuln, 0, len(raw))
for _, x := range raw {
m, ok := x.(map[string]any)
if !ok {
continue
}
str := func(k string) string { s, _ := m[k].(string); return s }
score, _ := m["score"].(float64)
out = append(out, Vuln{
ID: str("vulnerabilityID"), Severity: str("severity"), Package: str("resource"),
Installed: str("installedVersion"), Fixed: str("fixedVersion"), Title: str("title"),
Link: str("primaryLink"), Score: score, Image: image, Container: container,
})
}
return out
}
func podOwners(pods []corev1.Pod) map[string]string {
out := make(map[string]string, len(pods))
for _, p := range pods {
out[p.Namespace+"/"+p.Name] = OwnerWorkloadID(p)
}
return out
}
// attachVulns fills Node.Vulns. A CVE counts once per card, whatever the
// number of packages and containers it is found in.
func attachVulns(g *Graph, reports []*unstructured.Unstructured, pods []corev1.Pod) {
if len(reports) == 0 {
return
}
owners := podOwners(pods)
seen := map[string]map[string]bool{}
sums := map[string]*VulnSummary{}
for _, r := range reports {
card := vulnTargetID(r, owners)
if card == "" {
continue
}
if seen[card] == nil {
seen[card], sums[card] = map[string]bool{}, &VulnSummary{}
}
for _, v := range reportVulns(r) {
if seen[card][v.ID] {
continue
}
seen[card][v.ID] = true
s := sums[card]
switch v.Severity {
case "CRITICAL":
s.Critical++
if v.Fixed != "" {
s.FixableCritical++
}
case "HIGH":
s.High++
default:
continue
}
if v.Fixed != "" {
s.Fixable++
}
}
}
for i := range g.Nodes {
if s, ok := sums[g.Nodes[i].ID]; ok && (s.Critical > 0 || s.High > 0) {
g.Nodes[i].Vulns = s
}
}
}
var severityOrder = map[string]int{"CRITICAL": 0, "HIGH": 1, "MEDIUM": 2, "LOW": 3}
// VulnsFor lists the findings of one card, most severe first, fixable
// before unfixable, one entry per CVE and image with its packages joined.
func VulnsFor(reports []*unstructured.Unstructured, pods []corev1.Pod, cardID string, limit int) []Vuln {
owners := podOwners(pods)
type key struct{ id, image string }
at := map[key]int{}
pkgs := map[key]map[string]bool{}
out := []Vuln{}
for _, r := range reports {
if vulnTargetID(r, owners) != cardID {
continue
}
for _, v := range reportVulns(r) {
k := key{v.ID, v.Image}
i, ok := at[k]
if !ok {
at[k], pkgs[k] = len(out), map[string]bool{v.Package: true}
out = append(out, v)
continue
}
if !pkgs[k][v.Package] {
pkgs[k][v.Package] = true
out[i].Package += ", " + v.Package
}
if out[i].Fixed == "" {
out[i].Fixed = v.Fixed
}
}
}
sort.SliceStable(out, func(i, j int) bool {
a, b := out[i], out[j]
if severityOrder[a.Severity] != severityOrder[b.Severity] {
return severityOrder[a.Severity] < severityOrder[b.Severity]
}
if (a.Fixed != "") != (b.Fixed != "") {
return a.Fixed != ""
}
if a.Score != b.Score {
return a.Score > b.Score
}
return a.ID < b.ID
})
if limit > 0 && len(out) > limit {
out = out[:limit]
}
return out
}
@@ -0,0 +1,73 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package topology
import (
"testing"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
func vulnReport(ns, kind, name, container, repo string, vulns ...map[string]any) *unstructured.Unstructured {
list := make([]any, len(vulns))
for i, v := range vulns {
list[i] = v
}
u := &unstructured.Unstructured{Object: map[string]any{
"report": map[string]any{
"registry": map[string]any{"server": "ghcr.io"},
"artifact": map[string]any{"repository": repo, "tag": "1.0"},
"vulnerabilities": list,
},
}}
u.SetNamespace(ns)
u.SetLabels(map[string]string{"trivy-operator.resource.kind": kind, "trivy-operator.resource.name": name, "trivy-operator.resource.namespace": ns, "trivy-operator.container.name": container})
return u
}
func cve(id, sev, pkg, fixed string, score float64) map[string]any {
return map[string]any{"vulnerabilityID": id, "severity": sev, "resource": pkg, "installedVersion": "1.0", "fixedVersion": fixed, "score": score}
}
func TestVulns(t *testing.T) {
g := &Graph{Nodes: []Node{{ID: "wl/shop/deployment/web"}, {ID: "wl/shop/cronjob/backup"}, {ID: "wl/shop/deployment/clean"}}}
reports := []*unstructured.Unstructured{
vulnReport("shop", "ReplicaSet", "web-5f", "app", "acme/web",
cve("CVE-1", "CRITICAL", "openssl", "3.0.2", 9.8), cve("CVE-1", "CRITICAL", "libssl3", "3.0.2", 9.8),
cve("CVE-2", "CRITICAL", "zlib", "", 9.1), cve("CVE-3", "HIGH", "curl", "8.1", 7.5)),
// the sidecar on the same base image repeats CVE-1: counted once
vulnReport("shop", "ReplicaSet", "web-5f", "sidecar", "acme/web-sidecar", cve("CVE-1", "CRITICAL", "openssl", "3.0.2", 9.8)),
vulnReport("shop", "Job", "backup-29100000", "dump", "library/alpine", cve("CVE-4", "HIGH", "busybox", "1.37", 7.0)),
}
attachVulns(g, reports, nil)
web := g.Nodes[0].Vulns
if web == nil || web.Critical != 2 || web.High != 1 || web.FixableCritical != 1 || web.Fixable != 2 {
t.Errorf("web summary: %+v", web)
}
if b := g.Nodes[1].Vulns; b == nil || b.High != 1 {
t.Errorf("a CronJob's job report attaches to the CronJob: %+v", b)
}
if g.Nodes[2].Vulns != nil {
t.Error("a card without reports carries no summary")
}
list := VulnsFor(reports, []corev1.Pod{{ObjectMeta: metav1.ObjectMeta{Name: "x"}}}, "wl/shop/deployment/web", 0)
if len(list) != 4 || list[0].ID != "CVE-1" || list[0].Package != "openssl, libssl3" || list[0].Image != "ghcr.io/acme/web:1.0" || list[2].ID != "CVE-2" || list[3].Severity != "HIGH" {
t.Errorf("order (critical fixable, critical fixable sidecar, critical unfixable, high): %+v", list)
}
}
@@ -282,6 +282,14 @@ table.pods th { text-align: left; color: var(--muted); font-weight: 500; padding
table.pods td { padding: 0.3rem; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; } table.pods td { padding: 0.3rem; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
table.pods .warn-text { color: var(--warn); font-weight: 600; } table.pods .warn-text { color: var(--warn); font-weight: 600; }
/* vulnerabilities */
.vuln-crit { color: var(--error); font-weight: 600; }
.sev-chip { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 3px; font-size: 0.6rem; font-weight: 800; color: #fff; }
.sev-chip.critical { background: var(--error); }
.sev-chip.high { background: var(--warn); }
table.vulns a { color: var(--accent); }
.shield-legend { display: inline-block; width: 10px; height: 12px; background: var(--error); clip-path: polygon(50% 0, 100% 15%, 100% 50%, 50% 100%, 0 50%, 0 15%); }
/* events */ /* events */
.event-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; } .event-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.event-list li { border-left: 3px solid var(--line); padding: 0.1rem 0 0.1rem 0.5rem; } .event-list li { border-left: 3px solid var(--line); padding: 0.1rem 0 0.1rem 0.5rem; }
+50 -6
View File
@@ -83,12 +83,12 @@ function fitText(text, font, max) {
return text.slice(0, lo) + '…'; return text.slice(0, lo) + '…';
} }
const imgCache = new Map(); const imgCache = new Map();
function cardImage({ kind, title, sub, health, ghost, w, h, badge }) { function cardImage({ kind, title, sub, health, ghost, w, h, badge, shield }) {
const key = [kind, title, sub, health, ghost, w, h, badge].join('|'); const key = [kind, title, sub, health, ghost, w, h, badge, shield].join('|');
if (imgCache.has(key)) return imgCache.get(key); if (imgCache.has(key)) return imgCache.get(key);
const c = (KIND[kind] || KIND.external).color; const c = (KIND[kind] || KIND.external).color;
const name = fitText(title, `600 12.5px ${FONT}`, w - (badge ? 74 : 58)); const name = fitText(title, `600 12.5px ${FONT}`, w - (badge ? 74 : 58));
const line2 = sub ? fitText(sub, `11px ${FONT}`, w - 50) : ''; const line2 = sub ? fitText(sub, `11px ${FONT}`, w - (shield ? 78 : 50)) : '';
const nameY = sub ? h / 2 - 3 : h / 2 + 4.5; const nameY = sub ? h / 2 - 3 : h / 2 + 4.5;
const dot = health ? `<circle cx="${w - 12}" cy="12" r="4" fill="${T[health]}"/>` : ''; const dot = health ? `<circle cx="${w - 12}" cy="12" r="4" fill="${T[health]}"/>` : '';
// "!" in a circle left of the health dot: yellow warning, red critical // "!" in a circle left of the health dot: yellow warning, red critical
@@ -103,12 +103,22 @@ function cardImage({ kind, title, sub, health, ghost, w, h, badge }) {
<g transform="translate(13 ${h / 2 - 10})" fill="none" stroke="${c}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">${ICON[kind] || ''}</g> <g transform="translate(13 ${h / 2 - 10})" fill="none" stroke="${c}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">${ICON[kind] || ''}</g>
<text x="41" y="${nameY}" font-family="${FONT}" font-size="12.5" font-weight="600" fill="${ghost ? T.muted : T.text}">${esc(name)}</text> <text x="41" y="${nameY}" font-family="${FONT}" font-size="12.5" font-weight="600" fill="${ghost ? T.muted : T.text}">${esc(name)}</text>
${sub ? `<text x="41" y="${h / 2 + 12}" font-family="${FONT}" font-size="11" fill="${T.muted}">${esc(line2)}</text>` : ''} ${sub ? `<text x="41" y="${h / 2 + 12}" font-family="${FONT}" font-size="11" fill="${T.muted}">${esc(line2)}</text>` : ''}
${dot}${mark}</svg>`; ${dot}${mark}${shieldMark(shield, w, h)}</svg>`;
const url = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg); const url = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
imgCache.set(key, url); imgCache.set(key, url);
return url; return url;
} }
// Shield in the bottom-right corner: critical CVEs in the card's images
// (operator-trivy). Kept apart from the problem badge: nearly every image
// has some, and they would drown the "is it working" signal.
function shieldMark(n, w, h) {
if (!n) return '';
const x = w - 30, y = h - 17, label = n > 99 ? '99+' : String(n);
return `<g transform="translate(${x} ${y})"><path d="M5 0.5 L9.5 2 V5.5 C9.5 8.3 7.6 10.2 5 11.2 C2.4 10.2 0.5 8.3 0.5 5.5 V2 Z" fill="${T.error}" opacity="0.9"/></g>
<text x="${x + 12}" y="${y + 9.5}" font-family="${FONT}" font-size="10" font-weight="700" fill="${T.error}">${label}</text>`;
}
/* ---------- data ---------- */ /* ---------- data ---------- */
const G = { const G = {
raw: null, byId: new Map(), byNs: new Map(), nsNodes: [], hostNodes: [], raw: null, byId: new Map(), byNs: new Map(), nsNodes: [], hostNodes: [],
@@ -530,7 +540,7 @@ function cardNode(n, parent, ghost) {
group: 'nodes', classes: ghost ? 'ghostcard' : '', group: 'nodes', classes: ghost ? 'ghostcard' : '',
data: { data: {
id: n.id, ref: n.id, parent, kind: n.kind, w: size.w, h: size.h, id: n.id, ref: n.id, parent, kind: n.kind, w: size.w, h: size.h,
img: cardImage({ kind: n.kind, title: n.label, sub: ghost ? n.namespace + ' · ' + KIND[n.kind].title : subline(n), health: ghost ? null : n.facts?.health, ghost, w: size.w, h: size.h, badge: cardSev(n) }), img: cardImage({ kind: n.kind, title: n.label, sub: ghost ? n.namespace + ' · ' + KIND[n.kind].title : subline(n), health: ghost ? null : n.facts?.health, ghost, w: size.w, h: size.h, badge: cardSev(n), shield: ghost ? 0 : n.vulns?.critical }),
}, },
}; };
} }
@@ -1029,7 +1039,9 @@ function renderLegend() {
); );
} }
function badgeLegend() { function badgeLegend() {
return ['warning', 'critical'].map((sev) => el('span', {}, el('span', { class: 'pbadge ' + sev, 'aria-hidden': 'true' }, '!'), t('legend.' + sev))); const items = ['warning', 'critical'].map((sev) => el('span', {}, el('span', { class: 'pbadge ' + sev, 'aria-hidden': 'true' }, '!'), t('legend.' + sev)));
if (G.raw?.vulnsAvailable) items.push(el('span', {}, el('span', { class: 'shield-legend', 'aria-hidden': 'true' }), t('legend.vulns')));
return items;
} }
/* ---------- details panel ---------- */ /* ---------- details panel ---------- */
@@ -1152,6 +1164,7 @@ function renderOverview(n) {
} }
parts.push(dl); parts.push(dl);
if (hasPods(n) || n.kind === 'node') parts.push(el('div', { class: 'section-title' }, t('usage.title')), el('div', { id: 'd-usage' }, el('p', { class: 'muted small' }, t('loading')))); if (hasPods(n) || n.kind === 'node') parts.push(el('div', { class: 'section-title' }, t('usage.title')), el('div', { id: 'd-usage' }, el('p', { class: 'muted small' }, t('loading'))));
if (n.id.startsWith('wl/') && G.raw?.vulnsAvailable) parts.push(el('div', { class: 'section-title' }, t('vulns.title')), el('div', { id: 'd-vulns' }, vulnSummary(n)));
const hosts = [...(G.placement.get(id) || [])].sort(); const hosts = [...(G.placement.get(id) || [])].sort();
if (hosts.length) { if (hosts.length) {
parts.push(el('div', { class: 'section-title' }, t('details.runsOn')), parts.push(el('div', { class: 'section-title' }, t('details.runsOn')),
@@ -1160,6 +1173,7 @@ function renderOverview(n) {
} }
panel.replaceChildren(...parts); panel.replaceChildren(...parts);
if (hasPods(n) || n.kind === 'node') loadUsage(n); if (hasPods(n) || n.kind === 'node') loadUsage(n);
if (n.vulns && G.raw?.vulnsAvailable) loadVulns(n);
} }
/* ---------- usage ---------- */ /* ---------- usage ---------- */
@@ -1211,6 +1225,36 @@ async function loadUsage(n) {
if (detailsId === n.id) box.replaceChildren(...parts); if (detailsId === n.id) box.replaceChildren(...parts);
} }
/* ---------- vulnerabilities ---------- */
function vulnSummary(n) {
const v = n.vulns;
if (!v) return el('p', { class: 'muted small' }, t('vulns.none'));
return el('p', { class: 'small' },
el('span', { class: v.critical ? 'vuln-crit' : '' }, t('plural.critical_cve', { n: v.critical })), ', ',
t('plural.high_cve', { n: v.high }), ' · ', t('vulns.fixable', { n: v.fixable }));
}
async function loadVulns(n) {
const r = await fetch('/api/vulns?' + new URLSearchParams({ id: n.id }));
const box = $('#d-vulns');
if (detailsId !== n.id || !box) return;
if (!r.ok) { box.append(el('p', { class: 'muted small' }, t('vulns.failed', { code: r.status }))); return; }
const { vulns } = await r.json();
if (!vulns.length) return;
const shown = vulns.slice(0, 40);
const table = el('table', { class: 'pods vulns' },
el('thead', {}, el('tr', {}, ...[t('vulns.cve'), t('vulns.package'), t('vulns.version')].map((x) => el('th', {}, x)))),
el('tbody', {}, shown.map((v) => el('tr', {},
el('td', {}, el('span', { class: 'sev-chip ' + v.severity.toLowerCase() }, v.severity === 'CRITICAL' ? 'C' : 'H'), ' ',
v.link ? el('a', { href: v.link, target: '_blank', rel: 'noopener noreferrer', title: v.title || '' }, v.id) : v.id),
el('td', {}, v.package, el('div', { class: 'muted small' }, shortImage(v.image))),
el('td', {}, v.installed, ' → ', v.fixed ? el('strong', {}, v.fixed) : el('span', { class: 'muted' }, t('vulns.noFix')))))));
const parts = [table];
if (vulns.length > shown.length) parts.push(el('p', { class: 'muted small' }, t('vulns.more', { n: vulns.length - shown.length })));
box.append(...parts);
}
// drop the registry host (a first segment with a dot) and any digest
const shortImage = (img) => img.replace(/^[^/]*\.[^/]*\//, '').replace(/@sha256:.*/, '');
/* ---------- events ---------- */ /* ---------- events ---------- */
async function loadEvents(id) { async function loadEvents(id) {
const panel = document.querySelector('[data-panel="events"]'); const panel = document.querySelector('[data-panel="events"]');
+14
View File
@@ -110,6 +110,13 @@ const I18N = {
'confirm.cordon': 'No new pods are scheduled on {target}. Running pods stay.', 'confirm.cordon': 'No new pods are scheduled on {target}. Running pods stay.',
'confirm.uncordon': 'New pods can be scheduled on {target} again.', 'confirm.uncordon': 'New pods can be scheduled on {target} again.',
'confirm.delete-pod': 'Pod {target} in {ns} is deleted; its controller starts a new one.', 'confirm.delete-pod': 'Pod {target} in {ns} is deleted; its controller starts a new one.',
'vulns.title': 'Vulnerabilities', 'vulns.none': 'No CRITICAL or HIGH vulnerabilities found in the scanned images.',
'vulns.fixable': 'fixed in a newer version: {n}', 'vulns.failed': 'could not read vulnerabilities: HTTP {code}',
'vulns.cve': 'CVE', 'vulns.package': 'Package', 'vulns.version': 'Installed → fixed', 'vulns.noFix': 'no fix yet',
'vulns.more': 'and {n} more',
'plural.critical_cve': { one: '{n} critical', other: '{n} critical' },
'plural.high_cve': { one: '{n} high', other: '{n} high' },
'legend.vulns': 'critical vulnerabilities in the images (trivy)',
}, },
ru: { ru: {
'kind.pod': 'Контроллер', 'kind.external': 'Внешний', 'folder.pod': 'Другие контроллеры', 'kind.pod': 'Контроллер', 'kind.external': 'Внешний', 'folder.pod': 'Другие контроллеры',
@@ -217,6 +224,13 @@ const I18N = {
'confirm.cordon': 'На {target} не будут назначаться новые поды. Работающие остаются.', 'confirm.cordon': 'На {target} не будут назначаться новые поды. Работающие остаются.',
'confirm.uncordon': 'На {target} снова можно назначать новые поды.', 'confirm.uncordon': 'На {target} снова можно назначать новые поды.',
'confirm.delete-pod': 'Под {target} в {ns} удаляется; контроллер запустит новый.', 'confirm.delete-pod': 'Под {target} в {ns} удаляется; контроллер запустит новый.',
'vulns.title': 'Уязвимости', 'vulns.none': 'В проверенных образах нет уязвимостей уровня CRITICAL и HIGH.',
'vulns.fixable': 'исправлено в новой версии: {n}', 'vulns.failed': 'не удалось получить уязвимости: HTTP {code}',
'vulns.cve': 'CVE', 'vulns.package': 'Пакет', 'vulns.version': 'Стоит → исправлено', 'vulns.noFix': 'исправления нет',
'vulns.more': 'и ещё {n}',
'plural.critical_cve': { one: '{n} критическая', few: '{n} критические', many: '{n} критических', other: '{n} критической' },
'plural.high_cve': { one: '{n} высокая', few: '{n} высокие', many: '{n} высоких', other: '{n} высокой' },
'legend.vulns': 'критические уязвимости в образах (trivy)',
}, },
}; };
+6 -2
View File
@@ -9,8 +9,9 @@ automountServiceAccountToken: true
--- ---
# Read-only on exactly what the map shows. No Secrets, no ConfigMaps, no # Read-only on exactly what the map shows. No Secrets, no ConfigMaps, no
# write verbs. pods/log backs the Logs tab, events and clusteralerts the # write verbs. pods/log backs the Logs tab, events and clusteralerts the
# problem badges, metrics.k8s.io the Load section. Actions (restart, scale…) # problem badges, vulnerabilityreports (operator-trivy) the shield on
# never use this account: they run with the viewer's own token. # cards, metrics.k8s.io the Load section. Actions (restart, scale…) never
# use this account: they run with the viewer's own token.
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole kind: ClusterRole
metadata: metadata:
@@ -29,6 +30,9 @@ rules:
- apiGroups: ["deckhouse.io"] - apiGroups: ["deckhouse.io"]
resources: ["clusteralerts"] resources: ["clusteralerts"]
verbs: ["get", "list", "watch"] verbs: ["get", "list", "watch"]
- apiGroups: ["aquasecurity.github.io"]
resources: ["vulnerabilityreports"]
verbs: ["get", "list", "watch"]
- apiGroups: ["metrics.k8s.io"] - apiGroups: ["metrics.k8s.io"]
resources: ["pods", "nodes"] resources: ["pods", "nodes"]
verbs: ["get", "list"] verbs: ["get", "list"]