diff --git a/README.ko.md b/README.ko.md index ff29a50..6f3e29b 100644 --- a/README.ko.md +++ b/README.ko.md @@ -1,4 +1,4 @@ - + # vmsctl [![CI](https://github.com/with-developer/vmsctl/actions/workflows/ci.yml/badge.svg)](https://github.com/with-developer/vmsctl/actions/workflows/ci.yml) @@ -70,7 +70,8 @@ vmsctl server demo # 가상의 호스트 12대로 둘러보기. 실제로 ``` - **통과율이 시간에 따라 어떻게 달라졌는지** 7일·30일·90일 차트로 보고, 호스트마다 최근 추이도 봅니다. -- **가장 많은 호스트에서 실패하는 점검 항목과 방금 나빠진 점검 항목**을 바로 확인합니다. +- **먼저 고칠 것:** 실패한 점검 항목을 심각도와 실패한 호스트 수로 정렬하고, 고치면 통과율이 얼마나 오르는지 보여 줍니다. + 최근 악화되거나 해결된 점검 항목과 보고가 끊긴 호스트도 한 목록으로 봅니다. - **모든 결과에 근거**(파일과 줄)가 붙고, 실패한 항목 옆에 **조치 방법**이 나옵니다. - **모든 호스트 × 모든 점검 항목 매트릭스.** 칸을 누르면 그 호스트로 이동합니다. - 프로파일(KISA, essentials, 직접 만든 정책 팩)을 **한 번에 하나씩** 골라 봅니다. 목록에는 호스트의 OS와 라벨이 보입니다. diff --git a/README.md b/README.md index 6732b6c..4e99a79 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,8 @@ vmsctl server demo # a made-up fleet of twelve hosts, nothing scanned, noth ``` - **Pass rate over time** for the whole fleet (7, 30 or 90 days), and a trend line on every host. -- **What fails most, and what just got worse:** the controls that fail on most hosts, and the regressions of the last scans. +- **What to fix first:** the failing controls ranked by severity and the hosts that fail them, each with what fixing it adds to the + pass rate; and what just changed (controls that got worse or were fixed, hosts that stopped reporting). - **The evidence behind every result,** the file and the line, with **how to fix it** next to each failure. - **A matrix of every control on every host,** one click from a cell to the host. - **One profile at a time** (KISA, essentials, your own policy pack), with host OS and labels in the list. diff --git a/docs/demo/dashboard-overview.png b/docs/demo/dashboard-overview.png index e67c851..cea8846 100644 Binary files a/docs/demo/dashboard-overview.png and b/docs/demo/dashboard-overview.png differ diff --git a/docs/fleet.ko.md b/docs/fleet.ko.md index a97ee08..74d4c5c 100644 --- a/docs/fleet.ko.md +++ b/docs/fleet.ko.md @@ -1,4 +1,4 @@ - + # 서버로 모아 보기 > 설계는 [ADR 0010](adr/0010-fleet-server-and-dashboard.md)에 있습니다. 호스트가 결과를 보내고, 서버가 저장해 두었다가 조회 @@ -297,7 +297,7 @@ curl --cacert tls.crt -H "Authorization: Bearer hlt_api_..." https://vmsctl.exam |---|---| | `GET /api/v1/profiles` | 최신 스캔에 쓰인 프로파일과 프로파일별 호스트 수, 가장 많은 호스트가 쓰는 프로파일(`default`), 각 프로파일의 제목 | | `GET /api/v1/trend` | 전체 호스트의 최근 추이를 하루에 한 점씩, 오래된 날부터: 호스트 수, 실패한 점검 항목이 있는 호스트 수, 그날 기준의 상태별 개수와 통과율(`?days=30`, 1~90). 저장된 스캔으로 계산하므로 `server prune`을 하면 볼 수 있는 날짜가 달라지고, 같은 답을 30초 동안 재사용합니다 | -| `GET /api/v1/overview` | 호스트 수, 실패한 점검 항목이 있는 호스트 수, 오래 보고하지 않은 호스트 수, 상태별 개수, 가장 많은 호스트에서 실패하는 점검 항목, 최근 악화(`?staleDays=7`) | +| `GET /api/v1/overview` | 호스트 수, 실패한 점검 항목이 있는 호스트 수, 오래 보고하지 않은 호스트 수, 상태별 개수, 심각도와 호스트 수로 정렬한 실패 점검 항목(각각 고치면 오르는 통과율 `gain`, %p 단위), 최근 악화와 최근 해결(`?staleDays=7`) | | `GET /api/v1/hosts` | 호스트 목록과 각 호스트의 최신 스캔 개수·통과율(`?q=`, `?status=failing\|stale`, `?sort=name\|score\|last`, `?limit=`, `?offset=`, `?format=csv`, 이미지를 보려면 `?kind=image`, 레이블이 있는 호스트만 보려면 `?label=env%3Dprod`. 대시보드에서는 레이블을 눌러 거릅니다). 호스트마다 `os`, `labels`(최신 결과가 알려 준 값이고 개수에 상한이 있습니다), `agentOnline`, 최근 스캔의 통과율 `trend`도 들어 있습니다 | | `GET /api/v1/controls`, `GET /api/v1/controls/PROFILE/ID` | 점검 항목 전체와 최신 스캔의 상태별 개수. 점검 항목 하나의 경우 해당 호스트, 무엇을 점검하는지, 어떻게 고치는지 | | `GET /api/v1/matrix` | 모든 호스트의 모든 점검 항목의 최신 상태. 가장 많이 실패한 호스트가 먼저 나옵니다. `?format=csv`를 붙이면 스프레드시트용 표(호스트마다 한 행, 점검 항목마다 한 열, `?lang=ko`로 열 제목을 한국어로)로 받으며, 대시보드의 매트릭스 화면에서 내려받을 수 있습니다 | diff --git a/docs/fleet.md b/docs/fleet.md index 0d38535..d04f3fe 100644 --- a/docs/fleet.md +++ b/docs/fleet.md @@ -265,7 +265,7 @@ curl --cacert tls.crt -H "Authorization: Bearer hlt_api_..." https://vmsctl.exam |---|---| | `GET /api/v1/profiles` | The profiles of the latest scans with the number of hosts of each, the one most hosts use (`default`), and their titles | | `GET /api/v1/trend` | The fleet over the last days, one point a day, oldest first: hosts, hosts with a failing control, counts and pass rate as of that day (`?days=30`, 1 to 90). It is computed from the scans that are stored, so `server prune` changes the days it covers, and is served again for 30 seconds | -| `GET /api/v1/overview` | Hosts, hosts with a failing control, stale hosts, counts, the controls that fail on most hosts, recent regressions (`?staleDays=7`) | +| `GET /api/v1/overview` | Hosts, hosts with a failing control, stale hosts, counts, the failing controls ranked by severity times hosts with the `gain` in pass rate (percentage points) of fixing each, recent regressions and recent fixes (`?staleDays=7`) | | `GET /api/v1/hosts` | The hosts with the counts and score of their latest scan (`?q=`, `?status=failing\|stale`, `?sort=name\|score\|last`, `?limit=`, `?offset=`, `?format=csv`, `?kind=image` for the images, `?label=env%3Dprod` for the hosts with a label; the dashboard filters by a clicked label); each host also has its `os`, `labels` (what its latest result says, bounded), `agentOnline` and a `trend` of the pass rate of its latest scans | | `GET /api/v1/controls`, `GET /api/v1/controls/PROFILE/ID` | Every control with the status counts of the latest scans; one control with its hosts, and what it checks and how to fix it | | `GET /api/v1/matrix` | The latest status of every control on every host, hosts that fail most first; with `?format=csv`, a sheet for a spreadsheet (a row per host, a column per control, `?lang=ko` for Korean column titles; the dashboard offers it on the matrix page) | diff --git a/internal/server/api.go b/internal/server/api.go index 66557e6..089c38d 100644 --- a/internal/server/api.go +++ b/internal/server/api.go @@ -163,6 +163,9 @@ func (s *Server) handleOverview(w http.ResponseWriter, r *http.Request) { for i := range o.RecentRegression { o.RecentRegression[i].TitleKo = s.titleKo(o.RecentRegression[i].Profile, o.RecentRegression[i].ControlID) } + for i := range o.RecentFixes { + o.RecentFixes[i].TitleKo = s.titleKo(o.RecentFixes[i].Profile, o.RecentFixes[i].ControlID) + } writeJSON(w, http.StatusOK, o) } diff --git a/internal/server/api_test.go b/internal/server/api_test.go index 4044441..729ac37 100644 --- a/internal/server/api_test.go +++ b/internal/server/api_test.go @@ -7,6 +7,7 @@ import ( "encoding/csv" "encoding/json" "fmt" + "math" "net/http" "net/http/httptest" "path/filepath" @@ -948,3 +949,96 @@ func TestMatrixCSV(t *testing.T) { t.Errorf("csv without a token: %d", code) } } + +// The overview says what fixing a failing control would add to the pass rate, and lists a control that a host fixed since its +// previous scan next to the regressions. +// rescan posts a fixture again as a new scan an hour later, with its controls changed by edit. +func (f *apiFixture) rescan(t *testing.T, name, id string, edit func(controls []any) []any) { + t.Helper() + var doc map[string]any + if err := json.Unmarshal(fixture(t, name), &doc); err != nil { + t.Fatal(err) + } + doc["scan"].(map[string]any)["id"] = id + doc["controls"] = edit(doc["controls"].([]any)) + raw, err := json.Marshal(doc) + if err != nil { + t.Fatal(err) + } + f.clock = f.clock.Add(time.Hour) + if code, out := post(t, f.srv, token(t, f.store, ScopeIngest, ""), raw); code != http.StatusCreated { + t.Fatalf("%s: the scan was not stored: %d %v", id, code, out) + } +} + +func setStatus(controls []any, status map[string]string) []any { + for _, c := range controls { + if st, ok := status[c.(map[string]any)["id"].(string)]; ok { + c.(map[string]any)["status"] = st + } + } + return controls +} + +func TestOverviewGainAndFixes(t *testing.T) { + f := newAPIFixture(t) + var o Overview + f.json(t, "/api/v1/overview", &o) + decided := o.Counts["PASS"] + o.Counts["FAIL"] + o.Counts["ERROR"] + o.Counts["MANUAL"] + for _, c := range o.TopFailing { + want := 100 * float64(c.Hosts) / float64(decided) + if math.Abs(c.Gain-want) > 0.001 || c.Gain <= 0 { + t.Errorf("%s: gain %v, want %v", c.ID, c.Gain, want) + } + } + if len(o.RecentFixes) != 0 { + t.Errorf("fixes before any = %+v", o.RecentFixes) + } + // web-01 fixes U-01 (FAIL), and U-04 (ERROR) passes again: a check that ran, not a fix. + f.rescan(t, "web-01.json", "web-01-fixed", func(cs []any) []any { return setStatus(cs, map[string]string{"U-01": "PASS", "U-04": "PASS"}) }) + f.json(t, "/api/v1/overview", &o) + if len(o.RecentFixes) != 1 || o.RecentFixes[0].Host != "web-01" || o.RecentFixes[0].ControlID != "U-01" || o.RecentFixes[0].Status != "PASS" { + t.Errorf("fixes = %+v", o.RecentFixes) + } + for _, r := range o.RecentRegression { + if r.Host == "web-01" && r.ControlID == "U-01" { + t.Errorf("a fixed control is still a regression: %+v", r) + } + } +} + +// The fix-first order is severity (high 3, medium 2, low 1) times the failing hosts, and a control that hosts report with +// different severities counts with the highest one. +func TestOverviewFixFirstOrder(t *testing.T) { + f := newAPIFixture(t) + add := func(sev map[string]string) func([]any) []any { + return func(cs []any) []any { + for _, id := range []string{"X-1", "X-2", "X-3"} { + if sev[id] != "" { + cs = append(cs, map[string]any{"profile": "kisa-2026", "id": id, "title": id, "severity": sev[id], "status": "FAIL", "checks": []string{}}) + } + } + return cs + } + } + f.rescan(t, "web-01.json", "web-01-more", add(map[string]string{"X-1": "low", "X-2": "medium", "X-3": "high"})) + f.rescan(t, "db-01.json", "db-01-more", add(map[string]string{"X-1": "low", "X-3": "medium"})) + var o Overview + f.json(t, "/api/v1/overview", &o) + at := map[string]int{} + for i, c := range o.TopFailing { + at[c.ID] = i + } + for _, id := range []string{"U-08", "X-1", "X-2"} { + if _, ok := at[id]; !ok { + t.Fatalf("%s is not in %+v", id, o.TopFailing) + } + } + // X-3: 2 hosts × high = 6; U-08: 1 host × high = 3; X-1: 2 hosts × low = 2; X-2: 1 host × medium = 2, fewer hosts. + if len(o.TopFailing) == 0 || o.TopFailing[0].ID != "X-3" || o.TopFailing[0].Severity != "high" { + t.Fatalf("first = %+v", o.TopFailing) + } + if at["U-08"] >= at["X-1"] || at["X-1"] >= at["X-2"] { + t.Errorf("order = %+v", o.TopFailing) + } +} diff --git a/internal/server/query.go b/internal/server/query.go index 43ead0f..c7a3a60 100644 --- a/internal/server/query.go +++ b/internal/server/query.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "io" + "math" "sort" "strconv" "strings" @@ -486,6 +487,9 @@ type FailingControl struct { TitleKo string `json:"titleKo,omitempty"` Severity string `json:"severity"` Hosts int `json:"hosts"` + // Gain is what fixing the control on every host that fails it would add to the pass rate, in percentage points: each host + // moves one result from FAIL to PASS, over the same total. + Gain float64 `json:"gain"` } // Overview is the numbers of the dashboard's first page. @@ -500,7 +504,10 @@ type Overview struct { Score *float64 `json:"score"` TopFailing []FailingControl `json:"topFailing"` RecentRegression []RegressedControl `json:"recentRegressions"` - StaleAfterDays int `json:"staleAfterDays"` + // RecentFixes are controls that were FAIL in a host's previous scan and pass now (or are not applicable), + // in the same time as the regressions. + RecentFixes []RegressedControl `json:"recentFixes"` + StaleAfterDays int `json:"staleAfterDays"` } // Overview computes the first page of the dashboard. A host is stale when it has not reported @@ -513,7 +520,7 @@ func (s *Store) Overview(ctx context.Context, staleAfter time.Duration, profile if err != nil { return nil, err } - o := &Overview{Counts: Counts{}, TopFailing: []FailingControl{}, RecentRegression: []RegressedControl{}, StaleAfterDays: int(staleAfter.Hours() / 24), Profile: profile} + o := &Overview{Counts: Counts{}, TopFailing: []FailingControl{}, RecentRegression: []RegressedControl{}, RecentFixes: []RegressedControl{}, StaleAfterDays: int(staleAfter.Hours() / 24), Profile: profile} for _, h := range hosts { if h.Stale { o.HostsStale++ // that a host is silent does not depend on the profile it scanned with @@ -533,10 +540,13 @@ func (s *Store) Overview(ctx context.Context, staleAfter time.Duration, profile o.Score = o.Counts.Score() rs, err := s.db.QueryContext(ctx, ` - SELECT c.profile, c.control_id, MAX(c.title), MAX(c.severity), COUNT(*) - FROM scan_controls c JOIN (`+latestScans+`) l ON l.id = c.scan_row - WHERE c.status = 'FAIL' AND (? = '' OR c.profile = ?) GROUP BY c.profile, c.control_id - ORDER BY COUNT(*) DESC, c.control_id LIMIT 10`, profile, profile) + SELECT profile, control_id, title, CASE w WHEN 3 THEN 'high' WHEN 2 THEN 'medium' ELSE sev END, n FROM ( + SELECT c.profile AS profile, c.control_id AS control_id, MAX(c.title) AS title, MAX(c.severity) AS sev, COUNT(*) AS n, + MAX(CASE c.severity WHEN 'high' THEN 3 WHEN 'medium' THEN 2 ELSE 1 END) AS w + FROM scan_controls c JOIN (`+latestScans+`) l ON l.id = c.scan_row + WHERE c.status = 'FAIL' AND (? = '' OR c.profile = ?) GROUP BY c.profile, c.control_id + ) + ORDER BY n * w DESC, n DESC, control_id LIMIT 10`, profile, profile) if err != nil { return nil, err } @@ -546,6 +556,9 @@ func (s *Store) Overview(ctx context.Context, staleAfter time.Duration, profile _ = rs.Close() return nil, err } + if decided := o.Counts["PASS"] + o.Counts["FAIL"] + o.Counts["ERROR"] + o.Counts["MANUAL"]; decided > 0 { + f.Gain = math.Round(1e5*float64(f.Hosts)/float64(decided)) / 1e3 // three decimals: the dashboard rounds for display + } o.TopFailing = append(o.TopFailing, f) } if err := rs.Err(); err != nil { @@ -554,31 +567,54 @@ func (s *Store) Overview(ctx context.Context, staleAfter time.Duration, profile _ = rs.Close() cutoff := s.now().UTC().Add(-staleAfter).Format(stampLayout) - rr, err := s.db.QueryContext(ctx, ` + if o.RecentRegression, o.RecentFixes, err = s.recentChanges(ctx, cutoff, profile); err != nil { + return nil, err + } + return o, nil +} + +// recentChanges compares each host's latest scan, received since cutoff, with its previous one. A regression is a control that is +// FAIL or ERROR now and was not before; a fix is a control that was FAIL and is PASS or NOT_APPLICABLE now (ERROR to PASS is a +// check that ran again, not a fix, and a waived control is not a fix). At most 20 of each, newest first. +func (s *Store) recentChanges(ctx context.Context, cutoff, profile string) (regressions, fixes []RegressedControl, err error) { + rows, err := s.db.QueryContext(ctx, ` WITH ranked AS ( SELECT s.id AS id, s.host_row AS host_row, s.received_at AS received_at, ROW_NUMBER() OVER (PARTITION BY s.host_row ORDER BY s.received_at DESC, s.id DESC) AS rn FROM scans s JOIN hosts k ON k.id = s.host_row AND k.kind = 'host' + ), changed AS ( + SELECT h.id AS host_id, h.name AS host, c.profile AS profile, c.control_id AS control_id, c.title AS title, c.severity AS severity, + c.status AS status, l.received_at AS received_at, c.status IN ('FAIL', 'ERROR') AS regressed + FROM ranked l + JOIN ranked pv ON pv.host_row = l.host_row AND pv.rn = 2 + JOIN hosts h ON h.id = l.host_row + JOIN scan_controls c ON c.scan_row = l.id + LEFT JOIN scan_controls p ON p.scan_row = pv.id AND p.profile = c.profile AND p.control_id = c.control_id + WHERE l.rn = 1 AND l.received_at >= ? AND (? = '' OR c.profile = ?) AND ( + (c.status IN ('FAIL', 'ERROR') AND (p.status IS NULL OR p.status NOT IN ('FAIL', 'ERROR'))) + OR (c.status IN ('PASS', 'NOT_APPLICABLE') AND p.status = 'FAIL')) + ), numbered AS ( + SELECT *, ROW_NUMBER() OVER (PARTITION BY regressed ORDER BY received_at DESC, host, control_id) AS k FROM changed ) - SELECT h.id, h.name, c.profile, c.control_id, c.title, c.severity, c.status, l.received_at - FROM ranked l - JOIN ranked pv ON pv.host_row = l.host_row AND pv.rn = 2 - JOIN hosts h ON h.id = l.host_row - JOIN scan_controls c ON c.scan_row = l.id AND c.status IN ('FAIL', 'ERROR') - LEFT JOIN scan_controls p ON p.scan_row = pv.id AND p.profile = c.profile AND p.control_id = c.control_id - WHERE l.rn = 1 AND (p.status IS NULL OR p.status NOT IN ('FAIL', 'ERROR')) AND l.received_at >= ? AND (? = '' OR c.profile = ?) - ORDER BY l.received_at DESC, h.name, c.control_id LIMIT 20`, cutoff, profile, profile) + SELECT host_id, host, profile, control_id, title, severity, status, received_at, regressed + FROM numbered WHERE k <= 20 ORDER BY received_at DESC, host, control_id`, cutoff, profile, profile) if err != nil { - return nil, err + return nil, nil, err } - defer rr.Close() - for rr.Next() { + defer rows.Close() + regressions, fixes = []RegressedControl{}, []RegressedControl{} + for rows.Next() { var r RegressedControl - if err := rr.Scan(&r.HostID, &r.Host, &r.Profile, &r.ControlID, &r.Title, &r.Severity, &r.Status, &r.ReceivedAt); err != nil { - return nil, err + var regressed bool + if err := rows.Scan(&r.HostID, &r.Host, &r.Profile, &r.ControlID, &r.Title, &r.Severity, &r.Status, &r.ReceivedAt, ®ressed); err != nil { + return nil, nil, err + } + if regressed { + regressions = append(regressions, r) + } else { + fixes = append(fixes, r) } - o.RecentRegression = append(o.RecentRegression, r) } - return o, rr.Err() + return regressions, fixes, rows.Err() } // MatrixControl is a column of the matrix. diff --git a/site/img/dashboard-overview.png b/site/img/dashboard-overview.png index e67c851..cea8846 100644 Binary files a/site/img/dashboard-overview.png and b/site/img/dashboard-overview.png differ diff --git a/site/img/ko/dashboard-overview.png b/site/img/ko/dashboard-overview.png index ef2a87a..7722cda 100644 Binary files a/site/img/ko/dashboard-overview.png and b/site/img/ko/dashboard-overview.png differ diff --git a/web/src/lib/i18n.tsx b/web/src/lib/i18n.tsx index fe42906..c686959 100644 --- a/web/src/lib/i18n.tsx +++ b/web/src/lib/i18n.tsx @@ -20,6 +20,19 @@ const en = { "error": "Something went wrong", "retry": "Try again", "overview.title": "Overview", + "overview.fixFirst": "Fix first", + "overview.fixFirstHelp": "Ranked by severity and the number of hosts that fail. The number is what fixing it adds to the pass rate.", + "overview.gain": "+{n} pts", + "overview.onHosts": "on {n} hosts", + "overview.howToFix": "How to fix", + "overview.topThree": "Fixing the first three would lift the pass rate to {score}.", + "overview.changes": "Recent changes", + "overview.changesHelp": "Controls that got worse or were fixed in a host's latest scan, and hosts that stopped reporting.", + "change.regressed": "Worse", + "change.fixed": "Fixed", + "change.stale": "Silent", + "change.staleWhat": "no result for {n} days", + "overview.tiles": "Hosts at a glance", "overview.hosts": "Hosts", "overview.results": "results", "overview.failing": "Hosts with a failing control", @@ -27,9 +40,6 @@ const en = { "overview.score": "Pass rate", "overview.scoreHelp": "PASS ÷ (PASS + FAIL + ERROR + MANUAL). Undecided results count against it; WAIVED and NOT_APPLICABLE are shown beside it.", "overview.distribution": "Control results across the fleet", - "overview.topFailing": "Controls that fail on most hosts", - "overview.regressions": "Recent regressions", - "overview.regressionsHelp": "Controls that are failing in a host's latest scan and were not failing in the one before.", "overview.none": "Nothing to show.", "overview.empty": "No results yet. Push one with: vmsctl push result.json --server …", "hosts.title": "Hosts", @@ -126,8 +136,6 @@ const en = { "login.tagline": "Know how hardened every server is, and what changed since yesterday.", "login.hint": "Read-only access to the results your hosts pushed.", "overview.subtitle": "How hardened your fleet is right now", - "overview.attention": "Needs attention", - "overview.attentionHelp": "Hosts that stopped reporting.", "overview.failRate": "{n} of {total} hosts fail at least one control", "overview.viewAll": "View all", "hosts.subtitle": "Every host with the result of its latest scan", @@ -191,6 +199,19 @@ const ko: Record = { "error": "문제가 생겼습니다", "retry": "다시 시도", "overview.title": "개요", + "overview.fixFirst": "먼저 고칠 것", + "overview.fixFirstHelp": "심각도와 실패한 호스트 수로 정렬했습니다. 숫자는 고치면 오르는 통과율입니다.", + "overview.gain": "+{n}%p", + "overview.onHosts": "호스트 {n}대", + "overview.howToFix": "조치 방법", + "overview.topThree": "먼저 고칠 것의 상위 3개를 고치면 통과율이 {score}까지 오릅니다.", + "overview.changes": "최근 바뀐 것", + "overview.changesHelp": "호스트의 최신 스캔에서 악화되거나 해결된 점검 항목, 그리고 보고가 끊긴 호스트입니다.", + "change.regressed": "악화", + "change.fixed": "해결", + "change.stale": "보고 끊김", + "change.staleWhat": "{n}일째 결과가 오지 않음", + "overview.tiles": "호스트 한눈에 보기", "overview.hosts": "호스트", "overview.results": "결과", "overview.failing": "실패한 점검 항목이 있는 호스트", @@ -198,9 +219,6 @@ const ko: Record = { "overview.score": "통과율", "overview.scoreHelp": "PASS ÷ (PASS + FAIL + ERROR + MANUAL). 판정되지 않은 결과는 통과하지 못한 것으로 계산하고, WAIVED와 NOT_APPLICABLE은 옆에 따로 표시합니다.", "overview.distribution": "전체 호스트의 점검 항목 결과", - "overview.topFailing": "가장 많은 호스트에서 실패하는 점검 항목", - "overview.regressions": "최근 악화된 점검 항목", - "overview.regressionsHelp": "호스트의 최신 스캔에서 실패 중이고 직전 스캔에서는 아니었던 점검 항목입니다.", "overview.none": "표시할 내용이 없습니다.", "overview.empty": "아직 결과가 없습니다. 이렇게 보내세요: vmsctl push result.json --server …", "hosts.title": "호스트", @@ -297,8 +315,6 @@ const ko: Record = { "login.tagline": "모든 서버의 보안 설정 상태와 어제 이후 달라진 점을 한눈에.", "login.hint": "호스트가 보낸 결과를 읽기 전용으로 봅니다.", "overview.subtitle": "서버 전체의 보안 설정 현황", - "overview.attention": "확인이 필요한 곳", - "overview.attentionHelp": "보고가 끊긴 호스트입니다.", "overview.failRate": "호스트 {total}대 중 {n}대에서 실패한 점검 항목이 있습니다", "overview.viewAll": "모두 보기", "hosts.subtitle": "모든 호스트와 최신 스캔 결과", @@ -349,6 +365,8 @@ export type Translate = (key: Key | string, n?: number | Record = { "overview.stale": "Hosts not reporting for 1 day", + "overview.onHosts": "on 1 host", + "change.staleWhat": "no result for 1 day", "trend.days": "1 day", "profile.hosts": "1 host", "profile.other": "1 host scanned with another profile is not counted here. Pick that profile to see it.", diff --git a/web/src/lib/types.ts b/web/src/lib/types.ts index e583d83..a832e2b 100644 --- a/web/src/lib/types.ts +++ b/web/src/lib/types.ts @@ -36,11 +36,11 @@ export interface PackInfo { name: string; version: string; digest: string } export interface HostDetail extends HostSummary { profiles?: string[]; controls: ControlRow[]; scans: ScanRow[]; packs?: PackInfo[] } export interface ScanJob { id: number; profile: string; state: "queued" | "claimed" | "done" | "failed" | "expired"; createdAt: string; finishedAt?: string; scan?: number; error?: string } export interface AgentInfo { online: boolean; profiles: string[]; job?: ScanJob } -export interface FailingControl { profile: string; id: string; title: string; titleKo?: string; severity: string; hosts: number } +export interface FailingControl { profile: string; id: string; title: string; titleKo?: string; severity: string; hosts: number; gain?: number } export interface RegressedControl { hostId: number; host: string; profile: string; id: string; title: string; titleKo?: string; severity: string; status: Status; receivedAt: string } export interface Overview { hosts: number; hostsFailing: number; hostsStale: number; counts: Counts; score: number | null; - topFailing: FailingControl[]; recentRegressions: RegressedControl[]; staleAfterDays: number; + topFailing: FailingControl[]; recentRegressions: RegressedControl[]; recentFixes?: RegressedControl[]; staleAfterDays: number; profile?: string; hostsOther?: number; } export interface CheckChange { ref: string; title: string; old: Status | ""; new: Status | "" } diff --git a/web/src/pages/Overview.tsx b/web/src/pages/Overview.tsx index f26a26b..db5d1b0 100644 --- a/web/src/pages/Overview.tsx +++ b/web/src/pages/Overview.tsx @@ -2,19 +2,25 @@ import { api } from "../lib/api"; import { useState } from "react"; import { useAsync, useNow } from "../lib/hooks"; import { useI18n } from "../lib/i18n"; -import { ago, ctitle } from "../lib/format"; -import { Avatar, Await, Donut, Empty, Gauge, PageHeader, Severity, StatusBadge, StatusBar, Stat } from "../components/ui"; +import { ago, ctitle, percent } from "../lib/format"; +import { Await, Donut, Empty, Gauge, PageHeader, ScorePill, Severity, StatusBadge, StatusBar, Stat } from "../components/ui"; import { IconAlert, IconClock, IconServer } from "../components/icons"; import { TrendChart } from "../components/charts"; import { GettingStarted } from "../components/start"; +import type { FailingControl, HostSummary, Overview, RegressedControl } from "../lib/types"; export const STALE_DAYS = 7; +/** How many controls the "fix first" list shows, and how many of them the pass-rate sentence adds up. */ +const FIX_FIRST = 5; +const TOP = 3; + export function OverviewPage() { - const { t, lang } = useI18n(); - const now = useNow(); + const { t } = useI18n(); const state = useAsync(() => api.overview(STALE_DAYS), []); - const stale = useAsync(() => api.hosts({ status: "stale", sort: "last", limit: 5, staleDays: STALE_DAYS }), []); + const hosts = useAsync(() => api.hosts({ sort: "score", limit: 60, staleDays: STALE_DAYS }), []); + // The hosts that went silent most recently, wherever their score puts them in the tiles. + const silent = useAsync(() => api.hosts({ status: "stale", sort: "recent", limit: 2, staleDays: STALE_DAYS }), []); return ( <> @@ -34,10 +40,16 @@ export function OverviewPage() {

{t("overview.distribution")}

{t("overview.scoreHelp")}

+ +
+ + +
+
@@ -46,71 +58,7 @@ export function OverviewPage() { } value={o.hostsStale} label={t("overview.stale", o.staleAfterDays)} tone={o.hostsStale > 0 ? "warn" : "good"} />
-
-
-

{t("overview.topFailing")}

- {o.topFailing.length === 0 ? ( - {t("overview.none")} - ) : ( -
    - {o.topFailing.map((c) => ( -
  1. -
    - - {c.id} - - {ctitle(c, lang)} - - - {c.hosts} - / {o.hosts} - -
    -
    - -
    -
  2. - ))} -
- )} -
- -
-
-

{t("overview.regressions")}

-

{t("overview.regressionsHelp")}

- {o.recentRegressions.length === 0 ? ( - {t("overview.none")} - ) : ( -
    - {o.recentRegressions.map((r) => ( -
  • - -
    - {r.host} {r.id} {ctitle(r, lang)} -
    {ago(r.receivedAt, now, t)}
    -
    -
  • - ))} -
- )} -
- {(stale.data?.hosts.length ?? 0) > 0 && ( -
-

{t("overview.attention")}

-

{t("overview.attentionHelp")}

-
    - {stale.data?.hosts.map((h) => ( -
  • - {h.name} - {ago(h.lastScanAt, now, t)} -
  • - ))} -
-
- )} -
-
+ {(hosts.data?.hosts.length ?? 0) > 0 && } ) } @@ -119,6 +67,125 @@ export function OverviewPage() { ); } +/** The pass rate the fleet would have if the first controls of the list were fixed on every host that fails them. */ +function TopThree({ o }: { o: Overview }) { + const { t } = useI18n(); + const gains = o.topFailing.slice(0, TOP).map((c) => c.gain ?? 0); + if (o.score === null || gains.length < TOP || gains.some((g) => g <= 0)) return null; + const after = Math.min(1, o.score + gains.reduce((a, b) => a + b, 0) / 100); + if (percent(after) === percent(o.score)) return null; // a lift too small to show + return

{t("overview.topThree", { score: percent(after) })}

; +} + +/** The failing controls in the order to fix them: severity times the hosts that fail, with what each adds to the pass rate. */ +function FixFirst({ o }: { o: Overview }) { + const { t, lang } = useI18n(); + const list = o.topFailing.slice(0, FIX_FIRST); + return ( +
+

{t("overview.fixFirst")}

+

{t("overview.fixFirstHelp")}

+ {list.length === 0 ? ( + {t("overview.none")} + ) : ( +
    + {list.map((c: FailingControl) => ( +
  1. +
    +
    + {c.id} {ctitle(c, lang)} +
    +
    + · {t("overview.onHosts", c.hosts)} +
    +
    + {(c.gain ?? 0) > 0 && {t("overview.gain", { n: points(c.gain ?? 0) })}} + + {t("overview.howToFix")} + +
  2. + ))} +
+ )} +
+ ); +} + +/** Percentage points for display: one decimal, or two for a small gain so that it does not read as zero. */ +function points(g: number): string { + return g >= 0.1 ? g.toFixed(1) : g >= 0.01 ? g.toFixed(2) : "<0.01"; +} + +type Change = { key: string; kind: "regressed" | "fixed" | "stale"; at: string; hostId: number; host: string; what: string; status?: RegressedControl["status"] }; + +/** What changed lately, newest first: controls that got worse or were fixed, and hosts that stopped reporting. */ +function Changes({ o, silent: stale }: { o: Overview; silent: HostSummary[] }) { + const { t, lang } = useI18n(); + const now = useNow(); + const control = (kind: "regressed" | "fixed") => (r: RegressedControl): Change => ({ + key: `${kind}/${r.hostId}/${r.profile}/${r.id}`, kind, at: r.receivedAt, hostId: r.hostId, host: r.host, what: `${r.id} ${ctitle(r, lang)}`, + status: kind === "regressed" && r.status === "ERROR" ? r.status : undefined, // worse because the check could not run, not because it failed + }); + const silent = stale.map((h): Change => ({ + key: `stale/${h.id}`, kind: "stale", at: h.lastScanAt, hostId: h.id, host: h.name, + what: t("change.staleWhat", Math.max(1, Math.floor((now - Date.parse(h.lastScanAt)) / 86400000))), + })); + // A share for each kind, so that a burst of regressions does not hide the fixes and the silent hosts. + const newest = (a: Change, b: Change) => (a.at < b.at ? 1 : a.at > b.at ? -1 : 0); + const all = [ + ...o.recentRegressions.map(control("regressed")).sort(newest).slice(0, 5), + ...(o.recentFixes ?? []).map(control("fixed")).sort(newest).slice(0, 3), + ...silent.sort(newest).slice(0, 2), + ].sort(newest); + return ( +
+

{t("overview.changes")}

+

{t("overview.changesHelp")}

+ {all.length === 0 ? ( + {t("overview.none")} + ) : ( +
    + {all.map((c) => ( +
  • + {t(`change.${c.kind}`)} + + {c.host} · {c.what} {c.status && } + + {/* a silent host says how long already */} + {c.kind === "stale" ? "" : ago(c.at, now, t)} +
  • + ))} +
+ )} +
+ ); +} + +/** Every host as a tile with its pass rate, worst first: a fleet at a glance. */ +function HostTiles({ hosts }: { hosts: HostSummary[] }) { + const { t } = useI18n(); + const now = useNow(); + return ( +
+
+

{t("overview.tiles")}

+ {t("overview.viewAll")} +
+ +
+ ); +} + /** The fleet's pass rate over the last days (7, 30 or 90), one point a day. */ function TrendCard() { const { t } = useI18n(); diff --git a/web/src/styles.css b/web/src/styles.css index 02784d7..1d6261c 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -148,16 +148,6 @@ input::placeholder { color: var(--muted); } .stat.good .stat-icon { background: color-mix(in srgb, var(--pass) 16%, transparent); color: var(--pass); } .stat-value { font-size: 1.7rem; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; } .stat-label { color: var(--muted); font-size: .84rem; } -.ranked { list-style: none; padding: 0; display: grid; gap: .85rem; } -.ranked-head { display: grid; grid-template-columns: 3.2rem 1fr auto auto; gap: .6rem; align-items: baseline; } -.ranked .id { color: var(--muted); } -.ranked-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -.meter { height: 6px; background: var(--surface-2); border-radius: 999px; margin-top: .35rem; overflow: hidden; } -.meter span { display: block; height: 100%; border-radius: 999px; background: var(--na); } -.meter .sev-high { background: var(--fail); } .meter .sev-medium { background: var(--manual); } .meter .sev-low { background: var(--waived); } -.timeline { list-style: none; padding: 0; display: grid; gap: .8rem; margin-top: .6rem; } -.timeline li { display: grid; grid-template-columns: 12px 1fr; gap: .7rem; } -.timeline-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: .45rem; background: var(--fail); } .signed { display: inline-flex; align-items: center; gap: .25rem; font-size: .75rem; color: var(--pass-text); background: color-mix(in srgb, var(--pass) 14%, transparent); border-radius: 999px; padding: .05rem .5rem; font-weight: 600; white-space: nowrap; } .id { font-weight: 600; } .prose { white-space: pre-line; max-width: 80ch; } @@ -184,7 +174,7 @@ table.matrix .col a { color: inherit; } .statusbar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); gap: 2px; } .statusbar.thin { height: 8px; } .statusbar .seg { display: block; height: 100%; min-width: 3px; } -.seg.s-FAIL, .dot.s-FAIL, .timeline-dot.s-FAIL { background: var(--fail); } .seg.s-ERROR, .dot.s-ERROR { background: var(--error); } +.seg.s-FAIL, .dot.s-FAIL { background: var(--fail); } .seg.s-ERROR, .dot.s-ERROR { background: var(--error); } .seg.s-MANUAL, .dot.s-MANUAL { background: var(--manual); } .seg.s-WAIVED, .dot.s-WAIVED { background: var(--waived); } .seg.s-PASS, .dot.s-PASS { background: var(--pass); } .seg.s-NOT_APPLICABLE, .dot.s-NOT_APPLICABLE { background: var(--na); } .legend { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; padding: 0; margin: .8rem 0 0; font-size: .84rem; color: var(--muted); } @@ -361,3 +351,32 @@ html[lang="ko"] .evidence, html[lang="ko"] code, html[lang="ko"] .mono { word-br /* the live demo (site/demo) */ .demo-banner { margin: 0 0 1.1rem; padding: .6rem .9rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--accent-soft, var(--bg)); font-size: .88rem; color: var(--muted); } .demo-banner a { color: var(--accent); } + +/* overview: fix first, recent changes, host tiles */ +.topthree { margin: .6rem 0 0; padding: .55rem .75rem; background: var(--surface-2); border-radius: var(--radius-sm); font-size: .9rem; } +.fixlist { list-style: none; padding: 0; margin: .4rem 0 0; display: grid; } +.fixlist li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .75rem; align-items: center; padding: .65rem 0; border-top: 1px solid var(--border); } +.fixlist li:first-child { border-top: 0; } +.fixlist-title { font-weight: 600; overflow-wrap: anywhere; } +.fixlist .id { color: var(--accent); margin-right: .25rem; } +.gain { font-weight: 700; color: var(--pass-text); font-variant-numeric: tabular-nums; white-space: nowrap; } +.changes { list-style: none; padding: 0; margin: .4rem 0 0; display: grid; } +.changes li { display: grid; grid-template-columns: 5.2rem minmax(0, 1fr) auto; gap: .7rem; align-items: center; padding: .55rem 0; border-top: 1px solid var(--border); font-size: .92rem; } +.changes li:first-child { border-top: 0; } +.changes-what { overflow-wrap: anywhere; } +.kind { display: inline-block; text-align: center; font-size: .78rem; font-weight: 700; padding: .2rem .4rem; border-radius: 6px; } +.kind-regressed { background: color-mix(in srgb, var(--fail) 16%, transparent); color: var(--fail-text); } +.kind-fixed { background: color-mix(in srgb, var(--pass) 10%, transparent); color: var(--pass-text); } +.kind-stale { background: color-mix(in srgb, var(--manual) 18%, transparent); color: var(--manual-text); } +.tiles { list-style: none; padding: 0; margin: .4rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; } +.tile { display: grid; gap: .35rem; padding: .7rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); text-decoration: none; background: var(--surface); } +.tile:hover { border-color: var(--accent); } +.tile-name { font-weight: 600; overflow-wrap: anywhere; } +@media (max-width: 720px) { + .fixlist li { grid-template-columns: minmax(0, 1fr) auto; } + .fixlist li .button { grid-column: 1 / -1; justify-self: start; } + .changes li { grid-template-columns: 5.2rem minmax(0, 1fr); } + .changes li > .muted { grid-column: 2; } +} +.changes-what a { text-decoration: underline; text-underline-offset: 2px; } +.tile .pill { justify-self: start; }