Skip to main content

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, full and restricted mean, 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
KeyDefaultMeaning
external-accessautoauto, 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:

  1. Loads the extensions flAPI needs: httpfs, ducklake (with caching on), azure (when something names az://), every extension a connection init loads or installs, and aws for a CREDENTIAL_CHAIN secret. Then it turns autoinstall_known_extensions off.
  2. Sets the allowed directories: the config's directory (for a remote config, its URL prefix with the query string stripped), template.path, the DuckLake data-path, embed:// in a packed bundle, and your allowed-directories / allowed-paths. DuckDB adds the attached database files and its temp directory itself.
  3. Switches external access off (enable_external_access = false). Any other file, URL, bucket, ATTACH target or extension load is refused with Permission Error: ... disabled by configuration.
  4. Locks the DuckDB configuration. A template can change only TimeZone, default_order, enable_profiling and tracked_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.

AllowedRefused
SELECT / WITH, INSERT, UPDATE, DELETE, MERGEPRAGMA (including IMPORT DATABASE), EXPORT DATABASE
CREATE / DROP / ALTER of tables, views, macros, schemas, sequences, indexes, typesATTACH / DETACH, COPY FROM DATABASE
COPY (within the allowed directories)INSTALL / LOAD / UPDATE EXTENSIONS
Transactions, CALL of table functions, VACUUM / ANALYZECREATE / DROP SECRET
PREPARE / EXECUTE / EXPLAIN of an allowed statementSET 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 ... TO a file under the config directory, template.path or the DuckLake data-path. With a local config directory that includes flapi.yaml itself. 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.yaml chooses the mode. With the config in a bucket, the bucket writer can set full. Write access to the config bucket is code execution.
  • Connection init SQL and the duckdb: 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 under restricted.

Upgrading to v26.11.25​

If your config is local or packed, nothing changes. If --config is remote:

  1. Reads of other buckets or local paths fail with Permission Error: ... disabled by configuration. List them under duckdb-hardening.allowed-directories (or allowed-paths), or set duckdb-hardening.external-access: full.
  2. Extensions a template needs must be loaded at startup: LOAD in a connection init, or duckdb.default-extensions (which replaces the defaults httpfs, ducklake, fts, json, postgres, sqlite, parquet).
  3. Secrets go in a connection init. A template may only SET SESSION (or SET a session setting) of TimeZone, default_order, enable_profiling, tracked_metrics, schema / search_path. ATTACH, PRAGMA and SET GLOBAL in templates fail.
  4. duckdb_extensions() in a template fails.
  5. 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.

🍪 Cookie Settings