func newServerKeyAndCert(s *kubeadmapi.KubeadmConfig, caCert *x509.Certificate, caKey *rsa.PrivateKey, altNames certutil.AltNames) (*rsa.PrivateKey, *x509.Certificate, error) { key, err := certutil.NewPrivateKey() if err != nil { return nil, nil, fmt.Errorf("unabel to create private key [%v]", err) } internalAPIServerFQDN := []string{ "kubernetes", "kubernetes.default", "kubernetes.default.svc", fmt.Sprintf("kubernetes.default.svc.%s", s.InitFlags.Services.DNSDomain), } internalAPIServerVirtualIP, err := ipallocator.GetIndexedIP(&s.InitFlags.Services.CIDR, 1) if err != nil { return nil, nil, fmt.Errorf("unable to allocate IP address for the API server from the given CIDR (%q) [%v]", &s.InitFlags.Services.CIDR, err) } altNames.IPs = append(altNames.IPs, internalAPIServerVirtualIP) altNames.DNSNames = append(altNames.DNSNames, internalAPIServerFQDN...) config := certutil.Config{ CommonName: "kube-apiserver", AltNames: altNames, } cert, err := certutil.NewSignedCert(config, key, caCert, caKey) if err != nil { return nil, nil, fmt.Errorf("unable to sign certificate [%v]", err) } return key, cert, nil }
func NewClientKeyAndCert(config *certutil.Config, caCert *x509.Certificate, caKey *rsa.PrivateKey) (*rsa.PrivateKey, *x509.Certificate, error) { key, err := certutil.NewPrivateKey() if err != nil { return nil, nil, fmt.Errorf("unable to create private key [%v]", err) } cert, err := certutil.NewSignedCert(*config, key, caCert, caKey) if err != nil { return nil, nil, fmt.Errorf("unable to sign certificate [%v]", err) } return key, cert, nil }
func newClientKeyAndCert(caCert *x509.Certificate, caKey *rsa.PrivateKey) (*rsa.PrivateKey, *x509.Certificate, error) { key, err := certutil.NewPrivateKey() if err != nil { return nil, nil, fmt.Errorf("unable to create private key [%v]", err) } config := certutil.Config{ CommonName: "kubernetes-admin", } cert, err := certutil.NewSignedCert(config, key, caCert, caKey) if err != nil { return nil, nil, fmt.Errorf("unable to sign certificate [%v]", err) } return key, cert, nil }
func newServerKeyAndCert(caCert *x509.Certificate, caKey *rsa.PrivateKey, altNames certutil.AltNames) (*rsa.PrivateKey, *x509.Certificate, error) { key, err := certutil.NewPrivateKey() if err != nil { return nil, nil, fmt.Errorf("unable to create private key [%v]", err) } config := certutil.Config{ CommonName: "kube-apiserver", AltNames: altNames, } cert, err := certutil.NewSignedCert(config, key, caCert, caKey) if err != nil { return nil, nil, fmt.Errorf("unable to sign certificate [%v]", err) } return key, cert, nil }
func NewClientKeyPair(ca *KeyPair, commonName string) (*KeyPair, error) { key, err := certutil.NewPrivateKey() if err != nil { return nil, fmt.Errorf("unable to create a client private key: %v", err) } config := certutil.Config{ CommonName: commonName, } cert, err := certutil.NewSignedCert(config, key, ca.Cert, ca.Key) if err != nil { return nil, fmt.Errorf("unable to sign the client certificate: %v", err) } return &KeyPair{ Key: key, Cert: cert, }, nil }
func NewServerKeyPair(ca *KeyPair, commonName, svcName, svcNamespace, dnsDomain string, ips, hostnames []string) (*KeyPair, error) { key, err := certutil.NewPrivateKey() if err != nil { return nil, fmt.Errorf("unable to create a server private key: %v", err) } namespacedName := fmt.Sprintf("%s.%s", svcName, svcNamespace) internalAPIServerFQDN := []string{ svcName, namespacedName, fmt.Sprintf("%s.svc", namespacedName), fmt.Sprintf("%s.svc.%s", namespacedName, dnsDomain), } altNames := certutil.AltNames{} for _, ipStr := range ips { ip := net.ParseIP(ipStr) if ip != nil { altNames.IPs = append(altNames.IPs, ip) } } altNames.DNSNames = append(altNames.DNSNames, hostnames...) altNames.DNSNames = append(altNames.DNSNames, internalAPIServerFQDN...) config := certutil.Config{ CommonName: commonName, AltNames: altNames, } cert, err := certutil.NewSignedCert(config, key, ca.Cert, ca.Key) if err != nil { return nil, fmt.Errorf("unable to sign the server certificate: %v", err) } return &KeyPair{ Key: key, Cert: cert, }, nil }
func newServerKeyAndCert(cfg *kubeadmapi.MasterConfiguration, caCert *x509.Certificate, caKey *rsa.PrivateKey, altNames certutil.AltNames) (*rsa.PrivateKey, *x509.Certificate, error) { key, err := certutil.NewPrivateKey() if err != nil { return nil, nil, fmt.Errorf("unabel to create private key [%v]", err) } internalAPIServerFQDN := []string{ "kubernetes", "kubernetes.default", "kubernetes.default.svc", fmt.Sprintf("kubernetes.default.svc.%s", cfg.Networking.DNSDomain), } _, n, err := net.ParseCIDR(cfg.Networking.ServiceSubnet) if err != nil { return nil, nil, fmt.Errorf("error parsing CIDR %q: %v", cfg.Networking.ServiceSubnet, err) } internalAPIServerVirtualIP, err := ipallocator.GetIndexedIP(n, 1) if err != nil { return nil, nil, fmt.Errorf("unable to allocate IP address for the API server from the given CIDR (%q) [%v]", &cfg.Networking.ServiceSubnet, err) } altNames.IPs = append(altNames.IPs, internalAPIServerVirtualIP) altNames.DNSNames = append(altNames.DNSNames, internalAPIServerFQDN...) config := certutil.Config{ CommonName: "kube-apiserver", AltNames: altNames, } cert, err := certutil.NewSignedCert(config, key, caCert, caKey) if err != nil { return nil, nil, fmt.Errorf("unable to sign certificate [%v]", err) } return key, cert, nil }