From f062513c16fcaf2b5ccb70c7f718963c167cd8dc Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Wed, 28 Jun 2023 15:23:32 -0400 Subject: [PATCH] Add support for dns names to controller type --- zititest/zitilab/component_controller.go | 3 ++- zititest/zitilab/pki/cert.go | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/zititest/zitilab/component_controller.go b/zititest/zitilab/component_controller.go index 62a9fc154..95f2f5569 100644 --- a/zititest/zitilab/component_controller.go +++ b/zititest/zitilab/component_controller.go @@ -42,6 +42,7 @@ type ControllerType struct { ConfigName string Version string LocalPath string + DNSNames []string } func (self *ControllerType) GetActions() map[string]model.ComponentAction { @@ -72,7 +73,7 @@ func (self *ControllerType) StageFiles(r model.Run, c *model.Component) error { return err } - if err := pki.CreateControllerCerts(r, c, c.Id); err != nil { + if err := pki.CreateControllerCerts(r, c, self.DNSNames, c.Id); err != nil { return err } diff --git a/zititest/zitilab/pki/cert.go b/zititest/zitilab/pki/cert.go index ac145fc6a..10ad6c556 100644 --- a/zititest/zitilab/pki/cert.go +++ b/zititest/zitilab/pki/cert.go @@ -90,7 +90,7 @@ func loadInfoFile(file string) string { return string(data) } -func EnsureServerCertExists(run model.Run, name string, ip string, spiffeId string) error { +func EnsureServerCertExists(run model.Run, name string, ip string, dns []string, spiffeId string) error { logrus.Infof("generating server certificate [%s:%s]", name, ip) certFile := name + "-server" @@ -124,6 +124,10 @@ func EnsureServerCertExists(run model.Run, name string, ip string, spiffeId stri "--allow-overwrite", "--ip", ip} + if len(dns) > 0 { + args = append(args, "--dns", strings.Join(dns, ",")) + } + if spiffeId != "" { args = append(args, "--spiffe-id", spiffeId) } @@ -138,7 +142,7 @@ func EnsureServerCertExists(run model.Run, name string, ip string, spiffeId stri return os.WriteFile(infoFile, []byte(certInfo), 0600) } -func CreateControllerCerts(run model.Run, component *model.Component, name string) error { +func CreateControllerCerts(run model.Run, component *model.Component, dns []string, name string) error { trustDomain := component.GetStringVariableOr("ca.trustDomain", "ziti.test") rootCaName := component.GetStringVariableOr("ca.rootName", "root") if err := EnsureCaExists(run, trustDomain, rootCaName); err != nil { @@ -149,5 +153,5 @@ func CreateControllerCerts(run model.Run, component *model.Component, name strin return errors.Wrapf(err, "error generating public identity for component [%s]", component.Id) } - return EnsureServerCertExists(run, name, component.Host.PublicIp, "controller/"+name) + return EnsureServerCertExists(run, name, component.Host.PublicIp, dns, "controller/"+name) }