Skip to content

fix: Keep Secrets-Manager users and bootstrap credentials away from SQL templates (#254) - #260

Merged
jrosskopf merged 9 commits into
mainfrom
fix/gh-254-bootstrap-secrets
Nov 24, 2026
Merged

jrosskopf merged 9 commits into
mainfrom
fix/gh-254-bootstrap-secrets

Conversation

@jrosskopf

@jrosskopf jrosskopf commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

auth.from-aws-secretmanager exposed the fetched user list (passwords, roles) as a main-DB table that any template could SELECT. Its bootstrap S3 secret sat in duckdb_secrets(), and the init SQL holding the AWS key was built unescaped and logged. Changes:

  • Credentials go straight to the AWS SDK. secret-id/secret-key use a simple provider; with neither, the SDK default chain. No DuckDB secret and no SQL. A legacy custom init: runs in a private DuckDB, with a deprecated main-DB fallback.
  • The user list lives in C++ memory, fetched once per secret-name. Blocks that share a name but differ fail at startup. Old auth_<name> tables left in a persistent db_path are dropped at startup with a warning.
  • Fixed a real bug: a missing session token or region was sent as the literal "NULL", so real AWS rejected the request. The region now comes from config, then AWS_REGION/AWS_DEFAULT_REGION, then the SDK profile.
  • Endpoint override: only AWS_ENDPOINT_URL_SECRETS_MANAGER. The generic AWS_ENDPOINT_URL, often MinIO, is ignored. http:// is refused unless loopback or FLAPI_ALLOW_INSECURE_SECRETS_ENDPOINT=1, and a WARNING says the endpoint decides who can log in.
  • No credentials in logs or responses:
    • init SQL is no longer logged;
    • init errors are redacted against the statement's own literals plus DSN/URL redaction;
    • AWS error text is trimmed and masked;
    • /api/v1/_config/project returns connection init with literals redacted.
  • Auth hardening: a dummy verify for unknown users (timing), constant-time compares, an exception gives 401, and a top-level block is honoured only for type: basic.
  • Docs: authentication guide (the secret JSON format, credential precedence, restart to rotate), CONFIG_REFERENCE, CLI_REFERENCE env table, security.md, the flapi-auth skill. The CHANGELOG lists each behaviour change and an upgrade note to rotate passwords if you ran a persistent db_path.

Red / green

  • New test_auth_secretsmanager.py with a fake Secrets Manager that verifies SigV4 (checked against AWS's get-vanilla vector).
  • RED on main: 15/17 fail at startup (wrong endpoint, NULL token).
  • RED on the intermediate commit 07e0ad5: 10/17 fail for the leak itself (/peek-users returns PWCANARY123, duckdb_secrets() lists flapi_users, the init SQL is logged).
  • A second RED round for the review findings: 10 integration and 5 unit tests.
  • GREEN: 28 passed, 1 skipped (legacy CREDENTIAL_CHAIN, which needs the aws extension), twice. flapi_tests passed (1015 before the review round). Auth, config-service and remote-template integration files pass (list in the session notes). check_skills --static-only passes.
  • Two crew reviews per round (correctness, security). All blockers and should-fix items are fixed.
  • Local note: the final rerun of 13 MCP/auth files and the full flapi_tests was cut off by host memory pressure, unrelated to this PR. CI is the gate for those.

Follow-ups

Closes #254

🤖 Generated with Claude Code

https://claude.ai/code/session_018txuxF9jXyiKakpUoXrKBi


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

- Fake Secrets Manager (GetSecretValue, AWS JSON 1.1) reached through
  AWS_ENDPOINT_URL_SECRETS_MANAGER / AWS_ENDPOINT_URL
- Basic auth against a fetched user; templates must not read the user
  table or list the bootstrap DuckDB secret
- An apostrophe in secret-key must not break startup; secret-key and
  secret-id must not appear in the debug log
- Regression guard: remote-config credentials reach templates only as the
  redacted zz_flapi_s3 secret
…rets-Manager auth (#254)

- The fake Secrets Manager verifies the AWS SigV4 signature against the
  secret key it knows, so tests assert which credentials signed the call,
  for which region, and that no session token was sent
- Endpoint precedence: AWS_ENDPOINT_URL_SECRETS_MANAGER over
  AWS_ENDPOINT_URL; AWS_IGNORE_CONFIGURED_ENDPOINT_URLS=true uses neither
- A running server at debug level logs neither key, also with an apostrophe
- Roles from the secret give 403/200; a PBKDF2 password verifies
- One secret shared by two endpoints and the top-level auth: one fetch
- Custom init: still authenticates, its secret is not visible to templates
- The schema API does not list the user table
- No keys configured: the SDK credential chain (environment) signs
…t overrides (#254)

- A key the DuckDB secret lacks read back as the string "NULL": every
  request carried X-Amz-Security-Token: NULL and AWS rejected it, and an
  omitted region became the region "NULL". Missing keys are now empty
- Region: the configured one, else AWS_REGION, else AWS_DEFAULT_REGION,
  else a startup error naming the key
- AWS_ENDPOINT_URL_SECRETS_MANAGER, else AWS_ENDPOINT_URL, becomes the
  client's endpointOverride unless AWS_IGNORE_CONFIGURED_ENDPOINT_URLS is
  true; the SDK for C++ does not read them itself
- The client no longer probes instance metadata for a region
…ate database (#254)

- secret-id/secret-key go straight to the AWS SDK; with neither, the SDK's
  default credential chain. No DuckDB secret and no SQL, so a key with an
  apostrophe works and httpfs is not needed
- A legacy init: runs in a private DuckDB (persistent secrets off); the
  main database's secret of that name is a deprecated fallback with a
  warning
- The fetched user list is parsed once into memory, keyed by secret-name,
  instead of a table every SQL template and the schema API could read;
  secret-table is accepted and ignored with a warning
- Each secret is fetched once, however many endpoints share it; the
  top-level auth: now parses from-aws-secretmanager too
- Aws::InitAPI runs once per process
- Init SQL is never logged: the Init: debug line is gone, and
  executeInitStatement errors name the statement position and a
  redacted DuckDB error instead of the statement
- secret-id and secret-key must be set together
- OpenPrivateDuckDb generalises the bootstrap DuckDB opener
…oint, rotation (#254)

- Authentication guide: the {"auth":[{username,password,roles}]} secret
  format, credential precedence, endpoint override variables, fetch-once
  and restart-to-rotate
- CONFIG_REFERENCE 7.5: secret-table ignored, init legacy, region fallback;
  2.4: persistent DuckDB secrets are visible to templates unless
  duckdb.allow_persistent_secrets is false
- security.md: where the users and credentials live, logging redaction
- flapi-auth skill teaches the new behaviour; secret-table is a forbidden
  term unless described as having no effect
- CHANGELOG Unreleased: Security and Fixed entries, behaviour changes
- Old auth_<name> / secret-table tables on a file db_path are dropped
- Only AWS_ENDPOINT_URL_SECRETS_MANAGER redirects; plain http off loopback
  is refused; an active override is warned about
- An unknown user takes as long as a wrong password
- Two blocks sharing a secret-name must agree
- AWS error messages are logged short with key ids masked
- A bearer block with a leftover from-aws-secretmanager does not fetch
- The region can come from the AWS profile
- Connection init literals are not returned by the project config APIs
- SQL error redaction: PEG tokens, prose apostrophes, DSNs, URLs
- Guards: top-level-only inheritance, malformed secret, init without a
  secret, clean exit after SIGTERM, legacy CREDENTIAL_CHAIN init
- Drop auth_<name> and secret-table tables older versions left in the
  main database (a file db_path kept them readable), with a warning
- Only AWS_ENDPOINT_URL_SECRETS_MANAGER overrides the endpoint; plain
  http off loopback is refused unless FLAPI_ALLOW_INSECURE_SECRETS_ENDPOINT
  is set; an active override is logged as a warning
- redactSqlErrorMessage takes the statement and replaces its literals,
  quoted identifiers and dollar bodies wherever the error repeats them,
  the token after "at or near", connection-string secrets and URL
  credentials; apostrophes in the message are no longer literals
- Connection init is returned with its literals redacted by
  /config, /api/v1/_config/project and flapi_get_project_config
- An unknown username is checked against a dummy hash shaped like the
  stored ones (inline users too); plaintext and MD5 compare in constant
  time over SHA-256 digests
- Blocks sharing a secret-name must agree on region, credentials and
  init; only enabled basic blocks fetch
- Region falls back to the AWS profile's region
- AWS error messages are logged short, key ids and long runs masked
- A legacy init that uses CREDENTIAL_CHAIN loads the aws extension
- authenticateAwsSecrets catches exceptions again (401, not a throw)
- AuthSignature keeps digests of secret-key and init, not the key
- Only AWS_ENDPOINT_URL_SECRETS_MANAGER overrides the endpoint; plain
  http needs loopback or FLAPI_ALLOW_INSECURE_SECRETS_ENDPOINT; both env
  vars in the reference tables
- Old auth tables are dropped at startup: rotate passwords if a file
  db_path was in use
- Region from the AWS profile; basic-only; blocks sharing a secret must
  agree; init has no side effects on the main database
- security.md: the default chain reads ~/.aws/config, credential_process
  included; timing, redaction and upgrade notes
- CHANGELOG: malformed secret, init without a secret, SDK chain, basic
  only, project-config init redaction, username timing
@jrosskopf
jrosskopf force-pushed the fix/gh-254-bootstrap-secrets branch from a72a77a to 24e76f8 Compare November 24, 2026 14:15
@jrosskopf
jrosskopf merged commit 9d663f2 into main Nov 24, 2026
29 checks passed
@jrosskopf
jrosskopf deleted the fix/gh-254-bootstrap-secrets branch November 24, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection-scoped secrets for bootstrap credentials

1 participant