Add an admin page for managing collector API keys
Admins (Microsoft 365 sign-in names in BACKUP_DASH_ADMINS) get an Admin link to /admin.html, where they can create, list and revoke the API keys collectors use, instead of running manage.py on the server. Backend - /api/v1/admin/keys (list, create, revoke), admins only (403 otherwise); the user comes from the headers nginx sets after sign-in - Changes need an X-Requested-By header, which another site's page can't add, so a signed-in admin's browser can't be used to forge them - A new key is returned once; only its hash is stored. Names are unique for good, so revoked keys' history stays unambiguous - Keys record who created/revoked them and the company they last reported for (schema v2; databases migrate automatically on start) - /api/v1/me reports is_admin; manage.py shares the key code and records itself as creator/revoker Frontend - admin.html / admin.js: name validation shown after interaction (:user-invalid, aria-invalid kept in sync), the one-time key with a copy button (falls back to selecting it if clipboard access is refused), a key table flagging keys quiet for over 24 hours, and revoking confirmed in a <dialog>; results announced in a status region - Shared el() and signed-in helpers moved to dom.js / signed-in.js - Mock mode (?mock=1) includes sample keys Tested: 15 new backend tests (access, forged requests, names, duplicates, revoking, last-used company, v1 -> v2 upgrade); in the browser, every admin flow in mock mode and at phone width; end to end through the nginx config with the real API (a key created on the API works for ingest; revoking it makes ingest 401; non-admins see an explanation and no Admin link). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+78
-1
@@ -344,4 +344,81 @@ button.badge:hover { filter: brightness(0.95); }
|
||||
}
|
||||
.runs tbody tr:last-child td { border-bottom: none; }
|
||||
.runs tr.is-selected td { background: color-mix(in srgb, var(--accent) 16%, transparent); }
|
||||
.runs .badge { font-size: 0.75rem; padding: 0.1rem 0.5rem; }
|
||||
.runs .badge { font-size: 0.75rem; padding: 0.1rem 0.5rem; }
|
||||
/* ---------- Admin page ---------- */
|
||||
.container--narrow { max-width: 1100px; }
|
||||
.topbar__nav { display: flex; align-items: center; gap: 1rem; }
|
||||
|
||||
.banner--info { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
|
||||
|
||||
.panel {
|
||||
margin-bottom: 1.5rem;
|
||||
padding: 1rem 1.25rem 1.25rem;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
.panel__title { font-size: 1.05rem; margin: 0 0 0.25rem; }
|
||||
section > .panel__title { margin: 0 0 0.75rem; }
|
||||
.panel__title:focus { outline: none; } /* focused from script after a change, not by the user */
|
||||
.panel p { margin: 0 0 0.75rem; }
|
||||
|
||||
code {
|
||||
font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
|
||||
font-size: 0.9em;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
/* New key form: label, hint above the input (so autocomplete can't cover it), error below */
|
||||
.new-key { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; }
|
||||
.field { display: flex; flex-direction: column; gap: 0.25rem; flex: 1 1 22rem; max-width: 30rem; }
|
||||
.field label { font-weight: 600; }
|
||||
.hint { font-size: 0.85rem; color: var(--muted); }
|
||||
.field .input { width: 100%; }
|
||||
.error-msg { display: none; font-size: 0.85rem; color: var(--failed-fg); }
|
||||
/* Only after the user has interacted with the field (or tried to submit) */
|
||||
.field .input:user-invalid { border-color: var(--failed-bd); background: var(--failed-bg); }
|
||||
.field .input:user-invalid + .error-msg { display: block; }
|
||||
.form-error { flex-basis: 100%; margin: 0; color: var(--failed-fg); }
|
||||
|
||||
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
|
||||
.btn--primary:hover { filter: brightness(1.08); border-color: var(--accent); }
|
||||
.btn--danger { background: var(--failed-bd); border-color: var(--failed-bd); color: #fff; font-weight: 600; }
|
||||
.btn--danger-outline { color: var(--failed-fg); border-color: var(--failed-bd); background: transparent; }
|
||||
.btn--danger-outline:hover { background: var(--failed-bg); border-color: var(--failed-bd); }
|
||||
|
||||
/* The one-time key */
|
||||
.secret {
|
||||
margin-top: 1rem;
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--warning-bd);
|
||||
border-left-width: 4px;
|
||||
border-radius: 6px;
|
||||
background: var(--warning-bg);
|
||||
}
|
||||
.secret__title { margin: 0 0 0.5rem; font-size: 1rem; }
|
||||
.secret__title:focus { outline: none; }
|
||||
.secret__row { display: flex; gap: 0.5rem; align-items: stretch; margin-bottom: 0.75rem; flex-wrap: wrap; }
|
||||
.secret__value {
|
||||
flex: 1 1 20rem;
|
||||
padding: 0.45rem 0.75rem;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
user-select: all; /* one click selects the whole key */
|
||||
}
|
||||
|
||||
/* Key table */
|
||||
.keys td { vertical-align: top; }
|
||||
.keys td .badge { margin-bottom: 0.25rem; }
|
||||
.keys td > .time__rel { display: block; }
|
||||
.keys .actions { text-align: right; width: 1%; }
|
||||
.keys tr.is-revoked td { color: var(--muted); }
|
||||
.keys tr.is-revoked code { text-decoration: line-through; }
|
||||
.stale-note { display: block; font-size: 0.8rem; font-weight: 600; color: var(--warning-fg); }
|
||||
|
||||
/* Confirm dialog */
|
||||
.modal--small { width: min(460px, calc(100vw - 2rem)); }
|
||||
.modal--small .modal__body p { margin-top: 0; }
|
||||
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
|
||||
|
||||
Reference in New Issue
Block a user