Provider Sessions and Secrets
See also:
[SET] [UNSET] [ Session Variables ] [ Global Flags ]
A session can bind a provider under an alias with its own credentials, tenancy label, parameter defaults and request concurrency limits, so several accounts or tenants of the same provider can be queried in one session, and in one statement. Credential fields can also be overridden for the session, and secrets can be held in session memory or, with an operator opt-in, in the operating system's secret store. From v1.1.959 a session can also set tuning and parameter defaults for a canonical provider and overlay patches on the provider documents. All of this is configured with SET and UNSET; aliases, credential overrides and session secrets are available in StackQL v1.0 and later. The configuration of the session's next transaction, $.transaction, is set the same way.
Everything described here is scoped to the current session. Independent connections to a stackql srv server do not share bindings or secrets, and each MCP request is its own session, so configure and query in one statement batch when using the MCP server. The MCP server classifies such a batch as unknown, so it needs approval unless the server runs in full_access mode, and is refused in read_only mode.
Provider aliases
SET "$.providers.<alias>" binds an alias to a provider. The value is a JSON document held in a string:
| Key | Required | Description |
|---|---|---|
provider | Yes | The canonical provider the alias resolves to, for example aws. |
tenancy | Yes | A grouping label such as an account or tenant name. StackQL does not verify it against the provider. |
auth | One of auth or auth_secret | An authentication document in the alias format, which differs from the provider's entry in the --auth object: for AWS the keys are access_key_id_env_var and secret_access_key_env_var, not keyIDenvvar and credentialsenvvar, and a key the alias format does not know fails with invalid session configuration field or type. The alias does not borrow the canonical provider's credentials. |
auth_secret | One of auth or auth_secret | The name of a session secret holding the authentication document. |
params | No | Default values for declared provider parameters, including declared server parameters. A predicate in the query overrides a default. |
tuning | No | max_concurrent and max_per_host limits for the alias's requests, and from v1.1.959 page_limit, proxy_port, retry_tries and retry_rate (see Provider defaults). Aliases that share a provider and tenancy share these controls and must declare identical tuning. |
The following binds two AWS accounts under separate aliases, each reading its keys from differently named environment variables, and queries both in one statement:
SET "$.providers.production" = '{
"provider": "aws",
"tenancy": "production-account",
"auth": {
"type": "aws_signing_v4",
"access_key_id_env_var": "PRODUCTION_AWS_ACCESS_KEY_ID",
"secret_access_key_env_var": "PRODUCTION_AWS_SECRET_ACCESS_KEY"
},
"params": {"region": "ap-southeast-2"},
"tuning": {"max_concurrent": 4, "max_per_host": 4}
}';
SET "$.providers.development" = '{
"provider": "aws",
"tenancy": "development-account",
"auth": {
"type": "aws_signing_v4",
"access_key_id_env_var": "DEVELOPMENT_AWS_ACCESS_KEY_ID",
"secret_access_key_env_var": "DEVELOPMENT_AWS_SECRET_ACCESS_KEY"
},
"params": {"region": "ap-southeast-2"},
"tuning": {"max_concurrent": 2}
}';
SELECT name, 'production' AS account FROM production.s3.buckets
UNION ALL
SELECT name, 'development' AS account FROM development.s3.buckets;
Environment variable references are resolved from the StackQL process environment; there is no session-local environment. Temporary AWS credentials also need the session token field or environment variable reference.
An alias behaves like its provider for metadata and data statements: SHOW, DESCRIBE, SELECT, INSERT, UPDATE, DELETE and EXEC all accept the alias in place of the provider name. Aliases do not extend to native built-in relations or to the preview IaC relations. UNION ALL branches that use different aliases run sequentially.
Each query takes a detached snapshot of the alias's credentials. Changing a binding affects later queries, not one that is already running. UNSET "$.providers.<alias>" removes the binding.
Overriding credential fields
SET "$.auth.<provider>.<field>" changes one field of a provider's authentication context for the session, where the field names are the keys of the provider's --auth entry:
SET "$.auth.github.password_var" = 'GITHUB_TOKEN_READONLY';
SELECT name FROM github.repos.repos WHERE org = 'stackql';
UNSET "$.auth.github.password_var";
SET "$.auth.<provider>" replaces the provider's whole authentication document for the session, in the --auth format, for example to switch to an assumed AWS role:
SET "$.auth.aws" = '{"type": "aws_assume_role", "keyIDenvvar": "AWS_ACCESS_KEY_ID", "credentialsenvvar": "AWS_SECRET_ACCESS_KEY", "aws_role_arn": "arn:aws:iam::123456789012:role/StackQLReadOnly"}';
As with aliases, the change applies to queries started after the SET. Queries against a provider whose authentication has been unset, or whose alias has no usable auth, fail before any request is sent.
Provider defaults
From v1.1.959, SET "$.tuning_by_provider.<provider>" and SET "$.params_by_provider.<provider>" set request tuning and parameter defaults for a canonical provider for the rest of the session, without binding an alias:
SET "$.tuning_by_provider.google" = '{"page_limit": 3}';
SET "$.params_by_provider.google" = '{"maxResults": "200"}';
| Tuning key | Description |
|---|---|
page_limit | Maximum pages read per resource. 0 inherits and a negative value removes the cap. |
max_concurrent, max_per_host | Request concurrency limits. |
retry_tries, retry_rate | HTTP retry attempts and rate, with the same meaning as the engine's global retry settings. |
proxy_port | Replaces the port of the proxy that the HTTP transport selects for a request. 0 inherits and -1 restores the transport's own port. The transport still decides which requests use a proxy, including NO_PROXY exclusions; --http.proxy.port continues to configure the registry transport. |
A page limit resolves from an alias's tuning.page_limit, then the canonical provider's tuning, then --http.response.pageLimit. For reads that declare a maxResults query parameter, the value comes from the query's own predicate, then an alias's params.maxResults, then the canonical provider's parameters, then --http.response.maxResults. Each SET replaces that provider's object; UNSET on either path restores the inherited defaults. New client sessions of a stackql srv server inherit these defaults from the server's configuration, and later changes stay within the session.
Document merge
SET "$.document_merge" overlays patches on the provider documents for the current session, so that later document descriptions, document-driven queries and native IaC runs use the patched view while the registry copy stays unchanged. The value is a JSON object with a patches array, in which each patch names a document-driven service and the fragment to merge into it, or @ followed by the absolute path of a JSON file on the StackQL host:
SET "$.document_merge" = '{"patches":[{"service":"stackql_unstable_google.compute","merge":{"components":{"x-stackQL-resources":{"networks":{"methods":{"list":{"response":{"objectKey":"$.items"}}}}}}}}]}';
-- or read the same configuration from a file on the StackQL host
SET "$.document_merge" = '@/absolute/path/merge.json';
UNSET "$.document_merge";
- Available in StackQL releases from
v1.1.959. - Each
SETreplaces the whole patch set against the base documents, so include every fragment you need, in order. A failedSETkeeps the previous view, an emptypatchesarray is refused, andUNSETrestores the base. - The merged view is built in
<approot>/cache/document-viewsunless adoc_cacheobject besidepatchesnames another directory ({"patches": [...], "doc_cache": {"dir": "/path/to/cache"}});"fresh": trueis refused, so use a new cache directory instead. Keep the cache available while readers use it. - Building the view creates symbolic links to the base documents. On Windows this needs a process allowed to create symbolic links (Developer Mode or an elevated session); otherwise the
SETfails withA required privilege is not held by the client. - Inline JSON follows SQL string escaping; use the
@fileform for patches that embed programs or many quotes. File paths refer to the StackQL process's file system, not a remote SQL client's.
Session secrets
By default every session has a memory-only secret store, with no configuration needed. SET "$.secrets.<name>" stores a literal string, typically a JSON authentication document, and a provider alias references it with auth_secret:
SET "$.secrets.production" = '{"type":"aws_signing_v4","access_key_id_env_var":"PRODUCTION_AWS_ACCESS_KEY_ID","secret_access_key_env_var":"PRODUCTION_AWS_SECRET_ACCESS_KEY"}';
SET "$.providers.production" = '{"provider":"aws","tenancy":"production-account","auth_secret":"production","params":{"region":"ap-southeast-2"}}';
SELECT name FROM production.s3.buckets;
UNSET "$.secrets.production";
Rotating a secret affects later queries; deleting it makes later uses fail. A new session receives a fresh, empty store, and ending the session releases it. UNSET "$.secret_store" discards the current store binding and starts again with empty session memory.
Normal credential use, and SET statements that store variables or configuration, do not write secrets into the SQL backend. Putting sensitive data into an ordinary variable or table is the caller's responsibility.
Persistent OS secret stores
Persistent storage is disabled by default and can only be enabled by the operator starting StackQL with --allow-persistent-secrets; SQL cannot grant it. With the flag set, a session selects an OS store with:
SET "$.secret_store" = '{"backend": "os", "namespace": "stackql/provider-auth"}';
The store is the macOS Keychain, the Linux Secret Service (secret-tool with a working session service) or the Windows Credential Manager. Only the os backend is accepted: flat-file stores, file paths and any implicit file fallback are rejected even with the flag set, and an unavailable OS facility fails rather than falling back to a file.
Values written to an OS store outlive the SQL session and are deleted explicitly with UNSET "$.secrets.<name>". Resetting the store binding does not delete values already persisted. Access to the store is governed by the operating system identity of the StackQL process; a namespace is not a per-user access control, so do not treat this opt-in as a multi-user vault.
Secret values in SQL
Secret values are never dereferenced into SQL unless the operator starts StackQL with --allow-secret-dereference. With that flag, references such as "$secrets.production", "$secrets.production.credentials", "$auth.github.password" and "$providers.production.auth.credentials" resolve in expressions:
SELECT upper("$secrets.production.credentials") AS credential;
/*
-- the same statement in a session started without --allow-secret-dereference
SELECT upper("$secrets.production.credentials") AS credential;
-- FAILS with secret variable dereferencing is disabled
*/
Started without the flag, the same statement is refused before anything is evaluated, as the commented-out copy shows. The flag is an acknowledgement that explicitly dereferenced values can enter SQL staging, results, logs and persisted query artefacts. Normal provider authentication does not require it.
Permissions
With access management enabled, reading variables and secrets requires session/variables:read, and SET or UNSET requires session/config:write. A resolved alias is authorised as its canonical provider before execution. Per-variable and per-secret ownership and grants are not implemented.