certificate

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package certificate is the certificate behavior: the certificate authorities that the host trusts. It reads them through gohai on every platform, and on Linux adds and removes the ones that osapi deploys, from the Object Store, into the family's local directory, then rebuilds the trust store.

Index

Constants

This section is empty.

Variables

View Source
var Behavior = behavior.Register(behavior.Define(
	"certificate", "The certificate authorities that the host trusts",
	behavior.Node,
	behavior.API,
	behavior.Area(area.Security),
	behavior.CLI,
	behavior.Requires(object.Behavior),
	behavior.Requires(managedfile.Behavior),
	behavior.Platform(behavior.PlatformDebian, newWriter),
	behavior.Platform(behavior.PlatformSUSE, newWriter),
	behavior.Platform(behavior.PlatformLinux, newWriter),
	behavior.Platform(behavior.PlatformDarwin, newReader),
	behavior.RunsOnPlatform(behavior.PlatformDarwin, "security"),

	behavior.SudoOnPlatform(behavior.PlatformDebian, "update-ca-certificates"),
	behavior.SudoOnPlatform(behavior.PlatformSUSE, "update-ca-certificates"),
	behavior.SudoOnPlatform(behavior.PlatformLinux, "update-ca-trust"),
	behavior.Writes(
		"/usr/local/share/ca-certificates/osapi-*.crt",
		"/etc/pki/ca-trust/source/anchors/osapi-*.crt",
		"/etc/pki/trust/anchors/osapi-*.crt",
		"/etc/ca-certificates/trust-source/anchors/osapi-*.crt",
	),
	behavior.Validator("ca_name", caNameRE.MatchString,
		func(t rule.Target) { t.Pattern(caNamePattern) },
		"is not a name of a CA that a path can hold: it has a slash, a % or a control character"),
	behavior.Read("list", List).
		Describe("List the certificate authorities that the host trusts").
		Explain("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.").
		Example("A Debian host with a system CA", ListInput{}, []Entry{debRoot},
			behavior.OnPlatform(behavior.PlatformDebian),
			behavior.Exists(debSystem, pem),
		).
		Example("A CA that osapi deployed reads by its name", ListInput{},
			[]Entry{debRoot, debManaged},
			behavior.OnPlatform(behavior.PlatformDebian),
			behavior.Exists(debSystem, pem),
			stored, deployed,
		).
		Example("A host of the RHEL family", ListInput{}, []Entry{rhelRoot},
			behavior.OnPlatform(behavior.PlatformLinux),
			behavior.Exists(rhelSys, pem),
		).
		Example("A CA that osapi deployed on SUSE", ListInput{}, []Entry{suseManaged},
			behavior.OnPlatform(behavior.PlatformSUSE),
			stored, deployed,
		).
		Example("A Mac", ListInput{}, []Entry{macRoot},
			behavior.OnPlatform(behavior.PlatformDarwin),
			behavior.Prints("security find-certificate -a -p "+systemKeychain, pem),
			behavior.Prints("security find-certificate -a -p "+localKeychain, ""),
		),
	behavior.Read("get", Get).Key("name").
		Describe("Get one certificate authority").
		Explain("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.").
		Example("A CA that osapi deployed, by the name it was deployed with",
			GetInput{Name: "internal-ca"}, debManaged,
			behavior.OnPlatform(behavior.PlatformDebian),
			stored, deployed,
		).
		Example("A CA that osapi deployed on the RHEL family",
			GetInput{Name: "internal-ca"}, rhelManaged,
			behavior.OnPlatform(behavior.PlatformLinux),
			stored, deployed,
		).
		Example("A CA that osapi deployed on SUSE",
			GetInput{Name: "internal-ca"}, suseManaged,
			behavior.OnPlatform(behavior.PlatformSUSE),
			stored, deployed,
		).
		Example("A CA of a Mac", GetInput{Name: "osapi example CA"}, macRoot,
			behavior.OnPlatform(behavior.PlatformDarwin),
			behavior.Prints("security find-certificate -a -p "+systemKeychain, pem),
			behavior.Prints("security find-certificate -a -p "+localKeychain, ""),
		).
		Fails("A CA that the host does not trust", GetInput{Name: "nothing"}, "not found").
		Fails("A name with a %, which an encoded slash has", GetInput{Name: "mozilla%2FExample_Root"}, "ca_name").
		Fails("A name of 256 characters", GetInput{Name: strings.Repeat("a", 256)}, "max"),
	behavior.Write("create", Create).
		On(behavior.PlatformDebian, behavior.PlatformSUSE, behavior.PlatformLinux).
		Describe("Add a certificate authority to the trust store").
		Explain("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.").
		Example("Add a CA", CreateInput{Name: "internal-ca", Object: "internal-ca.pem"},
			Result{Name: "internal-ca", Changed: true},
			behavior.OnPlatform(behavior.PlatformDebian),
			stored,
			behavior.Wrote(debPath, pem),
			behavior.Ran("update-ca-certificates"),
			behavior.Reads(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true, Object: "internal-ca.pem"}),
		).
		Example("Add a CA on the RHEL family", CreateInput{Name: "internal-ca", Object: "internal-ca.pem"},
			Result{Name: "internal-ca", Changed: true},
			behavior.OnPlatform(behavior.PlatformLinux),
			stored,
			behavior.Wrote(rhelPath, pem),
			behavior.Ran("update-ca-trust"),
			behavior.Reads(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true, Object: "internal-ca.pem"}),
		).
		Example("Add a CA on SUSE", CreateInput{Name: "internal-ca", Object: "internal-ca.pem"},
			Result{Name: "internal-ca", Changed: true},
			behavior.OnPlatform(behavior.PlatformSUSE),
			stored,
			behavior.Wrote(susePath, pem),
			behavior.Ran("update-ca-certificates"),
			behavior.Reads(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true, Object: "internal-ca.pem"}),
		).
		Example("A CA that osapi deployed with the same content",
			CreateInput{Name: "internal-ca", Object: "internal-ca.pem"},
			Result{Name: "internal-ca"},
			stored, deployed,
			behavior.Reads(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true, Object: "internal-ca.pem"}),
		).
		Fails("A file that osapi did not write", CreateInput{Name: "internal-ca", Object: "internal-ca.pem"},
			"osapi did not deploy it",
			stored, behavior.Exists(debPath, pem), behavior.Exists(rhelPath, pem),
			behavior.Exists(susePath, pem),
		).
		Fails("A name that is an option", CreateInput{Name: "-r", Object: "internal-ca.pem"},
			"not a valid name").
		Fails("No object", CreateInput{Name: "internal-ca"}, "required").
		Fails("A name with a space", CreateInput{Name: "a b", Object: "internal-ca.pem"}, "resource_name"),
	behavior.Write("update", Update).Key("name").
		On(behavior.PlatformDebian, behavior.PlatformSUSE, behavior.PlatformLinux).
		Describe("Write a certificate authority that osapi deployed again").
		Explain("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.").
		Example("Write a CA from a new object", UpdateInput{Name: "internal-ca", Object: "internal-ca-2.pem"},
			Result{Name: "internal-ca", Changed: true},
			behavior.OnPlatform(behavior.PlatformDebian),
			stored, stored2, deployed,
			behavior.Wrote(debPath, pem2),
			behavior.Ran("update-ca-certificates"),
			behavior.Reads(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true, Object: "internal-ca-2.pem"}),
		).
		Example("Write a CA from a new object on the RHEL family",
			UpdateInput{Name: "internal-ca", Object: "internal-ca-2.pem"},
			Result{Name: "internal-ca", Changed: true},
			behavior.OnPlatform(behavior.PlatformLinux),
			stored, stored2, deployed,
			behavior.Wrote(rhelPath, pem2),
			behavior.Ran("update-ca-trust"),
			behavior.Reads(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true, Object: "internal-ca-2.pem"}),
		).
		Example("Write a CA from a new object on SUSE",
			UpdateInput{Name: "internal-ca", Object: "internal-ca-2.pem"},
			Result{Name: "internal-ca", Changed: true},
			behavior.OnPlatform(behavior.PlatformSUSE),
			stored, stored2, deployed,
			behavior.Wrote(susePath, pem2),
			behavior.Ran("update-ca-certificates"),
			behavior.Reads(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true, Object: "internal-ca-2.pem"}),
		).
		Example("The object that it was deployed from", UpdateInput{Name: "internal-ca"},
			Result{Name: "internal-ca"},
			stored, deployed,
			behavior.Reads(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true}),
		).
		Fails("A CA that osapi did not deploy", UpdateInput{Name: "nothing"}, "not found").
		Fails("A name that is an option", UpdateInput{Name: "-r"}, "not a valid name").
		Fails("A name with a space", UpdateInput{Name: "a b"}, "resource_name"),
	behavior.Write("delete", Delete).Key("name").
		On(behavior.PlatformDebian, behavior.PlatformSUSE, behavior.PlatformLinux).
		Describe("Remove a certificate authority that osapi deployed").
		Explain("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.").
		Example("Remove a CA", DeleteInput{Name: "internal-ca"},
			Result{Name: "internal-ca", Changed: true},
			behavior.OnPlatform(behavior.PlatformDebian),
			stored, deployed,
			behavior.Removed(debPath),
			behavior.Ran("update-ca-certificates --fresh"),
			behavior.ReadsNone(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true}, "name", "managed"),
		).
		Example("Remove a CA on the RHEL family", DeleteInput{Name: "internal-ca"},
			Result{Name: "internal-ca", Changed: true},
			behavior.OnPlatform(behavior.PlatformLinux),
			stored, deployed,
			behavior.Removed(rhelPath),
			behavior.Ran("update-ca-trust"),
			behavior.ReadsNone(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true}, "name", "managed"),
		).
		Example("Remove a CA on SUSE", DeleteInput{Name: "internal-ca"},
			Result{Name: "internal-ca", Changed: true},
			behavior.OnPlatform(behavior.PlatformSUSE),
			stored, deployed,
			behavior.Removed(susePath),
			behavior.Ran("update-ca-certificates --fresh"),
			behavior.ReadsNone(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true}, "name", "managed"),
		).
		Example("A CA that osapi did not deploy", DeleteInput{Name: "internal-ca"},
			Result{Name: "internal-ca"},
			behavior.ReadsNone(GetInput{Name: "internal-ca"}, Entry{Name: "internal-ca", Managed: true}, "name", "managed"),
		).
		Fails("A name that is an option", DeleteInput{Name: "-r"}, "not a valid name").
		Fails("A name with a space", DeleteInput{Name: "a b"}, "resource_name"),
))

Behavior is the certificate authorities that the host trusts. gohai reads each one. osapi writes and removes the CAs it deploys only: each has a file osapi-<name>.crt in the family's local directory that managedfile has a record of, whose content is an object that a person uploads once with osapi client file upload.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	Name   string `` /* 167-byte string literal not displayed */
	Object string `` /* 150-byte string literal not displayed */
}

CreateInput is the CA to add to the trust store, from an object in the Object Store.

type DeleteInput

type DeleteInput struct {
	Name string `json:"name" validate:"required,resource_name" doc:"The CA that osapi deployed, such as internal-ca"`
}

DeleteInput names the CA that osapi deployed to remove.

type Entry

type Entry struct {
	Name        string `json:"name"                  doc:"The CA: the name it was deployed with for a CA that osapi deployed, else its file's name"`
	Path        string `json:"path"                  doc:"The file, or on macOS the keychain, that has it"`
	Source      string `json:"source"                doc:"system for a CA of the distribution, local for one an administrator added"`
	Enabled     bool   `json:"enabled"               doc:"Whether the host trusts it: false for a system CA that the trust store turns off"`
	Subject     string `` /* 132-byte string literal not displayed */
	Fingerprint string `` /* 142-byte string literal not displayed */
	NotAfter    string `` /* 132-byte string literal not displayed */
	Managed     bool   `json:"managed"               doc:"Whether osapi deployed it, and its writes change it"`
	Object      string `` /* 132-byte string literal not displayed */
}

Entry is a certificate authority that the host trusts.

func Get

func Get(
	ctx context.Context,
	p Provider,
	in GetInput,
) (Entry, error)

Get reads one certificate authority.

func List

func List(
	ctx context.Context,
	p Provider,
	_ ListInput,
) ([]Entry, error)

List reads the certificate authorities that the host trusts.

type GetInput

type GetInput struct {
	Name string `` /* 233-byte string literal not displayed */
}

GetInput names the certificate authority to read.

type ListInput

type ListInput struct{}

ListInput is list's input: it takes none.

type Provider

type Provider interface {
	List(ctx context.Context) ([]Entry, error)
	Get(ctx context.Context, name string) (Entry, error)
	Deploy(ctx context.Context, name string, object string, create bool) (bool, error)
	Remove(ctx context.Context, name string) (bool, error)
}

Provider reads the certificate authorities that the host trusts, and adds and removes the ones that osapi deploys. reader.go reads them through gohai on every platform, and writer.go changes them on Linux.

type Result

type Result struct {
	Name    string `json:"name"    doc:"The CA"`
	Changed bool   `json:"changed" doc:"Whether the host changed"`
}

Result is what a write did.

func Create

func Create(
	ctx context.Context,
	p Provider,
	in CreateInput,
) (Result, error)

Create adds a certificate authority to the trust store.

func Delete

func Delete(
	ctx context.Context,
	p Provider,
	in DeleteInput,
) (Result, error)

Delete removes a certificate authority that osapi deployed.

func Update

func Update(
	ctx context.Context,
	p Provider,
	in UpdateInput,
) (Result, error)

Update writes a certificate authority that osapi deployed again.

type UpdateInput

type UpdateInput struct {
	Name   string `json:"name"             validate:"required,resource_name" doc:"The CA that osapi deployed, such as internal-ca"`
	Object string `` /* 132-byte string literal not displayed */
}

UpdateInput writes a CA that osapi deployed again, from its object or from a different one.

Directories

Path Synopsis
Package mocks holds the generated double of the certificate provider, for the methods' tests.
Package mocks holds the generated double of the certificate provider, for the methods' tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL