Connections and secrets
What reaches the rivet process, and how Airflow Connections become what rivet reads.
Secrets
-
rivet is configured through environment variables and nothing else, and the subprocess gets a minimal environment, not the worker’s. It is built from three things:
- The worker’s variables on one allow-list (
ENV_ALLOWLISTininvocation.py):PATH,HOME,USER,LOGNAME,TZ,LANG,LC_*,TMPDIR,SSL_CERT_FILE,SSL_CERT_DIR,HTTP_PROXY,HTTPS_PROXY,NO_PROXY,ALL_PROXY,http_proxy,https_proxy,no_proxy,all_proxy,KUBERNETES_SERVICE_HOST,KUBERNETES_SERVICE_PORT. Nothing else is inherited: notAIRFLOW__*, notAIRFLOW_CONN_*, not aRIVET_*variable set on the worker.env_passthrough=["RIVET_STATE_URL", "MY_*"]extends the list with names or shell-style patterns.cloud_credentials=["gcp", "aws", "azure"]addsGOOGLE_APPLICATION_CREDENTIALSandGOOGLE_CLOUD_PROJECT,AWS_*,AZURE_*for a destination or warehouse that authenticates from the environment. A storage Connection (connections=, below) that supplies a credential of one of these kinds replaces the worker’s variables of that kind, whichever way they were passed: the worker’sAWS_SESSION_TOKENnever rides beside a Connection’s static keys, nor its account key beside a Connection’s SAS token. A Connection that supplies no credential (an AWS one with only a region, a GCP one with only a project) leaves the worker’s identity in place. env={NAME: value}. It is not templated and not stored in the metadata database, but it is whatever your DAG file computes: do not write a secret literal there.env_from_connections={ENV_NAME: conn_id}, which builds a URL from an Airflow Connection’s fields insideexecute, credentials percent-encoded, and so the database name for PostgreSQL, MySQL and MongoDB. For SQL Server and Oracle the database is written as it is, because rivet reads that URL path without decoding it; a name holding@,?or#(and/on Oracle) is refused (RIVET_AIRFLOW_CONNECTION_UNSUPPORTED) as rivet would cut it there. An IPv6 host of a SQL Server connection with no port gets:1433, which rivet needs to split host from port. The scheme comes from{ENV_NAME: (conn_id, "postgresql")}, else the connection extrarivet_scheme, else the connection type (postgres,mysql,mssql,mongo,oracle); a type that names no rivet scheme, such asgeneric, is refused before rivet starts (RIVET_AIRFLOW_CONNECTION_SCHEME). A password without a login is kept, an IPv6 literal is bracketed with its zone encoded (fe80::1%eth0becomes[fe80::1%25eth0]), any other host is kept as written (db:5432with an empty port field), an Oracle connection’s extraservice_nameis used as the path. The standard extras that have a URL form become query parameters: PostgreSQLsslmode,application_name,connect_timeout; MongoDBsrv(themongodb+srvscheme, which takes no port),authSource,authMechanism,replicaSet,tls/ssl,allow_insecure,directConnection,readPreference,appName. An extra that changes how the hook authenticates and has no URL form (PostgreSQLiam,redshift; MySQLunix_socket) is refused (RIVET_AIRFLOW_CONNECTION_UNSUPPORTED). Other extras are client-library settings and are not read. The extrarivet_paramsis appended as written and wins over a mapped extra of the same name. Aconn_idno backend defines, here or inconnections=[...], is refused before rivet starts (RIVET_AIRFLOW_CONNECTION_MISSING), not retried.connections=[conn_id, ...]: storage and warehouse Connections, see below.
argv carries the config path, export names and flags.
- The worker’s variables on one allow-list (
-
XCom carries code, class, exit_code, retryable, action, kind, counts,
stop_reason, the degradations and file paths. It never carries the errormessage: redaction covers credentials only, and error text can embed source cell values. -
The task log gets a readable block (see “Reading the task log”): outcome, codes, class, action, counts, run id, step exit statuses, paths, and, on a failure, rivet’s error text on the headline and on a failed unit’s line, and in the exception. That text is rivet’s, not the package’s: Airflow’s secrets masker reads it first, it is cut to one line of at most 300 characters, and its control characters are shown as escapes. It can still hold a source value (a cell that failed to convert), which is why it is in the task log and the exception and never in XCom. Names the DAG gives (export, table) are the only other text in it the package did not write. The one-line JSON records,
rivet.start(argv),rivet.step,rivet.unit(one per unit),rivet.result,rivet.warning,rivet.crashed,rivet.cdc.max_events,rivet.refused, …, are written at DEBUG, under the same rules. -
rivet’s raw stdout and stderr go to files and never to the task log or to the worker process’s own stderr (which Airflow 3, and Airflow 2 with
run_as_user, copy into the task log). The files are<base>/<dag_id>/<task_id>-<hash>/<run_id>__try<N>.<step>.stderr.log(and.stdout.log), mode0600in0700directories; XCom and a failed task’sstderrlog line name the path (and therivet.startrecord at DEBUG).<base>isstderr_dirwhen given, else<state_dir>/logs, else, on a worker with no state directory,<temp dir>/rivet-airflow-<uid>/logs(recorded asstderr_temp; a pod loses the files with its disk, and what a failure was is still in the error object). -
Retention. When a task ends, the files of its newest
log_keeptries (default 10, counted per task across runs) are kept and the older ones are removed.log_keep=Nonekeeps everything. Only the task’s own folder is looked at; a file of an older layout is never removed (see “Upgrading a state directory” in State). Underairflow/<dag_id>/, a sealed plan artifact that has expired and was last written over 24 h ago is removed (with theplans/<run_id>/folder it leaves empty, when the folder itself was untouched for 24 h before the pass: the folder of a run in progress, even an empty one, is never removed by a sibling task’s cleanup), and so is a crashed ledger untouched for 24 h (a crash of that series more than 24 h after its last one starts a fresh budget). A ledger that is not the ledger’s JSON is left for a person to delete. -
stream_stderr=Truecopies stderr into the task log when each step ends. It is the one way raw stderr reaches the task log, and it is for debugging: it puts possibly data-bearing text into a store with wider access than the worker.
Storage and warehouse connections
connections=["gcp_rivet", "sf_rivet"] (on every operator, or in a builder’s operator_kwargs)
turns each Airflow Connection into what rivet reads, inside execute: variables, and key files
written mode 0600 into a private folder that is removed when the task ends, whatever its
outcome. The kind comes from the connection type, or from the extra rivet_kind; one task
takes at most one Connection of each kind (RIVET_AIRFLOW_CONNECTION_KIND_TWICE), and a type
that is none of them is refused before rivet starts (RIVET_AIRFLOW_CONNECTION_KIND).
| Kind (connection type) | Read from the Connection | rivet gets | The config names it |
|---|---|---|---|
gcp (google_cloud_platform) | extra keyfile_dict (written to a file) or key_path; project | GOOGLE_APPLICATION_CREDENTIALS, GOOGLE_CLOUD_PROJECT | nothing: GCS and BigQuery read it |
aws (aws) | login, password; extras aws_session_token, region_name, endpoint_url. A role (role_arn, assume_role_*), a profile_name, or keys in extras (also under session_kwargs) are refused, RIVET_AIRFLOW_CONNECTION_UNSUPPORTED: rivet signs with static or session keys only | AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_REGION, AWS_ENDPOINT_URL | access_key_env: AWS_ACCESS_KEY_ID, secret_key_env: AWS_SECRET_ACCESS_KEY (+ session_token_env) |
azure (wasb) | login (account), password (key); extra sas_token | AZURE_STORAGE_ACCOUNT, AZURE_STORAGE_KEY, AZURE_STORAGE_SAS_TOKEN | account_name: ${AZURE_STORAGE_ACCOUNT} (rivet reads no account variable of its own), and account_key_env: AZURE_STORAGE_KEY or sas_token_env: AZURE_STORAGE_SAS_TOKEN |
snowflake (snowflake) | extras account, region, role, warehouse, database, private_key_content (PEM, or base64 of PEM as Airflow’s SnowflakeHook takes it; written to a file) or private_key_file; with a key the password is the key’s passphrase, else the login password | a snow connection named as load.connection in a private SNOWFLAKE_HOME; RIVET_SNOWFLAKE_KEY; PRIVATE_KEY_PASSPHRASE for an encrypted key | load.connection |
clickhouse (clickhouse, or any type with rivet_kind: clickhouse) | host (required, RIVET_AIRFLOW_CONNECTION_INCOMPLETE without one), port, login, password; extra secure or protocol | RIVET_CLICKHOUSE_URL, RIVET_CLICKHOUSE_USER, RIVET_CLICKHOUSE_PASSWORD, and the password also under the config’s own password_env (rivet init writes CLICKHOUSE_PASSWORD) | url: ${RIVET_CLICKHOUSE_URL}, user: ${RIVET_CLICKHOUSE_USER}, password_env: RIVET_CLICKHOUSE_PASSWORD (or any name) |
The config keeps what is not a secret (bucket, project, dataset, database, schema); the
Connection holds who may write there. The Snowflake loader runs the snow CLI, which must be on
the worker (pip install snowflake-cli into its own environment). On BigQuery rivet compact
merges the buffer into the base table; on Snowflake and ClickHouse the current state is a view
over <table>__changes and there is nothing to merge. rivet 0.32.2 reports that table as skipped in its result
(compact [<table>]: skipped — this warehouse keeps a change log behind a view and never compacts),
so a compact task whose every table is skipped ends as an Airflow skip, not green. For these warehouses
build the CDC DAG with compact=False and leave such exports out of compact_exports.
Source credentials from Google Secret Manager
A config can name its source’s URL or password by a Secret Manager secret instead of a Connection, an environment variable or a file. rivet reads the secret when it starts; the value is never written to the plan, the state or the log.
source:
type: postgres
url_secret: projects/my-project/secrets/shop-url # the whole URL, latest version
source:
type: mysql
host: db.internal
user: rivet
database: shop
password_secret: projects/my-project/secrets/shop-mysql-pw/versions/3 # a pinned version
url_secrettakes the place ofurl,url_envorurl_file: exactly one of them.password_secrettakes the place ofpasswordorpassword_env: at most one. A reference isprojects/<project>/secrets/<secret>(the latest version) or.../versions/<n>; any other shape isRIVET_CONFIG_SOURCE_CONNECTION_INVALID.- The credential is the one the GCS and BigQuery legs use: the key
GOOGLE_APPLICATION_CREDENTIALSnames, or gcloud application-default credentials. It needsroles/secretmanager.secretAccessoron each secret, not on the project. A secret rivet cannot read stops the run withRIVET_CONFIG_GCP_SECRET_UNREADABLE, naming the secret: HTTP 403 is the missing role, 404 a wrong project, name or version. That is an environment failure, so it is not retried as a bad config. - The worker passes the key to rivet the way it passes it to those legs. Either a GCP Connection with a key
(
connections=["gcp_rivet"], which writesGOOGLE_APPLICATION_CREDENTIALSfor the task) orcloud_credentials=["gcp"](the worker’s ownGOOGLE_APPLICATION_CREDENTIALSpassed through). A worker whose identity Google’s default chain finds without a file (a GKE workload identity, a VM’s service account) needs neither. - A config with
url_secret, or withpassword_secretand nourl_env(its host, user and database written in the config), reads no source Connection: a DAG built from it (below) needs only the state Connection. Apassword_secretwithurl_envstill reads the Connection for the URL. - rivet version. Secret sources need rivet 0.33.0 or newer.
An older rivet is refused before it starts with
RIVET_AIRFLOW_BINARY_TOO_OLD, naming the version needed.
rivet init writes url_env:. To source a config from a secret, write the file yourself, or change the written
url_env: <NAME> line to url_secret: ... before the DAG parses it. Then the DAG for the source reads the secret:
from datetime import datetime
from airflow_provider_rivet.dags import build_source_dags
# shop.yaml in config_dir names the secret (url_secret) and the exports; the DAG reads that file at parse time.
globals().update(
build_source_dags(
["shop"],
mode="batch",
config_dir="/opt/airflow/dags/rivet",
state_root="/opt/airflow/rivet-state",
state_connection="rivet_state",
# the worker's GOOGLE_APPLICATION_CREDENTIALS for the secret, as the GCS and BigQuery legs get it
operator_kwargs={"cloud_credentials": ["gcp"]},
schedule="0 */2 * * *",
start_date=datetime(2026, 1, 1),
catchup=False,
)
)
One Variable per source: the secret name at task run time
The secret’s name differs by deployment, and a DAG file must not read it at parse. So the name lives in an Airflow Variable per source, and the task puts it in rivet’s environment when it runs:
- The Variable
rivet_<name>_url_secretholds the reference,projects/<project>/secrets/<secret>(not a secret itself):airflow variables set rivet_shop_url_secret projects/my-project/secrets/shop-url, or the environment variableAIRFLOW_VAR_rivet_shop_url_secreton the worker. - The DAG says which variable fills which environment variable:
env_from_variables={"RIVET_SOURCE_URL_SECRET": "rivet_{name}_url_secret"}.{name}is the source’s name, so each source has its own Variable. - The config names the environment variable:
url_secret: ${RIVET_SOURCE_URL_SECRET}. rivet interpolates${...}from its environment, so it reads the secret the Variable named. - A Variable no backend defines fails only that source’s tasks, before rivet starts, with
RIVET_AIRFLOW_VARIABLE_MISSINGnaming the Variable, the environment variable it fills and the command that sets it. A retry cannot create it, so the task is not retried. The other sources of the DAG file are not affected.
from datetime import datetime
from airflow_provider_rivet.dags import build_source_dags
# shop.yaml and billing.yaml in config_dir each say `url_secret: ${RIVET_SOURCE_URL_SECRET}`
globals().update(
build_source_dags(
["shop", "billing"],
mode="batch",
config_dir="/opt/airflow/dags/rivet",
state_root="/opt/airflow/rivet-state",
state_connection="rivet_state",
env_from_variables={"RIVET_SOURCE_URL_SECRET": "rivet_{name}_url_secret"},
operator_kwargs={"cloud_credentials": ["gcp"]},
schedule="0 */2 * * *",
start_date=datetime(2026, 1, 1),
catchup=False,
)
)
Here the Variables are rivet_shop_url_secret and rivet_billing_url_secret, one secret each. The same mapping works on
the operators directly (env_from_variables= on any rivet task); operator_kwargs may not set it, since the builder
sets it per source.
- IAM is per secret. The credential rivet runs as (the key
GOOGLE_APPLICATION_CREDENTIALSnames, or the worker’s default identity) needsroles/secretmanager.secretAccessoron each secret it reads, not on the project:gcloud secrets add-iam-policy-binding shop-url --project my-project --member serviceAccount:$GSA --role roles/secretmanager.secretAccessor. A source whose binding is missing stops withRIVET_CONFIG_GCP_SECRET_UNREADABLE(HTTP 403) on its own. - Getting the config.
rivet initcannot read a secret: it writesurl_env:. A source in secret mode has its config one of two ways. Write<config_dir>/<name>.yamlby hand withurl_secret: ${RIVET_SOURCE_URL_SECRET}, before the DAG is unpaused. Or let theinittask write it once through the source’s Connection, then change the writtenurl_env: RIVET_SOURCE_URLline tourl_secret: ${RIVET_SOURCE_URL_SECRET}. The next parse builds the DAG from the edited file, and the source Connection is then not read. Theinittask reads the Variables too: a source whose Variable is missing is refused there as well.
Secret Manager by reference or by Airflow’s backend. Airflow’s CloudSecretManagerBackend reads a Connection (or a
Variable) from Secret Manager when a task asks for it: the secret’s value reaches the Airflow worker process, and rivet
gets it through the environment that process builds. url_secret and password_secret keep the value out of Airflow.
Only the reference passes through Airflow, as a Variable whose value is a name, so the metadata database and the task
log hold a resource name and never the password. rivet fetches the value itself when it starts, with its own
credential. Recommendation: for a source database, use url_secret or password_secret, with the per-source Variable
above, and the secret’s IAM granted per secret. Keep the backend for the Connections Airflow hands to rivet (the storage,
warehouse and state Connections), and for rivet versions older than the one that reads the secret keys.
Connections and secrets: recommended setup
Where the Connections of a rivet DAG live decides who else can read them. Safest first:
- Keyless GCP: the worker’s own identity. On GKE the worker pod runs as a Kubernetes service
account bound to a Google service account (Workload Identity); on Cloud Composer it is the
environment’s service account. No key file exists anywhere. The GCP Connection holds only
project; a Connection that supplies no credential leaves the worker’s identity in place, and rivet finds it through Google’s default chain (GCS: an ADC file, else the metadata server). rivet’s BigQuery loader has no metadata-server path of its own: with no ADC file it runsgcloud auth application-default print-access-token, so a Workload Identity worker that loads BigQuery needs thegcloudCLI on itsPATH. The live gate proves this leg with a credential file mounted read-only where the default chain looks; it has no Workload Identity to test. - Google Secret Manager as Airflow’s secrets backend for what has to be a secret: the Snowflake key, the ClickHouse password, source database passwords. Airflow reads a Connection from Secret Manager when a task asks for it; it is never in the metadata database, a compose file or the container’s environment. The worker’s identity is granted access to the connection secrets only, not to the project’s other secrets.
- Connections in the metadata database, with a Fernet key set (
[core] fernet_key). Without one Airflow stores every password in clear and logsempty cryptography key. AIRFLOW_CONN_*environment variables: the worst place. They are readable throughdocker inspect,/proc/<pid>/environof every Airflow process, compose files and deployment manifests. Use them for a throwaway stand only (the live gate’s default leg).
GCP, keyless. The Connection (it holds no secret, so it may live anywhere):
airflow connections add gcp_rivet --conn-json '{"conn_type": "google_cloud_platform", "extra": {"project": "my-project"}}'
The grants, for a worker running as rivet-worker@my-project.iam.gserviceaccount.com (these are the
usual roles; the gate runs as a project owner and does not measure the minimum):
GSA=rivet-worker@my-project.iam.gserviceaccount.com
gcloud iam service-accounts add-iam-policy-binding "$GSA" --role roles/iam.workloadIdentityUser \
--member "serviceAccount:my-project.svc.id.goog[airflow/airflow-worker]" # GKE: namespace/KSA
gcloud storage buckets add-iam-policy-binding gs://my-bucket --member "serviceAccount:$GSA" --role roles/storage.objectAdmin
gcloud projects add-iam-policy-binding my-project --member "serviceAccount:$GSA" --role roles/bigquery.jobUser
bq add-iam-policy-binding --member "serviceAccount:$GSA" --role roles/bigquery.dataEditor my-project:raw
Secrets, from Google Secret Manager. Airflow’s configuration (airflow.cfg, or the same as
AIRFLOW__SECRETS__BACKEND / AIRFLOW__SECRETS__BACKEND_KWARGS, which hold no secret):
[secrets]
backend = airflow.providers.google.cloud.secrets.secret_manager.CloudSecretManagerBackend
backend_kwargs = {"connections_prefix": "airflow-connections", "sep": "-", "variables_prefix": null, "config_prefix": null, "project_id": "my-project"}
A conn_id sf_rivet is then the secret airflow-connections-sf_rivet, holding the Connection in
Airflow’s JSON form. Make each secret from a file or stdin, never from a command-line argument:
# Snowflake: the key file goes in whole (private_key_content), the login is the key's user
jq -n --rawfile key rsa_key.p8 '{conn_type: "snowflake", login: "RIVET_LOADER",
extra: {account: "xy12345", role: "LOADER", warehouse: "LOAD_WH", database: "RAW", private_key_content: $key}}' |
gcloud secrets create airflow-connections-sf_rivet --data-file=-
# ClickHouse and a source database: the password is read from the terminal, not typed into argv
read -rs PW
jq -n --rawfile pw /dev/stdin '{conn_type: "clickhouse", host: "ch.internal", port: 8443, login: "loader",
password: $pw, extra: {secure: true}}' < <(printf %s "$PW") | gcloud secrets create airflow-connections-ch_rivet --data-file=-
jq -n --rawfile pw /dev/stdin '{conn_type: "postgres", host: "db.internal", port: 5432, login: "rivet_reader",
password: $pw, schema: "app", extra: {sslmode: "verify-full"}}' < <(printf %s "$PW") |
gcloud secrets create airflow-connections-pg_app --data-file=-
(printf %s is a shell builtin: the password is in no process’s argv, and it gets no trailing newline.) The worker’s identity reads these secrets only, through an IAM
condition on the secret name (it needs the project NUMBER):
gcloud projects add-iam-policy-binding my-project --member "serviceAccount:$GSA" \
--role roles/secretmanager.secretAccessor \
--condition='title=airflow-connections,expression=resource.name.startsWith("projects/123456789012/secrets/airflow-connections-")'
The DAG names the same conn_ids whatever backend serves them:
connections=["gcp_rivet", "sf_rivet"], env_from_connections={"PG_URL": "pg_app"}.
What the operator does with a secret. Inside execute, each try makes a private folder
(tempfile.mkdtemp, mode 0700, in the worker’s temp directory); a key a Connection carries
(keyfile_dict, private_key_content) and the Snowflake config.toml are written into it with
mode 0600, and the folder is removed in a finally when the try ends, whatever its outcome. A
worker killed with SIGKILL runs no finally, and the folder stays in its temp directory. A
password (ClickHouse, a database URL) is passed in the environment of the rivet process only, not
of the worker: the same user and root can read it in /proc/<pid>/environ while rivet runs.