Skip to content

Commit 8641e58

Browse files
committed
Fix RootCA for replica meshing
1 parent ee59d88 commit 8641e58

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

enterprise/coderd/coderd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ func New(ctx context.Context, options *Options) (*API, error) {
146146
// internal IP addresses, and if TLS is configured we use the same
147147
// certificates.
148148
meshTLSConfig := &tls.Config{
149-
ServerName: options.AccessURL.Hostname(),
150-
RootCAs: meshRootCA,
149+
Certificates: options.TLSCertificates,
150+
RootCAs: meshRootCA,
151+
ServerName: options.AccessURL.Hostname(),
151152
}
152153
var err error
153154
api.replicaManager, err = replicasync.New(ctx, options.Logger, options.Database, options.Pubsub, replicasync.Options{

enterprise/replicasync/replicasync_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package replicasync_test
22

33
import (
44
"context"
5+
"crypto/tls"
6+
"crypto/x509"
57
"net/http"
68
"net/http/httptest"
79
"sync"
@@ -112,6 +114,48 @@ func TestReplica(t *testing.T) {
112114
require.False(t, server.Self().Error.Valid)
113115
_ = server.Close()
114116
})
117+
t.Run("ConnectsToPeerReplicaTLS", func(t *testing.T) {
118+
// Ensures that the replica reports a successful status for
119+
// accessing all of its peers.
120+
t.Parallel()
121+
rawCert := testutil.GenerateTLSCertificate(t, "hello.org")
122+
certificate, err := x509.ParseCertificate(rawCert.Certificate[0])
123+
require.NoError(t, err)
124+
pool := x509.NewCertPool()
125+
pool.AddCert(certificate)
126+
// nolint:gosec
127+
tlsConfig := &tls.Config{
128+
Certificates: []tls.Certificate{rawCert},
129+
ServerName: "hello.org",
130+
RootCAs: pool,
131+
}
132+
srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
133+
w.WriteHeader(http.StatusOK)
134+
}))
135+
srv.TLS = tlsConfig
136+
srv.StartTLS()
137+
defer srv.Close()
138+
db, pubsub := dbtestutil.NewDB(t)
139+
peer, err := db.InsertReplica(context.Background(), database.InsertReplicaParams{
140+
ID: uuid.New(),
141+
CreatedAt: database.Now(),
142+
StartedAt: database.Now(),
143+
UpdatedAt: database.Now(),
144+
Hostname: "something",
145+
RelayAddress: srv.URL,
146+
})
147+
require.NoError(t, err)
148+
server, err := replicasync.New(context.Background(), slogtest.Make(t, nil), db, pubsub, replicasync.Options{
149+
ID: uuid.New(),
150+
RelayAddress: "http://169.254.169.254",
151+
TLSConfig: tlsConfig,
152+
})
153+
require.NoError(t, err)
154+
require.Len(t, server.Regional(), 1)
155+
require.Equal(t, peer.ID, server.Regional()[0].ID)
156+
require.False(t, server.Self().Error.Valid)
157+
_ = server.Close()
158+
})
115159
t.Run("ConnectsToFakePeerWithError", func(t *testing.T) {
116160
t.Parallel()
117161
db, pubsub := dbtestutil.NewDB(t)

helm/templates/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ metadata:
1010
{{- toYaml .Values.coder.service.annotations | nindent 4 }}
1111
spec:
1212
type: {{ .Values.coder.service.type }}
13+
sessionAffinity: ClientIP
1314
ports:
1415
- name: {{ include "coder.portName" . | quote }}
1516
port: {{ include "coder.servicePort" . }}

0 commit comments

Comments
 (0)