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

Fix inverted certificate symlink creation logic #6889

Merged
merged 3 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions pkg/minikube/bootstrapper/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ func SetupCerts(cmd command.Runner, k8s config.KubernetesConfig, n config.Node)
}
}

// configure CA certificates
if err := configureCACerts(cmd, caCerts); err != nil {
return errors.Wrapf(err, "Configuring CA certs")
if err := installCertSymlinks(cmd, caCerts); err != nil {
return errors.Wrapf(err, "certificate symlinks")
}
return nil
}
Expand Down Expand Up @@ -318,9 +317,9 @@ func getSubjectHash(cr command.Runner, filePath string) (string, error) {
return stringHash, nil
}

// configureCACerts looks up and installs all uploaded PEM certificates in /usr/share/ca-certificates to system-wide certificate store (/etc/ssl/certs).
// installCertSymlinks installs certs in /usr/share/ca-certificates into system-wide certificate store (/etc/ssl/certs).
// OpenSSL binary required in minikube ISO
func configureCACerts(cr command.Runner, caCerts map[string]string) error {
func installCertSymlinks(cr command.Runner, caCerts map[string]string) error {
hasSSLBinary := true
_, err := cr.RunCmd(exec.Command("openssl", "version"))
if err != nil {
Expand All @@ -334,7 +333,8 @@ func configureCACerts(cr command.Runner, caCerts map[string]string) error {
for _, caCertFile := range caCerts {
dstFilename := path.Base(caCertFile)
certStorePath := path.Join(vmpath.GuestCertStoreDir, dstFilename)
cmd := fmt.Sprintf("test -f %s || ln -fs %s %s", caCertFile, certStorePath, caCertFile)
// If the cert really exists, add a named symlink
cmd := fmt.Sprintf("test -f %s && ln -fs %s %s", caCertFile, caCertFile, certStorePath)
if _, err := cr.RunCmd(exec.Command("sudo", "/bin/bash", "-c", cmd)); err != nil {
return errors.Wrapf(err, "create symlink for %s", caCertFile)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/bootstrapper/certs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func TestSetupCerts(t *testing.T) {
}

expected := map[string]string{
`sudo /bin/bash -c "test -f /usr/share/ca-certificates/mycert.pem || ln -fs /etc/ssl/certs/mycert.pem /usr/share/ca-certificates/mycert.pem"`: "-",
`sudo /bin/bash -c "test -f /usr/share/ca-certificates/minikubeCA.pem || ln -fs /etc/ssl/certs/minikubeCA.pem /usr/share/ca-certificates/minikubeCA.pem"`: "-",
`sudo /bin/bash -c "test -f /usr/share/ca-certificates/mycert.pem && ln -fs /usr/share/ca-certificates/mycert.pem /etc/ssl/certs/mycert.pem"`: "-",
`sudo /bin/bash -c "test -f /usr/share/ca-certificates/minikubeCA.pem && ln -fs /usr/share/ca-certificates/minikubeCA.pem /etc/ssl/certs/minikubeCA.pem"`: "-",
}
f := command.NewFakeCommandRunner()
f.SetCommandToOutput(expected)
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/command/ssh_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,13 @@ func (s *SSHRunner) sameFileExists(f assets.CopyableFile, dst string) (bool, err
if err != nil {
return false, err
}
glog.Infof("found %s: %d bytes, modified at %s", dst, dstSize, dstModTime)

// compare sizes and modtimes
if srcSize != dstSize {
return false, errors.New("source file and destination file are different sizes")
}

return srcModTime.Equal(dstModTime), nil
}

Expand Down
57 changes: 57 additions & 0 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"net/url"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"runtime"
Expand Down Expand Up @@ -57,10 +58,17 @@ func TestFunctional(t *testing.T) {
profile := UniqueProfileName("functional")
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Minute)
defer func() {
if !*cleanup {
return
}
p := localSyncTestPath()
if err := os.Remove(p); err != nil {
t.Logf("unable to remove %s: %v", p, err)
}
p = localTestCertPath()
if err := os.Remove(p); err != nil {
t.Logf("unable to remove %s: %v", p, err)
}
CleanupWithLogs(t, profile, cancel)
}()

Expand Down Expand Up @@ -110,6 +118,7 @@ func TestFunctional(t *testing.T) {
{"SSHCmd", validateSSHCmd},
{"MySQL", validateMySQL},
{"FileSync", validateFileSync},
{"CertSync", validateCertSync},
{"UpdateContextCmd", validateUpdateContextCmd},
{"DockerEnv", validateDockerEnv},
}
Expand Down Expand Up @@ -716,6 +725,16 @@ func localSyncTestPath() string {
return filepath.Join(localpath.MiniPath(), "/files", vmSyncTestPath())
}

// testCert is name of the test certificate installed
func testCert() string {
return fmt.Sprintf("%d.pem", os.Getpid())
}

// localTestCertPath is where the test file will be synced into the VM
func localTestCertPath() string {
return filepath.Join(localpath.MiniPath(), "/certs", testCert())
}

// Copy extra file into minikube home folder for file sync test
func setupFileSync(ctx context.Context, t *testing.T, profile string) {
p := localSyncTestPath()
Expand All @@ -724,6 +743,11 @@ func setupFileSync(ctx context.Context, t *testing.T, profile string) {
if err != nil {
t.Fatalf("copy: %v", err)
}

err = copy.Copy("./testdata/minikube_test.pem", localTestCertPath())
if err != nil {
t.Fatalf("copy: %v", err)
}
}

// validateFileSync to check existence of the test file
Expand Down Expand Up @@ -751,6 +775,39 @@ func validateFileSync(ctx context.Context, t *testing.T, profile string) {
}
}

// validateCertSync to check existence of the test certificate
func validateCertSync(ctx context.Context, t *testing.T, profile string) {
if NoneDriver() {
t.Skipf("skipping: ssh unsupported by none")
}

want, err := ioutil.ReadFile("./testdata/minikube_test.pem")
if err != nil {
t.Errorf("test file not found: %v", err)
}

// Check both the installed & reference certs (they should be symlinked)
paths := []string{
path.Join("/etc/ssl/certs", testCert()),
path.Join("/usr/share/ca-certificates", testCert()),
// hashed path generated by: 'openssl x509 -hash -noout -in testCert()'
"/etc/ssl/certs/51391683.0",
}
for _, vp := range paths {
t.Logf("Checking for existence of %s within VM", vp)
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", fmt.Sprintf("cat %s", vp)))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}

// Strip carriage returned by ssh
got := strings.Replace(rr.Stdout.String(), "\r", "", -1)
if diff := cmp.Diff(string(want), got); diff != "" {
t.Errorf("minikube_test.pem -> %s mismatch (-want +got):\n%s", vp, diff)
}
}
}

// validateUpdateContextCmd asserts basic "update-context" command functionality
func validateUpdateContextCmd(ctx context.Context, t *testing.T, profile string) {
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "update-context", "--alsologtostderr", "-v=2"))
Expand Down
22 changes: 22 additions & 0 deletions test/integration/testdata/minikube_test.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-----BEGIN CERTIFICATE-----
MIIDsDCCApgCCQD5n0OIsOYIjDANBgkqhkiG9w0BAQsFADCBmTELMAkGA1UEBhMC
VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28x
ETAPBgNVBAoMCG1pbmlrdWJlMRYwFAYDVQQLDA1QYXJ0eSBQYXJyb3RzMREwDwYD
VQQDDAhtaW5pa3ViZTEfMB0GCSqGSIb3DQEJARYQbWluaWt1YmVAY25jZi5pbzAe
Fw0yMDAzMDQyMTU2MjZaFw0yMTAzMDQyMTU2MjZaMIGZMQswCQYDVQQGEwJVUzET
MBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzERMA8G
A1UECgwIbWluaWt1YmUxFjAUBgNVBAsMDVBhcnR5IFBhcnJvdHMxETAPBgNVBAMM
CG1pbmlrdWJlMR8wHQYJKoZIhvcNAQkBFhBtaW5pa3ViZUBjbmNmLmlvMIIBIjAN
BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA/qVMQ/234ul5yWI1yaHvV4pZ5Ffy
M0bSMjzZU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