Documentation
¶
Index ¶
- Variables
- func BuildHTTPClient(caFile string, insecure bool) (*http.Client, error)
- func EncodeToken(packageID, downloadToken, coreAPIURL string) (string, error)
- func EnrollAgentFromToken(ctx context.Context, opts EnrollOptions) error
- func EnrollCollectorFromToken(ctx context.Context, opts CollectorEnrollOptions) error
- func GenerateCollectorPermissions(namespace, collectorType string) (publishAllow, subscribeAllow []string)
- func GenerateNATSConfig(cfg *NATSServerConfig) ([]byte, error)
- func Rotate(ctx context.Context, storagePath string, log logger.Logger) error
- type Bootstrapper
- func (b *Bootstrapper) Bootstrap(ctx context.Context) error
- func (b *Bootstrapper) GetAllConfigs() map[string][]byte
- func (b *Bootstrapper) GetConfig(key string) ([]byte, bool)
- func (b *Bootstrapper) GetCoreEndpoint() string
- func (b *Bootstrapper) GetGatewayEndpoint() string
- func (b *Bootstrapper) GetJoinToken() string
- func (b *Bootstrapper) GetKVEndpoint() string
- func (b *Bootstrapper) GetPackage() *models.EdgeOnboardingPackage
- func (b *Bootstrapper) GetSPIFFEID() string
- type CollectorCredsConfig
- type CollectorEnrollOptions
- type Config
- type DeploymentType
- type EnrollOptions
- type NATSBootstrapFiles
- type NATSBootstrapRequest
- type NATSServerConfig
- type RotationInfo
Constants ¶
This section is empty.
Variables ¶
var ( ErrBundleDownloadFailed = errors.New("bundle download failed") ErrConfigAlreadyExists = errors.New("config already exists") ErrCertsAlreadyExist = errors.New("certs already exist") ErrBundleMissingConfig = errors.New("bundle missing config.json") ErrBundleMissingCerts = errors.New("bundle missing certificate files") ErrCoreAPIHostRequired = errors.New("core API host is required") )
var ( // ErrConfigRequired is returned when no config is provided. ErrConfigRequired = errors.New("config is required") // ErrTokenRequired is returned when no onboarding token is provided. ErrTokenRequired = errors.New("onboarding token is required") // ErrTokenOrPackageRequired is returned when neither token nor package path are provided. ErrTokenOrPackageRequired = errors.New("onboarding token or package archive is required") // ErrCredentialRotationNotImplemented is returned when credential rotation is attempted. ErrCredentialRotationNotImplemented = errors.New("not implemented: credential rotation") // ErrRotationInfoNotImplemented is returned when rotation info is requested. ErrRotationInfoNotImplemented = errors.New("not implemented: rotation info") )
var ( ErrCollectorTokenInvalid = errors.New("collector token is invalid") ErrCollectorTokenExpired = errors.New("collector token is expired") ErrCollectorBundleDownloadFailed = errors.New("collector bundle download failed") ErrCollectorBundleIncomplete = errors.New("collector bundle is incomplete") ErrCollectorConfigExists = errors.New("collector config already exists") ErrCollectorCertsExist = errors.New("collector certs already exist") ErrCollectorCredsExist = errors.New("collector creds already exist") )
var ( // ErrUnsupportedComponentType is returned when an unknown component type is encountered. ErrUnsupportedComponentType = errors.New("unsupported component type") // ErrCoreAddressNotFound is returned when core_address is missing from metadata. ErrCoreAddressNotFound = errors.New("core_address not found in metadata") // ErrCoreSPIFFEIDNotFound is returned when core_spiffe_id is missing from metadata. ErrCoreSPIFFEIDNotFound = errors.New("core_spiffe_id not found in metadata") // ErrSPIREUpstreamAddressNotFound is returned when spire_upstream_address is missing from metadata. ErrSPIREUpstreamAddressNotFound = errors.New("spire_upstream_address not found in metadata") // ErrSPIREParentIDNotFound is returned when spire_parent_id is missing from metadata. ErrSPIREParentIDNotFound = errors.New("spire_parent_id not found in metadata") // ErrAgentSPIFFEIDNotFound is returned when agent_spiffe_id is missing from metadata. ErrAgentSPIFFEIDNotFound = errors.New("agent_spiffe_id not found in metadata") // ErrSPIREUpstreamPortNotFound is returned when spire_upstream_port is missing from metadata. ErrSPIREUpstreamPortNotFound = errors.New("spire_upstream_port not found in metadata") // ErrGatewayIDNotFound is returned when gateway_id is missing from metadata. ErrGatewayIDNotFound = errors.New("gateway_id not found in metadata") // ErrKVAddressNotFound is returned when kv_address is missing from metadata. ErrKVAddressNotFound = errors.New("kv_address not found in metadata") // ErrKVSPIFFEIDNotFound is returned when kv_spiffe_id is missing from metadata. ErrKVSPIFFEIDNotFound = errors.New("kv_spiffe_id not found in metadata") // ErrAgentIDNotFound is returned when agent_id is missing from metadata. ErrAgentIDNotFound = errors.New("agent_id not found in metadata") // ErrGatewayAddrRequired is returned when gateway_addr is missing for agent/sync bootstrap config. ErrGatewayAddrRequired = errors.New("gateway_addr is required to generate bootstrap config") )
var ( // ErrPackageNotDownloaded is returned when package validation is attempted before download. ErrPackageNotDownloaded = errors.New("package not downloaded") // ErrDownloadResultNotAvailable is returned when download result is missing. ErrDownloadResultNotAvailable = errors.New("download result not available") // ErrPackageIDEmpty is returned when package_id is empty. ErrPackageIDEmpty = errors.New("package_id is empty") // ErrComponentIDEmpty is returned when component_id is empty. ErrComponentIDEmpty = errors.New("component_id is empty") // ErrComponentTypeNotSet is returned when component_type is not set. ErrComponentTypeNotSet = errors.New("component_type is not set") // ErrDownstreamSPIFFEIDEmpty is returned when downstream_spiffe_id is empty. ErrDownstreamSPIFFEIDEmpty = errors.New("downstream_spiffe_id is empty") // ErrJoinTokenEmpty is returned when join token is empty. ErrJoinTokenEmpty = errors.New("join token is empty") // ErrBundlePEMEmpty is returned when bundle PEM is empty. ErrBundlePEMEmpty = errors.New("bundle PEM is empty") // ErrDownloadTokenEmpty is returned when the download token segment is missing. ErrDownloadTokenEmpty = errors.New("download token is empty") // ErrCoreAPIURLRequired is returned when the Core API URL cannot be determined. ErrCoreAPIURLRequired = errors.New("core API URL is required") // ErrPackageRevoked is returned when package has been revoked. ErrPackageRevoked = errors.New("package has been revoked") // ErrPackageExpired is returned when package has expired. ErrPackageExpired = errors.New("package has expired") // ErrPackageDeleted is returned when package has been deleted. ErrPackageDeleted = errors.New("package has been deleted") // ErrPackageNotDelivered is returned when package is still in issued state. ErrPackageNotDelivered = errors.New("package has not been delivered yet") // ErrPackageArchiveMissingMetadata is returned when metadata.json is missing from archived package. ErrPackageArchiveMissingMetadata = errors.New("package archive missing metadata.json") // ErrPackageArchiveMissingJoinToken is returned when the archive is missing the join token. ErrPackageArchiveMissingJoinToken = errors.New("package archive missing SPIRE join token") // ErrPackageArchiveMissingBundle is returned when the archive is missing the SPIRE trust bundle. ErrPackageArchiveMissingBundle = errors.New("package archive missing SPIRE trust bundle") // ErrPackageArchiveInvalid is returned when the archive is malformed. ErrPackageArchiveInvalid = errors.New("package archive invalid") // ErrCoreDeliverEndpoint indicates the Core deliver endpoint returned an error. ErrCoreDeliverEndpoint = errors.New("core deliver endpoint error") // ErrCoreAPIURLMissingHost indicates the base URL lacks a host. ErrCoreAPIURLMissingHost = errors.New("core api url missing host") )
var ( // ErrOperatorJWTRequired is returned when no operator JWT is provided for config generation. ErrOperatorJWTRequired = errors.New("operator JWT is required") // ErrSystemAccountPublicKeyRequired is returned when no system account public key is provided. ErrSystemAccountPublicKeyRequired = errors.New("system account public key is required") )
var ( // ErrSPIREAddressResolutionNotImplemented is returned when SPIRE address resolution is attempted. ErrSPIREAddressResolutionNotImplemented = errors.New("not implemented: SPIRE address resolution") )
Functions ¶
func BuildHTTPClient ¶ added in v1.0.85
BuildHTTPClient returns a client configured for optional TLS overrides.
func EncodeToken ¶
EncodeToken builds an edgepkg-v1 token that embeds the package id, download token, and optional Core API base URL so bootstrap clients only need ONBOARDING_TOKEN.
func EnrollAgentFromToken ¶ added in v1.0.85
func EnrollAgentFromToken(ctx context.Context, opts EnrollOptions) error
EnrollAgentFromToken downloads an edge onboarding bundle and writes agent config + certs.
func EnrollCollectorFromToken ¶ added in v1.0.85
func EnrollCollectorFromToken(ctx context.Context, opts CollectorEnrollOptions) error
EnrollCollectorFromToken downloads a collector bundle and installs config/creds/certs.
func GenerateCollectorPermissions ¶ added in v1.0.79
func GenerateCollectorPermissions(namespace, collectorType string) (publishAllow, subscribeAllow []string)
GenerateCollectorPermissions returns NATS permissions for a specific collector type.
func GenerateNATSConfig ¶ added in v1.0.79
func GenerateNATSConfig(cfg *NATSServerConfig) ([]byte, error)
GenerateNATSConfig generates a nats-server configuration file.
Types ¶
type Bootstrapper ¶
type Bootstrapper struct {
// contains filtered or unexported fields
}
Bootstrapper handles the complete onboarding flow for edge services.
func NewBootstrapper ¶
func NewBootstrapper(cfg *Config) (*Bootstrapper, error)
NewBootstrapper creates a new bootstrapper instance.
For SaaS mode, only GatewayEndpoint is required - agents receive all configuration dynamically via GetConfig after connecting. For legacy/on-prem mode, KVEndpoint may still be used.
func (*Bootstrapper) Bootstrap ¶
func (b *Bootstrapper) Bootstrap(ctx context.Context) error
Bootstrap executes the complete onboarding process. Steps: 1. Download package from Core using token 2. Validate and extract package contents 3. Configure SPIRE (nested server for gateway, workload API for others) 4. Auto-register with Core via database (update edge_packages table) 5. Generate service config based on deployment type 6. Set up credential rotation 7. Return ready-to-use config
func (*Bootstrapper) GetAllConfigs ¶
func (b *Bootstrapper) GetAllConfigs() map[string][]byte
GetAllConfigs returns all generated configuration files.
func (*Bootstrapper) GetConfig ¶
func (b *Bootstrapper) GetConfig(key string) ([]byte, bool)
GetConfig returns the generated configuration for a specific file/key.
func (*Bootstrapper) GetCoreEndpoint ¶
func (b *Bootstrapper) GetCoreEndpoint() string
GetCoreEndpoint returns the Core service endpoint (legacy/on-prem use).
func (*Bootstrapper) GetGatewayEndpoint ¶ added in v1.0.79
func (b *Bootstrapper) GetGatewayEndpoint() string
GetGatewayEndpoint returns the Gateway service endpoint (primary for SaaS mode).
func (*Bootstrapper) GetJoinToken ¶
func (b *Bootstrapper) GetJoinToken() string
GetJoinToken returns the SPIRE join token (only available before SPIRE is configured).
func (*Bootstrapper) GetKVEndpoint ¶
func (b *Bootstrapper) GetKVEndpoint() string
GetKVEndpoint returns the KV service endpoint (legacy/on-prem use). In SaaS mode, agents receive config from gateway via GetConfig instead.
func (*Bootstrapper) GetPackage ¶
func (b *Bootstrapper) GetPackage() *models.EdgeOnboardingPackage
GetPackage returns the downloaded package information.
func (*Bootstrapper) GetSPIFFEID ¶
func (b *Bootstrapper) GetSPIFFEID() string
GetSPIFFEID returns the assigned SPIFFE ID for this service.
type CollectorCredsConfig ¶ added in v1.0.79
type CollectorCredsConfig struct {
// Namespace is the namespace for subject prefixing
Namespace string
// CollectorType is the type of collector (flowgger, trapd, netflow, otel)
CollectorType string
// UserName is the NATS user name
UserName string
// CredsContent is the .creds file content
CredsContent string
// ConfigContent is the collector-specific configuration
ConfigContent string
}
CollectorCredsConfig contains parameters for generating collector NATS credentials.
type CollectorEnrollOptions ¶ added in v1.0.85
type CollectorEnrollOptions struct {
Token string
BaseURL string
ConfigDir string
ConfigFile string
CertsDir string
CredsDir string
HTTPClient *http.Client
Logf func(string, ...interface{})
SkipOverwrite bool
}
CollectorEnrollOptions controls collector enrollment.
type Config ¶
type Config struct {
// Token is the onboarding/download token from the package
Token string
// GatewayEndpoint is the agent-gateway gRPC endpoint (required for SaaS mode)
// Format: "host:port" e.g., "agent-gateway:50052"
// This is the only required endpoint - all config is delivered via GetConfig.
GatewayEndpoint string
// CoreEndpoint is the Core service gRPC endpoint (optional: legacy/on-prem use)
// Format: "host:port" e.g., "23.138.124.18:50052"
CoreEndpoint string
// KVEndpoint is the KV service (datasvc) gRPC endpoint (optional: legacy/on-prem use)
// In SaaS mode, agents get configuration from gateway via GetConfig.
// Format: "host:port" e.g., "23.138.124.23:50057"
KVEndpoint string
// CoreAPIURL is the HTTP(S) endpoint for the Core API (e.g., https://serviceradar.local)
// If empty, the token payload or environment variables may provide it.
CoreAPIURL string
// PackagePath points to a pre-downloaded onboarding archive (tar.gz) for offline installs.
// When set, Token/CoreAPIURL are optional and the archive is used instead of contacting Core.
PackagePath string
// PackageID optionally overrides the package identifier when the token format does not embed it.
PackageID string
// ServiceType identifies what type of service is being onboarded
ServiceType models.EdgeOnboardingComponentType
// ServiceID is an optional readable name override for the service
// If not provided, will use the component_id from the package
ServiceID string
// StoragePath is where to persist configuration and credentials
// Default: "/var/lib/serviceradar" or "./data" for non-root
StoragePath string
// DeploymentType specifies the deployment environment
// Values: "docker", "kubernetes", "bare-metal"
// If empty, will auto-detect
DeploymentType DeploymentType
// HTTPClient allows callers to override the HTTP client used for Core API requests.
HTTPClient *http.Client
// Logger is optional; if nil, a default logger will be created
Logger logger.Logger
}
Config contains all parameters needed for edge service onboarding. This is the client-side configuration for edge services (gateway, agent, checker; sync uses agent bootstrap config) to bootstrap themselves from an onboarding token.
## Minimal Bootstrap Configuration
Per the SaaS connectivity spec, the on-disk bootstrap config only needs: - GatewayEndpoint: Where to connect - mTLS credentials: For authentication
All monitoring configuration (checks, schedules, etc.) is delivered dynamically via GetConfig after the agent connects to the gateway.
type DeploymentType ¶
type DeploymentType string
DeploymentType represents the environment where the service is running.
const ( DeploymentTypeDocker DeploymentType = "docker" DeploymentTypeKubernetes DeploymentType = "kubernetes" DeploymentTypeBareMetal DeploymentType = "bare-metal" )
type EnrollOptions ¶ added in v1.0.85
type EnrollOptions struct {
Token string
CoreHost string
HostIP string
ConfigPath string
CertDir string
HTTPClient *http.Client
Logf func(string, ...interface{})
Errorf func(string, ...interface{})
SkipOverwrite bool
}
EnrollOptions controls the agent enrollment workflow.
type NATSBootstrapFiles ¶ added in v1.0.79
type NATSBootstrapFiles struct {
// ConfigFile is the nats.conf content
ConfigFile []byte
// OperatorJWT is the operator JWT content
OperatorJWT []byte
// SystemAccountJWT is the system account JWT content
SystemAccountJWT []byte
// OperatorSeed is the operator seed (sensitive - only for initial setup)
OperatorSeed string
// SystemAccountSeed is the system account seed (sensitive - only for initial setup)
SystemAccountSeed string
}
NATSBootstrapFiles represents the files generated during NATS bootstrap.
type NATSBootstrapRequest ¶ added in v1.0.79
type NATSBootstrapRequest struct {
// OperatorName is the name for the NATS operator
OperatorName string
// ExistingOperatorSeed allows importing an existing operator seed
ExistingOperatorSeed string
// GenerateSystemAccount indicates whether to generate a system account
GenerateSystemAccount bool
// ConfigOverrides allows customizing the generated configuration
ConfigOverrides *NATSServerConfig
}
NATSBootstrapRequest contains parameters for bootstrapping a NATS server.
type NATSServerConfig ¶ added in v1.0.79
type NATSServerConfig struct {
// ServerName is the name of the NATS server instance
ServerName string
// ListenPort is the main client connection port (default: 4222)
ListenPort int
// OperatorJWTPath is the path to the operator JWT file
OperatorJWTPath string
// SystemAccountPublicKey is the public key of the system account
SystemAccountPublicKey string
// ResolverDir is the directory where the JWT resolver stores account JWTs
ResolverDir string
// TLSEnabled enables TLS for client connections
TLSEnabled bool
// TLSCertPath is the path to the server certificate
TLSCertPath string
// TLSKeyPath is the path to the server private key
TLSKeyPath string
// TLSCAPath is the path to the CA certificate for client verification
TLSCAPath string
// TLSVerify enables mutual TLS (client certificate verification)
TLSVerify bool
// JetStreamEnabled enables JetStream for persistence
JetStreamEnabled bool
// JetStreamStoreDir is the directory for JetStream storage
JetStreamStoreDir string
// JetStreamMaxMemory is the maximum memory for JetStream (in bytes, 0 = default)
JetStreamMaxMemory int64
// JetStreamMaxFile is the maximum file storage for JetStream (in bytes, 0 = default)
JetStreamMaxFile int64
// ClusterEnabled enables NATS clustering
ClusterEnabled bool
// ClusterName is the name of the NATS cluster
ClusterName string
// ClusterPort is the port for cluster communication
ClusterPort int
// ClusterRoutes are the routes to other cluster members
ClusterRoutes []string
// LeafNodeEnabled enables leaf node connections
LeafNodeEnabled bool
// LeafNodePort is the port for leaf node connections
LeafNodePort int
// HTTPMonitorPort is the port for the HTTP monitoring endpoint (0 = disabled)
HTTPMonitorPort int
// LogFile is the path to the log file (empty = stdout)
LogFile string
// Debug enables debug logging
Debug bool
// Trace enables trace logging
Trace bool
// MaxPayload is the maximum message payload size (default: 1MB)
MaxPayload int
// PingInterval is the interval for client pings (in seconds)
PingInterval int
// MaxPingsOut is the maximum outstanding pings before disconnect
MaxPingsOut int
}
NATSServerConfig contains parameters for generating nats-server configuration.
func DefaultNATSServerConfig ¶ added in v1.0.79
func DefaultNATSServerConfig() *NATSServerConfig
DefaultNATSServerConfig returns a NATSServerConfig with sensible defaults.
type RotationInfo ¶
type RotationInfo struct {
LastRotation time.Time
NextRotation time.Time
RotationCount int64
Healthy bool
Error string
}
RotationInfo contains information about credential rotation status.
func GetRotationInfo ¶
func GetRotationInfo(storagePath string) (*RotationInfo, error)
GetRotationInfo returns the current rotation status.