Skip to main content

Certificate

c.Certificate calls the API's Certificate group. The certificate authorities that the host trusts.

Methods​

MethodReturnsPermissionDescription
List(ctx, hostname)*Response[Collection[CertificateEntry]]certificate:readList the certificate authorities that the host trusts.
Create(ctx, hostname, input)*Response[Collection[CertificateResult]]certificate:writeAdd a certificate authority to the trust store.
Get(ctx, hostname, name)*Response[Collection[CertificateEntry]]certificate:readGet one certificate authority.
Update(ctx, hostname, input)*Response[Collection[CertificateResult]]certificate:writeWrite a certificate authority that osapi deployed again.
Delete(ctx, hostname, name)*Response[Collection[CertificateResult]]certificate:writeRemove a certificate authority that osapi deployed.

List​

func (s *CertificateService) List(
ctx context.Context,
hostname string,
) (*Response[Collection[CertificateEntry]], error)

List the certificate authorities that the host trusts.

Lists each CA of the trust store through gohai: the distribution's and the local ones on Linux, from the family's directories, and the system keychains on macOS, each with its subject, fingerprint and expiry. A CA that osapi deployed reads by the name that it was deployed with, not its file's osapi- name, and is managed.

It sends GET /api/node/{hostname}/certificate, and needs the permission certificate:read.

The examples of the method's definition:

A Debian host with a system CA, go run certificate.go list:

resp, err := c.Certificate.List(ctx, target)

Create​

func (s *CertificateService) Create(
ctx context.Context,
hostname string,
input CertificateCreateInput,
) (*Response[Collection[CertificateResult]], error)

Add a certificate authority to the trust store.

Writes the PEM of the object as a file with the osapi- prefix, such as osapi-internal-ca.crt for internal-ca, in the family's local directory: /usr/local/share/ca-certificates on the Debian family, /etc/pki/trust/anchors on SUSE, /etc/pki/ca-trust/source/anchors on RHEL and Fedora. Then it rebuilds the trust store: with update-ca-certificates on the Debian family and SUSE, and with update-ca-trust on the others. Alpine reports skipped. A CA that osapi deployed already with the same content does not change and reports changed: false. A file of that name that osapi did not write is refused. macOS reports skipped.

It sends POST /api/node/{hostname}/certificate, and needs the permission certificate:write.

The examples of the method's definition:

Add a CA, go run certificate.go create:

resp, err := c.Certificate.Create(ctx, target, client.CertificateCreateInput{
Name: "internal-ca",
Object: "internal-ca.pem",
})

Get​

func (s *CertificateService) Get(
ctx context.Context,
hostname string,
name string,
) (*Response[Collection[CertificateEntry]], error)

Get one certificate authority.

Reads one CA from the same list, by the name that list gives it. A CA that the host does not trust is not found. A name with a slash, such as a system CA of the Debian family, is in list only.

It sends GET /api/node/{hostname}/certificate/{name}, and needs the permission certificate:read.

The examples of the method's definition:

A CA that osapi deployed, by the name it was deployed with, go run certificate.go get:

resp, err := c.Certificate.Get(ctx, target, "internal-ca")

A CA of a Mac, go run certificate.go get-2:

resp, err := c.Certificate.Get(ctx, target, "osapi example CA")

Update​

func (s *CertificateService) Update(
ctx context.Context,
hostname string,
input CertificateUpdateInput,
) (*Response[Collection[CertificateResult]], error)

Write a certificate authority that osapi deployed again.

Writes the CA from the object, or from the one that it was deployed from when the object is empty, and rebuilds the trust store when the file changed. A CA that osapi did not deploy is not found. macOS reports skipped.

It sends PUT /api/node/{hostname}/certificate/{name}, and needs the permission certificate:write.

The examples of the method's definition:

Write a CA from a new object, go run certificate.go update:

resp, err := c.Certificate.Update(ctx, target, client.CertificateUpdateInput{
Name: "internal-ca",
Object: "internal-ca-2.pem",
})

The object that it was deployed from, go run certificate.go update-2:

resp, err := c.Certificate.Update(ctx, target, client.CertificateUpdateInput{Name: "internal-ca"})

Delete​

func (s *CertificateService) Delete(
ctx context.Context,
hostname string,
name string,
) (*Response[Collection[CertificateResult]], error)

Remove a certificate authority that osapi deployed.

Removes the file of the CA and rebuilds the trust store: with update-ca-certificates --fresh on the Debian family and SUSE, which removes the links of the CA from /etc/ssl/certs, and update-ca-trust on the RHEL family. A CA that osapi did not deploy does not change and reports changed: false: a system CA is not osapi's to remove. macOS reports skipped.

It sends DELETE /api/node/{hostname}/certificate/{name}, and needs the permission certificate:write.

The examples of the method's definition:

Remove a CA, go run certificate.go delete:

resp, err := c.Certificate.Delete(ctx, target, "internal-ca")

Types​

The fields of each type are the properties of its schema in the API's spec.

CertificateCreateInput​

FieldTypeDescription
NamestringThe name of the CA, such as internal-ca, which osapi writes as osapi-internal-ca.crt.
ObjectstringThe object of the Object Store that has the PEM of the CA, as osapi client file upload stored it.

CertificateEntry​

FieldTypeDescription
EnabledboolWhether the host trusts it: false for a system CA that the trust store turns off.
ErrorstringError message if the agent failed.
FingerprintstringThe SHA-256 of the certificate, in hex.
HostnamestringHostname of the agent that produced this result.
ManagedboolWhether osapi deployed it, and its writes change it.
NamestringThe CA: the name it was deployed with for a CA that osapi deployed, else its file's name.
NotAfterstringWhen it expires.
ObjectstringThe object that osapi deployed it from.
PathstringThe file, or on macOS the keychain, that has it.
Sourcestringsystem for a CA of the distribution, local for one an administrator added.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.
SubjectstringIts subject, such as CN=ISRG Root X1,O=Internet Security Research Group,C=US.

CertificateResult​

FieldTypeDescription
ChangedboolWhether the host changed.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
NamestringThe CA.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

CertificateUpdateInput​

FieldTypeDescription
NamestringThe name of the path. The CA that osapi deployed, such as internal-ca.
ObjectstringThe object that has the PEM; the one it was deployed from when empty.

RowStatus​

What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

A string, one of ok, failed, skipped, timeout.

Example​

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