Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(auth): point the startup banner at the real key file

Yudhi Armyndharisb1fc36216e50
diff --git a/src/modules/auth/auth.service.spec.ts b/src/modules/auth/auth.service.spec.ts
index 442d8eca5..e22ca0e62 100644
--- a/src/modules/auth/auth.service.spec.ts
+++ b/src/modules/auth/auth.service.spec.ts
@@ -94,7 +94,19 @@ describe('bannerKeyLine (startup banner key masking)', () => {
const line = bannerKeyLine(FULL, false);
expect(line).not.toContain('0123456789abcdef'); // the secret tail must not appear
expect(line.startsWith('owa_k1_0')).toBe(true); // a short fingerprint is fine
- expect(line).toMatch(/data\/\.api-key|dashboard/); // points the operator to the real source
+ expect(line).toMatch(/data\/\.api-key/); // points the operator to the real source
+ expect(line).not.toContain('dashboard'); // the dashboard only ever shows a key's prefix
+ });
+
+ it('names the bootstrap key file BOOTSTRAP_KEY_FILE points at', () => {
+ const original = process.env.BOOTSTRAP_KEY_FILE;
+ process.env.BOOTSTRAP_KEY_FILE = '/run/secrets/openwa-key';
+ try {
+ expect(bannerKeyLine(FULL, false)).toContain('(full key in /run/secrets/openwa-key)');
+ } finally {
+ if (original === undefined) delete process.env.BOOTSTRAP_KEY_FILE;
+ else process.env.BOOTSTRAP_KEY_FILE = original;
+ }
});
it('passes a placeholder through unchanged', () => {
@@ -1110,7 +1122,7 @@ describe('AuthService', () => {
await service.onModuleInit();
expect(unlinkSpy).not.toHaveBeenCalled();
- expect(bannerText()).toContain('(full key in data/.api-key');
+ expect(bannerText()).toMatch(/\(full key in \S*data\/\.api-key\)/);
});
});
diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts
index 341b41e7f..c031dc5e2 100644
--- a/src/modules/auth/auth.service.ts
+++ b/src/modules/auth/auth.service.ts
@@ -18,7 +18,7 @@ import { ApiKey, ApiKeyRole } from './entities/api-key.entity';
import { CreateApiKeyDto, UpdateApiKeyDto } from './dto';
import { createLogger } from '../../common/services/logger.service';
import { setRequestActor } from '../../common/services/request-context';
-import { readBootstrapKey, removeBootstrapKey, writeBootstrapKey } from './bootstrap-key-file';
+import { bootstrapKeyFilePath, readBootstrapKey, removeBootstrapKey, writeBootstrapKey } from './bootstrap-key-file';
import { ApiKeyUsageTracker } from './api-key-usage-tracker.service';
import { ActiveKeyIndex } from './active-key-index';
import { apiKeyAuthorizationFingerprint, normalizeScopeList } from './api-key-authorization';
@@ -62,13 +62,14 @@ export function resolveSeedApiKey(): string {
* The line to print for the API key in the startup banner. The full raw key is shown ONLY when it was
* just created (first run, when the operator needs to capture it once). On every subsequent boot the
* key is masked to a short non-secret fingerprint, so the live admin key is not re-written to the log
- * pipeline (Docker/Loki/CloudWatch) on each restart — it stays in `data/.api-key` (0600) and the
- * dashboard. A placeholder (e.g. "(check dashboard for keys)") is passed through unchanged.
+ * pipeline (Docker/Loki/CloudWatch) on each restart — it stays in `data/.api-key` (0600), or wherever
+ * `BOOTSTRAP_KEY_FILE` points; the dashboard only ever shows a key's prefix. A placeholder
+ * (e.g. "(check dashboard for keys)") is passed through unchanged.
*/
export function bannerKeyLine(displayKey: string, isNewKey: boolean): string {
if (isNewKey) return displayKey;
if (displayKey.startsWith('(')) return displayKey;
- return `${displayKey.slice(0, 8)}… (full key in data/.api-key or the dashboard)`;
+ return `${displayKey.slice(0, 8)}… (full key in ${bootstrapKeyFilePath()})`;
}
@Injectable()