CREATE SECRET
CREATE SECRET stores a credential for providers, external connections,
foreign data wrappers, and backup operations. Only administrators can create
secrets in the current release.
CREATE SECRET name TYPE TEXT VALUE 'sensitive value';
CREATE SECRET openai_api_key TYPE TEXT VALUE '...';
CREATE SECRET IF NOT EXISTS service_credentials TYPE JSON
VALUE '{"access_token":"..."}';
The value cannot be read through SQL, SHOW, system views, audit output, error
messages, or dumps. Providers need to recover credentials to authenticate, so
values are encrypted at rest rather than hashed.
For systemd services, provide the key as a protected credential. Configure
LoadCredentialEncrypted in the unit; the process reads the amphi-secret-key
credential from $CREDENTIALS_DIRECTORY:
[Service]
LoadCredentialEncrypted=amphi-secret-key:/etc/credstore.encrypted/amphi-secret-key
The decrypted credential must contain 64 hexadecimal characters (32 bytes),
optionally followed by a newline. This credential is the only supported key
configuration; environment variables are not supported. Without
CREDENTIALS_DIRECTORY, the server can start without secret access, but
creating or resolving secrets fails.
The key is not written to the data directory. secrets.bin and its temporary
file are restricted to the server user (mode 0600); keep the data directory
accessible only to that user as well. Without the key, the server can start,
but creating or resolving secrets fails. Storage uses AES-256-GCM and an atomic
file update. The file format is not a public API. KMS, HSM, and external secret
managers are future work.
CREATE SECRET writes outside the catalog transaction, so run it in autocommit;
ROLLBACK cannot undo it. Statement audit events redact the SQL literal.
Rotate a value without changing its name or type:
ALTER SECRET openai_api_key VALUE 'new-sensitive-value';
ALTER SECRET encrypts the replacement value with a fresh nonce and atomically
rewrites secrets.bin. It must run in autocommit and cannot be rolled back. The
secret type is preserved. Statement and security audit events include the secret
name but redact the value.
Remove a secret that is no longer used:
DROP SECRET openai_api_key;
DROP SECRET IF EXISTS optional_key;
DROP SECRET is administrator-only and autocommit-only. It refuses to remove a
secret referenced by an external connection, server option, or foreign-table
option. Remove those definitions first, then drop the secret. IF EXISTS
suppresses only the missing secret error; it does not bypass dependency checks.
Secret values remain outside logical dumps. Fine-grained permissions are not
available yet.
Reference a secret from an external connection instead of passing its value to the provider:
CREATE EXTERNAL CONNECTION openai_prod
PROVIDER openai
OPTIONS (api_key = SECRET openai_api_key);