Skip to content

feat(BRE2-797): Allow SSH Port to be Specified#311

Open
drewmalin wants to merge 3 commits intomainfrom
dm/sshport
Open

feat(BRE2-797): Allow SSH Port to be Specified#311
drewmalin wants to merge 3 commits intomainfrom
dm/sshport

Conversation

@drewmalin
Copy link
Contributor

@drewmalin drewmalin commented Mar 5, 2026

Specify:

Enabling SSH access on this device

  Node:       dmvm (extnode-3AVS2hsSEp50RAunnzsZta63737)
  Brev user:  user-33tX4k1ZsFFoISEzsxdlIkhpdCr
  Linux user: dmalin

  SSH port (default 22):  2222
  Brev public key added to authorized_keys.

Keep blank:

Enabling SSH access on this device

  Node:       dmvm (extnode-3AVSBym2IFR7isDgPWbPBiKcNmG)
  Brev user:  user-33tX4k1ZsFFoISEzsxdlIkhpdCr
  Linux user: dmalin

  SSH port (default 22):
  Brev public key added to authorized_keys.
  SSH access not yet granted; retrying in: 1s...
  SSH access not yet granted; retrying in: 1.5s...
  SSH access not yet granted; retrying in: 2.5s...
SSH access enabled. You can now SSH to this device via: brev shell dmvm

Copilot AI review requested due to automatic review settings March 5, 2026 01:20
@drewmalin drewmalin requested a review from a team as a code owner March 5, 2026 01:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for specifying a target SSH port during SSH access granting/enabling flows, and forwards that port to the server via the node RPC request.

Changes:

  • Prompt for an SSH port (defaulting to 22) in register, grant-ssh, and enable-ssh flows.
  • Extend GrantSSHAccessToNode / GrantNodeSSHAccessRequest to include the selected port.
  • Update tests to avoid blocking on interactive input and bump the generated devplane protos dependency.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/cmd/register/sshkeys.go Adds SSH port prompting + threads port into GrantNodeSSHAccessRequest.
pkg/cmd/register/register.go Prompts for SSH port and passes it to GrantSSHAccessToNode.
pkg/cmd/register/register_test.go Sets a fixed test port to prevent interactive prompts in affected tests.
pkg/cmd/grantssh/grantssh.go Prompts for SSH port and passes it to GrantSSHAccessToNode.
pkg/cmd/grantssh/grantssh_test.go Sets a fixed test port to prevent interactive prompts.
pkg/cmd/enablessh/enablessh.go Prompts for SSH port and passes it to GrantSSHAccessToNode.
go.mod Updates devplane protocolbuffers module version.
go.sum Updates sums for the bumped devplane protocolbuffers module.
Comments suppressed due to low confidence (3)

pkg/cmd/register/sshkeys.go:209

  • The new SSH port prompting logic relies on package-level mutable state (testSSHPort) and exported SetTestSSHPort/ClearTestSSHPort helpers to make tests non-interactive. This leaks a test-only control surface into production code and introduces hidden global state that can become flaky if tests (or commands) ever run in parallel. Consider injecting an input/port provider via existing deps/prompter patterns (or passing the port down from the command layer) so production code stays deterministic and tests don’t need globals/exported test hooks.
const defaultSSHPort = 22

// testSSHPort is set by tests to avoid blocking on stdin. When non-nil,
// PromptSSHPort returns this value without prompting.
var testSSHPort *int32

// SetTestSSHPort sets the port returned by PromptSSHPort without prompting.
// Only for use in tests; call ClearTestSSHPort when done.
func SetTestSSHPort(port int32) { testSSHPort = &port }

// ClearTestSSHPort clears the test port override.
func ClearTestSSHPort() { testSSHPort = nil }

pkg/cmd/register/sshkeys.go:232

  • PromptSSHPort hard-codes the default port value in multiple places (label/default string and defaultSSHPort constant). To avoid drift, reuse defaultSSHPort when building the prompt label/default. Also, strconv.ParseUint with bitSize=16 already constrains values to <= 65535, so the explicit upper-bound check is redundant (or switch to bitSize=32 and keep the range check).
	portStr := terminal.PromptGetInput(terminal.PromptContent{
		Label:      "  SSH port (default 22): ",
		Default:    "22",
		AllowEmpty: true,
	})
	portStr = strings.TrimSpace(portStr)
	if portStr == "" {
		return defaultSSHPort, nil
	}
	n, err := strconv.ParseUint(portStr, 10, 16)
	if err != nil {
		return 0, fmt.Errorf("invalid port %q: %w", portStr, err)
	}
	if n < 1 || n > 65535 {
		return 0, fmt.Errorf("port must be between 1 and 65535, got %d", n)
	}

pkg/cmd/register/sshkeys.go:169

  • The SSH port is now sent to the server via GrantNodeSSHAccessRequest.Port, but the updated tests only set a fixed port to avoid blocking; they don’t assert that the port value is actually propagated into the RPC request. Add an assertion in the existing register/grant-ssh flow tests (which already capture the request) that Port equals the chosen value to prevent regressions.
	opToTry := func() error {
		_, err := client.GrantNodeSSHAccess(ctx, connect.NewRequest(&nodev1.GrantNodeSSHAccessRequest{
			ExternalNodeId: reg.ExternalNodeID,
			UserId:         targetUser.ID,
			LinuxUser:      osUser.Username,
			Port:           port,
		}))

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@drewmalin drewmalin changed the title sshport feat(BRE2-797): Allow SSH Port to be Specified Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants