Skip to content

feat: Restrict DuckDB external access for remote configs (#253) - #261

Merged
jrosskopf merged 17 commits into
mainfrom
feat/gh-253-external-access
Nov 24, 2026
Merged

jrosskopf merged 17 commits into
mainfrom
feat/gh-253-external-access

Conversation

@jrosskopf

@jrosskopf jrosskopf commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

New top-level block:

duckdb-hardening:
  external-access: auto      # auto (default) = restricted for a config loaded from s3/gs/az/http(s), else full
  allowed-directories: []
  allowed-paths: []

When restricted, DatabaseManager::applyExternalAccessPolicy() runs at the end of startup and:

  1. preloads every extension flAPI needs;
  2. turns autoinstall off;
  3. sets allowed_directories/allowed_paths (config prefix, template path, DuckLake data-path, embed:// when bundled, the user's lists);
  4. sets enable_external_access=false;
  5. sets lock_configuration=true with allowed_configs limited to what flAPI SETs per session.

flAPI also refuses INSTALL/LOAD/secret DDL in templates while restricted. A template's CREATE SECRET (ENDPOINT …, SCOPE 's3://mybucket/') redirected both data reads and flAPI's own template reads to a host of the template's choosing; that is verified on main with a honeypot. Local configs keep full access by default, so they see no change.

Draft: merges after #256, #258 and the #254 PR, then gets a cross-PR review against them.

Red / green

  • RED on main: 23/30 then 5 more (/etc/passwd, URLs, other buckets, .. traversal, mybucket-evil, ATTACH, COPY TO, LOAD/INSTALL, SET bypasses, the CREATE SECRET redirect, missing policy line).
  • GREEN: test_external_access.py 35 passed; C++ [external_access] 9 cases.
  • Also green:
    • test_remote_templates_s3 (12) and test_remote_templates (37)
    • cache: reliability 15, ops 4, scheduler/maintenance 10, catalog 14
    • MCP: integration 33, methods 35
    • pack: hardening 21, validates 3
    • self-packaging: http 3, main 8
    • check_skills --static-only
  • The full serial suite reached 98% with no failure before host memory pressure (unrelated) cut it off. CI is the gate.

Known limits (documented in security.md / DESIGN_DECISIONS §14)

  • Whoever writes flapi.yaml chooses the mode. There is no floor the config cannot lower yet (follow-up).
  • Connection init, duckdb: settings and a Secrets-Manager init run unrestricted at startup.
  • Allowed directories are writable, so a template can COPY into its own prefix.
  • Scanner extensions other than sqlite/postgres are unaudited.

Closes #253

🤖 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.

- New test/integration/test_external_access.py: a local server with
  `duckdb-hardening.external-access: restricted` must refuse /etc/passwd,
  an http URL, another bucket, ATTACH outside the allowed dirs, LOAD of a
  non-preloaded extension and INSTALL from a foreign repository, while the
  own CSV, a DuckLake cache refresh and an MCP tools/call keep working
- A remote (s3://) config with no block defaults to restricted; with
  `external-access: full` local files are readable again
- `allowed-directories` opens exactly the listed prefix
- Local configs without the block keep full access (no-regression guard)
- Startup logs `external access: restricted` / `external access: full`
- Failure messages separate "SERVER DID NOT START" from "NOT REFUSED"
- Match a refusal on the log lines of that request only (request_id from the 500 body)
- Give the module fixture its own FakeS3 subclass and honeypot; FakeS3 records per class
- Pin the policy line exactly once
- Add traversal (.., %2e%2e) and prefix-boundary escapes, the configuration lock
  (secret_directory, enable_external_access, allowed_directories, http_proxy), COPY TO
  outside, glob('/etc/*'), INSTALL FROM core / LOAD refused by flAPI, a CREATE SECRET
  ENDPOINT redirect, reload of a remote endpoint, cache gc/compact, template.path in
  another bucket and a restricted packed bundle reading embed://
- A DuckDB error spans lines and the request_id lands on the record's last line:
  group the log into records before matching
- ATTACH (TYPE sqlite) outside the allowed directories and ATTACH (TYPE postgres)
  to a honeypot must be refused
- New top-level duckdb-hardening block: external-access auto|full|restricted,
  allowed-directories, allowed-paths; auto = restricted for a remote config
- DatabaseManager::applyExternalAccessPolicy runs last in startup: preloads httpfs,
  ducklake, azure and init-loaded extensions, turns autoinstall off, sets
  allowed_directories/allowed_paths, enable_external_access=false, then
  lock_configuration with allowed_configs = what flAPI SETs per connection
- Templates may not INSTALL/LOAD or CREATE/DROP SECRET while restricted (refused
  at render, before DuckDB sees them): a temporary secret is instance-wide and
  redirected every read of the allowed bucket, flAPI's own config reads included
- LoadOrInstallExtension and query errors explain a refusal by the hardening
- The policy is logged once: external access: restricted (...) / full (...)
#253)

- CONFIG_REFERENCE 2.4.1: keys, what restricted does in order, the policy line, limits
- security.md and DESIGN_DECISIONS 14: why it runs last, preloads, locks the
  configuration, refuses INSTALL/LOAD and secret DDL, and why allowed directories
  are writable (known limit) and the extension directory is not allowed
- cloud-storage guide, flapi-setup and flapi-deploy skills, CHANGELOG Unreleased
  with an upgrade note for remote configs that read other buckets or local paths
- node["allowed-directories"] / node["allowed-paths"] literally, so the readers are
  greppable and check_skills sees the keys
…ow list (#253)

- RefusedTemplateStatement: LOAD/INSTALL/FORCE INSTALL/UPDATE EXTENSIONS/secret DDL,
  keywords as identifiers pass, unparsable SQL with LOAD fails closed
- duckdb-hardening parsing: defaults, absolute entries, URLs kept, bad mode/key
- ComputeExternalAccessAllowList: config dir, templates, DuckLake data path,
  embed:// only in a bundle, never the extension directory
- DatabaseManager::ComputeExternalAccessPreload, unchanged behaviour, so a unit test
  can check what is preloaded
- Statements outside a template allowlist refused by flAPI: EXPLAIN ANALYZE of
  INSTALL/LOAD/CREATE SECRET/DROP SECRET, PREPARE of secret DDL, PRAGMA and
  IMPORT/EXPORT DATABASE, ATTACH/DETACH, COPY FROM DATABASE, SET/RESET GLOBAL and a
  bare SET of a global-default setting; what templates use keeps running
- The IMPORT DATABASE chain: COPY a schema.sql into an allowed dir, import it
- HTTPS under restricted with a CA bundle outside the allowed dirs (local TLS server)
- A persistent secret in duckdb.secret_directory serving reads under restricted
- flapi cache refresh (one-shot) applies the policy to a remote config
- C++: LoadOrInstallExtension decides per connection; preload covers aws for
  credential_chain and azure in connection properties; CA bundle and file:// in the
  allow list
…#253)

- Every rendered template is parsed and each statement must be of an allowed type,
  recursing into EXPLAIN and PREPARE: EXPLAIN ANALYZE CREATE/DROP SECRET and INSTALL
  walked past the keyword-gated denylist. PRAGMA (IMPORT DATABASE runs a planted
  schema.sql), EXPORT, ATTACH/DETACH, COPY FROM DATABASE, secret DDL, extension
  statements and SET/RESET GLOBAL (or a bare SET resolving to global) are refused;
  approved SQL is remembered (bounded) so a stable template is parsed once
- Load persistent secrets before external access goes off; allow the CA bundle httpfs
  uses (system bundles, SSL_CERT_FILE, ca_cert_file) so https works
- Preload aws for from-aws-secretmanager or credential_chain; azure detection matches
  main() (connection properties, metadata path)
- LoadOrInstallExtension asks the connection whether external access is on, so an
  unrestricted DuckDB (the bootstrap) gets DuckDB's own answer; hints name the defaults
  duckdb.default-extensions replaces
- Allow the DuckLake data path stored in the catalog; strip file:// from entries
- flapi cache refresh configures cloud credentials and applies the policy
- A policy failure shuts the database down and logs once, redacted
…imits (#253)

- CONFIG_REFERENCE 2.4.1: the allowlist, persistent secrets, CA bundles, the one-shot,
  default-extensions replacing the defaults, extensions only templates use
- Limits: flapi.yaml and the CA bundle are writable when allowed, redirects are not
  re-checked, includes outside the prefix fail on a hot reload
- security.md, DESIGN_DECISIONS 14, CHANGELOG and the flapi-setup skill follow
…#253)

- After #254, Secrets Manager auth never uses the main DuckDB: the AWS SDK fetches the users
  and a legacy init runs in a private DuckDB, so preloading aws and the init's extensions
  into the main database only downloaded extensions templates never needed
- Connection inits with CREDENTIAL_CHAIN still preload aws
- With secret-id/secret-key and with a legacy init, auth works under restricted,
  the main database gets no aws preload, and templates still cannot list the secret
, #253)

- With log-http-requests on and restricted, a template's HTTP read is logged, and
  CALL disable_logging() and SET redact_http_logs are refused by the locked configuration
- OBSERVABILITY.md and the observability spec say so
…restricted (#253)

- Red: the init's private DuckDB has full file and network access under restricted
…ricted (#253)

- An endpoint YAML's auth.from-aws-secretmanager.init ran with full file and network
  access after the policy; for a remote config that YAML is in the untrusted bucket.
  Under restricted its private DuckDB now has external access off and a locked config
- flapi cache refresh redacts URLs in a failed policy's error, as the server does
- CONFIG_REFERENCE no longer says aws is preloaded for Secrets-Manager auth
@jrosskopf

Copy link
Copy Markdown
Contributor Author

Rebased onto main with #254 (#260) and #252 (#258). Cross-PR changes:

🤖 Generated with Claude Code

https://claude.ai/code/session_018txuxF9jXyiKakpUoXrKBi

@jrosskopf
jrosskopf merged commit bda6888 into main Nov 24, 2026
55 of 56 checks passed
@jrosskopf
jrosskopf deleted the feat/gh-253-external-access 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.

Harden remote-origin configs with enable_external_access=false

1 participant