Tailnet domains: publish a compose service on a Tailscale tailnet through an injected sidecar (design for the per-app mode of #4312)

オープン
#6,023 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
18/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
docker, docker-compose, typescript

調査の方向性

This is a design proposal awaiting maintainer agreement, not a scoped task. Start from the plug-in points it names: the domain schema and publishToCloudflare precedent from #4531, addDomainToCompose, and handle-domain.tsx, then read the Cloudflare Tunnel PRs #4528/#4531 as the model. It spans a new organization-level integration, encrypted credentials, key minting via the Tailscale API, compose injection and lifecycle cleanup — read the thread and the linked issues before writing anything.

索引モデルが issue の本文から書いたものです。

説明

enhancement
What problem will this feature address?

Many Dokploy apps are internal tools that should not answer the internet at all, and their operators already run Tailscale. Today the ways to put such an app on the tailnet all sit outside Dokploy:

  • Tailscale on the host plus tailscale serve per app. Every app shares the host's single name and gets a port of its own (host.<tailnet>.ts.net:8443, :8444, …). Each change needs root on the host. Funnel is limited to 443, 8443 and 10000, so at most three apps can be public. A host that is logged in as a user cannot host Tailscale Services ("You cannot use a device authenticated with a user account as a Service host", KB 1552). On top of that, tailscaled and Traefik compete for :443 on the host (#5157).
  • tailscale cert plus a custom certificate, the main ask of #4312. Traefik keeps serving it, and certificates have to be renewed by hand.
  • A hand-written tailscale/tailscale sidecar in each compose. It works, and we run it in production (see below). But every compose repeats about 40 lines of boilerplate and carries its own auth-key secret, and Dokploy knows nothing about it: the Domains tab is empty and the DNS check (#2615, #4312) does not apply.

A sidecar gives each app what the host-level approaches can't: its own tailnet name (myapp.<tailnet>.ts.net), a valid HTTPS certificate on 443, per-app ACLs through a tag, and optional Funnel. No port is opened on the host, Traefik is not involved, and nothing needs to be installed on a remote server. Dokploy already rewrites the compose file for every domain (addDomainToCompose adds Traefik labels and dokploy-network), so injecting a sidecar for a "tailnet" domain fits the same step.

Describe the solution you'd like

A domain can be published to a tailnet instead of through Traefik. The first iteration covers compose apps only. The shape follows the Cloudflare Tunnel proposal (#4309, PRs #4528/#4531), so the two publishing paths could later share one "publish via" field.

1. Credentials: an organization-level Tailscale integration (Settings → Tailscale)

  • It stores an OAuth client ID and secret. The client needs only Keys → Auth Keys → Write, limited to the tags it may assign. Devices → Core → Write is optional and enables cleanup (item 5).
  • It also stores the default tag (for example tag:dokploy-apps) and an optional control URL (baseURL, for Headscale or a custom deployment), plus a "Test connection" button that mints and immediately revokes a key.
  • The secret is stored with encryptedText, like compose.env, and never leaves the Dokploy server. The OAuth secret is not passed to the sidecar. On each deploy Dokploy mints a single-use, pre-authorized, non-ephemeral, tagged auth key that expires after one hour (POST /api/v2/tailnet/-/keys) and passes that key in. The sidecar runs with TS_AUTH_ONCE=true, so the key is used only on the first start. After that the node lives in the state volume, and an expired key in the generated .env is useless to anyone who reads the file. Passing the OAuth secret itself (TS_AUTHKEY=tskey-client-…?ephemeral=false, which the image supports) gains nothing: tailscale up mints the same kind of single-use key from it internally (feature/oauthkey). Meanwhile the long-lived secret would sit in the compose .env, in docker inspect, and in the argv of tailscale up --authkey=…, which containerboot builds from TS_AUTHKEY and which every local user can read in /proc.

2. Domain fields (same pattern as publishToCloudflare in #4531)

  • publishToTailnet: boolean and tailscaleId (a foreign key to the integration).
  • host holds the node name, a single DNS label (myapp). The UI shows it as myapp.<tailnet>.ts.net, using the suffix the node reports after its first start.
  • port, path and serviceName keep their current meaning.
  • https and certificateType do not apply: Tailscale always terminates HTTPS on 443.
  • tailnetFunnel: boolean.
  • validateDomain is skipped for these domains.

3. What Dokploy writes into the compose. For each node name, one service is added. Several domains with the same host become several serve handlers or ports on one node.

configs:
  dokploy-ts-<key>:
    content: |
      {"TCP": {"443": {"HTTPS": true}},
       "Web": {"$${TS_CERT_DOMAIN}:443": {"Handlers": {"/": {"Proxy": "http://<serviceName>:<port>"}}}},
       "AllowFunnel": {"$${TS_CERT_DOMAIN}:443": false}}
services:
  dokploy-ts-<key>:
    image: tailscale/tailscale:<version pinned by Dokploy>
    restart: unless-stopped
    environment:
      TS_HOSTNAME: <host>
      TS_AUTHKEY: ${DOKPLOY_TS_AUTHKEY_<key>}   # single-use key minted at deploy, written to the generated .env
      TS_EXTRA_ARGS: --advertise-tags=<tags>
      TS_AUTH_ONCE: "true"
      TS_STATE_DIR: /var/lib/tailscale
      TS_SERVE_CONFIG: /config/serve.json
      TS_USERSPACE: "true"
      TS_ENABLE_HEALTH_CHECK: "true"
      TS_LOCAL_ADDR_PORT: 127.0.0.1:9002
    configs: [{source: dokploy-ts-<key>, target: /config/serve.json}]
    volumes: [dokploy-ts-<key>:/var/lib/tailscale]
    cap_drop: [ALL]
    security_opt: [no-new-privileges:true]
    networks: <the networks of serviceName>   # default network, or the isolated-deployment network
volumes:
  dokploy-ts-<key>:
  • The target service is left unchanged: it gets no Traefik labels and does not join dokploy-network.
  • Userspace networking needs no /dev/net/tun and no capabilities, because serve only proxies to another container by name. ScaleTail-style network_mode: service:tailscale is not needed and would change how the app's own ports behave.
  • randomize and isolatedDeployment keep working: the sidecar takes the suffixed service name and the app's networks.

4. Remote servers. Nothing changes. The compose is generated and written by the existing SSH path, and the sidecar runs next to the app on that server. Keys are minted by the main Dokploy server through the Tailscale API, so neither Tailscale on the remote host nor Traefik there is involved.

5. Lifecycle

  • A deploy is idempotent: an unchanged sidecar is not recreated, and a recreated one comes back with the same device because the state is on the volume.
  • Removing a tailnet domain drops the sidecar at the next deploy (--remove-orphans). The device stays in the tailnet, though. With the Devices scope Dokploy deletes it through the API (the node ID comes from tailscale status --json inside the sidecar before it goes); without that scope, the UI says so.
  • The state volume is the node's identity. If it is lost, the next start registers a new device (myapp-1) with a freshly minted key, so the old device has to be removed for the name to come back.

6. Funnel. tailnetFunnel sets AllowFunnel in the serve config. The tailnet policy must grant the funnel node attribute to the tag. Dokploy does not edit the policy and only shows that requirement.

Not in this proposal

  • Applications (swarm services) are left for a second step. They would need a companion swarm service on the app's network and a state volume pinned to one node.
  • The stack compose type is excluded for the same reason (state volume placement).
  • Tailscale Services (svc: VIPs) are excluded. They require tagged hosts and approval flows, so they are a possible later mode.
  • Editing the tailnet policy (tags, grants, Funnel attribute) stays with the operator.
  • Putting Dokploy's own UI on the tailnet is a separate topic (#2661, #5157).
  • Traefik middlewares (basic auth, forward auth, custom middlewares) are not applied, because access control comes from the tailnet ACL. Open question: would you rather route sidecar → dokploy-traefik → app to keep them?
Describe alternatives you've considered
  • Host-level tailscale serve: covered above. One name, ports per app, root on every change, three Funnel ports, and conflicts with Traefik on 443.
  • tailscale cert plus custom certificates (#4312): still Traefik on the host's IP, with manual renewal.
  • IP allow-lists per domain (#5420): this restricts who may connect but gives no tailnet name or certificate. It complements this proposal rather than replacing it.
  • tsdproxy, DockTail: a separate proxy outside Dokploy's domain model. DockTail needs a tagged host to use Tailscale Services.
  • A hand-written sidecar in every compose: what we do today (below).
Additional context

We run this today, by hand. On Dokploy v0.31.0 we added the sidecar from item 3 by hand to a raw compose app (a self-hosted web app with Postgres): tailscale/tailscale:v1.104.7, userspace, cap_drop: ALL. Our deploy script does what item 1 proposes for Dokploy: it keeps the OAuth client and passes the container a single-use, pre-approved, tagged key that expires in an hour. What we saw:

  • Name and certificate. The app answers on https://<app>.<tailnet>.ts.net with a Let's Encrypt certificate, from the tailnet only. The first deploy, including node registration and the certificate, took about a minute.
  • Nothing else changed. The app's own services, ports and the existing access path were left as they were. The deploy recreated only the service whose env changed.
  • The device survives recreation. docker compose up --force-recreate of the sidecar came back as the same device (doLogin(regen=false), no <app>-1), even though the single-use key was already spent. A plain Dokploy redeploy doesn't recreate it at all.
  • Access is set by the tailnet policy. With a grant of only tcp:443 to the tag, every other port of the node is closed. A tag that appears nowhere as src keeps a compromised app container from reaching anything else in the tailnet.
  • Gotchas worth handling in Dokploy:
    • An OAuth client secret passed as TS_AUTHKEY registers an ephemeral node unless ?ephemeral=false is appended (feature/oauthkey defaults to true). Item 1 sidesteps this.
    • ${TS_CERT_DOMAIN} in an inline configs.content must be written as $${TS_CERT_DOMAIN}, or compose interpolates it to an empty string.
    • Apps that check the request origin (Better Auth and similar) need the new https://<app>.<tailnet>.ts.net origin trusted. Dokploy can't do that for the app, but the domain dialog could say so.
    • Behind a stateless provider firewall that drops inbound UDP, the sidecar connects through DERP relays. It still works, but a direct path needs a fixed --port and a firewall rule per node.

Related: #4312 (native Tailscale, whose optional third item is this per-app mode), #5420, #5862, #2615, #5157, #4309 / #4531 (the same plug-in points: domain schema, addDomainToCompose, handle-domain.tsx).

Will you send a PR to implement it?

Yes, for the compose part, once the design is agreed.

主要言語
TypeScript
スター
38.8k
フォーク
3.2k
平均マージ
1日 10時間
マージ済み PR(30日)
110

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Dokploy/dokploy のほかの issue

Dokploy/dokploy の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。