Skip to content

fix(BRE2-766): Backoff on ssh Attempt During Registration#307

Merged
drewmalin merged 5 commits intomainfrom
dm/sshretry
Mar 4, 2026
Merged

fix(BRE2-766): Backoff on ssh Attempt During Registration#307
drewmalin merged 5 commits intomainfrom
dm/sshretry

Conversation

@drewmalin
Copy link
Contributor

@drewmalin drewmalin commented Mar 4, 2026

Example output for inline enable (during register):

Registering your device with Brev

  Name:         dmvm
  Organization: dm
  Registering for Linux user:   dmalin

This will perform the following steps:
  1. Set up Brev tunnel
  2. Collect hardware profile
  3. Register this machine with Brev

✔ Yes, proceed

[Step 1/3] Setting up Brev tunnel...
  Brev tunnel ready.

[Step 2/3] Collecting hardware profile...

  Hardware profile:
    CPU:     14 cores
    RAM:     15.7 GB
    Arch:    amd64
    OS:      Ubuntu 25.10
    Storage: 0.0 GB (SSD)
    Storage: 0.0 GB (SSD)
    Storage: 0.0 GB (SSD)
    Storage: 0.0 GB (SSD)
    Storage: 15.7 GB (SSD)
    Storage: 0.4 GB (HDD)
    Storage: 8192.0 GB (HDD)
    Storage: 1.0 GB (HDD)


[Step 3/3] Registering with Brev...
  Registration complete.
✔ Yes, proceed

Enabling SSH access on this device

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

  Brev public key added to authorized_keys.
  SSH access not yet granted; retrying in: 1s...
  SSH access not yet granted; retrying in: 2s...
  SSH access not yet granted; retrying in: 3s...
  SSH access not yet granted; retrying in: 3.5s...
SSH access enabled. You can now SSH to this device via: brev shell dmvm

Example output during explicit enable-ssh (post register):

Enabling SSH access on this device

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

  Brev public key added to authorized_keys.
  SSH access not yet granted; retrying in: 1.5s...
  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

@drewmalin drewmalin requested a review from a team as a code owner March 4, 2026 02:17
Copilot AI review requested due to automatic review settings March 4, 2026 02:17
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 exponential backoff retry behavior when enabling SSH access during device registration, and refines authorized_keys handling to avoid unnecessary writes.

Changes:

  • Retry GrantSSHAccessToNode using exponential backoff rather than a single fixed-delay retry.
  • Adjust InstallAuthorizedKey to return whether it wrote a new entry, and suppress duplicate “added” messaging.
  • Add github.com/cenkalti/backoff/v4 dependency and update tests for the new InstallAuthorizedKey signature.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkg/cmd/register/sshkeys.go Adds transient/permanent error branching for rollback behavior; changes InstallAuthorizedKey to return (bool, error).
pkg/cmd/register/register.go Replaces single retry with exponential backoff retry and adds backoff configuration helpers/constants.
pkg/cmd/enablessh/enablessh_test.go Updates tests to match the new InstallAuthorizedKey return signature.
go.mod Adds backoff dependency.
go.sum Adds backoff checksums.

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

Comment on lines +50 to 52
} else if added {
t.Vprint(" Brev public key added to authorized_keys.")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly so that we don't keep (incorrectly) printing that we added keys -- InstallAuthorizedKey already no-ops if it can.

Comment on lines -45 to -53
_, err := client.GrantNodeSSHAccess(ctx, connect.NewRequest(&nodev1.GrantNodeSSHAccessRequest{
ExternalNodeId: reg.ExternalNodeID,
UserId: targetUser.ID,
LinuxUser: osUser.Username,
}))
if err != nil {
if targetUser.PublicKey != "" {
if rerr := RemoveAuthorizedKey(osUser, targetUser.PublicKey); rerr != nil {
t.Vprintf(" %s\n", t.Yellow(fmt.Sprintf("Warning: failed to remove SSH key after failed grant: %v", rerr)))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main change here -- wrap this logic in a backoff. This function is the one called by register, enable ssh, and grant ssh.

@drewmalin drewmalin changed the title backoff on ssh attempt during registration fix(BRE2-766): Backoff on ssh Attempt During Registration Mar 4, 2026
@drewmalin drewmalin merged commit 8cbe47b into main Mar 4, 2026
9 checks passed
@drewmalin drewmalin deleted the dm/sshretry branch March 4, 2026 19:53
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.

3 participants