Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d84a56b
reporting: traffic-light scorecard, health overlay and exports (spec …
Yoshiofthewire Nov 25, 2026
7e9d8bd
notes: scorecard
Yoshiofthewire Nov 25, 2026
6edd769
reporting: pick each account's newest release in SQL
Yoshiofthewire Nov 25, 2026
cc0079e
reporting: filter the decommissioned count too
Yoshiofthewire Nov 25, 2026
478b4ac
Merge kyguard/inventory into kyguard/scorecard
Yoshiofthewire Nov 25, 2026
0e0afee
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 25, 2026
d4bbb7c
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 25, 2026
2b12ee7
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 25, 2026
3c10e0a
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 25, 2026
3305947
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 25, 2026
a7db71b
reports: the scorecard waits for a break-glass session's reason
Yoshiofthewire Nov 25, 2026
fb18df7
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 25, 2026
c84f93e
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 26, 2026
ea1f070
reports: classify the report routes, match principals by users.sso_is…
Yoshiofthewire Nov 26, 2026
0715a15
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 26, 2026
1223288
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 26, 2026
d6b48ba
Merge branch 'kyguard/inventory' into kyguard/scorecard
Yoshiofthewire Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ overlay merges with synthetic inputs and starts no containers.
- [internal/backup/AGENTS.md](internal/backup/AGENTS.md): Product-side adapters over `ky-primitives/recoveryclient`: payload collection, drill checks, settings and sealer glue.
- [internal/testdb/AGENTS.md](internal/testdb/AGENTS.md): Test-only isolated database provisioning (SQLite or PostgreSQL).
- [internal/api/AGENTS.md](internal/api/AGENTS.md): HTTP REST API endpoints, routing, and middleware.
- [internal/reporting/AGENTS.md](internal/reporting/AGENTS.md): Traffic-light scorecard, health overlay, filters and CSV/JSON export (spec §8).
- [web/AGENTS.md](web/AGENTS.md): React 19 + TypeScript + Vite PWA frontend and KySecurity design system.

`docs/REPLICAS.md` owns topology, shared secrets, health/drain, the Compose replica overlay
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ History before the KyGuard import is `ky-server-base` at `fed0fb3` and its own `
account's owner and status, upload target descriptors (strictly decoded, 1A slice only,
bound to this deployment, account and asset) and define account and user attributes
(`string` or `enum`); SCIM-sourced attributes are read-only.
- Traffic-light scorecard (spec §8.1, §8.3): every active account is Green (scheduled and
released at least once), Yellow (sealed current envelope) or Red, with one health value
beside it; `GET /api/reports/scorecard` serves the dashboard and, with `format=json|csv`,
an audited download of the same rows. Non-admins see accounts they own or are listed on.

### Upgrade impact

Expand Down
13 changes: 13 additions & 0 deletions docs/DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,16 @@ Numbered separately: these came from the parallel crypto stack.
`session` class. The writes (assets, accounts, target descriptors, attribute definitions
and values) also need a step-up within five minutes: a descriptor is what a policy pins,
and the rest feed the reports. The reads need none.
205. §8.1 (overdue). An account is `overdue` when the newest occurrence due at least one
`interval_seconds` ago came after its last `release` receipt (Control Plane time).
206. §8.1 (one health value). Health is a single value: a non-`healthy` broker report wins,
then `checkout_open`, `pending_first_rotation`, `overdue`, else `healthy`. It never
changes the class.
207. §8.3 (listed on in the policy). A non-admin is listed when a principal in any of the
current policy's principal lists has a verified `KeyEnrollmentManifest` whose issuer
and subject are the caller's own (`users.sso_issuer`, §7.2); a subject alone never
matches, and a local account is never listed.
208. §8.3 (what is audited). The dashboard view is not an export and is not audited; every
`format=json` or `format=csv` download is, before its body is sent. CSV cells that a
spreadsheet would run as a formula are prefixed with `'`.

10 changes: 10 additions & 0 deletions docs/INTERFACES.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,16 @@ is session class; the writes need a step-up within five minutes (decision 204b).
| DELETE `/api/attributes/{id}` | Administrator | 204; the values go with it; 400 for a SCIM definition |
| PUT `/api/attributes/{id}/values/{entity_id}` | Administrator; JSON `{"value"}` (≤256 printable characters, `""` clears) | 200; 400 for a SCIM attribute, an enum value outside the list or an unknown account or user; audited `attribute.value_set` |

### Scorecard and jobs (spec §8.1–§8.3, §10)

Source: [report handlers](../internal/api/report_handlers.go), [reporting](../internal/reporting/reporting.go).

| Route | Authentication and input | Success |
|---|---|---|
| GET `/api/reports/scorecard` | Any active session; filters `class`, `health`, `pool`, `attr.<key>`, `owner.<key>` (equality) | 200 `{generated_at, totals:{active, decommissioned, classes, percent, health}, account_attribute_keys, owner_attribute_keys, rows}`; admins see every account, others the accounts they own or are listed on in the current policy |
| GET `/api/reports/scorecard?format=json\|csv` | Same | 200 download (`Content-Disposition: attachment`, `no-store`) with the same rows and totals; CSV has the fixed columns, then `attr.<key>` and `owner.<key>`. Audited `report.exported` (format, row count, filter) before the body is sent; 500 and no body if the audit fails |
| GET `/api/jobs` | Administrator | 200 `{runs, leases}`: the 200 newest rotation runs and checkout leases, open leases first |

## Replicas and database migration

[Replication and migration](REPLICAS.md) owns deployment requirements and the cutover runbook.
Expand Down
4 changes: 4 additions & 0 deletions internal/api/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Owns HTTP routing, request parsing, session cookie validation, CORS headers, and
JSON (unknown fields refused), audited in the store transaction, session class; the
writes need a five-minute step-up (decision 204b). Descriptor upload decodes with `pqcrypto.DecodeTargetDescriptor` and
stores the canonical bytes.
- `report_handlers.go`: GET `/api/reports/scorecard` (session) serves the dashboard and,
with `format=json|csv`, an audited download from the same `reporting.Build` dataset and
filter; GET `/api/jobs` (admin). Both are session class with no step-up window.
`callerIssuer` is `users.sso_issuer`, empty for a local account.
- Update `docs/INTERFACES.md` when a route's inputs, outputs, permissions or errors change.
- POST `/api/auth/change-password` accepts a break-glass session (restricted or not; SSO accounts get 409), current password, a TOTP code (checked after the password) and a different policy-valid new password. Browser CSRF and per-IP/account limits apply. Success revokes all sessions and requires sign-in again; flagged sessions get `password_change_required` on protected routes and public-only settings.
- `GET|HEAD /livez` and `/readyz` (`health.go`) are unauthenticated, `Cache-Control: no-store`,
Expand Down
102 changes: 102 additions & 0 deletions internal/api/report_handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package api

import (
"bytes"
"encoding/json"
"net/http"
"time"

"github.com/Busnes-app/kyguard-server/internal/reporting"
"github.com/Busnes-app/kyguard-server/internal/store"
)

func (s *Server) reportRoutes() {
// Reads only, so no step-up window. The dataset is authorized per caller (§8.3).
s.route(ClassSession, "GET /api/reports/scorecard", http.HandlerFunc(s.requireSession(s.handleScorecard)))
s.route(ClassSession, "GET /api/jobs", http.HandlerFunc(s.requireAdmin(s.handleJobs)))
}

// callerIssuer is the issuer of the caller's SSO identity (users.sso_issuer, §7.2), or ""
// for a local account, so a principal can never be matched to them by subject alone.
func callerIssuer(u *store.User) string {
if u.SSOSubject == "" {
return ""
}
return u.SSOIssuer
}

type scorecard struct {
GeneratedAt time.Time `json:"generated_at"`
Totals reporting.Totals `json:"totals"`
AccountKeys []string `json:"account_attribute_keys"`
OwnerKeys []string `json:"owner_attribute_keys"`
Rows []*reporting.Row `json:"rows"`
}

// handleScorecard serves the dashboard (no format) and the exports (format=json|csv) from
// one dataset, one classifier and one filter (§8.3). Exports are downloads and audited.
func (s *Server) handleScorecard(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
u, _, err := s.sessions.AuthenticateRequest(r)
if err != nil {
s.writeError(w, http.StatusUnauthorized, "Authentication required")
return
}
q := r.URL.Query()
format := q.Get("format")
if format != "" && format != "json" && format != "csv" {
s.writeError(w, http.StatusBadRequest, "format is json or csv")
return
}
now := time.Now().UTC()
ds, err := reporting.Build(ctx, s.store, s.trust, reporting.Caller{UserID: u.ID, Admin: u.Role == "admin", Issuer: callerIssuer(u), Subject: u.SSOSubject}, now)
if err != nil {
s.writeError(w, http.StatusInternalServerError, "could not build the scorecard")
return
}
f := reporting.ParseFilter(q)
rows := f.Apply(ds.Rows)
card := scorecard{GeneratedAt: now, Totals: reporting.Summarize(rows, f.Retired(ds.Retired)), AccountKeys: ds.AccountKeys, OwnerKeys: ds.OwnerKeys, Rows: rows}
if format == "" {
s.writeJSON(w, http.StatusOK, card)
return
}
var body bytes.Buffer
ctype := "application/json"
if format == "csv" {
ctype = "text/csv; charset=utf-8"
err = reporting.WriteCSV(&body, ds, rows)
} else {
err = json.NewEncoder(&body).Encode(card)
}
if err != nil {
s.writeError(w, http.StatusInternalServerError, "could not write the export")
return
}
// The audit row lands before a byte of the export leaves (§8.3, §9.3).
if err := s.store.Audit().LogAudit(ctx, s.audit(r, "report.exported", "scorecard",
map[string]any{"format": format, "rows": len(rows), "filter": r.URL.Query().Encode()})); err != nil {
s.writeError(w, http.StatusInternalServerError, "could not audit the export")
return
}
w.Header().Set("Content-Type", ctype)
w.Header().Set("Content-Disposition", `attachment; filename="kyguard-scorecard-`+now.Format("20060102T150405Z")+`.`+format+`"`)
w.Header().Set("Cache-Control", "no-store")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(body.Bytes())
}

// handleJobs lists recent rotation runs and checkout leases for the jobs screen (§10).
func (s *Server) handleJobs(w http.ResponseWriter, r *http.Request) {
runs, err := s.store.Inventory().RecentRuns(r.Context(), 200)
if err != nil {
s.writeError(w, http.StatusInternalServerError, "could not list rotation runs")
return
}
leases, err := s.store.Inventory().RecentLeases(r.Context(), 200)
if err != nil {
s.writeError(w, http.StatusInternalServerError, "could not list leases")
return
}
s.writeJSON(w, http.StatusOK, map[string]any{"runs": runs, "leases": leases})
}
Loading