@annotations @router.cookie @release-1.22

Feature: Rewrite

An Ingress may define rewrite rules in its annotations. If the a Request matches the rule defined in a Ingress which have rewrite annotations, BFE should rewrite the host, path and query param according to the annotations in the Ingress.

Scenarios
Status Progress

Passed

100.00%

Failed

0.00%
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-host-static
annotations:
bfe.ingress.kubernetes.io/rewrite-url.host: '[{"params": "bar.com", "when": "AfterLocation"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request host must be bar.com
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-host-dynamic
annotations:
bfe.ingress.kubernetes.io/rewrite-url.host-from-path-prefix: '[{"params": true}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /baidu.com/bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/baidu.com/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request host must be baidu.com
check_circle
And 0s the request path must be /bar
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-host-dynamic
annotations:
bfe.ingress.kubernetes.io/rewrite-url.host-from-path-prefix: '[{"params": true}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request host must be rewrite-url.com
check_circle
And 0s the request path must be /bar
check_circle
Given 15s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-path-static
annotations:
bfe.ingress.kubernetes.io/rewrite-url.path: '[{"params": "/index"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 3s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /index
check_circle
Given 10s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-path-add
annotations:
bfe.ingress.kubernetes.io/rewrite-url.path-prefix-add: '[{"params": "/foo/"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /foo/bar
check_circle
Given 10s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-path-delete
annotations:
bfe.ingress.kubernetes.io/rewrite-url.path-prefix-trim: '[{"params": "/foo"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /foo/bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/foo/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /bar
Scenario: An Ingress with annotation `bfe.ingress.kubernetes.io/rewrite-url.path-prefix-trim`

and the route path doesn't have the specific prefix to be removed.

check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-path-delete
annotations:
bfe.ingress.kubernetes.io/rewrite-url.path-prefix-trim: '[{"params": "/foo"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /bar
check_circle
Given 15s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-path-strip
annotations:
bfe.ingress.kubernetes.io/rewrite-url.path-prefix-strip: '[{"params": 1}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /foo/bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/foo/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /bar
Scenario: An Ingress with annotation `bfe.ingress.kubernetes.io/rewrite-url.path-prefix-strip`,

but the length of route path segments is less than the strip length

check_circle
Given 10s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-path-strip
annotations:
bfe.ingress.kubernetes.io/rewrite-url.path-prefix-strip: '[{"params": 3}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-query-add
annotations:
bfe.ingress.kubernetes.io/rewrite-url.query-add: '[{"params": {"user": "bob", "age": "18"}}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 3s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /bar?age=18&user=bob
check_circle
Given 10s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-query-delete
annotations:
bfe.ingress.kubernetes.io/rewrite-url.query-delete: '[{"params": ["user"]}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar?user=bob&age=18
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /bar?age=18
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-query-rename
annotations:
bfe.ingress.kubernetes.io/rewrite-url.query-rename: '[{"params": {"name": "user"}}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar?name=bob
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /bar?user=bob
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-query-delete-all-except
annotations:
bfe.ingress.kubernetes.io/rewrite-url.query-delete-all-except: '[{"params": "name"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar?name=bob&age=18&gender=man
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /bar?name=bob
check_circle
Given 10s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-callback-illegal
annotations:
bfe.ingress.kubernetes.io/rewrite-url.host: '[{"params": "bar.com", "when": "BeforeForward"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 3s The Ingress status should not be success
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-host-multiple
annotations:
bfe.ingress.kubernetes.io/rewrite-url.host: '[{"params": "bar.com"}]'
bfe.ingress.kubernetes.io/rewrite-url.host-from-path-prefix: '[{"params": "bar.com"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 3s The Ingress status should not be success
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-path-illegal
annotations:
bfe.ingress.kubernetes.io/rewrite-url.path: '[{"params": "/index"}]'
bfe.ingress.kubernetes.io/rewrite-url.path-prefix-add: '[{"params": "/foo/"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 3s The Ingress status should not be success
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-path-compound
annotations:
bfe.ingress.kubernetes.io/rewrite-url.path: '[{"params": "/index"}]'
bfe.ingress.kubernetes.io/rewrite-url.path-prefix-trim: '[{"params": "/foo"}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 3s The Ingress status should not be success
check_circle
Given 5s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-path-compound
annotations:
bfe.ingress.kubernetes.io/rewrite-url.path-prefix-add: '[{"params": "/index/", "order": 1}]'
bfe.ingress.kubernetes.io/rewrite-url.path-prefix-trim: '[{"params": "/bar", "order": 2}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /index/bar
check_circle
Given 10s an Ingress resource with rewrite annotation +Show Parameter
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rewrite-query-compound
annotations:
bfe.ingress.kubernetes.io/rewrite-url.query-delete-all-except: '[{"params": "name", "order": 1}]'
bfe.ingress.kubernetes.io/rewrite-url.query-add: '[{"params": {"age": "18"}, "order": 3}]'
bfe.ingress.kubernetes.io/rewrite-url.query-rename: '[{"params": {"name": "user"}, "order": 2}]'
spec:
rules:
- host: "rewrite-url.com"
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-exact
port:
number: 3000
check_circle
And 6s The Ingress status shows the IP address or FQDN where it is exposed
check_circle
When 0s I send a GET request to http://rewrite-url.com/bar?name=bob&gender=man
check_circle
Then 0s the response status code must be 200
check_circle
And 0s the request path must be /bar?age=18&user=bob