auth

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth provides netclient auth logic with server

Index

Constants

View Source
const DeviceHostIDHeader = "X-Host-ID"

DeviceHostIDHeader identifies the local host when authenticating with a user JWT.

Variables

View Source
var (

	// UserTokenProvider returns the active Desktop user JWT, or empty when
	// logged out. Wired from the desktop package to avoid an import cycle.
	UserTokenProvider func() string

	// EnsureUserSessionLoaded loads the persisted Desktop session into memory.
	// CLI commands run in a separate process from the daemon and must call this
	// before reading UserTokenProvider, or peer_info/ping auth fails with
	// ErrUserSessionRequired despite an active Desktop login on disk.
	EnsureUserSessionLoaded func()
)
View Source
var ErrMDMDenied = errors.New("device not enrolled or compliant in MDM")

ErrMDMDenied is returned (via wrapping) when the netmaker server refuses a request because the host is not enrolled or compliant in the configured MDM. Callers should detect it with errors.Is and surface MDMDeniedMessage to the operator instead of a generic transport error.

View Source
var ErrUserSessionRequired = errors.New("user session required for this device")

ErrUserSessionRequired is returned for user-owned devices when Desktop has no active user JWT. Host-password auth is not allowed for those devices.

Functions

func ApplyAPIHeaders added in v1.8.0

func ApplyAPIHeaders(headers http.Header, token string, host *config.Config)

ApplyAPIHeaders sets Authorization. X-Host-ID is always included when a host is known so user-JWT AuthorizeHost can bind the request to this device.

func AsMDMDenied added in v1.7.0

func AsMDMDenied(err error) error

AsMDMDenied returns a wrapped ErrMDMDenied when err carries the well-known MDM denial signature (HTTP 403 + message containing "mdm_posture"), and otherwise returns err unchanged. The original ErrStatusNotOk remains in the wrap chain so existing transport handling still works.

func Authenticate

func Authenticate(server *config.Server, host *config.Config) (string, error)

Authenticate authenticates with netmaker api to permit subsequent interactions with the api

func AuthenticateOnce added in v1.8.0

func AuthenticateOnce(server *config.Server, host *config.Config, timeout time.Duration) (string, error)

AuthenticateOnce is a single short attempt. Interactive disconnect uses it when the cached host JWT is missing, so a blackholed API cannot add another full retry budget before the node update itself.

func AuthenticateWithOptions added in v1.8.0

func AuthenticateWithOptions(server *config.Server, host *config.Config, opts AuthenticateOptions) (string, error)

AuthenticateWithOptions authenticates with optional control over 401 cleanup behavior.

func CleanJwtToken added in v0.30.0

func CleanJwtToken()

func IsMissingHostError added in v1.8.0

func IsMissingHostError(err error) bool

IsMissingHostError reports host authenticate failures where the server no longer has this device (deleted host, leftover enrollment after reinstall). The API returns HTTP 400 with "record not found", not 401.

func IsUserOwnedDevice added in v1.8.0

func IsUserOwnedDevice(host *config.Config) bool

IsUserOwnedDevice reports whether this host is bound to a Netmaker user (desktop/device registration).

func SetPendingUserToken added in v1.8.0

func SetPendingUserToken(token string)

SetPendingUserToken temporarily exposes a user JWT to Authenticate (login pull). Pass empty to clear.

Types

type AuthenticateOptions added in v1.8.0

type AuthenticateOptions struct {
	// CleanupOnUnauthorized removes local server registration on HTTP 401.
	// Desktop UI flows should set this false to avoid wiping servers.json on re-login.
	CleanupOnUnauthorized bool
}

AuthenticateOptions controls host authentication behavior.

Jump to

Keyboard shortcuts

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