<p>I would like to pass header <em>foo</em> from service <em>A</em> to service <em>B</em>, but how to do that?</p>
<ul>
<li><code>VirtualService</code>'s <a href="https://istio.io/latest/docs/reference/config/networking/virtual-service/#Headers" rel="nofollow noreferrer">header</a> will work only with actual virtual service and wouldn't be passed to service <em>B</em> (as I would hope)</li>
<li><code>JWTRule</code> describes how we can work propagating jwt to upstream services.</li>
<li>changing headers for tracing is possible.</li>
<li><code>Envoy Filter</code> looks promising, but I haven't figured out a straightforward way to do that, atm.</li>
</ul>
<p>What am I missing? How propagation of a particular header or group of headers can be done to upstream services without changing services source code.</p>

Oleg Butuzov
<p>VirtualServices can configure service-to-service traffic, just as it configures traffic to be rotued from the ingress gateway to the services.</p>
<p>For example with this virtual service, you will add the test header in the requests with the echo destination:</p>
<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: echo
spec:
  hosts:
  - echo
  http:
  - headers:
      request:
        set:
          test: &quot;true&quot;
    route:
    - destination:
        host: echo
</code></pre>
<p>To verify that create a two deployments so that we can make a request from one to another:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: echo
  name: echo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: echo
  template:
    metadata:
      labels:
        app: echo
    spec:
      containers:
      - image: ealen/echo-server
        imagePullPolicy: IfNotPresent
        name: echo
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        env:
        - name: PORT
          value: '8080'
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: echo
  name: echo
spec:
  ports:
  - name: http
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: echo
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sleep
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sleep
  template:
    metadata:
      labels:
        app: sleep
    spec:
      containers:
      - name: sleep
        image: governmentpaas/curl-ssl
        command: [&quot;/bin/sleep&quot;, &quot;3650d&quot;]
</code></pre>
<p>Wait until it is up and execute a request against the echo server:</p>
<pre><code>kubectl exec -it deploy/sleep -- /bin/sh -c 'curl echo:8080'
</code></pre>
<p>And you will see that the test header is added in the request header, this can be seen in the response where the echo server echoes the headers and in the logs of the echo server.</p>
<p>Note: For the above to work all need to be applied in the same namespace. The namespace must be labeled for sidecar injection.</p>
