Commit 20f12e9c authored by Darren Shepherd's avatar Darren Shepherd

Don't generation self signed certs

parent ed7002ac
...@@ -22,7 +22,6 @@ package app ...@@ -22,7 +22,6 @@ package app
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net"
"os" "os"
"strings" "strings"
"time" "time"
...@@ -501,14 +500,11 @@ func Complete(s *options.ServerRunOptions) (completedServerRunOptions, error) { ...@@ -501,14 +500,11 @@ func Complete(s *options.ServerRunOptions) (completedServerRunOptions, error) {
if err := kubeoptions.DefaultAdvertiseAddress(s.GenericServerRunOptions, s.InsecureServing.DeprecatedInsecureServingOptions); err != nil { if err := kubeoptions.DefaultAdvertiseAddress(s.GenericServerRunOptions, s.InsecureServing.DeprecatedInsecureServingOptions); err != nil {
return options, err return options, err
} }
serviceIPRange, apiServerServiceIP, err := master.DefaultServiceIPRange(s.ServiceClusterIPRange) serviceIPRange, _, err := master.DefaultServiceIPRange(s.ServiceClusterIPRange)
if err != nil { if err != nil {
return options, fmt.Errorf("error determining service IP ranges: %v", err) return options, fmt.Errorf("error determining service IP ranges: %v", err)
} }
s.ServiceClusterIPRange = serviceIPRange s.ServiceClusterIPRange = serviceIPRange
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts(s.GenericServerRunOptions.AdvertiseAddress.String(), []string{"kubernetes.default.svc", "kubernetes.default", "kubernetes"}, []net.IP{apiServerServiceIP}); err != nil {
return options, fmt.Errorf("error creating self-signed certificates: %v", err)
}
if len(s.GenericServerRunOptions.ExternalHost) == 0 { if len(s.GenericServerRunOptions.ExternalHost) == 0 {
if len(s.GenericServerRunOptions.AdvertiseAddress) > 0 { if len(s.GenericServerRunOptions.AdvertiseAddress) > 0 {
......
...@@ -19,7 +19,6 @@ limitations under the License. ...@@ -19,7 +19,6 @@ limitations under the License.
package options package options
import ( import (
"fmt"
"net" "net"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
...@@ -392,10 +391,6 @@ func (s KubeControllerManagerOptions) Config(allControllers []string, disabledBy ...@@ -392,10 +391,6 @@ func (s KubeControllerManagerOptions) Config(allControllers []string, disabledBy
return nil, err return nil, err
} }
if err := s.SecureServing.MaybeDefaultWithSelfSignedCerts("localhost", nil, []net.IP{net.ParseIP("127.0.0.1")}); err != nil {
return nil, fmt.Errorf("error creating self-signed certificates: %v", err)
}
kubeconfig, err := clientcmd.BuildConfigFromFlags(s.Master, s.Kubeconfig) kubeconfig, err := clientcmd.BuildConfigFromFlags(s.Master, s.Kubeconfig)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -17,9 +17,7 @@ limitations under the License. ...@@ -17,9 +17,7 @@ limitations under the License.
package options package options
import ( import (
"fmt"
"io" "io"
"net"
"github.com/spf13/pflag" "github.com/spf13/pflag"
...@@ -77,11 +75,6 @@ func (o *CustomResourceDefinitionsServerOptions) Complete() error { ...@@ -77,11 +75,6 @@ func (o *CustomResourceDefinitionsServerOptions) Complete() error {
// Config returns an apiextensions-apiserver configuration. // Config returns an apiextensions-apiserver configuration.
func (o CustomResourceDefinitionsServerOptions) Config() (*apiserver.Config, error) { func (o CustomResourceDefinitionsServerOptions) Config() (*apiserver.Config, error) {
// TODO have a "real" external address
if err := o.RecommendedOptions.SecureServing.MaybeDefaultWithSelfSignedCerts("localhost", nil, []net.IP{net.ParseIP("127.0.0.1")}); err != nil {
return nil, fmt.Errorf("error creating self-signed certificates: %v", err)
}
serverConfig := genericapiserver.NewRecommendedConfig(apiserver.Codecs) serverConfig := genericapiserver.NewRecommendedConfig(apiserver.Codecs)
if err := o.RecommendedOptions.ApplyTo(serverConfig, apiserver.Scheme); err != nil { if err := o.RecommendedOptions.ApplyTo(serverConfig, apiserver.Scheme); err != nil {
return nil, err return nil, err
......
...@@ -20,17 +20,14 @@ import ( ...@@ -20,17 +20,14 @@ import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"net" "net"
"path"
"strconv" "strconv"
"strings" "strings"
"github.com/golang/glog"
"github.com/spf13/pflag" "github.com/spf13/pflag"
utilnet "k8s.io/apimachinery/pkg/util/net" utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apiserver/pkg/server" "k8s.io/apiserver/pkg/server"
utilflag "k8s.io/apiserver/pkg/util/flag" utilflag "k8s.io/apiserver/pkg/util/flag"
certutil "k8s.io/client-go/util/cert"
) )
type SecureServingOptions struct { type SecureServingOptions struct {
...@@ -259,48 +256,6 @@ func (s *SecureServingOptions) ApplyTo(config **server.SecureServingInfo) error ...@@ -259,48 +256,6 @@ func (s *SecureServingOptions) ApplyTo(config **server.SecureServingInfo) error
return nil return nil
} }
func (s *SecureServingOptions) MaybeDefaultWithSelfSignedCerts(publicAddress string, alternateDNS []string, alternateIPs []net.IP) error {
if s == nil || (s.BindPort == 0 && s.Listener == nil) {
return nil
}
keyCert := &s.ServerCert.CertKey
if len(keyCert.CertFile) != 0 || len(keyCert.KeyFile) != 0 {
return nil
}
keyCert.CertFile = path.Join(s.ServerCert.CertDirectory, s.ServerCert.PairName+".crt")
keyCert.KeyFile = path.Join(s.ServerCert.CertDirectory, s.ServerCert.PairName+".key")
canReadCertAndKey, err := certutil.CanReadCertAndKey(keyCert.CertFile, keyCert.KeyFile)
if err != nil {
return err
}
if !canReadCertAndKey {
// add either the bind address or localhost to the valid alternates
bindIP := s.BindAddress.String()
if bindIP == "0.0.0.0" {
alternateDNS = append(alternateDNS, "localhost")
} else {
alternateIPs = append(alternateIPs, s.BindAddress)
}
if cert, key, err := certutil.GenerateSelfSignedCertKeyWithFixtures(publicAddress, alternateIPs, alternateDNS, s.ServerCert.FixtureDirectory); err != nil {
return fmt.Errorf("unable to generate self signed cert: %v", err)
} else {
if err := certutil.WriteCert(keyCert.CertFile, cert); err != nil {
return err
}
if err := certutil.WriteKey(keyCert.KeyFile, key); err != nil {
return err
}
glog.Infof("Generated self-signed cert (%s, %s)", keyCert.CertFile, keyCert.KeyFile)
}
}
return nil
}
func CreateListener(network, addr string) (net.Listener, int, error) { func CreateListener(network, addr string) (net.Listener, int, error) {
if len(network) == 0 { if len(network) == 0 {
network = "tcp" network = "tcp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment