Skip to content

docs: add guide for self-hosting a STUN server - #31996

Merged
nickvigilante merged 4 commits into
mainfrom
superblink/docs-310-self-hosted-stun
Nov 12, 2026
Merged

nickvigilante merged 4 commits into
mainfrom
superblink/docs-310-self-hosted-stun

Conversation

@nickvigilante

@nickvigilante nickvigilante commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a how-to guide for self-hosting a STUN server with coturn and pointing CODER_DERP_SERVER_STUN_ADDRESSES at it.
The guide is linked from the STUN and NAT page, the networking overview, and the air-gapped comparison table.

Refs #16537, DOCS-310

Verification

  • Both coturn install paths were run on an Ubuntu 24.04 VM and checked with coder netcheck against a v2.39.0 deployment configured with only self-hosted STUN servers: the coturn 4.6 package under systemd with the documented config, and the coturn/coturn:4.18.0 container with a published UDP port. Hostname and IP entries in CODER_DERP_SERVER_STUN_ADDRESSES both worked.
  • A client on a separate home NAT network got p2p connections from coder ping, and the STUN servers logged requests from both the client and the agent. With the STUN servers stopped, connections fell back to DERP and coder ping printed the "could not connect to STUN over UDP" hints. Running workspaces picked up the new STUN list without a restart.
  • Custom relay map path, checked in-process only (a throwaway derphealth test, not committed): with a nil built-in region, tailnet.NewDERPMap drops CODER_DERP_SERVER_STUN_ADDRESSES, and hand-written STUN-only regions loaded from a relay map file report can_stun: true. The documented jq filter lists them for both built-in and custom maps.
  • Source-verified only: each address becomes its own STUN-only region (tailnet.STUNRegions), which backs the "two or more servers" advice. With the built-in relay off, a relay map that has only STUN-only nodes fails startup (tailnet.NewDERPMap, pinned by TestNewDERPMap/RequireDERPNodes), which backs the "keep at least one relay node" note.
  • Not tested: Kubernetes or ingress setups. The VM-only guidance follows Spike's comment on docs: Self hosting a STUN server #16537.

markdownlint, Vale, lint/emdash, lint/docs-manifest, and lint/docs-html pass on the changed files, and a doc-check self-check left no blocking findings.

Decision log
  • Dropped stund. It has no releases, packages, or container images, so the guide had readers build an unpinned binary from Tailscale's main branch with no distribution security updates. It also answers only binding requests that carry a FINGERPRINT attribute, so generic STUN test tools can't check it. Its only advantage over coturn is a smaller, memory-safe, STUN-only codebase, and coturn's stun-only mode covers the practical need.
  • The built-in relay is optional unless you use CODER_DERP_SERVER_STUN_ADDRESSES. cli/server.go sets the built-in region to nil when CODER_DERP_SERVER_ENABLE=false, and tailnet.NewDERPMap adds STUN regions only when that region exists, numbering them from its region ID. Deployments with a custom relay map add STUN-only regions to that map instead, so the prerequisite became a "Use a custom relay map" section under Configure Coder. The page doesn't drop the relay entirely, because the built-in relay is still required for CODER_DERP_SERVER_STUN_ADDRESSES, and a custom relay map still needs at least one relay node.
  • Changed the jq filter. The old filter matched generated coder_stun_* region codes, so it returned an empty list for STUN regions written into a custom relay map. The filter now selects nodes with STUNOnly set.

Supersedes #31802, reopened under a human author for attribution.


Generated with Coder Agents on behalf of @nickvigilante.

Adds a how-to for running coturn or Tailscale's stund as a self-hosted STUN server and pointing CODER_DERP_SERVER_STUN_ADDRESSES at it, and links it from the STUN, networking, and air-gapped pages.
@linear-code

linear-code Bot commented Nov 10, 2026

Copy link
Copy Markdown

DOCS-310

@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 16:07 — with GitHub Actions Inactive
@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 16:07 — with GitHub Actions Inactive
@nickvigilante nickvigilante added the community Pull Requests and issues created by the community. label Nov 10, 2026
@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 16:07 — with GitHub Actions Inactive
@nickvigilante
nickvigilante marked this pull request as ready for review November 10, 2026 16:10
@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 16:10 — with GitHub Actions Inactive
stund has no published releases, so readers would build an unpinned
binary from Tailscale's main branch. coturn ships as distribution
packages and an official container image, so the guide covers only it.

The built-in relay isn't a prerequisite for self-hosted STUN. Only the
CODER_DERP_SERVER_STUN_ADDRESSES setting depends on it, so the
Configure Coder note now says that and describes the STUN-only regions
to add to a custom relay map. The netcheck jq filter now selects
STUN-only nodes instead of generated coder_stun region codes, so it also
lists STUN servers from a custom relay map.

Also applies review wording for the NAT hairpinning and reverse proxy
bullets.
@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 22:22 — with GitHub Actions Inactive
@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 22:22 — with GitHub Actions Inactive
The built-in relay is optional for self-hosted STUN. It's needed only
for CODER_DERP_SERVER_STUN_ADDRESSES, which Coder ignores when
CODER_DERP_SERVER_ENABLE=false. Move the custom relay map guidance into
its own section that says so, and note that a relay map with only
STUN-only nodes fails startup (tailnet.NewDERPMap requires a relay
node).

Also scopes the apt-get step and config path to Debian and Ubuntu,
mentions installing jq before the verify step, and fixes a run-on in
the air-gapped STUN row.
@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 22:57 — with GitHub Actions Inactive
@nickvigilante
nickvigilante temporarily deployed to main November 10, 2026 22:58 — with GitHub Actions Inactive
@coderagents

coderagents Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Check

Blocking

  • docs/admin/networking/self-hosted-stun.md - This page is new. The coturn config fence at line 46 uses text; use txt.
  • docs/admin/networking/self-hosted-stun.md - This page is new. The coder ping output fence at line 179 uses text; use txt.
  • docs/admin/networking/self-hosted-stun.md - This page is new. "Coder's built-in relay" names the DERP relay server differently from the rest of the docs, which call it the "embedded DERP relay server" or "built-in DERP relay".
Findings for agents
- id: structure-1
  persona: structure
  class: rule
  blocking: true
  file: docs/admin/networking/self-hosted-stun.md
  line: 46
  quote: "   ```text"
  evidence:
    - docs/.style/style-guide/formatting.md#code-blocks-with-language-fences
  rule: docs/.style/style-guide/formatting.md#code-blocks-with-language-fences
  problem: "The coturn config fence uses `text`, but the canonical tag for a block with no syntax to highlight is `txt`."
  fix: "Change the fence to ```txt."
  verified: true
- id: structure-2
  persona: structure
  class: rule
  blocking: true
  file: docs/admin/networking/self-hosted-stun.md
  line: 179
  quote: "   ```text"
  evidence:
    - docs/.style/style-guide/formatting.md#code-blocks-with-language-fences
  rule: docs/.style/style-guide/formatting.md#code-blocks-with-language-fences
  problem: "The `coder ping` output block is tagged `text`; the style guide uses `txt` for command output shown on its own."
  fix: "Change the fence to ```txt."
  verified: true
- id: consistency-1
  persona: consistency
  class: rule
  blocking: true
  file: docs/admin/networking/self-hosted-stun.md
  line: 132
  quote: "Coder's built-in relay is optional for self-hosted STUN."
  evidence:
    - docs/reference/cli/server/index.md#--derp-server-enable
    - docs/admin/setup/configuration-reference.md
    - docs/install/prepare/airgap.md
  rule: docs/.style/style-guide/word-choice.md#one-term-per-concept
  problem: ""Coder's built-in relay" names the DERP relay server differently from the rest of the docs, which call it the "embedded DERP relay server" or "built-in DERP relay"."
  fix: "Use "built-in DERP relay" at lines 132, 133, and 135."
  verified: true
- id: consistency-2
  persona: consistency
  class: suggestion
  blocking: false
  file: docs/admin/networking/self-hosted-stun.md
  line: 135
  quote: "Without the built-in relay, add your STUN servers to the [custom relay map](./index.md#custom-relays) that you provide with `CODER_DERP_CONFIG_URL` or `CODER_DERP_CONFIG_PATH`:"
  evidence:
    - docs/reference/cli/server/index.md#--derp-config-url
  rule: docs/.style/style-guide/word-choice.md#one-term-per-concept
  problem: "This page calls the JSON artifact a "custom relay map", but the reference docs call the same thing a "DERP mapping"."
  fix: "Align the term with the canonical "DERP map"/"DERP mapping"."
  verified: true
- id: consistency-3
  persona: consistency
  class: suggestion
  blocking: false
  file: docs/admin/networking/self-hosted-stun.md
  line: 127
  quote: "- Run two or more STUN servers on separate hosts."
  evidence:
    - docs/reference/cli/server/index.md#--derp-server-stun-addresses
  rule: null
  problem: ""Run two or more STUN servers" diverges from the canonical wording "at least two"."
  fix: "Use "Run at least two STUN servers on separate hosts.""
  verified: true
- id: consistency-4
  persona: consistency
  class: suggestion
  blocking: false
  file: docs/admin/networking/self-hosted-stun.md
  line: 103
  quote: "Set [`CODER_DERP_SERVER_STUN_ADDRESSES`](../../reference/cli/server/index.md#--derp-server-stun-addresses) to a comma-separated list of your STUN servers, in `host:port` form:"
  evidence:
    - cli/server.go:693
    - tailnet/derpmap.go:72
  rule: null
  problem: "The "Configure Coder" section sets `CODER_DERP_SERVER_STUN_ADDRESSES` without noting Coder ignores it when `CODER_DERP_SERVER_ENABLE=false`."
  fix: "Add a pointer to `./index.md#custom-relays` here."
  verified: true
- id: coverage-1
  persona: coverage
  class: suggestion
  blocking: false
  file: docs/admin/networking/self-hosted-stun.md
  line: 135
  quote: "Without the built-in relay, add your STUN servers to the [custom relay map](./index.md#custom-relays) that you provide with `CODER_DERP_CONFIG_URL` or `CODER_DERP_CONFIG_PATH`:"
  evidence:
    - docs/admin/networking/index.md#custom-relays
  rule: null
  problem: "The "Use a custom relay map" section links to `index.md#custom-relays`, whose example shows only a relay node with no `STUNOnly`/`STUNPort`, so the reader cannot compose the map."
  fix: "Extend the `index.md` example to show a STUN-only region."
  verified: true
- id: accuracy-1
  persona: accuracy
  class: suggestion
  blocking: false
  file: docs/admin/networking/self-hosted-stun.md
  line: 127
  quote: "- Run two or more STUN servers on separate hosts."
  evidence:
    - tailnet/derpmap.go:21-54
  rule: null
  problem: ""Direct connections keep working if one server goes down" is not pinned by a test."
  fix: "Add a test dropping one STUN region and asserting the remaining region still probes, or qualify the claim."
  verified: true
- id: accuracy-2
  persona: accuracy
  class: suggestion
  blocking: false
  file: docs/admin/networking/self-hosted-stun.md
  line: 119
  quote: "Running workspaces pick up the new STUN servers without a restart."
  evidence:
    - workspaceagents.go:1257
    - agent/agent_test.go:3628
  rule: null
  problem: ""Running workspaces pick up the new STUN servers without a restart" is not pinned by a test of the coderd `/api/v2/derp-map` websocket stream."
  fix: "Add a stream-level test, or the claim is untested at the documented path."
  verified: true

Automated review via Coder Agents. Reply to a finding's thread with the reason if the finding is wrong.

@matifali
matifali removed their request for review November 11, 2026 13:21
@nickvigilante
nickvigilante temporarily deployed to main November 12, 2026 14:56 — with GitHub Actions Inactive
@nickvigilante
nickvigilante merged commit 71ab161 into main Nov 12, 2026
28 of 29 checks passed
@nickvigilante
nickvigilante deleted the superblink/docs-310-self-hosted-stun branch November 12, 2026 15:20
@nickvigilante
nickvigilante temporarily deployed to main November 12, 2026 15:20 — with GitHub Actions Inactive
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026

This branch was previously deployed

1 inactive deployment
main — 3a059124 Deployed Nov 12, 2026 by nickvigilante via cla #254997
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community Pull Requests and issues created by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants