mirror of https://github.com/istio/istio.io.git
290 lines
64 KiB
HTML
290 lines
64 KiB
HTML
<!doctype html><html lang=zh itemscope itemtype=https://schema.org/WebPage><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name=theme-color content="#466BB0"><meta name=title content="HTTP Egress 流量监控和访问策略"><meta name=description content="描述如何配置 Istio 进行 HTTP Egress 流量监控和访问策略。"><meta name=author content="Vadim Eisenberg and Ronen Schaffer (IBM)"><meta name=keywords content="microservices,services,mesh,egress,traffic-management,access-control,monitoring"><meta property="og:title" content="HTTP Egress 流量监控和访问策略"><meta property="og:type" content="website"><meta property="og:description" content="描述如何配置 Istio 进行 HTTP Egress 流量监控和访问策略。"><meta property="og:url" content="/v1.5/zh/blog/2018/egress-monitoring-access-control/"><meta property="og:image" content="/v1.5/img/istio-whitelogo-bluebackground-framed.svg"><meta property="og:image:alt" content="Istio Logo"><meta property="og:image:width" content="112"><meta property="og:image:height" content="150"><meta property="og:site_name" content="Istio"><meta name=twitter:card content="summary"><meta name=twitter:site content="@IstioMesh"><title>Istioldie 1.5 / HTTP Egress 流量监控和访问策略</title><script async src="https://www.googletagmanager.com/gtag/js?id=UA-98480406-2"></script><script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}
|
||
gtag('js',new Date());gtag('config','UA-98480406-2');</script><link rel=alternate type=application/rss+xml title="Istio Blog" href=/v1.5/blog/feed.xml><link rel=alternate type=application/rss+xml title="Istio News" href=/v1.5/news/feed.xml><link rel=alternate type=application/rss+xml title="Istio Blog and News" href=/v1.5/feed.xml><link rel="shortcut icon" href=/v1.5/favicons/favicon.ico><link rel=apple-touch-icon href=/v1.5/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=icon type=image/png href=/v1.5/favicons/favicon-16x16.png sizes=16x16><link rel=icon type=image/png href=/v1.5/favicons/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=/v1.5/favicons/android-36x36.png sizes=36x36><link rel=icon type=image/png href=/v1.5/favicons/android-48x48.png sizes=48x48><link rel=icon type=image/png href=/v1.5/favicons/android-72x72.png sizes=72x72><link rel=icon type=image/png href=/v1.5/favicons/android-96x96.png sizes=96xW96><link rel=icon type=image/png href=/v1.5/favicons/android-144x144.png sizes=144x144><link rel=icon type=image/png href=/v1.5/favicons/android-192x192.png sizes=192x192><link rel=manifest href=/v1.5/manifest.json><meta name=apple-mobile-web-app-title content="Istio"><meta name=application-name content="Istio"><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Work+Sans:400|Chivo:400|Work+Sans:500,300,600,300italic,400italic,500italic,600italic|Chivo:500,300,600,300italic,400italic,500italic,600italic"><link rel=stylesheet href=/v1.5/css/all.css><script src=/v1.5/js/themes_init.min.js></script></head><body class="language-unknown archive-site"><script>const branchName="release-1.5";const docTitle="HTTP Egress 流量监控和访问策略";const iconFile="\/v1.5/img/icons.svg";const buttonCopy='复制到剪切板';const buttonPrint='打印';const buttonDownload='下载';</script><script src="https://www.google.com/cse/brand?form=search-form" defer></script><script src=/v1.5/js/all.min.js data-manual defer></script><header><nav><a id=brand href=/v1.5/zh/><span class=logo><svg viewBox="0 0 300 300"><circle cx="150" cy="150" r="146" stroke-width="2"/><polygon points="65 240 225 240 125 270"/><polygon points="65 230 125 220 125 110"/><polygon points="135 220 225 230 135 30"/></svg></span><span class=name>Istioldie 1.5</span></a><div id=hamburger><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#hamburger"/></svg></div><div id=header-links><a title="了解如何部署、使用和运维 Istio。" href=/v1.5/zh/docs/>文档</a>
|
||
<a class=current title="关于使用 Istio 的博客文章。" href=/v1.5/zh/blog/2020/>博客<i class=dot data-prefix=/blog></i></a>
|
||
<a title="关于 Istio 项目的最新报道。" href=/v1.5/zh/news/>新闻<i class=dot data-prefix=/news></i></a>
|
||
<a title="关于 Istio 的常见问题。" href=/v1.5/zh/faq/>FAQ</a>
|
||
<a title="关于 Istio 项目的说明。" href=/v1.5/zh/about/>关于</a><div class=menu><button id=gearDropdownButton class=menu-trigger title=选项和设置 aria-label="Options and Settings" aria-controls=gearDropdownContent><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#gear"/></svg></button><div id=gearDropdownContent class=menu-content aria-labelledby=gearDropdownButton role=menu><a tabindex=-1 role=menuitem lang=en id=switch-lang-en>English</a>
|
||
<a tabindex=-1 role=menuitem lang=zh id=switch-lang-zh class=active>中文</a><div role=separator></div><a tabindex=-1 role=menuitem class=active id=light-theme-item>亮主题</a>
|
||
<a tabindex=-1 role=menuitem id=dark-theme-item>暗主题</a><div role=separator></div><a tabindex=-1 role=menuitem id=syntax-coloring-item>代码高亮</a><div role=separator></div><h6>本站的其它版本</h6><a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://istio.io/blog\/2018\/egress-monitoring-access-control\/');return false;">当前版本</a>
|
||
<a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://preliminary.istio.io/blog\/2018\/egress-monitoring-access-control\/');return false;">下个版本</a>
|
||
<a tabindex=-1 role=menuitem href=https://istio.io/archive>旧版本</a></div></div><button id=search-show title="搜索 istio.io" aria-label=搜索><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#magnifier"/></svg></button></div><form id=search-form name=cse role=search><input type=hidden name=cx value=002184991200833970123:iwwf17ikgf4>
|
||
<input type=hidden name=ie value=utf-8>
|
||
<input type=hidden name=hl value=en>
|
||
<input type=hidden id=search-page-url value=/v1.5/search>
|
||
<input id=search-textbox class=form-control name=q type=search aria-label="搜索 istio.io">
|
||
<button id=search-close title=取消搜索 type=reset aria-label=取消搜索><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#cancel-x"/></svg></button></form></nav></header><div class=banner-container></div><main class=primary><div id=sidebar-container class="sidebar-container sidebar-offcanvas"><nav id=sidebar aria-label="Section Navigation"><div class=directory><div class=card><button class="header dynamic" id=card0 title="2020 年的博客文章。" aria-controls=card0-body><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#blog"/></svg>2020 年的博客文章</button><div class=body aria-labelledby=card0 role=region id=card0-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card0><li role=none><a role=treeitem title="Istio 的扩展中使用 WASM 的前景。 (2020年3月5日)" href=/v1.5/zh/blog/2020/wasm-announce/>重新定义代理的扩展性:Envoy 和 Istio 引入 WebAssembly</a></li><li role=none><a role=treeitem title="Istio 在 2020 年的愿景声明及路线图。 (2020年3月3日)" href=/v1.5/zh/blog/2020/tradewinds-2020/>Istio 2020——为了商用</a></li><li role=none><a role=treeitem title="一种更安全的秘密管理方式。 (2020年2月20日)" href=/v1.5/zh/blog/2020/istio-agent/>移除跨 pod Unix domain socket</a></li><li role=none><a role=treeitem title="为 Istio deployment(cluster)提供自动化 Istio 配置,并让其像单个网格一样工作。 (2020年1月5日)" href=/v1.5/zh/blog/2020/multi-cluster-mesh-automation/>使用 Admiral 管理 Istio 多集群的配置和服务发现</a></li></ul></div></div><div class=card><button class="header dynamic" id=card1 title="2019 年的博客文章。" aria-controls=card1-body><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#blog"/></svg>2019 年的博客文章</button><div class=body aria-labelledby=card1 role=region id=card1-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card1><li role=none><a role=treeitem title="一种更安全管理 Istio webhook 的方法。 (2019年11月14日)" href=/v1.5/zh/blog/2019/webhook/>安全管理 Webhook</a></li><li role=none><a role=treeitem title="关于 Istio 基于 operator 的安装和控制平面管理特性的介绍。 (2019年11月14日)" href=/v1.5/zh/blog/2019/introducing-istio-operator/>Istio Operator 简介</a></li><li role=none><a role=treeitem title="Istio v1beta1 授权策略的设计原则、基本概述及迁移操作。 (2019年11月14日)" href=/v1.5/zh/blog/2019/v1beta1-authorization-policy/>Istio v1beta1 授权策略概述</a></li><li role=none><a role=treeitem title="通过分析 Istio 配置来发现潜在问题和一般问题。 (2019年11月14日)" href=/v1.5/zh/blog/2019/introducing-istioctl-analyze/>istioctl analyze 介绍</a></li><li role=none><a role=treeitem title="在 Istio 中配置和管理 DNS 证书。 (2019年11月14日)" href=/v1.5/zh/blog/2019/dns-cert/>DNS 证书管理</a></li><li role=none><a role=treeitem title="正式启用访问 Istio 资源。 (2019年11月14日)" href=/v1.5/zh/blog/2019/announcing-istio-client-go/>Istio client-go 发布公告</a></li><li role=none><a role=treeitem title="把 Istio 入口网关配置为外部服务的代理。 (2019年10月15日)" href=/v1.5/zh/blog/2019/proxy/>把 Istio 作为外部服务的代理</a></li><li role=none><a role=treeitem title="将需要隔离的环境部署到单独的网格中,并通过网格联邦启用网格间通信。 (2019年10月2日)" href=/v1.5/zh/blog/2019/isolated-clusters/>用于隔离和边界保护的多网格部署</a></li><li role=none><a role=treeitem title="如何使用 Istio 去监控被阻止的和透传的外部服务流量。 (2019年9月28日)" href=/v1.5/zh/blog/2019/monitoring-external-service-traffic/>监控被阻止的和透传的外部服务流量</a></li><li role=none><a role=treeitem title="本文演示 Mixer 进程外适配器实现 Knative scale-from-zero 逻辑的具体过程。 (2019年9月18日)" href=/v1.5/zh/blog/2019/knative-activator-adapter/>适用于 Knative 的 Mixer 适配器</a></li><li role=none><a role=treeitem title="使用 Istio 实现零代码改动保护多云 Kubernetes 应用。 (2019年9月18日)" href=/v1.5/zh/blog/2019/app-identity-and-access-adapter/>APP 身份和访问适配器</a></li><li role=none><a role=treeitem title="利用 Kubernetes 可信任的 JWT 来更安全地为工作负载实例颁发证书。 (2019年9月10日)" href=/v1.5/zh/blog/2019/trustworthy-jwt-sds/>Istio 1.3 Secret 服务发现的更改</a></li><li role=none><a role=treeitem title="Istio API 的设计原则和这些 API 是如何演变的。 (2019年8月5日)" href=/v1.5/zh/blog/2019/evolving-istios-apis/>Istio API 的演变</a></li><li role=none><a role=treeitem title="管控出口流量的备选方案比较,包括性能因素。 (2019年7月22日)" href=/v1.5/zh/blog/2019/egress-traffic-control-in-istio-part-3/>Istio 中安全管控出口流量,第三部分</a></li><li role=none><a role=treeitem title="使用 Istio 的出口流量管控来阻止相关出口流量攻击。 (2019年7月10日)" href=/v1.5/zh/blog/2019/egress-traffic-control-in-istio-part-2/>Istio 中的安全管控出口流量,第二部分</a></li><li role=none><a role=treeitem title="评估 Istio 数据平面性能的工具和指南。 (2019年7月9日)" href=/v1.5/zh/blog/2019/performance-best-practices/>最佳实践:Service Mesh 基准性能测试</a></li><li role=none><a role=treeitem title="了解如何延长 Istio 自签名根证书的有效期。 (2019年6月7日)" href=/v1.5/zh/blog/2019/root-transition/>延长 Istio 自签名根证书的有效期</a></li><li role=none><a role=treeitem title="涉及出口流量攻击和出口流量管控要求。 (2019年5月22日)" href=/v1.5/zh/blog/2019/egress-traffic-control-in-istio-part-1/>Istio 中的安全管控出口流量,第一部分</a></li><li role=none><a role=treeitem title="Istio 1.1 性能概览。 (2019年3月19日)" href=/v1.5/zh/blog/2019/istio1.1_perf/>为性能而设计的 Istio 1.1</a></li><li role=none><a role=treeitem title="在多集群服务网格环境中配置 Istio 的路由规则。 (2019年2月7日)" href=/v1.5/zh/blog/2019/multicluster-version-routing/>多集群服务网格中的分版本路由</a></li><li role=none><a role=treeitem title="宣布新的博客策略。 (2019年2月5日)" href=/v1.5/zh/blog/2019/sail-the-blog/>博客策略更新!</a></li><li role=none><a role=treeitem title="揭秘 Istio 是如何将其数据平面组件添加到现有 deployment。 (2019年1月31日)" href=/v1.5/zh/blog/2019/data-plane-setup/>揭开 Istio Sidecar 注入模型的神秘面纱</a></li><li role=none><a role=treeitem title="评估加入 Egress gateway 对性能造成的影响。 (2019年1月31日)" href=/v1.5/zh/blog/2019/egress-performance/>Egress gateway 性能测试</a></li><li role=none><a role=treeitem title="使用 AppSwitch 解决应用程序启动顺序和启动延迟。 (2019年1月14日)" href=/v1.5/zh/blog/2019/appswitch/>使用 AppSwitch 进行 Sidestepping 依赖性排序</a></li><li role=none><a role=treeitem title="Istio 有了一个新的论坛。 (2019年1月10日)" href=/v1.5/zh/blog/2019/announcing-discuss.istio.io/>Istio 论坛成立</a></li><li role=none><a role=treeitem title="如何使用 cert-manager 手工部署一个自定义 Ingress 网关。 (2019年1月10日)" href=/v1.5/zh/blog/2019/custom-ingress-gateway/>使用 Cert-Manager 部署一个自定义 Ingress 网关</a></li></ul></div></div><div class=card><button class="header dynamic" id=card2 title="2018 年的博客文章。" aria-controls=card2-body><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#blog"/></svg>2018 年的博客文章</button><div class="body default" aria-labelledby=card2 role=region id=card2-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card2><li role=none><a role=treeitem title="如何在不部署 Sidecar 代理的情况下使用 Istio 进行流量管理。 (2018年11月21日)" href=/v1.5/zh/blog/2018/incremental-traffic-management/>增量式应用 Istio 第一部分,流量管理</a></li><li role=none><a role=treeitem title="描述了一个基于 Istio 的 Bookinfo 示例的简单场景。 (2018年11月16日)" href=/v1.5/zh/blog/2018/egress-mongo/>使用外部 MongoDB 服务</a></li><li role=none><a role=treeitem title="Istio 在 Twitch 举办了为期一天的直播庆祝 1.0 的发布。 (2018年8月3日)" href=/v1.5/zh/blog/2018/istio-twitch-stream/>Istio 在 Twitch 上全天直播</a></li><li role=none><a role=treeitem title="惠普如何在 Istio 上构建其下一代鞋类个性化平台。 (2018年7月31日)" href=/v1.5/zh/blog/2018/hp/>Istio 是惠普 FitStation 平台的改变者</a></li><li role=none><a role=treeitem title="使用 AppSwitch 自动接入应用并降低延迟。 (2018年7月30日)" href=/v1.5/zh/blog/2018/delayering-istio/>使用 AppSwitch 精简 Istio 层次</a></li><li role=none><a role=treeitem title="描述 Istio 的授权功能以及如何在各种用例中使用它。 (2018年7月20日)" href=/v1.5/zh/blog/2018/istio-authorization/>基于 Istio 授权的 Micro-Segmentation</a></li><li role=none><a role=treeitem title="如何通过 Stackdriver 将 Istio 访问日志导出到 BigQuery、GCS、Pub/Sub 等不同的接收器。 (2018年7月9日)" href=/v1.5/zh/blog/2018/export-logs-through-stackdriver/>通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub</a></li><li role=none><span role=treeitem class=current title="描述如何配置 Istio 进行 HTTP Egress 流量监控和访问策略。 (2018年6月22日)">HTTP Egress 流量监控和访问策略</span></li><li role=none><a role=treeitem title="Istio v1alpha3 路由 API 介绍, 动机及其设计原则。 (2018年4月25日)" href=/v1.5/zh/blog/2018/v1alpha3-routing/>Istio v1aplha3 路由 API 介绍</a></li><li role=none><a role=treeitem title="描述如何在 AWS 上使用网络负载均衡器配置 Istio Ingress。 (2018年4月20日)" href=/v1.5/zh/blog/2018/aws-nlb/>使用 AWS NLB 配置 Istio Ingress</a></li><li role=none><a role=treeitem title="使用 Kubernetes 命名空间和 RBAC 为 Istio 构建软性多租户环境。 (2018年4月19日)" href=/v1.5/zh/blog/2018/soft-multitenancy/>Istio 的软性多租户支持</a></li><li role=none><a role=treeitem title="介绍更安全,低风险的部署和发布到生产。 (2018年2月8日)" href=/v1.5/zh/blog/2018/traffic-mirroring/>用于在生产环境进行测试的 Istio 流量镜像功能</a></li><li role=none><a role=treeitem title="描述基于 Istio 的 Bookinfo 示例的简单场景。 (2018年2月6日)" href=/v1.5/zh/blog/2018/egress-tcp/>使用外部 TCP 服务</a></li><li role=none><a role=treeitem title="描述基于 Istio Bookinfo 示例的简单场景。 (2018年1月31日)" href=/v1.5/zh/blog/2018/egress-https/>使用外部 Web 服务</a></li></ul></div></div><div class=card><button class="header dynamic" id=card3 title="2017 年的博客文章。" aria-controls=card3-body><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#blog"/></svg>2017 年的博客文章</button><div class=body aria-labelledby=card3 role=region id=card3-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card3><li role=none><a role=treeitem title="提高可用,降低延迟。 (2017年12月7日)" href=/v1.5/zh/blog/2017/mixer-spof-myth/>Mixer 和 SPOF 神话</a></li><li role=none><a role=treeitem title="概要说明 Mixer 的插件架构。 (2017年11月3日)" href=/v1.5/zh/blog/2017/adapter-model/>Mixer 适配器模型</a></li><li role=none><a role=treeitem title="Istio 的策略如何关联 Kubernetes 的网络策略 。 (2017年8月10日)" href=/v1.5/zh/blog/2017/0.1-using-network-policy/>Istio 使用网络策略</a></li><li role=none><a role=treeitem title="使用 Istio 创建自动缩放的金丝雀部署。 (2017年6月14日)" href=/v1.5/zh/blog/2017/0.1-canary/>使用 Istio 进行金丝雀部署</a></li><li role=none><a role=treeitem title="Istio Auth 0.1 公告。 (2017年5月25日)" href=/v1.5/zh/blog/2017/0.1-auth/>使用 Istio 增强端到端安全</a></li></ul></div></div></div></nav></div><div class=article-container><button tabindex=-1 id=sidebar-toggler title=折叠导航栏><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#pull"/></svg></button><nav aria-label=Breadcrumb><ol><li><a href=/v1.5/zh/ title=用于连接、保护、控制和观测服务。>Istio</a></li><li><a href=/v1.5/zh/blog/ title="关于使用 Istio 的博客文章。">博客</a></li><li><a href=/v1.5/zh/blog/2018/ title="2018 年的博客文章。">2018 年的博客文章</a></li><li>HTTP Egress 流量监控和访问策略</li></ol></nav><article aria-labelledby=title><div class=title-area><div style=width:100%><h1 id=title>HTTP Egress 流量监控和访问策略</h1><p class=byline><span>作者</span>
|
||
<span class=attribution>Vadim Eisenberg and Ronen Schaffer (IBM)</span><span> | </span><span><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#calendar"/></svg><span> </span>2018年6月22日<span> </span>(更新于 2019年3月4日)</span><span> | </span><span title="1494 字"><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#clock"/></svg><span> </span>阅读大约需要 8 分钟</span></p></div></div><nav class=toc-inlined aria-label="Table of Contents"><div><hr><ol><li role=none aria-label=用例><a href=#use-case>用例</a><li role=none aria-label=相关工作和示例><a href=#related-tasks-and-examples>相关工作和示例</a><li role=none aria-label=开始之前><a href=#before-you-begin>开始之前</a><li role=none aria-label=配置监控和访问策略><a href=#configure-monitoring-and-access-policies>配置监控和访问策略</a><ol><li role=none aria-label=日志><a href=#logging>日志</a><li role=none aria-label=路由访问控制><a href=#access-control-by-routing>路由访问控制</a><li role=none aria-label="Mixer 策略检查访问控制"><a href=#access-control-by-Mixer-policy-checks>Mixer 策略检查访问控制</a><li role=none aria-label="Mixer 策略检查访问控制,第二部分"><a href=#access-control-by-Mixer-policy-checks-part-2>Mixer 策略检查访问控制,第二部分</a></ol></li><li role=none aria-label="与 HTTPS egress 流量控制进行比较"><a href=#comparison-with-HTTPS-egress-traffic-control>与 HTTPS egress 流量控制进行比较</a><li role=none aria-label=总结><a href=#summary>总结</a><li role=none aria-label=清理><a href=#cleanup>清理</a><li role=none aria-label=相关内容><a href=#see-also>相关内容</a></li></ol><hr></div></nav><div><aside class="callout warning"><div class=type><svg class="large-icon"><use xlink:href="/v1.5/img/icons.svg#callout-warning"/></svg></div><div class=content>该博客文章是在 Istio 1.1 的版本下编写的,因此其中某些内容现在可能已过时。</div></aside></div><p>虽然 Istio 的主要关注点是管理服务网格内微服务之间的流量,但它也可以管理 ingress (从外部进入网格) 和 egress (从网格向外) 的流量。Istio 可以统一执行访问策略,并为网格内部、ingress 和 egress 流量聚合遥测数据。</p><p>在这篇博客文章中,将向您展示如何使用 Istio 进行 HTTP Egress 流量监控和访问策略。</p><h2 id=use-case>用例</h2><p>考虑一个运行处理 <em>cnn.com</em> 内容的应用程序的组织。应用程序被解耦为部署在 Istio 服务网格中的微服务。应用程序访问 <em>cnn.com</em> 的各种话题页面:<a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a>, <a href=https://edition.cnn.com/sport>edition.cnn.com/sport</a> 和 <a href=https://edition.cnn.com/health>edition.cnn.com/health</a>。该组织<a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway-tls-origination/>配置了访问 edition.cnn.com 的权限</a>,一切都正常运行。然而,在某一时刻,本组织决定移除政治话题。实际上,这意味着禁止访问 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> ,只允许访问 <a href=https://edition.cnn.com/sport>edition.cnn.com/sport</a> 和 <a href=https://edition.cnn.com/health>edition.cnn.com/health</a> 。该组织将根据具体情况,向个别应用程序和特定用户授予访问 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> 的权限。</p><p>为了实现这一目标,组织的运维人员监控对外部服务的访问,并分析 Istio 日志,以验证没有向 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> 发送未经授权的请求。他们还配置了 Istio 来防止自动访问 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> 。</p><p>本组织决心防止对新策略的任何篡改,决定设置一些机制以防止恶意应用程序访问禁止的话题。</p><h2 id=related-tasks-and-examples>相关工作和示例</h2><ul><li><a href=/v1.5/zh/docs/tasks/traffic-management/egress/>Control Egress 流量</a>任务演示了网格内的应用程序如何访问外部(Kubernetes 集群之外) HTTP 和 HTTPS 服务。</li><li><a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway/>配置 Egress 网关</a>示例描述了如何配置 Istio 来通过一个称为 <em>出口网关</em> 的专用网关服务来引导出口流量。</li><li><a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway-tls-origination/>带 TLS 发起的 Egress 网关</a>示例演示了如何允许应用程序向需要 HTTPS 的外部服务器发送 HTTP 请求,同时通过 Egress Gateway 引导流量。</li><li><a href=/v1.5/zh/docs/tasks/observability/metrics/collecting-metrics/>收集指标</a>任务描述如何为网格中的服务配置指标。</li><li><a href=/v1.5/zh/docs/tasks/observability/metrics/using-istio-dashboard/>Grafana 的可视化指标</a>描述了用于监控网格流量的 Istio 仪表板。</li><li><a href=/v1.5/zh/docs/tasks/policy-enforcement/denial-and-list/>基本访问控制</a>任务显示如何控制对网格内服务的访问。</li><li><a href=/v1.5/zh/docs/tasks/policy-enforcement/denial-and-list/>拒绝和白/黑名单</a>任务显示如何使用黑名单或白名单检查器配置访问策略。</li></ul><p>与上面的遥测和安全任务相反,这篇博客文章描述了 Istio 的监控和访问策略,专门应用于 egress 流量。</p><h2 id=before-you-begin>开始之前</h2><p>按照<a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway-tls-origination/>带 TLS 发起的 Egress 网关</a>中的步骤,<strong>启用了双向 TLS 身份验证</strong>,而不需要<a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway-tls-origination//#cleanup>清除</a>步骤。完成该示例后,您可以从安装了 <code>curl</code> 的网格中容器访问 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a>。本文假设 <code>SOURCE_POD</code> 环境变量包含源 pod 的名称,容器的名称为 <code>sleep</code>。</p><h2 id=configure-monitoring-and-access-policies>配置监控和访问策略</h2><p>由于您希望以 <em>安全方式</em> 完成您的任务,您应该通过 <em>egress 网关</em> 引导流量,正如<a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway-tls-origination/>带 TLS 发起的 Egress 网关</a>任务中所描述的那样。这里的 <em>安全方式</em> 意味着您希望防止恶意应用程序绕过 Istio 监控和策略强制。</p><p>根据我们的场景,组织执行了<a href=#before-you-begin>开始之前</a>部分中的命令,启用 HTTP 流量到 <em>edition.cnn.com</em> ,并将该流量配置为通过 egress 网关。egress 网关执行 TLS 发起到 <em>edition.cnn.com</em> ,因此流量在网格中被加密。此时,组织已经准备好配置 Istio 来监控和应用 <em>edition.cnn.com</em> 流量的访问策略。</p><h3 id=logging>日志</h3><p>配置 Istio 以记录对 <em>*.cnn.com</em> 的访问。创建一个 <code>logentry</code> 和两个 <a href=/v1.5/zh/docs/reference/config/policy-and-telemetry/adapters/stdio/>stdio</a> <code>handlers</code>,一个用于记录禁止访问(<em>error</em> 日志级别),另一个用于记录对 <em>*.cnn.com</em> 的所有访问(<em>info</em> 日志级别)。然后创建规则将 <code>logentry</code> 实例定向到 <code>handlers</code>。一个规则指导访问 <em>*.cnn.com/politics</em> 为日志禁止访问处理程序, 另一个规则指导日志条目的处理程序,输出每个访问 <em>*.cnn.com</em> 作为 <em>info</em> 的日志级别。要了解 Istio <code>logentries</code>、<code>rules</code> 和 <code>handlers</code>,请参见 <a href=/v1.5/zh/blog/2017/adapter-model/>Istio 适配器模型</a>。下图显示了涉及的实体和它们之间的依赖关系:</p><figure style=width:80%><div class=wrapper-with-intrinsic-ratio style=padding-bottom:46.46700562636976%><a data-skipendnotes=true href=/v1.5/zh/blog/2018/egress-monitoring-access-control/egress-adapters-monitoring.svg title="用于 egress 监视和访问策略的实例、规则和处理程序"><img class=element-to-stretch src=/v1.5/zh/blog/2018/egress-monitoring-access-control/egress-adapters-monitoring.svg alt="用于 egress 监视和访问策略的实例、规则和处理程序"></a></div><figcaption>用于 egress 监视和访问策略的实例、规则和处理程序</figcaption></figure><ol><li><p>创建 <code>logentry</code>、 <code>rules</code> 和 <code>handlers</code>。 注意您指定了 <code>context.reporter.uid</code> 作为
|
||
<code>kubernetes://istio-egressgateway</code> 在规则中只能从 egress 网关获取日志信息。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -f -
|
||
# Log entry for egress access
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: logentry
|
||
metadata:
|
||
name: egress-access
|
||
namespace: istio-system
|
||
spec:
|
||
severity: '"info"'
|
||
timestamp: request.time
|
||
variables:
|
||
destination: request.host | "unknown"
|
||
path: request.path | "unknown"
|
||
responseCode: response.code | 0
|
||
responseSize: response.size | 0
|
||
reporterUID: context.reporter.uid | "unknown"
|
||
sourcePrincipal: source.principal | "unknown"
|
||
monitored_resource_type: '"UNSPECIFIED"'
|
||
---
|
||
# Handler for error egress access entries
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: stdio
|
||
metadata:
|
||
name: egress-error-logger
|
||
namespace: istio-system
|
||
spec:
|
||
severity_levels:
|
||
info: 2 # output log level as error
|
||
outputAsJson: true
|
||
---
|
||
# Rule to handle access to *.cnn.com/politics
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: rule
|
||
metadata:
|
||
name: handle-politics
|
||
namespace: istio-system
|
||
spec:
|
||
match: request.host.endsWith("cnn.com") && request.path.startsWith("/politics") && context.reporter.uid.startsWith("kubernetes://istio-egressgateway")
|
||
actions:
|
||
- handler: egress-error-logger.stdio
|
||
instances:
|
||
- egress-access.logentry
|
||
---
|
||
# Handler for info egress access entries
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: stdio
|
||
metadata:
|
||
name: egress-access-logger
|
||
namespace: istio-system
|
||
spec:
|
||
severity_levels:
|
||
info: 0 # output log level as info
|
||
outputAsJson: true
|
||
---
|
||
# Rule to handle access to *.cnn.com
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: rule
|
||
metadata:
|
||
name: handle-cnn-access
|
||
namespace: istio-system
|
||
spec:
|
||
match: request.host.endsWith(".cnn.com") && context.reporter.uid.startsWith("kubernetes://istio-egressgateway")
|
||
actions:
|
||
- handler: egress-access-logger.stdio
|
||
instances:
|
||
- egress-access.logentry
|
||
EOF
|
||
</code></pre></li><li><p>发送三个 HTTP 请求到 <em>cnn.com</em> 、 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a>、 <a href=https://edition.cnn.com/sport>edition.cnn.com/sport</a> 和 <a href=https://edition.cnn.com/health>edition.cnn.com/health</a>。
|
||
三个请求都应该返回 <em>200 OK</em> 。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/politics; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/sport; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/health'
|
||
200
|
||
200
|
||
200
|
||
</code></pre></li><li><p>查询 Mixer 日志,查看请求信息出现在日志中:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl -n istio-system logs -l istio-mixer-type=telemetry -c mixer | grep egress-access | grep cnn | tail -4
|
||
{"level":"info","time":"2019-01-29T07:43:24.611462Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/politics","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":200,"responseSize":1883355,"sourcePrincipal":"cluster.local/ns/default/sa/sleep"}
|
||
{"level":"info","time":"2019-01-29T07:43:24.886316Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/sport","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":200,"responseSize":2094561,"sourcePrincipal":"cluster.local/ns/default/sa/sleep"}
|
||
{"level":"info","time":"2019-01-29T07:43:25.369663Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/health","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":200,"responseSize":2157009,"sourcePrincipal":"cluster.local/ns/default/sa/sleep"}
|
||
{"level":"error","time":"2019-01-29T07:43:24.611462Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/politics","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":200,"responseSize":1883355,"sourcePrincipal":"cluster.local/ns/default/sa/sleep"}
|
||
</code></pre><p>您将看到与您的三个请求相关的四个日志条目。三个关于访问 <em>edition.cnn.com</em> 的 <em>info</em> 信息和一个关于访问 <em>edition.cnn.com/politics</em> 的 <em>error</em> 信息。服务网格 operators 可以查看所有访问实例,还可以搜索日志中表示禁止访问的 <em>error</em> 日志。这是在自动地阻塞禁止访问之前可以应用的第一个安全措施,即将所有禁止访问实例记录为错误。在某些设置中,这可能是一个足够的安全措施。</p><p>注意以下属性:</p><ul><li><code>destination</code>、 <code>path</code>、 <code>responseCode</code> 和 <code>responseSize</code> 与请求的 HTTP 参数相关</li><li><code>sourcePrincipal</code>:<code>cluster.local/ns/default/sa/sleep</code> —— 表示 <code>default</code> 命名空间中的 <code>sleep</code> 服务帐户的字符串</li><li><code>reporterUID</code>: <code>kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system</code> —— 报告 pod 的 UID,在本例中为 <code>istio-egressgateway-747b6764b8-44rrh</code>,位于 <code>istio-system</code> 命名空间中</li></ul></li></ol><h3 id=access-control-by-routing>路由访问控制</h3><p>启用对 <em>edition.cnn.com</em> 的访问进行日志记录之后,自动执行访问策略,即只允许访问 <em>/health</em> 和 <em>/sport</em> URL 路径。这样一个简单的策略控制可以通过 Istio 路由实现。</p><ol><li><p>为 <em>edition.cnn.com</em> 重定义 <code>VirtualService</code> :</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -f -
|
||
apiVersion: networking.istio.io/v1alpha3
|
||
kind: VirtualService
|
||
metadata:
|
||
name: direct-cnn-through-egress-gateway
|
||
spec:
|
||
hosts:
|
||
- edition.cnn.com
|
||
gateways:
|
||
- istio-egressgateway
|
||
- mesh
|
||
http:
|
||
- match:
|
||
- gateways:
|
||
- mesh
|
||
port: 80
|
||
route:
|
||
- destination:
|
||
host: istio-egressgateway.istio-system.svc.cluster.local
|
||
subset: cnn
|
||
port:
|
||
number: 443
|
||
weight: 100
|
||
- match:
|
||
- gateways:
|
||
- istio-egressgateway
|
||
port: 443
|
||
uri:
|
||
regex: "/health|/sport"
|
||
route:
|
||
- destination:
|
||
host: edition.cnn.com
|
||
port:
|
||
number: 443
|
||
weight: 100
|
||
EOF
|
||
</code></pre><p>注意,您通过 <code>url</code> 添加添加了一个 <code>match</code>,该条件检查 URL 路径是 <em>/health</em> 还是 <em>/sport</em> 。还要注意,此条件已添加到 <code>VirtualService</code> 的 <code>istio-egressgateway</code> 部分,因为就安全性而言,egress 网关是一个经过加固的组件(请参阅 <a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway/#additional-security-considerations>egress 网关安全性注意事项</a>)。您一定不希望您的任何策略被篡改。</p></li><li><p>发送之前的三个 HTTP 请求到 <em>cnn.com</em> :</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/politics; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/sport; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/health'
|
||
404
|
||
200
|
||
200
|
||
</code></pre><p>向 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> 发送请求会返回 <em>404 Not Found</em> , 然而向
|
||
<a href=https://edition.cnn.com/sport>edition.cnn.com/sport</a> 和
|
||
<a href=https://edition.cnn.com/health>edition.cnn.com/health</a> 发送请求,会像我们预想的那样返回 <em>200 OK</em> 。</p><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.5/img/icons.svg#callout-tip"/></svg></div><div class=content>您可能需要等待几秒钟,等待 <code>VirtualService</code> 的更新传播到 egress 网关。</div></aside></div></li><li><p>查询 Mixer 日志,可以看到关于请求的信息再次出现在日志中:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl -n istio-system logs -l istio-mixer-type=telemetry -c mixer | grep egress-access | grep cnn | tail -4
|
||
{"level":"info","time":"2019-01-29T07:55:59.686082Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/politics","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":404,"responseSize":0,"sourcePrincipal":"cluster.local/ns/default/sa/sleep"}
|
||
{"level":"info","time":"2019-01-29T07:55:59.697565Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/sport","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":200,"responseSize":2094561,"sourcePrincipal":"cluster.local/ns/default/sa/sleep"}
|
||
{"level":"info","time":"2019-01-29T07:56:00.264498Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/health","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":200,"responseSize":2157009,"sourcePrincipal":"cluster.local/ns/default/sa/sleep"}
|
||
{"level":"error","time":"2019-01-29T07:55:59.686082Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/politics","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":404,"responseSize":0,"sourcePrincipal":"cluster.local/ns/default/sa/sleep"}
|
||
</code></pre><p>你依然会得到关于访问 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> 的信息和错误消息,然而这次 <code>responseCode</code> 会像我们预想的那样返回 <code>404</code> 。</p></li></ol><p>虽然在这个简单的例子中使用 Istio 路由实现访问控制是可行的,但是在更复杂的例子中就不够了。例如,组织可能希望在某些条件下允许访问 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a>,因此需要比仅通过 URL 路径过滤更复杂的策略逻辑。您可能想要应用 Istio Mixer 适配器,例如允许/禁止 URL 路径的<a href=/v1.5/zh/docs/tasks/policy-enforcement/denial-and-list/#attribute-based-whitelists-or-blacklists>白名单或黑名单</a>。策略规则允许指定复杂的条件,用丰富的表达式语言指定,其中包括与和或逻辑运算符。这些规则可用于日志记录和策略检查。更高级的用户可能希望应用基于 <a href=/v1.5/zh/docs/concepts/security/#authorization>Istio 角色访问控制</a>。</p><p>另一方面是与远程访问策略系统的集成。如果在我们的用例中组织操作一些<a href=https://en.wikipedia.org/wiki/Identity_management>标识和访问管理</a>系统,您可能希望配置 Istio 来使用来自这样一个系统的访问策略信息。您可以通过应用 <a href=/v1.5/zh/blog/2017/adapter-model/>Istio Mixer 适配器</a>来实现这种集成。</p><p>现在您移除在本节中使用的路由取消访问控制,在下一节将向您演示通过 Mixer 策略检查实现访问控制。</p><ol><li><p>用之前<a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway-tls-origination/#perform-TLS-origination-with-an-egress-gateway>配置 Egress 网关</a>示例中的版本替换 <em>edition.cnn.com</em> 的 <code>VirtualService</code>:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -f -
|
||
apiVersion: networking.istio.io/v1alpha3
|
||
kind: VirtualService
|
||
metadata:
|
||
name: direct-cnn-through-egress-gateway
|
||
spec:
|
||
hosts:
|
||
- edition.cnn.com
|
||
gateways:
|
||
- istio-egressgateway
|
||
- mesh
|
||
http:
|
||
- match:
|
||
- gateways:
|
||
- mesh
|
||
port: 80
|
||
route:
|
||
- destination:
|
||
host: istio-egressgateway.istio-system.svc.cluster.local
|
||
subset: cnn
|
||
port:
|
||
number: 443
|
||
weight: 100
|
||
- match:
|
||
- gateways:
|
||
- istio-egressgateway
|
||
port: 443
|
||
route:
|
||
- destination:
|
||
host: edition.cnn.com
|
||
port:
|
||
number: 443
|
||
weight: 100
|
||
EOF
|
||
</code></pre></li><li><p>发送之前的三个 HTTP 请求到 <em>cnn.com</em> , 这一次您应该会收到三个 <em>200 OK</em> 的响应:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/politics; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/sport; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/health'
|
||
200
|
||
200
|
||
200
|
||
</code></pre></li></ol><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.5/img/icons.svg#callout-tip"/></svg></div><div class=content>您可能需要等待几秒钟,等待 <code>VirtualService</code> 的更新传播到 egress 网关。</div></aside></div><h3 id=access-control-by-Mixer-policy-checks>Mixer 策略检查访问控制</h3><p>在该步骤中,您使用 Mixer <a href=/v1.5/zh/docs/reference/config/policy-and-telemetry/adapters/list/><code>Listchecker</code> 适配器</a>,它是一种白名单。您可以使用请求的 URL 路径定义一个 <code>listentry</code>,并使用一个 <code>listchecker</code> 由 <code>overrides</code> 字段指定的允许 URL 路径的静态列表检查 <code>listentry</code>。对于<a href=https://en.wikipedia.org/wiki/Identity_management>外部标识和访问管理</a>系统,请使用 <code>providerurl</code> 字段。实例、规则和处理程序的更新图如下所示。注意,您重用相同的策略规则 <code>handle-cn-access</code> 来进行日志记录和访问策略检查。</p><figure style=width:80%><div class=wrapper-with-intrinsic-ratio style=padding-bottom:52.79420593027812%><a data-skipendnotes=true href=/v1.5/zh/blog/2018/egress-monitoring-access-control/egress-adapters-monitoring-policy.svg title="用于 egress 监视和访问策略的实例、规则和处理程序"><img class=element-to-stretch src=/v1.5/zh/blog/2018/egress-monitoring-access-control/egress-adapters-monitoring-policy.svg alt="用于 egress 监视和访问策略的实例、规则和处理程序"></a></div><figcaption>用于 egress 监视和访问策略的实例、规则和处理程序</figcaption></figure><ol><li><p>定义 <code>path-checker</code> 和 <code>request-path</code>:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl create -f -
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: listchecker
|
||
metadata:
|
||
name: path-checker
|
||
namespace: istio-system
|
||
spec:
|
||
overrides: ["/health", "/sport"] # overrides provide a static list
|
||
blacklist: false
|
||
---
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: listentry
|
||
metadata:
|
||
name: request-path
|
||
namespace: istio-system
|
||
spec:
|
||
value: request.path
|
||
EOF
|
||
</code></pre></li><li><p>修改 <code>handle-cnn-access</code> 策略规则并发送 <code>request-path</code> 实例到 <code>path-checker</code>:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -f -
|
||
# Rule handle egress access to cnn.com
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: rule
|
||
metadata:
|
||
name: handle-cnn-access
|
||
namespace: istio-system
|
||
spec:
|
||
match: request.host.endsWith(".cnn.com") && context.reporter.uid.startsWith("kubernetes://istio-egressgateway")
|
||
actions:
|
||
- handler: egress-access-logger.stdio
|
||
instances:
|
||
- egress-access.logentry
|
||
- handler: path-checker.listchecker
|
||
instances:
|
||
- request-path.listentry
|
||
EOF
|
||
</code></pre></li><li><p>执行常规测试,将 HTTP 请求发送到 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a>, <a href=https://edition.cnn.com/sport>edition.cnn.com/sport</a> 和 <a href=https://edition.cnn.com/health>edition.cnn.com/health</a>。正如所料,对 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> 的请求返回 <em>403</em> (禁止)。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/politics; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/sport; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/health'
|
||
403
|
||
200
|
||
200
|
||
</code></pre></li></ol><h3 id=access-control-by-Mixer-policy-checks-part-2>Mixer 策略检查访问控制,第二部分</h3><p>在我们用例中的组织设法配置日志和访问控制之后,它决定扩展它的访问策略,允许具有特殊<a href=https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/>服务帐户</a>的应用程序访问 <em>cnn.com</em> 的任何主题,而不受监控。您将看到如何在 Istio 中配置此需求。</p><ol><li><p>使用 <code>politics</code> 服务账户开启 <a href=https://github.com/istio/istio/tree/release-1.5/samples/sleep>sleep</a> 示例程序。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ sed 's/: sleep/: politics/g' samples/sleep/sleep.yaml | kubectl create -f -
|
||
serviceaccount "politics" created
|
||
service "politics" created
|
||
deployment "politics" created
|
||
</code></pre></li><li><p>定义 <code>SOURCE_POD_POLITICS</code> shell 变量来保存带有 <code>politics</code> 服务帐户的源 pod 的名称,以便向外部服务发送请求。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ export SOURCE_POD_POLITICS=$(kubectl get pod -l app=politics -o jsonpath={.items..metadata.name})
|
||
</code></pre></li><li><p>执行常规测试,这次从 <code>SOURCE_POD_POLITICS</code> 发送三个 HTTP 请求。对 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> 的请求返回 <em>403</em> ,因为您没有为 <em>politics</em> 命名空间配置异常。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec -it $SOURCE_POD_POLITICS -c politics -- sh -c 'curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/politics; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/sport; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/health'
|
||
403
|
||
200
|
||
200
|
||
</code></pre></li><li><p>查询 Mixer 日志,可以看到来自 <em>politics</em> 命名空间的请求信息出现在日志中:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl -n istio-system logs -l istio-mixer-type=telemetry -c mixer | grep egress-access | grep cnn | tail -4
|
||
{"level":"info","time":"2019-01-29T08:04:42.559812Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/politics","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":403,"responseSize":84,"sourcePrincipal":"cluster.local/ns/default/sa/politics"}
|
||
{"level":"info","time":"2019-01-29T08:04:42.568424Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/sport","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":200,"responseSize":2094561,"sourcePrincipal":"cluster.local/ns/default/sa/politics"}
|
||
{"level":"error","time":"2019-01-29T08:04:42.559812Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/politics","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":403,"responseSize":84,"sourcePrincipal":"cluster.local/ns/default/sa/politics"}
|
||
{"level":"info","time":"2019-01-29T08:04:42.615641Z","instance":"egress-access.logentry.istio-system","destination":"edition.cnn.com","path":"/health","reporterUID":"kubernetes://istio-egressgateway-747b6764b8-44rrh.istio-system","responseCode":200,"responseSize":2157009,"sourcePrincipal":"cluster.local/ns/default/sa/politics"}
|
||
</code></pre><p>注意 <code>sourcePrincipal</code> 是 <code>cluster.local/ns/default/sa/politics</code>,表示 <code>default</code> 命名空间中的 <code>politics</code> 服务帐户。</p></li><li><p>重新定义 <code>handle-cn-access</code> 和 <code>handl-politics</code> 策略规则,使 <em>politics</em> 命名空间中的应用程序免受监控和策略强制。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -f -
|
||
# Rule to handle access to *.cnn.com/politics
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: rule
|
||
metadata:
|
||
name: handle-politics
|
||
namespace: istio-system
|
||
spec:
|
||
match: request.host.endsWith("cnn.com") && context.reporter.uid.startsWith("kubernetes://istio-egressgateway") && request.path.startsWith("/politics") && source.principal != "cluster.local/ns/default/sa/politics"
|
||
actions:
|
||
- handler: egress-error-logger.stdio
|
||
instances:
|
||
- egress-access.logentry
|
||
---
|
||
# Rule handle egress access to cnn.com
|
||
apiVersion: "config.istio.io/v1alpha2"
|
||
kind: rule
|
||
metadata:
|
||
name: handle-cnn-access
|
||
namespace: istio-system
|
||
spec:
|
||
match: request.host.endsWith(".cnn.com") && context.reporter.uid.startsWith("kubernetes://istio-egressgateway") && source.principal != "cluster.local/ns/default/sa/politics"
|
||
actions:
|
||
- handler: egress-access-logger.stdio
|
||
instances:
|
||
- egress-access.logentry
|
||
- handler: path-checker.listchecker
|
||
instances:
|
||
- request-path.listentry
|
||
EOF
|
||
</code></pre></li><li><p>从 <code>SOURCE_POD</code> 中执行常规测试:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/politics; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/sport; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/health'
|
||
403
|
||
200
|
||
200
|
||
</code></pre><p>由于 <code>SOURCE_POD</code> 没有 <code>politics</code> 服务帐户,所以像以前一样访问 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> 会被禁止。</p></li><li><p>从 <code>SOURCE_POD_POLITICS</code> 中执行之前的测试:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec -it $SOURCE_POD_POLITICS -c politics -- sh -c 'curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/politics; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/sport; curl -sL -o /dev/null -w "%{http_code}\n" http://edition.cnn.com/health'
|
||
200
|
||
200
|
||
200
|
||
</code></pre><p>访问 <em>edition.cnn.com</em> 的所有话题都是被允许的。</p></li><li><p>检查 Mixer 日志,查看是否有更多使用 <code>sourcePrincipal</code> 请求,能够匹配 <code>cluster.local/ns/default/sa/politics</code> 的内容出现在日志中。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl -n istio-system logs -l istio-mixer-type=telemetry -c mixer | grep egress-access | grep cnn | tail -4
|
||
</code></pre></li></ol><h2 id=comparison-with-HTTPS-egress-traffic-control>与 HTTPS egress 流量控制进行比较</h2><p>在这个用例中,应用程序使用 HTTP 和 Istio Egress 网关为它们执行 TLS 初始化。或者,应用程序可以通过向 <em>edition.cnn.com</em> 发出 HTTPS 请求来发起 TLS 本身。在本节中,我们将描述这两种方法及其优缺点。</p><p>在 HTTP 方法中,请求在本地主机上不加密地发送,由 Istio sidecar 代理拦截并转发到 egress 网关。由于您将 Istio 配置为在 sidecar 代理和 egress 网关之间使用相互的 TLS,因此流量会使 pod 加密。egress 网关解密流量,检查 URL 路径、 HTTP 方法和报头,报告遥测数据并执行策略检查。如果请求没有被某些策略检查阻止,那么 egress 网关将执行 TLS 发起到外部目的地(在我们的示例中是 <em>cnn.com</em> ),因此请求将再次加密并发送到外部目的地。下图演示了这种方法的流程。网关内的 HTTP 协议根据解密后网关看到的协议来指定协议。</p><figure style=width:80%><div class=wrapper-with-intrinsic-ratio style=padding-bottom:64.81718469808756%><a data-skipendnotes=true href=/v1.5/zh/blog/2018/egress-monitoring-access-control/http-to-gateway.svg title="HTTP egress 流量通过 egress 网关"><img class=element-to-stretch src=/v1.5/zh/blog/2018/egress-monitoring-access-control/http-to-gateway.svg alt="HTTP egress 流量通过 egress 网关"></a></div><figcaption>HTTP egress 流量通过 egress 网关</figcaption></figure><p>这种方法的缺点是请求在 pod 中发送时没有加密,这可能违反某些组织的安全策略。此外,一些 SDK 具有硬编码的外部服务 URL,包括协议,因此不可能发送 HTTP 请求。这种方法的优点是能够检查 HTTP 方法、头和 URL 路径,并基于它们应用策略。</p><p>在 HTTPS 方法中,从应用程序到外部目的地的请求是端到端加密的。下图演示了这种方法的流程。网关中的 HTTPS 协议指定网关所看到的协议。</p><figure style=width:80%><div class=wrapper-with-intrinsic-ratio style=padding-bottom:64.81718469808756%><a data-skipendnotes=true href=/v1.5/zh/blog/2018/egress-monitoring-access-control/https-to-gateway.svg title="HTTPS egress 流量通过 egress 网关"><img class=element-to-stretch src=/v1.5/zh/blog/2018/egress-monitoring-access-control/https-to-gateway.svg alt="HTTPS egress 流量通过 egress 网关"></a></div><figcaption>HTTPS egress 流量通过 egress 网关</figcaption></figure><p>从安全的角度来看,端到端 HTTPS 被认为是一种更好的方法。然而,由于流量是加密的,Istio 代理和出口网关只能看到源和目标 IP 以及目标的 <a href=https://en.wikipedia.org/wiki/Server_Name_Indication>SNI</a>。由于您将 Istio 配置为在 sidecar 代理和 egress 网关之间使用相互的 TLS ,所以<a href=/v1.5/zh/docs/concepts/security/#istio-identity>源标识</a>也是已知的。网关无法检查 URL 路径、HTTP 方法和请求的头,因此无法基于 HTTP 信息进行监控和策略。在我们的用例中,组织将能够允许访问 <em>edition.cnn.com</em> 并指定允许哪些应用程序访问 <em>edition.cnn.com</em> 。但是,将不可能允许或阻止对 <em>edition.cnn.com</em> 的特定 URL 路径的访问。使用 HTTPS 方法既不能阻止对 <a href=https://edition.cnn.com/politics>edition.cnn.com/politics</a> 的访问,也不能监控此类访问。</p><p>我们认为,每个组织都应充分考虑这两种方法的优缺点,并选择最适合其需要的方法。</p><h2 id=summary>总结</h2><p>在这篇博客文章中,我们展示了如何将 Istio 的不同监控和策略机制应用于 HTTP egress 流量。可以通过配置日志适配器来实现监控。访问策略可以通过配置 <code>VirtualServices</code> 或配置各种策略检查适配器来实现。向您演示了一个只允许特定 URL 路径的简单策略。还向您展示了一个更复杂的策略,通过对具有特定服务帐户的应用程序进行豁免,扩展了简单策略。最后,比较了 HTTP-with-TLS-origination egress 流量与 HTTPS egress 流量,以及通过 Istio 进行控制的可能性。</p><h2 id=cleanup>清理</h2><ol><li><p>执行<a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway/>配置 Egress 网关</a>示例的<a href=/v1.5/zh/docs/tasks/traffic-management/egress/egress-gateway/#cleanup>清理</a>部分中的说明。</p></li><li><p>删除日志和策略检查配置:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl delete logentry egress-access -n istio-system
|
||
$ kubectl delete stdio egress-error-logger -n istio-system
|
||
$ kubectl delete stdio egress-access-logger -n istio-system
|
||
$ kubectl delete rule handle-politics -n istio-system
|
||
$ kubectl delete rule handle-cnn-access -n istio-system
|
||
$ kubectl delete -n istio-system listchecker path-checker
|
||
$ kubectl delete -n istio-system listentry request-path
|
||
</code></pre></li><li><p>删除 <em>politics</em> 源 pod:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ sed 's/: sleep/: politics/g' samples/sleep/sleep.yaml | kubectl delete -f -
|
||
serviceaccount "politics" deleted
|
||
service "politics" deleted
|
||
deployment "politics" deleted
|
||
</code></pre></li></ol><nav id=see-also><h2>相关内容</h2><div class=see-also><div class=entry><p class=link><a data-skipendnotes=true href=/v1.5/zh/blog/2019/egress-traffic-control-in-istio-part-3/>Istio 中安全管控出口流量,第三部分</a></p><p class=desc>管控出口流量的备选方案比较,包括性能因素。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.5/zh/blog/2019/egress-traffic-control-in-istio-part-2/>Istio 中的安全管控出口流量,第二部分</a></p><p class=desc>使用 Istio 的出口流量管控来阻止相关出口流量攻击。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.5/zh/blog/2019/egress-traffic-control-in-istio-part-1/>Istio 中的安全管控出口流量,第一部分</a></p><p class=desc>涉及出口流量攻击和出口流量管控要求。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.5/zh/blog/2019/egress-performance/>Egress gateway 性能测试</a></p><p class=desc>评估加入 Egress gateway 对性能造成的影响。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.5/zh/blog/2018/egress-mongo/>使用外部 MongoDB 服务</a></p><p class=desc>描述了一个基于 Istio 的 Bookinfo 示例的简单场景。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.5/zh/blog/2018/egress-tcp/>使用外部 TCP 服务</a></p><p class=desc>描述基于 Istio 的 Bookinfo 示例的简单场景。</p></div></div></nav></article><nav class=pagenav><div class=left><a title="如何通过 Stackdriver 将 Istio 访问日志导出到 BigQuery、GCS、Pub/Sub 等不同的接收器。" href=/v1.5/zh/blog/2018/export-logs-through-stackdriver/><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#left-arrow"/></svg>通过 Stackdriver 将日志导出到 BigQuery、GCS、Pub/Sub</a></div><div class=right><a title="Istio v1alpha3 路由 API 介绍, 动机及其设计原则。" href=/v1.5/zh/blog/2018/v1alpha3-routing/>Istio v1aplha3 路由 API 介绍<svg class="icon"><use xlink:href="/v1.5/img/icons.svg#right-arrow"/></svg></a></div></nav><div id=feedback><div id=feedback-initial>这些信息有用吗?<br><button class="btn feedback" onclick="sendFeedback('zh',1)">是的</button>
|
||
<button class="btn feedback" onclick="sendFeedback('zh',0)">没有</button></div><div id=feedback-comment>Do you have any suggestions for improvement?<br><br><input id=feedback-textbox type=text placeholder="Help us improve..." data-lang=zh></div><div id=feedback-thankyou>Thanks for your feedback!</div></div><div id=endnotes-container aria-hidden=true><h2>链接</h2><ol id=endnotes></ol></div></div><div class=toc-container><nav class=toc aria-label="Table of Contents"><div id=toc><ol><li role=none aria-label=用例><a href=#use-case>用例</a><li role=none aria-label=相关工作和示例><a href=#related-tasks-and-examples>相关工作和示例</a><li role=none aria-label=开始之前><a href=#before-you-begin>开始之前</a><li role=none aria-label=配置监控和访问策略><a href=#configure-monitoring-and-access-policies>配置监控和访问策略</a><ol><li role=none aria-label=日志><a href=#logging>日志</a><li role=none aria-label=路由访问控制><a href=#access-control-by-routing>路由访问控制</a><li role=none aria-label="Mixer 策略检查访问控制"><a href=#access-control-by-Mixer-policy-checks>Mixer 策略检查访问控制</a><li role=none aria-label="Mixer 策略检查访问控制,第二部分"><a href=#access-control-by-Mixer-policy-checks-part-2>Mixer 策略检查访问控制,第二部分</a></ol></li><li role=none aria-label="与 HTTPS egress 流量控制进行比较"><a href=#comparison-with-HTTPS-egress-traffic-control>与 HTTPS egress 流量控制进行比较</a><li role=none aria-label=总结><a href=#summary>总结</a><li role=none aria-label=清理><a href=#cleanup>清理</a><li role=none aria-label=相关内容><a href=#see-also>相关内容</a></li></ol></div></nav></div></main><footer><div class=user-links><a class=channel title="立刻下载 Istio 1.5.4" href=/v1.5/docs/setup/getting-started/#download aria-label="Download Istio"><span>download</span><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#download"/></svg>
|
||
</a><a class=channel title="加入 Istio discussion board 参与讨论获取帮助" href=https://discuss.istio.io aria-label="Istio discussion board"><span>discuss</span><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#discourse"/></svg></a>
|
||
<a class=channel title="Stack Overflow 中列举了针对实际问题以及部署、配置和使用 Istio 的各项回答" href=https://stackoverflow.com/questions/tagged/istio aria-label="Stack Overflow"><span>stack overflow</span><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#stackoverflow"/></svg></a>
|
||
<a class=channel title="在 Slack 上与 Istio 社区交互讨论开发问题(仅限邀请)" href=https://istio.slack.com aria-label=slack><span>slack</span><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#slack"/></svg></a>
|
||
<a class=channel title="关注我们的 Twitter 来获取最新信息" href=https://twitter.com/IstioMesh aria-label=Twitter><span>twitter</span><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#twitter"/></svg></a><div class=tag>对于用户</div></div><div class=info><p class=copyright>中文内容由 ServiceMesher 社区维护,部分文档可能稍微滞后于英文版本,同步工作持续进行中<br>Istio 归档
|
||
1.5.4<br>© 2020 Istio Authors, <a href=https://policies.google.com/privacy>隐私政策</a><br>归档于 2020年5月21日</p></div><div class=dev-links><a class=channel title="Istio 的代码在 GitHub 上开发" href=https://github.com/istio/community aria-label=GitHub><span>github</span><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#github"/></svg></a>
|
||
<a class=channel title="如果您想深入了解 Istio 的技术细节,请查看我们日益完善的设计文档" href=https://groups.google.com/forum/#!forum/istio-team-drive-access aria-label="team drive"><span>drive</span><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#drive"/></svg></a>
|
||
<a class=channel title="如果您想为 Istio 项目做出贡献,请考虑加入我们的工作组" href=https://github.com/istio/community/blob/master/WORKING-GROUPS.md aria-label="working groups"><span>working groups</span><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#working-groups"/></svg></a><div class=tag>对于开发者</div></div></footer><div id=scroll-to-top-container aria-hidden=true><button id=scroll-to-top title=回到顶部><svg class="icon"><use xlink:href="/v1.5/img/icons.svg#top"/></svg></button></div></body></html> |