Security Hardening for SQL Templates
A SQL template runs on DuckDB, and DuckDB can do much more than query your tables. Left alone, a template can read any local file (read_csv('/etc/passwd')), any URL or bucket, ATTACH or COPY anywhere and LOAD any extension. When the templates come from a bucket, whoever can write to that bucket can make the server do all of that.
Since v26.11.25 the top-level duckdb-hardening: block decides what templates may reach outside the database. By the end of this page you know:
- what
auto,fullandrestrictedmean, and which one you get by default; - how to allow the extra buckets and directories your templates read;
- which statements a template may no longer run under
restricted; - what to check when you upgrade.
The duckdb-hardening block
It is a top-level block of flapi.yaml, not part of duckdb: (every scalar under duckdb: is handed to DuckDB as a setting).
# flapi.yaml
duckdb-hardening:
external-access: restricted # auto (default) | full | restricted
allowed-directories:
- s3://shared-reference-data/ # another bucket the templates read
- /srv/flapi/data
allowed-paths:
- /srv/flapi/lookup/countries.csv # single files
| Key | Default | Meaning |
|---|---|---|
external-access | auto | auto, full or restricted. Any other value stops startup, naming the key. |
allowed-directories | [] | Extra prefixes templates may read and write under restricted. Relative entries resolve against the working directory and get a trailing /; URLs (s3://other-bucket/data/) are kept as written. |
allowed-paths | [] | Extra single files, same rules without the trailing /. |
An unknown key inside the block, a scalar where a list belongs, or an empty entry stops startup.
What auto picks
Main config (--config) | auto means |
|---|---|
Remote: s3://, gs://, az://, http(s):// | restricted |
Local file, or a packed bundle (flapi pack) | full |
So local configs and packed binaries see no change. With a local flapi.yaml and a remote template.path, auto is full: set restricted yourself.
The policy is logged once at startup:
external access: restricted (auto: the configuration is remote; allowed: s3://bucket/, ...)
external access: full (auto: the configuration is local)
What restricted does
Once, at the very end of startup (after the DuckLake ATTACH, the connection init: SQL and the cloud credentials), flAPI:
- Loads the extensions flAPI needs:
httpfs,ducklake(with caching on),azure(when something namesaz://), every extension a connectioninitloads or installs, andawsfor aCREDENTIAL_CHAINsecret. Then it turnsautoinstall_known_extensionsoff. - Sets the allowed directories: the config's directory (for a remote config, its URL prefix with the query string stripped),
template.path, the DuckLakedata-path,embed://in a packed bundle, and yourallowed-directories/allowed-paths. DuckDB adds the attached database files and its temp directory itself. - Switches external access off (
enable_external_access = false). Any other file, URL, bucket,ATTACHtarget or extension load is refused withPermission Error: ... disabled by configuration. - Locks the DuckDB configuration. A template can change only
TimeZone,default_order,enable_profilingandtracked_metrics, the settings flAPI itself sets per connection.
Startup also loads the persistent secrets and allows the system CA bundle (plus SSL_CERT_FILE / ca_cert_file when set), so https and stored secrets keep working. flapi cache refresh applies the same policy.
Statements a template may run
While restricted, every rendered template (endpoint, cache populate, write, MCP tool, config-service expand) is parsed and checked against an allowlist of statement types before DuckDB sees it.
| Allowed | Refused |
|---|---|
SELECT / WITH, INSERT, UPDATE, DELETE, MERGE | PRAGMA (including IMPORT DATABASE), EXPORT DATABASE |
CREATE / DROP / ALTER of tables, views, macros, schemas, sequences, indexes, types | ATTACH / DETACH, COPY FROM DATABASE |
COPY (within the allowed directories) | INSTALL / LOAD / UPDATE EXTENSIONS |
Transactions, CALL of table functions, VACUUM / ANALYZE | CREATE / DROP SECRET |
PREPARE / EXECUTE / EXPLAIN of an allowed statement | SET GLOBAL / RESET GLOBAL |
SET SESSION / RESET SESSION, SET VARIABLE, a bare SET of a session setting (USE, schema, search_path) | A bare SET of a global-default setting (SET TimeZone: write SET SESSION TimeZone) |
A refused statement fails with ... is not allowed in a template: external access is restricted (duckdb-hardening.external-access). Wrapping does not help: EXPLAIN ANALYZE and PREPARE are judged by the statement they wrap, and SQL flAPI cannot parse is refused.
Why so strict? DuckDB still lets INSTALL ... FROM core reach the official repository with external access off, and a temporary secret is instance-wide: a template's CREATE SECRET (TYPE s3, ENDPOINT ..., SCOPE 's3://your-bucket/') would redirect every endpoint's reads of that bucket, and flAPI's own template reads, to another host.
duckdb_extensions() fails in a template under restricted: it scans the extension directory, which is deliberately not allowed (allowed directories are writable, and a file planted there would load at the next start).
Load extensions and secrets at startup
Under restricted nothing can load after startup. Two ways to make an extension available to templates:
# Option 1: LOAD it in a connection init (runs at startup, with full access)
connections:
spreadsheets:
init: |
INSTALL excel;
LOAD excel;
# Option 2: list it in duckdb.default-extensions.
# This REPLACES the defaults, so list those too.
duckdb:
default-extensions: [httpfs, ducklake, fts, json, postgres, sqlite, parquet, spatial]
Secrets belong in a connection init as well: CREATE SECRET in a template is refused. aws is preloaded when a connection init uses credential_chain, and azure when anything names az://.
An endpoint's auth.from-aws-secretmanager.init runs in a private DuckDB with external access off and its configuration locked: it can create its secret, but cannot read or write files, reach the network or INSTALL. See AWS Secrets Manager.
Limits
- Allowed directories are writable too. A template can
COPY ... TOa file under the config directory,template.pathor the DuckLakedata-path. With a local config directory that includesflapi.yamlitself. Keep flAPI's credentials and files read-only where the deployment allows it. - HTTP redirects are followed without re-checking the allow list (DuckDB checks the first URL only). Do not allow an http(s) origin whose redirects you do not control.
- Whoever writes
flapi.yamlchooses the mode. With the config in a bucket, the bucket writer can setfull. Write access to the config bucket is code execution. - Connection
initSQL and theduckdb:settings run at startup, before the policy, with full access. - An endpoint YAML
{{include}}outside the config or template prefix fails on a hot reload underrestricted.
Upgrading to v26.11.25
If your config is local or packed, nothing changes. If --config is remote:
- Reads of other buckets or local paths fail with
Permission Error: ... disabled by configuration. List them underduckdb-hardening.allowed-directories(orallowed-paths), or setduckdb-hardening.external-access: full. - Extensions a template needs must be loaded at startup:
LOADin a connectioninit, orduckdb.default-extensions(which replaces the defaultshttpfs, ducklake, fts, json, postgres, sqlite, parquet). - Secrets go in a connection
init. A template may onlySET SESSION(orSETa session setting) ofTimeZone,default_order,enable_profiling,tracked_metrics,schema/search_path.ATTACH,PRAGMAandSET GLOBALin templates fail. duckdb_extensions()in a template fails.- Secrets-Manager
init:runs with external access off: creating its secret works;INSTALL, file and network access in it fail.
Check the startup log line external access: ... after the upgrade to see the mode and the allow list flAPI derived.
Related
- Cloud Storage and VFS: loading
flapi.yamland templates from S3, GCS, Azure and HTTPS - Multi-Environment Cloud Config: one image, three buckets
- Authentication: who may call an endpoint
CONFIG_REFERENCE.md§2.4.1: the upstream reference