close
Skip to content

pkg/transport: reload TLS certificates for every client requests#7829

Merged
gyuho merged 2 commits into
etcd-io:masterfrom
gyuho:certs
Apr 27, 2017
Merged

pkg/transport: reload TLS certificates for every client requests#7829
gyuho merged 2 commits into
etcd-io:masterfrom
gyuho:certs

Conversation

@gyuho
Copy link
Copy Markdown
Contributor

@gyuho gyuho commented Apr 27, 2017

No description provided.

Comment thread clientv3/integration/dial_test.go Outdated

// TestDialTLSExpiredReload ensures server reloads expired certs,
// rejecting client requests, and vice versa.
func TestDialTLSExpiredReload(t *testing.T) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integration/ instead of clientv3/integration since it's testing server behavior that's client independent?

Comment thread clientv3/integration/dial_test.go Outdated
}

// copyTLSFiles clones certs files to temp directory.
func copyTLSFiles(ti transport.TLSInfo) (transport.TLSInfo, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func copyTLSFiles(ti transport.TLSInfo, dst string) (transport.TLSInfo, error) instead of bothering with tempdirs here; can be passed in as an argument

Comment thread clientv3/integration/dial_test.go Outdated
if err = w.Sync(); err != nil {
return err
}
if _, err = w.Seek(0, io.SeekStart); err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Comment thread clientv3/integration/dial_test.go Outdated
defer clus.Terminate(t)

// replace certs directory with expired ones
if err = os.Rename(certsDir, tmpDir); err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two separate tests: atomic directory rename and copy-over. The copy-over case would cause connection failures during cert update (or might take down the server in some way).

Comment thread clientv3/integration/dial_test.go Outdated

// now server expects 'tls: bad certificate'
// on incoming client requests
tls, err := ts.ClientConfig()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some concurrency would be good here. Boot a cluster, start a goroutine that spams it with connections, manipulate the certs while connections concurrently hit the server. The connection goroutine would complete when it transitions from good connections to tls rejects.

@gyuho gyuho added the WIP label Apr 27, 2017
@gyuho gyuho force-pushed the certs branch 2 times, most recently from c2f7574 to 8020d42 Compare April 27, 2017 18:13
This changes the baseConfig used when creating tls Configs to utilize
the GetCertificate and GetClientCertificate functions to always reload
the certificates from disk whenever they are needed.

Always reloading the certificates allows changing the certificates via
an external process without interrupting etcd.

Fixes etcd-io#7576

Cherry-picked by Gyu-Ho Lee <gyuhox@gmail.com>
Original commit can be found at etcd-io#7784
@gyuho
Copy link
Copy Markdown
Contributor Author

gyuho commented Apr 27, 2017

@heyitsanthony PTAL. Thanks.

}
}()

// overwrite valid certs with expired ones
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyTLSFiles to replace the copyFiles?

t.Fatal("expected dial timeout in 3 seconds, but never got it")
}

// now, replace expired certs back with valid ones
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyTLSFiles to replace the copyFiles?

Comment thread integration/v3_grpc_test.go Outdated
defer clus.Terminate(t)

// concurrent client dialing while certs transition from valid to expired
errc := make(chan error)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make(chan error, 1)

Comment thread integration/v3_grpc_test.go Outdated
}
cli, cerr := clientv3.New(clientv3.Config{
Endpoints: []string{clus.Members[0].GRPCAddr()},
DialTimeout: 3 * time.Second,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1s?

Comment thread integration/v3_grpc_test.go Outdated
}
cli, cerr := clientv3.New(clientv3.Config{
Endpoints: []string{clus.Members[0].GRPCAddr()},
DialTimeout: 3 * time.Second,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1s?

Comment thread integration/cluster.go Outdated
Auth pb.AuthClient
}

// copyTLSFiles clones certs files to dst directory.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

util_test.go or some other test file for these copy functions since they're not used by the integration package outside of tests?

@gyuho gyuho force-pushed the certs branch 3 times, most recently from 059044f to 4aa95cd Compare April 27, 2017 20:13
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
@heyitsanthony
Copy link
Copy Markdown

lgtm

@gyuho gyuho merged commit 747993d into etcd-io:master Apr 27, 2017
@gyuho gyuho deleted the certs branch April 27, 2017 21:36
@gyuho gyuho mentioned this pull request Nov 1, 2017
14 tasks
clwluvw added a commit to clwluvw/grafana-plugin-sdk-go that referenced this pull request Nov 14, 2025
Setting golang's tls config.GetClientCertificate will let us pass
a func that could read the certificate and key file on every req.
This is useful for when using mTLS and the certificate is rotated
so we can let the rotation be done without needing of restarting
the app.

e.g. etcd implementation: etcd-io/etcd#7829

Signed-off-by: Seena Fallah <seenafallah@gmail.com>
clwluvw added a commit to clwluvw/grafana-plugin-sdk-go that referenced this pull request Nov 14, 2025
Setting golang's tls config.GetClientCertificate will let us pass
a func that could read the certificate and key file on every req.
This is useful for when using mTLS and the certificate is rotated
so we can let the rotation be done without needing of restarting
the app.

e.g. etcd implementation: etcd-io/etcd#7829

Signed-off-by: Seena Fallah <seenafallah@gmail.com>
clwluvw added a commit to clwluvw/grafana-plugin-sdk-go that referenced this pull request Nov 14, 2025
Expose tls.Config.GetClientCertificate to allow supplying a callback
that loads the client certificate and key on each request. This enables
mTLS setups where certificates are rotated automatically without
restarting the application.

Inspired by the etcd approach: etcd-io/etcd#7829

Signed-off-by: Seena Fallah <seenafallah@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants