Skip to content

Commit

Permalink
fix: changes to work correctly with ClusterClient
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy committed Apr 5, 2023
1 parent e8c8bda commit be99cb6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
35 changes: 14 additions & 21 deletions lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1501,15 +1501,26 @@ func (tc *TeleportClient) ConnectToNode(ctx context.Context, clt *ClusterClient,
directCtx, directCancel := context.WithCancel(ctx)
mfaCtx, mfaCancel := context.WithCancel(ctx)
go func() {
ctx, span := tc.Tracer.Start(
directCtx,
"teleportClient/connectToNode",
oteltrace.WithSpanKind(oteltrace.SpanKindClient),
oteltrace.WithAttributes(
attribute.String("cluster", nodeDetails.Cluster),
attribute.String("node", node),
),
)
defer span.End()

// try connecting to the node with the certs we already have
// try connecting to the node
conn, details, err := clt.ProxyClient.DialHost(directCtx, nodeDetails.Addr, nodeDetails.Cluster, tc.localAgent.ExtendedAgent)
conn, details, err := clt.ProxyClient.DialHost(ctx, nodeDetails.Addr, nodeDetails.Cluster, tc.localAgent.ExtendedAgent)
if err != nil {
directResultC <- clientRes{err: err}
return
}

sshConfig := clt.ProxyClient.SSHConfig(user)
clt, err := NewNodeClient(directCtx, sshConfig, conn, nodeDetails.ProxyFormat(), nodeDetails.Addr, tc, details.FIPS)
clt, err := NewNodeClient(ctx, sshConfig, conn, nodeDetails.ProxyFormat(), nodeDetails.Addr, tc, details.FIPS)
directResultC <- clientRes{clt: clt, err: err}
}()

Expand Down Expand Up @@ -1617,24 +1628,6 @@ func (tc *TeleportClient) connectToNodeWithMFA(ctx context.Context, clt *Cluster
return nil, trace.Wrap(MFARequiredUnknown(trace.AccessDenied("no access to %s", nodeDetails.Addr)))
}

check, err := clt.AuthClient.IsMFARequired(ctx, &proto.IsMFARequiredRequest{
Target: &proto.IsMFARequiredRequest_Node{
Node: &proto.NodeLogin{
Node: node,
Login: tc.HostLogin,
},
},
})
if err != nil {
return nil, trace.Wrap(MFARequiredUnknown(err))
}

// per-session mfa isn't required, the user simply does not
// have access to the provided node
if !check.Required {
return nil, trace.Wrap(MFARequiredUnknown(trace.AccessDenied("no access to %s", nodeDetails.Addr)))
}

// per-session mfa is required, perform the mfa ceremony
cfg, err := clt.SessionSSHConfig(ctx, user, nodeDetails)
if err != nil {
Expand Down
9 changes: 2 additions & 7 deletions lib/client/cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ func (c *ClusterClient) SessionSSHConfig(ctx context.Context, user string, targe

key, err := c.tc.localAgent.GetKey(target.Cluster, WithAllCerts...)
if err != nil {
if trace.IsNotFound(err) {
// Either running inside the web UI in a proxy or using an identity
// file. Fall back to whatever AuthMethod we currently have.
return sshConfig, nil
}
return nil, trace.Wrap(err)
return nil, trace.Wrap(MFARequiredUnknown(err))
}

params := ReissueParams{
Expand All @@ -93,7 +88,7 @@ func (c *ClusterClient) SessionSSHConfig(ctx context.Context, user string, targe
if target.MFACheck == nil {
check, err := c.AuthClient.IsMFARequired(ctx, params.isMFARequiredRequest(c.tc.HostLogin))
if err != nil {
return nil, trace.Wrap(err)
return nil, trace.Wrap(MFARequiredUnknown(err))
}
target.MFACheck = check
}
Expand Down
1 change: 1 addition & 0 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3849,6 +3849,7 @@ func (process *TeleportProcess) initProxyEndpoint(conn *Connector) error {
}

tlscfg := serverTLSConfig.Clone()
setupTLSConfigClientCAsForCluster(tlscfg, accessPoint, clusterName)
tlscfg.ClientAuth = tls.RequireAndVerifyClientCert
if lib.IsInsecureDevMode() {
tlscfg.InsecureSkipVerify = true
Expand Down

0 comments on commit be99cb6

Please sign in to comment.