mirror of https://github.com/istio/istio.io.git
132 lines
32 KiB
HTML
132 lines
32 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=展示授权功能的调试过程。><meta name=keywords content=microservices,services,mesh,debug,security,authorization,rbac><meta property=og:title content=调试授权><meta property=og:type content=website><meta property=og:description content=展示授权功能的调试过程。><meta property=og:url content=/v1.1/zh/help/ops/security/debugging-authorization/><meta property=og:image content=/v1.1/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.1 / 调试授权</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.1/feed.xml><link rel="shortcut icon" href=/v1.1/favicons/favicon.ico><link rel=apple-touch-icon href=/v1.1/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=icon type=image/png href=/v1.1/favicons/favicon-16x16.png sizes=16x16><link rel=icon type=image/png href=/v1.1/favicons/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=/v1.1/favicons/android-36x36.png sizes=36x36><link rel=icon type=image/png href=/v1.1/favicons/android-48x48.png sizes=48x48><link rel=icon type=image/png href=/v1.1/favicons/android-72x72.png sizes=72x72><link rel=icon type=image/png href=/v1.1/favicons/android-96x96.png sizes=96xW96><link rel=icon type=image/png href=/v1.1/favicons/android-144x144.png sizes=144x144><link rel=icon type=image/png href=/v1.1/favicons/android-192x192.png sizes=192x192><link rel=manifest href=/v1.1/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.1/css/all.css></head><body class="language-unknown archive-site"><script src=/v1.1/js/themes_init.min.js></script><script>const branchName="release-1.1";const docTitle="调试授权";const iconFile="\/v1.1/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.1/js/all.min.js data-manual defer></script><header><nav><a id=brand href=/v1.1/zh/><span class=logo><svg viewBox="0 0 300 300"><circle cx="150" cy="150" r="146" stroke-width="2" /><path d="M65 240H225L125 270z"/><path d="M65 230l60-10V110z"/><path d="M135 220l90 10L135 30z"/></svg></span><span class=name>Istioldie 1.1</span></a><div id=hamburger><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#hamburger"/></svg></div><div id=header-links><a title="了解如何部署、使用和运维 Istio。" href=/v1.1/zh/docs/>文档</a>
|
||
<a title="关于使用 Istio 的博客文章。" href=/v1.1/zh/blog/2019/root-transition/>博客</a>
|
||
<span title="一堆帮助您部署、配置和使用 Istio 的资源。">帮助</span>
|
||
<a title=关于Istio的说明。 href=/v1.1/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.1/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/help\/ops\/security\/debugging-authorization\/');return false;">当前版本</a>
|
||
<a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://preliminary.istio.io/help\/ops\/security\/debugging-authorization\/');return false;">下个版本</a>
|
||
<a tabindex=-1 role=menuitem href=https://archive.istio.io>旧版本</a></div></div><button id=search-show title=搜索istio.io aria-label=Search><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#magnifier"/></svg></button></div><form id=search-form name=cse role=search><input type=hidden name=cx value=013699703217164175118: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.1/search.html>
|
||
<input id=search-textbox class=form-control name=q type=search aria-label=搜索istio.io>
|
||
<button id=search-close title="Cancel search" type=reset aria-label="Cancel search"><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#cancel-x"/></svg></button></form></nav></header><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><div id=header0 class=header title="一堆帮助您部署、配置和使用 Istio 的资源。"><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#help"/></svg>需要帮助吗?</div><div class="body default" aria-labelledby=header0><ul role=tree aria-expanded=true aria-labelledby=header0><li role=treeitem aria-label=运维指南><button class=show aria-hidden=true></button><a title="关于运行 Istio 网格的提示、技巧和窍门。" href=/v1.1/zh/help/ops/>运维指南</a><ul role=group aria-expanded=true><li role=none><a role=treeitem title=描述如何使用组件日志来深入了解运行组件的行为。 href=/v1.1/zh/help/ops/component-logging/>组件日志</a></li><li role=none><a role=treeitem title="描述如何使用 ControlZ 检测查看单个组件的运行状态。" href=/v1.1/zh/help/ops/controlz/>组件内检</a></li><li role=none><a role=treeitem title="如何从底层调试 Istio 组件。" href=/v1.1/zh/help/ops/component-debugging/>组件调试</a></li><li role=treeitem aria-label=流量管理><button aria-hidden=true></button><a title=帮助管理服务网格中的网络。 href=/v1.1/zh/help/ops/traffic-management/>流量管理</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="介绍 Istio 网络操作方面知识。" href=/v1.1/zh/help/ops/traffic-management/introduction/>网络运维介绍</a></li><li role=none><a role=treeitem title=提供特定的部署和配置指南。 href=/v1.1/zh/help/ops/traffic-management/deploy-guidelines/>部署和配置指南</a></li><li role=none><a role=treeitem title=常见网络相关问题的识别和处理。 href=/v1.1/zh/help/ops/traffic-management/troubleshooting/>网络问题排查</a></li><li role=none><a role=treeitem title=有关如何启用和理解本地负载均衡的信息。 href=/v1.1/zh/help/ops/traffic-management/locality-load-balancing/>本地负载均衡</a></li><li role=none><a role=treeitem title="用于对流量管理方面的 Envoy 配置问题进行检测的工具和技术。" href=/v1.1/zh/help/ops/traffic-management/proxy-cmd/>调试 Envoy 和 Pilot</a></li><li role=none><a role=treeitem title=介绍一些工具和技术,用来针对流量管理方面的配置问题进行诊断。 href=/v1.1/zh/help/ops/traffic-management/observing/>配置问题诊断</a></li></ul></li><li role=treeitem aria-label=安全><button class=show aria-hidden=true></button><a title=帮助你管理运行中的网格的安全性方面问题。 href=/v1.1/zh/help/ops/security/>安全</a><ul role=group aria-expanded=true class=leaf-section><li role=none><span role=treeitem class=current title=展示授权功能的调试过程。>调试授权</span></li><li role=none><a role=treeitem title="如果 Citadel 表现不正常该怎么办。" href=/v1.1/zh/help/ops/security/repairing-citadel/>修复 Citadel</a></li><li role=none><a role=treeitem title="如果您怀疑 Istio 密钥和证书有问题该怎么办。" href=/v1.1/zh/help/ops/security/keys-and-certs/>密钥和证书</a></li><li role=none><a role=treeitem title="如何处理 TLS 认证的失效问题。" href=/v1.1/zh/help/ops/security/mutual-tls/>双向 TLS</a></li><li role=none><a role=treeitem title="如何在启用双向 TLS 的情况下运行健康检查。" href=/v1.1/zh/help/ops/security/health-checks-and-mtls/>健康检查和双向 TLS</a></li><li role=none><a role=treeitem title=已经启用了授权,但是无论如何请求还是会通过。 href=/v1.1/zh/help/ops/security/authorization-permissive/>授权太过宽松</a></li><li role=none><a role=treeitem title=启用了授权然后任何请求都无法到达服务。 href=/v1.1/zh/help/ops/security/authorization-restrictive/>授权过于严格</a></li><li role=none><a role=treeitem title=如果终端用户身份验证不起作用,该怎么办。 href=/v1.1/zh/help/ops/security/end-user-auth/>终端用户身份验证</a></li><li role=none><a role=treeitem title="学习如何延长 Istio 自签发根证书的有效期。" href=/v1.1/zh/help/ops/security/root-transition/>延长自签发证书的有效期</a></li></ul></li><li role=treeitem aria-label=遥测><button aria-hidden=true></button><a title=帮助您在一个运行的服务网格中管理遥测数据的采集和可视化。 href=/v1.1/zh/help/ops/telemetry/>遥测</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem href=/v1.1/zh/help/ops/telemetry/missing-metrics/>查看不到指标</a></li><li role=none><a role=treeitem title="处理 Grafana 相关问题。" href=/v1.1/zh/help/ops/telemetry/grafana/>Grafana</a></li><li role=none><a role=treeitem title="Envoy 统计数据的细粒度控制。" href=/v1.1/zh/help/ops/telemetry/envoy-stats/>Envoy 统计数据</a></li></ul></li><li role=treeitem aria-label=安装和设置><button aria-hidden=true></button><a title="帮助诊断和修复 Isto 安装问题。" href=/v1.1/zh/help/ops/setup/>安装和设置</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title="概述了 Istio 使用 Kubernetes Webhook 及可能出现的相关问题。" href=/v1.1/zh/help/ops/setup/webhook/>动态准入 Webhook 概述</a></li><li role=none><a role=treeitem title="Istio 使用 Kubernetes webhook 进行服务器端配置验证的方式。" href=/v1.1/zh/help/ops/setup/validation/>配置验证 Webhook</a></li><li role=none><a role=treeitem title="描述了 Istio 如何使用 Kubernetes webhooks 进行自动 sidecar 注入。" href=/v1.1/zh/help/ops/setup/injection/>Sidecar 注入 Webhook</a></li><li role=none><a role=treeitem title="如何检查 Pod 中被许可的功能。" href=/v1.1/zh/help/ops/setup/required-pod-capabilities/>Pod 的必要功能</a></li><li role=none><a role=treeitem title="展示如何对 Istio service 进行健康检查。" href=/v1.1/zh/help/ops/setup/app-health-check/>Istio Service 健康检查</a></li></ul></li><li role=none><a role=treeitem title="关于解决 Istio 常见问题的建议。" href=/v1.1/zh/help/ops/misc/>杂项</a></li></ul></li><li role=treeitem aria-label=FAQ><button aria-hidden=true></button><a title=关于Istio的常见问题。 href=/v1.1/zh/help/faq/>FAQ</a><ul role=group aria-expanded=false class=leaf-section><li role=none><a role=treeitem title=常见问题。 href=/v1.1/zh/help/faq/general/>常见问题</a></li><li role=none><a role=treeitem title="安装 Q & A。" href=/v1.1/zh/help/faq/setup/>安装</a></li><li role=none><a role=treeitem title=安全方面的常见问题。 href=/v1.1/zh/help/faq/security/>安全</a></li><li role=none><a role=treeitem title="Mixer Q & A。" href=/v1.1/zh/help/faq/mixer/>Mixer</a></li><li role=none><a role=treeitem title=度量和日志的常见问题。 href=/v1.1/zh/help/faq/metrics-and-logs/>度量和日志</a></li><li role=none><a role=treeitem title="遥测 Q & A." href=/v1.1/zh/help/faq/telemetry/>遥测</a></li><li role=none><a role=treeitem title=分布式追踪问答。 href=/v1.1/zh/help/faq/distributed-tracing/>分布式追踪</a></li><li role=none><a role=treeitem title="流量管理 Q & A。" href=/v1.1/zh/help/faq/traffic-management/>流量管理</a></li></ul></li><li role=none><a role=treeitem title="Istio 常见的术语表。" href=/v1.1/zh/help/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.1/img/icons.svg#pull"/></svg></button><nav aria-label=Breadcrumb><ol><li><a href=/v1.1/zh/>Istio</a></li><li><a href=/v1.1/zh/help/ title="一堆帮助您部署、配置和使用 Istio 的资源。">帮助</a></li><li><a href=/v1.1/zh/help/ops/ title="关于运行 Istio 网格的提示、技巧和窍门。">运维指南</a></li><li><a href=/v1.1/zh/help/ops/security/ title=帮助你管理运行中的网格的安全性方面问题。>安全</a></li><li>调试授权</li></ol></nav><article aria-labelledby=title><div class=title-area><div><h1 id=title>调试授权</h1><p class=byline><span title="524 字"><svg class="icon"><use xlink:href="/v1.1/img/icons.svg#clock"/></svg><span> </span>阅读大约需要 3 分钟</span></p></div></div><nav class=toc-inlined aria-label="Table of Contents"><div><hr><ol><li role=none aria-label=确保授权功能已经正确启用><a href=#%e7%a1%ae%e4%bf%9d%e6%8e%88%e6%9d%83%e5%8a%9f%e8%83%bd%e5%b7%b2%e7%bb%8f%e6%ad%a3%e7%a1%ae%e5%90%af%e7%94%a8>确保授权功能已经正确启用</a><li role=none aria-label="检查 Pilot 的工作状态"><a href=#%e6%a3%80%e6%9f%a5-pilot-%e7%9a%84%e5%b7%a5%e4%bd%9c%e7%8a%b6%e6%80%81>检查 Pilot 的工作状态</a><li role=none aria-label="确认 Pilot 正确的将策略分发给了代理服务器"><a href=#%e7%a1%ae%e8%ae%a4-pilot-%e6%ad%a3%e7%a1%ae%e7%9a%84%e5%b0%86%e7%ad%96%e7%95%a5%e5%88%86%e5%8f%91%e7%bb%99%e4%ba%86%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8>确认 Pilot 正确的将策略分发给了代理服务器</a><li role=none aria-label=确认策略在代理服务器中正确执行><a href=#%e7%a1%ae%e8%ae%a4%e7%ad%96%e7%95%a5%e5%9c%a8%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%ad%e6%ad%a3%e7%a1%ae%e6%89%a7%e8%a1%8c>确认策略在代理服务器中正确执行</a><li role=none aria-label=相关内容><a href=#see-also>相关内容</a></li></ol><hr></div></nav><p>这篇文章展示了调试 Istio 授权功能的过程。</p><div><aside class="callout idea"><div class=type><svg class="large-icon"><use xlink:href="/v1.1/img/icons.svg#callout-idea"/></svg></div><div class=content>如果能够按照<a href=/v1.1/zh/about/bugs>报告错误</a>的说明生成集群状态存档,会对调试过程产生很大帮助</div></aside></div><h2 id=确保授权功能已经正确启用>确保授权功能已经正确启用</h2><p><code>ClusterRbacConfig</code> 是一个集群级的单例 CRD,用于控制全局的授权功能。</p><ol><li><p>运行下面的命令来列出现存的 <code>ClusterRbacConfig</code>:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl get clusterrbacconfigs.rbac.istio.io --all-namespaces
|
||
</code></pre></li><li><p>这里应该<strong>只有一个</strong> <code>ClusterRbacConfig</code> 实例,其名称应该是 <code>default</code>。否则 Istio 会禁用授权功能并忽略所有策略。</p><pre><code class=language-plain data-expandlinks=true>NAMESPACE NAME AGE
|
||
default default 1d
|
||
</code></pre></li><li><p>如果上面步骤中出现了不止一个的 <code>ClusterRbacConfig</code> 实例,请删除其它的 <code>ClusterRbacConfig</code>,保证集群之中只有一个名为 <code>default</code> 的 <code>ClusterRbacConfig</code>。</p></li></ol><h2 id=检查-pilot-的工作状态>检查 Pilot 的工作状态</h2><p>Pilot 负责对授权策略进行转换,并将其传播给 Sidecar。下面的的步骤可以用于确认 Pilot 是否能够正常工作:</p><ol><li><p>运行下列命令,导出 Pilot 的 <code>ControlZ</code>:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl port-forward $(kubectl -n istio-system get pods -l istio=pilot -o jsonpath='{.items[0].metadata.name}') -n istio-system 9876:9876
|
||
</code></pre></li><li><p>正常情况下应该看到如下输出:</p><pre><code class=language-plain data-expandlinks=true>Forwarding from 127.0.0.1:9876 -> 9876
|
||
</code></pre></li><li><p>用浏览器打开 <code>http://127.0.0.1:9876/scopez/</code>,浏览 <code>ControlZ</code> 页面。</p></li><li><p>将 <code>rbac</code> 输出级别修改为 <code>debug</code>。</p></li><li><p>在步骤 1 中打开的终端窗口中输入 <code>Ctrl+C</code>,终止端口转发进程。</p></li><li><p>输出 Pilot 日志,在其中搜索 <code>rbac</code>:</p><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.1/img/icons.svg#callout-tip"/></svg></div><div class=content>你可能需要先删除并重建授权策略,以保证调试日志能够根据这些策略正常生成。</div></aside></div><pre><code class=language-bash data-expandlinks=true>$ kubectl logs $(kubectl -n istio-system get pods -l istio=pilot -o jsonpath='{.items[0].metadata.name}') -c discovery -n istio-system | grep rbac
|
||
</code></pre></li><li><p>检查输出:</p><ul><li>没有出现错误。</li><li>出现 <code>"built filter config for ..."</code> 消息,意味着为目标服务生成了过滤器。</li></ul></li><li><p>例如你可能会看到类似这样的内容:</p><pre><code class=language-plain data-expandlinks=true>2018-07-26T22:25:41.009838Z debug rbac building filter config for {sleep.foo.svc.cluster.local map[app:sleep pod-template-hash:3326367878] map[destination.name:sleep destination.namespace:foo destination.user:default]}
|
||
2018-07-26T22:25:41.009915Z info rbac no service role in namespace foo
|
||
2018-07-26T22:25:41.009957Z info rbac no service role binding in namespace foo
|
||
2018-07-26T22:25:41.010000Z debug rbac generated filter config: { }
|
||
2018-07-26T22:25:41.010114Z info rbac built filter config for sleep.foo.svc.cluster.local
|
||
2018-07-26T22:25:41.182400Z debug rbac building filter config for {productpage.default.svc.cluster.local map[pod-template-hash:2600844901 version:v1 app:productpage] map[destination.name:productpage destination.namespace:default destination.user:bookinfo-productpage]}
|
||
2018-07-26T22:25:41.183131Z debug rbac checking role app2-grpc-viewer
|
||
2018-07-26T22:25:41.183214Z debug rbac role skipped for no AccessRule matched
|
||
2018-07-26T22:25:41.183255Z debug rbac checking role productpage-viewer
|
||
2018-07-26T22:25:41.183281Z debug rbac matched AccessRule[0]
|
||
2018-07-26T22:25:41.183390Z debug rbac generated filter config: {policies:<key:"productpage-viewer" value:<permissions:<and_rules:<rules:<or_rules:<rules:<header:<name:":method" exact_match:"GET" > > > > > > principals:<and_ids:<ids:<any:true > > > > > }
|
||
2018-07-26T22:25:41.184407Z info rbac built filter config for productpage.default.svc.cluster.local
|
||
</code></pre><p>说明 Pilot 生成了:</p><ul><li><p>针对 <code>sleep.foo.svc.cluster.local</code> 的配置是空的,原因是没有符合条件的策略可以使用,结果是 Istio 缺省情况下,会禁止所有对这一服务的访问。</p></li><li><p><code>productpage.default.svc.cluster.local</code> 的配置让 Istio 放行所有针对该服务的 GET 访问。</p></li></ul></li></ol><h2 id=确认-pilot-正确的将策略分发给了代理服务器>确认 Pilot 正确的将策略分发给了代理服务器</h2><p>Pilot 负责向代理服务器分发授权策略。下面的步骤用来确认 Pilot 的分发工作状态。</p><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.1/img/icons.svg#callout-tip"/></svg></div><div class=content>这里的命令假设用户已经部署了 <a href=/v1.1/zh/docs/examples/bookinfo/>Bookinfo</a>,否则的话应该将 <code>"-l app=productpage"</code> 部分根据实际情况进行替换。</div></aside></div><ol><li><p>运行下面的命令,获取 <code>productpage</code> 服务的代理配置信息:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl exec $(kubectl get pods -l app=productpage -o jsonpath='{.items[0].metadata.name}') -c istio-proxy -- curl localhost:15000/config_dump -s
|
||
</code></pre></li><li><p>校验日志内容:</p><ul><li>日志中包含了一个 <code>envoy.filters.http.rbac</code> 过滤器,会针对进入请求执行授权策略。</li><li>授权策略更新之后,Istio 会据此更新过滤器。</li></ul></li><li><p>后续输出表明,<code>productpage</code> 的代理服务器启用了 <code>envoy.filters.http.rbac</code> 过滤器,这个过滤器允许任何人通过 <code>GET</code> 方法进行访问。<code>shadow_rules</code> 没有生效,可以安全忽略。</p><pre><code class=language-json data-expandlinks=true>{
|
||
"name": "envoy.filters.http.rbac",
|
||
"config": {
|
||
"rules": {
|
||
"policies": {
|
||
"productpage-viewer": {
|
||
"permissions": [
|
||
{
|
||
"and_rules": {
|
||
"rules": [
|
||
{
|
||
"or_rules": {
|
||
"rules": [
|
||
{
|
||
"header": {
|
||
"exact_match": "GET",
|
||
"name": ":method"
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
],
|
||
"principals": [
|
||
{
|
||
"and_ids": {
|
||
"ids": [
|
||
{
|
||
"any": true
|
||
}
|
||
]
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
},
|
||
"shadow_rules": {
|
||
"policies": {}
|
||
}
|
||
}
|
||
},
|
||
</code></pre></li></ol><h2 id=确认策略在代理服务器中正确执行>确认策略在代理服务器中正确执行</h2><p>代理是授权策略的最终实施者。下面的步骤帮助用户确认代理的工作情况:</p><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.1/img/icons.svg#callout-tip"/></svg></div><div class=content>这里的命令假设用户已经部署了 <a href=/v1.1/zh/docs/examples/bookinfo/>Bookinfo</a>,否则的话应该将 <code>"-l app=productpage"</code> 部分根据实际情况进行替换。</div></aside></div><ol><li><p>在代理中打开授权调试日志:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl exec $(kubectl get pods -l app=productpage -o jsonpath='{.items[0].metadata.name}') -c istio-proxy -- curl -X POST localhost:15000/logging?rbac=debug -s
|
||
</code></pre></li><li><p>检查输出内容是否包含如下内容:</p><pre><code class=language-plain data-expandlinks=true>active loggers:
|
||
... ...
|
||
rbac: debug
|
||
... ...
|
||
</code></pre></li><li><p>在浏览器中打开 <code>productpage</code>,以便生成日志。</p></li><li><p>用命令输出代理日志:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl logs $(kubectl get pods -l app=productpage -o jsonpath='{.items[0].metadata.name}') -c istio-proxy
|
||
</code></pre></li><li><p>检查日志内容:</p><ul><li><p>输出日志中可能包含 <code>enforced allowed</code> 或者 <code>enforced denied</code>,表示请求被允许或者拒绝。</p></li><li><p>授权策略需要从请求中获取数据。</p></li></ul></li><li><p>下面的输出表示,有请求 <code>productpage</code> 的 <code>GET</code> 请求被策略放行。</p><p><code>shadow denied</code> 没有实际效果,可以忽略。</p><pre><code class=language-plain data-expandlinks=true>...
|
||
[2018-07-26 20:39:18.060][152][debug][rbac] external/envoy/source/extensions/filters/http/rbac/rbac_filter.cc:79] checking request: remoteAddress: 10.60.0.139:51158, localAddress: 10.60.0.93:9080, ssl: uriSanPeerCertificate: spiffe://cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account, subjectPeerCertificate: O=, headers: ':authority', '35.238.0.62'
|
||
':path', '/productpage'
|
||
':method', 'GET'
|
||
'upgrade-insecure-requests', '1'
|
||
'user-agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
|
||
'dnt', '1'
|
||
'accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
|
||
'accept-encoding', 'gzip, deflate'
|
||
'accept-language', 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'
|
||
'x-forwarded-for', '10.60.0.1'
|
||
'x-forwarded-proto', 'http'
|
||
'x-request-id', 'e23ea62d-b25d-91be-857c-80a058d746d4'
|
||
'x-b3-traceid', '5983108bf6d05603'
|
||
'x-b3-spanid', '5983108bf6d05603'
|
||
'x-b3-sampled', '1'
|
||
'x-istio-attributes', 'CikKGGRlc3RpbmF0aW9uLnNlcnZpY2UubmFtZRINEgtwcm9kdWN0cGFnZQoqCh1kZXN0aW5hdGlvbi5zZXJ2aWNlLm5hbWVzcGFjZRIJEgdkZWZhdWx0Ck8KCnNvdXJjZS51aWQSQRI/a3ViZXJuZXRlczovL2lzdGlvLWluZ3Jlc3NnYXRld2F5LTc2NjY0Y2NmY2Ytd3hjcjQuaXN0aW8tc3lzdGVtCj4KE2Rlc3RpbmF0aW9uLnNlcnZpY2USJxIlcHJvZHVjdHBhZ2UuZGVmYXVsdC5zdmMuY2x1c3Rlci5sb2NhbApDChhkZXN0aW5hdGlvbi5zZXJ2aWNlLmhvc3QSJxIlcHJvZHVjdHBhZ2UuZGVmYXVsdC5zdmMuY2x1c3Rlci5sb2NhbApBChdkZXN0aW5hdGlvbi5zZXJ2aWNlLnVpZBImEiRpc3RpbzovL2RlZmF1bHQvc2VydmljZXMvcHJvZHVjdHBhZ2U='
|
||
'content-length', '0'
|
||
'x-envoy-internal', 'true'
|
||
'sec-istio-authn-payload', 'CkVjbHVzdGVyLmxvY2FsL25zL2lzdGlvLXN5c3RlbS9zYS9pc3Rpby1pbmdyZXNzZ2F0ZXdheS1zZXJ2aWNlLWFjY291bnQSRWNsdXN0ZXIubG9jYWwvbnMvaXN0aW8tc3lzdGVtL3NhL2lzdGlvLWluZ3Jlc3NnYXRld2F5LXNlcnZpY2UtYWNjb3VudA=='
|
||
, dynamicMetadata: filter_metadata {
|
||
key: "istio_authn"
|
||
value {
|
||
fields {
|
||
key: "request.auth.principal"
|
||
value {
|
||
string_value: "cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account"
|
||
}
|
||
}
|
||
fields {
|
||
key: "source.principal"
|
||
value {
|
||
string_value: "cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
[2018-07-26 20:39:18.060][152][debug][rbac] external/envoy/source/extensions/filters/http/rbac/rbac_filter.cc:88] shadow denied
|
||
[2018-07-26 20:39:18.060][152][debug][rbac] external/envoy/source/extensions/filters/http/rbac/rbac_filter.cc:98] enforced allowed
|
||
...
|
||
</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.1/zh/blog/2018/istio-authorization/>基于 Istio 的 Micro-Segmentation 授权</a></p><p class=desc>描述 Istio 的授权功能以及如何在各种用例中使用它。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/tasks/security/authz-http/>HTTP 服务的访问控制</a></p><p class=desc>展示为 HTTP 服务设置基于角色的访问控制方法。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/tasks/security/authz-tcp/>TCP 服务的访问控制</a></p><p class=desc>展示如何为 TCP 服务设置基于角色的访问控制。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/concepts/security/>安全</a></p><p class=desc>描述 Istio 的授权与鉴权功能。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/tasks/security/authz-permissive/>鉴权过程中的宽容模式</a></p><p class=desc>展示宽容模式的的鉴权过程。</p></div><div class=entry><p class=link><a data-skipendnotes=true href=/v1.1/zh/docs/tasks/security/rbac-groups/>基于组和列表类型声明的授权</a></p><p class=desc>有关如何在 Istio 中配置基于组的授权和配置列表类型声明的授权的教程。</p></div></div></nav></article><nav class=pagenav><div class=left></div><div class=right><a title="如果 Citadel 表现不正常该怎么办。" href=/v1.1/zh/help/ops/security/repairing-citadel/>修复 Citadel<svg class="icon"><use xlink:href="/v1.1/img/icons.svg#right-arrow"/></svg></a></div></nav><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=#%e7%a1%ae%e4%bf%9d%e6%8e%88%e6%9d%83%e5%8a%9f%e8%83%bd%e5%b7%b2%e7%bb%8f%e6%ad%a3%e7%a1%ae%e5%90%af%e7%94%a8>确保授权功能已经正确启用</a><li role=none aria-label="检查 Pilot 的工作状态"><a href=#%e6%a3%80%e6%9f%a5-pilot-%e7%9a%84%e5%b7%a5%e4%bd%9c%e7%8a%b6%e6%80%81>检查 Pilot 的工作状态</a><li role=none aria-label="确认 Pilot 正确的将策略分发给了代理服务器"><a href=#%e7%a1%ae%e8%ae%a4-pilot-%e6%ad%a3%e7%a1%ae%e7%9a%84%e5%b0%86%e7%ad%96%e7%95%a5%e5%88%86%e5%8f%91%e7%bb%99%e4%ba%86%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8>确认 Pilot 正确的将策略分发给了代理服务器</a><li role=none aria-label=确认策略在代理服务器中正确执行><a href=#%e7%a1%ae%e8%ae%a4%e7%ad%96%e7%95%a5%e5%9c%a8%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%ad%e6%ad%a3%e7%a1%ae%e6%89%a7%e8%a1%8c>确认策略在代理服务器中正确执行</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="Go download Istio 1.1.9 now" href=https://github.com/istio/istio/releases/tag/1.1.9 aria-label="Download Istio"><span>download</span><svg class="icon"><use xlink:href="/v1.1/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.1/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.1/img/icons.svg#stackoverflow"/></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.1/img/icons.svg#twitter"/></svg></a><div class=tag>对于用户</div></div><div class=info><p class=copyright>中文内容由 ServiceMesher 社区维护,部分文档可能稍微滞后于英文版本,同步工作持续进行中<br>Istio 归档
|
||
1.1.9<br>© 2019 Istio Authors, <a href=https://policies.google.com/privacy>隐私政策</a><br>归档于 2019年6月18日</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.1/img/icons.svg#github"/></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.1/img/icons.svg#slack"/></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.1/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.1/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.1/img/icons.svg#top"/></svg></button></div></body></html> |