当前位置:网站首页>Methods of accessing external services in istio grid
Methods of accessing external services in istio grid
2022-06-29 14:21:00 【Cloud native community】
background
Use in a production environment Istio When , Perhaps the most important issues to consider are security and performance , I'm here to discuss the next security issue with you , How to be in Istio Accessing external services in the grid .Istio Two modes are provided to configure the access policy for external requests , And through configuration items outboundTrafficPolicy.mode To specify the . The default mode is ALLOW_ANY, That is, it allows all external unknown services to be requested within the grid ; Another model is REGISTRY_ONLY, Indicates that only services registered in the service grid registry are allowed . default ALLOW_ANY Although the mode is easy to use , But there are some potential safety hazards , The recommended practice is to switch to REGISTRY_ONLY Pattern . So in REGISTRY_ONLY How to access external services in mode ? What is the implementation mechanism ? Here I will discuss these two issues with you .
Scheme Research
At present, we are installing and deploying Istio It uses helm, You can add the corresponding configuration in the installation --set meshConfig.outboundTrafficPolicy.mode=REGISTRY_ONLY modify outboundTrafficPolicy.mode Value ; If Istio Installed , adopt kubectl edit cm istio -n istio-system This value can be dynamically modified .
apiVersion: v1data: mesh: |- defaultConfig: discoveryAddress: istiod.istio-system.svc:15012 proxyMetadata: DNS_AGENT: "" tracing: zipkin: address: zipkin.istio-system:9411 outboundTrafficPolicy: mode: REGISTRY_ONLYEnd of configuration REGISTRY_ONLY after , We are pod Cannot access external services in

So in REGISTRY_ONLY In mode , How can I access external services ? First we pass The figure below look down Istio When can I access external services , How to modify the configuration to access external services at this time ?
The picture depicts product Service access review service , So let's assume that review The service will continue to call 36.152.44.96 This external service .

When reviews Application needs access 36.152.44.96 This external service , Will be in reviews Send request information upstream in the application container of , The following describes how to access external requests in the order shown in the figure .
- reviews Services access external services , This step is right reviews For service, it belongs to export flow , By iptables The rule intercepts and forwards the traffic to the outlet OUTPUT chain .
- OUTPUT Chain forwarding traffic to ISTIO_OUTPUT chain .
- stay ISTIO_OUTPUT There are nine rules in the chain by default , decision reviews Where does the traffic from the service accessing the external service go , Here we can customize a rule
-A ISTIO_OUTPUT -d 36.152.44.0/24 -j RETURN, Make a visit to 36.152.44.96 The traffic of this external service jumps out of the current chain , callPOSTROUTING chain, Direct access to external services ; If you use the default rule , Traffic is forwarded to ISTIO_REDIRECT chain . - ISTIO_REDIRECT The chain is redirected directly to Envoy Monitoring 15001 Outlet flow port .
- The traffic strategy for external services is not Istio In the service grid , If you do not configure it, register the external service in the service grid , after Envoy An error message will be returned after a series of outlet traffic management actions . So here we need to configure
ServiceEntry, Bring external services into the service grid , And then through Envoy You can continue to send external requests after the traffic governance , When accessing an external request, it will be iptables Intercept and forward to the outlet traffic OUTPUT chain . - OUTPUT Chain forwarding traffic to ISTIO_OUTPUT chain .
- Here it will match ISTIO_OUTPUT The fourth rule of the chain
-A ISTIO_OUTPUT -m owner --uid-owner 1337 -j RETURN, The flow is direct RETURN To the next chainPOSTROUTING chain, the POSTROUTING The chain flows out to access external services .
We see through the 11 Step 、 The first 13 The configuration can be modified in both ways Istio Internal services access external services , What should I do ?
adopt iptables Rule access
If you want to 11 Step straight out ISTIO_OUT Chain call POSTROUTING chain , You need to add a custom iptables The rules -A ISTIO_OUTPUT -d 36.152.44.0/24 -j RETURN, We know iptables The rule is istio-init The definition of ,istio-init What is executed at startup is istio-iptables command , We are manifests Of injection-template.yaml I see in the document istio-iptables Default partial configuration .
- "-i" - "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/includeOutboundIPRanges` .Values.global.proxy.includeIPRanges }}" - "-x" - "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/excludeOutboundIPRanges` .Values.global.proxy.excludeIPRanges }}" - "-b" - "{{ annotation .ObjectMeta `traffic.sidecar.istio.io/includeInboundPorts` `*` }}" - "-d" {{- if excludeInboundPort (annotation .ObjectMeta `status.sidecar.istio.io/port` .Values.global.proxy.statusPort) (annotation .ObjectMeta `traffic.sidecar.istio.io/excludeInboundPorts` .Values.global.proxy.excludeInboundPorts) }} - "15090,15021,{{ excludeInboundPort (annotation .ObjectMeta `status.sidecar.istio.io/port` .Values.global.proxy.statusPort) (annotation .ObjectMeta `traffic.sidecar.istio.io/excludeInboundPorts` .Values.global.proxy.excludeInboundPorts) }}" {{- else }} - "15090,15021,15020"-iThe default is*, All outbound traffic will be redirected to Envoy agent-xThe default is empty. , When -i Parameter is*when , Used to indicate which addresses are not redirected Envoy agent , Forward directly-bThe default is*, Comma separated ports , The traffic of the specified port will be redirected to Envoy-dThe default is 15090,15021,15020, Comma separated ports , Specify which ports do not need to redirect traffic to Envoy
According to the above configuration, we can Istio In service through global.proxy.* Global configuration , It can also be found in the deployment Pass through traffic.sidecar.istio.io/* Configure the corresponding parameters . Our goal now is to have access to 36.152.44.96 Your request will not be redirected to Envoy agent , Forward directly , So we have deployment Add in traffic.sidecar.istio.io/excludeOutboundIPRanges: 36.152.44.0/24, After the execution, we describe pod Details of , Get pod Some of the configurations in are as follows , You can see that the settings take effect ,36.152.44.0/24 Will not redirect to Envoy in
-i * -x 36.152.44.0/24 -b * -d 15090,15021,15020 Keep looking at pod Medium iptables The rules , Can be seen in the original ISTIO_OUTPUT Nine iptables A custom rule is inserted in the rule A ISTIO_OUTPUT -d 36.152.44.0/24 -j RETURN
-A ISTIO_OUTPUT -s 127.0.0.6/32 -o lo -j RETURN -A ISTIO_OUTPUT ! -d 127.0.0.1/32 -o lo -m owner --uid-owner 1337 -j ISTIO_IN_REDIRECT -A ISTIO_OUTPUT -o lo -m owner ! --uid-owner 1337 -j RETURN -A ISTIO_OUTPUT -m owner --uid-owner 1337 -j RETURN -A ISTIO_OUTPUT ! -d 127.0.0.1/32 -o lo -m owner --gid-owner 1337 -j ISTIO_IN_REDIRECT -A ISTIO_OUTPUT -o lo -m owner ! --gid-owner 1337 -j RETURN -A ISTIO_OUTPUT -m owner --gid-owner 1337 -j RETURN -A ISTIO_OUTPUT -d 127.0.0.1/32 -j RETURN -A ISTIO_OUTPUT -d 36.152.44.0/24 -j RETURN -A ISTIO_OUTPUT -j ISTIO_REDIRECTadopt ServiceEntry visit
Istio stay 15001 Port usage VirtualOutboundListener Process outgoing requests ,Iptable take Envoy Where Pod After the external request of is intercepted, it is sent to the local 15001 port , The listener does not perform service processing after receiving , Instead, it is distributed to other independent listeners according to the destination port of the request . The external services we access are 36.152.44.96:80, therefore Envoy Match to... According to the destination port 0.0.0.0_80 This Outbound listener, And forward to the listener.

When 0.0.0.0_80 After receiving the outbound request , It will not be sent directly to the destination cluster, Actually, by checking 0.0.0.0_80 Of listener Information about , We can't find the purpose cluster or endpoint, In this listener A routing rule is configured in 80, In this routing rule, route matching will be performed according to different request destinations .

adopt name by 80 We didn't find any routing rules that match 36.152.44.96 Request , So will be listener Inside default_filter_match Handle , Enter into BlackHoleCluster In cluster , The request is discarded . Let's briefly introduce Envoy Two special in cluster:BlackHoleCluster and PassthroughCluster,BlackHoleCluster There is no... Configured to process requests in host. Request access to the cluster Will be discarded , Instead of sending it to a host, If outboundTrafficPolicy.mode=REGISTRY_ONLY, By default, all requested external services will directly enter BlackHoleCluster Throw it away in the middle .PassthroughCluster Of type Set to ORIGINAL_DST, Indicates that any message sent to the cluster All requests are sent directly to the original destination in the request , If outboundTrafficPolicy.mode=ALLOW_ANY,Envoy The request will not be rerouted directly to the original destination .
stay outboundTrafficPolicy.mode=REGISTRY_ONLY In mode , In order to prevent the flow from entering BlackHoleCluster in , We need to add ServiceEntry, Register external requests in the service grid , In order to Envoy External services can be found route Conduct flow processing .
apiVersion: networking.istio.io/v1beta1kind: ServiceEntrymetadata: name: baidu-ipspec: hosts: - www.baidu.com addresses: - 36.152.44.96 location: MESH_EXTERNAL ports: - number: 80 name: baidu-http protocol: HTTP resolution: NONEEnd of configuration ServiceEntry Then we will check again review Of route Information , You can see 36.152.44.96 Has been added to route It's in , Directly in pod Access external services in 36.152.44.96 Can get the right request .

summary
Through to Istio Visit the scheme of external services to conduct research , We learned Istio How to pass iptables Handle traffic entering the grid , I also have a general understanding of Envoy Handle Outbound Flow of traffic . The above survey is based on Istio 1.8 edition , There may be errors or inaccuracies in the content , Welcome to exchange and correct .
边栏推荐
猜你喜欢

Thinkpad VMware 安装虚拟机出现此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态(问题解决方法)

By proxy, by buyout, the wild era of domestic end-to-end travel is waiting for the next "eternal robbery"

现场快递柜状态采集与控制系统

TikTok全球短视频霸主地位或被YouTube反超

微信小程序:全新独家云开发微群人脉

Summary of binary tree exercises

【blackduck】jenkins下配置指定的synopsys-detect扫描版本

Equivalence class partition method for test case design method

win10安装Monggodb的基本使用教程
![[dark horse morning post] the market value of China public education has evaporated by more than 200billion; New Oriental has more than 20million live fans; HM closes its first store in China; Vanke Y](/img/d7/4671b5a74317a8f87ffd36be2b34e1.jpg)
[dark horse morning post] the market value of China public education has evaporated by more than 200billion; New Oriental has more than 20million live fans; HM closes its first store in China; Vanke Y
随机推荐
Tiktok's global short video dominance may be reversed by YouTube
c语言入门教程–-6循环语句
NuScenes关于Radar的配置信息
Unity 关于Destroy 和 OnDestroy失效(延迟)的问题
ANSVC无功补偿装置在河北某购物广场中的应用
Distributed cache for memcached
Unity SplashImage 缩放问题
微信小程序:全新獨家雲開發微群人脈
Go unit testing introductory practice
传输层 用户数据报协议(UDP)
投资人跌下神坛:半年0出手,转行送外卖
Summary of binary tree exercises
【VEUX开发者工具的使用-getters使用】
Sixty years of deep learning
嵌入式开发:硬件在环测试
[blackduck] configure the specified Synopsys detect scan version under Jenkins
unity吃豆人小游戏,迷宫实现
Redis为什么这么快?Redis是单线程还是多线程?
Turbulent intermediary business, restless renters
用手机在指南针上开户靠谱吗?这样炒股有没有什么安全隐患