Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(infra): keep S3 keys the bundled MinIO already uses
Yudhi Armyndharis71460d8f268a
diff --git a/src/modules/infra/config-sections.ts b/src/modules/infra/config-sections.tsindex e138c5437..90ed6260d 100644--- a/src/modules/infra/config-sections.ts+++ b/src/modules/infra/config-sections.ts@@ -231,10 +231,15 @@ export function applyStorageSection(} else {staleKeys.add('STORAGE_LOCAL_PATH');if (storage.builtIn === true) {- // Built-in MinIO - use container name as endpoint+ // Built-in MinIO - use container name as endpoint. The bundled keys are only the DEFAULT, as for the database+ // password: keys the next boot already dials the bundled endpoint with (the flag already set, or the bundled+ // endpoint pinned or stored) are the ones that container was created with, and are kept.+ const keepKeys =+ existing.MINIO_BUILTIN === 'true' || nextBootHost('S3_ENDPOINT', existing) === 'http://minio:9000';updates.S3_ENDPOINT = 'http://minio:9000';- updates.S3_ACCESS_KEY_ID = 'minioadmin';- updates.S3_SECRET_ACCESS_KEY = 'minioadmin';+ updates.S3_ACCESS_KEY_ID = (keepKeys && (existing.S3_ACCESS_KEY_ID || existing.S3_ACCESS_KEY)) || 'minioadmin';+ updates.S3_SECRET_ACCESS_KEY =+ (keepKeys && (existing.S3_SECRET_ACCESS_KEY || existing.S3_SECRET_KEY)) || 'minioadmin';updates.S3_BUCKET = 'openwa';updates.S3_REGION = 'us-east-1';profiles.push('minio');diff --git a/src/modules/infra/infra-config.controller.spec.ts b/src/modules/infra/infra-config.controller.spec.tsindex 734ebc7a1..0fde0fb70 100644--- a/src/modules/infra/infra-config.controller.spec.ts+++ b/src/modules/infra/infra-config.controller.spec.ts@@ -1367,6 +1367,64 @@ describe('InfraConfigController.saveConfig built-in/external mode flips and the});});+ // The bundled MinIO is created with the keys the next boot reads, like the database password above.+ describe('built-in storage over stored keys the next boot already dials the bundled endpoint with', () => {+ const KEYS = 'S3_ACCESS_KEY_ID=StoredKey12345\nS3_SECRET_ACCESS_KEY=StoredSecret1234567890\n';++ afterEach(() => {+ delete process.env.S3_ENDPOINT;+ recordPinnedEnvKeys({});+ });++ it('keeps them when the flag is already set', () => {+ const env = written(+ { storage: { type: 's3', builtIn: true } },+ 'STORAGE_TYPE=s3\nMINIO_BUILTIN=true\nS3_ENDPOINT=http://minio:9000\nS3_BUCKET=openwa\n' + KEYS,+ );+ expect(env).toContain('S3_ACCESS_KEY_ID=StoredKey12345');+ expect(env).toContain('S3_SECRET_ACCESS_KEY=StoredSecret1234567890');+ });++ it('keeps them when the file names the bundled endpoint without the flag', () => {+ const env = written(+ { storage: { type: 's3', builtIn: true } },+ 'STORAGE_TYPE=s3\nMINIO_BUILTIN=false\nS3_ENDPOINT=http://minio:9000\nS3_BUCKET=openwa\n' + KEYS,+ );+ expect(env).toContain('MINIO_BUILTIN=true');+ expect(env).toContain('S3_ACCESS_KEY_ID=StoredKey12345');+ expect(env).toContain('S3_SECRET_ACCESS_KEY=StoredSecret1234567890');+ });++ it('keeps them when the environment pins the bundled endpoint', () => {+ process.env.S3_ENDPOINT = 'http://minio:9000';+ recordPinnedEnvKeys({ S3_ENDPOINT: 'http://minio:9000' });+ const env = written(+ { storage: { type: 's3', builtIn: true } },+ 'STORAGE_TYPE=s3\nMINIO_BUILTIN=false\nS3_BUCKET=media\n' + KEYS,+ );+ expect(env).toContain('S3_ACCESS_KEY_ID=StoredKey12345');+ });++ it('keeps the legacy names the bundled container was created with', () => {+ const env = written(+ { storage: { type: 's3', builtIn: true } },+ 'STORAGE_TYPE=s3\nMINIO_BUILTIN=true\nS3_ENDPOINT=http://minio:9000\nS3_ACCESS_KEY=LegacyKey12345\nS3_SECRET_KEY=LegacySecret1234567890\n',+ );+ expect(env).toContain('S3_ACCESS_KEY_ID=LegacyKey12345');+ expect(env).toContain('S3_SECRET_ACCESS_KEY=LegacySecret1234567890');+ });++ it('still resets the keys of another endpoint', () => {+ const env = written(+ { storage: { type: 's3', builtIn: true } },+ 'STORAGE_TYPE=s3\nMINIO_BUILTIN=false\nS3_ENDPOINT=https://s3.example.com\nS3_BUCKET=media\n' + KEYS,+ );+ expect(env).toContain('S3_ACCESS_KEY_ID=minioadmin');+ expect(env).toContain('S3_SECRET_ACCESS_KEY=minioadmin');+ expect(env).not.toContain('StoredKey12345');+ });+ });+// The guard must evaluate what the next boot would SEE: load-env.ts loads with dotenv// override:false, so a value in the container environment (compose `environment:`) wins over the// saved file. Snapshot + clear every guard-relevant key so these tests are hermetic.