certificates: update controllers to understand signerName field

Signed-off-by: James Munnelly <james.munnelly@jetstack.io>

Kubernetes-commit: d5dae048983cd299cdce9d2703f564bf4bd246ee
This commit is contained in:
James Munnelly
2020-02-17 23:06:02 +00:00
committed by Kubernetes Publisher
parent dd730ded40
commit e8be24fd4c
2 changed files with 10 additions and 4 deletions

View File

@@ -85,6 +85,9 @@ type Config struct {
// If no template is available, nil may be returned, and no certificate will be requested. // If no template is available, nil may be returned, and no certificate will be requested.
// If specified, takes precedence over Template. // If specified, takes precedence over Template.
GetTemplate func() *x509.CertificateRequest GetTemplate func() *x509.CertificateRequest
// SignerName is the name of the certificate signer that should sign certificates
// generated by the manager.
SignerName string
// Usages is the types of usages that certificates generated by the manager // Usages is the types of usages that certificates generated by the manager
// can be used for. // can be used for.
Usages []certificates.KeyUsage Usages []certificates.KeyUsage
@@ -174,6 +177,7 @@ type manager struct {
lastRequest *x509.CertificateRequest lastRequest *x509.CertificateRequest
dynamicTemplate bool dynamicTemplate bool
signerName string
usages []certificates.KeyUsage usages []certificates.KeyUsage
forceRotation bool forceRotation bool
@@ -219,6 +223,7 @@ func NewManager(config *Config) (Manager, error) {
clientFn: config.ClientFn, clientFn: config.ClientFn,
getTemplate: getTemplate, getTemplate: getTemplate,
dynamicTemplate: config.GetTemplate != nil, dynamicTemplate: config.GetTemplate != nil,
signerName: config.SignerName,
usages: config.Usages, usages: config.Usages,
certStore: config.CertificateStore, certStore: config.CertificateStore,
cert: cert, cert: cert,
@@ -424,7 +429,7 @@ func (m *manager) rotateCerts() (bool, error) {
// Call the Certificate Signing Request API to get a certificate for the // Call the Certificate Signing Request API to get a certificate for the
// new private key. // new private key.
req, err := csr.RequestCertificate(client, csrPEM, "", m.usages, privateKey) req, err := csr.RequestCertificate(client, csrPEM, "", m.signerName, m.usages, privateKey)
if err != nil { if err != nil {
utilruntime.HandleError(fmt.Errorf("Failed while requesting a signed certificate from the master: %v", err)) utilruntime.HandleError(fmt.Errorf("Failed while requesting a signed certificate from the master: %v", err))
if m.certificateRenewFailure != nil { if m.certificateRenewFailure != nil {

View File

@@ -46,7 +46,7 @@ import (
// status, once approved by API server, it will return the API server's issued // status, once approved by API server, it will return the API server's issued
// certificate (pem-encoded). If there is any errors, or the watch timeouts, it // certificate (pem-encoded). If there is any errors, or the watch timeouts, it
// will return an error. // will return an error.
func RequestCertificate(client certificatesclient.CertificateSigningRequestInterface, csrData []byte, name string, usages []certificates.KeyUsage, privateKey interface{}) (req *certificates.CertificateSigningRequest, err error) { func RequestCertificate(client certificatesclient.CertificateSigningRequestInterface, csrData []byte, name string, signerName string, usages []certificates.KeyUsage, privateKey interface{}) (req *certificates.CertificateSigningRequest, err error) {
csr := &certificates.CertificateSigningRequest{ csr := &certificates.CertificateSigningRequest{
// Username, UID, Groups will be injected by API server. // Username, UID, Groups will be injected by API server.
TypeMeta: metav1.TypeMeta{Kind: "CertificateSigningRequest"}, TypeMeta: metav1.TypeMeta{Kind: "CertificateSigningRequest"},
@@ -54,8 +54,9 @@ func RequestCertificate(client certificatesclient.CertificateSigningRequestInter
Name: name, Name: name,
}, },
Spec: certificates.CertificateSigningRequestSpec{ Spec: certificates.CertificateSigningRequestSpec{
Request: csrData, Request: csrData,
Usages: usages, Usages: usages,
SignerName: &signerName,
}, },
} }
if len(csr.Name) == 0 { if len(csr.Name) == 0 {