server

package
v0.83.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 95 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ManagementLegacyPort is the port that was used before by the Management gRPC server.
	// It is used for backward compatibility now.
	ManagementLegacyPort = 33073
	// DefaultSelfHostedDomain is the default domain used for self-hosted fresh installs.
	DefaultSelfHostedDomain = "netbird.selfhosted"

	ContainerKeyBaseServer = "baseServer"
)

Variables

This section is empty.

Functions

func Create

func Create[T any](s Server, createFunc func() T) T

Create a dependency and add it to the BaseServer's container. A string key identifier will be based on its type definition.

func CreateNamed

func CreateNamed[T any](s Server, name string, createFunc func() T) T

CreateNamed is the same as Create but will suffix the dependency string key identifier with a custom name. Useful if you want to have multiple named instances of the same object type.

func Inject

func Inject[T any](c Server, thing T)

Inject lets you override a specific service from outside the BaseServer itself. This is useful for tests

func InjectNamed

func InjectNamed[T any](c Server, name string, thing T)

InjectNamed is like Inject() but with a custom name.

Types

type BaseServer

type BaseServer struct {
	// Config holds the server configuration
	Config *nbconfig.Config

	lifecycle.StopHandlers
	// contains filtered or unexported fields
}

BaseServer holds the HTTP server instance. Add any additional fields you need, such as database connections, Config, etc.

func NewServer

func NewServer(cfg *Config) *BaseServer

NewServer initializes and configures a new Server instance

func (*BaseServer) APIHandler

func (s *BaseServer) APIHandler() http.Handler

func (*BaseServer) AccessLogDBConn added in v0.82.0

func (s *BaseServer) AccessLogDBConn() *db.Conn

func (*BaseServer) AccessLogsManager added in v0.65.0

func (s *BaseServer) AccessLogsManager() accesslogs.Manager

func (*BaseServer) AccountManager

func (s *BaseServer) AccountManager() account.Manager

func (*BaseServer) AccountRequestBuffer added in v0.59.13

func (s *BaseServer) AccountRequestBuffer() *server.AccountRequestBuffer

func (*BaseServer) AfterInit

func (s *BaseServer) AfterInit(fn func(s *BaseServer))

func (*BaseServer) AgentNetworkManager added in v0.74.0

func (s *BaseServer) AgentNetworkManager() agentnetwork.Manager

func (*BaseServer) ApiRouter added in v0.81.0

func (s *BaseServer) ApiRouter() *mux.Router

ApiRouter returns the subrouter for the unversioned API under apiPrefix.

func (*BaseServer) ApiV1Router added in v0.81.0

func (s *BaseServer) ApiV1Router() *mux.Router

ApiV1Router returns the subrouter for the versioned API under apiV1Prefix.

func (*BaseServer) AuthManager

func (s *BaseServer) AuthManager() auth.Manager

func (*BaseServer) CacheStore added in v0.69.0

func (s *BaseServer) CacheStore() nbcache.Store

CacheStore returns a shared cache store backed by Redis or in-memory depending on the environment. All consumers should reuse this store to avoid creating multiple Redis connections.

func (*BaseServer) DBConn added in v0.81.0

func (s *BaseServer) DBConn() *db.Conn

DBConn opens the database connection shared by the store and the domain repositories.

func (*BaseServer) DNSDomain added in v0.60.5

func (s *BaseServer) DNSDomain() string

func (*BaseServer) EphemeralManager

func (s *BaseServer) EphemeralManager() ephemeral.Manager

func (*BaseServer) Errors

func (s *BaseServer) Errors() <-chan error

Done returns a channel that is closed when the server stops

func (*BaseServer) EventStore

func (s *BaseServer) EventStore() activity.Store

func (*BaseServer) GRPCServer

func (s *BaseServer) GRPCServer() *grpc.Server

func (*BaseServer) GeoLocationManager

func (s *BaseServer) GeoLocationManager() geolocation.Geolocation

func (*BaseServer) GetContainer

func (s *BaseServer) GetContainer(key string) (any, bool)

GetContainer retrieves a dependency from the BaseServer's container by its key

func (*BaseServer) GroupsManager

func (s *BaseServer) GroupsManager() groups.Manager

func (*BaseServer) IDPHandler added in v0.72.0

func (s *BaseServer) IDPHandler() http.Handler

IDPHandler returns the HTTP handler for the embedded IdP (Dex), or nil if the deployment isn't using the embedded variant.

func (*BaseServer) IdpManager

func (s *BaseServer) IdpManager() idp.Manager

func (*BaseServer) IntegratedValidator

func (s *BaseServer) IntegratedValidator() integrated_validator.IntegratedValidator

func (*BaseServer) JobManager added in v0.64.0

func (s *BaseServer) JobManager() *job.Manager

func (*BaseServer) MCPBroker added in v0.83.0

func (s *BaseServer) MCPBroker() *mcpapi.Broker

MCPBroker is management's OAuth authorization server for MCP clients. It is nil when the MCP endpoint is off or no PKCE flow is configured to log users in with.

func (*BaseServer) ManagementGRPCServer added in v0.83.0

func (s *BaseServer) ManagementGRPCServer() *nbgrpc.Server

ManagementGRPCServer returns the management gRPC service, created once and served by GRPCServer.

func (*BaseServer) Metrics

func (s *BaseServer) Metrics() telemetry.AppMetrics

func (*BaseServer) NetworkMapController added in v0.59.13

func (s *BaseServer) NetworkMapController() network_map.Controller

func (*BaseServer) NetworkMapReplicaPool added in v0.82.0

func (s *BaseServer) NetworkMapReplicaPool() *pgxpool.Pool

NetworkMapReplicaPool opens the pgx pool to the Postgres read replica serving network map data reads. It is nil unless the store engine is Postgres and networkmapdbfactory.ReplicaDsnEnv is set.

func (*BaseServer) NetworkMapStore added in v0.78.0

func (s *BaseServer) NetworkMapStore() *networkmapdb.NetworkMapDBStoreImpl

TODO dmitri: move all validation checks (e.g. config+env vars) from runtime to base server creation this way we don't need to spread defensive checks throughout the codebase

func (*BaseServer) NetworksManager

func (s *BaseServer) NetworksManager() networks.Manager

func (*BaseServer) OAuthConfigProvider added in v0.62.0

func (s *BaseServer) OAuthConfigProvider() idp.OAuthConfigProvider

OAuthConfigProvider is only relevant when we have an embedded IdP service. Otherwise must be nil

func (*BaseServer) PeerLiveness added in v0.83.0

func (s *BaseServer) PeerLiveness() peerliveness.Controller

func (*BaseServer) PeersManager

func (s *BaseServer) PeersManager() peers.Manager

func (*BaseServer) PeersUpdateManager

func (s *BaseServer) PeersUpdateManager() network_map.PeersUpdateManager

func (*BaseServer) PermissionsManager

func (s *BaseServer) PermissionsManager() permissions.Manager

func (*BaseServer) ProxyActivityManager added in v0.77.0

func (s *BaseServer) ProxyActivityManager() proxyactivity.Manager

ProxyActivityManager records reverse proxy usage for activity accounting.

func (*BaseServer) ProxyManager added in v0.66.2

func (s *BaseServer) ProxyManager() proxy.Manager

func (*BaseServer) ProxyTokenStore added in v0.65.0

func (s *BaseServer) ProxyTokenStore() *nbgrpc.OneTimeTokenStore

func (*BaseServer) RateLimiter added in v0.70.0

func (s *BaseServer) RateLimiter() *ratelimit.APIRateLimiter

func (*BaseServer) RecordsManager added in v0.63.0

func (s *BaseServer) RecordsManager() records.Manager

func (*BaseServer) RegisterGRPCExtension added in v0.76.2

func (s *BaseServer) RegisterGRPCExtension(ext GRPCExtension)

RegisterGRPCExtension registers a gRPC extension. Call before the gRPC server is first built (i.e. before Start); registrations after that have no effect.

func (*BaseServer) ResolveDomains added in v0.72.0

func (s *BaseServer) ResolveDomains(ctx context.Context)

ResolveDomains determines dnsDomain and mgmtSingleAccModeDomain based on store state. Fresh installs use the default self-hosted domain, while existing installs reuse the persisted account domain to keep addressing stable across config changes.

func (*BaseServer) ResourcesManager

func (s *BaseServer) ResourcesManager() resources.Manager

func (*BaseServer) ReverseProxyDomainManager added in v0.65.0

func (s *BaseServer) ReverseProxyDomainManager() *manager.Manager

func (*BaseServer) ReverseProxyGRPCServer added in v0.65.0

func (s *BaseServer) ReverseProxyGRPCServer() *nbgrpc.ProxyServiceServer

func (*BaseServer) Router added in v0.72.0

func (s *BaseServer) Router() *mux.Router

Router returns the root HTTP router with the shared API middleware applied. With the MCP OAuth broker running, a challenge sits ahead of that middleware, since only a wrapper outside the auth middleware can add the RFC 9728 pointer to its 401, and the auth middleware also accepts the broker's tokens on the MCP endpoint.

func (*BaseServer) RoutesManager

func (s *BaseServer) RoutesManager() routers.Manager

func (*BaseServer) SecretsManager

func (s *BaseServer) SecretsManager() grpc.SecretsManager

func (*BaseServer) ServiceManager added in v0.66.2

func (s *BaseServer) ServiceManager() service.Manager

func (*BaseServer) ServiceProxyController added in v0.66.2

func (s *BaseServer) ServiceProxyController() proxy.Controller

func (*BaseServer) SessionStore added in v0.70.3

func (s *BaseServer) SessionStore() *auth.SessionStore

func (*BaseServer) SetContainer

func (s *BaseServer) SetContainer(key string, container any)

SetContainer stores a dependency in the BaseServer's container with the specified key

func (*BaseServer) SetHandlerFunc added in v0.65.0

func (s *BaseServer) SetHandlerFunc(handler http.Handler)

SetHandlerFunc allows overriding the default HTTP handler function. This is useful for multiplexing additional services on the same port.

func (*BaseServer) SettingsManager

func (s *BaseServer) SettingsManager() settings.Manager

func (*BaseServer) SingleUseStore added in v0.81.0

func (s *BaseServer) SingleUseStore() *nbgrpc.SingleUseStore

func (*BaseServer) Start

func (s *BaseServer) Start(ctx context.Context) error

Start begins listening for HTTP requests on the configured address

func (*BaseServer) Stop

func (s *BaseServer) Stop() error

Stop attempts a graceful shutdown within shutdownTimeout. Releasing the peer liveness instance may use the budget left after stopping the services and gRPC streams, except for shutdownCloseReserve, which stays for closing the stores; the extension hooks leave shutdownIdPReserve for stopping the embedded IdP. It returns an error when the instance could not be released or the shutdown ran out of time.

func (*BaseServer) Store

func (s *BaseServer) Store() store.Store

func (*BaseServer) UsersManager

func (s *BaseServer) UsersManager() users.Manager

func (*BaseServer) ZonesManager added in v0.63.0

func (s *BaseServer) ZonesManager() zones.Manager

type Config added in v0.65.2

type Config struct {
	NbConfig                    *nbconfig.Config
	DNSDomain                   string
	MgmtSingleAccModeDomain     string
	MgmtPort                    int
	MgmtMetricsPort             int
	DisableLegacyManagementPort bool
	DisableMetrics              bool
	DisableGeoliteUpdate        bool
	UserDeleteFromIDPEnabled    bool
	AutoResolveDomains          bool
	TLSConfig                   *tls.Config
	// LetsEncryptListenAddress is the separate Let's Encrypt challenge listener
	// used when MgmtPort is not 443. Empty disables it.
	LetsEncryptListenAddress string
}

Config holds the configuration parameters for creating a new server

type GRPCExtension added in v0.76.2

type GRPCExtension struct {
	// Register is invoked with the shared grpc.Server (as a ServiceRegistrar)
	// after the built-in services are registered. It may register any number of
	// services. May be nil.
	Register func(grpc.ServiceRegistrar)
	// UnaryInterceptors are appended to the server's unary interceptor chain,
	// running after the built-in interceptors. May be empty.
	UnaryInterceptors []grpc.UnaryServerInterceptor
	// StreamInterceptors are appended to the server's stream interceptor chain,
	// running after the built-in interceptors. May be empty.
	StreamInterceptors []grpc.StreamServerInterceptor
	// Shutdown, if non-nil, is called once during Stop() with the context
	// governing server shutdown, which carries a deadline. The hook MUST
	// return promptly and MUST abandon its work once that context is
	// cancelled or expires: it runs before the rest of Stop()'s cleanup
	// (store, event store, embedded IdP) and before Stop() itself checks the
	// context's deadline, so a hook that ignores the context will delay all
	// of that cleanup and prevent Stop() from returning on time. May be nil.
	Shutdown func(ctx context.Context)
}

GRPCExtension bundles an external module's contribution to the management gRPC server: the registration of one or more services onto the shared grpc.Server, any server-wide interceptors those services require, and an optional shutdown hook. It is a generic extension point with no knowledge of any specific service.

type Server

type Server interface {
	Start(ctx context.Context) error
	Stop() error
	Errors() <-chan error
	GetContainer(key string) (any, bool)
	SetContainer(key string, container any)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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