Pki
c.Pki calls the API's Pki group. The certificates of the fleet, and the
rotation of the controller's key and of the NATS server's certificate.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx, params) | *Response[PKICertList] | pki:read | List the certificates of the fleet. |
Get(ctx, name, params) | *Response[PKICert] | pki:read | Get one certificate of a host. |
Rotation(ctx) | *Response[PKIKeyRotation] | pki:read | Show the rotation of the controller's key. |
Rotate(ctx) | *Response[PKIKeyRotation] | pki:write | Rotate the controller's key. |
Natscertrotation(ctx) | *Response[PKINATSCertRotation] | pki:read | Show the rotation of the NATS server's certificate. |
Natscertrotate(ctx) | *Response[PKINATSCertRotation] | pki:write | Rotate the NATS server's certificate. |
List
func (s *PkiService) List(
ctx context.Context,
params PkiListParams,
) (*Response[PKICertList], error)
List the certificates of the fleet.
Lists the certificates of the controller's host, the API's, the controller's metrics and the NATS server's, and the certificates that each agent reports in its registration, with their expiry. A certificate that a host has not made is not made.
It sends GET /api/pki/cert, and needs the permission pki:read.
The examples of the method's definition:
List the certificates of the fleet, go run pki.go list:
resp, err := c.Pki.List(ctx, client.PkiListParams{})
List the certificates of the fleet, with --hostname web-01,
go run pki.go list-2:
resp, err := c.Pki.List(ctx, client.PkiListParams{Hostname: "web-01"})
Get
func (s *PkiService) Get(
ctx context.Context,
name string,
params PkiGetParams,
) (*Response[PKICert], error)
Get one certificate of a host.
Reads one certificate of one host: the controller's host when the hostname is empty, or the agent of the hostname.
It sends GET /api/pki/cert/{name}, and needs the permission pki:read.
The examples of the method's definition:
Get one certificate of a host, go run pki.go get:
resp, err := c.Pki.Get(ctx, "api", client.PkiGetParams{})
Get one certificate of a host, with --name agent-metrics --hostname web-01,
go run pki.go get-2:
resp, err := c.Pki.Get(ctx, "agent-metrics", client.PkiGetParams{Hostname: "web-01"})
Rotation
func (s *PkiService) Rotation(
ctx context.Context,
) (*Response[PKIKeyRotation], error)
Show the rotation of the controller's key.
Shows the key that the controller signs jobs with, and during a rotation the key that it switches to, when it switches at the latest, and each admitted agent that the switch waits for, with whether it has the next key.
It sends GET /api/pki/key, and needs the permission pki:read.
The examples of the method's definition:
Show the rotation of the controller's key, go run pki.go rotation:
resp, err := c.Pki.Rotation(ctx)
Rotate
func (s *PkiService) Rotate(
ctx context.Context,
) (*Response[PKIKeyRotation], error)
Rotate the controller's key.
Starts the rotation of the controller's key, with no new admission of the agents. The controller makes the next key, and signs a record that gives it to the agents with its current key. Each agent takes it at its next heartbeat. The controller switches to the next key when each admitted agent that reported within controller.pki.rotation_grace_period has it, or when the grace period ends. An agent that does not have it then needs a new admission. A rotation in progress is not started again.
It sends POST /api/pki/key, and needs the permission pki:write.
The examples of the method's definition:
Rotate the controller's key, go run pki.go rotate:
resp, err := c.Pki.Rotate(ctx)
Natscertrotation
func (s *PkiService) Natscertrotation(
ctx context.Context,
) (*Response[PKINATSCertRotation], error)
Show the rotation of the NATS server's certificate.
Shows the certificate that the NATS server serves, and during a rotation the certificate that it switches to, when it switches at the latest, and each admitted agent that the switch waits for, with whether it trusts the next certificate.
It sends GET /api/pki/nats, and needs the permission pki:read.
The examples of the method's definition:
Show the rotation of the NATS server's certificate,
go run pki.go natscertrotation:
resp, err := c.Pki.Natscertrotation(ctx)
Natscertrotate
func (s *PkiService) Natscertrotate(
ctx context.Context,
) (*Response[PKINATSCertRotation], error)
Rotate the NATS server's certificate.
Starts the rotation of the NATS server's self-signed certificate, which each joined agent pins, with no restart and no new join. The controller makes the next certificate beside the current one, and signs a record that gives both to the agents. Each agent trusts the next one at its next heartbeat. The controller renames it into place when each admitted agent that reported within controller.pki.rotation_grace_period trusts it, or when the grace period ends, and NATS serves it at its next handshake. A rotation in progress is not started again. It runs on the controller's host, which must hold the NATS server's certificate, and refuses a certificate of the operator's cert_file.
It sends POST /api/pki/nats, and needs the permission pki:write.
The examples of the method's definition:
Rotate the NATS server's certificate, go run pki.go natscertrotate:
resp, err := c.Pki.Natscertrotate(ctx)
Types
The fields of each type are the properties of its schema in the API's spec.
PKICert
| Field | Type | Description |
|---|---|---|
Component | string | The component that serves it: controller, nats or agent. |
DaysLeft | int | The days that are left until it expires. |
Expires | time.Time | When the certificate expires. |
File | string | The certificate's file on the host. |
Fingerprint | string | The SHA-256 fingerprint of the certificate. |
FipsApproved | bool | Whether FIPS 186-5 and SP 800-131A approve the key and the signature algorithms. |
Hostname | string | The host that serves the certificate. |
Key | string | The algorithm and size of the public key, such as ECDSA P-256. |
Name | string | The name of the certificate, such as api or agent-metrics. |
Names | []string | The DNS names and the IP addresses that the certificate is for. |
Signature | string | The algorithm that signed the certificate, such as ECDSA-SHA256. |
Source | string | self-signed, which osapi made, or cert_file, the operator's. |
State | string | ok; not made, when the component has not started on the host; or unreadable, with the reason. |
PKICertList
| Field | Type | Description |
|---|---|---|
Items | []PKICert | |
TotalItems | int | The number of certificates. |
PKIKeyRotation
| Field | Type | Description |
|---|---|---|
Agents | []PKIKeyRotationAgent | The admitted agents that the switch waits for: each one that reported within the grace period. |
Current | string | The fingerprint of the key that the controller signs jobs with. |
Next | string | The fingerprint of the key that the controller switches to. Empty when no rotation is in progress. |
StartedAt | time.Time | When the rotation started. |
SwitchBy | time.Time | When the controller switches at the latest: the start and controller.pki.rotation_grace_period. It switches before, once each agent has the next key. |
PKIKeyRotationAgent
| Field | Type | Description |
|---|---|---|
HasNext | bool | Whether the agent reports that it has the next key. |
Hostname | string | The hostname of the agent. |
MachineID | string | The machine ID of the agent. |
PKINATSCertRotation
| Field | Type | Description |
|---|---|---|
Agents | []PKINATSCertRotationAgent | The admitted agents that the switch waits for: each one that reported within the grace period. |
Current | string | The fingerprint of the certificate that the NATS server serves. |
Next | string | The fingerprint of the certificate that the server switches to. Empty when no rotation is in progress. |
StartedAt | time.Time | When the rotation started. |
SwitchBy | time.Time | When the server switches at the latest: the start and controller.pki.rotation_grace_period. It switches before, once each agent trusts the next certificate. |
PKINATSCertRotationAgent
| Field | Type | Description |
|---|---|---|
HasNext | bool | Whether the agent reports that it trusts the next certificate. |
Hostname | string | The hostname of the agent. |
MachineID | string | The machine ID of the agent. |
Example
examples/sdk/client/pki.go
runs each example of this page. With no argument, it lists them.