Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: generate separate certs per profile #4968

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ func setupKubeAdm(mAPI libmachine.API, kc cfg.KubernetesConfig) bootstrapper.Boo
if err := bs.UpdateCluster(kc); err != nil {
exit.WithError("Failed to update cluster", err)
}
if err := bs.SetupCerts(kc); err != nil {
if err := bs.SetupCerts(kc, cfg.GetMachineName()); err != nil {
exit.WithError("Failed to setup certs", err)
}
return bs
Expand All @@ -824,13 +824,14 @@ func updateKubeConfig(h *host.Host, c *cfg.Config) *pkgutil.KubeConfigSetup {
if c.KubernetesConfig.APIServerName != constants.APIServerName {
addr = strings.Replace(addr, c.KubernetesConfig.NodeIP, c.KubernetesConfig.APIServerName, -1)
}
p := cfg.GetMachineName()

kcs := &pkgutil.KubeConfigSetup{
ClusterName: cfg.GetMachineName(),
ClusterName: p,
ClusterServerAddress: addr,
ClientCertificate: constants.MakeMiniPath("client.crt"),
ClientKey: constants.MakeMiniPath("client.key"),
CertificateAuthority: constants.MakeMiniPath("ca.crt"),
ClientCertificate: filepath.Join(constants.GetProfilePath(p), "client.crt"),
ClientKey: filepath.Join(constants.GetProfilePath(p), "client.key"),
CertificateAuthority: filepath.Join(constants.GetProfilePath(p), "ca.crt"),
KeepContext: viper.GetBool(keepContext),
EmbedCerts: viper.GetBool(embedCerts),
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ require (
github.com/pmezard/go-difflib v1.0.0
github.com/samalba/dockerclient v0.0.0-20160414174713-91d7393ff859 // indirect
github.com/shirou/gopsutil v2.18.12+incompatible
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
medyagh marked this conversation as resolved.
Show resolved Hide resolved
github.com/sirupsen/logrus v1.4.1 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -398,6 +399,8 @@ github.com/seccomp/libseccomp-golang v0.0.0-20150813023252-1b506fc7c24e/go.mod h
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY=
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM=
github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470/go.mod h1:2dOwnU2uBioM+SGy2aZoq1f/Sd1l9OkAeAUvjSyvgU0=
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Bootstrapper interface {
WaitCluster(config.KubernetesConfig) error
// LogCommands returns a map of log type to a command which will display that log.
LogCommands(LogOptions) map[string]string
SetupCerts(cfg config.KubernetesConfig) error
SetupCerts(cfg config.KubernetesConfig, profile string) error
GetKubeletStatus() (string, error)
GetAPIServerStatus(net.IP, int) (string, error)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/minikube/bootstrapper/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ var (
)

// SetupCerts gets the generated credentials required to talk to the APIServer.
func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig) error {
localPath := constants.GetMinipath()
glog.Infof("Setting up certificates for IP: %s\n", k8s.NodeIP)
func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig, profile string) error {
localPath := constants.GetProfilePath(profile)
glog.Infof("Setting up certificates for profile %s IP: %s\n", profile, k8s.NodeIP)

if err := generateCerts(k8s); err != nil {
if err := generateCerts(k8s, profile); err != nil {
return errors.Wrap(err, "Error generating certs")
}

Expand Down Expand Up @@ -97,13 +97,13 @@ func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig) error {
return nil
}

func generateCerts(k8s config.KubernetesConfig) error {
func generateCerts(k8s config.KubernetesConfig, profile string) error {
serviceIP, err := util.GetServiceClusterIP(k8s.ServiceCIDR)
if err != nil {
return errors.Wrap(err, "getting service cluster ip")
}

localPath := constants.GetMinipath()
localPath := constants.GetProfilePath(profile)

caCertPath := filepath.Join(localPath, "ca.crt")
caKeyPath := filepath.Join(localPath, "ca.key")
Expand Down
7 changes: 4 additions & 3 deletions pkg/minikube/bootstrapper/certs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (
)

func TestSetupCerts(t *testing.T) {
tempDir := tests.MakeTempDir()
p := t.Name()
tempDir := tests.MakeTempDir() // TODO: this doesn't seem to be used
defer os.RemoveAll(tempDir)

f := command.NewFakeCommandRunner()
Expand All @@ -41,10 +42,10 @@ func TestSetupCerts(t *testing.T) {

var filesToBeTransferred []string
for _, cert := range certs {
filesToBeTransferred = append(filesToBeTransferred, filepath.Join(constants.GetMinipath(), cert))
filesToBeTransferred = append(filesToBeTransferred, filepath.Join(constants.GetProfilePath(p), cert))
}

if err := SetupCerts(f, k8s); err != nil {
if err := SetupCerts(f, k8s, p); err != nil {
t.Fatalf("Error starting cluster: %v", err)
}
for _, cert := range filesToBeTransferred {
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ func (k *Bootstrapper) PullImages(k8s config.KubernetesConfig) error {
}

// SetupCerts sets up certificates within the cluster.
func (k *Bootstrapper) SetupCerts(k8s config.KubernetesConfig) error {
return bootstrapper.SetupCerts(k.c, k8s)
func (k *Bootstrapper) SetupCerts(k8s config.KubernetesConfig, profile string) error {
return bootstrapper.SetupCerts(k.c, k8s, profile)
}

// NewKubeletConfig generates a new systemd unit containing a configured kubelet
Expand Down