Files
steve c8ead66f08 P1 polish: agent-as-root, init-repo flow, rest creds passthrough, UX fixes
Cohesive batch from a smoke-test session against a real rest-server.
Themed bullets:

* Agent runs as root, sandboxed via systemd. CapabilityBoundingSet
  drops to CAP_DAC_READ_SEARCH + restore caps; ProtectSystem=strict
  with ReadWritePaths confined to /etc + /var/lib/restic-manager;
  NoNewPrivileges blocks escalation. Install script no longer
  creates a service user. spec.md §4.2 / §14.1 / §14.3 explain the
  rationale (matches UrBackup / Veeam / Bareos defaults; trying to
  back up "everything" as an unprivileged user creates silent skips
  on /home, /root, /var/lib/* with no upside vs the threat model
  the agent already implies).

* Init-repo end-to-end. New JobKind="init" wired through agent
  runner, restic.Env.RunInit, server dispatcher, and a UI button
  (red "Initialise repo" in the run-now panel). hosts.repo_initialised_at
  flips on init success, on backup success, or on a non-empty
  snapshots.report. The "Run now" / "Init" / "Retry" branching now
  drives both the dashboard host row and the host-detail panel.
  Migrations 0004 (column), 0005 (jobs.kind CHECK widened — using
  the safe create-new-then-rename pattern; first version corrupted
  job_logs.job_id FK), 0006 (cleans up job_logs FK on already-
  affected DBs).

* rest-server creds embedded at exec time only. restic.Env gains
  RepoUsername; mergeRestCreds() builds the user:pass@-prefixed URL
  inside envSlice() and never assigns it back to the struct, so
  nothing slog-able ever sees the cleartext form. RedactURL helper
  for any future surface that needs to log a URL safely. Both
  helpers tested.

* Add-host UX. Repo password is now optional — server mints a
  24-byte URL-safe random one and surfaces it once, alongside an
  htpasswd snippet ("echo PASS | htpasswd -B -i ... USERNAME") so
  the operator pastes one command on the rest-server host and one
  on the endpoint. Result page also links the install snippet at
  /install/install.sh (was /install.sh — 404'd before) and pipes
  to bash (not sh — script uses set -o pipefail and other
  bashisms; on Debian/Ubuntu sh is dash).

* Late-subscriber race in JobHub. A fast-failing job could finish
  (DB write + Broadcast) before the browser's HX-Redirect → page
  load → WS-connect path completed, so the JS sat forever waiting
  on a job.finished that already passed. JobHub split into
  Register + Send + Run; handleJobStream now subscribes first,
  re-fetches the job, and sends a synthetic job.finished if the
  state is already terminal.

* HTMX error visibility. New toast partial listens to
  htmx:responseError and surfaces the response body as a
  bottom-right toast — every server-side validation error now
  becomes visible without per-handler JS wiring. Also handles
  custom rm:toast events for future server-pushed notifications
  via the HX-Trigger header. Themed via existing CSS vars.

* Dashboard rows are now whole-row clickable to host detail
  (CSS card-link pattern: absolute-positioned anchor + .row-action
  z-index restoration so the action button stays clickable).
  "View →" on a running job links to /jobs/<id> rather than
  /hosts/<id> since the row click already covers the host page.

* "Run first" / "Run first backup" → "Run now" everywhere for
  consistency.

* runbook (docs/e2e-smoke.md) updated — live-log streaming step
  now reflects P1-26; mentions the browser-driven Run-now flow.

* _diag/dump-creds — moved out of cmd/ so go build doesn't pick
  it up; .gitignore now excludes /_diag/ entirely.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 11:02:12 +01:00

109 lines
4.0 KiB
HTML

{{define "toast"}}
{{/*
Global toast notifications.
Two trigger paths:
1. htmx:responseError — fires on any 4xx/5xx HTMX response. We
grab the response body (already a plain-text human message)
and show it as an error toast.
2. rm:toast — custom DOM event the server can fire from any
handler by setting the HX-Trigger header to:
HX-Trigger: {"rm:toast":{"level":"info","message":"…"}}
Levels: error|warn|info|success.
Toasts auto-dismiss after 5s; click to dismiss early.
*/}}
<div id="toast-container"
class="fixed bottom-5 right-5 z-50 flex flex-col gap-2 pointer-events-none"></div>
<style>
.rm-toast {
pointer-events: auto;
min-width: 280px;
max-width: 480px;
padding: 11px 14px 12px;
border-radius: 7px;
border: 1px solid var(--line);
background: var(--panel);
color: var(--ink);
box-shadow: 0 6px 24px -8px rgba(0,0,0,0.35);
font-size: 13px;
line-height: 1.5;
display: flex;
gap: 10px;
align-items: flex-start;
transform: translateX(8px);
opacity: 0;
transition: transform 180ms ease-out, opacity 180ms ease-out;
}
.rm-toast.shown { transform: translateX(0); opacity: 1; }
.rm-toast.fading { opacity: 0; transform: translateX(12px); }
.rm-toast .rm-toast-tag {
font-family: var(--mono, ui-monospace, SFMono-Regular, monospace);
font-size: 10.5px;
text-transform: uppercase;
letter-spacing: 0.06em;
padding: 2px 6px;
border-radius: 3px;
flex: none;
}
.rm-toast.lvl-error { border-color: color-mix(in oklch, var(--bad), transparent 50%); }
.rm-toast.lvl-error .rm-toast-tag { background: color-mix(in oklch, var(--bad), transparent 85%); color: var(--bad); }
.rm-toast.lvl-warn { border-color: color-mix(in oklch, var(--warn), transparent 50%); }
.rm-toast.lvl-warn .rm-toast-tag { background: color-mix(in oklch, var(--warn), transparent 85%); color: var(--warn); }
.rm-toast.lvl-success{ border-color: color-mix(in oklch, var(--ok), transparent 50%); }
.rm-toast.lvl-success.rm-toast-tag,
.rm-toast.lvl-success .rm-toast-tag { background: color-mix(in oklch, var(--ok), transparent 85%); color: var(--ok); }
.rm-toast.lvl-info .rm-toast-tag { background: color-mix(in oklch, var(--accent), transparent 85%); color: var(--accent); }
.rm-toast .rm-toast-msg { flex: 1; word-break: break-word; }
</style>
<script>
(function() {
const container = document.getElementById('toast-container');
const TAGS = { error: 'ERR', warn: 'WARN', success: 'OK', info: 'INFO' };
function showToast(message, level) {
if (!container) return;
level = level || 'info';
const t = document.createElement('div');
t.className = 'rm-toast lvl-' + level;
const tag = document.createElement('span');
tag.className = 'rm-toast-tag';
tag.textContent = TAGS[level] || level.toUpperCase();
const body = document.createElement('span');
body.className = 'rm-toast-msg';
body.textContent = message;
t.appendChild(tag);
t.appendChild(body);
t.addEventListener('click', () => dismiss(t));
container.appendChild(t);
requestAnimationFrame(() => t.classList.add('shown'));
setTimeout(() => dismiss(t), 5000);
}
function dismiss(t) {
if (!t.parentNode) return;
t.classList.add('fading');
setTimeout(() => t.remove(), 220);
}
// 1. HTMX 4xx/5xx → error toast with the response body verbatim.
document.body.addEventListener('htmx:responseError', (e) => {
const xhr = e.detail.xhr;
let msg = (xhr.responseText || '').trim();
if (!msg) msg = 'Request failed (' + xhr.status + ')';
showToast(msg, 'error');
});
// 2. Server-pushed custom events via HX-Trigger header. Payload
// can be a string (treated as info) or {level, message}.
document.body.addEventListener('rm:toast', (e) => {
const d = e.detail || {};
if (typeof d === 'string') return showToast(d, 'info');
showToast(d.message || 'Done', d.level || 'info');
});
})();
</script>
{{end}}