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 ¶
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 ¶
var ErrIncomplete = errors.New("incomplete set of kube-apiserver PKI files")
ErrIncomplete is returned by Ensure when only some of the files exist.
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 ¶
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.