Certificate
c.Certificate calls the API's Certificate group. The certificate authorities
that the host trusts.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx, hostname) | *Response[Collection[CertificateEntry]] | certificate:read | List the certificate authorities that the host trusts. |
Create(ctx, hostname, input) | *Response[Collection[CertificateResult]] | certificate:write | Add a certificate authority to the trust store. |
Get(ctx, hostname, name) | *Response[Collection[CertificateEntry]] | certificate:read | Get one certificate authority. |
Update(ctx, hostname, input) | *Response[Collection[CertificateResult]] | certificate:write | Write a certificate authority that osapi deployed again. |
Delete(ctx, hostname, name) | *Response[Collection[CertificateResult]] | certificate:write | Remove 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
| Field | Type | Description |
|---|---|---|
Name | string | The name of the CA, such as internal-ca, which osapi writes as osapi-internal-ca.crt. |
Object | string | The object of the Object Store that has the PEM of the CA, as osapi client file upload stored it. |
CertificateEntry
| Field | Type | Description |
|---|---|---|
Enabled | bool | Whether the host trusts it: false for a system CA that the trust store turns off. |
Error | string | Error message if the agent failed. |
Fingerprint | string | The SHA-256 of the certificate, in hex. |
Hostname | string | Hostname of the agent that produced this result. |
Managed | bool | Whether osapi deployed it, and its writes change it. |
Name | string | The CA: the name it was deployed with for a CA that osapi deployed, else its file's name. |
NotAfter | string | When it expires. |
Object | string | The object that osapi deployed it from. |
Path | string | The file, or on macOS the keychain, that has it. |
Source | string | system for a CA of the distribution, local for one an administrator added. |
Status | 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. |
Subject | string | Its subject, such as CN=ISRG Root X1,O=Internet Security Research Group,C=US. |
CertificateResult
| Field | Type | Description |
|---|---|---|
Changed | bool | Whether the host changed. |
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Name | string | The CA. |
Status | 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. |
CertificateUpdateInput
| Field | Type | Description |
|---|---|---|
Name | string | The name of the path. The CA that osapi deployed, such as internal-ca. |
Object | string | The 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.