Documentation
¶
Overview ¶
Package register provides the brev register command for device registration
Index ¶
- Constants
- func BrevKeyTag(userID string) string
- func ClearTestSSHPort()
- func FormatHardwareProfile(s *HardwareProfile) string
- func GrantSSHAccessToNode(ctx context.Context, t *terminal.Terminal, ...) error
- func InstallAuthorizedKey(u *user.User, pubKey string, brevUserID string) (bool, error)
- func InstallNetbird() error
- func NewCmdRegister(t *terminal.Terminal, store RegisterStore) *cobra.Command
- func NewNodeServiceClient(provider externalnode.TokenProvider, baseURL string) nodev1connect.ExternalNodeServiceClient
- func OpenSSHPort(ctx context.Context, t *terminal.Terminal, ...) error
- func PromptSSHPort(t *terminal.Terminal) (int32, error)
- func RemoveAuthorizedKey(u *user.User, pubKey string) error
- func RemoveAuthorizedKeyLine(u *user.User, line string) error
- func RemoveBrevAuthorizedKeys(u *user.User) ([]string, error)
- func SetTestSSHPort(port int32)
- func UninstallNetbird() error
- type BrevAuthorizedKey
- type DefaultNodeClientFactory
- type DeviceRegistration
- type FileRegistrationStore
- type GPU
- type HardwareProfile
- type HardwareProfiler
- type Interconnect
- type LinuxPlatform
- type NetBirdManager
- type Netbird
- type RegisterStore
- type RegistrationStore
- type SetupRunner
- type ShellSetupRunner
- type StorageDevice
- type SystemHardwareProfiler
- type TerminalPrompter
Constants ¶
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
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 GrantSSHAccessToNode ¶ added in v0.6.318
func GrantSSHAccessToNode( ctx context.Context, t *terminal.Terminal, nodeClients externalnode.NodeClientFactory, tokenProvider externalnode.TokenProvider, reg *DeviceRegistration, targetUser *entity.User, osUser *user.User, ) error
GrantSSHAccessToNode 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.
func InstallAuthorizedKey ¶ added in v0.6.318
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
PromptSSHPort prompts the user for the target SSH port, defaulting to 22 if they press Enter or leave it empty. Returns an error for invalid port numbers.
func RemoveAuthorizedKey ¶ added in v0.6.318
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
RemoveAuthorizedKeyLine removes an exact line from authorized_keys.
func RemoveBrevAuthorizedKeys ¶ added in v0.6.318
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 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 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
func (DefaultNodeClientFactory) NewNodeClient(provider externalnode.TokenProvider, baseURL string) nodev1connect.ExternalNodeServiceClient
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"`
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
func (s *FileRegistrationStore) Load() (*DeviceRegistration, error)
Load reads the registration file and returns the parsed DeviceRegistration
func (*FileRegistrationStore) Save ¶ added in v0.6.318
func (s *FileRegistrationStore) Save(reg *DeviceRegistration) error
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
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.
type RegisterStore ¶ added in v0.6.318
type RegisterStore interface {
GetCurrentUser() (*entity.User, error)
GetActiveOrganizationOrDefault() (*entity.Organization, error)
GetOrganizationsByName(name string) ([]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
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