kubecerts

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 25 Imported by: ? 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 kubecerts generates the certificates, keys, and kubeconfig that a kube-apiserver, and the clients that talk to it, need to run with TLS and client certificate authentication.

Index

Constants

View Source
const (
	CACertFile            = "ca.crt"
	CAKeyFile             = "ca.key"
	ServerCertFile        = "server.crt"
	ServerKeyFile         = "server.key"
	ServiceAccountKeyFile = "service-account-key.pem"
	KubeconfigFile        = "kubeconfig"
)

File names in Config.Dir.

Variables

View Source
var ErrIncomplete = errors.New("incomplete set of kube-apiserver PKI files")

ErrIncomplete is returned by Ensure when only some of the files exist.

View Source
var ErrUnsafe = errors.New("kube-apiserver PKI directory is not safe to use")

ErrUnsafe is returned by Ensure when a user other than the current one or root could change the directory or one of its files, and so could replace the CA or the kubeconfig to take control of the kube-apiserver.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Dir is the directory holding the files. It is created if missing.
	Dir string
	// Host is the kube-apiserver name or IP address that the kubeconfig points
	// to. It is also added to the server certificate's SANs.
	Host string
	// Port is the kube-apiserver port that the kubeconfig points to.
	Port int
	// SANs are additional DNS names or IP addresses for the server
	// certificate. Empty values are ignored.
	SANs []string
}

Config describes the files that Ensure generates.

type Result

type Result struct {
	// Dir is the absolute path of the directory holding the files.
	Dir string
	// Generated is true when Ensure wrote the files, and false when they
	// already existed.
	Generated bool
}

Result describes the files that Ensure found or generated.

func Ensure

func Ensure(ctx context.Context, c Config) (*Result, error)

Ensure makes sure that c.Dir holds a CA, a kube-apiserver serving certificate signed by it, a service account signing key, and a kubeconfig that authenticates as a member of the system:masters group. Every key is ECDSA P-256 and every certificate is valid for 10 years.

If none of the files exist, Ensure generates all of them. If all of them exist, Ensure leaves them untouched and ignores every field of c except Dir, so changes to the other fields only take effect once the files are removed. If only some exist, Ensure returns an error wrapping ErrIncomplete rather than generate a new CA that the existing files do not trust.

c.Dir must be a directory, not a symbolic link, and its files must be regular files. Ensure returns an error wrapping ErrUnsafe if c.Dir or one of its files is owned by a user other than the current one or root, or is writable by its group or others.

Every file is staged before any is written, so a failure while generating or staging leaves c.Dir unchanged.

func (*Result) Path

func (r *Result) Path(name string) string

Path returns the absolute path of the named file.

Jump to

Keyboard shortcuts

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