Skip to content

Connection Security and Workers ​

Experimental

Connections are experimental and off by default. Turn them on with experimental_connections: true in config.yaml, or DAGU_EXPERIMENTAL_CONNECTIONS=true. See Turn Connections On.

What Connections Guarantee ​

  • A refresh token or client secret is stored only encrypted, with the server's key: DAGU_ENCRYPTION_KEY, or auth/encryption_key in the data directory. The connection directories are readable only by Dagu's user. No API response, CLI command, or MCP tool returns a token or secret, and the coordinator never sends a worker the key, a refresh token, or a client secret.
  • Over HTTP, Dagu sends an access token only to the connection's bound hosts, over HTTPS, and never follows a redirect to another host or to plain HTTP. Two paths fall outside this: an exported token goes wherever the script sends it, and a worker receives its tokens from the coordinator over gRPC, which is plaintext unless transport security is set up.
  • A run gets a token only for a connection its DAG names, and only from its own workspace.
  • Dagu never copies a sign-in between connections. Each connection signs in on its own.
  • A token that a step uses is masked in its logs, run status, and outputs, also on a worker.
  • A refresh never overwrites a newer reconnect, and a rotated refresh token is never lost.
  • Dagu never accepts an MCP server's confirmation request on its own. mcp.call declines every one.
  • On one host, many runs that reach an expired token together cause one refresh request to the provider.

What Connections Do Not Protect Against ​

Local Mode ​

Steps that run on the Dagu server run as Dagu's OS user. A DAG author can read the encryption key and every connection's tokens there, as they can read secrets. Workspaces, roles, and the export switch prevent mistakes and govern the API and the UI. They do not stop a malicious DAG author on the server's host.

A worker isolates tokens from DAG authors only when all of these hold:

Such a worker never reads the server's connection records, and receives from the coordinator only the access tokens of the connections named by the DAGs it runs. If DAG authors must not reach every connection, run their DAGs on such workers.

This holds per worker, not per run. Runs on one worker share its OS user, so a step can read the credential of a worker added with an invite, <data_dir>/worker/credential.json, and act as that worker for any attempt dispatched to it, and can read the exported tokens in other runs' environments. Keep DAG authors who must not reach each other's connections on separate workers, routed with worker labels.

Every connection wizard shows this warning, whatever the server's mode. The warning itself names the condition: DAGs that run on the server, rather than on a worker.

Exported Tokens ​

A script that receives an exported token can print it or send it to any host. Masking hides the exact value in Dagu's logs, nothing more. Export is off until an admin allows it per connection.

Refresh Across Hosts ​

Hosts that share the data directory, such as over NFS, can read a token record older than another host's write, and refresh again. One refresh per token lifetime across hosts is not guaranteed. See Shared Storage.

Runs on Workers ​

Worker code never opens the connection records and never refreshes. A run on a worker asks its coordinator for each token:

text
worker run                      coordinator                    provider
   | token for "tracker"?          |                              |
   |------------------------------>| an attempt it dispatched?    |
   |                               | DAG names the connection?    |
   |                               | name in the run's workspace? |
   |                               |-- refresh, when needed ----->|
   |<-- token, lifetime, binding --|                              |
   | enforce the bound hosts       |                              |
  • The coordinator answers only for a running attempt it dispatched, named by the worker ID, attempt ID, and attempt key the request carries, for a connection the run's DAG names, in the run's workspace. Any other request is refused, and the step fails.
  • The coordinator checks that the caller is the worker it dispatched to only when the call carries a per-worker certificate, as workers added with invites have. With the shared peer token, or without coordinator authentication, any peer that knows a running attempt's IDs and key can get that attempt's tokens.
  • The answer holds the token, its lifetime in seconds, so the worker's clock does not matter, and the binding: bound hosts, resource, and whether export is allowed. The worker enforces the binding as a local run does.
  • Before the first step, a worker checks each connection with a request that returns no token.
  • A run asks again only when its token runs low, and reports a refused token through the coordinator, which refreshes once.
  • Step output that a worker streams to the coordinator is masked as local output is.

The coordinator needs experimental_connections: true. A coordinator with the switch off refuses token requests, saying connections are not enabled on it.

A child DAG whose file name holds a reference, such as dag: sync-${params.team}, and that runs on the same worker as its parent, cannot use connections: its check fails, saying so. A child named as written, or one dispatched to its own worker, such as one with worker_selector, can.

Upgrade Order ​

Workers and coordinators of different versions handle connections like this:

  • The coordinator dispatches a DAG that names a connection only to workers that report they make token requests. A run that only older workers match waits or fails, saying the matching workers must be upgraded.
  • Workers of v2.28.0 and v2.28.1 already report that they make token requests, but their http.request has no connection field. A DAG with http.request and connection that reaches one fails validation there, without the upgrade message. Mixed versions are not safe for it.
  • A worker under an older coordinator, which cannot hand out tokens, fails each step that uses a connection, saying the coordinator must be upgraded. Steps that do not depend on those steps still run.

So upgrade in this order:

  1. Upgrade the server, the scheduler, and the coordinator, and turn experimental_connections on.
  2. Upgrade every worker.
  3. Name connections in DAGs.
  4. Only then name a connection in a base config.

A base config applies to every DAG, so a connection named there makes every DAG name it. Every run would then wait for an upgraded worker, and fail in each workspace that lacks the connection.

Binaries before v2.28.0 reject the connection fields as unknown, so a DAG that uses one fails validation there. v2.28.x accepts connection in mcp.call and provider: connection secrets, but not in http.request. Before a downgrade, remove connections from the base config.

Refresh Token Limits ​

Each sign-in asks the provider for a refresh token: each connection, each reconnect, and each server that connects the same account. Most providers issue a new one each time. Some return the same refresh token to every consent of one account and client, so two connections can hold one token. Some providers keep only a fixed number of refresh tokens per account and client, and silently revoke the oldest past it. A connection whose token was revoked that way becomes needs_reconnect at its next refresh.

For the oauth2 and mcp providers, Dagu cannot tell whether revoking one refresh token ends the account's whole grant to the client. So it does not revoke the refresh token that a reconnect replaces, or that a sign-in left unconfirmed. Those tokens stay unused at the provider until they expire. Only Remove revokes, when no other connection on the server holds the same account and client.

To stay under such a limit:

  • Keep one connection per account and client in a workspace. Dagu warns when a sign-in duplicates one.
  • Reconnect only when the connection needs it.
  • Connect the account on as few servers as you need. Each server holds its own refresh token.

Shared Storage ​

Hosts that share the data directory, such as the server, scheduler, and coordinator of a Kubernetes deployment on one ReadWriteMany volume, refresh through the same per-connection lock. A host may still read a token record older than another host's write:

  • When the provider does not rotate refresh tokens, a stale read costs one extra refresh.
  • When it rotates them and keeps the replaced token valid for a while, a refused refresh reads the record again and retries once with the newer token. A stale read costs one extra refresh.

Some providers detect refresh token reuse: when a replaced refresh token is used again, they revoke the whole token family, and every connection on it needs a reconnect. With such a provider, keep every process that has the data directory on one host, or keep the data directory on local disk.

Dagu is open source under the GNU General Public License v3.0.