[Envoy Filter] how to add http header with source service name, source namespace?

For each http request, I hope add below in http header

  • Source http request’s service name
  • Source http request’s namespace

Thanks a lot.

I am trying envoyfilter, normal running is good, as below:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: custom-filter-2
  namespace: istio-system
spec:
  filters:
  - listenerMatch:
      portNumber: 80
      listenerType: SIDECAR_INBOUND
      listenerProtocol: HTTP
    filterName: envoy.lua
    filterType: HTTP
    filterConfig:
      inlineCode: |
        function envoy_on_request(request_handle)
          request_handle:logInfo("******* enter envoy_on_request custom-filter-2")
          request_handle:headers():replace("mylol","hivalue")
        end

Test result:

tryc2@ip-172-31-0-31:~/tutorial-istio-envoy-lua-filters/example-6-istio/bk_sidecar$ k exec -ti nginx-c46747ffd-bnjgg -- curl web-service.default
Defaulting container name to nginx.
Use 'kubectl describe pod/nginx-c46747ffd-bnjgg -n default' to see all of the containers in this pod.
{
  "path": "/",
  "headers": {
    "host": "web-service.default",
    ... ...
    "content-length": "0",
    "mylol": "hivalue",
    ... ...
  },
  "method": "GET",
   ... ...
}