Help us shape the future of Go! Take the 2026 Go Developer Survey

storage

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")

	// ErrNodeBanned and ErrNodeSessionExpired are the two ways an enrolled node
	// stops being servable. See EnrolledNode.CheckAdmission.
	ErrNodeBanned         = errors.New("node is banned")
	ErrNodeSessionExpired = errors.New("node session expired")

	// ErrBootstrapTokenUnusable is returned by ConsumeBootstrapTokenUsage when
	// the token is expired, revoked or has no usages left. One error for the
	// three so a caller cannot tell them apart after the fact and race one.
	ErrBootstrapTokenUnusable = errors.New("bootstrap token is expired, revoked or exhausted")

	// ErrEnrollmentAlreadyResolved is returned by ResolveEnrollmentRequest
	// when the request is no longer pending: someone else approved or
	// rejected it first.
	ErrEnrollmentAlreadyResolved = errors.New("enrollment request is already resolved")
)

Functions

This section is empty.

Types

type BootstrapToken

type BootstrapToken struct {
	ID          string
	TokenHash   string
	Role        string
	OwnerID     string
	MaxUsages   int
	UsagesCount int
	Description string
	CreatedAt   time.Time
	ExpiresAt   time.Time
	// RevokedAt is set by RevokeBootstrapToken - a soft revoke, distinct from
	// natural expiry, since enrollment_requests.token_id has a foreign key
	// into this table and a hard delete would break that trail. Nil means
	// never revoked.
	RevokedAt *time.Time
	// AutonomousRecovery is copied onto every node this token enrolls; see
	// EnrolledNode.AutonomousRecovery.
	AutonomousRecovery bool
	// Ephemeral is copied onto every node this token enrolls; see
	// EnrolledNode.Ephemeral.
	Ephemeral bool
}

BootstrapToken represents a pre-shared token for node enrollment.

func (*BootstrapToken) IsRevoked

func (t *BootstrapToken) IsRevoked() bool

IsRevoked reports whether the token has been explicitly revoked, as opposed to merely expired or usage-exhausted.

type EnrolledNode

type EnrolledNode struct {
	PeerID         string
	PublicKey      []byte
	Biscuit        []byte
	Role           string
	EnrollmentType string
	ClaimsJSON     string
	OwnerID        string
	// Labels are the attested key=value claims minted into the node's
	// biscuit; kept on the record so token refreshes re-mint them unchanged.
	Labels     map[string]string
	EnrolledAt time.Time
	ExpiresAt  time.Time
	Banned     bool
	// AutonomousRecovery lets /refresh re-issue this node's biscuit after the
	// key that signed it has been retired, on proof of possession alone. Off
	// by default: without it a bootstrap node offline past the key grace
	// period needs an operator to mint a new token, which is what stops a
	// forgotten or stolen machine from rejoining on its own. Only ever set
	// server-side, from the token that enrolled the node or by an admin.
	AutonomousRecovery bool
	// Ephemeral marks a member enrolled by an ephemeral bootstrap token: a
	// fleet member, a probe, a CI job. Such a member is forgotten soon after
	// it falls silent (DeleteSilentBootstrapNodes), where a regular one is
	// kept for the full retention. Copied from the token at enrollment.
	Ephemeral bool
}

EnrolledNode represents a node enrolled in the mesh.

func (*EnrolledNode) CheckAdmission

func (n *EnrolledNode) CheckAdmission(now time.Time) error

CheckAdmission reports whether the control plane may still serve this node. Enrollment is bounded by two independent conditions, an explicit ban and the end of the OIDC session, and every path that acts on an enrolled node has to apply both: checking only Banned lets a node whose session lapsed keep reading mesh state until someone bans it by hand.

type EnrollmentRequest

type EnrollmentRequest struct {
	ID        string
	PeerID    string
	PublicKey []byte
	TokenID   string
	Status    api.EnrollmentStatus
	// Labels are the operator-declared key=value claims, surfaced to the
	// approving admin; approval attests them into the minted biscuit.
	Labels       map[string]string
	BiscuitToken []byte
	CreatedAt    time.Time
	ResolvedAt   *time.Time
	ResolvedBy   string
}

EnrollmentRequest represents a pending or resolved node registration request (CSR).

type KeyPair

type KeyPair struct {
	Private    ed25519.PrivateKey
	Public     ed25519.PublicKey
	Expiration time.Time
}

KeyPair holds cryptographic key information.

type NodeCount

type NodeCount struct {
	Role  string
	State NodeState
	Count int
}

NodeCount is how many nodes of one role are in one state.

type NodeCursor

type NodeCursor struct {
	EnrolledAt time.Time
	PeerID     string
}

NodeCursor is the sort key of the last row of a ListNodes page.

type NodeFilter

type NodeFilter struct {
	// States keeps the nodes in any of these states at Now, time.Now() if zero.
	States []NodeState
	Now    time.Time
	// OwnerID nil means every owner; any other value, even "", keeps only
	// that owner's nodes.
	OwnerID *string
	Role    string
	// After resumes from the last row of the previous page. Limit 0 is no limit.
	After *NodeCursor
	Limit int
}

NodeFilter selects what ListNodes returns; the zero value is every node.

type NodeState

type NodeState string

NodeState is what CheckAdmission says of a node at some instant. "admitted" is not liveness: a node that enrolled once and went away stays admitted until its session expires, or, for a bootstrap enrollment that has none, until it has been silent for the retention and is deleted.

const (
	NodeAdmitted NodeState = "admitted"
	NodeExpired  NodeState = "expired"
	NodeBanned   NodeState = "banned"
)

type OIDCKeyPair

type OIDCKeyPair struct {
	Kid        string
	PrivateKey []byte
	PublicKey  []byte
	Expiration time.Time
}

OIDCKeyPair holds an ES256 (P-256) key pair for outbound OIDC/STS JWT signing.

type RouterLease

type RouterLease struct {
	PeerID         string
	Addresses      []string
	LastRenewal    time.Time
	ExpiresAt      time.Time
	ConnectedPeers []string
	DHTSize        int
	// The router's load as of this lease: open inbound connections and the
	// number it accepts. Listed on /info for members to choose routers by.
	Connections     int
	ConnectionLimit int
}

RouterLease represents a router registered with the control plane.

type SQLStore

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

SQLStore implements Store interface using database/sql.

func NewSQLStore

func NewSQLStore(driverName, dataSourceName string) (*SQLStore, error)

NewSQLStore creates a new SQLStore, connects to the database, and initializes tables.

func (*SQLStore) ClaimKeyRotation

func (s *SQLStore) ClaimKeyRotation(ctx context.Context, now time.Time, interval time.Duration) (bool, error)

ClaimKeyRotation implements Store.

func (*SQLStore) Close

func (s *SQLStore) Close() error

Close implements Store.

func (*SQLStore) ConsumeBootstrapTokenUsage

func (s *SQLStore) ConsumeBootstrapTokenUsage(ctx context.Context, id string, now time.Time) error

ConsumeBootstrapTokenUsage implements Store. The validity conditions live in the WHERE clause so the check and the increment are one statement.

func (*SQLStore) CountEnrollmentRequests

func (s *SQLStore) CountEnrollmentRequests(ctx context.Context) (map[api.EnrollmentStatus]int64, error)

CountEnrollmentRequests implements Store.

func (*SQLStore) CountNodes

func (s *SQLStore) CountNodes(ctx context.Context, now time.Time) ([]NodeCount, error)

CountNodes implements Store. The CASE tests a ban first, as CheckAdmission does.

func (*SQLStore) CountRows

func (s *SQLStore) CountRows(ctx context.Context) (map[string]int64, error)

CountRows implements Store.

func (*SQLStore) CreateEnrollmentRequest

func (s *SQLStore) CreateEnrollmentRequest(ctx context.Context, req *EnrollmentRequest) error

CreateEnrollmentRequest saves a new pending request.

func (*SQLStore) DeleteExpiredBootstrapTokens

func (s *SQLStore) DeleteExpiredBootstrapTokens(ctx context.Context, before time.Time) (int64, error)

DeleteExpiredBootstrapTokens implements Store. The NOT EXISTS keeps the foreign key from enrollment_requests.token_id satisfied: a token goes once its requests have.

func (*SQLStore) DeleteExpiredNodes

func (s *SQLStore) DeleteExpiredNodes(ctx context.Context, before time.Time) (int64, error)

DeleteExpiredNodes implements Store.

func (*SQLStore) DeleteExpiredRouterLeases

func (s *SQLStore) DeleteExpiredRouterLeases(ctx context.Context, before time.Time) (int64, error)

DeleteExpiredRouterLeases implements Store.

func (*SQLStore) DeleteSilentBootstrapNodes

func (s *SQLStore) DeleteSilentBootstrapNodes(ctx context.Context, before, ephemeralBefore time.Time) (int64, int64, error)

DeleteSilentBootstrapNodes implements Store. Two statements, one per retention, each leading with banned and expires_at so the (banned, expires_at) index narrows them to the unbounded rows.

func (*SQLStore) DeleteStaleEnrollmentRequests

func (s *SQLStore) DeleteStaleEnrollmentRequests(ctx context.Context, before, ephemeralBefore time.Time) (int64, error)

DeleteStaleEnrollmentRequests implements Store.

func (*SQLStore) EnrollNode

func (s *SQLStore) EnrollNode(ctx context.Context, node *EnrolledNode) error

EnrollNode implements Store.

func (*SQLStore) GetActiveRouters

func (s *SQLStore) GetActiveRouters(ctx context.Context) ([]RouterLease, error)

GetActiveRouters implements Store. The order is by peer ID, so the store reads the same to every replica and caller; the control plane shuffles the list it hands members (routerAddresses) so they spread across the routers.

func (*SQLStore) GetAllValidKeys

func (s *SQLStore) GetAllValidKeys(ctx context.Context) ([]KeyPair, error)

GetAllValidKeys implements Store.

func (*SQLStore) GetAllValidOIDCKeys

func (s *SQLStore) GetAllValidOIDCKeys(ctx context.Context) ([]OIDCKeyPair, error)

GetAllValidOIDCKeys implements Store.

func (*SQLStore) GetAllValidPublicKeys

func (s *SQLStore) GetAllValidPublicKeys(ctx context.Context) ([]ed25519.PublicKey, error)

GetAllValidPublicKeys implements Store.

func (*SQLStore) GetBootstrapToken

func (s *SQLStore) GetBootstrapToken(ctx context.Context, id string) (*BootstrapToken, error)

GetBootstrapToken retrieves a bootstrap token by its ID (sha256 hash).

func (*SQLStore) GetCurrentKey

func (s *SQLStore) GetCurrentKey(ctx context.Context) (ed25519.PrivateKey, ed25519.PublicKey, error)

GetCurrentKey implements Store.

func (*SQLStore) GetCurrentOIDCKey

func (s *SQLStore) GetCurrentOIDCKey(ctx context.Context) (*OIDCKeyPair, error)

GetCurrentOIDCKey implements Store.

func (*SQLStore) GetEgressDestinations

func (s *SQLStore) GetEgressDestinations(ctx context.Context) ([]*api.EgressDestination, error)

GetEgressDestinations loads the egress section of the mesh policy, in name order so the rendered document and rules are stable.

func (*SQLStore) GetEnrollmentRequest

func (s *SQLStore) GetEnrollmentRequest(ctx context.Context, peerID string) (*EnrollmentRequest, error)

GetEnrollmentRequest retrieves request by PeerID.

func (*SQLStore) GetEnrollmentRequestByID

func (s *SQLStore) GetEnrollmentRequestByID(ctx context.Context, id string) (*EnrollmentRequest, error)

GetEnrollmentRequestByID retrieves request by UUID.

func (*SQLStore) GetMeshPolicy

func (s *SQLStore) GetMeshPolicy(ctx context.Context) ([]*api.PolicyRole, []*api.PolicyBinding, error)

GetMeshPolicy retrieves the entire mesh policy as structured data, in an order that does not change between reads: the policy is rendered to text a member compares with the last text it fetched to tell a change.

func (*SQLStore) GetNode

func (s *SQLStore) GetNode(ctx context.Context, peerID string) (*EnrolledNode, error)

GetNode implements Store.

func (*SQLStore) GetUser

func (s *SQLStore) GetUser(ctx context.Context, id string) (*User, error)

GetUser retrieves a user by ID.

func (*SQLStore) IsBiscuitRevoked

func (s *SQLStore) IsBiscuitRevoked(ctx context.Context, revocationID string, now time.Time) (bool, error)

IsBiscuitRevoked implements Store.

func (*SQLStore) IsIdentityBanned

func (s *SQLStore) IsIdentityBanned(ctx context.Context, identity string) (bool, error)

IsIdentityBanned implements Store.

func (*SQLStore) IsNodeBanned

func (s *SQLStore) IsNodeBanned(ctx context.Context, peerID string) (bool, error)

IsNodeBanned implements Store.

func (*SQLStore) ListBannedPeerIDs

func (s *SQLStore) ListBannedPeerIDs(ctx context.Context) ([]string, error)

ListBannedPeerIDs implements Store.

func (*SQLStore) ListBootstrapTokens

func (s *SQLStore) ListBootstrapTokens(ctx context.Context) ([]BootstrapToken, error)

ListBootstrapTokens retrieves all bootstrap tokens.

func (*SQLStore) ListEnrollmentRequests

func (s *SQLStore) ListEnrollmentRequests(ctx context.Context) ([]EnrollmentRequest, error)

ListEnrollmentRequests retrieves all requests.

func (*SQLStore) ListNodes

func (s *SQLStore) ListNodes(ctx context.Context, filter NodeFilter) ([]EnrolledNode, error)

ListNodes implements Store.

func (*SQLStore) ListRevokedBiscuits

func (s *SQLStore) ListRevokedBiscuits(ctx context.Context, now time.Time) (map[string]time.Time, error)

ListRevokedBiscuits implements Store.

func (*SQLStore) ListUsers

func (s *SQLStore) ListUsers(ctx context.Context) ([]User, error)

ListUsers retrieves all registered users.

func (*SQLStore) NextKeyRotation

func (s *SQLStore) NextKeyRotation(ctx context.Context) (time.Time, error)

NextKeyRotation implements Store.

func (*SQLStore) Ping

func (s *SQLStore) Ping(ctx context.Context) error

Ping implements Store.

func (*SQLStore) ReleaseKeyRotationClaim

func (s *SQLStore) ReleaseKeyRotationClaim(ctx context.Context, now time.Time, interval time.Duration) error

ReleaseKeyRotationClaim implements Store. It only resets the deadline if it still holds the exact value this claim set, so it can't clobber a newer claim.

func (*SQLStore) ResolveEnrollmentRequest

func (s *SQLStore) ResolveEnrollmentRequest(ctx context.Context, id string, status api.EnrollmentStatus, biscuit []byte, resolvedBy string) error

ResolveEnrollmentRequest implements Store.

func (*SQLStore) RevokeBootstrapToken

func (s *SQLStore) RevokeBootstrapToken(ctx context.Context, id string) error

RevokeBootstrapToken soft-revokes a token: see the Store interface comment for why this doesn't delete the row. The WHERE clause makes a repeat call a no-op rather than clobbering the original revocation time.

func (*SQLStore) RotateKeys

func (s *SQLStore) RotateKeys(ctx context.Context, newPriv ed25519.PrivateKey, newPub ed25519.PublicKey, gracePeriod time.Duration) error

RotateKeys implements Store.

func (*SQLStore) RotateOIDCKeys

func (s *SQLStore) RotateOIDCKeys(ctx context.Context, kid string, newPriv, newPub []byte, gracePeriod time.Duration) error

RotateOIDCKeys implements Store.

func (*SQLStore) SaveBootstrapToken

func (s *SQLStore) SaveBootstrapToken(ctx context.Context, token *BootstrapToken) error

SaveBootstrapToken persists a new bootstrap token.

func (*SQLStore) SaveEgressDestinations

func (s *SQLStore) SaveEgressDestinations(ctx context.Context, egress []*api.EgressDestination) error

SaveEgressDestinations replaces the egress section of the mesh policy.

func (*SQLStore) SaveInitialKey

func (s *SQLStore) SaveInitialKey(ctx context.Context, priv ed25519.PrivateKey, pub ed25519.PublicKey) error

SaveInitialKey implements Store.

func (*SQLStore) SaveInitialOIDCKey

func (s *SQLStore) SaveInitialOIDCKey(ctx context.Context, kid string, priv, pub []byte) error

SaveInitialOIDCKey implements Store.

func (*SQLStore) SaveMeshPolicy

func (s *SQLStore) SaveMeshPolicy(ctx context.Context, roles []*api.PolicyRole, bindings []*api.PolicyBinding) error

SaveMeshPolicy replaces the entire mesh policy with the provided roles and bindings.

func (*SQLStore) SavePolicyDocument

func (s *SQLStore) SavePolicyDocument(ctx context.Context, roles []*api.PolicyRole, bindings []*api.PolicyBinding, egress []*api.EgressDestination) error

SavePolicyDocument replaces roles, bindings and egress destinations in one transaction, so a POST /policies is applied whole or not at all.

func (*SQLStore) SaveRevokedBiscuit

func (s *SQLStore) SaveRevokedBiscuit(ctx context.Context, revocationID string, expiresAt time.Time) error

SaveRevokedBiscuit implements Store.

func (*SQLStore) SaveUser

func (s *SQLStore) SaveUser(ctx context.Context, user *User) error

SaveUser creates or updates a user.

func (*SQLStore) ScheduleKeyRotationIfUnset

func (s *SQLStore) ScheduleKeyRotationIfUnset(ctx context.Context, at time.Time) (bool, error)

ScheduleKeyRotationIfUnset implements Store.

func (*SQLStore) SetIdentityBanned

func (s *SQLStore) SetIdentityBanned(ctx context.Context, identity string, banned bool) error

SetIdentityBanned implements Store.

func (*SQLStore) SetKeyring added in v0.1.1

func (s *SQLStore) SetKeyring(ctx context.Context, current KeyPair, verifying []KeyPair, gracePeriod time.Duration) error

SetKeyring implements Store.

func (*SQLStore) SetNodeAndIdentityBanned

func (s *SQLStore) SetNodeAndIdentityBanned(ctx context.Context, peerID, identity string, banned bool) error

SetNodeAndIdentityBanned implements Store.

func (*SQLStore) SetNodeAutonomousRecovery

func (s *SQLStore) SetNodeAutonomousRecovery(ctx context.Context, peerID string, enabled bool) error

SetNodeAutonomousRecovery implements Store.

func (*SQLStore) SetNodeBanned

func (s *SQLStore) SetNodeBanned(ctx context.Context, peerID string, banned bool) error

SetNodeBanned implements Store.

func (*SQLStore) SetOIDCKeyring added in v0.1.1

func (s *SQLStore) SetOIDCKeyring(ctx context.Context, current OIDCKeyPair, verifying []OIDCKeyPair, gracePeriod time.Duration) error

SetOIDCKeyring implements Store.

func (*SQLStore) UpdateEnrollmentRequest

func (s *SQLStore) UpdateEnrollmentRequest(ctx context.Context, id string, status api.EnrollmentStatus, biscuit []byte, resolvedBy string) error

UpdateEnrollmentRequest updates status, timestamp and biscuit token.

func (*SQLStore) UpsertRouterLease

func (s *SQLStore) UpsertRouterLease(ctx context.Context, lease *RouterLease) error

UpsertRouterLease implements Store.

type Store

type Store interface {
	// Ping checks the health of the underlying database connection.
	Ping(ctx context.Context) error

	// GetCurrentKey retrieves the active key pair for biscuit signing.
	GetCurrentKey(ctx context.Context) (ed25519.PrivateKey, ed25519.PublicKey, error)

	// GetAllValidKeys retrieves the active key pair and any non-expired historical key pairs.
	GetAllValidKeys(ctx context.Context) ([]KeyPair, error)

	// GetAllValidPublicKeys is GetAllValidKeys for verifiers: the same key
	// set without the private halves.
	GetAllValidPublicKeys(ctx context.Context) ([]ed25519.PublicKey, error)

	// RotateKeys rotates the current key to a new key pair and sets the expiration of the old key.
	RotateKeys(ctx context.Context, newPriv ed25519.PrivateKey, newPub ed25519.PublicKey, gracePeriod time.Duration) error

	// ClaimKeyRotation atomically claims the next scheduled key-rotation
	// window, so multiple control-plane replicas sharing one database rotate
	// keys exactly once per interval instead of racing independently. It
	// returns true if the caller won the claim (advancing the deadline by
	// interval), false if another replica already claimed this window.
	ClaimKeyRotation(ctx context.Context, now time.Time, interval time.Duration) (bool, error)

	// ReleaseKeyRotationClaim reverts a claim won via ClaimKeyRotation with
	// the same now/interval back to its pre-claim deadline, so the window
	// can be retried without waiting a full interval. Callers use this when
	// the rotation that followed a successful claim failed.
	ReleaseKeyRotationClaim(ctx context.Context, now time.Time, interval time.Duration) error

	// ScheduleKeyRotationIfUnset sets the first rotation deadline of a store
	// that never had one, and reports whether it did. A store that already
	// carries a deadline, due or not, is left as it is.
	ScheduleKeyRotationIfUnset(ctx context.Context, at time.Time) (bool, error)

	// NextKeyRotation is the deadline ClaimKeyRotation will honour: the
	// instant the next rotation is due, zero when none was ever scheduled.
	NextKeyRotation(ctx context.Context) (time.Time, error)

	// SaveInitialKey sets the initial key pair if no keys exist yet.
	SaveInitialKey(ctx context.Context, priv ed25519.PrivateKey, pub ed25519.PublicKey) error

	// SetKeyring makes the keyring reflect a set the operator owns, in one
	// transaction: current becomes the signing key, each of verifying stays
	// valid for verification for as long as the operator lists it, and any
	// other key still valid in the store is given gracePeriod to expire so
	// that credentials it signed keep verifying meanwhile. Keys already
	// present are updated in place, so the same set applied twice is a
	// no-op and a key moved back to the front becomes current again.
	// Expired rows are purged first.
	SetKeyring(ctx context.Context, current KeyPair, verifying []KeyPair, gracePeriod time.Duration) error

	// SaveUser creates or updates a User.
	SaveUser(ctx context.Context, user *User) error

	// GetUser retrieves a User by ID.
	GetUser(ctx context.Context, id string) (*User, error)

	// ListUsers retrieves all registered users.
	ListUsers(ctx context.Context) ([]User, error)

	// EnrollNode registers or updates a node enrollment. EnrolledAt is when
	// the member was last seen; unset, it is recorded as now, never as the
	// zero time, which the silent-member sweep would read as decades ago.
	EnrollNode(ctx context.Context, node *EnrolledNode) error

	// GetNode retrieves node enrollment details.
	GetNode(ctx context.Context, peerID string) (*EnrolledNode, error)

	// SetNodeBanned updates the banned status of a node. ErrNotFound if no
	// node has that peer ID.
	SetNodeBanned(ctx context.Context, peerID string, banned bool) error

	// IsNodeBanned checks if a node is currently banned.
	IsNodeBanned(ctx context.Context, peerID string) (bool, error)

	// SetNodeAutonomousRecovery toggles EnrolledNode.AutonomousRecovery.
	// Returns ErrNotFound if no such node is enrolled.
	SetNodeAutonomousRecovery(ctx context.Context, peerID string, enabled bool) error

	// SetIdentityBanned bans or unbans an enrolled OIDC identity, keyed as
	// "issuer|subject". A node ban is keyed on a self-generated peer id, so
	// this is what makes a ban survive keypair regeneration.
	SetIdentityBanned(ctx context.Context, identity string, banned bool) error

	// SetNodeAndIdentityBanned is SetNodeBanned and SetIdentityBanned in one
	// transaction, so a failure cannot leave the device banned while its
	// identity may still enroll a new one, or the other way round. An empty
	// identity bans the node alone.
	SetNodeAndIdentityBanned(ctx context.Context, peerID, identity string, banned bool) error

	// IsIdentityBanned checks if an identity is currently banned.
	IsIdentityBanned(ctx context.Context, identity string) (bool, error)

	// ListBannedPeerIDs returns the peer IDs of every currently banned node.
	// Callers publish this as the complete ban set (see
	// ControlPlaneInfoResponse.banned_peer_ids), so it must be the whole list
	// rather than a page of it.
	ListBannedPeerIDs(ctx context.Context) ([]string, error)

	// UpsertRouterLease updates or creates a lease for a agentmesh-router.
	UpsertRouterLease(ctx context.Context, lease *RouterLease) error

	// GetActiveRouters retrieves all routers whose leases are still valid.
	GetActiveRouters(ctx context.Context) ([]RouterLease, error)

	// SaveMeshPolicy persists the mesh configurations.
	SaveMeshPolicy(ctx context.Context, roles []*api.PolicyRole, bindings []*api.PolicyBinding) error

	// GetMeshPolicy loads the mesh configurations.
	GetMeshPolicy(ctx context.Context) ([]*api.PolicyRole, []*api.PolicyBinding, error)

	// SaveEgressDestinations replaces the egress section of the mesh policy
	// (PolicyConfig.egress).
	SaveEgressDestinations(ctx context.Context, egress []*api.EgressDestination) error

	// GetEgressDestinations loads the egress section of the mesh policy.
	GetEgressDestinations(ctx context.Context) ([]*api.EgressDestination, error)

	// SavePolicyDocument replaces roles, bindings and egress destinations in
	// one transaction: a policy post is applied whole or not at all.
	SavePolicyDocument(ctx context.Context, roles []*api.PolicyRole, bindings []*api.PolicyBinding, egress []*api.EgressDestination) error

	// SaveBootstrapToken persists a new bootstrap token.
	SaveBootstrapToken(ctx context.Context, token *BootstrapToken) error

	// GetBootstrapToken retrieves a bootstrap token by its ID (sha256 hash).
	GetBootstrapToken(ctx context.Context, id string) (*BootstrapToken, error)

	// ConsumeBootstrapTokenUsage spends one usage of a token, atomically
	// with the check that a usage is left and that the token is neither
	// expired (as of now) nor revoked. ErrBootstrapTokenUnusable when it is
	// not: a read-then-increment would let concurrent enrollments overshoot
	// max_usages.
	ConsumeBootstrapTokenUsage(ctx context.Context, id string, now time.Time) error

	// RevokeBootstrapToken soft-revokes a token by setting its RevokedAt, so
	// HandleEnroll refuses it even though it may still be within its TTL and
	// usage count. Idempotent: revoking an already-revoked or unknown token
	// is not an error - callers that need to distinguish "unknown" first
	// look the token up with GetBootstrapToken.
	RevokeBootstrapToken(ctx context.Context, id string) error

	// CreateEnrollmentRequest saves a new pending enrollment request.
	CreateEnrollmentRequest(ctx context.Context, req *EnrollmentRequest) error

	// GetEnrollmentRequest retrieves an enrollment request by PeerID.
	GetEnrollmentRequest(ctx context.Context, peerID string) (*EnrollmentRequest, error)

	// GetEnrollmentRequestByID retrieves an enrollment request by ID.
	GetEnrollmentRequestByID(ctx context.Context, id string) (*EnrollmentRequest, error)

	// ListEnrollmentRequests retrieves all enrollment requests.
	ListEnrollmentRequests(ctx context.Context) ([]EnrollmentRequest, error)

	// UpdateEnrollmentRequest updates status, resolved details, and stored Biscuit of a request.
	UpdateEnrollmentRequest(ctx context.Context, id string, status api.EnrollmentStatus, biscuit []byte, resolvedBy string) error

	// ResolveEnrollmentRequest is UpdateEnrollmentRequest for a request that
	// must still be pending: two admins acting on the same request cannot
	// both succeed. ErrEnrollmentAlreadyResolved if it was not pending.
	ResolveEnrollmentRequest(ctx context.Context, id string, status api.EnrollmentStatus, biscuit []byte, resolvedBy string) error

	// ListNodes retrieves the enrolled nodes the filter selects, newest
	// enrollment first. Peer ID breaks ties, so pages neither skip nor repeat a row.
	// A listed node carries no PublicKey and no Biscuit: GetNode reads those.
	ListNodes(ctx context.Context, filter NodeFilter) ([]EnrolledNode, error)

	// CountNodes counts every enrolled node by role and by its state at now.
	CountNodes(ctx context.Context, now time.Time) ([]NodeCount, error)

	// CountEnrollmentRequests counts the enrollment requests by status.
	CountEnrollmentRequests(ctx context.Context) (map[api.EnrollmentStatus]int64, error)

	// DeleteExpiredNodes removes enrolled nodes whose session expired before
	// the given time and that are not banned, returning how many went. A
	// lapsed session already refuses every refresh, so the row only records
	// that the node once existed; a ban, by contrast, is the row, and must
	// outlive the session it was placed on. Nodes with no session bound
	// (zero ExpiresAt) are not removed here; see DeleteSilentBootstrapNodes.
	DeleteExpiredNodes(ctx context.Context, before time.Time) (int64, error)

	// DeleteSilentBootstrapNodes removes enrolled nodes that have no session
	// bound (a bootstrap enrollment) and are not banned, whose last refresh
	// (EnrolledAt, which a refresh rewrites) is before `before`, or before
	// `ephemeralBefore` for a node an ephemeral token enrolled. A member
	// that refreshes keeps its row; one that fell silent for the retention
	// is forgotten, and enrolls again if it comes back. It returns how many
	// regular and how many ephemeral rows went.
	DeleteSilentBootstrapNodes(ctx context.Context, before, ephemeralBefore time.Time) (regular, ephemeral int64, err error)

	// DeleteStaleEnrollmentRequests removes enrollment requests created, or
	// resolved, before `before`, and before `ephemeralBefore` when the token
	// that made them is ephemeral. A resolved request is a record of a
	// decision; a pending one that old was abandoned by its enrollee long
	// ago. It returns how many went.
	DeleteStaleEnrollmentRequests(ctx context.Context, before, ephemeralBefore time.Time) (int64, error)

	// DeleteExpiredBootstrapTokens removes tokens that expired before
	// `before` and that no enrollment request refers to any more; a token
	// is the proof a member gave once, and once its requests are gone
	// nothing points at it. It returns how many went.
	DeleteExpiredBootstrapTokens(ctx context.Context, before time.Time) (int64, error)

	// DeleteExpiredRouterLeases removes router leases that expired before
	// `before`. A router that comes back leases again under its peer ID; a
	// lease long expired is a router that is gone. It returns how many went.
	DeleteExpiredRouterLeases(ctx context.Context, before time.Time) (int64, error)

	// CountRows counts the rows of every table whose size the control plane
	// reports, keyed by table name.
	CountRows(ctx context.Context) (map[string]int64, error)

	// ListBootstrapTokens retrieves all bootstrap tokens.
	ListBootstrapTokens(ctx context.Context) ([]BootstrapToken, error)

	// GetCurrentOIDCKey retrieves the active ES256 key pair for OIDC/STS JWT signing.
	GetCurrentOIDCKey(ctx context.Context) (*OIDCKeyPair, error)

	// GetAllValidOIDCKeys retrieves the active ES256 key pair and any non-expired historical key pairs.
	GetAllValidOIDCKeys(ctx context.Context) ([]OIDCKeyPair, error)

	// SaveInitialOIDCKey saves the initial ES256 key pair if no OIDC keys exist yet.
	SaveInitialOIDCKey(ctx context.Context, kid string, priv, pub []byte) error

	// RotateOIDCKeys rotates the current ES256 key to a new key pair and sets the expiration of the old key.
	RotateOIDCKeys(ctx context.Context, kid string, newPriv, newPub []byte, gracePeriod time.Duration) error

	// SetOIDCKeyring is SetKeyring for the ES256 keyring, keyed by kid.
	SetOIDCKeyring(ctx context.Context, current OIDCKeyPair, verifying []OIDCKeyPair, gracePeriod time.Duration) error

	// SaveRevokedBiscuit persists a Biscuit revocation ID until its expiration time.
	SaveRevokedBiscuit(ctx context.Context, revocationID string, expiresAt time.Time) error

	// ListRevokedBiscuits returns all unexpired Biscuit revocation IDs as of now and prunes expired rows.
	ListRevokedBiscuits(ctx context.Context, now time.Time) (map[string]time.Time, error)

	// IsBiscuitRevoked checks if the given base64url-encoded revocation ID is currently revoked.
	IsBiscuitRevoked(ctx context.Context, revocationID string, now time.Time) (bool, error)

	// Close closes the underlying database connection.
	Close() error
}

Store defines the persistent operations for the Agent Mesh control plane.

type User

type User struct {
	// ID is the OIDC subject. Issuer is the OIDC issuer it came from: the
	// pair is what an identity ban is keyed on (see SetIdentityBanned), and
	// two issuers may hand out the same subject to different people.
	ID        string
	Issuer    string
	Email     string
	Role      string
	CreatedAt time.Time
}

User represents a human identity in the mesh.

func (*User) IdentityKey

func (u *User) IdentityKey() string

IdentityKey is the "issuer|subject" form identity bans are keyed on.

Jump to

Keyboard shortcuts

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