diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aecb4c8ceb..238efbeb7ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ BUG FIXES: * cli: Fixed a bug where `nomad operator debug` incorrectly parsed https Consul API URLs. [[GH-10082](https://github.com/hashicorp/nomad/pull/10082)] * cli: Remove extra linefeeds in monitor.log files written by `nomad operator debug`. [[GH-10252](https://github.com/hashicorp/nomad/issues/10252)] * client: Fixed log formatting when killing tasks. [[GH-10135](https://github.com/hashicorp/nomad/issues/10135)] + * client: Fixed a bug where small files would be assigned the wrong content type. [[GH-10348](https://github.com/hashicorp/nomad/pull/10348)] + * consul/connect: Fixed a bug where HTTP ingress gateways could not use wildcard names. [[GH-10457](https://github.com/hashicorp/nomad/pull/10457)] * csi: Fixed a bug where volume with IDs that are a substring prefix of another volume could use the wrong volume for feasibility checking. [[GH-10158](https://github.com/hashicorp/nomad/issues/10158)] * scheduler: Fixed a bug where jobs requesting multiple CSI volumes could be incorrectly scheduled if only one of the volumes passed feasibility checking. [[GH-10143](https://github.com/hashicorp/nomad/issues/10143)] * ui: Fixed the rendering of interstitial components shown after processing a dynamic application sizing recommendation. [[GH-10094](https://github.com/hashicorp/nomad/pull/10094)] diff --git a/nomad/structs/services.go b/nomad/structs/services.go index 63107654ae1..e75f303fb8d 100644 --- a/nomad/structs/services.go +++ b/nomad/structs/services.go @@ -2,6 +2,7 @@ package structs import ( "crypto/sha1" + "errors" "fmt" "hash" "io" @@ -1560,13 +1561,29 @@ func (s *ConsulIngressService) Validate(isHTTP bool) error { } if s.Name == "" { - return fmt.Errorf("Consul Ingress Service requires a name") + return errors.New("Consul Ingress Service requires a name") } - if isHTTP && len(s.Hosts) == 0 { - return fmt.Errorf("Consul Ingress Service requires one or more hosts when using HTTP protocol") - } else if !isHTTP && len(s.Hosts) > 0 { - return fmt.Errorf("Consul Ingress Service supports hosts only when using HTTP protocol") + // Validation of wildcard service name and hosts varies on whether the protocol + // for the gateway is HTTP. + // https://www.consul.io/docs/connect/config-entries/ingress-gateway#hosts + switch isHTTP { + case true: + if s.Name == "*" { + return nil + } + + if len(s.Hosts) == 0 { + return errors.New("Consul Ingress Service requires one or more hosts when using HTTP protocol") + } + case false: + if s.Name == "*" { + return errors.New("Consul Ingress Service supports wildcard names only with HTTP protocol") + } + + if len(s.Hosts) > 0 { + return errors.New("Consul Ingress Service supports hosts only when using HTTP protocol") + } } return nil diff --git a/nomad/structs/services_test.go b/nomad/structs/services_test.go index 68182bb21e7..f649f616ef0 100644 --- a/nomad/structs/services_test.go +++ b/nomad/structs/services_test.go @@ -1051,6 +1051,20 @@ func TestConsulIngressService_Validate(t *testing.T) { }).Validate(true) require.NoError(t, err) }) + + t.Run("http with wildcard service", func(t *testing.T) { + err := (&ConsulIngressService{ + Name: "*", + }).Validate(true) + require.NoError(t, err) + }) + + t.Run("tcp with wildcard service", func(t *testing.T) { + err := (&ConsulIngressService{ + Name: "*", + }).Validate(false) + require.EqualError(t, err, "Consul Ingress Service supports wildcard names only with HTTP protocol") + }) } func TestConsulIngressListener_Validate(t *testing.T) {