CipherStashDocs

Reference

Complete configuration reference for CipherStash Proxy, including all TOML and environment variable options, CLI flags, Prometheus metrics, and per-target log levels.

Configuration loading order

Proxy accepts configuration from a TOML file, environment variables, or both.

  1. If cipherstash-proxy.toml exists in the current working directory, Proxy reads it first.
  2. Proxy then reads any environment variables that are set.
  3. When both are present, environment variables override values from the TOML file.

Config options

[server]

OptionEnv variableDefaultDescription
hostCS_SERVER__HOST0.0.0.0Proxy listen address
portCS_SERVER__PORT6432Proxy listen port
require_tlsCS_SERVER__REQUIRE_TLSfalseEnforce TLS for client-to-proxy connections
shutdown_timeoutCS_SERVER__SHUTDOWN_TIMEOUT2000Milliseconds to wait for connections to drain on shutdown
worker_threadsCS_SERVER__WORKER_THREADSNUMBER_OF_CORES/2 or 4Number of server worker threads
thread_stack_sizeCS_SERVER__THREAD_STACK_SIZE2097152 (2 MiB)Thread stack size in bytes. Automatically set to 4 MiB when log level is debug or trace
cipher_cache_sizeCS_SERVER__CIPHER_CACHE_SIZE64Maximum number of encryption/decryption operations to cache
cipher_cache_ttl_secondsCS_SERVER__CIPHER_CACHE_TTL_SECONDS3600Seconds before cached cipher operations expire

[database]

OptionEnv variableDefaultDescription
hostCS_DATABASE__HOST0.0.0.0Database host address
portCS_DATABASE__PORT5432Database port
nameCS_DATABASE__NAME(required)Database name
usernameCS_DATABASE__USERNAME(required)Database username
passwordCS_DATABASE__PASSWORD(required)Database password
connection_timeoutCS_DATABASE__CONNECTION_TIMEOUTnoneMilliseconds to hold an idle connection open. In production, set this higher than your application's connection pool idle timeout
with_tls_verificationCS_DATABASE__WITH_TLS_VERIFICATIONfalseEnable TLS verification between Proxy and the database
config_reload_intervalCS_DATABASE__CONFIG_RELOAD_INTERVAL60Seconds between encrypted index configuration reloads
schema_reload_intervalCS_DATABASE__SCHEMA_RELOAD_INTERVAL60Seconds between database schema reloads

[tls]

Configure TLS for client-to-proxy connections. Provide either file paths or inline PEM strings.

OptionEnv variableDescription
certificate_pathCS_TLS__CERTIFICATE_PATHPath to the public certificate .crt file
private_key_pathCS_TLS__PRIVATE_KEY_PATHPath to the private key file
certificate_pemCS_TLS__CERTIFICATE_PEMPublic certificate as a PEM string
private_key_pemCS_TLS__PRIVATE_KEY_PEMPrivate key as a PEM string

[auth]

OptionEnv variableDescription
workspace_crnCS_WORKSPACE_CRNCipherStash Workspace CRN
client_access_keyCS_CLIENT_ACCESS_KEYCipherStash Client Access Key

[encrypt]

OptionEnv variableDescription
default_keyset_idCS_DEFAULT_KEYSET_IDCipherStash Dataset ID
client_idCS_CLIENT_IDCipherStash Client ID
client_keyCS_CLIENT_KEYCipherStash Client Key

[log]

OptionEnv variableDefaultDescription
levelCS_LOG__LEVELinfoGlobal log level. Valid values: error, warn, info, debug, trace
formatCS_LOG__FORMATpretty (terminal), structured (non-terminal)Log format. Valid values: pretty, text, structured (JSON)
outputCS_LOG__OUTPUTstdoutLog output destination. Valid values: stdout, stderr
ansi_enabledCS_LOG__ANSI_ENABLEDtrue (terminal), false (non-terminal)Enable colored output
slow_statementsCS_LOG__SLOW_STATEMENTSfalseEnable slow statement logging
slow_statement_min_duration_msCS_LOG__SLOW_STATEMENT_MIN_DURATION_MS2000Minimum duration in milliseconds for a statement to be considered slow
slow_db_response_min_duration_msCS_LOG__SLOW_DB_RESPONSE_MIN_DURATION_MS100Minimum duration in milliseconds for a database response to be considered slow

[prometheus]

OptionEnv variableDefaultDescription
enabledCS_PROMETHEUS__ENABLEDfalseEnable the Prometheus metrics exporter
portCS_PROMETHEUS__PORT9930Port for the Prometheus exporter

Full TOML example

[server]
host = "0.0.0.0"
port = "6432"
require_tls = "false"
shutdown_timeout = "2000"
worker_threads = "4"
thread_stack_size = "2097152"
cipher_cache_size = "64"
cipher_cache_ttl_seconds = "3600"

[database]
host = "0.0.0.0"
port = "5432"
name = "database"
username = "username"
password = "password"
connection_timeout = "300000"
with_tls_verification = "false"
config_reload_interval = "60"
schema_reload_interval = "60"

[tls]
certificate_path = "./server.crt"
private_key_path = "./server.key"

[auth]
workspace_crn = "cipherstash-workspace-crn"
client_access_key = "cipherstash-client-access-key"

[encrypt]
default_keyset_id = "cipherstash-dataset-id"
client_id = "cipherstash-client-id"
client_key = "cipherstash-client-key"

[log]
level = "info"
format = "pretty"
output = "stdout"
ansi_enabled = "true"
slow_statements = "false"
slow_statement_min_duration_ms = "2000"
slow_db_response_min_duration_ms = "100"

[prometheus]
enabled = "false"
port = "9930"

Development settings

Default settings are tuned for production. When running Proxy locally, override these for a better development experience. None of these settings are appropriate for production.

Enable colored, human-readable logs:

CS_LOG__FORMAT="pretty"
CS_LOG__ANSI_ENABLED="true"

Reduce reload intervals when iterating on your schema:

CS_DATABASE__CONFIG_RELOAD_INTERVAL="10"
CS_DATABASE__SCHEMA_RELOAD_INTERVAL="10"

Slow query logging

Slow query logging helps you identify statements that take longer than expected. Enable it with:

CS_LOG__SLOW_STATEMENTS="true"

By default, any statement taking longer than 2000 ms is flagged. Tune the thresholds to match your latency expectations:

CS_LOG__SLOW_STATEMENT_MIN_DURATION_MS="500"   # statement total time
CS_LOG__SLOW_DB_RESPONSE_MIN_DURATION_MS="200" # database round-trip only

When a slow statement is detected, Proxy emits a structured log line at the SLOW_STATEMENTS target. With format = "pretty", it looks like:

WARN  slow_statement  duration_ms=620  query="SELECT * FROM users WHERE ..."

Use these log lines to identify queries that need indexes or to spot unexpectedly slow EQL operations. To isolate slow-statement output in production, set CS_LOG__SLOW_STATEMENTS_LEVEL=warn while keeping the global level at error.

Docker-specific options

These environment variables are only available in the Docker container image and are not present in the binary.

Env variableDescription
CS_DATABASE__INSTALL_EQLInstall EQL on container startup
CS_DATABASE__INSTALL_EXAMPLE_SCHEMALoad the example schema on container startup
CS_DATABASE__INSTALL_AWS_RDS_CERT_BUNDLEAdd the AWS RDS certificate bundle for TLS verification

CS_DATABASE__INSTALL_EQL and CS_DATABASE__INSTALL_EXAMPLE_SCHEMA are for development use only. Install EQL using the installation script as a database migration in production.

Per-target log levels

Override the log level for specific internal components using the pattern CS_LOG__{TARGET}_LEVEL. These environment variables accept the same values as CS_LOG__LEVEL.

Env variableTargetDescription
CS_LOG__DEVELOPMENT_LEVELDEVELOPMENTGeneral development logging
CS_LOG__AUTHENTICATION_LEVELAUTHENTICATIONClient authentication and SASL
CS_LOG__CONFIG_LEVELCONFIGConfiguration loading
CS_LOG__CONTEXT_LEVELCONTEXTConnection context
CS_LOG__ENCODING_LEVELENCODINGData encoding and decoding
CS_LOG__ENCRYPT_LEVELENCRYPTEncryption operations
CS_LOG__DECRYPT_LEVELDECRYPTDecryption operations
CS_LOG__ENCRYPT_CONFIG_LEVELENCRYPT_CONFIGEncryption configuration loading
CS_LOG__ZEROKMS_LEVELZEROKMSZeroKMS cipher initialization, cache, and connectivity
CS_LOG__MIGRATE_LEVELMIGRATESchema migration
CS_LOG__PROTOCOL_LEVELPROTOCOLPostgreSQL wire protocol
CS_LOG__MAPPER_LEVELMAPPERSQL statement mapping and transformation
CS_LOG__SCHEMA_LEVELSCHEMADatabase schema analysis
CS_LOG__SLOW_STATEMENTS_LEVELSLOW_STATEMENTSSlow statement detection

CLI reference

cipherstash-proxy [OPTIONS] [DBNAME] [COMMAND]

Commands

CommandDescription
encryptEncrypt existing plaintext data in the database
helpPrint help information

Arguments and options

FlagDefaultDescription
DBNAMEDatabase name (positional, optional)
-H, --db-host <DB_HOST>127.0.0.1Database host
-u, --db-user <DB_USER>postgresDatabase user
-p, --config-file-path <CONFIG_FILE_PATH>cipherstash-proxy.tomlPath to the TOML config file
-l, --log-level <LOG_LEVEL>infoLog level
-f, --log-format <LOG_FORMAT>pretty (terminal), structured (non-terminal)Log format

Prometheus metrics

Enable the Prometheus exporter by setting CS_PROMETHEUS__ENABLED=true. Metrics are exposed on port 9930 by default.

MetricTypeDescription
cipherstash_proxy_keyset_cipher_cache_hits_totalCounterKeyset-scoped cipher cache hits
cipherstash_proxy_keyset_cipher_cache_miss_totalCounterCipher cache misses requiring initialization
cipherstash_proxy_keyset_cipher_init_totalCounterNew keyset-scoped cipher initializations
cipherstash_proxy_keyset_cipher_init_duration_secondsHistogramDuration of cipher initialization, including ZeroKMS network call
cipherstash_proxy_clients_active_connectionsGaugeCurrent active client connections
cipherstash_proxy_clients_bytes_received_totalCounterBytes received from clients
cipherstash_proxy_clients_bytes_sent_totalCounterBytes sent to clients
cipherstash_proxy_decrypted_values_totalCounterIndividual values decrypted
cipherstash_proxy_decryption_duration_secondsHistogramTime spent performing decryption
cipherstash_proxy_decryption_duration_seconds_countCounterNumber of decryption timing observations
cipherstash_proxy_decryption_duration_seconds_sumCounterTotal cumulative decryption time
cipherstash_proxy_decryption_error_totalCounterUnsuccessful decryption operations
cipherstash_proxy_decryption_requests_totalCounterZeroKMS decrypt requests
cipherstash_proxy_encrypted_values_totalCounterIndividual values encrypted
cipherstash_proxy_encryption_duration_secondsHistogramTime spent performing encryption
cipherstash_proxy_encryption_duration_seconds_countCounterNumber of encryption timing observations
cipherstash_proxy_encryption_duration_seconds_sumCounterTotal cumulative encryption time
cipherstash_proxy_encryption_error_totalCounterUnsuccessful encryption operations
cipherstash_proxy_encryption_requests_totalCounterZeroKMS encrypt requests
cipherstash_proxy_rows_encrypted_totalCounterEncrypted rows returned to clients
cipherstash_proxy_rows_passthrough_totalCounterNon-encrypted rows returned to clients
cipherstash_proxy_rows_totalCounterTotal rows returned to clients
cipherstash_proxy_server_bytes_received_totalCounterBytes received from the PostgreSQL server
cipherstash_proxy_server_bytes_sent_totalCounterBytes sent to the PostgreSQL server
cipherstash_proxy_statements_execution_duration_secondsHistogramDatabase SQL execution time
cipherstash_proxy_statements_session_duration_secondsHistogramTotal statement processing time (encrypt + execute + decrypt)
cipherstash_proxy_statements_encrypted_totalCounterStatements requiring encryption
cipherstash_proxy_statements_passthrough_totalCounterStatements not requiring encryption
cipherstash_proxy_statements_totalCounterTotal statements processed
cipherstash_proxy_statements_unmappable_totalCounterStatements that could not be mapped

Supported architectures

CipherStash Proxy is available as a Docker container image for linux/arm64 architectures.

On this page