Istio添加和删除标题,但不会覆盖 [英] Istio adds and removed headers, but doesn't overwrite

查看:126
本文介绍了Istio添加和删除标题,但不会覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Istio使用VirtualServices添加,覆盖和删除标头.在请求中添加标头,然后从响应中删除标头也可以,但是不会覆盖请求中的标头.

I am trying to add, overwrite and remove headers with VirtualServices, with Istio. Adding a header to the request and removing a header from the response works just fine, but it is not overwriting the header from the request.

因此,根据Istio文档,标头操作如下:

So, according to Istio docs, headers operations are as follows:

这是我的VirtualService:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: server-vs
spec:
  hosts:
  - server.istio.svc.cluster.local
  http:
  - headers:
      request:
        set:
          test: "true"
        add:
          added: "header"
    route:
    - destination:
        host: server.istio.svc.cluster.local
        subset: apache
      weight: 90
    - destination:
        host: server.istio.svc.cluster.local
        subset: nginx
      headers:
        response:
          remove:
          - foo
      weight: 10

set为标题,这是我的理解. Istio将使用键test标识标头,并用true覆盖该值.因此,如果我使用-H "test: hello"参数卷曲服务,则应该在请求中看到test: true.

Focusing on set a header, this is my understanding. Istio is going to identify a header with key test, and it is going to overwrite the value by true. So, if I curl my service with -H "test: hello" parameter, I should see test: true in my request.

现在,我在后端pod中安装了tcpdump,可以看到added: header.我还可以看到foo: bar已被删除(我的nginx服务器正在将foo: bar与响应一起返回),但是我看不到test: true标头.我对Istio标头操作的理解正确吗?

Now, I have tcpdump installed in my backend pod, and I can see added: header. I can also see that foo: bar has been removed (my nginx server is returning foo: bar along with the response), but I can't see test: true header. Is my understanding correct about header operations with Istio?

从测试中

请求

/ # curl -H "test: hello" server
<h1>THIS IS AN ISTIO DEMO</h1>/ # 

响应

15:47:27.387891 IP 192.168.49.58.39652 > 192.168.113.134.80: Flags [S], seq 2810811797, win 28000, options [mss 1400,sackOK,TS val 1900372734 ecr 0,nop,wscale 7], length 0
E..<d.@.>.....1:..q....P..........m`
3.....x...
qEb.........
15:47:27.388130 IP 192.168.49.58.39652 > 192.168.113.134.80: Flags [.], ack 2093848160, win 219, options [nop,nop,TS val 1900372735 ecr 3950379544], length 0
E..4d.@.>.....1:..q....P....|..`.....z.....
qEb..v..
15:47:27.388202 IP 192.168.49.58.39652 > 192.168.113.134.80: Flags [P.], seq 2810811798:2810812507, ack 2093848160, win 219, options [nop,nop,TS val 1900372735 ecr 3950379544], length 709: HTTP: GET / HTTP/1.1
E...d.@.>.....1:..q....P....|..`....S&.....
qEb..v..GET / HTTP/1.1
host: server
user-agent: curl/7.59.0
accept: */*
test: hello                  <-HERE IS THE HEADER THAT SUPPOSED TO BE OVERWRITTEN
x-forwarded-proto: http
x-request-id: 05ff2bb6-8810-9411-8a3b-7456066e1d16
x-envoy-decorator-operation: server-vs:80/*
x-istio-attributes: CjwKGGRlc3RpbmF0aW9uLnNlcnZpY2UuaG9zdBIgEh5zZXJ2ZXIuaXN0aW8uc3ZjLmNsdXN0ZXIubG9jYWwKOgoXZGVzdGluYXRpb24uc2VydmljZS51aWQSHxIdaXN0aW86Ly9pc3Rpby9zZXJ2aWNlcy9zZXJ2ZXIKJAoYZGVzdGluYXRpb24uc2VydmljZS5uYW1lEggSBnNlcnZlcgooCh1kZXN0aW5hdGlvbi5zZXJ2aWNlLm5hbWVzcGFjZRIHEgVpc3Rpbwo6Cgpzb3VyY2UudWlkEiwSKmt1YmVybmV0ZXM6Ly9jdXJsZXItNzU1Y2M3Y2ZmZi14dmxiMi5pc3Rpbw==
x-b3-traceid: 741c90fab1ca5e23802399916451563e
x-b3-spanid: 802399916451563e
x-b3-sampled: 1
added: header                <- HERE IS THE ADDED HEADER
content-length: 0


15:47:27.390857 IP 192.168.49.58.39652 > 192.168.113.134.80: Flags [.], ack 2093848436, win 228, options [nop,nop,TS val 1900372737 ecr 3950379547], length 0
E..4d.@.>.....1:..q....P...[|..t...........
qEc..v..

但是我希望看到test: true

推荐答案

一个愚蠢的事情解决了这个问题.看起来如果我在yaml文件中先定义set然后定义add,那是行不通的,但是如果我使用backword,它就可以了.我想这是一个错误.因此以下yaml起作用了:

A silly thing solved the problem. Looks like if I define first set then add, in the yaml file, it doesn't work, but if I do it backwords, it works. I guess it's a bug. So the following yaml worked:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: server-vs
spec:
  hosts:
  - server.istio.svc.cluster.local
  http:
  - headers:
      request:
        add:                    <- add goes first
          added: "header"
        set:                    <- set goes second
          test: "true"
    route:
    - destination:
        host: server.istio.svc.cluster.local
        subset: apache
      weight: 90
    - destination:
        host: server.istio.svc.cluster.local
        subset: nginx
      headers:
        response:
          remove:
          - foo
      weight: 10

这篇关于Istio添加和删除标题,但不会覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆