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

Use serverUID for web scp target #23124

Merged
merged 7 commits into from
Mar 15, 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
14 changes: 3 additions & 11 deletions lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ func PlayFile(ctx context.Context, tarFile io.Reader, sid string) error {

// ExecuteSCP executes SCP command. It executes scp.Command using
// lower-level API integrations that mimic SCP CLI command behavior
func (tc *TeleportClient) ExecuteSCP(ctx context.Context, cmd scp.Command) (err error) {
func (tc *TeleportClient) ExecuteSCP(ctx context.Context, serverAddr string, cmd scp.Command) error {
ctx, span := tc.Tracer.Start(
ctx,
"teleportClient/ExecuteSCP",
Expand All @@ -1874,19 +1874,11 @@ func (tc *TeleportClient) ExecuteSCP(ctx context.Context, cmd scp.Command) (err
}
defer proxyClient.Close()

// which nodes are we executing this commands on?
nodeAddrs, err := tc.getTargetNodes(ctx, proxyClient)
if err != nil {
return trace.Wrap(err)
}
if len(nodeAddrs) == 0 {
return trace.BadParameter("no target host specified")
}

nodeClient, err := tc.ConnectToNode(
ctx,
proxyClient,
NodeDetails{Addr: nodeAddrs[0], Namespace: tc.Namespace, Cluster: tc.SiteName},
// We append the ":0" to tell the server to figure out the port for us.
NodeDetails{Addr: serverAddr + ":0", Namespace: tc.Namespace, Cluster: tc.SiteName},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I'm not sure what the :0 is or why it's necessary. Once you figure it out, a comment is probably warranted.

Copy link
Contributor Author

@avatus avatus Mar 15, 2023

Choose a reason for hiding this comment

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

Add a comment!

tc.Config.HostLogin,
)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions lib/web/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// fileTransferRequest describes HTTP file transfer request
type fileTransferRequest struct {
// Server describes a server to connect to (serverId|hostname[:port]).
server string
serverID string
// Login is Linux username to connect as.
login string
// Namespace is node namespace.
Expand All @@ -51,7 +51,7 @@ func (h *Handler) transferFile(w http.ResponseWriter, r *http.Request, p httprou
req := fileTransferRequest{
cluster: site.GetName(),
login: p.ByName("login"),
server: p.ByName("server"),
serverID: p.ByName("server"),
remoteLocation: query.Get("location"),
filename: query.Get("filename"),
namespace: defaults.Namespace,
Expand Down Expand Up @@ -106,7 +106,7 @@ func (f *fileTransfer) download(req fileTransferRequest, httpReq *http.Request,
return trace.Wrap(err)
}

err = tc.ExecuteSCP(httpReq.Context(), cmd)
err = tc.ExecuteSCP(httpReq.Context(), req.serverID, cmd)
if err != nil {
return trace.Wrap(err)
}
Expand All @@ -130,7 +130,7 @@ func (f *fileTransfer) upload(req fileTransferRequest, httpReq *http.Request) er
return trace.Wrap(err)
}

err = tc.ExecuteSCP(httpReq.Context(), cmd)
err = tc.ExecuteSCP(httpReq.Context(), req.serverID, cmd)
if err != nil {
return trace.Wrap(err)
}
Expand All @@ -152,9 +152,9 @@ func (f *fileTransfer) createClient(req fileTransferRequest, httpReq *http.Reque
return nil, trace.Wrap(err)
}

hostName, hostPort, err := resolveServerHostPort(req.server, servers)
hostName, hostPort, err := resolveServerHostPort(req.serverID, servers)
if err != nil {
return nil, trace.BadParameter("invalid server name %q: %v", req.server, err)
return nil, trace.BadParameter("invalid server name %q: %v", req.serverID, err)
}

cfg, err := makeTeleportClientConfig(httpReq.Context(), f.ctx)
Expand Down