Repository navigation
feat(admin): trust and automation for operator console #920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
82bb60b
feat(admin): trust and automation for operator console
Ferryx349 8f491bd
fix(admin): harden trust notifications and address review feedback
Ferryx349 bee8246
fix(redis): retry eval on NOSCRIPT for trust probe transitions
Ferryx349 e572093
fix(admin): skip audit Redis when cache is not configured
Ferryx349 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "nostream": minor | ||
| --- | ||
|
|
||
| Add admin trust and automation: Redis-backed audit log API and UI, signed HTTP webhooks for probe/mirror/SSL events, OpenTelemetry probe and mirror metrics, and redacted diagnostics export. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| (() => { | ||
| const config = window.__ADMIN_DASHBOARD__ || { pathPrefix: '' } | ||
| const adminBase = `${config.pathPrefix || ''}/admin` | ||
|
|
||
| const auditBody = document.getElementById('trust-audit-body') | ||
| if (!auditBody) { | ||
| return | ||
| } | ||
|
|
||
| const elements = { | ||
| auditSync: document.getElementById('trust-audit-sync'), | ||
| auditRefresh: document.getElementById('trust-audit-refresh'), | ||
| auditBody, | ||
| diagnosticsDownload: document.getElementById('trust-diagnostics-download'), | ||
| diagnosticsPreviewButton: document.getElementById('trust-diagnostics-preview-button'), | ||
| diagnosticsPreviewWrap: document.getElementById('trust-diagnostics-preview-wrap'), | ||
| diagnosticsPreviewClose: document.getElementById('trust-diagnostics-preview-close'), | ||
| diagnosticsPreviewPlaceholder: document.getElementById('trust-diagnostics-preview-placeholder'), | ||
| diagnosticsPreviewBody: document.getElementById('trust-diagnostics-preview-body'), | ||
| diagnosticsStatus: document.getElementById('trust-diagnostics-status'), | ||
| error: document.getElementById('trust-error'), | ||
| } | ||
|
|
||
| const escapeHtml = (value) => | ||
| String(value) | ||
| .replaceAll('&', '&') | ||
| .replaceAll('<', '<') | ||
| .replaceAll('>', '>') | ||
| .replaceAll('"', '"') | ||
| .replaceAll("'", ''') | ||
|
|
||
| const formatTime = (iso) => { | ||
| if (!iso) { | ||
| return '—' | ||
| } | ||
| const date = new Date(iso) | ||
| if (Number.isNaN(date.getTime())) { | ||
| return iso | ||
| } | ||
| return date.toISOString().replace('T', ' ').replace(/\.\d{3}Z$/, ' UTC') | ||
| } | ||
|
|
||
| const adminFetch = async (path, options = {}) => { | ||
| const response = await fetch(`${adminBase}${path}`, { | ||
| credentials: 'same-origin', | ||
| ...options, | ||
| }) | ||
| if (response.status === 401) { | ||
| throw new Error('Unauthorized') | ||
| } | ||
| return response | ||
| } | ||
|
|
||
| const showError = (message) => { | ||
| if (!elements.error) { | ||
| return | ||
| } | ||
| elements.error.textContent = message | ||
| elements.error.classList.remove('d-none') | ||
| } | ||
|
|
||
| const hideError = () => { | ||
| elements.error?.classList.add('d-none') | ||
| } | ||
|
|
||
| const handleUnauthorized = () => { | ||
| globalThis.dispatchEvent(new CustomEvent('admin-unauthorized')) | ||
| } | ||
|
|
||
| const handleFetchError = (error, fallbackMessage) => { | ||
| if (error instanceof Error && error.message === 'Unauthorized') { | ||
| handleUnauthorized() | ||
| return | ||
| } | ||
| showError(fallbackMessage) | ||
| } | ||
|
|
||
| const renderAuditEntries = (entries) => { | ||
| elements.auditBody.replaceChildren() | ||
| if (!Array.isArray(entries) || entries.length === 0) { | ||
| elements.auditBody.innerHTML = '<tr><td colspan="4" class="admin-muted small">No audit entries yet.</td></tr>' | ||
| return | ||
| } | ||
|
|
||
| entries.forEach((entry) => { | ||
| const row = document.createElement('tr') | ||
| const detail = | ||
| entry.detail && Object.keys(entry.detail).length > 0 | ||
| ? `<code class="small">${escapeHtml(JSON.stringify(entry.detail))}</code>` | ||
| : '—' | ||
| row.innerHTML = ` | ||
| <td>${escapeHtml(formatTime(entry.at))}</td> | ||
| <td><code>${escapeHtml(entry.action ?? '')}</code></td> | ||
| <td>${escapeHtml(entry.remoteAddress ?? '—')}</td> | ||
| <td>${detail}</td> | ||
| ` | ||
| elements.auditBody.appendChild(row) | ||
| }) | ||
| } | ||
|
|
||
| const loadAuditLog = async () => { | ||
| hideError() | ||
| if (elements.auditSync) { | ||
| elements.auditSync.textContent = '> audit: loading…' | ||
| } | ||
|
|
||
| try { | ||
| const response = await adminFetch('/audit-log?limit=100') | ||
| if (!response.ok) { | ||
| showError('Failed to load audit log') | ||
| if (elements.auditSync) { | ||
| elements.auditSync.textContent = '> audit: load failed' | ||
| } | ||
| return | ||
| } | ||
|
|
||
| const body = await response.json() | ||
| renderAuditEntries(body.entries ?? []) | ||
| if (elements.auditSync) { | ||
| elements.auditSync.textContent = `> audit: ${body.entries?.length ?? 0} entries` | ||
| } | ||
| } catch (error) { | ||
| handleFetchError(error, 'Network error while loading audit log') | ||
| } | ||
| } | ||
|
|
||
| const downloadDiagnostics = async () => { | ||
| hideError() | ||
| if (elements.diagnosticsStatus) { | ||
| elements.diagnosticsStatus.textContent = 'Preparing export…' | ||
| } | ||
|
|
||
| try { | ||
| const response = await adminFetch('/diagnostics/export?download=1') | ||
| if (!response.ok) { | ||
| showError('Diagnostics export failed') | ||
| return | ||
| } | ||
|
|
||
| const blob = await response.blob() | ||
| const url = URL.createObjectURL(blob) | ||
| const anchor = document.createElement('a') | ||
| anchor.href = url | ||
| anchor.download = `nostream-diagnostics-${new Date().toISOString().replace(/[:.]/g, '-')}.json` | ||
| anchor.click() | ||
| URL.revokeObjectURL(url) | ||
| if (elements.diagnosticsStatus) { | ||
| elements.diagnosticsStatus.textContent = 'Download started (secrets redacted).' | ||
| } | ||
| } catch (error) { | ||
| handleFetchError(error, 'Network error during diagnostics export') | ||
| } | ||
| } | ||
|
|
||
| const closeDiagnosticsPreview = () => { | ||
| elements.diagnosticsPreviewWrap?.classList.add('d-none') | ||
| elements.diagnosticsPreviewPlaceholder?.classList.remove('d-none') | ||
| if (elements.diagnosticsPreviewBody) { | ||
| elements.diagnosticsPreviewBody.textContent = '' | ||
| } | ||
| if (elements.diagnosticsStatus) { | ||
| elements.diagnosticsStatus.innerHTML = | ||
| '<span class="prompt-char">></span> diagnostics: idle' | ||
| } | ||
| } | ||
|
|
||
| const showDiagnosticsPreview = (payload) => { | ||
| elements.diagnosticsPreviewPlaceholder?.classList.add('d-none') | ||
| elements.diagnosticsPreviewWrap?.classList.remove('d-none') | ||
| if (elements.diagnosticsPreviewBody) { | ||
| elements.diagnosticsPreviewBody.textContent = JSON.stringify(payload, null, 2) | ||
| } | ||
| if (elements.diagnosticsStatus) { | ||
| elements.diagnosticsStatus.textContent = `Generated ${payload.generatedAt ?? ''} · version ${payload.version ?? 'unknown'}` | ||
| } | ||
| } | ||
|
|
||
| const previewDiagnostics = async () => { | ||
| hideError() | ||
| if (elements.diagnosticsStatus) { | ||
| elements.diagnosticsStatus.textContent = 'Loading preview…' | ||
| } | ||
|
|
||
| try { | ||
| const response = await adminFetch('/diagnostics/export') | ||
| if (!response.ok) { | ||
| showError('Diagnostics preview failed') | ||
| return | ||
| } | ||
|
|
||
| const payload = await response.json() | ||
| showDiagnosticsPreview(payload) | ||
| } catch (error) { | ||
| handleFetchError(error, 'Network error during diagnostics preview') | ||
| } | ||
| } | ||
|
|
||
| elements.auditRefresh?.addEventListener('click', () => { | ||
| void loadAuditLog() | ||
| }) | ||
| elements.diagnosticsDownload?.addEventListener('click', () => { | ||
| void downloadDiagnostics() | ||
| }) | ||
| elements.diagnosticsPreviewButton?.addEventListener('click', () => { | ||
| void previewDiagnostics() | ||
| }) | ||
| elements.diagnosticsPreviewClose?.addEventListener('click', () => { | ||
| closeDiagnosticsPreview() | ||
| }) | ||
|
|
||
| window.__ADMIN_TRUST__ = { | ||
| load: loadAuditLog, | ||
| closeDiagnosticsPreview, | ||
| } | ||
| })() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.