# connections Connections and their types. Generated by `make records` from the decisions whose `topic` (or `also`) is this one; edit the decisions, not this page. ## Current ### Defining connections - **Connections provide sync and async clients and checks** (D53): Connections use generator functions with secret/literal arguments and missing-secret defaults; tasks must declare what they open, and test doubles are supported. `connections check` renders without opening; `connections test` runs built-in/custom checks on a worker. One definition supplies sync/async clients where supported: HTTP via httpx, Mongo via pymongo, SQL async on Postgres only; SSH is sync. Async generators/checks are supported. Reading Airflow's own entry format is not built (the Airflow layer, M5). - **Connections use optional clients and worker-side checks and tests** (D174): Connection clients are optional extras; SQL uses psycopg 3/PyMySQL, and SSH requires known hosts unless explicitly disabled. HTTP supports bearer/basic authentication, headers, CA and client certificates. Connections are registered per root; checks and tests run on workers. `task_context` injects client objects, while `run_dag` supplies arguments to the real connection function; async connections come with M4.10. - **Tasks declare the connections they open** (D179): Tasks and operators declare connections with `connections=`; the agent renders only those declared. A missing declared name warns on the DAG, fails `dags check`, and fails the attempt before code runs. - **Connection values contain secrets and plain values** (D180): A connection is defined when its module loads outside a DAG. Run-specific values go through task arguments or `dag_ctx` read inside the task. - **Connection values are limited to 1 MiB** (D181): A file defining connection values larger than 1 MiB fails to import. The SDK and the master both enforce the limit. - **An imported file keeps connections when its DAG is invalid** (D182): A file that imports but has an invalid DAG still defines its connections for the root. A file that fails to import defines none; the master clears its reported connections. - **A typed connection takes its name as its first argument** (D183): Typed connections take the name as the first argument, as in `HTTP('billing_api', ...)`. This works in loops and under aliases. - **One connection definition provides sync and async clients** (D318): A connection definition provides clients for with and async with where its type supports both. Mongo and HTTP support both; SSH is sync only and Generic gives a dict. ### Commands - **Commands receive connections at startup or through task-ctx** (D184): A `CommandOperator` connection dict supplies prefixed variables and agent-written files at startup. The list form allows `task-ctx connection NAME --env P` to supply them at runtime. Files are mode 0600 and removed when the attempt ends. - **Command connection secrets go to files and prefixed variables** (D190): Connection secrets go to the tool's file and prefixed script variables, masked in logs. Passwords are moved out of URL variables into the files. - **Command connections expose prefixed variables** (D192): Connection variables use `_...` names. Documentation shows how to map them to tool-specific environment variables. *Not found in the code yet:* the documentation shows how to map the variables to tools. - **Mongo commands receive a database tools config file** (D194): Commands get _TOOLS_CONFIG, a 0600 YAML file containing a URI with the user but no password, and a separate password, for Mongo's database tools. _URI names no user; mongosh authenticates through the prefixed USER, PASSWORD and AUTH_SOURCE variables. - **One option file supports MySQL and MariaDB clients** (D195): One option file supports both vendors: login and loose-ssl-mode in [client], with MariaDB's TLS settings in [client-mariadb]. Without ca_cert, verification uses system CAs for every client; a self-made certificate needs sslmode=require. - **A Postgres connection URL names its pgpass file** (D197): The prefixed Postgres URL includes `passfile` pointing to the generated `.pgpass`. The URL contains no password and can be passed directly to psql. - **Command connection files default to memory-backed storage** (D201): Files default under /dev/shm/schedr-///; [worker] connection_dir overrides this, with the data directory the fallback. Startup refuses unsafe paths; the private directories must be real, user- owned, mode 0700. Startup sweeps old files except directories belonging to processes it could not stop. ### Checks and tests - **Connection clients are tested against real servers** (D185): HTTP is tested against a local server and Postgres in a test container. MySQL, Mongo and OpenSSH run in integration containers and pinned CI service containers. - **Connection checks and tests run on a selected worker** (D193): Check and test select a connected, active worker matching the root's current parse hash. Automatic selection uses fewest attempts, then name; --worker selects an eligible worker. Draining and drained workers are refused, including explicitly named workers. A check without a name covers every connection in the root. - **A connection test opens a connection without a check** (D198): A connection without a check is opened and closed by `connections test`. An exception fails the test; a Generic connection renders its values. - **A connection test runs without a task slot** (D199): Connection tests run beside tasks without using a task slot. Each worker runs one connection test at a time. - **Connection tests default to a 60-second timeout** (D200): A connection test defaults to a 60-second timeout, adjustable with --timeout. Time counts from arrival at the worker, including queueing and secret reads. The test process is stopped when that deadline expires. ### Building it - **M4.7b builds typed connections and command access in two steps** (D186): M4.7b1 builds the five typed connections, Python clients, checks and extras. M4.7b2 builds command variables and files, including JSON and custom connections. ### Python clients - **SQL verifies TLS and server identity by default** (D187): SQL uses libpq `sslmode` vocabulary for Postgres and MySQL, defaulting to `verify-full`. Both accept a PEM `ca_cert` or use system CAs; MySQL URL keys outside this vocabulary are refused. A server without TLS requires an explicit `sslmode=disable`. - **SQL and Mongo credentials may be separate or URL encoded** (D188): SQL and Mongo accept separate user/password values passed to drivers as keywords. URL t-string substitutions are percent- encoded, and their encoded forms are masked. Structural values such as a whole URL or host:port must be supplied whole. Credentials supplied both separately and in the URL are refused at load. - **Mongo verifies TLS by default** (D189): Mongo uses TLS with certificate and hostname verification by default. The URI can explicitly disable TLS or specify TLS options; `ca_cert` supplies a private CA. - **Command connections use the Python clients' TLS defaults** (D191): SQL URLs, MySQL option files, Mongo URIs and SSH configs carry verifying defaults. Curl's config names the CA file when one is supplied. - **SQL supports MariaDB URLs** (D196): SQL accepts mariadb:// through PyMySQL as it does mysql://. MariaDB 11.8 integration and CI tests cover login, TLS modes and both vendors' clients. Documentation states that MariaDB 11.4+'s self-made certificate cannot pass verify-*; use a real certificate or sslmode=require. - **Mongo users log in using the URI's authentication database** (D206): Mongo login uses the URI's `authSource`, then its path database, then `admin`. `database=` selects only the database the task gets, in Python and tools' files. - **Every connection type works in the base image** (D212): The base image includes every connection type's Python client and command-line tools. `schedr[connections]` installs all Python clients outside the image. - **Async SQL connections support PostgreSQL** (D317): async with on a PostgreSQL URL opens psycopg’s AsyncConnection with the same TLS rules. It commits or rolls back on exit; MySQL and MariaDB require with. ### Demo - **The connections demo runs in compose** (D202): Compose runs every connection type's server, standalones without their own UI, and one shared schedr ui; make demo builds and runs the images. The base image supplies client tools and Python libraries; the demo adds only start scripts. Until a release includes connections, the first run builds the base image using Rust and uv. - **The connections demo shows dev and prod deployments** (D203): Dev and prod use the same DAG folder and separate secrets for their databases and users. One federated `schedr ui` shows both deployments. - **The demo uses a pinned go-httpbin server** (D204): The demo's HTTP server is pinned go-httpbin. Its `/bearer` answers 200 for any bearer token and 401 without one; the demo's checks use it. - **The connections demo lands after M4.7c** (D205): The demo has its own commit after M4.7c. It shows `schedr connections check` and `test`. ### UI - **The DAG page has connection Check and Test buttons** (D207): The DAG page lists its declared connections, their names, types, tasks using them and results. Check all renders on a worker and checks secret availability without contacting services. Each row's Test opens the connection and runs its check, making a real login. - **The DAG page shows its connections from the root's check** (D208): The DAG page shows the DAG's connections from `GET /api/v1/connections` (the parsed roots' connections, from the database); its Check all sends `POST /api/v1/connections/check` for the root. - **Connection check and test results live on the page** (D209): A row shows running while its command is polled and fills in when the worker answers. Results stay until the user leaves the page. - **Anyone signed in can test a connection after confirmation** (D210): A confirmation names the connection and says Test logs in to the real system with this deployment's secrets. Anyone signed in can run it. - **A Connections page lists connections across deployments** (D211): `/connections` groups every root's connections by deployment, with Check all and row Tests. `GET /api/v1/connections` lists current names, types, files and declarers without values. ### From other topics - Attempt timeouts include secret and connection reads (D213, `task-processes`; built (B160 fixed)) - A cleanup receives its task's declared connections (D218, `cleanup`; built M4.8a) - Resource cleanup inherits setup secrets and connections (D226, `cleanup`; built M4.8c1) - Inline server timings use the hidden configuration (D240, `configuration`; built M4.8u) - Connections use generators; resources use separate functions (D269, `cleanup`; built M4.8c1) ## Replaced None. ## Where in code - `Makefile::demo` (D202) - `crates/schedr-agent/src/agent.rs` (D174, D190, D193) - `crates/schedr-agent/src/agent.rs::connection_jobs` (D199) - `crates/schedr-agent/src/attempt.rs::add_connection_env` (D184) - `crates/schedr-agent/src/connection_env.rs::credentials` (D188) - `crates/schedr-agent/src/connection_env.rs::default_dir` (D201) - `crates/schedr-agent/src/connection_env.rs::mongo` (D194, D206) - `crates/schedr-agent/src/connection_env.rs::mysql` (D191, D195) - `crates/schedr-agent/src/connection_env.rs::own` (D192) - `crates/schedr-agent/src/connection_env.rs::pgpass_field` (D197) - `crates/schedr-agent/src/connection_env.rs::prepare` (D201) - `crates/schedr-agent/src/connection_env.rs::sql` (D191, D197) - `crates/schedr-agent/src/connection_env.rs::view` (D190, D192) - `crates/schedr-agent/src/connection_env.rs::write` (D184, D190) - `crates/schedr-agent/src/connection_jobs.rs` (D193, D199, D200) - `crates/schedr-agent/src/connection_jobs.rs::check` (D174) - `crates/schedr-agent/src/connection_jobs.rs::test_report` (D198) - `crates/schedr-agent/src/connection_jobs.rs::test_spec` (D198) - `crates/schedr-agent/src/launch.rs::deadline` (D213) - `crates/schedr-agent/src/mask.rs::MaskSet` (D188) - `crates/schedr-agent/src/mask/tests.rs` (D188) - `crates/schedr-agent/src/render/tests.rs` (D188) - `crates/schedr-agent/src/secrets.rs` (D184, D190, D192) - `crates/schedr-agent/src/secrets.rs::with_connections` (D179) - `crates/schedr-api/src/routes.rs::list_connections` (D208, D211) - `crates/schedr-api/src/routes.rs::test_connection` (D200) - `crates/schedr-api/src/views.rs` (D179, D211) - `crates/schedr-config/src/config.rs::connection_dir` (D201) - `crates/schedr-config/src/config.rs::connection_job_cancel_grace` (D240) - `crates/schedr-config/src/config.rs::connection_test_timeout` (D200) - `crates/schedr-config/src/config.rs::stop_poll` (D240) - `crates/schedr-config/src/config.rs::vault_renew_check` (D240) - `crates/schedr-master/src/commands.rs::check_connections` (D193) - `crates/schedr-master/src/dispatch.rs::connection_worker` (D193) - `crates/schedr-master/src/dispatch.rs::set_connections` (D174) - `crates/schedr-master/src/validate.rs::MAX_CONNECTION_SIZE` (D181) - `crates/schedr-model/src/commands.rs::MAX_CONNECTION_TEST_MS` (D200) - `crates/schedr-model/src/connection.rs::ConnectionDef` (D53) - `crates/schedr-model/src/connection.rs::MAX_CONNECTION_SIZE` (D181) - `crates/schedr-model/src/connection.rs::problems` (D179) - `crates/schedr-model/src/runner.rs` (D198) - `crates/schedr-ui/src/connections.rs::check` (D207) - `crates/schedr-ui/src/connections.rs::groups` (D211) - `crates/schedr-ui/src/connections.rs::list` (D208) - `crates/schedr-ui/src/connections.rs::poll` (D209) - `crates/schedr-ui/src/connections.rs::row` (D210) - `crates/schedr-ui/src/connections.rs::test` (D207) - `crates/schedr-ui/src/pages.rs` (D207) - `crates/schedr/src/cli.rs` (D198, D199) - `crates/schedr/src/roles.rs` (D201) - `examples/demo/compose.yaml` (D205) - `examples/demo/compose.yaml::dev` (D203) - `examples/demo/compose.yaml::httpbin` (D204) - `examples/demo/compose.yaml::prod` (D203) - `examples/demo/compose.yaml::services` (D202) - `images/schedr/Dockerfile::mongodb-tools` (D212) - `images/schedr/Dockerfile::openssh-client` (D212) - `python/schedr/_build.py` (D180) - `python/schedr/connection_types.py` (D183) - `python/schedr/connection_types.py::AsyncSqlConnection` (D317) - `python/schedr/connection_types.py::Generic` (D318) - `python/schedr/connection_types.py::Mongo` (D206) - `python/schedr/connection_types.py::SQL` (D317) - `python/schedr/connection_types.py::_credentials` (D188) - `python/schedr/connection_types.py::_mongo_tls` (D189) - `python/schedr/connection_types.py::_mysql` (D196) - `python/schedr/connection_types.py::_postgres` (D187) - `python/schedr/connection_types.py::_scheme` (D196) - `python/schedr/connection_types.py::_sslmode` (D187) - `python/schedr/connections.py::MAX_CONNECTION_SIZE` (D181) - `python/schedr/connections.py::TwoWayConnection` (D53, D318) - `python/schedr/connections.py::defined_values` (D180) - `python/schedr/connections.py::take_connections` (D180) - `python/schedr/resources.py` (D226) - `python/schedr/resources.py::ResourceFunction` (D269) - `python/tests/integration/test_connection_types.py::test_commands_get_connections_as_their_tools_files` (D185) ## Open None. Details and edge cases, with the reasons; read them before changing this: - archive/PROJECT.md: Connections