0b300cbe42
To make an impersonation request, first make a TokenCredentialRequest to get a certificate. That cert will either be issued by the Kube API server's CA or by a new CA specific to the impersonator. Either way, you can then make a request to the impersonator and present that client cert for auth and the impersonator will accept it and make the impesonation call on your behalf. The impersonator http handler now borrows some Kube library code to handle request processing. This will allow us to more closely mimic the behavior of a real API server, e.g. the client cert auth will work exactly like the real API server. Signed-off-by: Monis Khan <mok@vmware.com>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package dynamiccertauthority implements a x509 certificate authority capable of issuing
|
|
// certificates from a dynamically updating CA keypair.
|
|
package dynamiccertauthority
|
|
|
|
import (
|
|
"crypto/x509/pkix"
|
|
"time"
|
|
|
|
"k8s.io/apiserver/pkg/server/dynamiccertificates"
|
|
|
|
"go.pinniped.dev/internal/certauthority"
|
|
)
|
|
|
|
// CA is a type capable of issuing certificates.
|
|
type CA struct {
|
|
provider dynamiccertificates.CertKeyContentProvider
|
|
}
|
|
|
|
// New creates a new CA, ready to issue certs whenever the provided provider has a keypair to
|
|
// provide.
|
|
func New(provider dynamiccertificates.CertKeyContentProvider) *CA {
|
|
return &CA{
|
|
provider: provider,
|
|
}
|
|
}
|
|
|
|
// IssuePEM issues a new server certificate for the given identity and duration, returning it as a
|
|
// pair of PEM-formatted byte slices for the certificate and private key.
|
|
func (c *CA) IssuePEM(subject pkix.Name, dnsNames []string, ttl time.Duration) ([]byte, []byte, error) {
|
|
caCrtPEM, caKeyPEM := c.provider.CurrentCertKeyContent()
|
|
ca, err := certauthority.Load(string(caCrtPEM), string(caKeyPEM))
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
return ca.IssuePEM(subject, dnsNames, ttl)
|
|
}
|