identity

package
v0.4.28 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package identity holds the agent's per-node mTLS identity.

The private key is generated on the cluster and never leaves it. Enrollment sends a certificate signing request; the SaaS signs it and returns a certificate. That is the difference between a vendor who can impersonate a customer's cluster and one who demonstrably cannot — and it is a property of where the key is made, not of anyone's good intentions.

Index

Constants

View Source
const ConsoleCAFileName = "console-ca.pub"

ConsoleCAFileName is where RecordConsoleCA writes, inside the identity dir.

View Source
const ConsoleOriginsFileName = "console-origins"

ConsoleOriginsFileName is where RecordConsoleOrigins writes, inside the identity directory. The node's own configuration management reads it; the agent never acts on it.

View Source
const CurrentReleaseFileName = "current-release"

CurrentReleaseFileName holds the agent version the SaaS reported as current at the last connect, or is absent when it reported none.

View Source
const (
	DefaultDir = "/etc/cube/advisor-agent"
)

Default locations on a CubeCOS node.

View Source
const PeersPendingFileName = "peers-pending"

PeersPendingFileName marks a fresh enrolment whose peers this node has not yet tried to enrol. Written by enroll, consumed on the first admitted connect.

View Source
const TrustedConsoleCAPath = "/etc/ssh/console-ca/cube-advisor.pub"

TrustedConsoleCAPath is the CA sshd trusts for console sessions. CubeCOS creates it at enrolment, and only when the token granted console access.

Variables

View Source
var (
	ErrTokenRejected   = errors.New("identity: pairing token rejected")
	ErrAlreadyEnrolled = errors.New("identity: this node already has an identity")
)

Enrollment errors a caller should distinguish, because the operator's next action differs for each: get a fresh token, fix connectivity, or re-enroll.

Functions

func CSR

func CSR(key *ecdsa.PrivateKey, clusterID, nodeID string) ([]byte, error)

CSR returns a PEM certificate signing request for nodeID within clusterID.

The node goes in CommonName, the cluster in the single-valued OrganizationalUnit — the SaaS refuses a CSR without exactly one OU, so a CSR built before this change cannot be admitted silently. It carries the public key and these names. It does not, and must not, carry the private key — see the test that inspects the bytes.

func Exists

func Exists(dir string) bool

Exists reports whether dir already holds a key and certificate. Enrollment consults this so a second run cannot silently replace a working identity — re-enrolling is a deliberate act, not an accident of running a command twice.

func Fingerprint

func Fingerprint(pub *ecdsa.PublicKey) (string, error)

Fingerprint is the SHA-256 of the public key in SPKI form, base64 encoded and prefixed — the same shape ssh prints.

This is the value an operator compares on screen during enrollment verify, so it must derive from the key alone: it has to be computable before a certificate exists, and identical on both sides.

func LoadServer

func LoadServer(dir string) (string, error)

LoadServer reads the tunnel address SaveServer persisted. A missing file is not an error — it just means enrolment predates this feature, or never resolved an address — so the caller (run) can fall back to requiring -server explicitly instead of failing to load an identity that is otherwise fine.

func MarkPeersPending added in v0.4.28

func MarkPeersPending(dir string) error

MarkPeersPending records that this node's peers still need enrolling.

func NewKey

func NewKey() (*ecdsa.PrivateKey, error)

NewKey generates a fresh keypair on this machine.

P-256 rather than Ed25519: it is what every TLS stack and every FIPS module on the target platforms already accepts, and enrollment is not the place to spend novelty budget.

func PublicKeyOf

func PublicKeyOf(k *ecdsa.PrivateKey) *ecdsa.PublicKey

PublicKeyOf exposes a key's public half, for callers computing a fingerprint before enrolment.

func RecordConsoleCA

func RecordConsoleCA(dir, line string) error

RecordConsoleCA writes the Advisor's console CA beside the identity. Public material, so world-readable; unchanged content is left alone.

func RecordConsoleOrigins

func RecordConsoleOrigins(dir string, origins map[string]string) error

RecordConsoleOrigins writes the origins the SaaS reported, one "<target> <origin>" per line.

Sorted and compared before writing: this runs on every connect and the node watches the file, so an unchanged set must not wake the watcher.

An empty map removes the file. Reporting no origins is a statement, and leaving the last set behind would keep a node trusting a withdrawn one.

func RecordCurrentRelease

func RecordCurrentRelease(dir, version string) error

RecordCurrentRelease writes the SaaS's current agent version beside the identity, for the node's own tooling (advisor status, cluster check, advisor upgrade) to compare with what is installed. Written only when it changes, so a watcher sees real changes and not every reconnect.

func Remove

func Remove(dir string) error

Remove deletes a stored identity.

Used only by an explicit re-enrolment. It is a separate function rather than something Save does implicitly, because silently replacing an identity is how a cluster loses the certificate the SaaS is currently accepting.

func RotateTrustedConsoleCA added in v0.4.28

func RotateTrustedConsoleCA(path, line string) (changed bool, err error)

RotateTrustedConsoleCA replaces the CA sshd trusts with line, but only when path already exists: console access is granted at enrolment, never here. sshd reads the file per authentication, so no reload is needed.

func SaveServer

func SaveServer(dir, addr string) error

SaveServer persists the tunnel address enrolment resolved, so a later `run` needs no operator argument. Mode 0644, unlike the key: this is not secret, it is the same host:port an operator could read straight off the SaaS.

It is a separate write from Save rather than a field on it, so an existing caller of Save is unaffected and a failure to persist the address (a read-only /etc, say) never looks like a failure to persist the identity.

func TakePeersPending added in v0.4.28

func TakePeersPending(dir string) bool

TakePeersPending reports whether the mark was set, and clears it.

func ValidConsoleCALine added in v0.4.28

func ValidConsoleCALine(line string) error

ValidConsoleCALine reports whether line is one SSH public key in authorized-keys form whose blob names the same key type as its first field.

Types

type EnrollRequest

type EnrollRequest = enrollproto.Request

The wire shapes live in pkg/enrollproto, which the SaaS imports too — one definition rather than two that must be kept in step.

type EnrollResponse

type EnrollResponse = enrollproto.Response

The wire shapes live in pkg/enrollproto, which the SaaS imports too — one definition rather than two that must be kept in step.

type Enroller

type Enroller struct {
	// BaseURL of the SaaS enrollment endpoint.
	BaseURL string
	// HTTPClient is overridable for tests and for sites behind an egress proxy.
	HTTPClient *http.Client
	// AgentVersion is reported so an operator can see what enrolled.
	AgentVersion string
}

Enroller exchanges a pairing token for a signed identity.

func (*Enroller) Enroll

func (e *Enroller) Enroll(ctx context.Context, clusterID, nodeID, token string) (*Identity, error)

Enroll generates a key, requests a certificate for nodeID in clusterID with the pairing token, and returns the resulting identity. It does not write anything to disk; the caller decides where an identity lives.

The token authenticates this one request and is deliberately not stored: it is single-use, and an unused copy on disk is a credential nobody is watching.

func (*Enroller) EnrollAndSave

func (e *Enroller) EnrollAndSave(ctx context.Context, dir, clusterID, nodeID, token string) (*Identity, error)

EnrollAndSave is the operator-facing path: enroll, then persist to dir.

It refuses when dir already holds an identity. Re-enrolling should be a deliberate act — running the command twice must not quietly invalidate the certificate the SaaS is currently accepting.

type Identity

type Identity struct {
	ClusterID string
	NodeID    string
	// ActionLevel and Consent as the Advisor reported them at enrolment;
	// not part of the saved identity — the toolplane keeps its own files.
	ActionLevel string
	Consent     string
	// ConsoleCA as the Advisor reported it; written beside the identity as
	// console-ca.pub for the OS to install.
	ConsoleCA string
	// contains filtered or unexported fields
}

Identity is this node's identity within its cluster: a private key that never leaves, the certificate the SaaS signed for it, and the CA that certificate chains to.

func Load

func Load(dir string) (*Identity, error)

Load reads an identity from dir.

It refuses a private key whose mode is looser than 0600. A key other users can read is not an identity, and continuing with a warning would make the agent's own logs the only record that its identity was readable.

func (*Identity) Fingerprint

func (i *Identity) Fingerprint() (string, error)

Fingerprint of this identity.

func (*Identity) Save

func (i *Identity) Save(dir string) error

Save writes the identity to dir with the key mode-restricted.

func (*Identity) TLSConfig

func (i *Identity) TLSConfig(serverName string) (*tls.Config, error)

TLSConfig builds the client configuration for the tunnel dial.

The CA obtained at enrollment is the only root trusted for this connection: the agent talks to the service that enrolled it, not to anything holding a certificate from a public CA.

Jump to

Keyboard shortcuts

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