Documentation
¶
Index ¶
- Variables
- type BootstrapToken
- type EnrolledNode
- type EnrollmentRequest
- type KeyPair
- type RouterLease
- type SQLStore
- func (s *SQLStore) ClaimKeyRotation(ctx context.Context, now time.Time, interval time.Duration) (bool, error)
- func (s *SQLStore) Close() error
- func (s *SQLStore) CreateEnrollmentRequest(ctx context.Context, req *EnrollmentRequest) error
- func (s *SQLStore) EnrollNode(ctx context.Context, node *EnrolledNode) error
- func (s *SQLStore) GetActiveRouters(ctx context.Context) ([]RouterLease, error)
- func (s *SQLStore) GetAllValidKeys(ctx context.Context) ([]KeyPair, error)
- func (s *SQLStore) GetBootstrapToken(ctx context.Context, id string) (*BootstrapToken, error)
- func (s *SQLStore) GetCurrentKey(ctx context.Context) (ed25519.PrivateKey, ed25519.PublicKey, error)
- func (s *SQLStore) GetEnrollmentRequest(ctx context.Context, peerID string) (*EnrollmentRequest, error)
- func (s *SQLStore) GetEnrollmentRequestByID(ctx context.Context, id string) (*EnrollmentRequest, error)
- func (s *SQLStore) GetMeshPolicy(ctx context.Context) ([]*api.PolicyRole, []*api.PolicyBinding, error)
- func (s *SQLStore) GetNode(ctx context.Context, peerID string) (*EnrolledNode, error)
- func (s *SQLStore) GetUser(ctx context.Context, id string) (*User, error)
- func (s *SQLStore) IncrementBootstrapTokenUsage(ctx context.Context, id string) error
- func (s *SQLStore) IsNodeBanned(ctx context.Context, peerID string) (bool, error)
- func (s *SQLStore) ListBootstrapTokens(ctx context.Context) ([]BootstrapToken, error)
- func (s *SQLStore) ListEnrollmentRequests(ctx context.Context) ([]EnrollmentRequest, error)
- func (s *SQLStore) ListNodes(ctx context.Context) ([]EnrolledNode, error)
- func (s *SQLStore) ListUsers(ctx context.Context) ([]User, error)
- func (s *SQLStore) Ping(ctx context.Context) error
- func (s *SQLStore) ReleaseKeyRotationClaim(ctx context.Context, now time.Time, interval time.Duration) error
- func (s *SQLStore) RotateKeys(ctx context.Context, newPriv ed25519.PrivateKey, newPub ed25519.PublicKey, ...) error
- func (s *SQLStore) SaveBootstrapToken(ctx context.Context, token *BootstrapToken) error
- func (s *SQLStore) SaveInitialKey(ctx context.Context, priv ed25519.PrivateKey, pub ed25519.PublicKey) error
- func (s *SQLStore) SaveMeshPolicy(ctx context.Context, roles []*api.PolicyRole, bindings []*api.PolicyBinding) error
- func (s *SQLStore) SaveUser(ctx context.Context, user *User) error
- func (s *SQLStore) SetNodeBanned(ctx context.Context, peerID string, banned bool) error
- func (s *SQLStore) UpdateEnrollmentRequest(ctx context.Context, id string, status api.EnrollmentStatus, biscuit []byte, ...) error
- func (s *SQLStore) UpsertRouterLease(ctx context.Context, lease *RouterLease) error
- type Store
- type User
Constants ¶
This section is empty.
Variables ¶
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
}
BootstrapToken represents a pre-shared token for node enrollment.
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
}
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 RouterLease ¶
type RouterLease struct {
PeerID string
Addresses []string
LastRenewal time.Time
ExpiresAt time.Time
ConnectedPeers []string
DHTSize 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 ¶
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) CreateEnrollmentRequest ¶
func (s *SQLStore) CreateEnrollmentRequest(ctx context.Context, req *EnrollmentRequest) error
CreateEnrollmentRequest saves a new pending request.
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.
func (*SQLStore) GetAllValidKeys ¶
GetAllValidKeys implements Store.
func (*SQLStore) GetBootstrapToken ¶
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) 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.
func (*SQLStore) IncrementBootstrapTokenUsage ¶
IncrementBootstrapTokenUsage increments usage count.
func (*SQLStore) IsNodeBanned ¶
IsNodeBanned 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) ([]EnrolledNode, error)
ListNodes retrieves all enrolled nodes.
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) RotateKeys ¶
func (s *SQLStore) RotateKeys(ctx context.Context, newPriv ed25519.PrivateKey, newPub ed25519.PublicKey, gracePeriod time.Duration) error
RotateKeys implements Store.
func (*SQLStore) SaveBootstrapToken ¶
func (s *SQLStore) SaveBootstrapToken(ctx context.Context, token *BootstrapToken) error
SaveBootstrapToken persists a new bootstrap token.
func (*SQLStore) SaveInitialKey ¶
func (s *SQLStore) SaveInitialKey(ctx context.Context, priv ed25519.PrivateKey, pub ed25519.PublicKey) error
SaveInitialKey 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) SetNodeBanned ¶
SetNodeBanned 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)
// 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
// SaveInitialKey sets the initial key pair if no keys exist yet.
SaveInitialKey(ctx context.Context, priv ed25519.PrivateKey, pub ed25519.PublicKey) 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.
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.
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)
// UpsertRouterLease updates or creates a lease for a sam-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)
// 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)
// IncrementBootstrapTokenUsage increments the usage count of a token.
IncrementBootstrapTokenUsage(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
// ListNodes retrieves all enrolled nodes.
ListNodes(ctx context.Context) ([]EnrolledNode, error)
// ListBootstrapTokens retrieves all bootstrap tokens.
ListBootstrapTokens(ctx context.Context) ([]BootstrapToken, error)
// Close closes the underlying database connection.
Close() error
}
Store defines the persistent operations for the SAM control plane.