mirror of https://github.com/istio/istio.io.git
407 lines
103 KiB
HTML
407 lines
103 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="认证策略"><meta name=description content="为您展示如何使用 Istio 认证策略设置双向 TLS 和基础终端用户认证。"><meta name=keywords content="microservices,services,mesh,security,authentication"><meta property="og:title" content="认证策略"><meta property="og:type" content="website"><meta property="og:description" content="为您展示如何使用 Istio 认证策略设置双向 TLS 和基础终端用户认证。"><meta property="og:url" content="/v1.6/zh/docs/tasks/security/authentication/authn-policy/"><meta property="og:image" content="/v1.6/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.6 / 认证策略</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.6/blog/feed.xml><link rel=alternate type=application/rss+xml title="Istio News" href=/v1.6/news/feed.xml><link rel=alternate type=application/rss+xml title="Istio Blog and News" href=/v1.6/feed.xml><link rel="shortcut icon" href=/v1.6/favicons/favicon.ico><link rel=apple-touch-icon href=/v1.6/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=icon type=image/png href=/v1.6/favicons/favicon-16x16.png sizes=16x16><link rel=icon type=image/png href=/v1.6/favicons/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=/v1.6/favicons/android-36x36.png sizes=36x36><link rel=icon type=image/png href=/v1.6/favicons/android-48x48.png sizes=48x48><link rel=icon type=image/png href=/v1.6/favicons/android-72x72.png sizes=72x72><link rel=icon type=image/png href=/v1.6/favicons/android-96x96.png sizes=96xW96><link rel=icon type=image/png href=/v1.6/favicons/android-144x144.png sizes=144x144><link rel=icon type=image/png href=/v1.6/favicons/android-192x192.png sizes=192x192><link rel=manifest href=/v1.6/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.6/css/all.css><script src=/v1.6/js/themes_init.min.js></script></head><body class="language-unknown archive-site"><script>const branchName="release-1.6";const docTitle="认证策略";const iconFile="\/v1.6/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.6/js/all.min.js data-manual defer></script><header><nav><a id=brand href=/v1.6/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.6</span></a><div id=hamburger><svg class="icon"><use xlink:href="/v1.6/img/icons.svg#hamburger"/></svg></div><div id=header-links><a class=current title="了解如何部署、使用和运维 Istio。" href=/v1.6/zh/docs/>文档</a>
|
||
<a title="关于使用 Istio 的博客文章。" href=/v1.6/zh/blog/2020/>博客<i class=dot data-prefix=/blog></i></a>
|
||
<a title="关于 Istio 项目的最新报道。" href=/v1.6/zh/news/>新闻<i class=dot data-prefix=/news></i></a>
|
||
<a title="关于 Istio 的常见问题。" href=/v1.6/zh/faq/>FAQ</a>
|
||
<a title="关于 Istio 项目的说明。" href=/v1.6/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.6/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/docs\/tasks\/security\/authentication\/authn-policy\/');return false;">当前版本</a>
|
||
<a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://preliminary.istio.io/docs\/tasks\/security\/authentication\/authn-policy\/');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.6/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.6/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.6/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=card32 title="一些概念,理解它们有助于您更好地了解 Istio 系统的不同部分及其使用的抽象。" aria-controls=card32-body><svg class="icon"><use xlink:href="/v1.6/img/icons.svg#concepts"/></svg>概念</button><div class=body aria-labelledby=card32 role=region id=card32-body><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=card32><li role=none><a role=treeitem title="介绍 Istio,它要解决的问题,高层面的架构和设计目标。" href=/v1.6/zh/docs/concepts/what-is-istio/>Istio 是什么?</a></li><li role=none><a role=treeitem title="描述 Istio 多样的流量路由和控制特性。" href=/v1.6/zh/docs/concepts/traffic-management/>流量管理</a></li><li role=none><a role=treeitem title="讲述 Istio 的 WebAssembly 插件系统。" href=/v1.6/zh/docs/concepts/wasm/>扩展性</a></li><li role=none><a role=treeitem title="描述 Istio 的授权与认证功能。" href=/v1.6/zh/docs/concepts/security/>安全</a></li><li role=none><a role=treeitem title="描述 Istio 提供的遥测和监控特性。" href=/v1.6/zh/docs/concepts/observability/>可观察性</a></li></ul></div></div><div class=card><button class="header dynamic" id=card48 title="关于如何在 Kubernetes 集群中安装 Istio 控制平面和添加虚拟机到 mesh 中的说明。" aria-controls=card48-body><svg class="icon"><use xlink:href="/v1.6/img/icons.svg#setup"/></svg>安装</button><div class=body aria-labelledby=card48 role=region id=card48-body><ul role=tree aria-expanded=true aria-labelledby=card48><li role=none><a role=treeitem title="下载、安装并学习如何快速使用 Istio 的基本特性。" href=/v1.6/zh/docs/setup/getting-started/>开始</a></li><li role=treeitem aria-label=平台安装><button aria-hidden=true></button><a title="在安装 Istio 之前如何准备各种 Kubernetes 平台。" href=/v1.6/zh/docs/setup/platform-setup/>平台安装</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="对阿里云 Kubernetes 集群进行配置以便安装运行 Istio。" href=/v1.6/zh/docs/setup/platform-setup/alicloud/>阿里云</a></li><li role=none><a role=treeitem title="为 Istio 设置一个 Azure 集群的指令。" href=/v1.6/zh/docs/setup/platform-setup/azure/>Azure</a></li><li role=none><a role=treeitem title="在 Docker Desktop 中运行 Istio 的设置说明。" href=/v1.6/zh/docs/setup/platform-setup/docker/>Docker Desktop</a></li><li role=none><a role=treeitem title="在 Google Kubernetes Engine (GKE) 上快速搭建 Istio 服务。" href=/v1.6/zh/docs/setup/platform-setup/gke/>使用 Google Kubernetes Engine 快速开始</a></li><li role=none><a role=treeitem title="在 IBM 公有云或私有云上快速搭建 Istio 服务。" href=/v1.6/zh/docs/setup/platform-setup/ibm/>IBM Cloud 快速开始</a></li><li role=none><a role=treeitem title="为 Istio 设置 kind 的说明。" href=/v1.6/zh/docs/setup/platform-setup/kind/>kind</a></li><li role=none><a role=treeitem title="使用 Gardener 快速搭建 Istio 服务。" href=/v1.6/zh/docs/setup/platform-setup/gardener/>Kubernetes Gardener 快速开始</a></li><li role=none><a role=treeitem title="配置 MicroK8s 以便使用 Istio。" href=/v1.6/zh/docs/setup/platform-setup/microk8s/>MicroK8s</a></li><li role=none><a role=treeitem title="在 Minikube 上配置 Istio。" href=/v1.6/zh/docs/setup/platform-setup/minikube/>Minikube</a></li><li role=none><a role=treeitem title="对 OpenShift 集群进行配置以便安装运行 Istio。" href=/v1.6/zh/docs/setup/platform-setup/openshift/>OpenShift</a></li><li role=none><a role=treeitem title="为 Istio 配置 OKE 集群环境的说明。" href=/v1.6/zh/docs/setup/platform-setup/oci/>Oracle Cloud Infrastructure</a></li></ul></li><li role=treeitem aria-label=安装><button aria-hidden=true></button><a title=选择最适合您的需求和平台的指南。 href=/v1.6/zh/docs/setup/install/>安装</a><ul role=group aria-expanded=false><li role=none><a role=treeitem title="安装和自定义任何 Istio 配置文件以进行深入评估或用于生产。" href=/v1.6/zh/docs/setup/install/istioctl/>使用 Istioctl 安装</a></li><li role=none><a role=treeitem title="安装和配置 Istio 以进行深入评估或用于生产。" href=/v1.6/zh/docs/setup/install/helm/>使用 Helm 自定义安装</a></li><li role=none><a role=treeitem title="使用 Istio operator 在 Kubernetes 集群中安装 Istio 指南。" href=/v1.6/zh/docs/setup/install/standalone-operator/>安装独立 Operator [实验]</a></li><li role=treeitem aria-label=多集群安装><button aria-hidden=true></button><a title="配置跨越多个 Kubernetes 集群的 Istio 服务网格。" href=/v1.6/zh/docs/setup/install/multicluster/>多集群安装</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="配置一个跨多个 Kubernetes 集群的 Istio 网格。" href=/v1.6/zh/docs/setup/install/multicluster/simplified/>简化地多集群安装[实验性]</a></li><li role=none><a role=treeitem title="通过控制平面副本集实例,在多个 Kubernetes 集群上安装 Istio 网格。" href=/v1.6/zh/docs/setup/install/multicluster/gateways/>控制平面副本集</a></li><li role=none><a role=treeitem title="安装一个跨多个 Kubernetes 集群的 Istio 网格,多集群共享控制平面,并且集群间通过 VPN 互连。" href=/v1.6/zh/docs/setup/install/multicluster/shared-vpn/>共享控制平面(单一网络)</a></li><li role=none><a role=treeitem title="跨多个 Kubernetes 集群安装一个 Istio 网格,使互不联通的集群网络共享同一个控制平面。" href=/v1.6/zh/docs/setup/install/multicluster/shared-gateways/>共享的控制平面(多网络)</a></li></ul></li></ul></li><li role=treeitem aria-label=升级><button aria-hidden=true></button><a title="选择与您先前用于安装 Istio 的方法相对应的升级指南。" href=/v1.6/zh/docs/setup/upgrade/>升级</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="使用 istioctl 命令来升级或降级 Istio。" href=/v1.6/zh/docs/setup/upgrade/istioctl-upgrade/>使用 istioctl 命令升级 Istio [实验中]</a></li><li role=none><a role=treeitem title="升级 Istio 控制平面,可以选择使用 Helm 升级 CNI 插件。" href=/v1.6/zh/docs/setup/upgrade/cni-helm-upgrade/>使用 Helm 升级</a></li></ul></li><li role=treeitem aria-label=更多指南><button aria-hidden=true></button><a title=有关其他设置任务的更多信息。 href=/v1.6/zh/docs/setup/additional-setup/>更多指南</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="描述 Istio 内置的安装配置文件。" href=/v1.6/zh/docs/setup/additional-setup/config-profiles/>安装配置</a></li><li role=none><a role=treeitem title="在应用程序 Pod 中使用 sidecar injector webhook 自动安装或使用 istioctl CLI 手动安装 Istio sidecar。" href=/v1.6/zh/docs/setup/additional-setup/sidecar-injection/>设置 Sidecar</a></li><li role=none><a role=treeitem title="安装并使用 Istio CNI 插件,可以让运维人员用更低的权限来部署服务。" href=/v1.6/zh/docs/setup/additional-setup/cni/>安装 Istio CNI 插件</a></li></ul></li></ul></div></div><div class=card><button class="header dynamic" id=card64 title="如何用 Istio 系统实现特定目标的行为。" aria-controls=card64-body><svg class="icon"><use xlink:href="/v1.6/img/icons.svg#tasks"/></svg>任务</button><div class="body default" aria-labelledby=card64 role=region id=card64-body><ul role=tree aria-expanded=true aria-labelledby=card64><li role=treeitem aria-label=流量管理><button aria-hidden=true></button><a title="演示 Istio 的流量路由功能的任务。" href=/v1.6/zh/docs/tasks/traffic-management/>流量管理</a><ul role=group aria-expanded=false><li role=none><a role=treeitem title=此任务将展示如何将请求动态路由到微服务的多个版本。 href=/v1.6/zh/docs/tasks/traffic-management/request-routing/>配置请求路由</a></li><li role=none><a role=treeitem title=此任务说明如何注入故障并测试应用程序的弹性。 href=/v1.6/zh/docs/tasks/traffic-management/fault-injection/>故障注入</a></li><li role=none><a role=treeitem title=展示如何将流量从旧版本迁移到新版本的服务。 href=/v1.6/zh/docs/tasks/traffic-management/traffic-shifting/>流量转移</a></li><li role=none><a role=treeitem title="展示如何将一个服务的 TCP 流量从旧版本迁移到新版本。" href=/v1.6/zh/docs/tasks/traffic-management/tcp-traffic-shifting/>TCP 流量转移</a></li><li role=none><a role=treeitem title="本任务用于示范如何使用 Istio 在 Envoy 中设置请求超时。" href=/v1.6/zh/docs/tasks/traffic-management/request-timeouts/>设置请求超时</a></li><li role=none><a role=treeitem title=本任务展示如何为连接、请求以及异常检测配置熔断。 href=/v1.6/zh/docs/tasks/traffic-management/circuit-breaking/>熔断</a></li><li role=none><a role=treeitem title="此任务演示了 Istio 的流量镜像/影子功能。" href=/v1.6/zh/docs/tasks/traffic-management/mirroring/>镜像</a></li><li role=treeitem aria-label=Ingress><button aria-hidden=true></button><a title="控制 Istio 服务网格的入口流量。" href=/v1.6/zh/docs/tasks/traffic-management/ingress/>Ingress</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="描述如何配置 Istio gateway,以将服务暴露至服务网格之外。" href=/v1.6/zh/docs/tasks/traffic-management/ingress/ingress-control/>Ingress Gateway</a></li><li role=none><a role=treeitem title="使用文件挂载的证书并通过 TLS 或 mTLS 将服务暴露至服务网格之外。" href=/v1.6/zh/docs/tasks/traffic-management/ingress/secure-ingress-mount/>安全网关(文件挂载)</a></li><li role=none><a role=treeitem title="使用 Secret 发现服务(SDS) 通过 TLS 或者 mTLS 把服务暴露给服务网格外部。" href=/v1.6/zh/docs/tasks/traffic-management/ingress/secure-ingress-sds/>使用 SDS 为 Gateway 提供 HTTPS 加密支持</a></li><li role=none><a role=treeitem title="说明了如何为一个 ingress gateway 配置 SNI 透传。" href=/v1.6/zh/docs/tasks/traffic-management/ingress/ingress-sni-passthrough/>无 TLS 终止的 Ingress Gateway</a></li></ul></li><li role=treeitem aria-label=Egress><button aria-hidden=true></button><a title="控制 Istio 服务网格的出口流量。" href=/v1.6/zh/docs/tasks/traffic-management/egress/>Egress</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="描述如何配置 Istio 以将流量从网格中的服务路由到外部服务。" href=/v1.6/zh/docs/tasks/traffic-management/egress/egress-control/>访问外部服务</a></li><li role=none><a role=treeitem title="描述如何配置 Istio 对来自外部服务的流量执行 TLS 发起。" href=/v1.6/zh/docs/tasks/traffic-management/egress/egress-tls-origination/>Egress TLS Origination</a></li><li role=none><a role=treeitem title="描述如何配置 Istio 通过专用网关服务将流量定向到外部服务。" href=/v1.6/zh/docs/tasks/traffic-management/egress/egress-gateway/>Egress Gateway</a></li><li role=none><a role=treeitem title="描述如何配置一个 Egress 网关,来向外部服务发起 TLS 连接。" href=/v1.6/zh/docs/tasks/traffic-management/egress/egress-gateway-tls-origination/>Egress 网关的 TLS 发起过程</a></li><li role=none><a role=treeitem title="描述如何开启通用域中一组主机的 egress,无需单独配置每一台主机。" href=/v1.6/zh/docs/tasks/traffic-management/egress/wildcard-egress-hosts/>Wildcard 主机的 egress</a></li><li role=none><a role=treeitem title="描述如何在 TLS Egress 上配置 SNI 监控和策略。" href=/v1.6/zh/docs/tasks/traffic-management/egress/egress_sni_monitoring_and_policies/>TLS Egress 监控和策略配置</a></li><li role=none><a role=treeitem title="描述如何配置 Istio 以允许应用程序使用外部 HTTPS 代理。" href=/v1.6/zh/docs/tasks/traffic-management/egress/http-proxy/>使用外部 HTTPS 代理</a></li><li role=none><a role=treeitem title="展示如何配置 Istio Kubernetes 外部服务。" href=/v1.6/zh/docs/tasks/traffic-management/egress/egress-kubernetes-services/>Kubernetes Egress 流量服务</a></li></ul></li></ul></li><li role=treeitem aria-label=安全><button class=show aria-hidden=true></button><a title=演示如何保护网格。 href=/v1.6/zh/docs/tasks/security/>安全</a><ul role=group aria-expanded=true><li role=treeitem aria-label=认证><button class=show aria-hidden=true></button><a title="管控网格服务间的双向 TLS 和终端用户的身份认证。" href=/v1.6/zh/docs/tasks/security/authentication/>认证</a><ul role=group aria-expanded=true class=leaf-section><li role=none><a role=treeitem title="通过一个简化的工作流和最小化配置实现双向 TLS。" href=/v1.6/zh/docs/tasks/security/authentication/auto-mtls/>自动双向 TLS</a></li><li role=none><span role=treeitem class=current title="为您展示如何使用 Istio 认证策略设置双向 TLS 和基础终端用户认证。">认证策略</span></li><li role=none><a role=treeitem title="展示如何在 HTTPS 服务上启用双向 TLS。" href=/v1.6/zh/docs/tasks/security/authentication/https-overlay/>通过 HTTPS 进行 TLS</a></li><li role=none><a role=treeitem title="阐述如何将 Istio 服务逐步迁移至双向 TLS 通信模式。" href=/v1.6/zh/docs/tasks/security/authentication/mtls-migration/>双向 TLS 迁移</a></li></ul></li><li role=treeitem aria-label="Citadel 配置"><button aria-hidden=true></button><a title="定制 Citadel 证书颁发机构。" href=/v1.6/zh/docs/tasks/security/citadel-config/>Citadel 配置</a><ul role=group aria-expanded=false class=leaf-section></ul></li><li role=treeitem aria-label=授权><button aria-hidden=true></button><a title="展示如何控制到 Istio 服务的访问。" href=/v1.6/zh/docs/tasks/security/authorization/>授权</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="展示如何设置基于角色的 HTTP 流量访问控制。" href=/v1.6/zh/docs/tasks/security/authorization/authz-http/>HTTP 流量授权</a></li><li role=none><a role=treeitem title="展示如何设置 TCP 流量的访问控制。" href=/v1.6/zh/docs/tasks/security/authorization/authz-tcp/>TCP 流量的授权</a></li><li role=none><a role=treeitem title="有关如何在 Istio 中通过 JWT 实现访问控制的教程。" href=/v1.6/zh/docs/tasks/security/authorization/authz-jwt/>基于 JWT 授权</a></li><li role=none><a role=treeitem title=阐述如何在不更改授权策略的前提下从一个信任域迁移到另一个。 href=/v1.6/zh/docs/tasks/security/authorization/authz-td-migration/>授权策略信任域迁移</a></li></ul></li><li role=none><a role=treeitem title="演示系统管理员如何使用现有的根证书、签名证书和密钥配置 Istio 的 CA。" href=/v1.6/zh/docs/tasks/security/plugin-ca-cert/>插入外部 CA 证书</a></li><li role=none><a role=treeitem title="展示如何准备和管理 Istio DNS 证书。" href=/v1.6/zh/docs/tasks/security/dns-cert/>Istio DNS 证书管理</a></li></ul></li><li role=treeitem aria-label=策略><button aria-hidden=true></button><a title=演示策略执行功能。 href=/v1.6/zh/docs/tasks/policy-enforcement/>策略</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="这个任务将告诉你如何开启 Istio 的策略检查功能。" href=/v1.6/zh/docs/tasks/policy-enforcement/enabling-policy/>启用策略检查功能</a></li><li role=none><a role=treeitem title="这部分内容将向您展示如何使用 Istio 去动态限制服务间的流量。" href=/v1.6/zh/docs/tasks/policy-enforcement/rate-limiting/>启用速率限制</a></li><li role=none><a role=treeitem title=演示如何使用策略适配器修改请求头和路由。 href=/v1.6/zh/docs/tasks/policy-enforcement/control-headers/>请求头和路由控制</a></li><li role=none><a role=treeitem title="描述如何使用简单的 denials 或黑白名单来控制对服务的访问。" href=/v1.6/zh/docs/tasks/policy-enforcement/denial-and-list/>Denials 和黑白名单</a></li></ul></li><li role=treeitem aria-label=可观察性><button aria-hidden=true></button><a title=演示如何从网格收集遥测信息。 href=/v1.6/zh/docs/tasks/observability/>可观察性</a><ul role=group aria-expanded=false><li role=treeitem aria-label=指标度量><button aria-hidden=true></button><a title="演示 Istio 网格指标度量的配置、收集和处理。" href=/v1.6/zh/docs/tasks/observability/metrics/>指标度量</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="此任务向您展示如何配置 Istio 以采集和自定义指标。" href=/v1.6/zh/docs/tasks/observability/metrics/collecting-metrics/>采集指标</a></li><li role=none><a role=treeitem title="本任务展示了如何配置 Istio 进行 TCP 服务的指标收集。" href=/v1.6/zh/docs/tasks/observability/metrics/tcp-metrics/>收集 TCP 服务指标</a></li><li role=none><a role=treeitem title="本任务介绍如何通过 Prometheus 查询 Istio 度量指标。" href=/v1.6/zh/docs/tasks/observability/metrics/querying-metrics/>通过 Prometheus 查询度量指标</a></li><li role=none><a role=treeitem title="此任务展示了如何设置和使用 Istio Dashboard 监控网格流量。" href=/v1.6/zh/docs/tasks/observability/metrics/using-istio-dashboard/>使用 Grafana 可视化指标</a></li></ul></li><li role=treeitem aria-label=日志><button aria-hidden=true></button><a title="演示 Istio 网格日志的配置、收集和处理。" href=/v1.6/zh/docs/tasks/observability/logs/>日志</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="本任务向您展示如何配置 Istio 来收集和定制日志。" href=/v1.6/zh/docs/tasks/observability/logs/collecting-logs/>收集日志</a></li><li role=none><a role=treeitem title="此任务向您展示如何配置 Envoy 代理将访问日志打印到其标准输出。" href=/v1.6/zh/docs/tasks/observability/logs/access-log/>获取 Envoy 访问日志</a></li><li role=none><a role=treeitem title="此任务向您展示如何配置 Istio 以连接到 Fluentd 守护程序进行日志收集。" href=/v1.6/zh/docs/tasks/observability/logs/fluentd/>使用 Fluentd 进行日志收集</a></li></ul></li><li role=treeitem aria-label=分布式追踪><button aria-hidden=true></button><a title="该任务展示了如何为启用了 Istio 支持的应用进行追踪。" href=/v1.6/zh/docs/tasks/observability/distributed-tracing/>分布式追踪</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="Istio 分布式追踪的概述。" href=/v1.6/zh/docs/tasks/observability/distributed-tracing/overview/>概述</a></li><li role=none><a role=treeitem title="了解如何通过配置代理以将追踪请求发送到 Zipkin。" href=/v1.6/zh/docs/tasks/observability/distributed-tracing/zipkin/>Zipkin</a></li><li role=none><a role=treeitem title="了解如何配置代理以向 Jaeger 发送追踪请求。" href=/v1.6/zh/docs/tasks/observability/distributed-tracing/jaeger/>Jaeger</a></li><li role=none><a role=treeitem title="怎样配置代理才能把追踪请求发送到 LightStep。" href=/v1.6/zh/docs/tasks/observability/distributed-tracing/lightstep/>LightStep</a></li></ul></li><li role=none><a role=treeitem title="此任务向您展示如何在 Istio 网格中可视化服务。" href=/v1.6/zh/docs/tasks/observability/kiali/>网络可视化</a></li><li role=none><a role=treeitem title="此任务向您展示如何配置从外部访问 Istio 遥测插件。" href=/v1.6/zh/docs/tasks/observability/gateways/>远程访问遥测插件</a></li></ul></li></ul></div></div><div class=card><button class="header dynamic" id=card116 title="这里包括多个可供 Istio 使用的可完整工作的示例,你可以用来亲自部署和体验这些示例。" aria-controls=card116-body><svg class="icon"><use xlink:href="/v1.6/img/icons.svg#examples"/></svg>示例</button><div class=body aria-labelledby=card116 role=region id=card116-body><ul role=tree aria-expanded=true aria-labelledby=card116><li role=none><a role=treeitem title="部署一个用于演示多种 Istio 特性的应用,由四个单独的微服务构成。" href=/v1.6/zh/docs/examples/bookinfo/>Bookinfo 应用</a></li><li role=treeitem aria-label=虚拟机><button aria-hidden=true></button><a title="将虚拟机中运行的工作负载添加到 Istio 网格的示例。" href=/v1.6/zh/docs/examples/virtual-machines/>虚拟机</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="学习如何新增一个服务,使其运行在单网络 Istio 网格的虚拟机上。" href=/v1.6/zh/docs/examples/virtual-machines/single-network/>单个网络网格中的虚拟机</a></li><li role=none><a role=treeitem title="学习怎样添加运行在虚拟机上的服务到您的多网络 Istio 网格中。" href=/v1.6/zh/docs/examples/virtual-machines/multi-network/>多网络网格中的虚拟机</a></li><li role=none><a role=treeitem title="使用在网格内的虚拟机上运行的 MySQL 服务运行 Bookinfo 应用程序。" href=/v1.6/zh/docs/examples/virtual-machines/bookinfo/>在虚拟机上部署 Bookinfo 应用程序</a></li></ul></li><li role=treeitem aria-label="使用 Kubernetes 和 Istio 学习微服务"><button aria-hidden=true></button><a title="该模块化教程为新用户提供了一步步将 Istio 应用于常见微服务场景的动手经验。" href=/v1.6/zh/docs/examples/microservices-istio/>使用 Kubernetes 和 Istio 学习微服务</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem href=/v1.6/zh/docs/examples/microservices-istio/prereq/>前提条件</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/examples/microservices-istio/setup-kubernetes-cluster/>设置 Kubernetes 集群</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/examples/microservices-istio/setup-local-computer/>设置本地计算机</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/examples/microservices-istio/single/>本地运行微服务</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/examples/microservices-istio/package-service/>在 Docker 中运行 ratings 服务</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/examples/microservices-istio/bookinfo-kubernetes/>使用 Kubernetes 运行 Bookinfo</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/examples/microservices-istio/production-testing/>生产测试</a></li></ul></li></ul></div></div><div class=card><button class="header dynamic" id=card122 title="关于部署和管理 Istio 网格的概念、工具和技术。" aria-controls=card122-body><svg class="icon"><use xlink:href="/v1.6/img/icons.svg#guide"/></svg>运维</button><div class=body aria-labelledby=card122 role=region id=card122-body><ul role=tree aria-expanded=true aria-labelledby=card122><li role=treeitem aria-label=部署><button aria-hidden=true></button><a title="设置 Istio 部署的要求、概念和注意事项。" href=/v1.6/zh/docs/ops/deployment/>部署</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="描述 Istio 的整体架构与设计目标。" href=/v1.6/zh/docs/ops/deployment/architecture/>架构</a></li><li role=none><a role=treeitem title="描述 Istio 部署中的选择和建议。" href=/v1.6/zh/docs/ops/deployment/deployment-models/>部署模型</a></li><li role=none><a role=treeitem title="介绍 Istio 的性能和可扩展性。" href=/v1.6/zh/docs/ops/deployment/performance-and-scalability/>性能和可扩展性</a></li><li role=none><a role=treeitem title="在启用了 Istio 的集群中运行 Kubernetes 的 Pod 和 Service,您需要做些准备。" href=/v1.6/zh/docs/ops/deployment/requirements/>Pod 和 Service</a></li></ul></li><li role=treeitem aria-label=配置><button aria-hidden=true></button><a title="配置运行中的 Istio 网格的高级概念和功能。" href=/v1.6/zh/docs/ops/configuration/>配置</a><ul role=group aria-expanded=false><li role=treeitem aria-label=网格配置><button aria-hidden=true></button><a title=帮助您管理全局网格配置。 href=/v1.6/zh/docs/ops/configuration/mesh/>网格配置</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="简要描述 Istio 对 Kubernetes webhook 的使用以及可能出现的相关问题。" href=/v1.6/zh/docs/ops/configuration/mesh/webhook/>动态准入 Webhook 概述</a></li><li role=none><a role=treeitem title="介绍 Istio 是如何通过 Kubernetes 的 webhooks 机制来实现 Sidecar 自动注入。" href=/v1.6/zh/docs/ops/configuration/mesh/injection-concepts/>Sidecar 自动注入</a></li><li role=none><a role=treeitem title="描述 Citadel 如何确定是否创建服务账号 secret。" href=/v1.6/zh/docs/ops/configuration/mesh/secret-creation/>创建服务账号 Secret</a></li><li role=none><a role=treeitem title="为您展示如何对 Istio 服务做健康检查。" href=/v1.6/zh/docs/ops/configuration/mesh/app-health-check/>Istio 服务的健康检查</a></li></ul></li><li role=treeitem aria-label=流量管理><button aria-hidden=true></button><a title=帮助您管理正在运行的网格的网络方面。 href=/v1.6/zh/docs/ops/configuration/traffic-management/>流量管理</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title=关于怎么声明协议的信息。 href=/v1.6/zh/docs/ops/configuration/traffic-management/protocol-selection/>协议选择</a></li><li role=none><a role=treeitem title=有关如何启用和理解地域负载平衡。 href=/v1.6/zh/docs/ops/configuration/traffic-management/locality-load-balancing/>地域负载均衡</a></li></ul></li><li role=treeitem aria-label=安全><button aria-hidden=true></button><a title=帮助您管理正在运行的网格的安全性方面。 href=/v1.6/zh/docs/ops/configuration/security/>安全</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="使用加固的容器镜像来减小 Istio 的攻击面。" href=/v1.6/zh/docs/ops/configuration/security/harden-docker-images/>加固 Docker 容器镜像</a></li><li role=none><a role=treeitem title="学习如何延长 Istio 自签名根证书的寿命。" href=/v1.6/zh/docs/ops/configuration/security/root-transition/>延长自签名证书的寿命</a></li></ul></li><li role=treeitem aria-label=可观测性><button aria-hidden=true></button><a title=帮助您管理正在运行的网格中的遥测收集和可视化。 href=/v1.6/zh/docs/ops/configuration/telemetry/>可观测性</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="精细化控制 Envoy 的统计信息。" href=/v1.6/zh/docs/ops/configuration/telemetry/envoy-stats/>Envoy 的统计信息</a></li><li role=none><a role=treeitem title=怎样使用代理生成服务级别的指标。 href=/v1.6/zh/docs/ops/configuration/telemetry/in-proxy-service-telemetry/>不使用 Mixer 生成 Istio 指标 [Alpha]</a></li></ul></li></ul></li><li role=treeitem aria-label=最佳实践><button aria-hidden=true></button><a title="设置和管理 Istio 服务网格的最佳实践。" href=/v1.6/zh/docs/ops/best-practices/>最佳实践</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="设置 Istio 服务网格时的最佳实践。" href=/v1.6/zh/docs/ops/best-practices/deployment/>Deployment 最佳实践</a></li><li role=none><a role=treeitem title=避免网络或流量管理问题的配置最佳实践。 href=/v1.6/zh/docs/ops/best-practices/traffic-management/>流量管理最佳实践</a></li><li role=none><a role=treeitem title="使用 Istio 保护应用的最佳实践。" href=/v1.6/zh/docs/ops/best-practices/security/>安全最佳实践</a></li></ul></li><li role=treeitem aria-label=常见问题><button aria-hidden=true></button><a title="描述如何辨认和解决 Istio 中的常见问题。" href=/v1.6/zh/docs/ops/common-problems/>常见问题</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="定位常见的 Istio 流量管理和网络问题的技术。" href=/v1.6/zh/docs/ops/common-problems/network-issues/>流量管理问题</a></li><li role=none><a role=treeitem title="定位常见 Istio 认证、授权、安全相关问题的技巧。" href=/v1.6/zh/docs/ops/common-problems/security-issues/>安全问题</a></li><li role=none><a role=treeitem title="处理 Telemetry 收集问题。" href=/v1.6/zh/docs/ops/common-problems/observability-issues/>可观测性问题</a></li><li role=none><a role=treeitem title="解决 Istio 使用 Kubernetes Webhooks 进行 sidecar 自动注入的常见问题。" href=/v1.6/zh/docs/ops/common-problems/injection/>Sidecar 自动注入问题</a></li><li role=none><a role=treeitem title=如何解决配置验证的问题。 href=/v1.6/zh/docs/ops/common-problems/validation/>配置验证的问题</a></li></ul></li><li role=treeitem aria-label=诊断工具><button aria-hidden=true></button><a title="帮助解决 Istio 网格问题的工具和技术。" href=/v1.6/zh/docs/ops/diagnostic-tools/>诊断工具</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="Istio 自带的一个可以为服务网格部署提供调试和诊断的补充工具。" href=/v1.6/zh/docs/ops/diagnostic-tools/istioctl/>使用 Istioctl 命令行工具</a></li><li role=none><a role=treeitem title="描述诊断与流量管理相关的 Envoy 配置问题的工具和技术。" href=/v1.6/zh/docs/ops/diagnostic-tools/proxy-cmd/>调试 Envoy 和 Pilot</a></li><li role=none><a role=treeitem title="向您展示如何使用 istioctl describe 来验证您的网格中的 pod 的配置。" href=/v1.6/zh/docs/ops/diagnostic-tools/istioctl-describe/>通过 Istioctl Describe 理解您的网格</a></li><li role=none><a role=treeitem title="演示如何使用 istioctl analyze 来识别配置中的潜在问题。" href=/v1.6/zh/docs/ops/diagnostic-tools/istioctl-analyze/>使用 Istioctl Analyze 诊断配置</a></li><li role=none><a role=treeitem title="介绍如何使用 ControlZ 深入了解各个运行组件。" href=/v1.6/zh/docs/ops/diagnostic-tools/controlz/>组件自检</a></li><li role=none><a role=treeitem title=如何使用组件的级别日志来记录正在运行中的组件的行为。 href=/v1.6/zh/docs/ops/diagnostic-tools/component-logging/>组件日志记录</a></li></ul></li><li role=treeitem aria-label=集成><button aria-hidden=true></button><a title="能够与 Istio 集成以提供额外功能的其他软件。" href=/v1.6/zh/docs/ops/integrations/>集成</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="关于如何与 cert-manager 集成的相关说明。" href=/v1.6/zh/docs/ops/integrations/certmanager/>cert-manager</a></li></ul></li></ul></div></div><div class=card><button class="header dynamic" id=card155 title="参考部分包含详细的权威参考资料,如命令行选项、配置选项和 API 调用参数。" aria-controls=card155-body><svg class="icon"><use xlink:href="/v1.6/img/icons.svg#reference"/></svg>参考</button><div class=body aria-labelledby=card155 role=region id=card155-body><ul role=tree aria-expanded=true aria-labelledby=card155><li role=treeitem aria-label=配置><button aria-hidden=true></button><a title=关于配置选项的详细信息。 href=/v1.6/zh/docs/reference/config/>配置</a><ul role=group aria-expanded=false><li role=none><a role=treeitem title="Configuration affecting the service mesh as a whole." href=/v1.6/zh/docs/reference/config/istio.mesh.v1alpha1/>Service Mesh</a></li><li role=none><a role=treeitem title="Configuration for Istio control plane installation through the Operator." href=/v1.6/zh/docs/reference/config/istio.operator.v1alpha12.pb/>Operator Installation</a></li><li role=none><a role=treeitem title="描述使用 Helm chart 安装 Istio 时的可选项。" href=/v1.6/zh/docs/reference/config/installation-options/>安装选项(Helm)</a></li><li role=none><a role=treeitem title="Configuration affecting Istio control plane installation version and shape." href=/v1.6/zh/docs/reference/config/istio.operator.v1alpha1/>IstioOperator Options</a></li><li role=none><a role=treeitem title="Resource annotations used by Istio." href=/v1.6/zh/docs/reference/config/annotations/>Resource Annotations</a></li><li role=treeitem aria-label=流量管理><button aria-hidden=true></button><a title="描述如何配置 HTTP/TCP 路由功能。" href=/v1.6/zh/docs/reference/config/networking/>流量管理</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="Configuration affecting load balancing, outlier detection, etc." href=/v1.6/zh/docs/reference/config/networking/destination-rule/>Destination Rule</a></li><li role=none><a role=treeitem title="Customizing Envoy configuration generated by Istio." href=/v1.6/zh/docs/reference/config/networking/envoy-filter/>Envoy Filter</a></li><li role=none><a role=treeitem title="Configuration affecting edge load balancer." href=/v1.6/zh/docs/reference/config/networking/gateway/>Gateway</a></li><li role=none><a role=treeitem title="Configuration affecting label/content routing, sni routing, etc." href=/v1.6/zh/docs/reference/config/networking/virtual-service/>Virtual Service</a></li><li role=none><a role=treeitem title="Configuration affecting network reachability of a sidecar." href=/v1.6/zh/docs/reference/config/networking/sidecar/>Sidecar</a></li><li role=none><a role=treeitem title="Configuration affecting service registry." href=/v1.6/zh/docs/reference/config/networking/service-entry/>Service Entry</a></li></ul></li><li role=treeitem aria-label=Security><button aria-hidden=true></button><a title="如何配置 Istio 的安全功能。" href=/v1.6/zh/docs/reference/config/security/>Security</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="Configuration to validate JWT." href=/v1.6/zh/docs/reference/config/security/jwt/>JWTRule</a></li><li role=none><a role=treeitem title="Request authentication configuration for workloads." href=/v1.6/zh/docs/reference/config/security/request_authentication/>RequestAuthentication</a></li><li role=none><a role=treeitem title="Peer authentication configuration for workloads." href=/v1.6/zh/docs/reference/config/security/peer_authentication/>PeerAuthentication</a></li><li role=none><a role=treeitem title="Authentication policy for Istio services." href=/v1.6/zh/docs/reference/config/security/istio.authentication.v1alpha1/>Authentication Policy</a></li><li role=none><a role=treeitem title="Configuration for access control on workloads." href=/v1.6/zh/docs/reference/config/security/authorization-policy/>Authorization Policy</a></li><li role=none><a role=treeitem title=授权策略中支持的条件。 href=/v1.6/zh/docs/reference/config/security/conditions/>授权策略</a></li><li role=none><a role=treeitem title="Configuration for Role Based Access Control." href=/v1.6/zh/docs/reference/config/security/istio.rbac.v1alpha1/>RBAC (deprecated)</a></li><li role=none><a role=treeitem title=受支持的约束条件和属性。 href=/v1.6/zh/docs/reference/config/security/constraints-and-properties/>RBAC 约束和属性(不建议使用)</a></li></ul></li><li role=treeitem aria-label="Telemetry V2"><button aria-hidden=true></button><a title="介绍如何配置 Istio telemetry V2。" href=/v1.6/zh/docs/reference/config/telemetry/>Telemetry V2</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="通过 Istio 遥测导出的 Istio 标准指标。" href=/v1.6/zh/docs/reference/config/telemetry/metrics/>Istio 标准度量指标</a></li><li role=none><a role=treeitem title="如何通过 Wasm 运行时启用 Telemetry V2(实验性)。" href=/v1.6/zh/docs/reference/config/telemetry/telemetry_v2_with_wasm/>使用 Wasm 运行时的 Telemetry V2(实验性)</a></li><li role=none><a role=treeitem title="如何配置 v2 指标(实验性)。" href=/v1.6/zh/docs/reference/config/telemetry/configurable_metrics/>可配置指标(实验性)</a></li></ul></li><li role=treeitem aria-label=配置分析消息><button aria-hidden=true></button><a title=记录配置分析期间产生的各个错误和警告消息。 href=/v1.6/zh/docs/reference/config/analysis/>配置分析消息</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/message-format/>Analyzer Message Format</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0109/>ConflictingMeshGatewayVirtualServiceHosts</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0110/>ConflictingSidecarWorkloadSelectors</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0002/>Deprecated</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0104/>GatewayPortNotOnWorkload</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0001/>InternalError</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0105/>IstioProxyImageMismatch</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0119/>JwtFailureDueToInvalidServicePortPrefix</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0107/>MisplacedAnnotation</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0113/>MTLSPolicyConflict</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0111/>MultipleSidecarsWithoutWorkloadSelectors</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0102/>NamespaceNotInjected</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0112/>VirtualServiceDestinationPortSelectorRequired</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0108/>UnknownAnnotation</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0106/>SchemaValidationError</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0101/>ReferencedResourceNotFound</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0118/>PortNameIsNotUnderNamingConvention</a></li><li role=none><a role=treeitem href=/v1.6/zh/docs/reference/config/analysis/ist0103/>PodMissingProxy</a></li></ul></li><li role=treeitem aria-label="Mixer 策略和遥测"><button aria-hidden=true></button><a title="描述如何配置 Mixer 的策略和遥测功能。" href=/v1.6/zh/docs/reference/config/policy-and-telemetry/>Mixer 策略和遥测</a><ul role=group aria-expanded=false><li role=none><a role=treeitem title="Configuration state for the Mixer client library." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/istio.mixer.v1.config.client/>Mixer Client</a></li><li role=none><a role=treeitem title="Describes the rules used to configure Mixer's policy and telemetry features." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/istio.policy.v1beta1/>Rules</a></li><li role=none><a role=treeitem title="描述 Istio 策略执行和遥测机制的配置模型。" href=/v1.6/zh/docs/reference/config/policy-and-telemetry/mixer-overview/>Mixer 配置模型</a></li><li role=none><a role=treeitem title=描述用于策略和控制的基本属性词汇表。 href=/v1.6/zh/docs/reference/config/policy-and-telemetry/attribute-vocabulary/>属性词汇</a></li><li role=none><a role=treeitem title="Mixer 配置表达式语言手册。" href=/v1.6/zh/docs/reference/config/policy-and-telemetry/expression-language/>表达式语言</a></li><li role=treeitem aria-label=适配器><button aria-hidden=true></button><a title="Mixer 适配器能够让 Istio 连接各种基础设施后端以完成类似指标和日志这样的功能。" href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/>适配器</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="Adapter to deliver metrics to Apache SkyWalking." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/apache-skywalking/>Apache SkyWalking</a></li><li role=none><a role=treeitem title="Adapter for Apigee's distributed policy checks and analytics." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/apigee/>Apigee</a></li><li role=none><a role=treeitem title="Adapter to enforce authentication and authorization policies for web apps and APIs." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/app-identity-access-adapter/>App Identity and Access</a></li><li role=none><a role=treeitem title="Adapter for circonus.com's monitoring solution." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/circonus/>Circonus</a></li><li role=none><a role=treeitem title="Adapter for cloudmonitor metrics." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/cloudmonitor/>CloudMonitor</a></li><li role=none><a role=treeitem title="Adapter for cloudwatch metrics." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/cloudwatch/>CloudWatch</a></li><li role=none><a role=treeitem title="Adapter to deliver metrics to a dogstatsd agent for delivery to DataDog." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/datadog/>Datadog</a></li><li role=none><a role=treeitem title="Adapter to deliver tracing data to Zipkin." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/zipkin/>Zipkin</a></li><li role=none><a role=treeitem title="Adapter that always returns a precondition denial." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/denier/>Denier</a></li><li role=none><a role=treeitem title="Adapter that delivers logs to a Fluentd daemon." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/fluentd/>Fluentd</a></li><li role=none><a role=treeitem title="Adapter that extracts information from a Kubernetes environment." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/kubernetesenv/>Kubernetes Env</a></li><li role=none><a role=treeitem title="Adapter that performs whitelist or blacklist checks." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/list/>List</a></li><li role=none><a role=treeitem title="Adapter for a simple in-memory quota management system." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/memquota/>Memory quota</a></li><li role=none><a role=treeitem title="An Istio Mixer adapter to send telemetry data to New Relic." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/newrelic/>New Relic</a></li><li role=none><a role=treeitem title="Adapter to deliver metrics to Wavefront by VMware." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/wavefront/>Wavefront by VMware</a></li><li role=none><a role=treeitem title="Adapter to locally output logs and metrics." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/stdio/>Stdio</a></li><li role=none><a role=treeitem title="Adapter to deliver metrics to a StatsD backend." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/statsd/>StatsD</a></li><li role=none><a role=treeitem title="Adapter to deliver logs, metrics, and traces to Stackdriver." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/stackdriver/>Stackdriver</a></li><li role=none><a role=treeitem title="Adapter to deliver logs and metrics to Papertrail and AppOptics backends." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/solarwinds/>SolarWinds</a></li><li role=none><a role=treeitem title="Adapter for a Redis-based quota management system." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/redisquota/>Redis Quota</a></li><li role=none><a role=treeitem title="Adapter that exposes Istio metrics for ingestion by a Prometheus harvester." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/prometheus/>Prometheus</a></li><li role=none><a role=treeitem title="Adapter that implements an Open Policy Agent engine." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/adapters/opa/>OPA</a></li></ul></li><li role=treeitem aria-label=模板><button aria-hidden=true></button><a title="Mixer 模板用于将数据发送到各个适配器。" href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/>模板</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="The Analytics template is used to dispatch runtime telemetry to Apigee." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/analytics/>Analytics</a></li><li role=none><a role=treeitem title="A template that represents a single API key." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/apikey/>API Key</a></li><li role=none><a role=treeitem title="A template used to represent an access control query." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/authorization/>Authorization</a></li><li role=none><a role=treeitem title="A template that carries no data, useful for testing." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/checknothing/>Check Nothing</a></li><li role=none><a role=treeitem title="A template designed to report observed communication edges between workloads." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/edge/>Edge</a></li><li role=none><a role=treeitem title="A template that is used to control the production of Kubernetes-specific attributes." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/kubernetes/>Kubernetes</a></li><li role=none><a role=treeitem title="A template designed to let you perform list checking operations." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/listentry/>List Entry</a></li><li role=none><a role=treeitem title="A template that represents a single runtime log entry." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/logentry/>Log Entry</a></li><li role=none><a role=treeitem title="A template that represents a single runtime metric." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/metric/>Metric</a></li><li role=none><a role=treeitem title="A template that represents an individual span within a distributed trace." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/tracespan/>Trace Span</a></li><li role=none><a role=treeitem title="A template that carries no data, useful for testing." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/reportnothing/>Report Nothing</a></li><li role=none><a role=treeitem title="A template that represents a quota allocation request." href=/v1.6/zh/docs/reference/config/policy-and-telemetry/templates/quota/>Quota</a></li></ul></li><li role=none><a role=treeitem title="通过 Mixer 从 Istio 导出的默认监控指标。" href=/v1.6/zh/docs/reference/config/policy-and-telemetry/metrics/>默认监控指标</a></li></ul></li></ul></li><li role=treeitem aria-label=命令><button aria-hidden=true></button><a title="描述 Istio 命令和工具的用法及选项。" href=/v1.6/zh/docs/reference/commands/>命令</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="Galley provides configuration management services for Istio." href=/v1.6/zh/docs/reference/commands/galley/>galley</a></li><li role=none><a role=treeitem title="Istio Certificate Authority (CA)." href=/v1.6/zh/docs/reference/commands/istio_ca/>istio_ca</a></li><li role=none><a role=treeitem title="Istio control interface." href=/v1.6/zh/docs/reference/commands/istioctl/>istioctl</a></li><li role=none><a role=treeitem title="Mixer is Istio's abstraction on top of infrastructure backends." href=/v1.6/zh/docs/reference/commands/mixs/>mixs</a></li><li role=none><a role=treeitem title="Kubernetes webhook for automatic Istio sidecar injection." href=/v1.6/zh/docs/reference/commands/sidecar-injector/>sidecar-injector</a></li><li role=none><a role=treeitem title="Istio Pilot." href=/v1.6/zh/docs/reference/commands/pilot-discovery/>pilot-discovery</a></li><li role=none><a role=treeitem title="Istio Pilot agent." href=/v1.6/zh/docs/reference/commands/pilot-agent/>pilot-agent</a></li><li role=none><a role=treeitem title="The Istio operator." href=/v1.6/zh/docs/reference/commands/operator/>operator</a></li><li role=none><a role=treeitem title="Istio security per-node agent." href=/v1.6/zh/docs/reference/commands/node_agent/>node_agent</a></li></ul></li><li role=none><a role=treeitem title="Istio 常用术语的词汇表。" href=/v1.6/zh/docs/reference/glossary/>术语表</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.6/img/icons.svg#pull"/></svg></button><nav aria-label=Breadcrumb><ol><li><a href=/v1.6/zh/ title=用于连接、保护、控制和观测服务。>Istio</a></li><li><a href=/v1.6/zh/docs/ title="了解如何部署、使用和运维 Istio。">文档</a></li><li><a href=/v1.6/zh/docs/tasks/ title="如何用 Istio 系统实现特定目标的行为。">任务</a></li><li><a href=/v1.6/zh/docs/tasks/security/ title=演示如何保护网格。>安全</a></li><li><a href=/v1.6/zh/docs/tasks/security/authentication/ title="管控网格服务间的双向 TLS 和终端用户的身份认证。">认证</a></li><li>认证策略</li></ol></nav><article aria-labelledby=title><div class=title-area><div style=width:100%><h1 id=title>认证策略</h1><p class=byline><span title="2227 字"><svg class="icon"><use xlink:href="/v1.6/img/icons.svg#clock"/></svg><span> </span>阅读大约需要 11 分钟</span></p></div></div><nav class=toc-inlined aria-label="Table of Contents"><div><hr><ol><li role=none aria-label=开始之前><a href=#before-you-begin>开始之前</a><ol><li role=none aria-label=设置><a href=#setup>设置</a></ol></li><li role=none aria-label="自动双向 TLS"><a href=#auto-mutual-TLS>自动双向 TLS</a><li role=none aria-label="全局启用 Istio 双向 TLS"><a href=#globally-enabling-Istio-mutual-TLS>全局启用 Istio 双向 TLS</a><ol><li role=none aria-label="从非 Istio 服务到 Istio 服务的请求"><a href=#request-from-non-Istio-services-to-Istio-services>从非 Istio 服务到 Istio 服务的请求</a><li role=none aria-label="从 Istio 服务到非 Istio 服务的请求"><a href=#request-from-Istio-services-to-non-Istio-services>从 Istio 服务到非 Istio 服务的请求</a><li role=none aria-label="请求从 Istio 服务到 Kubernetes API server"><a href=#request-from-Istio-services-to-Kubernetes-API-server>请求从 Istio 服务到 Kubernetes API server</a><li role=none aria-label="清除部分 1"><a href=#cleanup-part-1>清除部分 1</a></ol></li><li role=none aria-label="为每个命名空间或者服务启用双向 TLS"><a href=#enable-mutual-TLS-per-namespace-or-service>为每个命名空间或者服务启用双向 TLS</a><ol><li role=none aria-label=命名空间范围的策略><a href=#namespace-wide-policy>命名空间范围的策略</a><li role=none aria-label=特定服务策略><a href=#service-specific-policy>特定服务策略</a><li role=none aria-label=策略优先级><a href=#policy-precedence>策略优先级</a><li role=none aria-label="清除部分 2"><a href=#cleanup-part-2>清除部分 2</a></ol></li><li role=none aria-label=终端用户认证><a href=#end-user-authentication>终端用户认证</a><ol><li role=none aria-label=按路径要求的终端用户认证><a href=#end-user-authentication-with-per-path-requirements>按路径要求的终端用户认证</a><ol><li role=none aria-label=为指定路径禁用终端用户认证><a href=#disable-end-user-authentication-for-specific-paths>为指定路径禁用终端用户认证</a><li role=none aria-label=为指定路径启用终端用户认证><a href=#enable-end-user-authentication-for-specific-paths>为指定路径启用终端用户认证</a></ol></li><li role=none aria-label="带双向 TLS 的终端用户认证"><a href=#end-user-authentication-with-mutual-TLS>带双向 TLS 的终端用户认证</a><li role=none aria-label="清除部分 3"><a href=#cleanup-part-3>清除部分 3</a></ol></li><li role=none aria-label=相关内容><a href=#see-also>相关内容</a></li></ol><hr></div></nav><p>本任务涵盖了您在启用、配置和使用 Istio 认证策略时可能需要做的主要工作。更多基本概念介绍请查看<a href=/v1.6/zh/docs/concepts/security/#authentication>认证总览</a>。</p><h2 id=before-you-begin>开始之前</h2><ul><li>理解 Istio <a href=/v1.6/zh/docs/concepts/security/#authentication-policies>认证策略</a>和<a href=/v1.6/zh/docs/concepts/security/#mutual-TLS-authentication>双向 TLS 认证</a>相关概念。</li><li>在 Kubernetes 集群中安装 Istio 并禁用全局双向 TLS (例如,使用<a href=/v1.6/zh/docs/setup/getting-started>安装步骤</a>提到的 demo 配置文件,或者设置 <code>global.mtls.enabled</code> 安装选项为 false )。</li></ul><h3 id=setup>设置</h3><p>我们的示例用到两个命名空间 <code>foo</code> 和 <code>bar</code>,以及两个服务 <code>httpbin</code> 和 <code>sleep</code>,这两个服务都带有 Envoy sidecar proxy 一起运行。我们也会用到两个运行在 <code>legacy</code> 命名空间下不带 sidecar 的 <code>httpbin</code> 和 <code>sleep</code> 实例。如果您想要使用相同的示例尝试任务,执行如下命令:</p><div><a data-skipendnotes=true style=display:none href=https://raw.githubusercontent.com/istio/istio/release-1.6/samples/sleep/sleep.yaml>Zip</a><a data-skipendnotes=true style=display:none href=https://raw.githubusercontent.com/istio/istio/release-1.6/samples/httpbin/httpbin.yaml>Zip</a><a data-skipendnotes=true style=display:none href=https://raw.githubusercontent.com/istio/istio/release-1.6/samples/sleep/sleep.yaml>Zip</a><a data-skipendnotes=true style=display:none href=https://raw.githubusercontent.com/istio/istio/release-1.6/samples/httpbin/httpbin.yaml>Zip</a><a data-skipendnotes=true style=display:none href=https://raw.githubusercontent.com/istio/istio/release-1.6/samples/sleep/sleep.yaml>Zip</a><a data-skipendnotes=true style=display:none href=https://raw.githubusercontent.com/istio/istio/release-1.6/samples/httpbin/httpbin.yaml>Zip</a><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl create ns foo
|
||
$ kubectl apply -f <(istioctl kube-inject -f @samples/httpbin/httpbin.yaml@) -n foo
|
||
$ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@) -n foo
|
||
$ kubectl create ns bar
|
||
$ kubectl apply -f <(istioctl kube-inject -f @samples/httpbin/httpbin.yaml@) -n bar
|
||
$ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@) -n bar
|
||
$ kubectl create ns legacy
|
||
$ kubectl apply -f @samples/httpbin/httpbin.yaml@ -n legacy
|
||
$ kubectl apply -f @samples/sleep/sleep.yaml@ -n legacy
|
||
</code></pre></div><p>您可以在命名空间 <code>foo</code>、<code>bar</code> 或 <code>legacy</code> 下的任意 <code>sleep</code> pod 中使用 <code>curl</code> 发送一个 HTTP 请求给 <code>httpbin.foo</code>、<code>httpbin.bar</code> 或 <code>httpbin.legacy</code> 来验证。所有请求应该都成功返回 HTTP 代码 200。</p><p>例如,这里的一个从 <code>sleep.bar</code> 到 <code>httpbin.foo</code> 的检查可达性的命令:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec $(kubectl get pod -l app=sleep -n bar -o jsonpath={.items..metadata.name}) -c sleep -n bar -- curl http://httpbin.foo:8000/ip -s -o /dev/null -w "%{http_code}\n"
|
||
200
|
||
</code></pre><p>这个单行命令可以方便地遍历所有可达性组合:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ for from in "foo" "bar" "legacy"; do for to in "foo" "bar" "legacy"; do kubectl exec $(kubectl get pod -l app=sleep -n ${from} -o jsonpath={.items..metadata.name}) -c sleep -n ${from} -- curl "http://httpbin.${to}:8000/ip" -s -o /dev/null -w "sleep.${from} to httpbin.${to}: %{http_code}\n"; done; done
|
||
sleep.foo to httpbin.foo: 200
|
||
sleep.foo to httpbin.bar: 200
|
||
sleep.foo to httpbin.legacy: 200
|
||
sleep.bar to httpbin.foo: 200
|
||
sleep.bar to httpbin.bar: 200
|
||
sleep.bar to httpbin.legacy: 200
|
||
sleep.legacy to httpbin.foo: 200
|
||
sleep.legacy to httpbin.bar: 200
|
||
sleep.legacy to httpbin.legacy: 200
|
||
</code></pre><p>您还应该要验证系统中是否有默认的网格认证策略,可执行如下命令:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl get policies.authentication.istio.io --all-namespaces
|
||
No resources found.
|
||
</code></pre><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl get meshpolicies.authentication.istio.io
|
||
NAME AGE
|
||
default 3m
|
||
</code></pre><p>最后同样重要的是,验证示例服务没有应用 destination rule。您可以检查现有 destination rule 中的 <code>host:</code> 值并确保它们不匹配。例如:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl get destinationrules.networking.istio.io --all-namespaces -o yaml | grep "host:"
|
||
host: istio-policy.istio-system.svc.cluster.local
|
||
host: istio-telemetry.istio-system.svc.cluster.local
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content>您可能会看到 destination rules 配置了除上面显示以外的其他 hosts,这依赖于 Istio 的版本。但是,应该没有 destination rules 配置 <code>foo</code>、<code>bar</code> 和 <code>legacy</code> 命名空间中的 hosts,也没有配置通配符 <code>*</code></div></aside></div><h2 id=auto-mutual-TLS>自动双向 TLS</h2><p>默认情况下,Istio 跟踪迁移到 Istio 代理的服务器工作负载,并配置客户端代理以自动将双向 TLS 流量发送到这些工作负载,并将纯文本流量发送到没有 sidecar 的工作负载。</p><p>因此,具有代理的工作负载之间的所有流量都使用双向 TLS,而无需执行任何操作。例如,检查 <code>httpbin/header</code> 请求的响应。
|
||
使用双向 TLS 时,代理会将 <code>X-Forwarded-Client-Cert</code> 标头注入到后端的上游请求。存在该标头说明流量使用双向 TLS。例如:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec $(kubectl get pod -l app=sleep -n foo -o jsonpath={.items..metadata.name}) -c sleep -n foo -- curl http://httpbin.foo:8000/headers -s | grep X-Forwarded-Client-Cert
|
||
"X-Forwarded-Client-Cert": "By=spiffe://cluster.local/ns/foo/sa/httpbin;Hash=<redacted>"
|
||
</code></pre><p>当服务器没有 sidecar 时, <code>X-Forwarded-Client-Cert</code> 标头将不会存在,这意味着请求是纯文本的。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec $(kubectl get pod -l app=sleep -n foo -o jsonpath={.items..metadata.name}) -c sleep -n foo -- curl http://httpbin.legacy:8000/headers -s | grep X-Forwarded-Client-Cert
|
||
</code></pre><h2 id=globally-enabling-Istio-mutual-TLS>全局启用 Istio 双向 TLS</h2><p>设置一个启用双向 TLS 的网格范围的认证策略,提交如下 <em>mesh authentication policy</em> :</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl apply -f - <<EOF
|
||
apiVersion: "authentication.istio.io/v1alpha1"
|
||
kind: "MeshPolicy"
|
||
metadata:
|
||
name: "default"
|
||
spec:
|
||
peers:
|
||
- mtls: {}
|
||
EOF
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content>网格认证策略使用<a href=/v1.6/zh/docs/reference/config/security/istio.authentication.v1alpha1/>通用认证策略 API</a>,它定义在集群作用域 <code>MeshPolicy</code> CRD 中。</div></aside></div><p>该策略规定网格上的所有工作负载只接收使用 TLS 的加密请求。如您所见,该认证策略的类型为:<code>MeshPolicy</code>。策略的名字必须是 <code>default</code>,并且不含 <code>targets</code> 属性(目的是应用到网格中所有服务上)。</p><p>这时候,只有接收方配置使用双向 TLS。如果您在 <em>Istio services</em> 之间执行 <code>curl</code> 命令(即,那些带有 sidecars 的服务),由于客户端仍旧使用纯文本,所有请求都会失败并报 503 错误。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ for from in "foo" "bar"; do for to in "foo" "bar"; do kubectl exec $(kubectl get pod -l app=sleep -n ${from} -o jsonpath={.items..metadata.name}) -c sleep -n ${from} -- curl "http://httpbin.${to}:8000/ip" -s -o /dev/null -w "sleep.${from} to httpbin.${to}: %{http_code}\n"; done; done
|
||
sleep.foo to httpbin.foo: 503
|
||
sleep.foo to httpbin.bar: 503
|
||
sleep.bar to httpbin.foo: 503
|
||
sleep.bar to httpbin.bar: 503
|
||
</code></pre><p>配置客户端,您需要设置 <a href=/v1.6/zh/docs/concepts/traffic-management/#destination-rules>destination rules</a> 来使用双向 TLS。也可以使用多 destination rules,为每个合适的服务(或命名空间)都配置一个。不过,更方便地方式是创建一个规则使用通配符 <code>*</code> 匹配所有服务,因此这也和网格范围的认证策略作用等同。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl apply -f - <<EOF
|
||
apiVersion: "networking.istio.io/v1alpha3"
|
||
kind: "DestinationRule"
|
||
metadata:
|
||
name: "default"
|
||
namespace: "istio-system"
|
||
spec:
|
||
host: "*.local"
|
||
trafficPolicy:
|
||
tls:
|
||
mode: ISTIO_MUTUAL
|
||
EOF
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content><ul><li>从 Istio 1.1 开始,只有客户端命名空间,服务端命名空间和 <code>global</code> 命名空间(默认是 <code>istio-system</code>)中的 destination rules 会按顺序提供给服务。</li><li>Host 值 <code>*.local</code> 限制只与集群中的服务匹配,而不是外部服务。同时注意,destination rule 的名字或命名空间没有做限制。</li><li>在 <code>ISTIO_MUTUAL</code> TLS 模式下,Istio 将根据密钥和证书(例如客户端证书,密钥和 CA 证书)的内部实现为它们设置路径。</li></ul></div></aside></div><p>别忘了 destination rules 也可用于非授权原因例如设置金丝雀发布,不过要适用同样的优先顺序。因此,如果一个服务不管什么原因要求一个特定的 destination rule —— 例如,配置负载均衡 —— 这个规则必须包含一个简单的 <code>ISTIO_MUTUAL</code> 模式的 TLS 块,否则它将会被网格或者命名空间范围的 TLS 设置覆盖并使 TLS 失效。</p><p>重新执行上述测试命令,您将看到所有 Istio 服务间的请求现在都成功完成。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ for from in "foo" "bar"; do for to in "foo" "bar"; do kubectl exec $(kubectl get pod -l app=sleep -n ${from} -o jsonpath={.items..metadata.name}) -c sleep -n ${from} -- curl "http://httpbin.${to}:8000/ip" -s -o /dev/null -w "sleep.${from} to httpbin.${to}: %{http_code}\n"; done; done
|
||
sleep.foo to httpbin.foo: 200
|
||
sleep.foo to httpbin.bar: 200
|
||
sleep.bar to httpbin.foo: 200
|
||
sleep.bar to httpbin.bar: 200
|
||
</code></pre><h3 id=request-from-non-Istio-services-to-Istio-services>从非 Istio 服务到 Istio 服务的请求</h3><p>非 Istio 服务,例如 <code>sleep.legacy</code> 没有 sidecar,所以它不能将要求的 TLS 连接初始化到 Istio 服务。这会导致从 <code>sleep.legacy</code> 到 <code>httpbin.foo</code> 或者 <code>httpbin.bar</code> 的请求失败:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ for from in "legacy"; do for to in "foo" "bar"; do kubectl exec $(kubectl get pod -l app=sleep -n ${from} -o jsonpath={.items..metadata.name}) -c sleep -n ${from} -- curl "http://httpbin.${to}:8000/ip" -s -o /dev/null -w "sleep.${from} to httpbin.${to}: %{http_code}\n"; done; done
|
||
sleep.legacy to httpbin.foo: 000
|
||
command terminated with exit code 56
|
||
sleep.legacy to httpbin.bar: 000
|
||
command terminated with exit code 56
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content>由于 Envoy 拒绝纯文本请求的方式,您将会在这个例子中看到 <code>curl</code> 返回 56 代码(接收网络数据失败)。</div></aside></div><p>这个按预期工作,而且很不幸,没有解决办法,除非降低对这些服务的认证条件要求。</p><h3 id=request-from-Istio-services-to-non-Istio-services>从 Istio 服务到非 Istio 服务的请求</h3><p>尝试从 <code>sleep.foo</code> (或者 <code>sleep.bar</code>) 发送请求给 <code>httpbin.legacy</code>。您将看到请求失败,因为 Istio 按照指示在 destination rule 中配置了客户端使用双向 TLS,但是 <code>httpbin.legacy</code> 没有 sidecar,所以它处理不了。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ for from in "foo" "bar"; do for to in "legacy"; do kubectl exec $(kubectl get pod -l app=sleep -n ${from} -o jsonpath={.items..metadata.name}) -c sleep -n ${from} -- curl "http://httpbin.${to}:8000/ip" -s -o /dev/null -w "sleep.${from} to httpbin.${to}: %{http_code}\n"; done; done
|
||
sleep.foo to httpbin.legacy: 503
|
||
sleep.bar to httpbin.legacy: 503
|
||
</code></pre><p>为了解决这个问题,我们可以为 <code>httpbin.legacy</code> 添加一个 destination rule 覆盖 TLS 设置。例如:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl apply -f - <<EOF
|
||
apiVersion: networking.istio.io/v1alpha3
|
||
kind: DestinationRule
|
||
metadata:
|
||
name: "httpbin-legacy"
|
||
namespace: "legacy"
|
||
spec:
|
||
host: "httpbin.legacy.svc.cluster.local"
|
||
trafficPolicy:
|
||
tls:
|
||
mode: DISABLE
|
||
EOF
|
||
</code></pre><p>在您添加了 destination rule 后再次测试,确保它能通过:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ for from in "foo" "bar"; do for to in "legacy"; do kubectl exec $(kubectl get pod -l app=sleep -n ${from} -o jsonpath={.items..metadata.name}) -c sleep -n ${from} -- curl "http://httpbin.${to}:8000/ip" -s -o /dev/null -w "sleep.${from} to httpbin.${to}: %{http_code}\n"; done; done
|
||
sleep.foo to httpbin.legacy: 200
|
||
sleep.bar to httpbin.legacy: 200
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content>这个 destination rule 在服务端(<code>httpbin.legacy</code>)的命名空间中,因此它优先于定义在 <code>istio-system</code> 中的全局 destination rule。</div></aside></div><h3 id=request-from-Istio-services-to-Kubernetes-API-server>请求从 Istio 服务到 Kubernetes API server</h3><p>Kubernetes API server 没有 sidecar,所以来自 Istio 服务的请求如 <code>sleep.foo</code> 将会失败,这跟发送请求给任何非 Istio 服务有相同的问题。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default-token | cut -f1 -d ' ' | head -1) | grep -E '^token' | cut -f2 -d':' | tr -d ' \t')
|
||
$ kubectl exec $(kubectl get pod -l app=sleep -n foo -o jsonpath={.items..metadata.name}) -c sleep -n foo -- curl https://kubernetes.default/api --header "Authorization: Bearer $TOKEN" --insecure -s -o /dev/null -w "%{http_code}\n"
|
||
000
|
||
command terminated with exit code 35
|
||
</code></pre><p>再次,我们通过覆盖 API server (<code>kubernetes.default</code>) 的 destination rule 来纠正它。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl apply -f - <<EOF
|
||
apiVersion: networking.istio.io/v1alpha3
|
||
kind: DestinationRule
|
||
metadata:
|
||
name: "api-server"
|
||
namespace: istio-system
|
||
spec:
|
||
host: "kubernetes.default.svc.cluster.local"
|
||
trafficPolicy:
|
||
tls:
|
||
mode: DISABLE
|
||
EOF
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content>当您安装 Istio 并启用双向 TLS 时,这个规则,会跟全局认证策略和上述 destination rule 一起被自动注入到系统中。</div></aside></div><p>重新执行上述测试命令确认在规则添加后会返回 200:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default-token | cut -f1 -d ' ' | head -1) | grep -E '^token' | cut -f2 -d':' | tr -d ' \t')
|
||
$ kubectl exec $(kubectl get pod -l app=sleep -n foo -o jsonpath={.items..metadata.name}) -c sleep -n foo -- curl https://kubernetes.default/api --header "Authorization: Bearer $TOKEN" --insecure -s -o /dev/null -w "%{http_code}\n"
|
||
200
|
||
</code></pre><h3 id=cleanup-part-1>清除部分 1</h3><p>删除在场景中添加的全局认证策略和 destination rules:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl delete meshpolicy default
|
||
$ kubectl delete destinationrules httpbin-legacy -n legacy
|
||
$ kubectl delete destinationrules api-server -n istio-system
|
||
$ kubectl delete destinationrules default -n istio-system
|
||
</code></pre><h2 id=enable-mutual-TLS-per-namespace-or-service>为每个命名空间或者服务启用双向 TLS</h2><p>除了为您的整个网格指定一个认证策略,Istio 也支持您为特定的命名空间或者服务指定策略。一个命名空间范围的策略优先级高于网格范围的策略,而服务范围的策略优先级更高。</p><h3 id=namespace-wide-policy>命名空间范围的策略</h3><p>下述示例展示为命名空间 <code>foo</code> 中的所有服务启用双向 TLS 的策略。如你所见,它使用的类型是 <code>Policy</code> 而不是 <code>MeshPolicy</code>,在这个案例中指定命名空间为 <code>foo</code>。如果您没有指定命名空间的值,策略将会应用默认命名空间。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl apply -f - <<EOF
|
||
apiVersion: "authentication.istio.io/v1alpha1"
|
||
kind: "Policy"
|
||
metadata:
|
||
name: "default"
|
||
namespace: "foo"
|
||
spec:
|
||
peers:
|
||
- mtls: {}
|
||
EOF
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content>与 <em>网格范围的策略</em> 类似,命名空间范围的策略必须命名为 <code>default</code>,并且没有限制任何具体服务(没有 <code>targets</code> 部分)。</div></aside></div><p>添加相应的 destination rule:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl apply -f - <<EOF
|
||
apiVersion: "networking.istio.io/v1alpha3"
|
||
kind: "DestinationRule"
|
||
metadata:
|
||
name: "default"
|
||
namespace: "foo"
|
||
spec:
|
||
host: "*.foo.svc.cluster.local"
|
||
trafficPolicy:
|
||
tls:
|
||
mode: ISTIO_MUTUAL
|
||
EOF
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content>Host <code>*.foo.svc.cluster.local</code> 限制只匹配 <code>foo</code> 命名空间中的服务。</div></aside></div><p>由于这些策略和 destination rule 只应用于命名空间 <code>foo</code> 中的服务,您应该会看到只有从没有 sidecar 的客户端(<code>sleep.legacy</code>) 到 <code>httpbin.foo</code> 的请求开始失败。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ for from in "foo" "bar" "legacy"; do for to in "foo" "bar" "legacy"; do kubectl exec $(kubectl get pod -l app=sleep -n ${from} -o jsonpath={.items..metadata.name}) -c sleep -n ${from} -- curl "http://httpbin.${to}:8000/ip" -s -o /dev/null -w "sleep.${from} to httpbin.${to}: %{http_code}\n"; done; done
|
||
sleep.foo to httpbin.foo: 200
|
||
sleep.foo to httpbin.bar: 200
|
||
sleep.foo to httpbin.legacy: 200
|
||
sleep.bar to httpbin.foo: 200
|
||
sleep.bar to httpbin.bar: 200
|
||
sleep.bar to httpbin.legacy: 200
|
||
sleep.legacy to httpbin.foo: 000
|
||
command terminated with exit code 56
|
||
sleep.legacy to httpbin.bar: 200
|
||
sleep.legacy to httpbin.legacy: 200
|
||
</code></pre><h3 id=service-specific-policy>特定服务策略</h3><p>您也可以为特定服务设置认证策略和 destination rule。执行这个命令为 <code>httpbin.bar</code> 服务设置另一个策略。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n bar -f -
|
||
apiVersion: "authentication.istio.io/v1alpha1"
|
||
kind: "Policy"
|
||
metadata:
|
||
name: "httpbin"
|
||
spec:
|
||
targets:
|
||
- name: httpbin
|
||
peers:
|
||
- mtls: {}
|
||
EOF
|
||
</code></pre><p>添加一个 destination rule:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n bar -f -
|
||
apiVersion: "networking.istio.io/v1alpha3"
|
||
kind: "DestinationRule"
|
||
metadata:
|
||
name: "httpbin"
|
||
spec:
|
||
host: "httpbin.bar.svc.cluster.local"
|
||
trafficPolicy:
|
||
tls:
|
||
mode: ISTIO_MUTUAL
|
||
EOF
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content><ul><li>本示例中,我们 <strong>不</strong> 在元数据中指定命名空间而是将它放在命令行上(<code>-n bar</code>),这也有相同的作用。</li><li>认证策略和 destination rule 的名字没有限制。为了简单起见,本示例使用服务本身的名字。</li></ul></div></aside></div><p>再次,执行探查命令。跟预期一样,从 <code>sleep.legacy</code> 到 <code>httpbin.bar</code> 的请求开始失败因为同样的问题。</p><pre><code class=language-plain data-expandlinks=true data-repo=istio>...
|
||
sleep.legacy to httpbin.bar: 000
|
||
command terminated with exit code 56
|
||
</code></pre><p>如果我们在命名空间 <code>bar</code> 中还有其它服务,我们应该会看到请求它们的流量将不会受到影响。除了添加更多服务来演示这个行为,我们也可以稍微编辑策略将其应用到一个具体端口:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n bar -f -
|
||
apiVersion: "authentication.istio.io/v1alpha1"
|
||
kind: "Policy"
|
||
metadata:
|
||
name: "httpbin"
|
||
spec:
|
||
targets:
|
||
- name: httpbin
|
||
ports:
|
||
- number: 1234
|
||
peers:
|
||
- mtls: {}
|
||
EOF
|
||
</code></pre><p>对 destination rule 也做相应修改:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n bar -f -
|
||
apiVersion: "networking.istio.io/v1alpha3"
|
||
kind: "DestinationRule"
|
||
metadata:
|
||
name: "httpbin"
|
||
spec:
|
||
host: httpbin.bar.svc.cluster.local
|
||
trafficPolicy:
|
||
tls:
|
||
mode: DISABLE
|
||
portLevelSettings:
|
||
- port:
|
||
number: 1234
|
||
tls:
|
||
mode: ISTIO_MUTUAL
|
||
EOF
|
||
</code></pre><p>这个新策略将只应用在 <code>httpbin</code> 服务的 <code>1234</code> 端口。结果,双向 TLS 在 <code>8000</code> 端口上会再次失效而来自 <code>sleep.legacy</code> 的请求将会恢复正常工作。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec $(kubectl get pod -l app=sleep -n legacy -o jsonpath={.items..metadata.name}) -c sleep -n legacy -- curl http://httpbin.bar:8000/ip -s -o /dev/null -w "%{http_code}\n"
|
||
200
|
||
</code></pre><h3 id=policy-precedence>策略优先级</h3><p>为了演示特定服务策略比命名空间范围的策略优先级高,您可以像下面一样为 <code>httpbin.foo</code> 添加一个禁用双向 TLS 的策略。
|
||
注意您已经为所有在命名空间 <code>foo</code> 中的服务创建了命名空间范围的策略来启用双向 TLS 并观察到从 <code>sleep.legacy</code> 到 <code>httpbin.foo</code> 的请求都会失败(如上所示)。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n foo -f -
|
||
apiVersion: "authentication.istio.io/v1alpha1"
|
||
kind: "Policy"
|
||
metadata:
|
||
name: "overwrite-example"
|
||
spec:
|
||
targets:
|
||
- name: httpbin
|
||
EOF
|
||
</code></pre><p>添加 destination rule:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n foo -f -
|
||
apiVersion: "networking.istio.io/v1alpha3"
|
||
kind: "DestinationRule"
|
||
metadata:
|
||
name: "overwrite-example"
|
||
spec:
|
||
host: httpbin.foo.svc.cluster.local
|
||
trafficPolicy:
|
||
tls:
|
||
mode: DISABLE
|
||
EOF
|
||
</code></pre><p>重新执行来自 <code>sleep.legacy</code> 的请求,您应该又会看到请求成功返回 200 代码,证明了特定服务策略覆盖了命名空间范围的策略。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec $(kubectl get pod -l app=sleep -n legacy -o jsonpath={.items..metadata.name}) -c sleep -n legacy -- curl http://httpbin.foo:8000/ip -s -o /dev/null -w "%{http_code}\n"
|
||
200
|
||
</code></pre><h3 id=cleanup-part-2>清除部分 2</h3><p>删除上面步骤中创建的策略和 destination rules:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl delete policy default overwrite-example -n foo
|
||
$ kubectl delete policy httpbin -n bar
|
||
$ kubectl delete destinationrules default overwrite-example -n foo
|
||
$ kubectl delete destinationrules httpbin -n bar
|
||
</code></pre><h2 id=end-user-authentication>终端用户认证</h2><p>为了体验这个特性,您需要一个有效的 JWT。该 JWT 必须和您用于该 demo 的 JWKS 终端对应。在这个教程中,我们使用来自 Istio 代码基础库的 <a href=https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/demo.jwt>JWT test</a> 和 <a href=https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/jwks.json>JWKS endpoint</a>
|
||
同时,为了方便,通过 <code>ingressgateway</code> 暴露 <code>httpbin.foo</code>(更多细节,查看 <a href=/v1.6/zh/docs/tasks/traffic-management/ingress/>ingress 任务</a>)。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl apply -f - <<EOF
|
||
apiVersion: networking.istio.io/v1alpha3
|
||
kind: Gateway
|
||
metadata:
|
||
name: httpbin-gateway
|
||
namespace: foo
|
||
spec:
|
||
selector:
|
||
istio: ingressgateway # use Istio default gateway implementation
|
||
servers:
|
||
- port:
|
||
number: 80
|
||
name: http
|
||
protocol: HTTP
|
||
hosts:
|
||
- "*"
|
||
EOF
|
||
</code></pre><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl apply -f - <<EOF
|
||
apiVersion: networking.istio.io/v1alpha3
|
||
kind: VirtualService
|
||
metadata:
|
||
name: httpbin
|
||
namespace: foo
|
||
spec:
|
||
hosts:
|
||
- "*"
|
||
gateways:
|
||
- httpbin-gateway
|
||
http:
|
||
- route:
|
||
- destination:
|
||
port:
|
||
number: 8000
|
||
host: httpbin.foo.svc.cluster.local
|
||
EOF
|
||
</code></pre><p>获取 ingress IP</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
|
||
</code></pre><p>执行一个查询测试</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ curl $INGRESS_HOST/headers -s -o /dev/null -w "%{http_code}\n"
|
||
200
|
||
</code></pre><p>现在,为 <code>httpbin.foo</code> 添加一个要求配置终端用户 JWT 的策略。下面的命令假定 <code>httpbin.foo</code> 没有特定服务策略(如果您执行了<a href=#cleanup-part-2>清除</a>所述的操作,就会是这样)。您可以执行 <code>kubectl get policies.authentication.istio.io -n foo</code> 进行确认。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n foo -f -
|
||
apiVersion: "authentication.istio.io/v1alpha1"
|
||
kind: "Policy"
|
||
metadata:
|
||
name: "jwt-example"
|
||
spec:
|
||
targets:
|
||
- name: httpbin
|
||
origins:
|
||
- jwt:
|
||
issuer: "testing@secure.istio.io"
|
||
jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/jwks.json"
|
||
principalBinding: USE_ORIGIN
|
||
EOF
|
||
</code></pre><p>之前相同的 <code>curl</code> 命令将会返回 401 错误代码,由于服务器结果期望 JWT 却没有提供:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ curl $INGRESS_HOST/headers -s -o /dev/null -w "%{http_code}\n"
|
||
401
|
||
</code></pre><p>附带上上面生成的有效 token 将返回成功:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ TOKEN=$(curl https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/demo.jwt -s)
|
||
$ curl --header "Authorization: Bearer $TOKEN" $INGRESS_HOST/headers -s -o /dev/null -w "%{http_code}\n"
|
||
200
|
||
</code></pre><p>为了观察 JWT 验证的其它方面,使用脚本 <a href=https://github.com/istio/istio/tree/release-1.6/security/tools/jwt/samples/gen-jwt.py><code>gen-jwt.py</code></a> 生成新 tokens 带上不同的发行人、受众、有效期等等进行测试。这个脚本可以从 Istio 库下载:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ wget https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/gen-jwt.py
|
||
$ chmod +x gen-jwt.py
|
||
</code></pre><p>您还需要 <code>key.pem</code> 文件:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ wget https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/key.pem
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content>下载 <a href=https://pypi.org/project/jwcrypto>jwcrypto</a> 库,如果您还没有在您的系统上安装的话。</div></aside></div><p>例如,下述命令创建一个 5 秒钟过期的 token。如您所见,Istio 使用这个 token 刚开始认证请求成功,但是 5 秒后拒绝了它们。</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ TOKEN=$(./gen-jwt.py ./key.pem --expire 5)
|
||
$ for i in `seq 1 10`; do curl --header "Authorization: Bearer $TOKEN" $INGRESS_HOST/headers -s -o /dev/null -w "%{http_code}\n"; sleep 1; done
|
||
200
|
||
200
|
||
200
|
||
200
|
||
200
|
||
401
|
||
401
|
||
401
|
||
401
|
||
401
|
||
</code></pre><p>您也可以给一个 ingress gateway 添加一个 JWT 策略(例如,服务 <code>istio-ingressgateway.istio-system.svc.cluster.local</code>)。
|
||
这个常用于为绑定到这个 gateway 的所有服务定义一个 JWT 策略,而不是单独的服务。</p><h3 id=end-user-authentication-with-per-path-requirements>按路径要求的终端用户认证</h3><p>终端用户认证可以基于请求路径启用或者禁用。如果您想要让某些路径禁用认证就非常有用,例如,用于健康检查或者状态报告的路径。
|
||
您也可以为不同的路径指定不同的 JWT。</p><div><aside class="callout warning"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-warning"/></svg></div><div class=content>按路径要求的终端用户认证在 Istio 1.1 中是一个实验性的特性并 <strong>不</strong> 推荐在生产环境中使用。</div></aside></div><h4 id=disable-end-user-authentication-for-specific-paths>为指定路径禁用终端用户认证</h4><p>修改 <code>jwt-example</code> 策略禁用路径 <code>/user-agent</code> 的终端用户认证:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n foo -f -
|
||
apiVersion: "authentication.istio.io/v1alpha1"
|
||
kind: "Policy"
|
||
metadata:
|
||
name: "jwt-example"
|
||
spec:
|
||
targets:
|
||
- name: httpbin
|
||
origins:
|
||
- jwt:
|
||
issuer: "testing@secure.istio.io"
|
||
jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/jwks.json"
|
||
trigger_rules:
|
||
- excluded_paths:
|
||
- exact: /user-agent
|
||
principalBinding: USE_ORIGIN
|
||
EOF
|
||
</code></pre><p>确认 <code>/user-agent</code> 路径允许免 JWT tokens 访问:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ curl $INGRESS_HOST/user-agent -s -o /dev/null -w "%{http_code}\n"
|
||
200
|
||
</code></pre><p>确认不带 JWT tokens 的非 <code>/user-agent</code> 路径拒绝访问:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ curl $INGRESS_HOST/headers -s -o /dev/null -w "%{http_code}\n"
|
||
401
|
||
</code></pre><h4 id=enable-end-user-authentication-for-specific-paths>为指定路径启用终端用户认证</h4><p>修改 <code>jwt-example</code> 策略启用路径 <code>/ip</code> 的终端用户认证:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n foo -f -
|
||
apiVersion: "authentication.istio.io/v1alpha1"
|
||
kind: "Policy"
|
||
metadata:
|
||
name: "jwt-example"
|
||
spec:
|
||
targets:
|
||
- name: httpbin
|
||
origins:
|
||
- jwt:
|
||
issuer: "testing@secure.istio.io"
|
||
jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/jwks.json"
|
||
trigger_rules:
|
||
- included_paths:
|
||
- exact: /ip
|
||
principalBinding: USE_ORIGIN
|
||
EOF
|
||
</code></pre><p>确认不带 JWT tokens 的非 <code>/ip</code> 路径允许访问:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ curl $INGRESS_HOST/user-agent -s -o /dev/null -w "%{http_code}\n"
|
||
200
|
||
</code></pre><p>确认不带 JWT tokens 的 <code>/ip</code> 路径拒绝访问:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ curl $INGRESS_HOST/ip -s -o /dev/null -w "%{http_code}\n"
|
||
401
|
||
</code></pre><p>确认带有效 JWT token 的 <code>/ip</code> 路径允许访问:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ TOKEN=$(curl https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/demo.jwt -s)
|
||
$ curl --header "Authorization: Bearer $TOKEN" $INGRESS_HOST/ip -s -o /dev/null -w "%{http_code}\n"
|
||
200
|
||
</code></pre><h3 id=end-user-authentication-with-mutual-TLS>带双向 TLS 的终端用户认证</h3><p>终端用户认证和双向 TLS 可以共用。修改上面的策略定义双向 TLS 和终端用户 JWT 认证:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ cat <<EOF | kubectl apply -n foo -f -
|
||
apiVersion: "authentication.istio.io/v1alpha1"
|
||
kind: "Policy"
|
||
metadata:
|
||
name: "jwt-example"
|
||
spec:
|
||
targets:
|
||
- name: httpbin
|
||
peers:
|
||
- mtls: {}
|
||
origins:
|
||
- jwt:
|
||
issuer: "testing@secure.istio.io"
|
||
jwksUri: "https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/jwks.json"
|
||
principalBinding: USE_ORIGIN
|
||
EOF
|
||
</code></pre><p>添加一个 destination rule:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl apply -f - <<EOF
|
||
apiVersion: "networking.istio.io/v1alpha3"
|
||
kind: "DestinationRule"
|
||
metadata:
|
||
name: "httpbin"
|
||
namespace: "foo"
|
||
spec:
|
||
host: "httpbin.foo.svc.cluster.local"
|
||
trafficPolicy:
|
||
tls:
|
||
mode: ISTIO_MUTUAL
|
||
EOF
|
||
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.6/img/icons.svg#callout-tip"/></svg></div><div class=content>如果您已经启用网格范围或者命名空间范围的 TLS,那么 host <code>httpbin.foo</code> 已经被这些 destination rule 覆盖。
|
||
因此,您不需要添加这个 destination rule 。另外,您仍然需要添加 <code>mtls</code> 段到认证策略,因为特定服务策略将完全覆盖网格范围(或者命名空间范围)的策略。</div></aside></div><p>修改这些后,从 Istio 服务,包括 ingress gateway,到 <code>httpbin.foo</code> 的流量将使用双向 TLS。上述测试命令将仍然会正常工作。给定正确的 token,从 Istio 服务直接到 <code>httpbin.foo</code> 的请求也会正常工作:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ TOKEN=$(curl https://raw.githubusercontent.com/istio/istio/release-1.6/security/tools/jwt/samples/demo.jwt -s)
|
||
$ kubectl exec $(kubectl get pod -l app=sleep -n foo -o jsonpath={.items..metadata.name}) -c sleep -n foo -- curl http://httpbin.foo:8000/ip -s -o /dev/null -w "%{http_code}\n" --header "Authorization: Bearer $TOKEN"
|
||
200
|
||
</code></pre><p>然而,来自非 Istio 服务,使用纯文本的请求将会失败:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl exec $(kubectl get pod -l app=sleep -n legacy -o jsonpath={.items..metadata.name}) -c sleep -n legacy -- curl http://httpbin.foo:8000/ip -s -o /dev/null -w "%{http_code}\n" --header "Authorization: Bearer $TOKEN"
|
||
000
|
||
command terminated with exit code 56
|
||
</code></pre><h3 id=cleanup-part-3>清除部分 3</h3><ol><li><p>删除认证策略:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl -n foo delete policy jwt-example
|
||
</code></pre></li><li><p>删除 destination rule:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl -n foo delete destinationrule httpbin
|
||
</code></pre></li><li><p>如果您不打算研究后续任务,您只需简单删除测试命名空间即可删除所有资源:</p><pre><code class=language-bash data-expandlinks=true data-repo=istio>$ kubectl delete ns foo bar legacy
|
||
</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.6/zh/docs/tasks/security/authentication/mtls-migration/>双向 TLS 迁移</a></p><p class=desc>阐述如何将 Istio 服务逐步迁移至双向 TLS 通信模式。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.6/zh/docs/concepts/security/>安全</a></p><p class=desc>描述 Istio 的授权与认证功能。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.6/zh/blog/2020/tradewinds-2020/>Istio 2020——为了商用</a></p><p class=desc>Istio 在 2020 年的愿景声明及路线图。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.6/zh/blog/2020/istio-agent/>移除跨 pod Unix domain socket</a></p><p class=desc>一种更安全的秘密管理方式。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.6/zh/blog/2019/dns-cert/>DNS 证书管理</a></p><p class=desc>在 Istio 中配置和管理 DNS 证书。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.6/zh/blog/2019/v1beta1-authorization-policy/>Istio v1beta1 授权策略概述</a></p><p class=desc>Istio v1beta1 授权策略的设计原则、基本概述及迁移操作。</p></div></div></nav></article><nav class=pagenav><div class=left><a title="通过一个简化的工作流和最小化配置实现双向 TLS。" href=/v1.6/zh/docs/tasks/security/authentication/auto-mtls/><svg class="icon"><use xlink:href="/v1.6/img/icons.svg#left-arrow"/></svg>自动双向 TLS</a></div><div class=right><a title="展示如何在 HTTPS 服务上启用双向 TLS。" href=/v1.6/zh/docs/tasks/security/authentication/https-overlay/>通过 HTTPS 进行 TLS<svg class="icon"><use xlink:href="/v1.6/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=#before-you-begin>开始之前</a><ol><li role=none aria-label=设置><a href=#setup>设置</a></ol></li><li role=none aria-label="自动双向 TLS"><a href=#auto-mutual-TLS>自动双向 TLS</a><li role=none aria-label="全局启用 Istio 双向 TLS"><a href=#globally-enabling-Istio-mutual-TLS>全局启用 Istio 双向 TLS</a><ol><li role=none aria-label="从非 Istio 服务到 Istio 服务的请求"><a href=#request-from-non-Istio-services-to-Istio-services>从非 Istio 服务到 Istio 服务的请求</a><li role=none aria-label="从 Istio 服务到非 Istio 服务的请求"><a href=#request-from-Istio-services-to-non-Istio-services>从 Istio 服务到非 Istio 服务的请求</a><li role=none aria-label="请求从 Istio 服务到 Kubernetes API server"><a href=#request-from-Istio-services-to-Kubernetes-API-server>请求从 Istio 服务到 Kubernetes API server</a><li role=none aria-label="清除部分 1"><a href=#cleanup-part-1>清除部分 1</a></ol></li><li role=none aria-label="为每个命名空间或者服务启用双向 TLS"><a href=#enable-mutual-TLS-per-namespace-or-service>为每个命名空间或者服务启用双向 TLS</a><ol><li role=none aria-label=命名空间范围的策略><a href=#namespace-wide-policy>命名空间范围的策略</a><li role=none aria-label=特定服务策略><a href=#service-specific-policy>特定服务策略</a><li role=none aria-label=策略优先级><a href=#policy-precedence>策略优先级</a><li role=none aria-label="清除部分 2"><a href=#cleanup-part-2>清除部分 2</a></ol></li><li role=none aria-label=终端用户认证><a href=#end-user-authentication>终端用户认证</a><ol><li role=none aria-label=按路径要求的终端用户认证><a href=#end-user-authentication-with-per-path-requirements>按路径要求的终端用户认证</a><ol><li role=none aria-label=为指定路径禁用终端用户认证><a href=#disable-end-user-authentication-for-specific-paths>为指定路径禁用终端用户认证</a><li role=none aria-label=为指定路径启用终端用户认证><a href=#enable-end-user-authentication-for-specific-paths>为指定路径启用终端用户认证</a></ol></li><li role=none aria-label="带双向 TLS 的终端用户认证"><a href=#end-user-authentication-with-mutual-TLS>带双向 TLS 的终端用户认证</a><li role=none aria-label="清除部分 3"><a href=#cleanup-part-3>清除部分 3</a></ol></li><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.6.8" href=/v1.6/docs/setup/getting-started/#download aria-label="Download Istio"><span>download</span><svg class="icon"><use xlink:href="/v1.6/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.6/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.6/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.6/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.6/img/icons.svg#twitter"/></svg></a><div class=tag>对于用户</div></div><div class=info><p class=copyright>中文内容由 ServiceMesher 社区维护,部分文档可能稍微滞后于英文版本,同步工作持续进行中<br>Istio 归档
|
||
1.6.8<br>© 2020 Istio Authors, <a href=https://policies.google.com/privacy>隐私政策</a><br>归档于 2020年8月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.6/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.6/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.6/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.6/img/icons.svg#top"/></svg></button></div></body></html> |