Skip to content

feat: inject pg_duckdb S3/GCS/R2 secrets into DuckDB connections#74

Merged
YuweiXiao merged 2 commits intomainfrom
worktree-duckdb-secrets
Apr 17, 2026
Merged

feat: inject pg_duckdb S3/GCS/R2 secrets into DuckDB connections#74
YuweiXiao merged 2 commits intomainfrom
worktree-duckdb-secrets

Conversation

@YuweiXiao
Copy link
Copy Markdown
Collaborator

Summary

  • Reads S3/GCS/R2/Azure credentials from pg_duckdb's existing FDW catalogs (pg_foreign_server + pg_user_mapping) and injects them as CREATE SECRET statements into pg_duckpipe's in-memory DuckDB connections
  • New duckdb_secrets module in duckpipe-core with a shared SQL query (SECRET_QUERY) that builds complete CREATE SECRET statements server-side
  • Both bgworker (SPI) and daemon (TCP) modes read secrets at startup and pass them through FlushCoordinator → flush threads + snapshot workers
  • Secret failures are non-fatal (logged as warnings) — local-storage tables work fine without them
  • Secrets shared across threads via Arc<Vec<String>> for zero-cost cloning
  • No new config keys or tables — reuses pg_duckdb's existing FDW catalog entries

Test plan

  • 6 unit tests for build_create_secret_sql (option parsing, quoting, edge cases)
  • New duckdb_secrets regression test: creates S3 secret via duckdb.create_simple_secret(), verifies catalog discovery, validates generated SQL format
  • ducklake_catalog_connstr regression test passes (exercises full bgworker + flush path with modified FlushCoordinator::new signature)
  • group_config regression test passes
  • cargo fmt --all --check clean
  • cargo check --workspace clean (no new warnings)

🤖 Generated with Claude Code

YuweiXiao and others added 2 commits April 15, 2026 22:20
pg_duckpipe's in-memory DuckDB connections had no cloud storage
credentials, so DuckLake tables with storage_location='s3://...'
would fail on flush. This reads secrets from pg_duckdb's existing
FDW catalogs (pg_foreign_server + pg_user_mapping) at bgworker/daemon
startup and injects them as CREATE SECRET statements into every
DuckDB connection.

- New duckdb_secrets module with shared SQL query (SECRET_QUERY)
- Secrets threaded through FlushCoordinator → flush threads + snapshots
- Both bgworker (SPI) and daemon (TCP) modes supported
- Secret failures are non-fatal (logged as warnings)
- Arc<Vec<String>> for zero-cost sharing across flush threads

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The raw pg_user_mapping catalog has column-level ACL in PG 17+ that
restricts umoptions visibility. Switch SECRET_QUERY to use the
pg_user_mappings VIEW which applies proper access control (shows
options when the user is the mapped user with USAGE on the server,
or is a superuser). Also fixes test assertion for lowercase option
names (PG lowercases unquoted FDW option identifiers).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@YuweiXiao YuweiXiao merged commit 79ad330 into main Apr 17, 2026
5 checks passed
@YuweiXiao YuweiXiao deleted the worktree-duckdb-secrets branch April 17, 2026 03:30
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.

1 participant