X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/08c80b2ba6a8fc090d2e998dfcf2f280c8508019..b1ed7c643f311605092991e01bcc3437130d6072:/lib/boot/cert.go diff --git a/lib/boot/cert.go b/lib/boot/cert.go index b2b8c896c2..916f9f53b2 100644 --- a/lib/boot/cert.go +++ b/lib/boot/cert.go @@ -26,18 +26,6 @@ func (createCertificates) String() string { } func (createCertificates) Run(ctx context.Context, fail func(error), super *Supervisor) error { - var san string - if net.ParseIP(super.ListenHost) != nil { - san += fmt.Sprintf(",IP:%s", super.ListenHost) - } else { - san += fmt.Sprintf(",DNS:%s", super.ListenHost) - } - if hostname, err := os.Hostname(); err != nil { - return fmt.Errorf("hostname: %w", err) - } else { - san += ",DNS:" + hostname - } - // Generate root key err := super.RunProgram(ctx, super.tempdir, runOptions{}, "openssl", "genrsa", "-out", "rootCA.key", "4096") if err != nil { @@ -58,7 +46,20 @@ func (createCertificates) Run(ctx context.Context, fail func(error), super *Supe if err != nil { return err } - err = ioutil.WriteFile(filepath.Join(super.tempdir, "server.cfg"), append(defaultconf, []byte(fmt.Sprintf("\n[SAN]\nsubjectAltName=DNS:localhost,DNS:localhost.localdomain%s\n", san))...), 0644) + hostname, err := os.Hostname() + if err != nil { + return fmt.Errorf("hostname: %w", err) + } + san := "DNS:localhost,DNS:localhost.localdomain,DNS:" + hostname + if super.ListenHost == hostname || super.ListenHost == "localhost" { + // already have it + } else if net.ParseIP(super.ListenHost) != nil { + san += fmt.Sprintf(",IP:%s", super.ListenHost) + } else { + san += fmt.Sprintf(",DNS:%s", super.ListenHost) + } + conf := append(defaultconf, []byte(fmt.Sprintf("\n[SAN]\nsubjectAltName=%s\n", san))...) + err = ioutil.WriteFile(filepath.Join(super.tempdir, "server.cfg"), conf, 0644) if err != nil { return err }