Skip to content

Commit

Permalink
fix(gateway): be more lenient with prefix paths trailing slashes (#5299)
Browse files Browse the repository at this point in the history
* fix(gateway): be more lenient with prefix paths trailing slashes
* test(e2e): add MeshGateway prefix with trailing slash
* test: remove validation error

Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont authored Nov 14, 2022
1 parent 8cacffb commit 1477105
Show file tree
Hide file tree
Showing 6 changed files with 553 additions and 78 deletions.
3 changes: 0 additions & 3 deletions pkg/core/resources/apis/mesh/gateway_route_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ func validateMeshGatewayRouteHTTPMatch(
if p.GetValue() == "/" {
break
}
if strings.HasSuffix(p.GetValue(), "/") {
err.AddViolationAt(path.Field("value"), "does not need a trailing slash because only a `/`-separated prefix or an entire path is matched")
}
if !strings.HasPrefix(p.GetValue(), "/") {
err.AddViolationAt(path.Field("value"), "must be an absolute path")
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/core/resources/apis/mesh/gateway_route_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,10 @@ conf:
destination:
kuma.io/service: target-2
`),
ErrorCases("prefix without leading slash and with trailing slash", []validators.Violation{{
Field: "conf.http.rules[0].matches[0].value",
Message: "does not need a trailing slash because only a `/`-separated prefix or an entire path is matched",
}, {
ErrorCase("prefix without leading slash and with trailing slash", validators.Violation{
Field: "conf.http.rules[0].matches[0].value",
Message: "must be an absolute path",
}}, `
}, `
type: MeshGatewayRoute
name: route
mesh: default
Expand Down
24 changes: 24 additions & 0 deletions pkg/plugins/runtime/gateway/gateway_route_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,30 @@ conf:
`,
),

Entry("should be able to rewrite a prefix that has a trailing slash",
"rewrite-prefix-trailing-gateway-route.yaml", `
type: MeshGatewayRoute
mesh: default
name: echo-service
selectors:
- match:
kuma.io/service: gateway-default
conf:
http:
rules:
- matches:
- path:
match: PREFIX
value: /prefix/a/
filters:
- rewrite:
replacePrefixMatch: "/a"
backends:
- destination:
kuma.io/service: echo-service
`,
),

Entry("should be able to drop a prefix",
"drop-prefix-gateway-route.yaml", `
type: MeshGatewayRoute
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
Clusters:
Resources:
echo-service-9f149ed9e14091ca:
circuitBreakers:
thresholds:
- maxConnections: 1024
maxPendingRequests: 1024
maxRequests: 1024
maxRetries: 3
connectTimeout: 5s
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
name: echo-service-9f149ed9e14091ca
outlierDetection:
enforcingConsecutive5xx: 0
enforcingConsecutiveGatewayFailure: 0
enforcingConsecutiveLocalOriginFailure: 0
enforcingFailurePercentage: 0
enforcingSuccessRate: 0
perConnectionBufferLimitBytes: 32768
type: EDS
typedExtensionProtocolOptions:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
'@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
commonHttpProtocolOptions:
idleTimeout: 3600s
explicitHttpConfig:
httpProtocolOptions: {}
Endpoints:
Resources:
echo-service-9f149ed9e14091ca:
clusterName: echo-service-9f149ed9e14091ca
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 192.168.1.6
portValue: 20006
loadBalancingWeight: 1
metadata:
filterMetadata:
envoy.lb:
kuma.io/protocol: http
envoy.transport_socket_match:
kuma.io/protocol: http
Listeners:
Resources:
edge-gateway:HTTP:8080:
address:
socketAddress:
address: 192.168.1.1
portValue: 8080
enableReusePort: true
filterChains:
- filters:
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
commonHttpProtocolOptions:
headersWithUnderscoresAction: REJECT_REQUEST
idleTimeout: 300s
http2ProtocolOptions:
allowConnect: true
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
maxConcurrentStreams: 100
httpFilters:
- name: envoy.filters.http.local_ratelimit
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.local_ratelimit.v3.LocalRateLimit
statPrefix: rate_limit
- name: gzip-compress
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor
compressorLibrary:
name: gzip
typedConfig:
'@type': type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip
responseDirectionConfig:
disableOnEtagHeader: true
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
mergeSlashes: true
normalizePath: true
pathWithEscapedSlashesAction: UNESCAPE_AND_REDIRECT
rds:
configSource:
ads: {}
resourceApiVersion: V3
routeConfigName: edge-gateway:HTTP:8080
requestHeadersTimeout: 0.500s
serverName: Kuma Gateway
statPrefix: gateway-default
streamIdleTimeout: 5s
stripAnyHostPort: true
useRemoteAddress: true
listenerFilters:
- name: envoy.filters.listener.tls_inspector
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector
name: edge-gateway:HTTP:8080
perConnectionBufferLimitBytes: 32768
trafficDirection: INBOUND
Routes:
Resources:
edge-gateway:HTTP:8080:
name: edge-gateway:HTTP:8080
requestHeadersToRemove:
- x-kuma-tags
validateClusters: false
virtualHosts:
- domains:
- echo.example.com
name: echo.example.com
routes:
- match:
path: /prefix/a
route:
regexRewrite:
pattern:
googleRe2: {}
regex: .*
substitution: /a
retryPolicy:
numRetries: 5
perTryTimeout: 16s
retryBackOff:
baseInterval: 0.025s
maxInterval: 0.250s
retryOn: gateway-error,connect-failure,refused-stream
timeout: 15s
weightedClusters:
clusters:
- name: echo-service-9f149ed9e14091ca
requestHeadersToAdd:
- header:
key: x-kuma-tags
value: '&kuma.io/service=gateway-default&'
weight: 1
totalWeight: 1
- match:
prefix: /prefix/a/
route:
prefixRewrite: /a/
retryPolicy:
numRetries: 5
perTryTimeout: 16s
retryBackOff:
baseInterval: 0.025s
maxInterval: 0.250s
retryOn: gateway-error,connect-failure,refused-stream
timeout: 15s
weightedClusters:
clusters:
- name: echo-service-9f149ed9e14091ca
requestHeadersToAdd:
- header:
key: x-kuma-tags
value: '&kuma.io/service=gateway-default&'
weight: 1
totalWeight: 1
Runtimes:
Resources:
gateway.listeners:
layer: {}
name: gateway.listeners
Secrets:
Resources: {}
Loading

0 comments on commit 1477105

Please sign in to comment.