Kubernetes Ingress Gateway for Response Content Manipulation

3/19/2020

In our Kubernetes Cluster, We have a requirement to do a string replace in our Response body. Is there such a thing in Istio for response content modification. I could only find header manipulation.

Can Nginx Ingress Controller do this?

The respone contains html content with hrefs as: <>"/static/myimages/logo.png"<> We would like to modify this response to prefix it with <>"/myapp/static/myimages/logo.png"<>

Does anyone have a recommendation for a gateway that can do this content rewrite. Do you have samples to share?

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: resource-manager
spec:
  hosts:
  - "*"
  gateways:
  - myapp-gateway
  http:
  - match:
    - uri:
       prefix: /myapp/
      rewrite:
       uri: "/"
    route:
     - destination:
        host: myapp.voting.svc.cluster.local
        port:
          number: 9099
       headers:
        response:
         add:
          foo: bar
-- Linda
istio
kubernetes
kubernetes-ingress
nginx-ingress
nginx-reverse-proxy

2 Answers

3/20/2020

AFAIK, istio does not offer body modification by default. It might not even be possible with custom envoy filters.

-- Piotr Malec
Source: StackOverflow

3/26/2020

I started looking at other Ingress Controllers and found that NGINX-Ingress can do response manipulation. Here is an ingress route I setup which does content manipulation. Sharing that here:

apiVersion: extensions/v1beta1 
kind: Ingress 
metadata: 
  name: app1-ingress 
  namespace: app1 
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      sub_filter '<title>My title' '<title>My updated title'; #This changes title that Chrome Shows on Top
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /$1 
spec:  
 rules:
  - http:
      paths:
      - backend:
          serviceName: app1
          servicePort: 8080
        path: /app1/(.*)
-- Linda
Source: StackOverflow