test(security): persist panic-lock across restarts and add multi-auth/recovery E2E tests
This commit is contained in:
parent
90a8bf8553
commit
21176265aa
4 changed files with 559 additions and 13 deletions
|
|
@ -107,7 +107,24 @@ export class VaultService {
|
|||
private wasPanicLocked = false;
|
||||
private readonly panicListeners = new Set<() => void>();
|
||||
|
||||
constructor(private readonly vaultFilePath: string) {}
|
||||
constructor(private readonly vaultFilePath: string) {
|
||||
this.wasPanicLocked = fs.existsSync(this.panicLockMarkerPath());
|
||||
}
|
||||
|
||||
private panicLockMarkerPath(): string {
|
||||
return `${this.vaultFilePath}.panic-locked`;
|
||||
}
|
||||
|
||||
private setPanicLockMarker(active: boolean): void {
|
||||
this.wasPanicLocked = active;
|
||||
const markerPath = this.panicLockMarkerPath();
|
||||
if (active) {
|
||||
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
||||
fs.writeFileSync(markerPath, `${Date.now()}\n`, { mode: 0o600 });
|
||||
} else {
|
||||
fs.rmSync(markerPath, { force: true });
|
||||
}
|
||||
}
|
||||
|
||||
get filePath(): string {
|
||||
return this.vaultFilePath;
|
||||
|
|
@ -119,7 +136,7 @@ export class VaultService {
|
|||
}
|
||||
|
||||
get isPanicLocked(): boolean {
|
||||
return this.wasPanicLocked;
|
||||
return this.wasPanicLocked || fs.existsSync(this.panicLockMarkerPath());
|
||||
}
|
||||
|
||||
onPanicLock(listener: () => void): () => void {
|
||||
|
|
@ -134,7 +151,7 @@ export class VaultService {
|
|||
envKey?: string;
|
||||
}): { unlocked: boolean; initialized?: boolean; reason?: string } {
|
||||
// Security invariant: never silently re-read disk secrets after Emergency Panic Lock
|
||||
if (this.wasPanicLocked) {
|
||||
if (this.isPanicLocked) {
|
||||
return { unlocked: false, reason: 'panic_locked' };
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +195,7 @@ export class VaultService {
|
|||
this.zeroizeMasterKey();
|
||||
this.masterKey = keyBuf;
|
||||
this.credentials.clear();
|
||||
this.wasPanicLocked = false;
|
||||
this.setPanicLockMarker(false);
|
||||
|
||||
return masterKeyInput ? {} : { generatedKeyHex: keyBuf.toString('hex') };
|
||||
}
|
||||
|
|
@ -197,7 +214,7 @@ export class VaultService {
|
|||
this.zeroizeMasterKey();
|
||||
this.masterKey = keyBuf;
|
||||
this.credentials = new Map(Object.entries(payload.credentials));
|
||||
this.wasPanicLocked = false;
|
||||
this.setPanicLockMarker(false);
|
||||
} catch (err) {
|
||||
keyBuf.fill(0);
|
||||
throw err;
|
||||
|
|
@ -207,7 +224,7 @@ export class VaultService {
|
|||
panicLock(): void {
|
||||
this.zeroizeMasterKey();
|
||||
this.credentials.clear();
|
||||
this.wasPanicLocked = true;
|
||||
this.setPanicLockMarker(true);
|
||||
|
||||
for (const listener of this.panicListeners) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue