feat(client): add write-only Vault lock/unlock UI and automatic modification unlock prompt
This commit is contained in:
parent
10a28bb316
commit
d3ffa597d4
5 changed files with 282 additions and 135 deletions
|
|
@ -8,6 +8,7 @@ export interface ApiError extends Error {
|
||||||
let inMemoryCsrf: string | null = null;
|
let inMemoryCsrf: string | null = null;
|
||||||
let safeModeActive = false;
|
let safeModeActive = false;
|
||||||
let stepUpHandler: (() => Promise<boolean>) | null = null;
|
let stepUpHandler: (() => Promise<boolean>) | null = null;
|
||||||
|
let vaultUnlockHandler: (() => Promise<boolean>) | null = null;
|
||||||
let unauthorizedHandler: (() => void) | null = null;
|
let unauthorizedHandler: (() => void) | null = null;
|
||||||
|
|
||||||
export function setCsrfToken(token: string | null): void {
|
export function setCsrfToken(token: string | null): void {
|
||||||
|
|
@ -22,6 +23,10 @@ export function registerStepUpHandler(fn: () => Promise<boolean>): void {
|
||||||
stepUpHandler = fn;
|
stepUpHandler = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function registerVaultUnlockHandler(fn: () => Promise<boolean>): void {
|
||||||
|
vaultUnlockHandler = fn;
|
||||||
|
}
|
||||||
|
|
||||||
export function registerUnauthorizedHandler(fn: () => void): void {
|
export function registerUnauthorizedHandler(fn: () => void): void {
|
||||||
unauthorizedHandler = fn;
|
unauthorizedHandler = fn;
|
||||||
}
|
}
|
||||||
|
|
@ -90,6 +95,7 @@ export async function apiFetch<T = unknown>(
|
||||||
method?: string;
|
method?: string;
|
||||||
body?: unknown;
|
body?: unknown;
|
||||||
allowStepUpRetry?: boolean;
|
allowStepUpRetry?: boolean;
|
||||||
|
allowVaultUnlockRetry?: boolean;
|
||||||
} = {},
|
} = {},
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const method = (options.method ?? 'GET').toUpperCase();
|
const method = (options.method ?? 'GET').toUpperCase();
|
||||||
|
|
@ -130,6 +136,18 @@ export async function apiFetch<T = unknown>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
res.status === 423 &&
|
||||||
|
data.error === 'VAULT_LOCKED' &&
|
||||||
|
options.allowVaultUnlockRetry !== false &&
|
||||||
|
vaultUnlockHandler
|
||||||
|
) {
|
||||||
|
const unlocked = await vaultUnlockHandler();
|
||||||
|
if (unlocked) {
|
||||||
|
return apiFetch<T>(url, { ...options, allowVaultUnlockRetry: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (res.status === 401 && unauthorizedHandler && !url.startsWith('/api/auth/')) {
|
if (res.status === 401 && unauthorizedHandler && !url.startsWith('/api/auth/')) {
|
||||||
unauthorizedHandler();
|
unauthorizedHandler();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {
|
||||||
apiFetch,
|
apiFetch,
|
||||||
registerStepUpHandler,
|
registerStepUpHandler,
|
||||||
registerUnauthorizedHandler,
|
registerUnauthorizedHandler,
|
||||||
|
registerVaultUnlockHandler,
|
||||||
setApiSafeMode,
|
setApiSafeMode,
|
||||||
setCsrfToken,
|
setCsrfToken,
|
||||||
} from './api.js';
|
} from './api.js';
|
||||||
|
|
@ -48,6 +49,7 @@ const state: ClientState = {
|
||||||
bootstrapped: false,
|
bootstrapped: false,
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
vaultState: 'uninitialized',
|
vaultState: 'uninitialized',
|
||||||
|
vaultRuntimeReady: true,
|
||||||
isPanicLocked: false,
|
isPanicLocked: false,
|
||||||
safeMode: false,
|
safeMode: false,
|
||||||
defaultMobileSafeMode: true,
|
defaultMobileSafeMode: true,
|
||||||
|
|
@ -106,8 +108,16 @@ function updateTopBarUi(): void {
|
||||||
safeBtn.setAttribute('aria-pressed', state.safeMode ? 'true' : 'false');
|
safeBtn.setAttribute('aria-pressed', state.safeMode ? 'true' : 'false');
|
||||||
safeBtn.className = state.safeMode ? 'btn btn-sm btn-safe-on' : 'btn btn-sm';
|
safeBtn.className = state.safeMode ? 'btn btn-sm btn-safe-on' : 'btn btn-sm';
|
||||||
|
|
||||||
vaultBadge.textContent = `[VAULT: ${state.vaultState.toUpperCase()}]`;
|
if (!state.vaultRuntimeReady || state.isPanicLocked) {
|
||||||
vaultBadge.className = `badge ${state.vaultState === 'unlocked' ? 'badge-ok' : 'badge-warn'}`;
|
vaultBadge.textContent = state.isPanicLocked ? '[VAULT: PANIC]' : '[VAULT: SEALED]';
|
||||||
|
vaultBadge.className = 'badge badge-err';
|
||||||
|
} else if (state.vaultState === 'unlocked') {
|
||||||
|
vaultBadge.textContent = '[VAULT: UNLOCKED]';
|
||||||
|
vaultBadge.className = 'badge badge-warn';
|
||||||
|
} else {
|
||||||
|
vaultBadge.textContent = '[VAULT: LOCKED]';
|
||||||
|
vaultBadge.className = 'badge badge-ok';
|
||||||
|
}
|
||||||
|
|
||||||
themeSelect.value = state.theme;
|
themeSelect.value = state.theme;
|
||||||
|
|
||||||
|
|
@ -244,6 +254,7 @@ function handleLocalSessionReset(panic = false): void {
|
||||||
state.overview = null;
|
state.overview = null;
|
||||||
if (panic) {
|
if (panic) {
|
||||||
state.vaultState = 'locked';
|
state.vaultState = 'locked';
|
||||||
|
state.vaultRuntimeReady = false;
|
||||||
state.isPanicLocked = true;
|
state.isPanicLocked = true;
|
||||||
}
|
}
|
||||||
void renderCurrentView();
|
void renderCurrentView();
|
||||||
|
|
@ -256,6 +267,7 @@ async function syncStatusAndRender(): Promise<void> {
|
||||||
safeMode?: boolean;
|
safeMode?: boolean;
|
||||||
elevatedUntil?: number | null;
|
elevatedUntil?: number | null;
|
||||||
vaultState: ClientState['vaultState'];
|
vaultState: ClientState['vaultState'];
|
||||||
|
vaultRuntimeReady?: boolean;
|
||||||
isPanicLocked?: boolean;
|
isPanicLocked?: boolean;
|
||||||
defaultMobileSafeMode: boolean;
|
defaultMobileSafeMode: boolean;
|
||||||
theme: string;
|
theme: string;
|
||||||
|
|
@ -266,6 +278,7 @@ async function syncStatusAndRender(): Promise<void> {
|
||||||
state.bootstrapped = status.bootstrapped;
|
state.bootstrapped = status.bootstrapped;
|
||||||
state.authenticated = status.authenticated;
|
state.authenticated = status.authenticated;
|
||||||
state.vaultState = status.vaultState;
|
state.vaultState = status.vaultState;
|
||||||
|
state.vaultRuntimeReady = status.vaultRuntimeReady ?? status.vaultState === 'unlocked';
|
||||||
state.isPanicLocked = Boolean(status.isPanicLocked);
|
state.isPanicLocked = Boolean(status.isPanicLocked);
|
||||||
state.defaultMobileSafeMode = status.defaultMobileSafeMode;
|
state.defaultMobileSafeMode = status.defaultMobileSafeMode;
|
||||||
state.elevatedUntil = status.elevatedUntil ?? null;
|
state.elevatedUntil = status.elevatedUntil ?? null;
|
||||||
|
|
@ -318,6 +331,29 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
registerVaultUnlockHandler(async () => {
|
||||||
|
if (state.vaultRuntimeReady && !state.isPanicLocked) {
|
||||||
|
const ok = await confirmDialog(
|
||||||
|
'dialog-confirm',
|
||||||
|
'The Vault is locked against modifications. Unlock the Vault now to proceed?',
|
||||||
|
);
|
||||||
|
if (!ok) return false;
|
||||||
|
try {
|
||||||
|
await apiFetch('/api/vault/unlock', {
|
||||||
|
method: 'POST',
|
||||||
|
body: {},
|
||||||
|
allowVaultUnlockRetry: false,
|
||||||
|
});
|
||||||
|
state.vaultState = 'unlocked';
|
||||||
|
updateTopBarUi();
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.location.hash = '#vault';
|
||||||
|
return false;
|
||||||
|
});
|
||||||
registerUnauthorizedHandler(() => {
|
registerUnauthorizedHandler(() => {
|
||||||
handleLocalSessionReset(false);
|
handleLocalSessionReset(false);
|
||||||
});
|
});
|
||||||
|
|
@ -342,8 +378,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
wsClient.onFrame((frame: ServerWsFrame) => {
|
wsClient.onFrame((frame: ServerWsFrame) => {
|
||||||
if (frame.type === 'hello') {
|
if (frame.type === 'hello') {
|
||||||
state.vaultState = frame.vaultState;
|
state.vaultState = frame.vaultState;
|
||||||
|
if (frame.vaultRuntimeReady !== undefined) {
|
||||||
|
state.vaultRuntimeReady = frame.vaultRuntimeReady;
|
||||||
|
}
|
||||||
state.elevatedUntil = frame.elevatedUntil;
|
state.elevatedUntil = frame.elevatedUntil;
|
||||||
updateTopBarUi();
|
updateTopBarUi();
|
||||||
|
} else if (frame.type === 'vault:state') {
|
||||||
|
state.vaultState = frame.vaultState;
|
||||||
|
state.vaultRuntimeReady = frame.vaultRuntimeReady;
|
||||||
|
state.isPanicLocked = frame.isPanicLocked;
|
||||||
|
updateTopBarUi();
|
||||||
|
if (state.authenticated && (state.route === 'vault' || state.route === 'dashboard')) {
|
||||||
|
void renderCurrentView();
|
||||||
|
}
|
||||||
} else if (frame.type === 'security:panic-lock') {
|
} else if (frame.type === 'security:panic-lock') {
|
||||||
handleLocalSessionReset(true);
|
handleLocalSessionReset(true);
|
||||||
} else if (frame.type === 'config:updated' && state.authenticated) {
|
} else if (frame.type === 'config:updated' && state.authenticated) {
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ export interface ClientState {
|
||||||
bootstrapped: boolean;
|
bootstrapped: boolean;
|
||||||
authenticated: boolean;
|
authenticated: boolean;
|
||||||
vaultState: VaultState;
|
vaultState: VaultState;
|
||||||
|
vaultRuntimeReady: boolean;
|
||||||
isPanicLocked: boolean;
|
isPanicLocked: boolean;
|
||||||
safeMode: boolean;
|
safeMode: boolean;
|
||||||
defaultMobileSafeMode: boolean;
|
defaultMobileSafeMode: boolean;
|
||||||
|
|
|
||||||
|
|
@ -276,11 +276,17 @@ export async function renderDashboardView(
|
||||||
void renderDashboardView(root, state);
|
void renderDashboardView(root, state);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const vaultSummary = !state.vaultRuntimeReady
|
||||||
|
? 'Vault: sealed (master key required)'
|
||||||
|
: state.vaultState === 'unlocked'
|
||||||
|
? 'Vault: unlocked (editable)'
|
||||||
|
: 'Vault: locked (collectors & secrets active)';
|
||||||
|
|
||||||
root.append(
|
root.append(
|
||||||
el(
|
el(
|
||||||
'div',
|
'div',
|
||||||
{ class: 'panel row-between' },
|
{ class: 'panel row-between' },
|
||||||
el('div', {}, el('h1', {}, `Fleet Monitor (${servers.length} servers)`), el('span', { class: 'muted' }, `Vault: ${state.vaultState}`)),
|
el('div', {}, el('h1', {}, `Fleet Monitor (${servers.length} servers)`), el('span', { class: 'muted' }, vaultSummary)),
|
||||||
el('div', { class: 'row' }, registerBtn, rotateFleetBtn, refreshBtn),
|
el('div', { class: 'row' }, registerBtn, rotateFleetBtn, refreshBtn),
|
||||||
),
|
),
|
||||||
actionStatus,
|
actionStatus,
|
||||||
|
|
|
||||||
|
|
@ -12,136 +12,11 @@ interface VaultCredMeta {
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function renderVaultView(
|
function buildCredentialsTable(
|
||||||
root: HTMLElement,
|
credentials: VaultCredMeta[],
|
||||||
state: ClientState,
|
revealBox: HTMLElement,
|
||||||
onStateChanged: () => Promise<void>,
|
onStateChanged: () => Promise<void>,
|
||||||
onPanicLock: () => Promise<void>,
|
): HTMLElement {
|
||||||
): Promise<void> {
|
|
||||||
root.replaceChildren();
|
|
||||||
const vaultData = await apiFetch<{
|
|
||||||
state: 'uninitialized' | 'locked' | 'unlocked';
|
|
||||||
credentials: VaultCredMeta[];
|
|
||||||
}>('/api/vault/credentials');
|
|
||||||
state.vaultState = vaultData.state;
|
|
||||||
|
|
||||||
const statusPanel = el('section', { class: 'panel' });
|
|
||||||
statusPanel.append(
|
|
||||||
el('h1', {}, `Encrypted Vault — [${vaultData.state.toUpperCase()}]`),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (vaultData.state === 'uninitialized') {
|
|
||||||
const msg = el('p', { class: 'form-msg' });
|
|
||||||
const keyInput = el('input', {
|
|
||||||
id: 'vault-init-key',
|
|
||||||
type: 'password',
|
|
||||||
placeholder: 'Optional 64-hex or base64 master key (leave blank to auto-generate)',
|
|
||||||
});
|
|
||||||
const initBtn = el(
|
|
||||||
'button',
|
|
||||||
{ type: 'submit', class: 'btn btn-primary mutating-action' },
|
|
||||||
'Initialize vault.enc',
|
|
||||||
);
|
|
||||||
const form = el(
|
|
||||||
'form',
|
|
||||||
{ class: 'stack' },
|
|
||||||
el('label', { for: 'vault-init-key' }, '32-Byte Master Key (Optional)'),
|
|
||||||
keyInput,
|
|
||||||
msg,
|
|
||||||
el('div', { class: 'row' }, initBtn),
|
|
||||||
);
|
|
||||||
|
|
||||||
form.addEventListener('submit', async (ev) => {
|
|
||||||
ev.preventDefault();
|
|
||||||
msg.textContent = '';
|
|
||||||
try {
|
|
||||||
const res = await apiFetch<{ state: string; generatedKeyHex?: string }>(
|
|
||||||
'/api/vault/init',
|
|
||||||
{
|
|
||||||
method: 'POST',
|
|
||||||
body: keyInput.value.trim() ? { masterKey: keyInput.value.trim() } : {},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (res.generatedKeyHex) {
|
|
||||||
const box = el(
|
|
||||||
'div',
|
|
||||||
{ class: 'panel' },
|
|
||||||
el('h2', {}, 'Store Generated Master Key Safely'),
|
|
||||||
el(
|
|
||||||
'p',
|
|
||||||
{ class: 'warn-text' },
|
|
||||||
state.security?.enableEmergencySecretsBackup !== false
|
|
||||||
? 'A readable chmod 0600 local backup has been saved automatically in data/recovery/emergency-secrets.json. You should still keep an offsite copy in your password manager.'
|
|
||||||
: 'Copy this 64-hex key to your password manager or Docker secret. Without it, vault.enc cannot be unlocked after a restart or Panic Lock.',
|
|
||||||
),
|
|
||||||
el('pre', { class: 'mono' }, res.generatedKeyHex),
|
|
||||||
);
|
|
||||||
const contBtn = el('button', { type: 'button', class: 'btn btn-primary' }, 'Continue');
|
|
||||||
contBtn.addEventListener('click', () => {
|
|
||||||
void onStateChanged();
|
|
||||||
});
|
|
||||||
box.append(contBtn);
|
|
||||||
statusPanel.replaceChildren(box);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await onStateChanged();
|
|
||||||
} catch (err) {
|
|
||||||
msg.className = 'form-msg err-text';
|
|
||||||
msg.textContent = extractErrorMessage(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
statusPanel.append(form);
|
|
||||||
root.append(statusPanel);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vaultData.state === 'locked') {
|
|
||||||
if (state.isPanicLocked) {
|
|
||||||
statusPanel.append(
|
|
||||||
el(
|
|
||||||
'p',
|
|
||||||
{ class: 'err-text' },
|
|
||||||
'Emergency Panic Lock was engaged. Enter the 32-byte master key manually to unlock.',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const keyInput = el('input', {
|
|
||||||
id: 'vault-unlock-key',
|
|
||||||
type: 'password',
|
|
||||||
autocomplete: 'off',
|
|
||||||
placeholder: 'Paste 64-hex or base64 master key',
|
|
||||||
required: true,
|
|
||||||
});
|
|
||||||
const msg = el('p', { class: 'form-msg err-text' });
|
|
||||||
const form = el(
|
|
||||||
'form',
|
|
||||||
{ class: 'stack' },
|
|
||||||
el('label', { for: 'vault-unlock-key' }, 'Master Key'),
|
|
||||||
keyInput,
|
|
||||||
msg,
|
|
||||||
el('div', { class: 'row' }, el('button', { type: 'submit', class: 'btn btn-primary' }, 'Unlock Vault')),
|
|
||||||
);
|
|
||||||
form.addEventListener('submit', async (ev) => {
|
|
||||||
ev.preventDefault();
|
|
||||||
msg.textContent = '';
|
|
||||||
try {
|
|
||||||
await apiFetch('/api/vault/unlock', {
|
|
||||||
method: 'POST',
|
|
||||||
body: { masterKey: keyInput.value.trim() },
|
|
||||||
});
|
|
||||||
await onStateChanged();
|
|
||||||
} catch (err) {
|
|
||||||
msg.textContent = extractErrorMessage(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
statusPanel.append(form);
|
|
||||||
root.append(statusPanel);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unlocked view
|
|
||||||
const revealBox = el('div', { class: 'panel', hidden: true });
|
|
||||||
const credTableWrap = el('div', { class: 'table-wrap' });
|
const credTableWrap = el('div', { class: 'table-wrap' });
|
||||||
const table = el('table');
|
const table = el('table');
|
||||||
table.append(
|
table.append(
|
||||||
|
|
@ -161,12 +36,12 @@ export async function renderVaultView(
|
||||||
);
|
);
|
||||||
const tbody = el('tbody');
|
const tbody = el('tbody');
|
||||||
|
|
||||||
if (vaultData.credentials.length === 0) {
|
if (credentials.length === 0) {
|
||||||
tbody.append(
|
tbody.append(
|
||||||
el('tr', {}, el('td', { colspan: 5, class: 'muted' }, 'No credentials stored in vault yet.')),
|
el('tr', {}, el('td', { colspan: 5, class: 'muted' }, 'No credentials stored in vault yet.')),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (const c of vaultData.credentials) {
|
for (const c of credentials) {
|
||||||
const revealBtn = el('button', { type: 'button', class: 'btn btn-sm' }, 'Reveal');
|
const revealBtn = el('button', { type: 'button', class: 'btn btn-sm' }, 'Reveal');
|
||||||
revealBtn.addEventListener('click', async () => {
|
revealBtn.addEventListener('click', async () => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -238,7 +113,207 @@ export async function renderVaultView(
|
||||||
}
|
}
|
||||||
table.append(tbody);
|
table.append(tbody);
|
||||||
credTableWrap.append(table);
|
credTableWrap.append(table);
|
||||||
statusPanel.append(credTableWrap, revealBox);
|
return credTableWrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function renderVaultView(
|
||||||
|
root: HTMLElement,
|
||||||
|
state: ClientState,
|
||||||
|
onStateChanged: () => Promise<void>,
|
||||||
|
onPanicLock: () => Promise<void>,
|
||||||
|
): Promise<void> {
|
||||||
|
root.replaceChildren();
|
||||||
|
const vaultData = await apiFetch<{
|
||||||
|
state: 'uninitialized' | 'locked' | 'unlocked';
|
||||||
|
runtimeReady?: boolean;
|
||||||
|
isPanicLocked?: boolean;
|
||||||
|
credentials: VaultCredMeta[];
|
||||||
|
}>('/api/vault/credentials');
|
||||||
|
const runtimeReady = Boolean(vaultData.runtimeReady ?? vaultData.state === 'unlocked');
|
||||||
|
state.vaultState = vaultData.state;
|
||||||
|
state.vaultRuntimeReady = runtimeReady;
|
||||||
|
if (vaultData.isPanicLocked !== undefined) {
|
||||||
|
state.isPanicLocked = vaultData.isPanicLocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusPanel = el('section', { class: 'panel' });
|
||||||
|
|
||||||
|
if (vaultData.state === 'uninitialized') {
|
||||||
|
statusPanel.append(
|
||||||
|
el('h1', {}, `Encrypted Vault — [${vaultData.state.toUpperCase()}]`),
|
||||||
|
);
|
||||||
|
const msg = el('p', { class: 'form-msg' });
|
||||||
|
const keyInput = el('input', {
|
||||||
|
id: 'vault-init-key',
|
||||||
|
type: 'password',
|
||||||
|
placeholder: 'Optional 64-hex or base64 master key (leave blank to auto-generate)',
|
||||||
|
});
|
||||||
|
const initBtn = el(
|
||||||
|
'button',
|
||||||
|
{ type: 'submit', class: 'btn btn-primary mutating-action' },
|
||||||
|
'Initialize vault.enc',
|
||||||
|
);
|
||||||
|
const form = el(
|
||||||
|
'form',
|
||||||
|
{ class: 'stack' },
|
||||||
|
el('label', { for: 'vault-init-key' }, '32-Byte Master Key (Optional)'),
|
||||||
|
keyInput,
|
||||||
|
msg,
|
||||||
|
el('div', { class: 'row' }, initBtn),
|
||||||
|
);
|
||||||
|
|
||||||
|
form.addEventListener('submit', async (ev) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
msg.textContent = '';
|
||||||
|
try {
|
||||||
|
const res = await apiFetch<{ state: string; generatedKeyHex?: string }>(
|
||||||
|
'/api/vault/init',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
body: keyInput.value.trim() ? { masterKey: keyInput.value.trim() } : {},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (res.generatedKeyHex) {
|
||||||
|
const box = el(
|
||||||
|
'div',
|
||||||
|
{ class: 'panel' },
|
||||||
|
el('h2', {}, 'Store Generated Master Key Safely'),
|
||||||
|
el(
|
||||||
|
'p',
|
||||||
|
{ class: 'warn-text' },
|
||||||
|
state.security?.enableEmergencySecretsBackup !== false
|
||||||
|
? 'A readable chmod 0600 local backup has been saved automatically in data/recovery/emergency-secrets.json. You should still keep an offsite copy in your password manager.'
|
||||||
|
: 'Copy this 64-hex key to your password manager or Docker secret. Without it, vault.enc cannot be unlocked after a restart or Panic Lock.',
|
||||||
|
),
|
||||||
|
el('pre', { class: 'mono' }, res.generatedKeyHex),
|
||||||
|
);
|
||||||
|
const contBtn = el('button', { type: 'button', class: 'btn btn-primary' }, 'Continue');
|
||||||
|
contBtn.addEventListener('click', () => {
|
||||||
|
void onStateChanged();
|
||||||
|
});
|
||||||
|
box.append(contBtn);
|
||||||
|
statusPanel.replaceChildren(box);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await onStateChanged();
|
||||||
|
} catch (err) {
|
||||||
|
msg.className = 'form-msg err-text';
|
||||||
|
msg.textContent = extractErrorMessage(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
statusPanel.append(form);
|
||||||
|
root.append(statusPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vaultData.state === 'locked' && !runtimeReady) {
|
||||||
|
statusPanel.append(
|
||||||
|
el('h1', {}, 'Encrypted Vault — [SEALED]'),
|
||||||
|
el(
|
||||||
|
'p',
|
||||||
|
{ class: state.isPanicLocked ? 'err-text' : 'warn-text' },
|
||||||
|
state.isPanicLocked
|
||||||
|
? 'Emergency Panic Lock was engaged. Enter the 32-byte master key manually to unseal the vault and resume background collectors.'
|
||||||
|
: 'Vault is sealed and no local unseal key was found. Enter the 32-byte master key to unseal the vault and start background collectors.',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const keyInput = el('input', {
|
||||||
|
id: 'vault-unlock-key',
|
||||||
|
type: 'password',
|
||||||
|
autocomplete: 'off',
|
||||||
|
placeholder: 'Paste 64-hex or base64 master key',
|
||||||
|
required: true,
|
||||||
|
});
|
||||||
|
const msg = el('p', { class: 'form-msg err-text' });
|
||||||
|
const form = el(
|
||||||
|
'form',
|
||||||
|
{ class: 'stack' },
|
||||||
|
el('label', { for: 'vault-unlock-key' }, 'Master Key'),
|
||||||
|
keyInput,
|
||||||
|
msg,
|
||||||
|
el('div', { class: 'row' }, el('button', { type: 'submit', class: 'btn btn-primary' }, 'Unseal Vault')),
|
||||||
|
);
|
||||||
|
form.addEventListener('submit', async (ev) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
msg.textContent = '';
|
||||||
|
try {
|
||||||
|
await apiFetch('/api/vault/unlock', {
|
||||||
|
method: 'POST',
|
||||||
|
body: { masterKey: keyInput.value.trim() },
|
||||||
|
});
|
||||||
|
await onStateChanged();
|
||||||
|
} catch (err) {
|
||||||
|
msg.textContent = extractErrorMessage(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
statusPanel.append(form);
|
||||||
|
root.append(statusPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const revealBox = el('div', { class: 'panel', hidden: true });
|
||||||
|
const credTableWrap = buildCredentialsTable(vaultData.credentials, revealBox, onStateChanged);
|
||||||
|
|
||||||
|
if (vaultData.state === 'locked') {
|
||||||
|
const lockMsg = el('p', { class: 'form-msg' });
|
||||||
|
const unlockBtn = el(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'btn btn-primary' },
|
||||||
|
'Unlock Vault for Modifications',
|
||||||
|
);
|
||||||
|
unlockBtn.addEventListener('click', async () => {
|
||||||
|
lockMsg.textContent = '';
|
||||||
|
try {
|
||||||
|
await apiFetch('/api/vault/unlock', { method: 'POST', body: {} });
|
||||||
|
await onStateChanged();
|
||||||
|
} catch (err) {
|
||||||
|
lockMsg.className = 'form-msg err-text';
|
||||||
|
lockMsg.textContent = extractErrorMessage(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const panicBtn = el(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'btn btn-danger' },
|
||||||
|
'Engage Emergency Panic Lock',
|
||||||
|
);
|
||||||
|
panicBtn.addEventListener('click', () => {
|
||||||
|
void onPanicLock();
|
||||||
|
});
|
||||||
|
|
||||||
|
statusPanel.append(
|
||||||
|
el('h1', {}, 'Encrypted Vault — [LOCKED]'),
|
||||||
|
el(
|
||||||
|
'p',
|
||||||
|
{ class: 'muted' },
|
||||||
|
'Established secrets remain active in the background for stat collectors, SSH, SFTP, Terminal, Systems, and Tunnels. Unlock the Vault to add, update, delete, rotate, or reveal secrets.',
|
||||||
|
),
|
||||||
|
el('div', { class: 'row' }, unlockBtn, panicBtn),
|
||||||
|
lockMsg,
|
||||||
|
credTableWrap,
|
||||||
|
revealBox,
|
||||||
|
);
|
||||||
|
root.append(statusPanel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlocked view
|
||||||
|
const lockBtn = el(
|
||||||
|
'button',
|
||||||
|
{ type: 'button', class: 'btn btn-sm' },
|
||||||
|
'Lock Vault',
|
||||||
|
);
|
||||||
|
lockBtn.addEventListener('click', async () => {
|
||||||
|
await apiFetch('/api/vault/lock', { method: 'POST' });
|
||||||
|
await onStateChanged();
|
||||||
|
});
|
||||||
|
|
||||||
|
statusPanel.append(
|
||||||
|
el('div', { class: 'row-between' }, el('h1', {}, 'Encrypted Vault — [UNLOCKED]'), lockBtn),
|
||||||
|
credTableWrap,
|
||||||
|
revealBox,
|
||||||
|
);
|
||||||
root.append(statusPanel);
|
root.append(statusPanel);
|
||||||
|
|
||||||
// Two-column tools: Generate Ed25519 + Add Secret
|
// Two-column tools: Generate Ed25519 + Add Secret
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue