From 9e7eb56aafebf56a5905848abfe477fecb0c6c1f Mon Sep 17 00:00:00 2001 From: Yota Hamada Date: Tue, 1 Dec 2026 23:08:48 +0900 Subject: [PATCH 1/8] Add the Connections overview page Connections ship behind the experimental_connections switch, and no page explained them. The overview says how to turn the switch on, how OAuth apps differ from connections, which role does what, how sign-in and its redirect modes work, and what reconnect, the badge, the connection.* notifications, expiry, and removal do. --- .vitepress/config.js | 12 ++ features/connections/index.md | 232 ++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 features/connections/index.md diff --git a/.vitepress/config.js b/.vitepress/config.js index c829806..76b42c4 100644 --- a/.vitepress/config.js +++ b/.vitepress/config.js @@ -393,6 +393,18 @@ const fullSidebar = [ { text: "Alibaba Provider", link: "/writing-workflows/secrets/alibaba-provider" }, ], }, + { + text: "Connections (Experimental)", + link: "/features/connections/", + collapsed: true, + items: [ + { text: "Overview", link: "/features/connections/" }, + { text: "OAuth 2.0 Servers", link: "/features/connections/oauth2" }, + { text: "MCP Servers", link: "/features/connections/mcp-servers" }, + { text: "Use in Steps", link: "/features/connections/steps" }, + { text: "Security and Workers", link: "/features/connections/security" }, + ], + }, { text: "Reference", collapsed: true, diff --git a/features/connections/index.md b/features/connections/index.md new file mode 100644 index 0000000..d97fd6b --- /dev/null +++ b/features/connections/index.md @@ -0,0 +1,232 @@ +--- +description: Sign in to an OAuth 2.0 or MCP server once, then name the connection in steps. Dagu keeps, refreshes, and binds the tokens. Experimental. +--- + +# Connections + +::: warning Experimental +Connections are experimental and off by default. Names, fields, and behavior may change in any release. [Turn them on](#turn-connections-on) with `experimental_connections: true`. +::: + +A connection is one signed-in account at an OAuth 2.0 server or a remote MCP server. You sign in once, from the Web UI or the CLI, and steps then name the connection. The DAG holds no secret: + +```yaml +labels: + - workspace=ops + +steps: + - id: open_issues + action: mcp.call + with: + connection: tracker + tool: list_issues + arguments: { state: open } +``` + +Dagu stores the tokens encrypted, refreshes an access token when a step needs one, saves a rotated refresh token, and sends a token only over HTTPS to the hosts the connection is bound to. When a sign-in expires or is revoked, Dagu reports it once per notification channel and offers Reconnect. + +These pages cover connections to any server: + +- [Connect an OAuth 2.0 Server](/features/connections/oauth2): the `oauth2` provider, with the authorization code or client credentials grant. +- [Connect Any MCP Server](/features/connections/mcp-servers): the `mcp` provider, for a remote MCP server that follows the MCP authorization spec. +- [Use Connections in Steps](/features/connections/steps): `mcp.call`, `http.request`, token export, errors, and rate limits. +- [Security and Workers](/features/connections/security): what connections protect against, runs on workers, and the upgrade order. + +## Turn Connections On + +Set the switch in `config.yaml`: + +```yaml +experimental_connections: true +``` + +Or set the environment variable: + +```bash +export DAGU_EXPERIMENTAL_CONNECTIONS=true +``` + +Set it for every Dagu process that reads the configuration: the server, the scheduler, and the coordinator. Workers get tokens from the coordinator, so in distributed mode the coordinator needs it too. + +While the switch is off: + +- The Connections page, the connection API endpoints, the `dagu_read` connection targets, and the connection starter DAG do not exist. +- `dagu connection` fails, saying the server does not serve connections. +- A DAG that names a connection still loads, but its run fails before its first step: `connections are not enabled; set experimental_connections: true to use them`. +- Stored connections are kept. Turning the switch on again restores them. + +## OAuth Apps and Connections + +| | OAuth app | Connection | +| --- | --- | --- | +| What it is | A client registered at a provider: its endpoints, client ID, and optional secret | One authorized account at that provider, or for client credentials, the client itself | +| Scope | Server-wide. Many connections share one app | Belongs to one workspace. Steps use it by name | +| Managed by | Admins | Managers of the workspace | +| Holds | The client secret, encrypted | The refresh and access tokens, encrypted | + +Register the client at the provider once, as an admin. Each connection then signs in its own account on that app, with its own consent and refresh token. An `mcp` connection can skip the admin step: Dagu finds or registers a client itself, as [Connect Any MCP Server](/features/connections/mcp-servers#how-dagu-picks-the-client) explains. + +### Names and Workspaces + +- A name has 1 to 63 lowercase letters, digits, and hyphens, and starts with a letter or digit, such as `work-api` or `tracker-2`. It never changes. +- A name is unique within its workspace. Two workspaces may each have a connection of the same name, with separate sign-ins. +- A DAG's `connection: tracker` resolves to the connection `tracker` of the run's workspace, taken from the DAG's `workspace` label, and to nothing else. +- DAGs without a `workspace` label use the connections the CLI and API call `global`. Unlike global secrets, `global` connections are not a fallback for other workspaces. +- A connection is never shared or copied between workspaces. A workspace that needs the same account connects it again. +- A workspace that owns connections cannot be deleted or renamed. Remove its connections first. + +## Roles + +| Action | Role | +| --- | --- | +| See connections: name, provider, account, status | `viewer` or above in the workspace | +| Test a connection, list its tools, call a tool with Try it | `developer` or above in the workspace | +| Create, sign in, reconnect, change, or remove a connection | `manager` or above in the workspace | +| Register, change, or delete an OAuth app | `admin` | +| Add a client credentials connection, or change its scopes or bound hosts | `admin` | +| Allow token export on a connection | `admin` | +| Name a connection in a DAG | Whoever may edit the DAG | + +No role sees a token or client secret. Responses report only whether a secret or refresh token is configured. A manager who finds no fitting app sees what to ask an admin for: the client type and the redirect URI to register. + +## Add a Connection + +In the Web UI, open **Connections**, click **New connection**, and pick a tile: + +- **Custom OAuth2** for [any OAuth 2.0 server](/features/connections/oauth2). +- **Any MCP server** for [a remote MCP server](/features/connections/mcp-servers). + +From the CLI, run `dagu connection add oauth2` or `dagu connection add mcp`. Both run the same connect flow as the UI, through the server's REST API. + +The connection belongs to the workspace selected in the UI, or to the one `--workspace` names in the CLI. On a server that runs DAGs itself, rather than on workers, the wizard warns that DAG authors can read the connection's tokens. See [Security and Workers](/features/connections/security#local-mode). + +## Sign In + +Signing in runs a session: + +1. Dagu creates the authorization request, with PKCE and an encrypted `state`, and opens the provider's consent page in a popup or a browser. +2. You consent at the provider. The provider redirects back with a code, which Dagu exchanges for tokens. +3. Dagu shows the account that signed in. The tokens go live only when the user who started the session confirms it. + +A session lasts 10 minutes. A session that fails, is cancelled, or expires changes nothing: a new connection stays `pending`, and a reconnected one keeps its previous tokens. + +Before consent, the UI and the CLI show the exact redirect URI to register in the client, and the client ID. + +### Redirect Modes + +| Mode | Used when | Redirect URI | Client type | +| --- | --- | --- | --- | +| Server callback | The server has a usable public URL | `/oauth/callback` | `web` | +| Loopback | The CLI runs where a browser can open | `http://127.0.0.1` on a random port the CLI listens on | `desktop` | +| Paste | Neither of the above | A loopback URL that fails to load. You copy the address the browser lands on and paste it into the UI or the CLI | `desktop` | + +The UI and the CLI pick the first mode that works for the server and the app's client type. Loopback needs the CLI. The UI uses server callback or paste. + +The usable public URL is `public_url` from `config.yaml`, else the [tunnel](/server-admin/tunnel) URL, else the UI's own origin when the browser reaches Dagu at `localhost` or a loopback address. A request through a proxy does not count, so a server behind a reverse proxy needs `public_url`. + +In server callback mode, **Copy sign-in link** gives the authorization URL to the account's owner. The owner consents in their own browser without a Dagu login, and you confirm the account. + +### The Account + +An OAuth 2.0 server names the account only in an OpenID Connect ID token, which it returns when the connection asks for the `openid` scope. Without one, the connection has no account, and you confirm the session as it is. + +A second connection in the same workspace for the same account and client is created with a warning, not refused. Some providers limit how many refresh tokens one account holds per client. See [Refresh Token Limits](/features/connections/security#refresh-token-limits). + +## Status + +| Status | Meaning | Steps that use it | +| --- | --- | --- | +| `pending` | Created, never signed in | Fail with `reconnect_required`, saying the connection was never connected | +| `connected` | Holds live tokens | Run | +| `needs_reconnect` | The provider refused the refresh token, as after a revocation or expiry | Fail with `reconnect_required`, without calling the provider | +| `broken` | The token record is missing or cannot be decrypted, as after a create that stopped halfway | Fail. Remove the connection and add it again | + +An app becomes `invalid` when the provider refuses its client, such as after the client secret was rotated or deleted at the provider. Every connection of the app then fails at once, without calling the provider, until an admin changes the app's client ID, client secret, token URL, or how the client sends its secret. + +Only a confirmed reconnect clears `needs_reconnect`, and only an admin's change to the app clears `invalid`. + +## Reconnect + +Click **Reconnect** on the connection page, or run: + +```bash +dagu connection reconnect tracker --workspace ops +``` + +A reconnect runs the same sign-in on the existing connection. The previous tokens stay live until you confirm. The CLI expects the account the connection holds, so the same account is confirmed without asking. A different account always asks first. + +Reconnect after the connection needs it, and after adding scopes, which take effect only at the next sign-in. A client credentials connection fetches a new token instead of signing in. + +**Test** on the connection page, or `dagu connection test`, probes the connection with its live token. + +## Badge and Notifications + +The **Connections** navigation item shows a badge while any connection you can see needs reconnecting, or holds a refresh token that expires within two days or has expired. The badge is a warning dot when only an expiry causes it. + +Two notification events report changes in a connection's status: + +| Event | Sent when | +| --- | --- | +| **Connection needs attention** (`connection.needs_attention`) | A connection becomes `needs_reconnect`, or its app becomes `invalid` | +| **Connection restored** (`connection.restored`) | A connection goes from `needs_reconnect` to `connected`, or an app from `invalid` to `ok` | + +- Each change sends one plain-text message per channel, however many runs fail on the broken connection. +- A connection's events follow its workspace's [notification rules](/web-ui/notifications#rules). An app's events follow the rules of each workspace with a connection on the app. +- The message holds a Reconnect link, `/connections/?workspace=`. Without a public URL, it names the Connections page and `dagu connection reconnect `. +- A channel that receives **Connection needs attention** does not also send the **Failed** message of a run whose only failures were steps on that broken connection. A channel that does not receive it sends every failure. +- New rules select both events. Existing rules keep their event lists until you add them. + +A first sign-in from `pending` sends no event, and a step that fails on a `pending` connection still sends the run's failure message. + +## Expiry + +Some providers report when a refresh token expires. Dagu then stores the date, and the Connections page and the connection page show the time left, as a warning within two days. Dagu sends no notification before the date: nothing checks on a timer. After the date, the next refresh fails, the connection becomes `needs_reconnect`, and **Connection needs attention** is sent. + +Reconnect before the date to avoid the failure. + +## Remove + +Click **Remove connection** on the connection page, or run: + +```bash +dagu connection remove tracker --workspace ops +``` + +Remove deletes the connection, its tokens, and its tool lists. Then Dagu revokes the refresh token at the provider's revocation endpoint, when the app names one. + +- Dagu does not revoke while another connection on this server holds the same account on the same client, since a provider may end the account's whole grant to the client. That connection keeps working. +- Connections on other servers that use the same client may lose access. The confirmation says so. +- Revocation is best effort. A failure is logged and audited, and never fails the remove. +- A DAG that still names the connection fails when it starts, naming the connection. +- The CLI asks first. Without a terminal it needs `--yes`. + +## Audit + +With the [audit log](/server-admin/server#audit-logging) on, Dagu records app and connection changes, sign-ins, reconnects, removals, status changes, and tool calls from Try it. Token issuance is not audited, and no entry holds a secret. + +## CLI Reference + +`dagu connection` is hidden from `dagu --help` while connections are experimental. `dagu connection --help` works. `connections` is an alias. + +```bash +dagu connection providers +dagu connection add oauth2 [NAME] --scopes a,b --bound-host HOST [--grant client_credentials] \ + [--app APP | --token-url URL [--authorize-url URL] [--revoke-url URL] --client-id ID \ + [--client-secret-stdin] [--client-type web|desktop] [--no-pkce] [--token-auth basic|post]] +dagu connection add mcp [NAME] --url URL [--app APP | --client cimd|dcr] [--scopes a,b] +dagu connection list +dagu connection show NAME +dagu connection test NAME +dagu connection reconnect NAME +dagu connection remove NAME [--yes] +dagu connection tools NAME [--json] +dagu connection call NAME --tool TOOL [--args JSON] [--yes] +dagu connection apps list +dagu connection apps remove APP +``` + +- Every command takes `--workspace`. The default is `global`, the connections of DAGs without a `workspace` label. +- `add` and `reconnect` take `--no-browser`, which prints the sign-in URL instead of opening a browser, such as over SSH. +- `add` without enough flags asks for what is missing on a terminal, and reads secrets without echo. Without a terminal it fails, naming what is missing. +- Every command calls the server's REST API. With a [remote context](/getting-started/cli#remote-contexts) it acts on that server. With the `local` context it calls the server that this host's configuration describes, which must be running. With builtin or OIDC authentication, the `local` context has no credential: add a context with an API key. +- No command prints a client secret, refresh token, or access token. From b49ab09855edddde242d4fd9ccff0e7e65875d7a Mon Sep 17 00:00:00 2001 From: Yota Hamada Date: Tue, 1 Dec 2026 23:08:48 +0900 Subject: [PATCH 2/8] Document OAuth 2.0 and MCP server connections The generic oauth2 and mcp providers can be added from the Custom OAuth2 and Any MCP server tiles and from dagu connection add. These pages give the app and connection fields, scopes, bound hosts, PKCE, token auth, both grants, token export, and how an mcp connection discovers its authorization server and picks a CIMD, DCR, or admin client. --- features/connections/mcp-servers.md | 152 +++++++++++++++++++++++ features/connections/oauth2.md | 183 ++++++++++++++++++++++++++++ 2 files changed, 335 insertions(+) create mode 100644 features/connections/mcp-servers.md create mode 100644 features/connections/oauth2.md diff --git a/features/connections/mcp-servers.md b/features/connections/mcp-servers.md new file mode 100644 index 0000000..66fdac2 --- /dev/null +++ b/features/connections/mcp-servers.md @@ -0,0 +1,152 @@ +--- +description: Connect any remote MCP server that follows the MCP authorization spec by its URL. Dagu discovers its authorization server and picks or registers the client. Experimental. +--- + +# Connect Any MCP Server + +::: warning 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](/features/connections/#turn-connections-on). +::: + +The `mcp` provider connects a remote MCP server that follows the [MCP authorization spec](https://modelcontextprotocol.io/specification/latest/basic/authorization). You give its URL. Dagu discovers its authorization server, picks or registers an OAuth client, and signs in. `mcp.call` then calls the server with `connection` alone: + +```yaml +labels: + - workspace=ops + +steps: + - id: open_issues + action: mcp.call + with: + connection: tracker + tool: list_issues + arguments: { state: open } +``` + +For a server that takes a static API key or token instead of OAuth, keep using [`mcp.call` with `headers`](/step-types/mcp#credentials). + +## Requirements + +- The MCP server's URL is HTTPS, without a user name, password, fragment, or credential in its query. Dagu stores it in canonical form, with a lowercase host and without the default port. +- The server publishes protected resource metadata (RFC 9728), named in its `WWW-Authenticate` challenge or at the well-known path. +- Its authorization server publishes metadata (RFC 8414) and supports PKCE with `S256`. +- The authorization server takes one of the clients in [How Dagu Picks the Client](#how-dagu-picks-the-client). + +A server or authorization server that lacks either metadata, or PKCE `S256`, is refused when the connection is created. + +## How Dagu Connects + +When the connection is created, before it is stored, Dagu runs discovery once: + +1. It calls the MCP server without a token, and reads the protected resource metadata. +2. It fetches the authorization server's metadata, and accepts it only when its `issuer` matches the URL it came from. +3. It picks a client, as below. +4. You sign in, as [Sign In](/features/connections/#sign-in) describes. The request carries PKCE and the server's URL as `resource` (RFC 8707), and so does every refresh. + +The connection's resource is the server's canonical URL. It never changes. To point at another URL, add another connection. + +An `mcp` connection has no bound hosts to set: its token goes only to its MCP server's host, over HTTPS. + +When the authorization server's metadata says it sends `iss` in its redirect (RFC 9207), a redirect whose `iss` is missing or names another issuer fails the sign-in before the code is exchanged. + +### How Dagu Picks the Client + +| Client | Picked when | Who can use it | +| --- | --- | --- | +| Client ID Metadata Document (CIMD) | The authorization server supports CIMD, and this server has a public HTTPS URL | A manager | +| Dynamic client registration (DCR) | The authorization server offers registration (RFC 7591) | A manager | +| An MCP app an admin added | The authorization server takes neither | A manager names it. An admin adds it | + +Unless you choose, Dagu takes the first that works, in this order. + +**CIMD.** The client ID is the URL of this server's client metadata document, `/oauth/client-metadata.json`, a public route that describes Dagu as a public client whose redirect URI is the server callback. The authorization server fetches it, so: + +- `public_url` in `config.yaml`, or the [tunnel](/server-admin/tunnel) URL, must be HTTPS. +- The authorization server must reach that URL from the internet. A server on a private network, or behind a VPN, does not work. Choose DCR there. + +One CIMD client serves every `mcp` connection to the same authorization server, and holds no secret. + +**DCR.** Dagu registers a client for this connection alone. It is a public client with PKCE and no secret, unless the authorization server takes no public client. Its redirect URI is the server callback when the server has a usable public URL, and the paste redirect otherwise. Removing the connection deletes its client in Dagu, as a best effort. The client stays registered at the authorization server. + +**An MCP app an admin added.** For an authorization server that takes neither, an admin registers a client there and adds it to Dagu as an `mcp` app. A connection on that app skips discovery, so give the scopes the server needs. When discovery finds no client it can use, the error names the redirect URI and endpoints to register. + +An admin adds an `mcp` app through the REST API: + +```bash +curl -X POST "https://dagu.example.com/api/v1/oauth-apps" \ + -H "Authorization: Bearer $DAGU_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "tracker-client", + "provider": "mcp", + "clientId": "dagu", + "clientType": "web", + "endpoints": { + "authorizeUrl": "https://auth.example.com/authorize", + "tokenUrl": "https://auth.example.com/token" + } + }' +``` + +### Scopes + +Without an app, the scopes default to those the server's challenge names, else those its protected resource metadata lists, with `offline_access` when the authorization server offers it. Name your own scopes to replace them. With an app, name the scopes yourself. + +### Network Limits + +Discovery and registration fetch only HTTPS URLs: + +- Discovery follows at most five redirects, each to HTTPS. Registration and token requests follow none. +- Each request takes at most 10 seconds, a whole discovery at most 30, and each response is read up to 1 MiB. +- Unless every address of the MCP server's host is private, loopback, or link-local, no discovery or registration request reaches such an address, and the token and revocation endpoints may not resolve to one. An internal MCP server is reached directly, never through a configured proxy. + +## From the Web UI + +1. Open **Connections** in the workspace that will own the connection, and click **New connection**. +2. Pick **Any MCP server**. +3. Enter the name and the **MCP server URL**. +4. Optionally, open **Advanced settings** and choose the **OAuth client**: **Automatic**, **Client ID Metadata Document (CIMD)**, **Dynamic client registration (DCR)**, or **An MCP app an admin added**. Add scopes if the server needs others than it names. +5. Create the connection, consent in the popup, and confirm the account. + +When the authorization server refuses the CIMD client, the dialog offers **Try again with DCR**, or, after a failed sign-in, **Add again with DCR**, which removes the connection that never signed in and adds it again with a DCR client. + +The connection page shows the server URL, the client kind, the scopes, and the granted scopes. + +## From the CLI + +```bash +dagu connection add mcp tracker --workspace ops --url https://mcp.example.com/mcp +``` + +| Flag | Meaning | +| --- | --- | +| `--url` | The MCP server's HTTPS URL. Required | +| `--client` | `cimd` or `dcr`, in place of the automatic choice | +| `--app` | An `mcp` app an admin added, by ID or name. Skips discovery | +| `--scopes` | Scopes, comma-separated | +| `--no-browser` | Print the sign-in URL instead of opening a browser | + +For a public URL the authorization server cannot reach: + +```bash +dagu connection add mcp tracker --workspace ops --url https://mcp.example.com/mcp --client dcr +``` + +For an authorization server that takes neither CIMD nor DCR: + +```bash +dagu connection add mcp tracker --workspace ops --url https://mcp.example.com/mcp \ + --app tracker-client --scopes read,offline_access +``` + +Then list the server's tools, and call one to check the connection: + +```bash +dagu connection tools tracker --workspace ops +dagu connection call tracker --workspace ops --tool list_issues --args '{"state": "open"}' +``` + +## Next Steps + +- [Use Connections in Steps](/features/connections/steps) covers `mcp.call` with `connection`, its errors, and the Tools panel. +- `dagu example connection-mcp-call --connection tracker` prints a starter DAG for the connection. diff --git a/features/connections/oauth2.md b/features/connections/oauth2.md new file mode 100644 index 0000000..8f69341 --- /dev/null +++ b/features/connections/oauth2.md @@ -0,0 +1,183 @@ +--- +description: Connect any OAuth 2.0 server from the Web UI or the CLI, with the authorization code or client credentials grant, and bind its token to the hosts you name. Experimental. +--- + +# Connect an OAuth 2.0 Server + +::: warning 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](/features/connections/#turn-connections-on). +::: + +The `oauth2` provider connects any OAuth 2.0 server by its endpoints. You name the scopes to ask for and the hosts that may receive the token. Steps then call the server's API with [`http.request`](/features/connections/steps#http-request), or an MCP server on a bound host with [`mcp.call`](/features/connections/steps#mcp-call), and scripts can [export the token](#token-export). + +Setting up takes two parts: + +1. An admin registers the client at the provider and adds it to Dagu as an OAuth app. +2. A manager of the workspace creates a connection on that app and signs in. + +## Register the Client at the Provider + +Create an OAuth client in the provider's developer console. Register the redirect URI that fits your server: + +- **Web client**, for a server with a public URL: `/oauth/callback`, such as `https://dagu.example.com/oauth/callback`. The browser that consents must reach this URL. +- **Desktop client**, for a server without one: sign-in ends on a loopback address, `http://127.0.0.1`. The CLI listens there on a random port, or you paste the address the browser lands on. The provider must accept that loopback redirect. + +The UI and the CLI show the exact redirect URI before consent. Note the authorization URL, token URL, client ID, and client secret, if the provider issues one. + +## OAuth App Fields + +| Field | Required | Meaning | +| --- | --- | --- | +| Name | Yes | Shown in pickers | +| Authorization URL | To sign in an account | The authorization endpoint. Leave it empty for an app used only with client credentials | +| Token URL | Yes | The token endpoint | +| Revocation URL | No | The revocation endpoint (RFC 7009), where a removed connection's refresh token is revoked. Without it, Dagu revokes nothing | +| Device authorization URL | No | Stored, not used yet | +| Client ID | Yes | The client's ID at the provider | +| Client secret | No | Leave it empty for a public client. Dagu stores it encrypted and never shows it again. The client credentials grant needs one | +| Client type | Yes | `web` for the server callback, or `desktop` for a loopback or paste sign-in | +| PKCE | On by default | Sends a PKCE challenge (`S256`) with every authorization request. Turn it off only for a server that rejects PKCE | +| Token auth | `client_secret_basic` by default | How the client sends its secret to the token and revocation endpoints: HTTP Basic, or `client_secret_post` in the form. Dagu never tries the other way, so set it as the provider expects | + +Every URL is HTTPS, or plain HTTP to a loopback address for local testing. A URL may not hold a user name, a password, a fragment, or a credential in its query. + +## Connection Fields + +| Field | Required | Meaning | +| --- | --- | --- | +| Name | Yes | The name DAGs use, such as `work-api` | +| App | Yes | The `oauth2` app to sign in through | +| Scopes | Yes | The scopes to ask for | +| Bound hosts | Yes | The hosts that may receive the token | +| Grant | `authorization_code` by default | `authorization_code` signs in an account. `client_credentials` uses the client's own token, and needs an admin | + +### Scopes + +Each scope is a scope token of RFC 6749: one word of printable ASCII, without quotes or backslashes. The UI separates scopes with spaces, and the CLI with commas. + +Add the scopes the server needs for two things Dagu relies on: + +- **A refresh token.** When the access token expires, the sign-in must return a refresh token, or the session fails. Many servers return one only for a scope such as `offline_access`. An access token without an expiry needs no refresh token. +- **The account.** With `openid`, the server returns an OpenID Connect ID token, which must name the app's client in `aud`. Dagu shows its email, preferred username, name, or subject as the account. Without `openid`, the connection has no account. + +The provider may grant fewer scopes than you asked for. The connection page shows the granted scopes. + +### Bound Hosts + +A bound host is a hostname, such as `api.example.com`, or `host:port`, such as `api.example.com:8443`. It has no scheme, path, or wildcard. Dagu sends the token only over HTTPS to a URL whose host matches one: + +- The hostname matches without regard to case, ignoring one trailing dot. +- A subdomain does not match. `api.example.com` does not cover `eu.api.example.com`. +- An IP address matches only the same IP address. +- An entry without a port matches only port 443. An entry with a port matches only that port. + +No step field, parameter, or tool argument changes a connection's bound hosts. A [token export](#token-export) is the exception: a script that receives the token can send it anywhere. + +## Grants + +### Authorization Code + +The connection signs in one account, as [Sign In](/features/connections/#sign-in) describes. Steps act as that account. A manager of the workspace creates, reconnects, and changes it. + +### Client Credentials + +The connection acts as the client itself, with no account and no refresh token: + +- Only an admin adds one, or changes its scopes or bound hosts. +- The app needs a client secret. +- Dagu fetches the client's token when the connection is created, and again whenever it expires. When the first fetch fails, the connection stays `pending` with the provider's error. +- **Reconnect** fetches a new token. +- New scopes take effect at once: Dagu discards the stored token and fetches one for the new scopes. +- A refused grant fails the step, and the connection keeps its status. When the provider refuses the client itself (`invalid_client` or `unauthorized_client`), the app becomes `invalid`. + +## From the Web UI + +1. Open **Connections** in the workspace that will own the connection, and click **New connection**. +2. Pick **Custom OAuth2**. +3. Pick an app that fits this server. An admin can click **Register an OAuth2 app** and fill in the [app fields](#oauth-app-fields). A manager who finds none sees what to ask an admin for. +4. Enter the name, scopes, and bound hosts. An admin also picks the grant. +5. With the authorization code grant, click **Create and sign in**, consent in the popup, and confirm the account. With client credentials, click **Create**: the connection page opens with the token already fetched. + +On the connection page, **Edit scopes and hosts** changes the scopes and bound hosts. New scopes of a signed-in connection need a reconnect. Only an admin edits a client credentials connection. + +## From the CLI + +Register a new app and sign in, as an admin: + +```bash +dagu connection add oauth2 work-api --workspace ops \ + --scopes openid,offline_access,read \ + --bound-host api.example.com \ + --authorize-url https://auth.example.com/authorize \ + --token-url https://auth.example.com/token \ + --revoke-url https://auth.example.com/revoke \ + --client-id dagu --client-secret-stdin < client-secret.txt +``` + +`--client-secret-stdin` reads the secret from the first line of stdin. On a terminal without it, the CLI asks for the secret without echo. Without a secret, the client is public. + +Use an app an admin already registered, as a manager: + +```bash +dagu connection add oauth2 work-api --workspace ops --app example \ + --scopes openid,offline_access,read --bound-host api.example.com +``` + +Add a client credentials connection, as an admin: + +```bash +dagu connection add oauth2 reports --workspace ops --grant client_credentials \ + --app example --scopes reports.read --bound-host reports.example.com +``` + +| Flag | Meaning | +| --- | --- | +| `--scopes` | Scopes, comma-separated. Required | +| `--bound-host` | A host that may receive the token. Repeat for each. Required | +| `--grant` | `authorization_code` (default) or `client_credentials` | +| `--app` | An existing `oauth2` app, by ID or name. `dagu connection apps list` lists them | +| `--authorize-url`, `--token-url`, `--revoke-url`, `--client-id` | Register a new app, named after the connection. Needs admin | +| `--client-secret-stdin` | Read the new app's client secret from stdin | +| `--client-type` | `web` or `desktop`. Default: `web` for client credentials, or when the server has a public URL; otherwise `desktop` | +| `--no-pkce` | Turn PKCE off for a server that rejects it | +| `--token-auth` | `basic` (default) or `post` | +| `--no-browser` | Print the sign-in URL instead of opening a browser | + +The CLI prints the redirect URI and the client ID before consent, waits for the sign-in, asks you to confirm the account, and prints the result. Ctrl-C before the confirm cancels the session and discards its tokens. + +## Token Export + +A script or CLI that takes a bearer token can read the connection's access token from a secret with `provider: connection`: + +```yaml +labels: + - workspace=ops + +secrets: + - name: API_TOKEN + provider: connection + key: work-api + +steps: + - id: profile + run: | + curl -fsS -H "Authorization: Bearer $API_TOKEN" https://api.example.com/v1/me +``` + +- It works only when an admin has allowed token export on the connection. Otherwise the run fails before its first step, naming the connection. +- `key` is the connection's name, a literal, in the run's workspace. +- `options` is not allowed for an `oauth2` connection. +- The token is fetched once, when the run starts, and stays valid for at least 50 minutes, or half the provider's token lifetime when that is shorter. A step that runs longer should use `http.request` with `connection`, which asks for a fresh token when it needs one. +- The value is masked in logs like any secret. Masking hides the exact value, nothing more: the script can send the token to any host, and the bound hosts do not apply. +- Like other secrets, it resolves before the first step, so a connection that needs reconnecting fails the whole run. In a [base config](/server-admin/base-config), it would fail the runs of every workspace without the connection, so keep it in the DAG. + +Token export has no switch in the UI or the CLI yet. An admin turns it on through the REST API: + +```bash +curl -X PATCH "https://dagu.example.com/api/v1/connections/work-api?workspace=ops" \ + -H "Authorization: Bearer $DAGU_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{"allowTokenExport": true}' +``` + +Prefer a connection-aware step. `http.request` and `mcp.call` need no export, keep the token out of the step's environment, and send it only to bound hosts. From 0c1144febc0eb2697710a01f9fc4ede8f565465d Mon Sep 17 00:00:00 2001 From: Yota Hamada Date: Tue, 1 Dec 2026 23:08:48 +0900 Subject: [PATCH 3/8] Document connections in steps and their security Steps name connections in mcp.call and http.request, and the errors they add need a fix a user can find. The steps page covers admission checks, reconnect_required, insufficient_scope, rate_limited, confirmation requests, Try it, and quotas without provider numbers. The security page states what connections do not protect against, how workers get tokens, refresh token limits, shared storage, and the upgrade order. --- features/connections/security.md | 102 +++++++++++++++ features/connections/steps.md | 218 +++++++++++++++++++++++++++++++ 2 files changed, 320 insertions(+) create mode 100644 features/connections/security.md create mode 100644 features/connections/steps.md diff --git a/features/connections/security.md b/features/connections/security.md new file mode 100644 index 0000000..6053145 --- /dev/null +++ b/features/connections/security.md @@ -0,0 +1,102 @@ +--- +description: What connections protect against and what they do not, how runs on workers get tokens, refresh token limits, shared storage, and the upgrade order. Experimental. +--- + +# Connection Security and Workers + +::: warning 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](/features/connections/#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 neither reaches a worker. +- An access token goes only to the connection's bound hosts, over HTTPS. It never follows a redirect to another host or to plain HTTP. +- A run gets a token only for a connection its DAG names, and only from its own workspace. +- A sign-in is never copied between connections. Each sign-in gets its own refresh token. +- 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 answers an MCP server's confirmation request on its own. +- 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. + +Workers are the isolation boundary. A worker never holds the encryption key, and receives only the tokens of the connections its DAG names. If DAG authors must not reach every connection, run their DAGs on [workers](/server-admin/distributed/workers/). + +The connection wizard says this when it creates a connection on a server that runs DAGs itself. + +### Exported Tokens + +A script that receives an [exported token](/features/connections/oauth2#token-export) 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](#shared-storage). + +## Runs on Workers + +A worker never reads connection records, never holds the encryption key, and never refreshes. It asks its coordinator for each token: + +```text +worker run coordinator provider + | token for "tracker"? | | + |------------------------------>| dispatched to this worker? | + | | 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 an attempt it dispatched to that worker, for a connection the run's DAG names, in the run's workspace. Any other request is refused, and the step fails. +- 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. +- A worker under an older coordinator, which cannot hand out tokens, fails each step that uses a connection, saying the coordinator must be upgraded. The run's other steps 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](/server-admin/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. + +An older binary rejects the `connection` fields as unknown, so a DAG that uses one fails validation there. Before a downgrade, remove connections from the base config. + +## Refresh Token Limits + +Each sign-in gets a new refresh token from the provider: each connection, each reconnect, and each server that connects the same account. 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](/features/connections/#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. diff --git a/features/connections/steps.md b/features/connections/steps.md new file mode 100644 index 0000000..4bb35f0 --- /dev/null +++ b/features/connections/steps.md @@ -0,0 +1,218 @@ +--- +description: Name a connection in mcp.call and http.request steps. Covers admission checks, the reconnect_required, insufficient_scope, rate_limited, and confirmation_required errors, and quotas. Experimental. +--- + +# Use Connections in Steps + +::: warning Experimental +Connections are experimental and off by default. Turn them on with `experimental_connections: true` in `config.yaml`, or `DAGU_EXPERIMENTAL_CONNECTIONS=true`. While they are off, a run that names a connection fails before its first step. See [Turn Connections On](/features/connections/#turn-connections-on). +::: + +A step names a connection in place of an `Authorization` header. Dagu takes a token that stays valid for at least 5 minutes, sends it only over HTTPS to the connection's bound hosts, refreshes it once when the server refuses it, and masks it in the step's logs, run status, and outputs. The run page shows the connection and account each step used. + +Three places take a connection: + +| Where | Field | Connection | +| --- | --- | --- | +| [`mcp.call`](#mcp-call) | `with.connection` | `mcp`, or another with a `url` on its bound hosts | +| [`http.request`](#http-request) | `with.connection` | Any, with a `url` on its bound hosts | +| [Token export](/features/connections/oauth2#token-export) | `secrets` with `provider: connection` | Any, when an admin allows export | + +A connection name is a literal. `connection: ${CONN}` fails validation, since Dagu checks connections before the run starts and reads no connection record while it validates. + +## mcp.call + +With an `mcp` connection, `connection` replaces `url` and the `Authorization` header. The step calls the connection's own MCP server: + +```yaml +labels: + - workspace=ops + +steps: + - id: open_issues + action: mcp.call + with: + connection: tracker + tool: list_issues + arguments: { state: open } + output: ISSUES + + - id: report + depends: open_issues + run: echo "${ISSUES.content[0].text}" +``` + +With an `oauth2` connection, set `url` to an MCP server on one of its bound hosts: + +```yaml +steps: + - id: search + action: mcp.call + with: + connection: work-api + url: https://api.example.com/mcp + tool: search + arguments: { query: dagu } +``` + +- `url`, when set, must be HTTPS on the connection's bound hosts. An `mcp` connection's only bound host is its server's host. +- `server` names a service of a provider with presets. The generic providers have none: a run that sets `server` beside an `mcp` or `oauth2` connection fails before its first step. +- `headers` may still set other headers, but not `Authorization`. +- A 401 reports the token once, takes the token Dagu returns, refreshed only if the refused token was still the stored one, and sends the request again. A second 401 fails with kind `auth`. +- Redirects are never followed. + +The output and the other fields are those of [MCP Call](/step-types/mcp). + +## http.request + +With `connection`, the request carries the connection's token as `Authorization: Bearer `: + +```yaml +labels: + - workspace=ops + +steps: + - id: me + action: http.request + with: + connection: work-api + method: GET + url: https://api.example.com/v1/me + format: json + output: ME +``` + +- The token goes only over HTTPS to one of the connection's bound hosts. +- A literal `url` off the bound hosts, or not HTTPS, fails the run before its first step. A `url` built from a reference is checked when the step sends it, and fails the step before any request. +- A redirect is followed only to HTTPS on the same host and port. Any other redirect fails the request, and its target receives no token. +- A 401 to the stored token refreshes it once and sends the request again. A 401 to that request is the step's response. A 401 after a redirect is not resent, since the server may have acted on the first request. +- `connection` cannot be combined with `debug: true`, `skip_tls_verify: true`, an `Authorization` or `Host` header, or a `command` or `args`. Validation fails. + +The other fields are those of [HTTP](/step-types/http). + +## Checks Before the Run + +Before its first step, and before its secrets resolve, a run checks every connection its DAG names: + +- The name resolves in the run's workspace. +- A `server` is one of the connection's services. An `mcp` connection takes none. +- A literal `http.request` URL is HTTPS and on the connection's bound hosts. + +A failed check fails the run before its first step, naming the connection. The run reports every failed check together. + +These checks read no tokens, so a `pending` or `needs_reconnect` connection passes them. Each step that uses it then fails, and the run's other steps run. A `provider: connection` secret is the exception: secrets resolve once, before the first step, so such a connection fails the whole run. + +## Errors + +| Error | Cause | Fix | +| --- | --- | --- | +| `reconnect_required` | The connection is `pending` or `needs_reconnect`, or its app is `invalid`. The step fails without calling the provider | Reconnect the connection. For an `invalid` app, an admin fixes the app's client ID or secret | +| `insufficient_scope` | The server answered 403 with an `insufficient_scope` challenge. No refresh is tried | Add the missing scope to the connection, then reconnect | +| `rate_limited` | The server answered HTTP 429 | Wait, or lower the request rate. See [Rate Limits and Quotas](#rate-limits-and-quotas) | +| `confirmation_required` | The MCP server asked a person to confirm the action | See [Confirmation Requests](#confirmation-requests) | + +In `mcp.call`, `rate_limited` and `confirmation_required` are error kinds. `reconnect_required` and `insufficient_scope` are the `detail` of an `auth` error, which also carries the connection's name and, for `insufficient_scope`, the missing `scope`: + +```json +{"error": {"kind": "auth", "message": "...", "connection": "tracker", "detail": "insufficient_scope", "scope": "issues:write"}} +``` + +A `rate_limited` error carries the provider's message and, when the server sent one, `retry_after` as sent. Every `mcp.call` reports HTTP 429 as `rate_limited`, with or without a connection. A DAG that matched `transport` to catch rate limits must also match `rate_limited`. + +In `http.request`, a connection that needs reconnecting fails the step before any request, with an error that names the connection. A 403 or 429 is the server's response: the step fails unless `status_exit_codes` maps the status. + +A transient refresh failure, such as the provider's token endpoint returning HTTP 503, fails the call with the provider's error. The connection keeps its status, and the step's `retry_policy` applies. + +## Confirmation Requests + +An MCP server may ask a person to confirm a sensitive action, such as sending a message or sharing a file, through MCP form elicitation. An MCP client that uses a connection advertises that it can show such forms. Dagu never accepts one on its own: only a person accepts one. + +`mcp.call` has no person to ask. It declines the request at once and fails with kind `confirmation_required`. To let the action through: + +- **Approve it once with Try it** on the connection page, or with `dagu connection call` on a terminal. Both show the server's form and send your answer. Where the form offers to remember the approval, save it, so later calls pass. +- **Ask the MCP server's admin** to change its confirmation rules. +- **Call the provider's REST API** with `http.request` and an `oauth2` connection, when the provider offers one. Confirmation requests belong to the MCP server. + +Try it and `dagu connection call` call the tool anew. They do not resume the failed step, so check that call's result before you retry the run, or the action may happen twice. + +## Try It and Copy as Step + +The **Tools** panel of the connection page lists each tool of an MCP connection, with its input schema. Developers of the workspace can: + +- **Try it**: fill in a form built from the tool's input schema and call the tool once. A tool not marked read-only asks first. A confirmation request from the server is shown inline, and only the user who started the call can answer it. +- **Copy as step**: copy the tool as an `mcp.call` step that names the connection. + +The CLI does the same: + +```bash +dagu connection tools tracker --workspace ops +dagu connection call tracker --workspace ops --tool create_issue --args '{"title": "Disk full"}' +``` + +`dagu connection call` prints the step's output as JSON. A tool not marked read-only is called only after a yes, or with `--yes`. `--yes` never answers the server's own form. Without a terminal, the command declines each form and fails with `confirmation_required`. + +Limits of Try it and `dagu connection call`: + +- Each request waits at most 50 seconds for the output or the next form. A slower tool fails with kind `timeout`. +- A call waiting for an answer is held for up to 10 minutes, by the server that took it. Behind several frontend replicas, an answer that reaches another replica fails with `call_not_found`, and the page offers **Call again**. +- A server holds at most 8 calls at once, 4 per user. Arguments or an answer over 64 KiB are refused. Output over 128 KiB, or responses over 192 KiB, fail with kind `too_large`. + +Tool lists are cached for 10 minutes per connection on each host, so the panel, `dagu connection tools`, and repeated reads cost the MCP server at most one listing per 10 minutes. + +## Starter DAG + +`dagu example connection-mcp-call --connection tracker` prints a starter DAG, and the connect dialog offers it after a sign-in. It takes the URL, tool, and arguments as parameters: + +```yaml +type: graph +params: + - name: URL + type: string + description: The MCP server's URL, on one of the connection's bound hosts + required: true + - name: TOOL + type: string + description: The tool to call. The connection page and dagu connection tools list them + required: true + - name: ARGUMENTS + type: string + description: The tool's arguments, as a JSON object + required: true + default: "{}" +steps: + - id: call + action: mcp.call + with: + connection: "tracker" + url: ${params.URL} + tool: ${params.TOOL} + arguments: ${params.ARGUMENTS} +``` + +## Rate Limits and Quotas + +Providers limit requests per client or project, and often per account too. These docs state no provider's numbers: they differ per provider and change. Dagu reports the provider's errors as they come, and HTTP 429 as [`rate_limited`](#errors). Check your provider's quota page and usage dashboard. + +To estimate usage: + +- A DAG that calls one tool every minute makes about 1,440 requests a day. Each `foreach` item and each retry is another request. +- Listing an MCP server's tools costs one request per connection per 10 minutes on each host, and only while something reads the tool list. +- Token refreshes go to the provider's token endpoint, about once per token lifetime per connection on a host, however many runs use it. + +To cap concurrent use of one account, put the DAGs that use the connection in a [queue](/writing-workflows/queues) whose `max_concurrency` limits how many run at once. A per-account limit can be reached by many runs at once even within a daily quota. + +```yaml +queue: tracker-api + +steps: + - id: open_issues + action: mcp.call + with: + connection: tracker + tool: list_issues + retry_policy: + limit: 3 + interval_sec: 60 +``` + +Define the queue in `config.yaml`, as [Queue Configuration](/server-admin/queues) shows. A `retry_policy` on `mcp.call` runs the tool again, so set one only for tools that are safe to call twice. From 97beb4783710acdac023961169cb81f3169a7b4f Mon Sep 17 00:00:00 2001 From: Yota Hamada Date: Tue, 1 Dec 2026 23:08:48 +0900 Subject: [PATCH 4/8] Link connections from the step and secret pages The mcp.call page listed HTTP 429 under transport, which is now rate_limited for every call, and said OAuth sign-in was unsupported. The mcp.call, http.request, secrets, and notifications pages now name the connection field, provider, and events, and link the new pages. --- step-types/http.md | 22 ++++++++++++++++++++++ step-types/mcp.md | 35 +++++++++++++++++++++++++++++------ web-ui/notifications.md | 2 ++ writing-workflows/secrets.md | 1 + 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/step-types/http.md b/step-types/http.md index 1abf1b8..49a24b2 100644 --- a/step-types/http.md +++ b/step-types/http.md @@ -31,6 +31,7 @@ steps: | `output` | File path to write the response body to instead of stdout. | `"${context.paths.artifacts_dir}/data.bin"` | | `skip_tls_verify` | Skip TLS certificate verification | `true` | | `status_exit_codes` | Map a non-2xx status code or class to the step exit code (0-255). See [Exit Codes](#exit-codes). | `"5xx": 75` | +| `connection` | Experimental. A [connection](/features/connections/) whose token the request sends. See [Connection](#connection). | `work-api` | ## Examples @@ -96,6 +97,27 @@ steps: Authorization: "Bearer ${env.API_TOKEN}" ``` +### Connection + +::: warning Experimental +Connections need `experimental_connections: true` in `config.yaml`. While they are off, a run that names a connection fails before its first step. +::: + +Name a [connection](/features/connections/) in place of the `Authorization` header. The request carries its token as `Authorization: Bearer `, only over HTTPS to the connection's bound hosts: + +```yaml +steps: + - id: me + action: http.request + with: + connection: work-api + method: GET + url: https://api.example.com/v1/me + format: json +``` + +A literal `url` off the bound hosts fails the run before its first step. A redirect is followed only to HTTPS on the same host and port. A 401 refreshes the token once and sends the request again, unless the request followed a redirect. `connection` cannot be combined with `debug: true`, `skip_tls_verify: true`, or an `Authorization` or `Host` header. See [Use Connections in Steps](/features/connections/steps#http-request). + ### Query Parameters ```yaml diff --git a/step-types/mcp.md b/step-types/mcp.md index 5b65a96..4d5ff94 100644 --- a/step-types/mcp.md +++ b/step-types/mcp.md @@ -44,10 +44,12 @@ steps: | Field | Required | Description | |-------|----------|-------------| -| `url` | Yes | Absolute `http` or `https` endpoint of the server. Accepts references such as `${MCP_URL}`. User info such as `https://user:pass@host` is rejected. | +| `url` | Yes, without `connection` | Absolute `http` or `https` endpoint of the server. Accepts references such as `${MCP_URL}`. User info such as `https://user:pass@host` is rejected. With `connection`, it must be HTTPS on the connection's bound hosts. | | `tool` | Yes | Name of the tool to call. | | `arguments` | No | Tool arguments as an object, or a `${...}` reference that resolves to a JSON object. | -| `headers` | No | Request headers sent with every request of the session. Use `${...}` references to [secrets](/writing-workflows/secrets) for credentials. | +| `headers` | No | Request headers sent with every request of the session. Use `${...}` references to [secrets](/writing-workflows/secrets) for credentials. With `connection`, `Authorization` is not allowed. | +| `connection` | No | Experimental. A [connection](/features/connections/) whose token the call sends, by its literal name. See [Connections](#connections). | +| `server` | No | Experimental. A service of a connection whose provider has service presets. Not allowed with an `mcp` or `oauth2` connection. | | `include_raw` | No | When `true`, also writes the full MCP result under `raw`. Default `false`. | | `save_binary` | No | When `true`, saves image, audio, and blob resource data as run artifacts instead of writing it as base64. Default `false`. See [Binary Content](#binary-content). | @@ -172,14 +174,35 @@ The step error starts with `mcp.call: error:`. When the step's own `timeo | Kind | Meaning | |------|---------| | `tool` | The tool ran and reported `isError: true`. The normal output is still written. | -| `auth` | The server answered HTTP 401 or 403. | +| `auth` | The server answered HTTP 401 or 403, or a connection could not give the call a token. | | `protocol` | A JSON-RPC error such as an unknown tool, a lost session, an invalid response, or an HTTP 3xx redirect. | -| `transport` | A network failure, such as a refused connection or a connection lost mid-response, or HTTP 429, 500, 502, 503, or 504. | +| `transport` | A network failure, such as a refused connection or a connection lost mid-response, or HTTP 500, 502, 503, or 504. | +| `rate_limited` | The server answered HTTP 429. The error carries the server's message, and `retry_after` when the server sent `Retry-After`. | +| `confirmation_required` | Through a connection, the server asked a person to confirm the action. See [Confirmation Requests](/features/connections/steps#confirmation-requests). | | `timeout` | The step or DAG timeout elapsed. | | `canceled` | The run was stopped. | Redirects are not followed. Configure the final URL of the endpoint. +## Connections + +::: warning Experimental +Connections need `experimental_connections: true` in `config.yaml`. While they are off, a run that names a connection fails before its first step. +::: + +For a server that uses OAuth, sign in once as a [connection](/features/connections/) and name it in place of `url` and the `Authorization` header: + +```yaml +steps: + - id: open_issues + action: mcp.call + with: + connection: tracker + tool: list_issues +``` + +Dagu sends the connection's token only over HTTPS to its bound hosts, refreshes it once when the server refuses it, and masks it in the step's logs and output. An `auth` error then carries `connection`, and `detail: reconnect_required` or `detail: insufficient_scope` with the missing `scope`. See [Use Connections in Steps](/features/connections/steps#mcp-call). + ## Credentials Put credentials in `headers` and read them from [secrets](/writing-workflows/secrets), which Dagu resolves at run time and masks in step logs. Never put them in the URL. @@ -216,8 +239,8 @@ The action sets no timeout of its own, and a tool may run as long as the server - Local stdio servers and the legacy HTTP+SSE transport. - MCP resources, prompts, and tasks. -- Server-initiated requests such as sampling and elicitation. -- OAuth sign-in flows. Send a token the server accepts in `headers`. +- Sampling, and elicitation without a connection. +- OAuth sign-in flows outside [connections](/features/connections/). Without a connection, send a token the server accepts in `headers`. - Connection pooling. Each run opens and closes its own session. Need one of these? [Request it](https://github.com/dagucloud/dagu/issues). diff --git a/web-ui/notifications.md b/web-ui/notifications.md index e12d0ea..d1da737 100644 --- a/web-ui/notifications.md +++ b/web-ui/notifications.md @@ -46,6 +46,8 @@ The Web UI lets you route these DAG-run events: New rules default to the operational events: **Failed**, **Aborted**, **Rejected**, and **Waiting**. **Partially succeeded** and **Succeeded** are opt-in to avoid noisy channels. +With the experimental [connections](/features/connections/) turned on, rules also offer **Connection needs attention** and **Connection restored**, which report a connection that needs a reconnect and its recovery. New rules select both. See [Badge and Notifications](/features/connections/#badge-and-notifications). + When a DAG has DAG-level auto retry remaining, Dagu does not send the **Failed** notification for the intermediate failed attempt. The failure notification is sent only after the retry budget is exhausted and the DAG run is finally failed. ## Channels diff --git a/writing-workflows/secrets.md b/writing-workflows/secrets.md index 815f2b1..3137c71 100644 --- a/writing-workflows/secrets.md +++ b/writing-workflows/secrets.md @@ -82,6 +82,7 @@ The current built-in direct provider registry contains: | `gcp` | A secret value from Google Secret Manager | | `azure` | A secret value from Azure Key Vault | | `alibaba` | A secret value from Alibaba Cloud KMS | +| `connection` | Experimental. The access token of a [connection](/features/connections/), when an admin allows its export. See [Token Export](/features/connections/oauth2#token-export) | Existing DAGs that use `provider` and `key` continue to work. Direct provider refs do not require the Web UI secret registry. From 1b9d900a2bd76e8e654be694f0c3e5032b9218bd Mon Sep 17 00:00:00 2001 From: Yota Hamada Date: Tue, 1 Dec 2026 23:42:19 +0900 Subject: [PATCH 5/8] Scope the worker isolation claims to what holds Every worker loads or creates an encryption key, and the coordinator checks the caller only when it carries a per-worker certificate. The page now says tokens are isolated from DAG authors only on workers with their own data directory and key, added with invites, and names the v2.28.x workers that accept no http.request connection. --- features/connections/security.md | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/features/connections/security.md b/features/connections/security.md index 6053145..2f3d847 100644 --- a/features/connections/security.md +++ b/features/connections/security.md @@ -10,13 +10,13 @@ Connections are experimental and off by default. Turn them on with `experimental ## 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 neither reaches a worker. -- An access token goes only to the connection's bound hosts, over HTTPS. It never follows a redirect to another host or to plain HTTP. +- 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](#exported-tokens) goes wherever the script sends it, and a worker receives its tokens from the coordinator over gRPC, which is plaintext unless [transport security](/server-admin/distributed/transport-security) is set up. - A run gets a token only for a connection its DAG names, and only from its own workspace. -- A sign-in is never copied between connections. Each sign-in gets its own refresh token. +- 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 answers an MCP server's confirmation request on its own. +- 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 @@ -25,9 +25,15 @@ Connections are experimental and off by default. Turn them on with `experimental 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. -Workers are the isolation boundary. A worker never holds the encryption key, and receives only the tokens of the connections its DAG names. If DAG authors must not reach every connection, run their DAGs on [workers](/server-admin/distributed/workers/). +A worker isolates tokens from DAG authors only when all of these hold: -The connection wizard says this when it creates a connection on a server that runs DAGs itself. +- The worker has its own data directory, as a [shared-nothing worker](/server-admin/distributed/workers/shared-nothing) does, not the server's data directory on a [shared filesystem](/server-admin/distributed/workers/shared-filesystem). +- It has its own encryption key, not the server's `DAGU_ENCRYPTION_KEY`. Every worker loads or creates a key at startup, so give it none of the server's. +- The coordinator can tell workers apart, which needs [per-worker certificates](/server-admin/distributed/transport-security#add-workers-with-invites). See [Runs on Workers](#runs-on-workers). + +Such a worker never reads the server's connection records, and receives from the coordinator only the access tokens of the connections its run's DAG names. If DAG authors must not reach every connection, run their DAGs on such workers. + +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 @@ -39,12 +45,12 @@ Hosts that share the data directory, such as over NFS, can read a token record o ## Runs on Workers -A worker never reads connection records, never holds the encryption key, and never refreshes. It asks its coordinator for each token: +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"? | | - |------------------------------>| dispatched to this worker? | + |------------------------------>| an attempt it dispatched? | | | DAG names the connection? | | | name in the run's workspace? | | |-- refresh, when needed ----->| @@ -52,7 +58,8 @@ worker run coordinator provider | enforce the bound hosts | | ``` -- The coordinator answers only for an attempt it dispatched to that worker, for a connection the run's DAG names, in the run's workspace. Any other request is refused, and the step fails. +- 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](/server-admin/distributed/transport-security#add-workers-with-invites) have. With the shared [peer token](/server-admin/distributed/transport-security#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. @@ -67,7 +74,8 @@ A child DAG whose file name holds a reference, such as `dag: sync-${params.team} 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. -- A worker under an older coordinator, which cannot hand out tokens, fails each step that uses a connection, saying the coordinator must be upgraded. The run's other steps run. +- 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: @@ -78,11 +86,11 @@ So upgrade in this order: 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. -An older binary rejects the `connection` fields as unknown, so a DAG that uses one fails validation there. Before a downgrade, remove connections from the base config. +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 gets a new refresh token from the provider: each connection, each reconnect, and each server that connects the same account. 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. +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](/features/connections/#remove) revokes, when no other connection on the server holds the same account and client. From 4bad22fe06bf027fc98e521696a3f97d37914de5 Mon Sep 17 00:00:00 2001 From: Yota Hamada Date: Tue, 1 Dec 2026 23:42:19 +0900 Subject: [PATCH 6/8] Correct connection details found in review dagu example takes only a number, and a redirected client secret breaks the account question, so the pages show commands that work on current main. They also give the exact loopback and paste redirect URIs, what Test checks, when a reconnect asks, the MCP client order without a fallback, the proxy exception, and the audited token events. --- features/connections/index.md | 22 +++++++++--------- features/connections/mcp-servers.md | 17 +++++++------- features/connections/oauth2.md | 36 +++++++++++++++++++---------- features/connections/steps.md | 15 +++++++++--- 4 files changed, 56 insertions(+), 34 deletions(-) diff --git a/features/connections/index.md b/features/connections/index.md index d97fd6b..5ee2016 100644 --- a/features/connections/index.md +++ b/features/connections/index.md @@ -23,7 +23,7 @@ steps: arguments: { state: open } ``` -Dagu stores the tokens encrypted, refreshes an access token when a step needs one, saves a rotated refresh token, and sends a token only over HTTPS to the hosts the connection is bound to. When a sign-in expires or is revoked, Dagu reports it once per notification channel and offers Reconnect. +Dagu stores the tokens encrypted, refreshes an access token when a step needs one, saves a rotated refresh token, and, over HTTP, sends a token only over HTTPS to the hosts the connection is bound to. An [exported token](/features/connections/oauth2#token-export) and the tokens a coordinator hands to workers travel outside that rule, as [Security and Workers](/features/connections/security#what-connections-guarantee) explains. When a sign-in expires or is revoked, Dagu reports it once per notification channel and offers Reconnect. These pages cover connections to any server: @@ -98,7 +98,7 @@ In the Web UI, open **Connections**, click **New connection**, and pick a tile: From the CLI, run `dagu connection add oauth2` or `dagu connection add mcp`. Both run the same connect flow as the UI, through the server's REST API. -The connection belongs to the workspace selected in the UI, or to the one `--workspace` names in the CLI. On a server that runs DAGs itself, rather than on workers, the wizard warns that DAG authors can read the connection's tokens. See [Security and Workers](/features/connections/security#local-mode). +The connection belongs to the workspace selected in the UI, or to the one `--workspace` names in the CLI. Every wizard warns that DAGs that run on the server, rather than on a worker, run as Dagu's user, so their authors can read the connection's tokens. See [Security and Workers](/features/connections/security#local-mode). ## Sign In @@ -117,12 +117,12 @@ Before consent, the UI and the CLI show the exact redirect URI to register in th | Mode | Used when | Redirect URI | Client type | | --- | --- | --- | --- | | Server callback | The server has a usable public URL | `/oauth/callback` | `web` | -| Loopback | The CLI runs where a browser can open | `http://127.0.0.1` on a random port the CLI listens on | `desktop` | -| Paste | Neither of the above | A loopback URL that fails to load. You copy the address the browser lands on and paste it into the UI or the CLI | `desktop` | +| Loopback | A `desktop` client, and the CLI runs where a browser can open | `http://127.0.0.1:/oauth/callback`, on a random port the CLI listens on | `desktop` | +| Paste | A `desktop` client, without the CLI's listener | `http://127.0.0.1:1/oauth/callback`, which fails to load. You copy the address the browser lands on and paste it into the UI or the CLI | `desktop` | -The UI and the CLI pick the first mode that works for the server and the app's client type. Loopback needs the CLI. The UI uses server callback or paste. +The UI and the CLI pick the first mode that works for the server and the app's client type. Loopback needs the CLI. The UI uses server callback or paste. A `web` client on a server without a usable public URL has no mode, and cannot sign in. Loopback works only with a provider that accepts any port on a loopback redirect (RFC 8252, section 7.3). -The usable public URL is `public_url` from `config.yaml`, else the [tunnel](/server-admin/tunnel) URL, else the UI's own origin when the browser reaches Dagu at `localhost` or a loopback address. A request through a proxy does not count, so a server behind a reverse proxy needs `public_url`. +The usable public URL is `public_url` from `config.yaml`, else the [tunnel](/server-admin/tunnel) URL, else the origin of the request when it reaches Dagu at `localhost` or a loopback address, without a proxy. So the UI opened at `http://localhost:8080`, and the CLI on the `local` context, get a server callback on that origin, such as `http://localhost:8080/oauth/callback`, and a `web` client. A request through a proxy does not count, so a server behind a reverse proxy needs `public_url`. In server callback mode, **Copy sign-in link** gives the authorization URL to the account's owner. The owner consents in their own browser without a Dagu login, and you confirm the account. @@ -153,11 +153,11 @@ Click **Reconnect** on the connection page, or run: dagu connection reconnect tracker --workspace ops ``` -A reconnect runs the same sign-in on the existing connection. The previous tokens stay live until you confirm. The CLI expects the account the connection holds, so the same account is confirmed without asking. A different account always asks first. +A reconnect runs the same sign-in on the existing connection. The previous tokens stay live until you confirm. The CLI expects the account the connection holds. It confirms without asking only when the provider vouches for that account's email, in an ID token with `email_verified`, and the account ID matches. Without `openid`, or without a verified email, the CLI asks even for the same account. A different account always asks first. Reconnect after the connection needs it, and after adding scopes, which take effect only at the next sign-in. A client credentials connection fetches a new token instead of signing in. -**Test** on the connection page, or `dagu connection test`, probes the connection with its live token. +**Test** on the connection page, or `dagu connection test`, checks that an `oauth2` or `mcp` connection can get a live token, refreshing it if needed. It does not call the API or the MCP server. To check the server, list its tools or call one, as [Try It](/features/connections/steps#try-it-and-copy-as-step) shows. ## Badge and Notifications @@ -186,7 +186,7 @@ Reconnect before the date to avoid the failure. ## Remove -Click **Remove connection** on the connection page, or run: +Click **Remove** on the connection page and confirm, or run: ```bash dagu connection remove tracker --workspace ops @@ -202,7 +202,7 @@ Remove deletes the connection, its tokens, and its tool lists. Then Dagu revokes ## Audit -With the [audit log](/server-admin/server#audit-logging) on, Dagu records app and connection changes, sign-ins, reconnects, removals, status changes, and tool calls from Try it. Token issuance is not audited, and no entry holds a secret. +With the [audit log](/server-admin/server#audit-logging) on, Dagu records app and connection changes, sign-ins, reconnects, removals, status changes, tool calls from Try it, a client credentials token fetched through the API, and a revocation. The tokens handed to steps are not audited, and no entry holds a secret. ## CLI Reference @@ -225,7 +225,7 @@ dagu connection apps list dagu connection apps remove APP ``` -- Every command takes `--workspace`. The default is `global`, the connections of DAGs without a `workspace` label. +- Every command except `providers` and `apps` takes `--workspace`. The default is `global`, the connections of DAGs without a `workspace` label. - `add` and `reconnect` take `--no-browser`, which prints the sign-in URL instead of opening a browser, such as over SSH. - `add` without enough flags asks for what is missing on a terminal, and reads secrets without echo. Without a terminal it fails, naming what is missing. - Every command calls the server's REST API. With a [remote context](/getting-started/cli#remote-contexts) it acts on that server. With the `local` context it calls the server that this host's configuration describes, which must be running. With builtin or OIDC authentication, the `local` context has no credential: add a context with an API key. diff --git a/features/connections/mcp-servers.md b/features/connections/mcp-servers.md index 66fdac2..1d4cd3b 100644 --- a/features/connections/mcp-servers.md +++ b/features/connections/mcp-servers.md @@ -53,11 +53,11 @@ When the authorization server's metadata says it sends `iss` in its redirect (RF | Client | Picked when | Who can use it | | --- | --- | --- | -| Client ID Metadata Document (CIMD) | The authorization server supports CIMD, and this server has a public HTTPS URL | A manager | -| Dynamic client registration (DCR) | The authorization server offers registration (RFC 7591) | A manager | -| An MCP app an admin added | The authorization server takes neither | A manager names it. An admin adds it | +| Client ID Metadata Document (CIMD) | The authorization server's metadata advertises CIMD, and this server has a public HTTPS URL | A manager | +| Dynamic client registration (DCR) | Otherwise, when the metadata names a registration endpoint (RFC 7591) | A manager | +| An MCP app an admin added | Only when you name it | A manager names it. An admin adds it | -Unless you choose, Dagu takes the first that works, in this order. +Unless you choose, Dagu takes the first the authorization server advertises: CIMD, then DCR. It picks by the metadata, not by what works, and does not fall back: when the authorization server later fails to fetch the CIMD document at consent, the sign-in fails, and you add the connection again with DCR. When the metadata advertises neither, the create fails and asks for an admin's app. **CIMD.** The client ID is the URL of this server's client metadata document, `/oauth/client-metadata.json`, a public route that describes Dagu as a public client whose redirect URI is the server callback. The authorization server fetches it, so: @@ -68,7 +68,7 @@ One CIMD client serves every `mcp` connection to the same authorization server, **DCR.** Dagu registers a client for this connection alone. It is a public client with PKCE and no secret, unless the authorization server takes no public client. Its redirect URI is the server callback when the server has a usable public URL, and the paste redirect otherwise. Removing the connection deletes its client in Dagu, as a best effort. The client stays registered at the authorization server. -**An MCP app an admin added.** For an authorization server that takes neither, an admin registers a client there and adds it to Dagu as an `mcp` app. A connection on that app skips discovery, so give the scopes the server needs. When discovery finds no client it can use, the error names the redirect URI and endpoints to register. +**An MCP app an admin added.** For an authorization server that takes neither, an admin registers a client there and adds it to Dagu as an `mcp` app. A connection on that app skips discovery, so give the scopes the server needs. When discovery finds no client it can use, the error names the redirect URI and endpoints to register. A `web` app signs in only on a server with a usable public URL. Without one, the error names the paste URI, `http://127.0.0.1:1/oauth/callback`, which needs a `desktop` app. An admin adds an `mcp` app through the REST API: @@ -98,7 +98,8 @@ Discovery and registration fetch only HTTPS URLs: - Discovery follows at most five redirects, each to HTTPS. Registration and token requests follow none. - Each request takes at most 10 seconds, a whole discovery at most 30, and each response is read up to 1 MiB. -- Unless every address of the MCP server's host is private, loopback, or link-local, no discovery or registration request reaches such an address, and the token and revocation endpoints may not resolve to one. An internal MCP server is reached directly, never through a configured proxy. +- Unless every address of the MCP server's host is private, loopback, or link-local, no discovery or registration request reaches such an address, and the token and revocation endpoints may not resolve to one when discovery checks them. Later token requests are not checked again. +- With a proxy configured, only the dial to the proxy skips that check, and the proxy resolves and reaches the target on its own, so the check does not cover requests through it. An internal MCP server is reached directly, never through the proxy. ## From the Web UI @@ -108,7 +109,7 @@ Discovery and registration fetch only HTTPS URLs: 4. Optionally, open **Advanced settings** and choose the **OAuth client**: **Automatic**, **Client ID Metadata Document (CIMD)**, **Dynamic client registration (DCR)**, or **An MCP app an admin added**. Add scopes if the server needs others than it names. 5. Create the connection, consent in the popup, and confirm the account. -When the authorization server refuses the CIMD client, the dialog offers **Try again with DCR**, or, after a failed sign-in, **Add again with DCR**, which removes the connection that never signed in and adds it again with a DCR client. +When you chose CIMD and the create fails, the dialog offers **Try again with DCR**. When the authorization server refuses the CIMD client at sign-in, under any choice, the dialog offers **Add again with DCR**, which removes the connection that never signed in and adds it again with a DCR client. The connection page shows the server URL, the client kind, the scopes, and the granted scopes. @@ -149,4 +150,4 @@ dagu connection call tracker --workspace ops --tool list_issues --args '{"state" ## Next Steps - [Use Connections in Steps](/features/connections/steps) covers `mcp.call` with `connection`, its errors, and the Tools panel. -- `dagu example connection-mcp-call --connection tracker` prints a starter DAG for the connection. +- The [starter DAG](/features/connections/steps#starter-dag) calls one tool of the connection. diff --git a/features/connections/oauth2.md b/features/connections/oauth2.md index 8f69341..78908fb 100644 --- a/features/connections/oauth2.md +++ b/features/connections/oauth2.md @@ -19,8 +19,10 @@ Setting up takes two parts: Create an OAuth client in the provider's developer console. Register the redirect URI that fits your server: -- **Web client**, for a server with a public URL: `/oauth/callback`, such as `https://dagu.example.com/oauth/callback`. The browser that consents must reach this URL. -- **Desktop client**, for a server without one: sign-in ends on a loopback address, `http://127.0.0.1`. The CLI listens there on a random port, or you paste the address the browser lands on. The provider must accept that loopback redirect. +- **Web client**, for a server with a [usable public URL](/features/connections/#redirect-modes): `/oauth/callback`, such as `https://dagu.example.com/oauth/callback`. The browser that consents must reach this URL. A server reached at `localhost` without a proxy counts, so the UI at `http://localhost:8080` and the CLI on the `local` context use `http://localhost:8080/oauth/callback`. +- **Desktop client**, for a server without one. Register both loopback URIs: + - `http://127.0.0.1:/oauth/callback`, where the CLI listens on a random port. The provider must accept any port on a loopback redirect (RFC 8252, section 7.3). + - `http://127.0.0.1:1/oauth/callback`, the paste URI. It fails to load, and you paste the address the browser lands on into the UI or the CLI. The UI and the CLI show the exact redirect URI before consent. Note the authorization URL, token URL, client ID, and client secret, if the provider issues one. @@ -94,7 +96,7 @@ The connection acts as the client itself, with no account and no refresh token: 1. Open **Connections** in the workspace that will own the connection, and click **New connection**. 2. Pick **Custom OAuth2**. -3. Pick an app that fits this server. An admin can click **Register an OAuth2 app** and fill in the [app fields](#oauth-app-fields). A manager who finds none sees what to ask an admin for. +3. Pick an app that fits this server. When none exists, an admin sees the **Register an OAuth2 app** form at once. When apps exist, an admin clicks **Register another app**. Fill in the [app fields](#oauth-app-fields) and click **Register app**. A manager who finds no app sees what to ask an admin for. 4. Enter the name, scopes, and bound hosts. An admin also picks the grant. 5. With the authorization code grant, click **Create and sign in**, consent in the popup, and confirm the account. With client credentials, click **Create**: the connection page opens with the token already fetched. @@ -102,7 +104,7 @@ On the connection page, **Edit scopes and hosts** changes the scopes and bound h ## From the CLI -Register a new app and sign in, as an admin: +Register a new app and sign in, as an admin, on a terminal: ```bash dagu connection add oauth2 work-api --workspace ops \ @@ -111,10 +113,10 @@ dagu connection add oauth2 work-api --workspace ops \ --authorize-url https://auth.example.com/authorize \ --token-url https://auth.example.com/token \ --revoke-url https://auth.example.com/revoke \ - --client-id dagu --client-secret-stdin < client-secret.txt + --client-id dagu ``` -`--client-secret-stdin` reads the secret from the first line of stdin. On a terminal without it, the CLI asks for the secret without echo. Without a secret, the client is public. +On a terminal, the CLI always asks for the client secret, without echo. Leave it empty for a public client. A sign-in then reads your answers from the terminal: the account confirmation, and in paste mode the pasted address. So do not redirect stdin for the authorization code grant. Use an app an admin already registered, as a manager: @@ -130,17 +132,27 @@ dagu connection add oauth2 reports --workspace ops --grant client_credentials \ --app example --scopes reports.read --bound-host reports.example.com ``` +A client credentials connection asks no question after it is created, so it can run without a terminal. To register its app there too, read the secret from stdin: + +```bash +dagu connection add oauth2 reports --workspace ops --grant client_credentials \ + --token-url https://auth.example.com/token --client-id reports-bot \ + --scopes reports.read --bound-host reports.example.com \ + --client-secret-stdin < client-secret.txt +``` + | Flag | Meaning | | --- | --- | +| `--workspace` | The workspace that owns the connection. Default: `global` | | `--scopes` | Scopes, comma-separated. Required | -| `--bound-host` | A host that may receive the token. Repeat for each. Required | +| `--bound-host` | A host that may receive the token. Repeat it, or give a comma-separated list. Required | | `--grant` | `authorization_code` (default) or `client_credentials` | -| `--app` | An existing `oauth2` app, by ID or name. `dagu connection apps list` lists them | +| `--app` | An existing `oauth2` app, by ID or name. `dagu connection apps list` lists them. Cannot be combined with the flags below that register a new app | | `--authorize-url`, `--token-url`, `--revoke-url`, `--client-id` | Register a new app, named after the connection. Needs admin | -| `--client-secret-stdin` | Read the new app's client secret from stdin | -| `--client-type` | `web` or `desktop`. Default: `web` for client credentials, or when the server has a public URL; otherwise `desktop` | -| `--no-pkce` | Turn PKCE off for a server that rejects it | -| `--token-auth` | `basic` (default) or `post` | +| `--client-secret-stdin` | Without a terminal, read the new app's client secret from the first line of stdin. On a terminal, the CLI asks for it either way | +| `--client-type` | For a new app: `web` or `desktop`. Default: `web` for client credentials, or when the server has a usable public URL, including `localhost` on the `local` context; otherwise `desktop` | +| `--no-pkce` | For a new app: turn PKCE off for a server that rejects it | +| `--token-auth` | For a new app: `basic` (default) or `post` | | `--no-browser` | Print the sign-in URL instead of opening a browser | The CLI prints the redirect URI and the client ID before consent, waits for the sign-in, asks you to confirm the account, and prints the result. Ctrl-C before the confirm cancels the session and discards its tokens. diff --git a/features/connections/steps.md b/features/connections/steps.md index 4bb35f0..6f1ad06 100644 --- a/features/connections/steps.md +++ b/features/connections/steps.md @@ -8,7 +8,7 @@ description: Name a connection in mcp.call and http.request steps. Covers admiss Connections are experimental and off by default. Turn them on with `experimental_connections: true` in `config.yaml`, or `DAGU_EXPERIMENTAL_CONNECTIONS=true`. While they are off, a run that names a connection fails before its first step. See [Turn Connections On](/features/connections/#turn-connections-on). ::: -A step names a connection in place of an `Authorization` header. Dagu takes a token that stays valid for at least 5 minutes, sends it only over HTTPS to the connection's bound hosts, refreshes it once when the server refuses it, and masks it in the step's logs, run status, and outputs. The run page shows the connection and account each step used. +A step names a connection in place of an `Authorization` header. Dagu takes a token that stays valid for at least 5 minutes, or for half its lifetime when the provider issues tokens that live under 10 minutes; a token without an expiry always serves. Dagu sends it only over HTTPS to the connection's bound hosts, refreshes it once when the server answers HTTP 401, never on a 403, and masks it in the step's logs, run status, and outputs. The run page shows the connection and account each step used. Three places take a connection: @@ -100,7 +100,7 @@ Before its first step, and before its secrets resolve, a run checks every connec A failed check fails the run before its first step, naming the connection. The run reports every failed check together. -These checks read no tokens, so a `pending` or `needs_reconnect` connection passes them. Each step that uses it then fails, and the run's other steps run. A `provider: connection` secret is the exception: secrets resolve once, before the first step, so such a connection fails the whole run. +These checks read no tokens, so a `pending` or `needs_reconnect` connection passes them. Each step that uses it then fails. Steps that depend on that step do not run and are marked `aborted`. Steps that do not depend on it keep running. A `provider: connection` secret is the exception: secrets resolve once, before the first step, so such a connection fails the whole run. ## Errors @@ -161,7 +161,16 @@ Tool lists are cached for 10 minutes per connection on each host, so the panel, ## Starter DAG -`dagu example connection-mcp-call --connection tracker` prints a starter DAG, and the connect dialog offers it after a sign-in. It takes the URL, tool, and arguments as parameters: +After a sign-in, the connect dialog offers a starter DAG under **Start from a template**, and **Create DAG** saves it. The CLI prints it too: run `dagu example` to list the examples, find `connection-mcp-call` and its number, and pass that number with the connection's name: + +```bash +dagu example # find the number of connection-mcp-call +dagu example --connection tracker +``` + +`dagu example` lists the starter DAG only when `experimental_connections` is on in the configuration it reads. Its number follows the built-in examples, so it changes when one is added. + +The DAG takes the URL, tool, and arguments as parameters. For an `mcp` connection, `URL` is the MCP server's own URL, the one the connection was created with: ```yaml type: graph From 5194dcd1164dd047b27a521cbbf063421bc30572 Mon Sep 17 00:00:00 2001 From: Yota Hamada Date: Tue, 1 Dec 2026 23:42:19 +0900 Subject: [PATCH 7/8] Correct the mcp.call and http.request notes An oauth2 connection still needs url in mcp.call, only a 401 refreshes the token, and mcp.call declines every confirmation request. The HTTP page now lists the not-HTTPS and command or args rules too. --- step-types/http.md | 2 +- step-types/mcp.md | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/step-types/http.md b/step-types/http.md index 49a24b2..b1f23b6 100644 --- a/step-types/http.md +++ b/step-types/http.md @@ -116,7 +116,7 @@ steps: format: json ``` -A literal `url` off the bound hosts fails the run before its first step. A redirect is followed only to HTTPS on the same host and port. A 401 refreshes the token once and sends the request again, unless the request followed a redirect. `connection` cannot be combined with `debug: true`, `skip_tls_verify: true`, or an `Authorization` or `Host` header. See [Use Connections in Steps](/features/connections/steps#http-request). +A literal `url` off the bound hosts, or not HTTPS, fails the run before its first step. A redirect is followed only to HTTPS on the same host and port. A 401 refreshes the token once and sends the request again, unless the request followed a redirect. `connection` cannot be combined with `debug: true`, `skip_tls_verify: true`, an `Authorization` or `Host` header, or a `command` or `args`. See [Use Connections in Steps](/features/connections/steps#http-request). ### Query Parameters diff --git a/step-types/mcp.md b/step-types/mcp.md index 4d5ff94..418b745 100644 --- a/step-types/mcp.md +++ b/step-types/mcp.md @@ -44,7 +44,7 @@ steps: | Field | Required | Description | |-------|----------|-------------| -| `url` | Yes, without `connection` | Absolute `http` or `https` endpoint of the server. Accepts references such as `${MCP_URL}`. User info such as `https://user:pass@host` is rejected. With `connection`, it must be HTTPS on the connection's bound hosts. | +| `url` | Yes, unless `connection` names an `mcp` connection | Absolute `http` or `https` endpoint of the server. Accepts references such as `${MCP_URL}`. User info such as `https://user:pass@host` is rejected. With `connection`, it must be HTTPS on the connection's bound hosts. | | `tool` | Yes | Name of the tool to call. | | `arguments` | No | Tool arguments as an object, or a `${...}` reference that resolves to a JSON object. | | `headers` | No | Request headers sent with every request of the session. Use `${...}` references to [secrets](/writing-workflows/secrets) for credentials. With `connection`, `Authorization` is not allowed. | @@ -190,7 +190,7 @@ Redirects are not followed. Configure the final URL of the endpoint. Connections need `experimental_connections: true` in `config.yaml`. While they are off, a run that names a connection fails before its first step. ::: -For a server that uses OAuth, sign in once as a [connection](/features/connections/) and name it in place of `url` and the `Authorization` header: +For an MCP server that uses OAuth, sign in once as an [`mcp` connection](/features/connections/mcp-servers) and name it in place of `url` and the `Authorization` header: ```yaml steps: @@ -201,7 +201,9 @@ steps: tool: list_issues ``` -Dagu sends the connection's token only over HTTPS to its bound hosts, refreshes it once when the server refuses it, and masks it in the step's logs and output. An `auth` error then carries `connection`, and `detail: reconnect_required` or `detail: insufficient_scope` with the missing `scope`. See [Use Connections in Steps](/features/connections/steps#mcp-call). +An `oauth2` connection still needs `url`, an MCP server on one of its bound hosts, as [the `oauth2` example](/features/connections/steps#mcp-call) shows. + +Dagu sends the connection's token only over HTTPS to its bound hosts, refreshes it once when the server answers HTTP 401, and masks it in the step's logs and output. An `auth` error then carries `connection`, and `detail: reconnect_required` or `detail: insufficient_scope` with the missing `scope`. See [Use Connections in Steps](/features/connections/steps#mcp-call). ## Credentials @@ -239,7 +241,7 @@ The action sets no timeout of its own, and a tool may run as long as the server - Local stdio servers and the legacy HTTP+SSE transport. - MCP resources, prompts, and tasks. -- Sampling, and elicitation without a connection. +- Sampling and elicitation. With a connection, `mcp.call` declines a confirmation request and fails with `confirmation_required`. - OAuth sign-in flows outside [connections](/features/connections/). Without a connection, send a token the server accepts in `headers`. - Connection pooling. Each run opens and closes its own session. From 22a92d86617d80eee9d1fcea5bbf329427e415eb Mon Sep 17 00:00:00 2001 From: Yota Hamada Date: Tue, 1 Dec 2026 23:50:28 +0900 Subject: [PATCH 8/8] Say worker isolation holds per worker, not run Runs on one worker share its OS user, so a step can read the worker's credential and other runs' exported tokens. The page now says to keep DAG authors apart on separate workers with worker labels, and that Try again with DCR follows only a refused create, not a failed discovery. --- features/connections/mcp-servers.md | 2 +- features/connections/security.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/features/connections/mcp-servers.md b/features/connections/mcp-servers.md index 1d4cd3b..5dda997 100644 --- a/features/connections/mcp-servers.md +++ b/features/connections/mcp-servers.md @@ -109,7 +109,7 @@ Discovery and registration fetch only HTTPS URLs: 4. Optionally, open **Advanced settings** and choose the **OAuth client**: **Automatic**, **Client ID Metadata Document (CIMD)**, **Dynamic client registration (DCR)**, or **An MCP app an admin added**. Add scopes if the server needs others than it names. 5. Create the connection, consent in the popup, and confirm the account. -When you chose CIMD and the create fails, the dialog offers **Try again with DCR**. When the authorization server refuses the CIMD client at sign-in, under any choice, the dialog offers **Add again with DCR**, which removes the connection that never signed in and adds it again with a DCR client. +When you chose CIMD and the create is refused, because the authorization server does not take CIMD or this server has no public HTTPS URL, the dialog offers **Try again with DCR**. A failed discovery offers no retry. When the authorization server refuses the CIMD client at sign-in, under any choice, the dialog offers **Add again with DCR**, which removes the connection that never signed in and adds it again with a DCR client. The connection page shows the server URL, the client kind, the scopes, and the granted scopes. diff --git a/features/connections/security.md b/features/connections/security.md index 2f3d847..f51afff 100644 --- a/features/connections/security.md +++ b/features/connections/security.md @@ -31,7 +31,9 @@ A worker isolates tokens from DAG authors only when all of these hold: - It has its own encryption key, not the server's `DAGU_ENCRYPTION_KEY`. Every worker loads or creates a key at startup, so give it none of the server's. - The coordinator can tell workers apart, which needs [per-worker certificates](/server-admin/distributed/transport-security#add-workers-with-invites). See [Runs on Workers](#runs-on-workers). -Such a worker never reads the server's connection records, and receives from the coordinator only the access tokens of the connections its run's DAG names. If DAG authors must not reach every connection, run their DAGs on such workers. +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, `/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](/server-admin/distributed/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.