Skip to content

Commit

Permalink
etcd: use a separate connection to check peer versions
Browse files Browse the repository at this point in the history
 There is a data race in etcd that breaks the internal state in etcd client
implementation for some server setups (user/pass authentication with
JWTs).
  • Loading branch information
Andrew Lytvynov committed May 18, 2021
1 parent 0e57934 commit 1bcc6ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion e
Submodule e updated from 2c178f to 9c5b6e
20 changes: 16 additions & 4 deletions lib/backend/etcdbk/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/gravitational/teleport/lib/utils"

"github.com/coreos/go-semver/semver"
"github.com/gravitational/teleport"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -45,6 +44,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/gravitational/teleport"
)

var (
Expand Down Expand Up @@ -216,11 +217,10 @@ func New(ctx context.Context, params backend.Params) (*EtcdBackend, error) {
buf: buf,
}

// Check that the etcd nodes are at least the minimum version supported
if err = b.reconnect(ctx); err != nil {
return nil, trace.Wrap(err)
}

// Check that the etcd nodes are at least the minimum version supported
timeout, cancel := context.WithTimeout(ctx, time.Second*3*time.Duration(len(cfg.Nodes)))
defer cancel()
for _, n := range cfg.Nodes {
Expand All @@ -237,6 +237,13 @@ func New(ctx context.Context, params backend.Params) (*EtcdBackend, error) {
}
}

// Reconnect the etcd client to work around a data race in their code.
// Upstream fix: https://github.com/etcd-io/etcd/pull/12992
if err = b.reconnect(ctx); err != nil {
return nil, trace.Wrap(err)
}
go b.asyncWatch()

// Wrap backend in a input sanitizer and return it.
return b, nil
}
Expand Down Expand Up @@ -292,6 +299,12 @@ func (b *EtcdBackend) CloseWatchers() {
}

func (b *EtcdBackend) reconnect(ctx context.Context) error {
if b.client != nil {
if err := b.client.Close(); err != nil {
b.Entry.WithError(err).Warning("Failed closing existing etcd client on reconnect.")
}
}

tlsConfig := utils.TLSConfig(nil)

if b.cfg.TLSCertFile != "" {
Expand Down Expand Up @@ -340,7 +353,6 @@ func (b *EtcdBackend) reconnect(ctx context.Context) error {
return trace.Wrap(err)
}
b.client = clt
go b.asyncWatch()
return nil
}

Expand Down

0 comments on commit 1bcc6ef

Please sign in to comment.