register

package
v0.6.322 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

Package register provides the brev register command for device registration

Index

Constants

View Source
const BrevKeyPrefix = "# brev-cli"

BrevKeyPrefix is the marker prefix appended to every SSH key that Brev installs. Both old-format ("# brev-cli") and new-format ("# brev-cli user_id=xxx") keys start with this prefix.

Variables

This section is empty.

Functions

func BrevKeyTag added in v0.6.318

func BrevKeyTag(userID string) string

BrevKeyTag returns a comment tag that encodes the Brev user ID. Example: "# brev-cli user_id=user_abc123"

func ClearTestSSHPort added in v0.6.318

func ClearTestSSHPort()

ClearTestSSHPort clears the test port override.

func FormatHardwareProfile added in v0.6.318

func FormatHardwareProfile(s *HardwareProfile) string

FormatHardwareProfile returns a human-readable summary of the hardware profile.

func InstallAuthorizedKey added in v0.6.318

func InstallAuthorizedKey(u *user.User, pubKey string, brevUserID string) (bool, error)

InstallAuthorizedKey appends the given public key to the user's ~/.ssh/authorized_keys if it isn't already present. The key is tagged with a brev-cli comment (including the user ID) so it can be identified and removed later by RemoveBrevAuthorizedKeys or ListBrevAuthorizedKeys. Returns true if the key was newly written, false if it was already present.

func InstallNetbird added in v0.6.318

func InstallNetbird() error

InstallNetbird installs NetBird if it is not already present.

func NewCmdRegister

func NewCmdRegister(t *terminal.Terminal, store RegisterStore) *cobra.Command

func NewNodeServiceClient added in v0.6.318

func NewNodeServiceClient(provider externalnode.TokenProvider, baseURL string) nodev1connect.ExternalNodeServiceClient

NewNodeServiceClient creates a ConnectRPC ExternalNodeServiceClient using the given token provider for authentication.

func OpenSSHPort added in v0.6.319

func OpenSSHPort(
	ctx context.Context,
	t *terminal.Terminal,
	nodeClients externalnode.NodeClientFactory,
	tokenProvider externalnode.TokenProvider,
	reg *DeviceRegistration,
	port int32,
) error

OpenSSHPort calls the OpenPort RPC to allocate an SSH port on the node. This must be called before GrantSSHAccessToNode when enabling SSH for the first time on a device. The call is idempotent — if the port is already open, the server returns the existing allocation.

func PromptSSHPort added in v0.6.318

func PromptSSHPort(t *terminal.Terminal) (int32, error)

PromptSSHPort prompts the user for the target SSH port, defaulting to 22 if they press Enter or leave it empty. Re-prompts on invalid input until a valid port is provided. Only returns an error for unrecoverable I/O failures.

func RemoveAuthorizedKey added in v0.6.318

func RemoveAuthorizedKey(u *user.User, pubKey string) error

RemoveAuthorizedKey removes a specific public key from the user's ~/.ssh/authorized_keys. It matches the key content regardless of whether the brev-cli comment tag is present.

func RemoveAuthorizedKeyLine added in v0.6.318

func RemoveAuthorizedKeyLine(u *user.User, line string) error

RemoveAuthorizedKeyLine removes an exact line from authorized_keys.

func RemoveBrevAuthorizedKeys added in v0.6.318

func RemoveBrevAuthorizedKeys(u *user.User) ([]string, error)

RemoveBrevAuthorizedKeys removes all SSH keys tagged with the brev-cli comment from the user's ~/.ssh/authorized_keys. It returns the lines that were removed so callers can report what was cleaned up.

func SelectNodeFromList added in v0.6.320

func SelectNodeFromList(ctx context.Context, t *terminal.Terminal, prompter terminal.Selector, registrationStore RegistrationStore, nodes []*nodev1.ExternalNode) (*nodev1.ExternalNode, error)

SelectNodeFromList prompts the user to select a node from the list, then fetches and returns the full node. When this machine is registered, that node is marked " — this node" in the list. Call this after ListNodes when in interactive mode (same pattern as SelectOrganizationInteractive).

func SetTestSSHPort added in v0.6.318

func SetTestSSHPort(port int32)

SetTestSSHPort sets the port returned by PromptSSHPort without prompting. Only for use in tests; call ClearTestSSHPort when done.

func SetupAndRegisterNodeSSHAccess added in v0.6.320

func SetupAndRegisterNodeSSHAccess(
	ctx context.Context,
	t *terminal.Terminal,
	nodeClients externalnode.NodeClientFactory,
	tokenProvider externalnode.TokenProvider,
	reg *DeviceRegistration,
	targetUser *entity.User,
	linuxUsername string,
) error

SetupAndRegisterNodeSSHAccess installs the user's public key in authorized_keys and calls GrantNodeSSHAccess to record access server-side. If the RPC fails, the installed key is rolled back. osUser is the target username on the remote device (e.g. "ubuntu"), used both in the RPC and to locate the correct ~/.ssh/authorized_keys for local key installation.

func UninstallNetbird added in v0.6.318

func UninstallNetbird() error

UninstallNetbird stops, uninstalls the service, and removes the NetBird package or binary. It reads /etc/netbird/install.conf (written by the install script) to determine the original installation method. The down/stop steps are best-effort since the service may already be disconnected or stopped after deregistration.

Types

type BrevAuthorizedKey added in v0.6.318

type BrevAuthorizedKey struct {
	Line       string // full line from authorized_keys
	KeyContent string // the ssh key portion (without the brev comment)
	UserID     string // parsed from "user_id=xxx", empty for old-format keys
}

BrevAuthorizedKey represents a single Brev-managed key found in authorized_keys.

func ListBrevAuthorizedKeys added in v0.6.318

func ListBrevAuthorizedKeys(u *user.User) ([]BrevAuthorizedKey, error)

ListBrevAuthorizedKeys reads ~/.ssh/authorized_keys and returns all lines containing the BrevKeyPrefix marker.

type DefaultNodeClientFactory added in v0.6.318

type DefaultNodeClientFactory struct{}

DefaultNodeClientFactory creates real ConnectRPC clients.

func (DefaultNodeClientFactory) NewNodeClient added in v0.6.318

type DeviceRegistration added in v0.6.318

type DeviceRegistration struct {
	ExternalNodeID  string          `json:"external_node_id"`
	DisplayName     string          `json:"display_name"`
	OrgID           string          `json:"org_id"`
	OrgName         string          `json:"org_name"`
	DeviceID        string          `json:"device_id"`
	RegisteredAt    string          `json:"registered_at"`
	HardwareProfile HardwareProfile `json:"hardware_profile"`
}

DeviceRegistration is the persistent identity file for a registered device. Fields align with the AddNodeResponse from dev-plane.

type FileRegistrationStore added in v0.6.318

type FileRegistrationStore struct{}

FileRegistrationStore implements RegistrationStore using the global /etc/brev/ path.

func NewFileRegistrationStore added in v0.6.318

func NewFileRegistrationStore() *FileRegistrationStore

NewFileRegistrationStore returns a FileRegistrationStore that reads/writes from /etc/brev/device_registration.json.

func (*FileRegistrationStore) Delete added in v0.6.318

func (s *FileRegistrationStore) Delete() error

func (*FileRegistrationStore) Exists added in v0.6.318

func (s *FileRegistrationStore) Exists() (bool, error)

func (*FileRegistrationStore) Load added in v0.6.318

Load reads the registration file and returns the parsed DeviceRegistration

func (*FileRegistrationStore) Save added in v0.6.318

type GPU added in v0.6.318

type GPU struct {
	Model        string `json:"model"`
	Architecture string `json:"architecture,omitempty"`
	Count        int32  `json:"count"`
	MemoryBytes  *int64 `json:"memory_bytes,omitempty"`
}

GPU describes a group of identical GPUs on the system.

type HardwareProfile added in v0.6.318

type HardwareProfile struct {
	GPUs          []GPU           `json:"gpus"`
	RAMBytes      *int64          `json:"ram_bytes,omitempty"`
	CPUCount      *int32          `json:"cpu_count,omitempty"`
	Architecture  string          `json:"architecture,omitempty"`
	Storage       []StorageDevice `json:"storage,omitempty"`
	OS            string          `json:"os,omitempty"`
	OSVersion     string          `json:"os_version,omitempty"`
	ProductName   string          `json:"product_name,omitempty"`
	Interconnects []Interconnect  `json:"interconnects,omitempty"`
}

HardwareProfile is the full hardware snapshot collected by a HardwareProfiler.

type HardwareProfiler added in v0.6.318

type HardwareProfiler interface {
	Profile() (*HardwareProfile, error)
}

HardwareProfiler abstracts system hardware detection so it can be replaced in tests and implemented per-platform via build tags.

type Interconnect added in v0.6.318

type Interconnect struct {
	Type        string `json:"type"`
	Device      string `json:"device"`
	ActiveLinks int    `json:"active_links,omitempty"`
	Version     uint32 `json:"version,omitempty"`
	Generation  int    `json:"generation,omitempty"`
	Width       int    `json:"width,omitempty"`
}

Interconnect describes a GPU interconnect (NVLink, PCIe, etc.).

type LinuxPlatform added in v0.6.318

type LinuxPlatform struct{}

LinuxPlatform reports compatibility based on whether the OS is Linux.

func (LinuxPlatform) IsCompatible added in v0.6.318

func (LinuxPlatform) IsCompatible() bool

type NetBirdManager added in v0.6.318

type NetBirdManager interface {
	Install() error
	Uninstall() error
	// EnsureRunning checks whether the NetBird service is active and
	// connected, starting or reconnecting it if needed. Returns nil when
	// the tunnel is healthy.
	EnsureRunning() error
}

NetBirdManager installs, uninstalls, and monitors the NetBird network agent.

type Netbird added in v0.6.318

type Netbird struct{}

Netbird handles NetBird installation and uninstallation.

func (Netbird) EnsureRunning added in v0.6.318

func (Netbird) EnsureRunning() error

EnsureRunning checks if the netbird systemd service is active and attempts to start it if it is not. It also checks the netbird peer connection status and runs "netbird up" if the peer is disconnected.

func (Netbird) Install added in v0.6.318

func (Netbird) Install() error

func (Netbird) Uninstall added in v0.6.318

func (Netbird) Uninstall() error

type RegisterStore added in v0.6.318

type RegisterStore interface {
	GetCurrentUser() (*entity.User, error)
	GetActiveOrganizationOrDefault() (*entity.Organization, error)
	GetOrganizationsByName(name string) ([]entity.Organization, error)
	ListOrganizations() ([]entity.Organization, error)
	GetAccessToken() (string, error)
}

RegisterStore defines the store methods needed by the register command.

type RegistrationStore added in v0.6.318

type RegistrationStore interface {
	Save(reg *DeviceRegistration) error
	Load() (*DeviceRegistration, error)
	Delete() error
	Exists() (bool, error)
}

RegistrationStore defines the contract for persisting device registration data.

type SetupRunner added in v0.6.318

type SetupRunner interface {
	RunSetup(script string) error
}

SetupRunner runs a setup script on the local machine.

type ShellSetupRunner added in v0.6.318

type ShellSetupRunner struct{}

ShellSetupRunner runs setup scripts via shell.

func (ShellSetupRunner) RunSetup added in v0.6.318

func (ShellSetupRunner) RunSetup(script string) error

type StorageDevice added in v0.6.318

type StorageDevice struct {
	Name         string `json:"name,omitempty"`
	StorageBytes int64  `json:"storage_bytes"`
	StorageType  string `json:"storage_type,omitempty"` // "SSD", "HDD", or "NVMe"
}

StorageDevice represents a single block storage device.

type SystemHardwareProfiler added in v0.6.318

type SystemHardwareProfiler struct{}

SystemHardwareProfiler probes hardware on Linux using NVML, sysfs, and procfs.

func (*SystemHardwareProfiler) Profile added in v0.6.318

func (p *SystemHardwareProfiler) Profile() (*HardwareProfile, error)

type TerminalPrompter added in v0.6.318

type TerminalPrompter struct{}

TerminalPrompter wraps terminal.PromptSelectInput for interactive prompts.

func (TerminalPrompter) ConfirmYesNo added in v0.6.318

func (TerminalPrompter) ConfirmYesNo(label string) bool

func (TerminalPrompter) Select added in v0.6.318

func (TerminalPrompter) Select(label string, items []string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL