fleet

package
v0.2.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package fleet manages the remote agents of the hub: the single-use tokens that let a new agent enroll, the registry of the agents that did, and the revocation of an agent. The certificates themselves come from package pki.

Index

Constants

View Source
const (
	EventTokenCreated  = "enroll_token_created"
	EventAgentEnrolled = "agent_enrolled"
	EventEnrollFailed  = "agent_enroll_failed"
	EventAgentRevoked  = "agent_revoked"
	EventAgentRenamed  = "agent_renamed"
)

Audit events recorded by the fleet.

View Source
const (
	// TokenTTL is how long an enrollment token can be used.
	TokenTTL = time.Hour
)

Variables

View Source
var (
	// ErrInvalidToken is the one answer for a token that is unknown, expired or
	// already used.
	ErrInvalidToken = errors.New("this enrollment token is invalid or has expired")
	ErrRateLimited  = errors.New("too many failed attempts, try again later")
	ErrNotFound     = errors.New("agent not found")
	// ErrRevoked is returned for an agent that was revoked, or whose
	// certificate is not the one the hub issued last.
	ErrRevoked = errors.New("this agent is revoked")
)

Errors returned by the service.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	ID         string
	Name       string
	Hostname   string
	Version    string
	OSVersion  string
	CreatedAt  time.Time
	EnrolledAt string    // the address it enrolled from
	LastSeen   time.Time // zero if it never connected
	Revoked    bool
	RevokedAt  time.Time
}

Agent is an enrolled agent.

type Auditor

type Auditor interface {
	Record(ctx context.Context, actor, event, target, detail string)
}

Auditor records events; *auth.Service implements it.

type Enrolled

type Enrolled struct {
	AgentID          string
	CertificateDER   []byte
	CACertificateDER []byte
}

Enrolled is the result of a successful enrollment.

type NameError

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

NameError is a problem with the name chosen for a server.

func (*NameError) Error

func (e *NameError) Error() string

type RequestError

type RequestError struct{ Err error }

RequestError is a problem with the certificate request of an agent.

func (*RequestError) Error

func (e *RequestError) Error() string

func (*RequestError) Unwrap

func (e *RequestError) Unwrap() error

type Service

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

Service is the registry of remote agents.

func New

func New(db *sql.DB, ca *pki.CA, audit Auditor) *Service

New returns the service. audit may be nil.

func (*Service) Agents

func (s *Service) Agents(ctx context.Context) ([]Agent, error)

Agents lists the enrolled agents, oldest first.

func (*Service) Authorize

func (s *Service) Authorize(ctx context.Context, id, serial string) error

Authorize checks that the agent may connect with the certificate that has this serial number: the agent exists, is not revoked, and the certificate is the one the hub issued for it.

func (*Service) CA

func (s *Service) CA() *pki.CA

CA returns the certificate authority, for the listener.

func (*Service) CreateToken

func (s *Service) CreateToken(ctx context.Context, by, name string) (token string, expires time.Time, err error)

CreateToken makes a single-use enrollment token, valid for TokenTTL. The name, if given, becomes the name of the server that enrolls with it. The token is returned once; only its hash is kept.

func (*Service) Enroll

func (s *Service) Enroll(ctx context.Context, remote, token string, csrDER []byte, hostname string) (Enrolled, error)

Enroll registers a new agent: it uses the token up and signs the agent's certificate request. remote is the address of the agent, for the limit on failed attempts and the audit log.

func (*Service) Rename

func (s *Service) Rename(ctx context.Context, by, id, name string) error

Rename sets the name shown for an agent; an empty name goes back to the host name.

func (*Service) Revoke

func (s *Service) Revoke(ctx context.Context, by, id string) error

Revoke makes the agent unable to connect again. It does not close a connection that is open: the hub does that.

func (*Service) Seen

func (s *Service) Seen(ctx context.Context, id, version, hostname, osVersion string, at time.Time) error

Seen records that the agent is connected, or was just now, with what it reported about itself. An id that is not an enrolled agent (the built-in agent) is ignored.

Jump to

Keyboard shortcuts

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