-
Notifications
You must be signed in to change notification settings - Fork 37
feat: Use Port IDs on Grant, Revoke SSH #397
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,9 @@ module github.com/brevdev/brev-cli | |
| go 1.25.0 | ||
|
|
||
| require ( | ||
| buf.build/gen/go/brevdev/devplane/connectrpc/go v1.19.1-20260228021043-887d38e1b474.2 | ||
| buf.build/gen/go/brevdev/devplane/protocolbuffers/go v1.36.11-20260309172248-8105d701fdce.1 | ||
| connectrpc.com/connect v1.19.1 | ||
| buf.build/gen/go/brevdev/devplane/connectrpc/go v1.19.2-20260520183101-9f4cb67aff2c.1 | ||
| buf.build/gen/go/brevdev/devplane/protocolbuffers/go v1.36.11-20260520183101-9f4cb67aff2c.1 | ||
|
Comment on lines
+6
to
+7
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will update once https://github.com/brevdev/dev-plane/pull/2182 is merged. |
||
| connectrpc.com/connect v1.19.2 | ||
| github.com/NVIDIA/go-nvml v0.13.0-1 | ||
| github.com/alessio/shellescape v1.4.1 | ||
| github.com/brevdev/parse v0.0.11 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,13 +33,15 @@ type enableSSHDeps struct { | |
| platform externalnode.PlatformChecker | ||
| nodeClients externalnode.NodeClientFactory | ||
| registrationStore register.RegistrationStore | ||
| prompter terminal.Selector | ||
| } | ||
|
|
||
| func defaultEnableSSHDeps() enableSSHDeps { | ||
| return enableSSHDeps{ | ||
| platform: register.LinuxPlatform{}, | ||
| nodeClients: register.DefaultNodeClientFactory{}, | ||
| registrationStore: register.NewFileRegistrationStore(), | ||
| prompter: register.TerminalPrompter{}, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -103,53 +105,39 @@ func enableSSH( | |
| t.Vprintf(" Linux user: %s\n", linuxUsername) | ||
| t.Vprint("") | ||
|
|
||
| // Check if the node already has an SSH port allocated (e.g. for another linux user) | ||
| port, err := existingSSHPort(ctx, deps, tokenProvider, reg) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a thing anymore. We now need to ask either: do you want to open a port, or do you want to use an existing port? |
||
| node, err := fetchRegisteredNode(ctx, deps, tokenProvider, reg) | ||
| if err != nil { | ||
| t.Vprintf(" %s\n", t.Yellow(fmt.Sprintf("Warning: could not check for existing ports: %v", err))) | ||
| return fmt.Errorf("enable SSH failed: %w", err) | ||
|
Comment on lines
-109
to
+110
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of these errors just ¯\(ツ)/¯ 'd before, so tightening them to immediately fail. |
||
| } | ||
|
|
||
| if port != 0 { | ||
| t.Vprintf(" Using existing SSH port %d.\n", port) | ||
| } else { | ||
| t.Vprint("") | ||
| port, err = register.PromptSSHPort(t) | ||
| if err != nil { | ||
| return fmt.Errorf("invalid SSH port: %w", err) | ||
| } | ||
|
|
||
| if err := register.OpenSSHPort(ctx, t, deps.nodeClients, tokenProvider, reg, port); err != nil { | ||
| return fmt.Errorf("enable SSH failed: %w", err) | ||
| } | ||
| brevPortID, err := register.ResolveSSHAccessPort(ctx, t, deps.prompter, deps.nodeClients, tokenProvider, reg, node) | ||
| if err != nil { | ||
| return fmt.Errorf("enable SSH failed: %w", err) | ||
| } | ||
|
|
||
| if err := register.SetupAndRegisterNodeSSHAccess(ctx, t, deps.nodeClients, tokenProvider, reg, brevUser, linuxUsername); err != nil { | ||
| if err := register.SetupAndRegisterNodeSSHAccess(ctx, t, deps.nodeClients, tokenProvider, reg, brevUser, linuxUsername, brevPortID); err != nil { | ||
| return fmt.Errorf("enable SSH failed: %w", err) | ||
| } | ||
|
|
||
| t.Vprint(t.Green(fmt.Sprintf("SSH access enabled. You can now SSH to this device via: brev shell %s", reg.DisplayName))) | ||
| return nil | ||
| } | ||
|
|
||
| // existingSSHPort calls GetNode and returns the PortNumber of an already-allocated | ||
| // SSH port, or 0 if none exists | ||
| func existingSSHPort(ctx context.Context, deps enableSSHDeps, tokenProvider externalnode.TokenProvider, reg *register.DeviceRegistration) (int32, error) { | ||
| func fetchRegisteredNode( | ||
| ctx context.Context, | ||
| deps enableSSHDeps, | ||
| tokenProvider externalnode.TokenProvider, | ||
| reg *register.DeviceRegistration, | ||
| ) (*nodev1.ExternalNode, error) { | ||
| client := deps.nodeClients.NewNodeClient(tokenProvider, config.GlobalConfig.GetBrevPublicAPIURL()) | ||
| resp, err := client.GetNode(ctx, connect.NewRequest(&nodev1.GetNodeRequest{ | ||
| ExternalNodeId: reg.ExternalNodeID, | ||
| OrganizationId: reg.OrgID, | ||
| })) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("error retrieving node: %w", err) | ||
| } | ||
|
|
||
| for _, p := range resp.Msg.GetExternalNode().GetPorts() { | ||
| // TODO if we ever allow more than one SSH port, this should be modified | ||
| if p.GetProtocol() == nodev1.PortProtocol_PORT_PROTOCOL_SSH { | ||
| return p.GetPortNumber(), nil | ||
| } | ||
|
Comment on lines
-148
to
-150
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core to this PR: this will now always return false, so there is no point in doing any of this checking for the SSH protocol. |
||
| return nil, fmt.Errorf("error retrieving node: %w", err) | ||
| } | ||
| return 0, nil | ||
| return resp.Msg.GetExternalNode(), nil | ||
| } | ||
|
|
||
| // checkSSHDaemon prints a warning if neither "ssh" nor "sshd" systemd services | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was failing to find the appropriate connect modules before.