Documentation
¶
Overview ¶
Package keyrotation rotates the controller's key with no new admission of the agents. The controller makes the next key, and writes a record to the state bucket that its current key signs. Each agent keeps the next key at its next heartbeat, and its registration reports it. When each admitted agent that reported within the grace period has it, or the grace period ends, the controller switches to the next key, and writes a record that the new key signs. The agents then take the new key, and keep the old one as the previous one, which still verifies the jobs that it signed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Admitted ¶
Admitted lists the admission records: the agents that the switch waits for are the admitted ones.
type Config ¶
type Config struct {
// KV and Bucket are the state bucket, which holds the record.
KV KV
Bucket string
// Keys are the controller's keys, which Start and the switch read and
// replace.
Keys *pki.Manager
// Admitted and Seen are the admitted agents and when each last
// reported. A Rotation with none of them, such as the one of the CLI,
// can start a rotation and show it, and does not switch.
Admitted Admitted
Seen Seen
// Grace is how long a rotation waits for the agents before it switches.
Grace time.Duration
// Logger logs the start and the switch.
Logger *slog.Logger
// Now is the clock. Nil is time.Now.
Now func() time.Time
}
Config is what a Rotation uses.
type KV ¶
type KV interface {
KVGet(ctx context.Context, bucket string, key string) (jetstream.KeyValueEntry, error)
KVCreate(ctx context.Context, bucket string, key string, value []byte) (uint64, error)
KVUpdate(
ctx context.Context,
bucket string,
key string,
value []byte,
revision uint64,
) (uint64, error)
}
KV is the part of a NATS client that the rotation uses: the record in the state bucket. A *natsclient.Client is one.
type Rotation ¶
type Rotation struct {
// contains filtered or unexported fields
}
Rotation rotates the controller's key.
func (*Rotation) Load ¶
Load takes the record at the start of the controller: the previous key after a switch keeps verifying the records that it signed, and a switch that stopped after its renames writes its record.
func (*Rotation) Run ¶
Run switches the key when Step says so, every interval, until ctx is done. An error of one step is logged, and the next step tries again.
func (*Rotation) Start ¶
Start starts a rotation: it makes the next key beside the current one, and writes the record that gives it to the agents. A rotation in progress is not started again: Start shows it.
type Seen ¶
type Seen interface {
ListAgents(ctx context.Context) ([]job.AgentInfo, error)
AgentsLastSeen(ctx context.Context) (map[string]time.Time, error)
}
Seen tells which admitted agents still report: the agents in the registry now, with the controller keys that each reports, and the last report of each machine. The job client is one.
type Status ¶
type Status struct {
// Current is the fingerprint of the key that the controller signs with.
Current string
// Next is the fingerprint of the key that it switches to, during a
// rotation.
Next string
// StartedAt is when the rotation started, and SwitchBy when it switches
// at the latest.
StartedAt time.Time
SwitchBy time.Time
// Agents are the admitted agents that the switch waits for, and whether
// each has the next key.
Agents []Agent
}
Status is a rotation as the API shows it.