Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v12] Validate proxy peer identity #23506

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
151 changes: 0 additions & 151 deletions lib/proxy/peer/auth.go

This file was deleted.

23 changes: 15 additions & 8 deletions lib/proxy/peer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type ClientConfig struct {
// GracefulShutdownTimout is used set the graceful shutdown
// duration limit.
GracefulShutdownTimeout time.Duration
// ClusterName is the name of the cluster.
ClusterName string

// getConfigForServer updates the client tls config.
// configurable for testing purposes.
Expand Down Expand Up @@ -124,6 +126,10 @@ func (c *ClientConfig) checkAndSetDefaults() error {
return trace.BadParameter("missing access cache")
}

if c.ClusterName == "" {
return trace.BadParameter("missing cluster name")
}

if c.TLSConfig == nil {
return trace.BadParameter("missing tls config")
}
Expand All @@ -137,7 +143,7 @@ func (c *ClientConfig) checkAndSetDefaults() error {
}

if c.getConfigForServer == nil {
c.getConfigForServer = getConfigForServer(c.TLSConfig, c.AccessPoint, c.Log)
c.getConfigForServer = getConfigForServer(c.TLSConfig, c.AccessPoint, c.Log, c.ClusterName)
}

return nil
Expand Down Expand Up @@ -552,7 +558,7 @@ func (c *Client) getConnections(proxyIDs []string) ([]*clientConn, bool, error)
}

// connect dials a new connection to proxyAddr.
func (c *Client) connect(id string, proxyPeerAddr string) (*clientConn, error) {
func (c *Client) connect(peerID string, peerAddr string) (*clientConn, error) {
tlsConfig, err := c.config.getConfigForServer()
if err != nil {
return nil, trace.Wrap(err, "Error updating client tls config")
Expand All @@ -561,11 +567,12 @@ func (c *Client) connect(id string, proxyPeerAddr string) (*clientConn, error) {
connCtx, cancel := context.WithCancel(c.ctx)
wg := new(sync.WaitGroup)

transportCreds := newProxyCredentials(credentials.NewTLS(tlsConfig))
expectedPeer := auth.HostFQDN(peerID, c.config.ClusterName)

conn, err := grpc.DialContext(
connCtx,
proxyPeerAddr,
grpc.WithTransportCredentials(transportCreds),
peerAddr,
grpc.WithTransportCredentials(newClientCredentials(expectedPeer, peerAddr, c.config.Log, credentials.NewTLS(tlsConfig))),
grpc.WithStatsHandler(newStatsHandler(c.reporter)),
grpc.WithChainStreamInterceptor(metadata.StreamClientInterceptor, utils.GRPCClientStreamErrorInterceptor, streamCounterInterceptor(wg)),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Expand All @@ -577,16 +584,16 @@ func (c *Client) connect(id string, proxyPeerAddr string) (*clientConn, error) {
)
if err != nil {
cancel()
return nil, trace.Wrap(err, "Error dialing proxy %+v", id)
return nil, trace.Wrap(err, "Error dialing proxy %q", peerID)
}

return &clientConn{
ClientConn: conn,
ctx: connCtx,
cancel: cancel,
wg: wg,
id: id,
addr: proxyPeerAddr,
id: peerID,
addr: peerAddr,
}, nil
}

Expand Down