diff --git a/.changelog/3502.txt b/.changelog/3502.txt new file mode 100644 index 0000000000..56b7334081 --- /dev/null +++ b/.changelog/3502.txt @@ -0,0 +1,3 @@ +```release-note:improvement +control-plane: Add `CaseInsensitive` flag to service-routers that allows paths and path prefixes to ignore URL upper and lower casing. +``` diff --git a/charts/consul/templates/crd-servicerouters.yaml b/charts/consul/templates/crd-servicerouters.yaml index c4e06d05bc..dca5aa7fc3 100644 --- a/charts/consul/templates/crd-servicerouters.yaml +++ b/charts/consul/templates/crd-servicerouters.yaml @@ -185,6 +185,10 @@ spec: http: description: HTTP is a set of http-specific match criteria. properties: + caseInsensitive: + description: CaseInsensitive configures PathExact and + PathPrefix matches to ignore upper/lower casing. + type: boolean header: description: Header is a set of criteria that can match on HTTP request headers. If more than one is configured diff --git a/control-plane/api/v1alpha1/servicerouter_types.go b/control-plane/api/v1alpha1/servicerouter_types.go index 7054d9e9e2..a06977b9e7 100644 --- a/control-plane/api/v1alpha1/servicerouter_types.go +++ b/control-plane/api/v1alpha1/servicerouter_types.go @@ -75,6 +75,8 @@ type ServiceRouteMatch struct { } type ServiceRouteHTTPMatch struct { + // CaseInsensitive configures PathExact and PathPrefix matches to ignore upper/lower casing. + CaseInsensitive bool `json:"caseInsensitive,omitempty"` // PathExact is an exact path to match on the HTTP request path. PathExact string `json:"pathExact,omitempty"` // PathPrefix is a path prefix to match on the HTTP request path. @@ -422,12 +424,13 @@ func (in *ServiceRouteHTTPMatch) toConsul() *capi.ServiceRouteHTTPMatch { query = append(query, q.toConsul()) } return &capi.ServiceRouteHTTPMatch{ - PathExact: in.PathExact, - PathPrefix: in.PathPrefix, - PathRegex: in.PathRegex, - Header: header, - QueryParam: query, - Methods: in.Methods, + CaseInsensitive: in.CaseInsensitive, + PathExact: in.PathExact, + PathPrefix: in.PathPrefix, + PathRegex: in.PathRegex, + Header: header, + QueryParam: query, + Methods: in.Methods, } } diff --git a/control-plane/api/v1alpha1/servicerouter_types_test.go b/control-plane/api/v1alpha1/servicerouter_types_test.go index f7eb766945..acd4437262 100644 --- a/control-plane/api/v1alpha1/servicerouter_types_test.go +++ b/control-plane/api/v1alpha1/servicerouter_types_test.go @@ -53,9 +53,10 @@ func TestServiceRouter_MatchesConsul(t *testing.T) { { Match: &ServiceRouteMatch{ HTTP: &ServiceRouteHTTPMatch{ - PathExact: "pathExact", - PathPrefix: "pathPrefix", - PathRegex: "pathRegex", + CaseInsensitive: true, + PathExact: "pathExact", + PathPrefix: "pathPrefix", + PathRegex: "pathRegex", Header: []ServiceRouteHTTPMatchHeader{ { Name: "name", @@ -131,9 +132,10 @@ func TestServiceRouter_MatchesConsul(t *testing.T) { { Match: &capi.ServiceRouteMatch{ HTTP: &capi.ServiceRouteHTTPMatch{ - PathExact: "pathExact", - PathPrefix: "pathPrefix", - PathRegex: "pathRegex", + CaseInsensitive: true, + PathExact: "pathExact", + PathPrefix: "pathPrefix", + PathRegex: "pathRegex", Header: []capi.ServiceRouteHTTPMatchHeader{ { Name: "name", @@ -259,9 +261,10 @@ func TestServiceRouter_ToConsul(t *testing.T) { { Match: &ServiceRouteMatch{ HTTP: &ServiceRouteHTTPMatch{ - PathExact: "pathExact", - PathPrefix: "pathPrefix", - PathRegex: "pathRegex", + CaseInsensitive: true, + PathExact: "pathExact", + PathPrefix: "pathPrefix", + PathRegex: "pathRegex", Header: []ServiceRouteHTTPMatchHeader{ { Name: "name", @@ -337,9 +340,10 @@ func TestServiceRouter_ToConsul(t *testing.T) { { Match: &capi.ServiceRouteMatch{ HTTP: &capi.ServiceRouteHTTPMatch{ - PathExact: "pathExact", - PathPrefix: "pathPrefix", - PathRegex: "pathRegex", + CaseInsensitive: true, + PathExact: "pathExact", + PathPrefix: "pathPrefix", + PathRegex: "pathRegex", Header: []capi.ServiceRouteHTTPMatchHeader{ { Name: "name", diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml index b43f225249..4c982dbf8e 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml @@ -181,6 +181,10 @@ spec: http: description: HTTP is a set of http-specific match criteria. properties: + caseInsensitive: + description: CaseInsensitive configures PathExact and + PathPrefix matches to ignore upper/lower casing. + type: boolean header: description: Header is a set of criteria that can match on HTTP request headers. If more than one is configured diff --git a/control-plane/go.mod b/control-plane/go.mod index 1a684922cc..ba5dfc4639 100644 --- a/control-plane/go.mod +++ b/control-plane/go.mod @@ -11,7 +11,7 @@ require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/hashicorp/consul-k8s/control-plane/cni v0.0.0-20230825213844-4ea04860c5ed github.com/hashicorp/consul-server-connection-manager v0.1.6 - github.com/hashicorp/consul/api v1.26.1 + github.com/hashicorp/consul/api v1.10.1-0.20240122160221-1c7e9443cbcd github.com/hashicorp/consul/proto-public v0.5.1 github.com/hashicorp/consul/sdk v0.15.0 github.com/hashicorp/go-bexpr v0.1.11 diff --git a/control-plane/go.sum b/control-plane/go.sum index ef0c1fbf34..77cb2910c9 100644 --- a/control-plane/go.sum +++ b/control-plane/go.sum @@ -263,8 +263,8 @@ github.com/hashicorp/consul-k8s/control-plane/cni v0.0.0-20230825213844-4ea04860 github.com/hashicorp/consul-k8s/control-plane/cni v0.0.0-20230825213844-4ea04860c5ed/go.mod h1:mwODEC+VTCA1LY/m2RUG4S2c5lNRvBcsvqaMJtMLLos= github.com/hashicorp/consul-server-connection-manager v0.1.6 h1:ktj8Fi+dRXn9hhM+FXsfEJayhzzgTqfH08Ne5M6Fmug= github.com/hashicorp/consul-server-connection-manager v0.1.6/go.mod h1:HngMIv57MT+pqCVeRQMa1eTB5dqnyMm8uxjyv+Hn8cs= -github.com/hashicorp/consul/api v1.26.1 h1:5oSXOO5fboPZeW5SN+TdGFP/BILDgBm19OrPZ/pICIM= -github.com/hashicorp/consul/api v1.26.1/go.mod h1:B4sQTeaSO16NtynqrAdwOlahJ7IUDZM9cj2420xYL8A= +github.com/hashicorp/consul/api v1.10.1-0.20240122160221-1c7e9443cbcd h1:M98X+hMQSPtK5xpAFuSGlgh4eE2py9UNmB1S6w6/a6c= +github.com/hashicorp/consul/api v1.10.1-0.20240122160221-1c7e9443cbcd/go.mod h1:gInwZGrnWlE1Vvq6rSD5pUf6qwNa69NTLLknbdwQRUk= github.com/hashicorp/consul/proto-public v0.5.1 h1:g4xHZ7rJ56iktDi1uThKp+IbvHrP6nveZeGVt2Qw5x0= github.com/hashicorp/consul/proto-public v0.5.1/go.mod h1:SayEhfXS3DQDnW/vKSZXvkwDObg7XK60KTfrJcp0wrg= github.com/hashicorp/consul/sdk v0.15.0 h1:2qK9nDrr4tiJKRoxPGhm6B7xJjLVIQqkjiab2M4aKjU=