@@ -129,32 +129,38 @@ func New(ctx context.Context, options *Options) (*API, error) {
129
129
})
130
130
}
131
131
132
- var err error
133
- api .replicaManager , err = replicasync .New (ctx , options .Logger , options .Database , options .Pubsub , replicasync.Options {
134
- // Create a new replica ID for each Coder instance!
135
- ID : uuid .New (),
136
- RelayAddress : options .DERPServerRelayAddress ,
137
- RegionID : int32 (options .DERPServerRegionID ),
138
- })
139
- if err != nil {
140
- return nil , xerrors .Errorf ("initialize replica: %w" , err )
141
- }
142
-
143
- rootCA := x509 .NewCertPool ()
132
+ meshRootCA := x509 .NewCertPool ()
144
133
for _ , certificate := range options .TLSCertificates {
145
134
for _ , certificatePart := range certificate .Certificate {
146
135
certificate , err := x509 .ParseCertificate (certificatePart )
147
136
if err != nil {
148
137
return nil , xerrors .Errorf ("parse certificate %s: %w" , certificate .Subject .CommonName , err )
149
138
}
150
- rootCA .AddCert (certificate )
139
+ meshRootCA .AddCert (certificate )
151
140
}
152
141
}
153
- // nolint:gosec
154
- api .derpMesh = derpmesh .New (options .Logger .Named ("derpmesh" ), api .DERPServer , & tls.Config {
142
+ // This TLS configuration spoofs access from the access URL hostname
143
+ // assuming that the certificates provided will cover that hostname.
144
+ //
145
+ // Replica sync and DERP meshing require accessing replicas via their
146
+ // internal IP addresses, and if TLS is configured we use the same
147
+ // certificates.
148
+ meshTLSConfig := & tls.Config {
155
149
ServerName : options .AccessURL .Hostname (),
156
- RootCAs : rootCA ,
150
+ RootCAs : meshRootCA ,
151
+ }
152
+ var err error
153
+ api .replicaManager , err = replicasync .New (ctx , options .Logger , options .Database , options .Pubsub , replicasync.Options {
154
+ // Create a new replica ID for each Coder instance!
155
+ ID : uuid .New (),
156
+ RelayAddress : options .DERPServerRelayAddress ,
157
+ RegionID : int32 (options .DERPServerRegionID ),
158
+ TLSConfig : meshTLSConfig ,
157
159
})
160
+ if err != nil {
161
+ return nil , xerrors .Errorf ("initialize replica: %w" , err )
162
+ }
163
+ api .derpMesh = derpmesh .New (options .Logger .Named ("derpmesh" ), api .DERPServer , meshTLSConfig )
158
164
159
165
err = api .updateEntitlements (ctx )
160
166
if err != nil {
0 commit comments