agent

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package agent implements the railgrid agent that connects edges to the hub.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentConfigPath

func AgentConfigPath(edgeName string) (string, error)

AgentConfigPath returns the path for the per-edge agent config file. Default location: ~/.railgrid/agent-<edgeName>.json

func AgentConfigPathForHome

func AgentConfigPathForHome(home, edgeName string) string

AgentConfigPathForHome returns the per-edge config path under home. It is used by installers that provision a service for a different local account (for example a root-installed launchd daemon running as a worker user).

func AgentKubeconfigPath

func AgentKubeconfigPath(edgeName string) (string, error)

AgentKubeconfigPath returns the path for the per-edge agent kubeconfig file. Default location: ~/.railgrid/agent-<edgeName>.kubeconfig

func AgentKubeconfigPathForHome

func AgentKubeconfigPathForHome(home, edgeName string) string

AgentKubeconfigPathForHome returns the per-edge kubeconfig path under home. See AgentConfigPathForHome for why installers need this variant.

func AgentKubeconfigSecretName

func AgentKubeconfigSecretName(edgeName string) string

AgentKubeconfigSecretName returns the name of the Secret used to persist the hub kubeconfig for the given edge when running in-cluster.

func DeleteAgentKubeconfig

func DeleteAgentKubeconfig(edgeName string) error

DeleteAgentKubeconfig removes a previously saved agent kubeconfig from disk.

func IsInCluster

func IsInCluster() bool

IsInCluster returns true when the process is running inside a Kubernetes Pod.

func LoadAgentKubeconfig

func LoadAgentKubeconfig(edgeName string) (string, error)

LoadAgentKubeconfig reads a previously saved agent kubeconfig from disk. Returns an empty string without error if the file does not exist yet.

func LoadKubeconfigFromSecret

func LoadKubeconfigFromSecret(edgeName string) (string, error)

LoadKubeconfigFromSecret reads the hub kubeconfig from the in-cluster Secret. Returns ("", nil) when the Secret does not exist yet (first boot before token exchange).

func SaveAgentConfig

func SaveAgentConfig(edgeName, hubURL, token string) error

SaveAgentConfig persists the durable agent token to disk so the agent can reconnect without the bootstrap join token after the first successful auth.

func SaveAgentConfigAt

func SaveAgentConfigAt(path string, cfg AgentConfig) error

SaveAgentConfigAt writes a persisted agent config at path with owner-only permissions. Callers that install for another account should chown the file to that account after this function returns.

func SaveAgentConfigWithCluster

func SaveAgentConfigWithCluster(edgeName, hubURL, token, cluster string) error

SaveAgentConfigWithCluster persists a durable agent token and its explicit kcp cluster context. The legacy SaveAgentConfig helper remains available for callers that do not need an explicit cluster.

func SaveAgentKubeconfig

func SaveAgentKubeconfig(edgeName, kubeconfigB64 string) error

SaveAgentKubeconfig decodes the base64-encoded kubeconfig returned by the hub (via X-Railgrid-Agent-Kubeconfig header) and persists it to disk so the agent can reconnect without the bootstrap join token after the first successful auth.

func SaveKubeconfigToSecret

func SaveKubeconfigToSecret(edgeName, kubeconfigData string) error

SaveKubeconfigToSecret writes the hub kubeconfig to the in-cluster Secret so that it survives a pod restart.

func ValidateAgentKubeconfig

func ValidateAgentKubeconfig(kubeconfigPath string, insecureSkipTLS bool) error

ValidateAgentKubeconfig checks whether the saved kubeconfig still has valid credentials by attempting a lightweight API call. Returns an error only if authentication definitively fails (401 Unauthorized — token revoked, e.g. after Edge recreation). All other errors (403 Forbidden, timeouts, network errors) return nil because they don't prove the token is invalid — the hub may be temporarily unreachable or the RBAC may not permit the probe call. When insecureSkipTLS is true, TLS certificate verification is disabled.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent is the railgrid agent that connects an edge to the hub.

func New

func New(opts *Options) (*Agent, error)

New creates a new agent.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context) error

Run starts the agent and blocks until the context is cancelled.

type AgentConfig

type AgentConfig struct {
	HubURL  string `json:"hubURL"`
	Token   string `json:"token"`
	Cluster string `json:"cluster,omitempty"`
}

AgentConfig holds the locally persisted agent configuration. It is written to disk after the first successful join-token authentication so that the agent can reconnect on restart without needing the bootstrap join token again.

func LoadAgentConfig

func LoadAgentConfig(edgeName string) (*AgentConfig, error)

LoadAgentConfig reads a previously saved agent config from disk. Returns nil without error if the config file does not exist yet.

type AgentType

type AgentType string

AgentType discriminates which connectable resource the agent registers and serves through the hub. Host agents share the same tunnel and Service path; only LinuxServer exposes the optional SSH bridge.

const (
	// AgentTypeKubernetes connects a Kubernetes cluster (registers a KubernetesCluster).
	AgentTypeKubernetes AgentType = "kubernetes"
	// AgentTypeServer connects a bare-metal Linux host via SSH
	// (registers a LinuxServer).
	AgentTypeServer AgentType = "server"
	// AgentTypeMacOS connects a macOS host as a service-only edge. It registers
	// a MacOSServer and deliberately does not probe, generate, or upload SSH
	// credentials.
	AgentTypeMacOS AgentType = "macos"
)

type Options

type Options struct {
	HubURL        string
	HubKubeconfig string
	HubContext    string
	TunnelURL     string // Separate URL for reverse tunnel (defaults to hubConfig.Host)
	Token         string
	EdgeName      string
	Kubeconfig    string
	Context       string
	Labels        map[string]string
	// Type controls whether the agent registers as a Kubernetes, Linux server,
	// or macOS service edge. Defaults to AgentTypeKubernetes.
	Type AgentType
	// InsecureSkipTLSVerify disables TLS certificate verification for the hub
	// connection. Should only be used in development/testing; never in production.
	InsecureSkipTLSVerify bool
	// SSHProxyPort is the local port of the SSH daemon the agent proxies to.
	// Defaults to 22; override in tests to avoid conflicts with the host sshd.
	SSHProxyPort int
	// SSHUser is the SSH username to authenticate as on server-type edges.
	// Defaults to the current user if not set.
	SSHUser string
	// SSHPassword is the SSH password for password-based authentication.
	// Prefer SSHPrivateKeyPath for better security.
	SSHPassword string
	// SSHPrivateKeyPath is the path to an SSH private key file for key-based auth.
	SSHPrivateKeyPath string
	// Cluster is the kcp logical cluster path (e.g., "root:railgrid:user-default").
	// If not set, it's extracted from the SA token (for kubeconfig-based auth)
	// or defaults to "default" (for static token auth).
	Cluster string
	// UsingSavedKubeconfig is set to true when the agent loaded a saved
	// kubeconfig from a previous join-token registration. When true, edge
	// registration is skipped (the edge was already registered).
	UsingSavedKubeconfig bool
	// DebugAddr, if non-empty, is the bind address for the agent's debug
	// HTTP server. It exposes /healthz and the standard /debug/pprof/*
	// endpoints. Use "127.0.0.1:6060" for local-only access; bind to a
	// non-loopback address only when port-forwarding is not an option.
	DebugAddr string
	// SvcAllowedCIDRs are the CIDRs (e.g. "192.168.1.0/24") the /svc proxy may
	// dial besides loopback and, in kubernetes mode, cluster-DNS names. A
	// Service's spec.host outside this set is refused (or warned about, per
	// SvcPolicy). Link-local, unspecified and multicast addresses are never
	// dialable even if listed. Flag: --svc-allow-cidr (repeatable); env:
	// RAILGRID_AGENT_SVC_ALLOW_CIDR (comma-separated).
	SvcAllowedCIDRs []string
	// SvcPolicy is what the /svc proxy does with a target outside the allowed
	// set: "enforce" (403, never dialed), "warn" (dialed, logged, response
	// carries X-Railgrid-Svc-Policy: warn) or "allow-any" (allow list disabled,
	// logged at startup). Defaults to "warn" in this release; the next release
	// flips the default to "enforce". Flag: --svc-policy; env: RAILGRID_AGENT_SVC_POLICY.
	SvcPolicy string
}

Options holds configuration for the agent.

func NewOptions

func NewOptions() *Options

NewOptions returns default agent options.

Directories

Path Synopsis
Package discovery detects HTTP services running on the edge host next to the agent (e.g.
Package discovery detects HTTP services running on the edge host next to the agent (e.g.
Package reconciler reconciles workloads on the agent side: it watches the edge's Placements in the tenant workspace and materializes each as a local Deployment.
Package reconciler reconciles workloads on the agent side: it watches the edge's Placements in the tenant workspace and materializes each as a local Deployment.
Package status reports agent status back to the hub.
Package status reports agent status back to the hub.
Package tunnel implements reverse-dial tunneling between agent and hub.
Package tunnel implements reverse-dial tunneling between agent and hub.

Jump to

Keyboard shortcuts

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