From c05c847d17075905eb12c2070bf9424c98573486 Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Sun, 18 Oct 2026 23:47:50 +0200 Subject: [PATCH] Profile pictures from Gravatar or the identity provider, fetched and kept by the server Both sources are off until switched on under Settings, Sign-in. The server asks only gravatar.com (by a hash of the email) and the identity provider's own host, accepts only small PNG/JPEG/WebP/GIF, keeps each picture for a day and serves it from /api/avatars/, so browsers never contact either. Shown in the user menu and on the Users page, with initials as the fallback; the Privacy page says when it is on. Co-Authored-By: Claude Sonnet 5.5 --- DATABASE.md | 1 + README.md | 7 + ROLES.md | 2 + server/drizzle/0041_open_silvermane.sql | 1 + server/drizzle/meta/0041_snapshot.json | 3728 +++++++++++++++++++++ server/drizzle/meta/_journal.json | 7 + server/src/app.ts | 2 + server/src/auth/router.ts | 3 +- server/src/auth/users.ts | 4 + server/src/db/schema.ts | 3 + server/src/routes/avatars.ts | 29 + server/src/routes/me.ts | 12 +- server/src/routes/privacy.ts | 6 +- server/src/routes/settings.ts | 1 + server/src/routes/users.ts | 5 +- server/src/services/avatars.ts | 186 + server/src/services/settingsStore.ts | 13 + server/test/avatars.test.ts | 252 ++ server/test/signInGroups.test.ts | 3 +- web/src/api/client.ts | 11 + web/src/components/Avatar.tsx | 22 + web/src/layout/AppShell.tsx | 9 +- web/src/pages/Privacy.tsx | 14 + web/src/pages/Users.tsx | 8 +- web/src/pages/settings/SignInSettings.tsx | 45 +- web/src/styles.css | 8 + 26 files changed, 4361 insertions(+), 21 deletions(-) create mode 100644 server/drizzle/0041_open_silvermane.sql create mode 100644 server/drizzle/meta/0041_snapshot.json create mode 100644 server/src/routes/avatars.ts create mode 100644 server/src/services/avatars.ts create mode 100644 server/test/avatars.test.ts create mode 100644 web/src/components/Avatar.tsx diff --git a/DATABASE.md b/DATABASE.md index db72dbb..ca7278c 100644 --- a/DATABASE.md +++ b/DATABASE.md @@ -91,6 +91,7 @@ Everyone who has signed in through Authentik. The first one becomes admin. | `created_at` | text NOT NULL | SQLite UTC. | | `last_login_at` | text | ISO. | | `favorites` | text | JSON array of the page paths this person pinned to the top of their menu (`["/servers","/alerts"]`), up to 24. A path may carry a short query for a saved view of a page (`"/servers?status=offline"`). Follows them to any browser. | +| `picture_url` | text | The `picture` claim the identity provider gave at the last sign-in. Only an address; nothing is fetched from it unless Settings → Sign-in → Profile pictures allows it (and then only Gravatar or the provider's own host). Pictures themselves are kept in the server's memory for a day, not in the database. | | `dashboard_layout` | text | JSON object `{"hidden":["Gitea"],"order":{"Secrets":0,"DNS":1}}`: the dashboard cards this person hid and the order of the rest (lower first; a card with no entry goes last). Null = the default layout. Follows them to any browser. | | `groups` | text | JSON array of the groups the identity provider reported at this person's last sign-in (null until they have signed in with groups available) — shown on the Users page, and what "roles from groups" works from. | | `last_looked_at` | text | ISO time this person last pressed "Got it" on the dashboard's "Since you last looked" card; the next summary starts there (null = never: the last day is shown). | diff --git a/README.md b/README.md index c75a97b..afec378 100644 --- a/README.md +++ b/README.md @@ -633,6 +633,13 @@ group rule, the first person ever is still the administrator, and while it is on Users page shows roles instead of letting you set them. The Users page also shows the groups each person had at their last sign-in. +**Profile pictures** (Settings → Sign-in, both sources off until switched on). Without one a person is their initials. An administrator can allow the picture the +identity provider names in its `picture` claim (kept at each sign-in; only an address on Authentik's own host or on Gravatar is ever used, so a claim can't make the +server fetch just anywhere) and/or **Gravatar** (by a SHA-256 hash of the person's email — never the address itself). The picture from the provider is tried first. +Either way it is **the server** that asks: it checks what comes back (a small PNG, JPEG, WebP or GIF — never SVG), keeps it for a day, and serves it from `/api/avatars/` +to anyone signed in, so people's browsers never contact Gravatar or Authentik for it, and a person with no picture, or a host that can't be reached, simply shows initials. +The Privacy page says when it is on. The picture shows in the user menu and on the Users page. + **Prometheus and webhooks** (Settings → API and webhooks). `/metrics` answers in Prometheus's text format — servers up or not, load, memory, disks, waiting updates, agent versions, alert counts, which integrations work, maintenance, what is about to diff --git a/ROLES.md b/ROLES.md index 7cef5e6..9c692f1 100644 --- a/ROLES.md +++ b/ROLES.md @@ -115,6 +115,8 @@ even further, to admin only: ignore** on its Host health card. Everyone sees *What the agent couldn't collect*. - **Host health** (failed services, disk health, ZFS pools) is shown to everyone on a server's page; **Update agents automatically** on the Servers page is admin-only. +- **Profile pictures** are shown to everyone signed in (`/api/avatars/`, the same people whose names everyone already sees); which sources are allowed is under + Settings → Sign-in, so admin-only. - **Sign-in groups, metrics tokens, event webhooks, share links (the wall display and the status pages, and what is on them) and the Grafana dashboard download** are all under Settings, so admin-only; `/metrics` itself needs a metrics token, not a login. - Everything under **Settings** (notification channels, badge colors, diff --git a/server/drizzle/0041_open_silvermane.sql b/server/drizzle/0041_open_silvermane.sql new file mode 100644 index 0000000..c114b66 --- /dev/null +++ b/server/drizzle/0041_open_silvermane.sql @@ -0,0 +1 @@ +ALTER TABLE `users` ADD `picture_url` text; \ No newline at end of file diff --git a/server/drizzle/meta/0041_snapshot.json b/server/drizzle/meta/0041_snapshot.json new file mode 100644 index 0000000..bd494a1 --- /dev/null +++ b/server/drizzle/meta/0041_snapshot.json @@ -0,0 +1,3728 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "63e09206-10d3-4f6b-9258-d3f0b85d1319", + "prevId": "5cefa6c3-fda8-4f42-a51f-a874daca7488", + "tables": { + "alert_acks": { + "name": "alert_acks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "alert_key": { + "name": "alert_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "''" + }, + "assignee_user_id": { + "name": "assignee_user_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "assignee_name": { + "name": "assignee_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "acked_by": { + "name": "acked_by", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "acked_at": { + "name": "acked_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "until": { + "name": "until", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "alert_acks_key_idx": { + "name": "alert_acks_key_idx", + "columns": [ + "alert_key" + ], + "isUnique": true + } + }, + "foreignKeys": { + "alert_acks_assignee_user_id_users_id_fk": { + "name": "alert_acks_assignee_user_id_users_id_fk", + "tableFrom": "alert_acks", + "tableTo": "users", + "columnsFrom": [ + "assignee_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "alert_incidents": { + "name": "alert_incidents", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "alert_key": { + "name": "alert_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "peak_severity": { + "name": "peak_severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "link": { + "name": "link", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_name": { + "name": "target_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "caused_by": { + "name": "caused_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "opened_at": { + "name": "opened_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "resolved_at": { + "name": "resolved_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "missing_since": { + "name": "missing_since", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "escalated_step": { + "name": "escalated_step", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "escalated_at": { + "name": "escalated_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "alert_incidents_key_idx": { + "name": "alert_incidents_key_idx", + "columns": [ + "alert_key" + ], + "isUnique": false + }, + "alert_incidents_opened_idx": { + "name": "alert_incidents_opened_idx", + "columns": [ + "opened_at" + ], + "isUnique": false + }, + "alert_incidents_target_idx": { + "name": "alert_incidents_target_idx", + "columns": [ + "target_type", + "target_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "alert_tickets": { + "name": "alert_tickets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "alert_key": { + "name": "alert_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "seen_count": { + "name": "seen_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ticket_number": { + "name": "ticket_number", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "grouped": { + "name": "grouped", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ticketed_at": { + "name": "ticketed_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cleared_at": { + "name": "cleared_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "alert_tickets_key_idx": { + "name": "alert_tickets_key_idx", + "columns": [ + "alert_key" + ], + "isUnique": false + } + }, + "foreignKeys": { + "alert_tickets_integration_id_integrations_id_fk": { + "name": "alert_tickets_integration_id_integrations_id_fk", + "tableFrom": "alert_tickets", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "assets": { + "name": "assets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'other'" + }, + "manufacturer": { + "name": "manufacturer", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "serial": { + "name": "serial", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "purchase_date": { + "name": "purchase_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "purchase_price": { + "name": "purchase_price", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "warranty_until": { + "name": "warranty_until", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "end_of_support": { + "name": "end_of_support", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "replacement_cost": { + "name": "replacement_cost", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rack_unit": { + "name": "rack_unit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "power_watts": { + "name": "power_watts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "audit_log": { + "name": "audit_log", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "actor_label": { + "name": "actor_label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "audit_log_actor_user_id_users_id_fk": { + "name": "audit_log_actor_user_id_users_id_fk", + "tableFrom": "audit_log", + "tableTo": "users", + "columnsFrom": [ + "actor_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "consistency_ignores": { + "name": "consistency_ignores", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "consistency_ignores_key_unique": { + "name": "consistency_ignores_key_unique", + "columns": [ + "key" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dependencies": { + "name": "dependencies", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "from_type": { + "name": "from_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "from_id": { + "name": "from_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "to_type": { + "name": "to_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "to_id": { + "name": "to_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "dependencies_edge_idx": { + "name": "dependencies_edge_idx", + "columns": [ + "from_type", + "from_id", + "to_type", + "to_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "diag_log": { + "name": "diag_log", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "operation": { + "name": "operation", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ok": { + "name": "ok", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "latency_ms": { + "name": "latency_ms", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dns_providers": { + "name": "dns_providers", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "provider_type": { + "name": "provider_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credential_id": { + "name": "credential_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "config": { + "name": "config", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "dns_providers_credential_id_integration_credentials_id_fk": { + "name": "dns_providers_credential_id_integration_credentials_id_fk", + "tableFrom": "dns_providers", + "tableTo": "integration_credentials", + "columnsFrom": [ + "credential_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dns_records_cache": { + "name": "dns_records_cache", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "provider_id": { + "name": "provider_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "zone_id": { + "name": "zone_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "record_id": { + "name": "record_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ttl": { + "name": "ttl", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxied": { + "name": "proxied", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "dns_records_cache_provider_id_dns_providers_id_fk": { + "name": "dns_records_cache_provider_id_dns_providers_id_fk", + "tableFrom": "dns_records_cache", + "tableTo": "dns_providers", + "columnsFrom": [ + "provider_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dns_zones_cache": { + "name": "dns_zones_cache", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "provider_id": { + "name": "provider_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "zone_id": { + "name": "zone_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "zone_name": { + "name": "zone_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "synced_at": { + "name": "synced_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "dns_zones_cache_provider_zone_idx": { + "name": "dns_zones_cache_provider_zone_idx", + "columns": [ + "provider_id", + "zone_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "dns_zones_cache_provider_id_dns_providers_id_fk": { + "name": "dns_zones_cache_provider_id_dns_providers_id_fk", + "tableFrom": "dns_zones_cache", + "tableTo": "dns_providers", + "columnsFrom": [ + "provider_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "domains": { + "name": "domains", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "origin": { + "name": "origin", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'manual'" + }, + "expires_at": { + "name": "expires_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "registrar": { + "name": "registrar", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lookup_source": { + "name": "lookup_source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_checked_at": { + "name": "last_checked_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_checked_ok_at": { + "name": "last_checked_ok_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_check_error": { + "name": "last_check_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "domains_name_unique": { + "name": "domains_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "endpoint_checks": { + "name": "endpoint_checks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target": { + "name": "target", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "port": { + "name": "port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expect_status": { + "name": "expect_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "keyword": { + "name": "keyword", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "insecure": { + "name": "insecure", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "interval_minutes": { + "name": "interval_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 5 + }, + "timeout_seconds": { + "name": "timeout_seconds", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 10 + }, + "failures_before_alert": { + "name": "failures_before_alert", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 2 + }, + "warn_days": { + "name": "warn_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 14 + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "last_checked_at": { + "name": "last_checked_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_ok": { + "name": "last_ok", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_message": { + "name": "last_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_response_ms": { + "name": "last_response_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cert_expires_at": { + "name": "cert_expires_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "last_change_at": { + "name": "last_change_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "endpoint_results": { + "name": "endpoint_results", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "check_id": { + "name": "check_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "at": { + "name": "at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ok": { + "name": "ok", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ms": { + "name": "ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "endpoint_results_check_idx": { + "name": "endpoint_results_check_idx", + "columns": [ + "check_id", + "at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "endpoint_results_check_id_endpoint_checks_id_fk": { + "name": "endpoint_results_check_id_endpoint_checks_id_fk", + "tableFrom": "endpoint_results", + "tableTo": "endpoint_checks", + "columnsFrom": [ + "check_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "event_webhooks": { + "name": "event_webhooks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "events": { + "name": "events", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_attempt_at": { + "name": "last_attempt_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_result": { + "name": "last_result", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "incident_notes": { + "name": "incident_notes", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "incident_id": { + "name": "incident_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "author": { + "name": "author", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "incident_notes_incident_idx": { + "name": "incident_notes_incident_idx", + "columns": [ + "incident_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "incident_notes_incident_id_alert_incidents_id_fk": { + "name": "incident_notes_incident_id_alert_incidents_id_fk", + "tableFrom": "incident_notes", + "tableTo": "alert_incidents", + "columnsFrom": [ + "incident_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "integration_credentials": { + "name": "integration_credentials", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "encrypted_secret": { + "name": "encrypted_secret", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "integrations": { + "name": "integrations", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "base_url": { + "name": "base_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credential_id": { + "name": "credential_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "config": { + "name": "config", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "integrations_credential_id_integration_credentials_id_fk": { + "name": "integrations_credential_id_integration_credentials_id_fk", + "tableFrom": "integrations", + "tableTo": "integration_credentials", + "columnsFrom": [ + "credential_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ipam_entries": { + "name": "ipam_entries", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "vendor": { + "name": "vendor", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "ipam_entries_ip_address_unique": { + "name": "ipam_entries_ip_address_unique", + "columns": [ + "ip_address" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "maintenance_aliases": { + "name": "maintenance_aliases", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "maintenance_aliases_unique_idx": { + "name": "maintenance_aliases_unique_idx", + "columns": [ + "address", + "target_type", + "target_id" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "maintenance_schedules": { + "name": "maintenance_schedules", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "targets": { + "name": "targets", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "days": { + "name": "days", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "start_time": { + "name": "start_time", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "duration_minutes": { + "name": "duration_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "maintenance_windows": { + "name": "maintenance_windows", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ends_at": { + "name": "ends_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "metrics_tokens": { + "name": "metrics_tokens", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_used_at": { + "name": "last_used_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "metrics_tokens_token_hash_unique": { + "name": "metrics_tokens_token_hash_unique", + "columns": [ + "token_hash" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "notification_queue": { + "name": "notification_queue", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "audience": { + "name": "audience", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "port_forwards": { + "name": "port_forwards", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "external_port": { + "name": "external_port", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "protocol": { + "name": "protocol", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'tcp'" + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "destination": { + "name": "destination", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "internal_port": { + "name": "internal_port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "port_forwards_server_id_servers_id_fk": { + "name": "port_forwards_server_id_servers_id_fk", + "tableFrom": "port_forwards", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "push_subscriptions": { + "name": "push_subscriptions", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "p256dh": { + "name": "p256dh", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "auth": { + "name": "auth", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_success_at": { + "name": "last_success_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "min_severity": { + "name": "min_severity", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "categories": { + "name": "categories", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "push_subscriptions_endpoint_unique": { + "name": "push_subscriptions_endpoint_unique", + "columns": [ + "endpoint" + ], + "isUnique": true + } + }, + "foreignKeys": { + "push_subscriptions_user_id_users_id_fk": { + "name": "push_subscriptions_user_id_users_id_fk", + "tableFrom": "push_subscriptions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "restore_tests": { + "name": "restore_tests", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "subject_key": { + "name": "subject_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tested_at": { + "name": "tested_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "result": { + "name": "result", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tested_by": { + "name": "tested_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "restore_tests_subject_idx": { + "name": "restore_tests_subject_idx", + "columns": [ + "subject_key", + "tested_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "runbooks": { + "name": "runbooks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "runbooks_target_idx": { + "name": "runbooks_target_idx", + "columns": [ + "target_type", + "target_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "scheduled_tasks": { + "name": "scheduled_tasks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "schedule_type": { + "name": "schedule_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "origin": { + "name": "origin", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'agent'" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "command": { + "name": "command", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "schedule_expression": { + "name": "schedule_expression", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "next_run_at": { + "name": "next_run_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "raw_metadata": { + "name": "raw_metadata", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_stale": { + "name": "is_stale", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "first_seen_at": { + "name": "first_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "scheduled_tasks_server_id_servers_id_fk": { + "name": "scheduled_tasks_server_id_servers_id_fk", + "tableFrom": "scheduled_tasks", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "secrets": { + "name": "secrets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'generic'" + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expiry_date": { + "name": "expiry_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "warn_days": { + "name": "warn_days", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 30 + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "check_host": { + "name": "check_host", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "check_port": { + "name": "check_port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_checked_at": { + "name": "last_checked_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_check_error": { + "name": "last_check_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "server_links": { + "name": "server_links", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": { + "server_links_server_id_servers_id_fk": { + "name": "server_links_server_id_servers_id_fk", + "tableFrom": "server_links", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "server_metrics": { + "name": "server_metrics", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "metric": { + "name": "metric", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "recorded_at": { + "name": "recorded_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "server_metrics_lookup_idx": { + "name": "server_metrics_lookup_idx", + "columns": [ + "server_id", + "metric", + "recorded_at" + ], + "isUnique": false + } + }, + "foreignKeys": { + "server_metrics_server_id_servers_id_fk": { + "name": "server_metrics_server_id_servers_id_fk", + "tableFrom": "server_metrics", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "server_ports": { + "name": "server_ports", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "port": { + "name": "port", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "protocol": { + "name": "protocol", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'tcp'" + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "open": { + "name": "open", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "last_seen_open_at": { + "name": "last_seen_open_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "server_ports_unique": { + "name": "server_ports_unique", + "columns": [ + "server_id", + "port", + "protocol" + ], + "isUnique": true + } + }, + "foreignKeys": { + "server_ports_server_id_servers_id_fk": { + "name": "server_ports_server_id_servers_id_fk", + "tableFrom": "server_ports", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "servers": { + "name": "servers", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hostname": { + "name": "hostname", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "os_type": { + "name": "os_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'linux'" + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "api_token_hash": { + "name": "api_token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "api_token_prefix": { + "name": "api_token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ip_addresses": { + "name": "ip_addresses", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpu_model": { + "name": "cpu_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpu_cores": { + "name": "cpu_cores", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpu_load_percent": { + "name": "cpu_load_percent", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mem_total_bytes": { + "name": "mem_total_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mem_used_bytes": { + "name": "mem_used_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "disks": { + "name": "disks", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "listening_ports": { + "name": "listening_ports", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_port_scan": { + "name": "last_port_scan", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tags": { + "name": "tags", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxmox_integration_id": { + "name": "proxmox_integration_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxmox_node": { + "name": "proxmox_node", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxmox_guest_type": { + "name": "proxmox_guest_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "proxmox_vmid": { + "name": "proxmox_vmid", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hide_proxmox_link": { + "name": "hide_proxmox_link", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "parent_server_id": { + "name": "parent_server_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "no_parent": { + "name": "no_parent", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "pending_updates": { + "name": "pending_updates", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updates_pending_since": { + "name": "updates_pending_since", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "host_health": { + "name": "host_health", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "agent_diagnostics": { + "name": "agent_diagnostics", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hw_manufacturer": { + "name": "hw_manufacturer", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hw_model": { + "name": "hw_model", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hw_serial": { + "name": "hw_serial", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "thresholds": { + "name": "thresholds", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "agent_version": { + "name": "agent_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "servers_proxmox_integration_id_integrations_id_fk": { + "name": "servers_proxmox_integration_id_integrations_id_fk", + "tableFrom": "servers", + "tableTo": "integrations", + "columnsFrom": [ + "proxmox_integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "settings": { + "name": "settings", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "share_links": { + "name": "share_links", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'summary'" + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'wall'" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "expires_at": { + "name": "expires_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "share_links_token_hash_unique": { + "name": "share_links_token_hash_unique", + "columns": [ + "token_hash" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "status_items": { + "name": "status_items", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "link_id": { + "name": "link_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "monitor_id": { + "name": "monitor_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "status_items_link_idx": { + "name": "status_items_link_idx", + "columns": [ + "link_id", + "position" + ], + "isUnique": false + } + }, + "foreignKeys": { + "status_items_link_id_share_links_id_fk": { + "name": "status_items_link_id_share_links_id_fk", + "tableFrom": "status_items", + "tableTo": "share_links", + "columnsFrom": [ + "link_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tag_definitions": { + "name": "tag_definitions", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + } + }, + "indexes": { + "tag_definitions_name_unique": { + "name": "tag_definitions_name_unique", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "update_runs": { + "name": "update_runs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "server_id": { + "name": "server_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "integration_id": { + "name": "integration_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "template_name": { + "name": "template_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "host_limit": { + "name": "host_limit", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "task_id": { + "name": "task_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "task_status": { + "name": "task_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "window_id": { + "name": "window_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "window_created": { + "name": "window_created", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_by": { + "name": "started_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "task_ended_at": { + "name": "task_ended_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "host_reported_at": { + "name": "host_reported_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "finished_at": { + "name": "finished_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updates_before": { + "name": "updates_before", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updates_after": { + "name": "updates_after", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reboot_required": { + "name": "reboot_required", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "poll_errors": { + "name": "poll_errors", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": { + "update_runs_server_idx": { + "name": "update_runs_server_idx", + "columns": [ + "server_id", + "started_at" + ], + "isUnique": false + }, + "update_runs_status_idx": { + "name": "update_runs_status_idx", + "columns": [ + "status" + ], + "isUnique": false + } + }, + "foreignKeys": { + "update_runs_server_id_servers_id_fk": { + "name": "update_runs_server_id_servers_id_fk", + "tableFrom": "update_runs", + "tableTo": "servers", + "columnsFrom": [ + "server_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "oidc_sub": { + "name": "oidc_sub", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'viewer'" + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "last_login_at": { + "name": "last_login_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "favorites": { + "name": "favorites", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_looked_at": { + "name": "last_looked_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "groups": { + "name": "groups", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dashboard_layout": { + "name": "dashboard_layout", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "picture_url": { + "name": "picture_url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "users_oidc_sub_unique": { + "name": "users_oidc_sub_unique", + "columns": [ + "oidc_sub" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/server/drizzle/meta/_journal.json b/server/drizzle/meta/_journal.json index 64f4902..1c93813 100644 --- a/server/drizzle/meta/_journal.json +++ b/server/drizzle/meta/_journal.json @@ -288,6 +288,13 @@ "when": 1792357895858, "tag": "0040_petite_invaders", "breakpoints": true + }, + { + "idx": 41, + "version": "6", + "when": 1792359507903, + "tag": "0041_open_silvermane", + "breakpoints": true } ] } \ No newline at end of file diff --git a/server/src/app.ts b/server/src/app.ts index e8856a0..66f8999 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -47,6 +47,7 @@ import { alertsRouter } from "./routes/alerts.js"; import { mapRouter } from "./routes/map.js"; import { generatorRouter } from "./routes/generator.js"; import { alertTicketsRouter } from "./routes/alertTickets.js"; +import { avatarsRouter } from "./routes/avatars.js"; import { apiErrorHandler } from "./utils/apiErrorHandler.js"; import { securityHeaders } from "./utils/securityHeaders.js"; import { sameOriginGuard } from "./utils/sameOriginGuard.js"; @@ -103,6 +104,7 @@ export function createApp() { app.use("/auth", authRouter); app.use("/api/me", meRouter); + app.use("/api/avatars", avatarsRouter); app.use("/api/uptime", uptimeRouter); app.use("/api/share-links", shareLinksRouter); app.use("/api/runbooks", runbooksRouter); diff --git a/server/src/auth/router.ts b/server/src/auth/router.ts index fbeba86..9bc3460 100644 --- a/server/src/auth/router.ts +++ b/server/src/auth/router.ts @@ -11,6 +11,7 @@ import { users } from "../db/schema.js"; import { recordAudit } from "../services/audit.js"; import { verifyIdTokenSignature } from "./idToken.js"; import { rateLimit } from "../utils/rateLimit.js"; +import { pictureFromClaims } from "../services/avatars.js"; export const authRouter = Router(); @@ -130,7 +131,7 @@ authRouter.get("/callback", signInLimiter, async (req, res, next) => { console.warn(`[auth] roles follow groups, but the sign-in carried no "${signIn.groupsClaim}" claim — roles left as they are`); } - const { user, created, roleChange } = await upsertUserFromLogin({ sub: claims.sub, email, name, groups }); + const { user, created, roleChange } = await upsertUserFromLogin({ sub: claims.sub, email, name, groups, pictureUrl: pictureFromClaims(claimSources) }); if (roleChange) { await recordAudit({ actor: user, diff --git a/server/src/auth/users.ts b/server/src/auth/users.ts index 5bc18d5..ea1d77f 100644 --- a/server/src/auth/users.ts +++ b/server/src/auth/users.ts @@ -27,6 +27,8 @@ export async function upsertUserFromLogin(params: { email?: string; name?: string; groups?: string[] | null; + /** The identity provider's "picture" claim, when it gave one; left as it was when it did not. */ + pictureUrl?: string; }): Promise<{ user: typeof users.$inferSelect; created: boolean; roleChange?: RoleChange }> { const [existing] = await db.select().from(users).where(eq(users.oidcSub, params.sub)).limit(1); const now = new Date().toISOString(); @@ -55,6 +57,7 @@ export async function upsertUserFromLogin(params: { .set({ email: params.email ?? existing.email, name: params.name ?? existing.name, + pictureUrl: params.pictureUrl ?? existing.pictureUrl, lastLoginAt: now, role, ...(groupsJson !== undefined ? { groups: groupsJson } : {}), @@ -74,6 +77,7 @@ export async function upsertUserFromLogin(params: { oidcSub: params.sub, email: params.email, name: params.name, + pictureUrl: params.pictureUrl ?? null, role, lastLoginAt: now, ...(groupsJson !== undefined ? { groups: groupsJson } : {}), diff --git a/server/src/db/schema.ts b/server/src/db/schema.ts index f4b923a..6953e97 100644 --- a/server/src/db/schema.ts +++ b/server/src/db/schema.ts @@ -26,6 +26,9 @@ export const users = sqliteTable("users", { // How this person arranged the dashboard: a JSON object with the cards they hid ("hidden": ["Gitea"]) and the order of the others // ("order": {"DNS": 0, "Secrets": 1}). Follows them to any browser; null is the default layout. dashboardLayout: text("dashboard_layout"), + // The address of the picture the identity provider gave for this person (the OIDC "picture" claim), as of their last sign-in. Only an address: + // nothing is fetched from it unless Settings → Sign-in → Profile pictures allows it, and then only by this server, never by the browser. + pictureUrl: text("picture_url"), }); // ─── Audit log ────────────────────────────────────────────────────────────── diff --git a/server/src/routes/avatars.ts b/server/src/routes/avatars.ts new file mode 100644 index 0000000..4a937e5 --- /dev/null +++ b/server/src/routes/avatars.ts @@ -0,0 +1,29 @@ +import { Router } from "express"; +import { eq } from "drizzle-orm"; +import { db } from "../db/client.js"; +import { users } from "../db/schema.js"; +import { requireAuth } from "../auth/middleware.js"; +import { getAvatar } from "../services/avatars.js"; +import { getSettings } from "../services/settingsStore.js"; +import { asyncHandler } from "../utils/asyncHandler.js"; + +export const avatarsRouter = Router(); +avatarsRouter.use(requireAuth); + +// A person's profile picture, for anyone signed in (their names are shown to everyone already). The server asks Gravatar or the identity +// provider; the browser only ever talks to this app. 404 means "no picture": the page falls back to initials. With the setting off nothing is asked. +avatarsRouter.get("/:id", asyncHandler(async (req, res) => { + const id = /^\d+$/.test(req.params.id) ? Number(req.params.id) : NaN; + if (!Number.isSafeInteger(id)) return res.status(404).json({ error: "not_found" }); + const [person] = await db.select({ email: users.email, pictureUrl: users.pictureUrl }).from(users).where(eq(users.id, id)).limit(1); + if (!person) return res.status(404).json({ error: "not_found" }); + + const image = await getAvatar(person, (await getSettings()).profilePictures); + if (!image) return res.status(404).json({ error: "no_picture" }); + + res.setHeader("Content-Type", image.contentType); + // Kept an hour by the browser: short enough that turning the setting off, or a new picture, is not long in showing. + res.setHeader("Cache-Control", "private, max-age=3600"); + res.setHeader("Content-Security-Policy", "default-src 'none'; sandbox"); + res.send(image.body); +})); diff --git a/server/src/routes/me.ts b/server/src/routes/me.ts index f1bf82c..5ca4dbf 100644 --- a/server/src/routes/me.ts +++ b/server/src/routes/me.ts @@ -6,6 +6,8 @@ import { users } from "../db/schema.js"; import { requireAuth } from "../auth/middleware.js"; import { asyncHandler } from "../utils/asyncHandler.js"; import { FIRST_LOOKBACK_MS, getChangesSince } from "../services/changesSince.js"; +import { avatarUrlFor } from "../services/avatars.js"; +import { getSettings } from "../services/settingsStore.js"; export const meRouter = Router(); @@ -36,10 +38,12 @@ export function parseDashboardLayout(stored: string | null): DashboardLayout { } } -meRouter.get("/", requireAuth, (req, res) => { - const { id, email, name, role, oidcSub, favorites, dashboardLayout } = req.currentUser!; - res.json({ user: { id, sub: oidcSub, email, name, role, favorites: parseFavorites(favorites), dashboard: parseDashboardLayout(dashboardLayout) } }); -}); +meRouter.get("/", requireAuth, asyncHandler(async (req, res) => { + const me = req.currentUser!; + const { id, email, name, role, oidcSub, favorites, dashboardLayout } = me; + const avatarUrl = avatarUrlFor(me, (await getSettings()).profilePictures); + res.json({ user: { id, sub: oidcSub, email, name, role, avatarUrl, favorites: parseFavorites(favorites), dashboard: parseDashboardLayout(dashboardLayout) } }); +})); // Paths inside the app only: a slash, then letters, digits, dashes, underscores and further slashes — and, for a saved view of a page, // a short query of the characters a browser leaves as they are or percent-encodes (the search words, a status, a sort). Which of them diff --git a/server/src/routes/privacy.ts b/server/src/routes/privacy.ts index 43fee3c..f5642cc 100644 --- a/server/src/routes/privacy.ts +++ b/server/src/routes/privacy.ts @@ -7,6 +7,7 @@ import { recordAudit } from "../services/audit.js"; import { getSettings } from "../services/settingsStore.js"; import { listSessions } from "../services/sessionStore.js"; import { asyncHandler } from "../utils/asyncHandler.js"; +import { env } from "../env.js"; export const privacyRouter = Router(); privacyRouter.use(requireAuth); @@ -46,7 +47,7 @@ privacyRouter.get("/", asyncHandler(async (req, res) => { res.json({ me: { - user: { email: me.email, name: me.name, role: me.role, subject: me.oidcSub, createdAt: me.createdAt, lastLoginAt: me.lastLoginAt }, + user: { email: me.email, name: me.name, role: me.role, subject: me.oidcSub, createdAt: me.createdAt, lastLoginAt: me.lastLoginAt, pictureUrl: me.pictureUrl }, auditEntries, sessions: await ownSessions(me.oidcSub, req.sessionID), }, @@ -58,6 +59,7 @@ privacyRouter.get("/", asyncHandler(async (req, res) => { tlsCertificateChecks: tlsChecks, servers: serverCount, serversWithAgent: agentCount, + profilePictures: { ...settings.profilePictures, identityProviderHost: isAdmin ? hostOf(env.authentik.issuerUrl) : null }, channels: { gotify: channel(settings.gotify.enabled, hostOf(settings.gotify.url)), ntfy: channel(settings.ntfy.enabled, hostOf(settings.ntfy.url)), @@ -84,7 +86,7 @@ privacyRouter.get("/export", asyncHandler(async (req, res) => { const body = { exportedAt: new Date().toISOString(), note: "Everything Homelab Manager holds that is specifically about you. Other people's data, server data and shared inventory are not included.", - account: { email: row.email, name: row.name, role: row.role, subject: row.oidcSub, createdAt: row.createdAt, lastLoginAt: row.lastLoginAt }, + account: { email: row.email, name: row.name, role: row.role, subject: row.oidcSub, createdAt: row.createdAt, lastLoginAt: row.lastLoginAt, pictureUrl: row.pictureUrl }, sessions: await ownSessions(me.oidcSub, req.sessionID), auditLog: entries.map((e) => ({ ...e, detail: e.detail ? safeJson(e.detail) : null })), }; diff --git a/server/src/routes/settings.ts b/server/src/routes/settings.ts index 72124e0..86f0342 100644 --- a/server/src/routes/settings.ts +++ b/server/src/routes/settings.ts @@ -160,6 +160,7 @@ const updateSchema = z.object({ }) .partial() .optional(), + profilePictures: z.object({ gravatar: z.boolean(), identityProvider: z.boolean() }).partial().optional(), digest: z .object({ enabled: z.boolean(), day: z.number().int().min(0).max(6), time: z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/) }) .partial() diff --git a/server/src/routes/users.ts b/server/src/routes/users.ts index 846c94e..6fd2200 100644 --- a/server/src/routes/users.ts +++ b/server/src/routes/users.ts @@ -8,6 +8,7 @@ import { recordAudit } from "../services/audit.js"; import { asyncHandler } from "../utils/asyncHandler.js"; import { getSettings } from "../services/settingsStore.js"; import { roleFromGroups } from "../auth/groups.js"; +import { avatarUrlFor } from "../services/avatars.js"; export const usersRouter = Router(); @@ -26,9 +27,9 @@ export function parseGroups(stored: string | null): string[] | null { usersRouter.get("/", asyncHandler(async (_req, res) => { const rows = await db.select().from(users).orderBy(users.createdAt); - const { signIn } = await getSettings(); + const { signIn, profilePictures } = await getSettings(); res.json({ - users: rows.map((u) => ({ id: u.id, oidcSub: u.oidcSub, email: u.email, name: u.name, role: u.role, createdAt: u.createdAt, lastLoginAt: u.lastLoginAt, groups: parseGroups(u.groups) })), + users: rows.map((u) => ({ id: u.id, oidcSub: u.oidcSub, email: u.email, name: u.name, role: u.role, createdAt: u.createdAt, lastLoginAt: u.lastLoginAt, groups: parseGroups(u.groups), avatarUrl: avatarUrlFor(u, profilePictures) })), // When roles follow groups, a role set by hand would be undone at the next sign-in, so the page says so instead of offering it. rolesFollowGroups: signIn.roleFromGroups, }); diff --git a/server/src/services/avatars.ts b/server/src/services/avatars.ts new file mode 100644 index 0000000..43c2857 --- /dev/null +++ b/server/src/services/avatars.ts @@ -0,0 +1,186 @@ +/** + * Profile pictures, fetched and kept by this server so that people's browsers never contact an outside address. + * + * Where a picture can come from (Settings → Sign-in → Profile pictures, both off until an administrator turns them on): + * - the identity provider's own "picture" claim, tried first, and + * - Gravatar, by a SHA-256 hash of the person's email address (never the address itself). + * + * The server only ever asks the hosts it is allowed to: gravatar.com, and the identity provider's own host. A "picture" claim naming anywhere + * else is ignored, so a claim cannot be used to make the server fetch an arbitrary address. What comes back must be a small PNG, JPEG, WebP or + * GIF — never SVG, which can carry script and would be served from this app's own origin. + */ +import { createHash } from "node:crypto"; +import { env } from "../env.js"; +import type { ProfilePictureSettings } from "./settingsStore.js"; + +/** What the server will accept as a picture. */ +const MAX_BYTES = 256 * 1024; +const TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]); +const FETCH_TIMEOUT_MS = 4000; +const MAX_REDIRECTS = 2; +const FOUND_TTL_MS = 24 * 3600_000; +/** Someone with no picture is asked about again after this, so adding one shows up the same day without asking every page view. */ +const MISSING_TTL_MS = 3600_000; +/** A host that could not be reached is tried again soon. */ +const FAILED_TTL_MS = 5 * 60_000; +const MAX_CACHED = 200; + +export interface AvatarImage { + contentType: string; + body: Buffer; +} + +export type AvatarFetcher = (url: string) => Promise; + +const realFetcher: AvatarFetcher = (url) => + fetch(url, { redirect: "manual", signal: AbortSignal.timeout(FETCH_TIMEOUT_MS), headers: { accept: [...TYPES].join(", "), "user-agent": "HomelabManager" } }); + +let fetcher: AvatarFetcher = realFetcher; +/** Tests stand in for the network. */ +export function setAvatarFetcherForTests(f: AvatarFetcher | null): void { + fetcher = f ?? realFetcher; + cache.clear(); +} + +/** A person's email as Gravatar wants it: trimmed, lower case, SHA-256. */ +export function gravatarHash(email: string): string { + return createHash("sha256").update(email.trim().toLowerCase()).digest("hex"); +} + +export function gravatarUrl(email: string): string { + return `https://gravatar.com/avatar/${gravatarHash(email)}?s=128&d=404`; +} + +function issuerHost(): string | null { + try { + return new URL(env.authentik.issuerUrl).host.toLowerCase(); + } catch { + return null; + } +} + +const isGravatarHost = (host: string) => host === "gravatar.com" || host.endsWith(".gravatar.com"); + +/** Whether the server may ask this address for a picture: Gravatar over HTTPS, or the identity provider's own host. */ +export function isAllowedPictureUrl(raw: string, idpHost: string | null = issuerHost()): boolean { + let url: URL; + try { + url = new URL(raw); + } catch { + return false; + } + const host = url.host.toLowerCase(); + if (url.username || url.password) return false; + if (isGravatarHost(url.hostname.toLowerCase())) return url.protocol === "https:"; + return idpHost !== null && host === idpHost && (url.protocol === "https:" || url.protocol === "http:"); +} + +/** The "picture" claim, if it is an address at all; kept as given and judged again whenever it is used. */ +export function pictureFromClaims(sources: Record[]): string | undefined { + for (const source of sources) { + const value = source.picture; + if (typeof value !== "string") continue; + const trimmed = value.trim(); + if (trimmed.length === 0 || trimmed.length > 500) continue; + try { + const url = new URL(trimmed); + if (url.protocol === "https:" || url.protocol === "http:") return trimmed; + } catch { + // not an address + } + } + return undefined; +} + +/** The addresses this person's picture may be fetched from under the current settings, in the order they are tried. */ +export function avatarSources(user: { email: string | null; pictureUrl: string | null }, settings: ProfilePictureSettings, idpHost: string | null = issuerHost()): string[] { + const out: string[] = []; + if (settings.identityProvider && user.pictureUrl && isAllowedPictureUrl(user.pictureUrl, idpHost)) { + // A claim that names Gravatar is Gravatar all the same: it needs that switched on too. + let host = ""; + try { + host = new URL(user.pictureUrl).hostname.toLowerCase(); + } catch { + // judged above + } + if (!isGravatarHost(host) || settings.gravatar) out.push(user.pictureUrl); + } + if (settings.gravatar && user.email && user.email.includes("@")) out.push(gravatarUrl(user.email)); + return [...new Set(out)]; +} + +/** The address the browser asks this server for, or null when there is no picture to look for. `v` changes with the source so a new one is not hidden by the browser's copy. */ +export function avatarUrlFor(user: { id: number; email: string | null; pictureUrl: string | null }, settings: ProfilePictureSettings): string | null { + const sources = avatarSources(user, settings); + if (sources.length === 0) return null; + return `/api/avatars/${user.id}?v=${createHash("sha256").update(sources.join("\n")).digest("hex").slice(0, 8)}`; +} + +// ─── Fetching and keeping ────────────────────────────────────────────────── + +interface Entry { + until: number; + image: AvatarImage | null; +} +const cache = new Map(); + +function remember(url: string, image: AvatarImage | null, ttl: number): void { + cache.delete(url); + cache.set(url, { until: Date.now() + ttl, image }); + while (cache.size > MAX_CACHED) cache.delete(cache.keys().next().value as string); +} + +/** One picture from one address: followed through at most two redirects, only to addresses that are allowed too. */ +async function download(start: string): Promise<{ image: AvatarImage | null; failed: boolean }> { + let url = start; + for (let hop = 0; hop <= MAX_REDIRECTS; hop++) { + let res: Response; + try { + res = await fetcher(url); + } catch { + return { image: null, failed: true }; + } + if (res.status >= 300 && res.status < 400) { + const location = res.headers.get("location"); + let next: string | null = null; + try { + next = location ? new URL(location, url).toString() : null; + } catch { + next = null; + } + if (!next || !isAllowedPictureUrl(next)) return { image: null, failed: false }; + url = next; + continue; + } + if (res.status >= 500) return { image: null, failed: true }; + if (!res.ok) return { image: null, failed: false }; + const type = (res.headers.get("content-type") ?? "").split(";")[0].trim().toLowerCase(); + if (!TYPES.has(type)) return { image: null, failed: false }; + const declared = Number(res.headers.get("content-length")); + if (Number.isFinite(declared) && declared > MAX_BYTES) return { image: null, failed: false }; + let body: Buffer; + try { + body = Buffer.from(await res.arrayBuffer()); + } catch { + return { image: null, failed: true }; + } + if (body.length === 0 || body.length > MAX_BYTES) return { image: null, failed: false }; + return { image: { contentType: type, body }, failed: false }; + } + return { image: null, failed: false }; +} + +/** The first of this person's sources that has a picture, from the keep or from the source itself. Null when none does. */ +export async function getAvatar(user: { email: string | null; pictureUrl: string | null }, settings: ProfilePictureSettings): Promise { + for (const source of avatarSources(user, settings)) { + const kept = cache.get(source); + if (kept && kept.until > Date.now()) { + if (kept.image) return kept.image; + continue; + } + const { image, failed } = await download(source); + remember(source, image, image ? FOUND_TTL_MS : failed ? FAILED_TTL_MS : MISSING_TTL_MS); + if (image) return image; + } + return null; +} diff --git a/server/src/services/settingsStore.ts b/server/src/services/settingsStore.ts index 47a36cb..a4a695b 100644 --- a/server/src/services/settingsStore.ts +++ b/server/src/services/settingsStore.ts @@ -135,6 +135,17 @@ export interface SignInSettings { otherwise: "viewer" | "keep"; } +/** + * Where people's profile pictures may come from. Both are off until an administrator turns them on, because each means this server asks an + * outside address for a picture (Gravatar is told a hash of the person's email). The browser never does: pictures are fetched and kept by the server. + */ +export interface ProfilePictureSettings { + /** gravatar.com, by a hash of the person's email address. */ + gravatar: boolean; + /** The picture the identity provider (Authentik) names for the person in its "picture" claim. */ + identityProvider: boolean; +} + /** How the agents out on the servers are kept up to date. Off until an administrator turns it on. */ export interface AgentSettings { /** An agent that is behind downloads the newer script from this app, checks it and replaces itself. */ @@ -215,6 +226,7 @@ export interface AppSettings { healthChecks: HealthCheckSettings; digest: DigestSettings; signIn: SignInSettings; + profilePictures: ProfilePictureSettings; inventory: InventorySettings; selfBackup: SelfBackupSettings; agents: AgentSettings; @@ -258,6 +270,7 @@ const DEFAULTS: AppSettings = { inventory: { currency: "", pricePerKwh: null }, agents: { autoUpdate: false }, selfBackup: { enabled: true, time: "03:30", keep: 14 }, + profilePictures: { gravatar: false, identityProvider: false }, signIn: { roleFromGroups: false, groupsClaim: "groups", adminGroups: [], operatorGroups: [], otherwise: "viewer" }, healthChecks: { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0 }, // Docker's default bridge (172.17.0.0/16) and the pool it hands custom networks from (172.18–31) live here, and every diff --git a/server/test/avatars.test.ts b/server/test/avatars.test.ts new file mode 100644 index 0000000..48238f6 --- /dev/null +++ b/server/test/avatars.test.ts @@ -0,0 +1,252 @@ +/** + * Profile pictures: where they may come from, what is accepted, that nothing is asked of anyone while the settings are off, and that the + * browser only ever talks to this app. + * + * Run with: npm test --workspace server + */ +import { test, describe, before, after, beforeEach } from "node:test"; +import assert from "node:assert/strict"; +import { createHash } from "node:crypto"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import type { AddressInfo } from "node:net"; +import type { Server } from "node:http"; + +const dir = mkdtempSync(join(tmpdir(), "hm-avatars-")); +process.env.DATABASE_PATH = join(dir, "test.sqlite"); +process.env.SESSION_DIR = join(dir, "sessions"); +process.env.CREDENTIALS_ENCRYPTION_KEY = "ab".repeat(32); +process.env.HEALTH_STARTUP_GRACE_MS = "0"; +process.env.AUTHENTIK_ISSUER_URL = "https://auth.example.lan/application/o/homelab/"; + +const express = (await import("express")).default; +const { db } = await import("../src/db/client.js"); +const { users } = await import("../src/db/schema.js"); +const { runMigrations } = await import("../src/db/migrate.js"); +const { avatarsRouter } = await import("../src/routes/avatars.js"); +const { meRouter } = await import("../src/routes/me.js"); +const { usersRouter } = await import("../src/routes/users.js"); +const { upsertUserFromLogin } = await import("../src/auth/users.js"); +const { updateSettings } = await import("../src/services/settingsStore.js"); +const { gravatarHash, gravatarUrl, isAllowedPictureUrl, pictureFromClaims, avatarSources, avatarUrlFor, getAvatar, setAvatarFetcherForTests } = await import("../src/services/avatars.js"); + +await runMigrations(); + +const IDP = "auth.example.lan"; +const PNG = Buffer.from("89504e470d0a1a0a0000000d49484452", "hex"); +const none = { gravatar: false, identityProvider: false }; +const both = { gravatar: true, identityProvider: true }; + +describe("where a picture may come from", () => { + test("Gravatar gets a hash of the address — trimmed, lower case, SHA-256 — never the address itself", () => { + const hash = createHash("sha256").update("olga@example.com").digest("hex"); + assert.equal(gravatarHash(" Olga@Example.COM "), hash); + assert.equal(gravatarUrl("Olga@example.com"), `https://gravatar.com/avatar/${hash}?s=128&d=404`); + assert.equal(gravatarUrl("Olga@example.com").includes("olga"), false); + }); + + test("only Gravatar over HTTPS and the identity provider's own host are allowed", () => { + assert.equal(isAllowedPictureUrl("https://gravatar.com/avatar/abc", IDP), true); + assert.equal(isAllowedPictureUrl("https://secure.gravatar.com/avatar/abc", IDP), true); + assert.equal(isAllowedPictureUrl("http://gravatar.com/avatar/abc", IDP), false, "Gravatar only over HTTPS"); + assert.equal(isAllowedPictureUrl("https://auth.example.lan/media/me.png", IDP), true); + assert.equal(isAllowedPictureUrl("http://auth.example.lan/media/me.png", IDP), true, "the provider's own host may be plain HTTP on a LAN"); + for (const bad of ["https://evil.example/me.png", "https://gravatar.com.evil.example/a", "https://evilgravatar.com/a", "http://169.254.169.254/latest", "https://user:pw@auth.example.lan/x", "file:///etc/passwd", "not a url"]) { + assert.equal(isAllowedPictureUrl(bad, IDP), false, bad); + } + assert.equal(isAllowedPictureUrl("https://auth.example.lan/x", null), false, "with no provider known, only Gravatar"); + }); + + test("the picture claim is read from the ID token or userinfo, and only if it is an address", () => { + assert.equal(pictureFromClaims([{ sub: "a" }, { picture: "https://auth.example.lan/media/me.png" }]), "https://auth.example.lan/media/me.png"); + assert.equal(pictureFromClaims([{ picture: "not an address" }, { picture: "https://x.example/p.png" }]), "https://x.example/p.png", "an unusable claim is skipped for a usable one"); + assert.equal(pictureFromClaims([{ picture: "javascript:alert(1)" }, { picture: 5 }, { picture: "" }, { picture: "https://x/" + "a".repeat(600) }]), undefined); + }); + + test("the provider's picture is tried before Gravatar; each needs its own setting; a claim naming Gravatar needs Gravatar on", () => { + const user = { email: "olga@example.com", pictureUrl: "https://auth.example.lan/media/olga.png" }; + assert.deepEqual(avatarSources(user, none, IDP), []); + assert.deepEqual(avatarSources(user, { gravatar: false, identityProvider: true }, IDP), ["https://auth.example.lan/media/olga.png"]); + assert.deepEqual(avatarSources(user, { gravatar: true, identityProvider: false }, IDP), [gravatarUrl("olga@example.com")]); + assert.deepEqual(avatarSources(user, both, IDP), ["https://auth.example.lan/media/olga.png", gravatarUrl("olga@example.com")]); + const viaGravatar = { email: null, pictureUrl: gravatarUrl("olga@example.com") }; + assert.deepEqual(avatarSources(viaGravatar, { gravatar: false, identityProvider: true }, IDP), [], "that would tell Gravatar all the same"); + assert.deepEqual(avatarSources(viaGravatar, both, IDP), [gravatarUrl("olga@example.com")], "and one address is not asked twice"); + assert.deepEqual(avatarSources({ email: "no-at-sign", pictureUrl: "https://evil.example/x.png" }, both, IDP), [], "a claim naming anywhere else, and no address, is no source"); + }); + + test("the address the page uses changes when the source does, and is null with nothing to look for", () => { + const a = avatarUrlFor({ id: 7, email: "a@example.com", pictureUrl: null }, { gravatar: true, identityProvider: false })!; + const b = avatarUrlFor({ id: 7, email: "b@example.com", pictureUrl: null }, { gravatar: true, identityProvider: false })!; + assert.match(a, /^\/api\/avatars\/7\?v=[0-9a-f]{8}$/); + assert.notEqual(a, b); + assert.equal(avatarUrlFor({ id: 7, email: "a@example.com", pictureUrl: null }, none), null); + }); +}); + +describe("fetching and keeping", () => { + let calls: string[] = []; + const image = (type = "image/png", body: Buffer = PNG) => new Response(body, { status: 200, headers: { "content-type": type } }); + const answer = (fn: (url: string) => Response) => setAvatarFetcherForTests(async (url) => (calls.push(url), fn(url))); + const user = { email: "olga@example.com", pictureUrl: null }; + const on = { gravatar: true, identityProvider: false }; + + beforeEach(() => { + calls = []; + }); + after(() => setAvatarFetcherForTests(null)); + + test("nothing is asked of anyone while both settings are off", async () => { + answer(() => image()); + assert.equal(await getAvatar(user, none), null); + assert.deepEqual(calls, []); + }); + + test("a picture comes back with its type, and is kept so the next ask does not go out again", async () => { + answer(() => image()); + const first = await getAvatar(user, on); + assert.equal(first?.contentType, "image/png"); + assert.deepEqual(first?.body, PNG); + await getAvatar(user, on); + assert.equal(calls.length, 1); + assert.equal(calls[0], gravatarUrl("olga@example.com")); + }); + + test("no picture (404) is kept for a while too, and falls through to the next source", async () => { + answer((url) => (url.includes("auth.example.lan") ? new Response("", { status: 404 }) : image("image/jpeg"))); + const both_ = { user: { email: "olga@example.com", pictureUrl: "https://auth.example.lan/media/olga.png" }, settings: both }; + assert.equal((await getAvatar(both_.user, both_.settings))?.contentType, "image/jpeg", "the provider had none, so Gravatar's"); + await getAvatar(both_.user, both_.settings); + assert.equal(calls.filter((c) => c.includes("auth.example.lan")).length, 1, "the provider is not asked again straight away"); + }); + + test("only small PNG, JPEG, WebP and GIF are accepted — not SVG, not HTML, not something huge", async () => { + answer(() => image("image/svg+xml", Buffer.from(""))); + assert.equal(await getAvatar({ email: "svg@example.com", pictureUrl: null }, on), null); + answer(() => image("text/html", Buffer.from(" + ); +} diff --git a/web/src/layout/AppShell.tsx b/web/src/layout/AppShell.tsx index e7d99de..af84acc 100644 --- a/web/src/layout/AppShell.tsx +++ b/web/src/layout/AppShell.tsx @@ -16,6 +16,7 @@ import { useStackedTables } from "../hooks/useStackedTables"; import { useShortcuts } from "../hooks/useShortcuts"; import { useFormLabels } from "../hooks/useFormLabels"; import ShortcutHelp from "../components/ShortcutHelp"; +import Avatar from "../components/Avatar"; import { useBreadcrumbTailValue } from "../utils/breadcrumb"; const RAIL_KEY = "hlm-sidebar-rail"; @@ -33,12 +34,6 @@ function useMediaQuery(query: string): boolean { return matches; } -/** Up to two initials for the little avatar in the user menu. */ -function initialsOf(name: string): string { - const words = name.replace(/@.*$/, "").split(/[\s._-]+/).filter(Boolean); - return (words.length > 1 ? words[0][0] + words[1][0] : (words[0] ?? "?").slice(0, 2)).toUpperCase(); -} - const OPEN_GROUPS_KEY = "hlm-nav-open-groups"; function loadOpenGroups(): Set { @@ -326,7 +321,7 @@ export default function AppShell({ user, children }: { user: CurrentUser; childr title={user.email ?? undefined} onClick={() => setMenuOpen((open) => !open)} > - {initialsOf(user.name ?? user.email ?? user.sub)} + {user.name ?? user.email ?? user.sub} {user.role} diff --git a/web/src/pages/Privacy.tsx b/web/src/pages/Privacy.tsx index 957d437..ec49e51 100644 --- a/web/src/pages/Privacy.tsx +++ b/web/src/pages/Privacy.tsx @@ -260,6 +260,20 @@ export default function Privacy() { Certificate checks — for {outbound?.tlsCertificateChecks ?? 0} secret{outbound?.tlsCertificateChecks === 1 ? "" : "s"} with a host to check, the app connects to that host to read its certificate — never to this server itself, a loopback or link-local address, or a cloud metadata address. +
  • + Profile pictures —{" "} + {outbound && (outbound.profilePictures.gravatar || outbound.profilePictures.identityProvider) ? ( + <> + this server fetches pictures + {outbound.profilePictures.identityProvider ? ` from the identity provider${outbound.profilePictures.identityProviderHost ? ` (${outbound.profilePictures.identityProviderHost})` : ""}` : ""} + {outbound.profilePictures.identityProvider && outbound.profilePictures.gravatar ? " and" : ""} + {outbound.profilePictures.gravatar ? " from Gravatar, which is sent a hash of each person's email address and sees this server's IP address" : ""}. Your browser never + contacts either: it asks this app, which keeps each picture for a day. + + ) : ( + "switched off, so nothing is fetched. People are shown as their initials." + )} +
  • Skatteverket — only when an admin clicks "Import from Skatteverket" under Settings → Names, the app asks Skatteverket's open name statistics for the most common given names. The request carries a sex and a birth year, nothing about you diff --git a/web/src/pages/Users.tsx b/web/src/pages/Users.tsx index 1ebefeb..527079d 100644 --- a/web/src/pages/Users.tsx +++ b/web/src/pages/Users.tsx @@ -9,6 +9,7 @@ import { ErrorNotice } from "../components/Notice"; import { SearchBox } from "../components/TableToolbar"; import { useTableSearch } from "../hooks/useTableSearch"; import { EmptyRow, LoadingRow } from "../components/EmptyState"; +import Avatar from "../components/Avatar"; const ROLES: UserRole[] = ["viewer", "operator", "admin"]; @@ -95,7 +96,12 @@ export default function Users() { {sorted?.map((u) => ( - {u.name ?? "—"} + + + + {u.name ?? "—"} + + {u.email ?? "—"} setPictures({ ...pictures, identityProvider: e.target.checked })} /> + + The picture the identity provider gives + + The picture claim from Authentik, kept at each sign-in. Only addresses on Authentik's own host (or Gravatar, if that is allowed too) are used. + + + + + + + {preview && (
    diff --git a/web/src/styles.css b/web/src/styles.css index 57190ec..2e86393 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -149,6 +149,14 @@ html[data-env] .navbar-vertical { background: color-mix(in srgb, currentColor 14%, transparent); } +/* A profile picture fills the little circle; without one the circle holds initials. */ +.avatar .avatar-img { + width: 100%; + height: 100%; + object-fit: cover; + border-radius: inherit; +} + .user-menu-who { flex: 1; min-width: 0;