Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0578357

Browse files
committed
feat: allow disabling stun addresses via env
Resolves #6791
1 parent e5c6ebd commit 0578357

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cli/server.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,19 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
568568
if !cfg.DERP.Server.Enable {
569569
defaultRegion = nil
570570
}
571+
572+
// HACK: see https://github.com/coder/coder/issues/6791.
573+
for _, addr := range cfg.DERP.Server.STUNAddresses {
574+
if addr != "disable" {
575+
continue
576+
}
577+
err := cfg.DERP.Server.STUNAddresses.Replace(nil)
578+
if err != nil {
579+
panic(err)
580+
}
581+
break
582+
}
583+
571584
derpMap, err := tailnet.NewDERPMap(
572585
ctx, defaultRegion, cfg.DERP.Server.STUNAddresses,
573586
cfg.DERP.Config.URL.String(), cfg.DERP.Config.Path.String(),

cli/server_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,29 @@ func TestServer(t *testing.T) {
14891489
w.RequireSuccess()
14901490
})
14911491
})
1492+
t.Run("DisableDERP", func(t *testing.T) {
1493+
t.Parallel()
1494+
1495+
// Make sure that $CODER_DERP_SERVER_STUN_ADDRESSES can be set to
1496+
// disable STUN.
1497+
1498+
inv, cfg := clitest.New(t,
1499+
"--in-memory",
1500+
"--http-address", ":0",
1501+
)
1502+
inv.Environ.Set("CODER_DERP_SERVER_STUN_ADDRESSES", "disable")
1503+
ptytest.New(t).Attach(inv)
1504+
clitest.Start(t, inv)
1505+
gotURL := waitAccessURL(t, cfg)
1506+
client := codersdk.New(gotURL)
1507+
1508+
ctx := testutil.Context(t, testutil.WaitMedium)
1509+
_ = coderdtest.CreateFirstUser(t, client)
1510+
gotConfig, err := client.DeploymentConfig(ctx)
1511+
require.NoError(t, err)
1512+
1513+
require.Len(t, gotConfig.Values.DERP.Server.STUNAddresses, 0)
1514+
})
14921515
}
14931516

14941517
func generateTLSCertificate(t testing.TB, commonName ...string) (certPath, keyPath string) {

0 commit comments

Comments
 (0)