Skip to main content

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​

MethodReturnsPermissionDescription
List(ctx, params)*Response[PKICertList]pki:readList the certificates of the fleet.
Get(ctx, name, params)*Response[PKICert]pki:readGet one certificate of a host.
Rotation(ctx)*Response[PKIKeyRotation]pki:readShow the rotation of the controller's key.
Rotate(ctx)*Response[PKIKeyRotation]pki:writeRotate the controller's key.
Natscertrotation(ctx)*Response[PKINATSCertRotation]pki:readShow the rotation of the NATS server's certificate.
Natscertrotate(ctx)*Response[PKINATSCertRotation]pki:writeRotate 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​

FieldTypeDescription
ComponentstringThe component that serves it: controller, nats or agent.
DaysLeftintThe days that are left until it expires.
Expirestime.TimeWhen the certificate expires.
FilestringThe certificate's file on the host.
FingerprintstringThe SHA-256 fingerprint of the certificate.
FipsApprovedboolWhether FIPS 186-5 and SP 800-131A approve the key and the signature algorithms.
HostnamestringThe host that serves the certificate.
KeystringThe algorithm and size of the public key, such as ECDSA P-256.
NamestringThe name of the certificate, such as api or agent-metrics.
Names[]stringThe DNS names and the IP addresses that the certificate is for.
SignaturestringThe algorithm that signed the certificate, such as ECDSA-SHA256.
Sourcestringself-signed, which osapi made, or cert_file, the operator's.
Statestringok; not made, when the component has not started on the host; or unreadable, with the reason.

PKICertList​

FieldTypeDescription
Items[]PKICert
TotalItemsintThe number of certificates.

PKIKeyRotation​

FieldTypeDescription
Agents[]PKIKeyRotationAgentThe admitted agents that the switch waits for: each one that reported within the grace period.
CurrentstringThe fingerprint of the key that the controller signs jobs with.
NextstringThe fingerprint of the key that the controller switches to. Empty when no rotation is in progress.
StartedAttime.TimeWhen the rotation started.
SwitchBytime.TimeWhen 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​

FieldTypeDescription
HasNextboolWhether the agent reports that it has the next key.
HostnamestringThe hostname of the agent.
MachineIDstringThe machine ID of the agent.

PKINATSCertRotation​

FieldTypeDescription
Agents[]PKINATSCertRotationAgentThe admitted agents that the switch waits for: each one that reported within the grace period.
CurrentstringThe fingerprint of the certificate that the NATS server serves.
NextstringThe fingerprint of the certificate that the server switches to. Empty when no rotation is in progress.
StartedAttime.TimeWhen the rotation started.
SwitchBytime.TimeWhen 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​

FieldTypeDescription
HasNextboolWhether the agent reports that it trusts the next certificate.
HostnamestringThe hostname of the agent.
MachineIDstringThe machine ID of the agent.

Example​

examples/sdk/client/pki.go runs each example of this page. With no argument, it lists them.