diff --git a/agent/consul/config_endpoint.go b/agent/consul/config_endpoint.go index e87e9eceda..2e72f992ee 100644 --- a/agent/consul/config_endpoint.go +++ b/agent/consul/config_endpoint.go @@ -89,6 +89,14 @@ func (c *ConfigEntry) Apply(args *structs.ConfigEntryRequest, reply *bool) error return err } + // Log any applicable warnings about the contents of the config entry. + if warnEntry, ok := args.Entry.(structs.WarningConfigEntry); ok { + warnings := warnEntry.Warnings() + for _, warning := range warnings { + c.logger.Warn(warning) + } + } + if err := args.Entry.CanWrite(authz); err != nil { return err } diff --git a/agent/structs/config_entry.go b/agent/structs/config_entry.go index 7222a1ec61..09e05fa4ca 100644 --- a/agent/structs/config_entry.go +++ b/agent/structs/config_entry.go @@ -82,6 +82,14 @@ type UpdatableConfigEntry interface { ConfigEntry } +// WarningConfigEntry is an optional interface implemented by a ConfigEntry +// if it wants to be able to emit warnings when it is being upserted. +type WarningConfigEntry interface { + Warnings() []string + + ConfigEntry +} + // ServiceConfiguration is the top-level struct for the configuration of a service // across the entire cluster. type ServiceConfigEntry struct { diff --git a/agent/structs/config_entry_gateways.go b/agent/structs/config_entry_gateways.go index 94014230d5..fc9c840a06 100644 --- a/agent/structs/config_entry_gateways.go +++ b/agent/structs/config_entry_gateways.go @@ -570,6 +570,22 @@ func (e *TerminatingGatewayConfigEntry) GetEnterpriseMeta() *EnterpriseMeta { return &e.EnterpriseMeta } +func (e *TerminatingGatewayConfigEntry) Warnings() []string { + if e == nil { + return nil + } + + warnings := make([]string, 0) + for _, svc := range e.Services { + if (svc.CAFile != "" || svc.CertFile != "" || svc.KeyFile != "") && svc.SNI == "" { + warning := fmt.Sprintf("TLS is configured but SNI is not set for service %q. Enabling SNI is strongly recommended when using TLS.", svc.Name) + warnings = append(warnings, warning) + } + } + + return warnings +} + // GatewayService is used to associate gateways with their linked services. type GatewayService struct { Gateway ServiceName