Skip to content

Commit c1aa3d2

Browse files
committed
Pipe TLS to DERP mesh
1 parent 9914840 commit c1aa3d2

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

cli/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ func Server(dflags *codersdk.DeploymentFlags, newAPI func(context.Context, *code
322322
Experimental: ExperimentalEnabled(cmd),
323323
DeploymentFlags: dflags,
324324
}
325+
if tlsConfig != nil {
326+
options.TLSCertificates = tlsConfig.Certificates
327+
}
325328

326329
if dflags.OAuth2GithubClientSecret.Value != "" {
327330
options.GithubOAuth2Config, err = configureGithubOAuth2(accessURLParsed,

coderd/coderd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package coderd
22

33
import (
4+
"crypto/tls"
45
"crypto/x509"
56
"io"
67
"net/http"
@@ -76,6 +77,8 @@ type Options struct {
7677
TracerProvider trace.TracerProvider
7778
AutoImportTemplates []AutoImportTemplate
7879

80+
// TLSCertificates is used to mesh DERP servers securely.
81+
TLSCertificates []tls.Certificate
7982
TailnetCoordinator tailnet.Coordinator
8083
DERPServer *derp.Server
8184
DERPMap *tailcfg.DERPMap

enterprise/coderd/coderd.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package coderd
33
import (
44
"context"
55
"crypto/ed25519"
6+
"crypto/tls"
67
"net/http"
78
"sync"
89
"time"
@@ -137,7 +138,11 @@ func New(ctx context.Context, options *Options) (*API, error) {
137138
if err != nil {
138139
return nil, xerrors.Errorf("initialize replica: %w", err)
139140
}
140-
api.derpMesh = derpmesh.New(options.Logger.Named("derpmesh"), api.DERPServer, nil)
141+
// nolint:gosec
142+
api.derpMesh = derpmesh.New(options.Logger.Named("derpmesh"), api.DERPServer, &tls.Config{
143+
Certificates: options.TLSCertificates,
144+
ServerName: options.AccessURL.Host,
145+
})
141146

142147
err = api.updateEntitlements(ctx)
143148
if err != nil {

0 commit comments

Comments
 (0)