011_sources_secrets.up.sql 1.5 KB

12345678910111213141516171819202122232425262728293031
  1. -- 010_sources_secrets.up.sql
  2. --
  3. -- M13b W2: add secret + cert-lifecycle fields to public.sources
  4. -- so the admin UI can issue HMAC + API keys for sources and
  5. -- (later, in M14) manage mTLS client certs. Until this migration
  6. -- landed, sources had no DB-side secret storage — the M0 pattern
  7. -- was to keep secrets in BA_INGESTD_SOURCES env. The new columns
  8. -- are nullable so rows created before this migration still load.
  9. --
  10. -- Storage policy:
  11. -- hmac_secret_hash: bcrypt of the HMAC secret (cost 10 for
  12. -- dev/smoke; cost 12 in prod — the secret length is 32 bytes
  13. -- hex = 64 chars, which is well under bcrypt's 72-byte
  14. -- limit so no truncation handling is needed).
  15. -- api_key_hash: bcrypt of the API key. Same cost notes.
  16. -- mtls_required: when TRUE, ingestd requires a client cert
  17. -- signed by the company mTLS CA. M14 W2 will check this flag
  18. -- on every ingest. W2 just stores it; the M14 backend is
  19. -- the one that actually enforces it.
  20. -- description: free-text label. Optional but the UI always
  21. -- shows it on the detail page.
  22. --
  23. -- Plaintext is returned to the UI EXACTLY ONCE at create / rotate
  24. -- time, in a "one-time secrets" payload. After that, only the
  25. -- hashes are stored. The UI cannot re-fetch the plaintext.
  26. ALTER TABLE sources
  27. ADD COLUMN IF NOT EXISTS hmac_secret_hash TEXT,
  28. ADD COLUMN IF NOT EXISTS api_key_hash TEXT,
  29. ADD COLUMN IF NOT EXISTS mtls_required BOOLEAN NOT NULL DEFAULT FALSE,
  30. ADD COLUMN IF NOT EXISTS description TEXT;