istio.io/archive/v1.2/zh/faq/security/index.html

71 lines
22 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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><meta property=og:title content=安全方面的常见问题><meta property=og:type content=website><meta property=og:description content=安全方面的常见问题。><meta property=og:url content=/v1.2/zh/faq/security/><meta property=og:image content=/v1.2/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.2 / 安全方面的常见问题</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.2/feed.xml><link rel="shortcut icon" href=/v1.2/favicons/favicon.ico><link rel=apple-touch-icon href=/v1.2/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=icon type=image/png href=/v1.2/favicons/favicon-16x16.png sizes=16x16><link rel=icon type=image/png href=/v1.2/favicons/favicon-32x32.png sizes=32x32><link rel=icon type=image/png href=/v1.2/favicons/android-36x36.png sizes=36x36><link rel=icon type=image/png href=/v1.2/favicons/android-48x48.png sizes=48x48><link rel=icon type=image/png href=/v1.2/favicons/android-72x72.png sizes=72x72><link rel=icon type=image/png href=/v1.2/favicons/android-96x96.png sizes=96xW96><link rel=icon type=image/png href=/v1.2/favicons/android-144x144.png sizes=144x144><link rel=icon type=image/png href=/v1.2/favicons/android-192x192.png sizes=192x192><link rel=manifest href=/v1.2/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.2/css/all.css><script src=/v1.2/js/themes_init.min.js></script></head><body class="language-unknown archive-site"><script>const branchName="release-1.2";const docTitle="安全方面的常见问题";const iconFile="\/v1.2/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.2/js/all.min.js data-manual defer></script><header><nav><a id=brand href=/v1.2/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.2</span></a><div id=hamburger><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#hamburger"/></svg></div><div id=header-links><a title="了解如何部署、使用和运维 Istio。" href=/v1.2/zh/docs/>文档</a>
<a title="关于使用 Istio 的博客文章。" href=/v1.2/zh/blog/2019/announcing-1.1.3/>博客</a>
<span title=关于Istio的常见问题。>FAQ</span>
<a title=关于Istio的说明。 href=/v1.2/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.2/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/faq\/security\/');return false;">当前版本</a>
<a tabindex=-1 role=menuitem onclick="navigateToUrlOrRoot('https://preliminary.istio.io/faq\/security\/');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.2/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.2/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.2/img/icons.svg#cancel-x"/></svg></button></form></nav></header><main class="primary notoc"><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.2/img/icons.svg#faq"/></svg>FAQ</div><div class="body default" aria-labelledby=header0><ul role=tree aria-expanded=true class=leaf-section aria-labelledby=header0><li role=none><a role=treeitem title=常见问题。 href=/v1.2/zh/faq/general/>常见问题</a></li><li role=none><a role=treeitem title="安装 Q &amp; A。" href=/v1.2/zh/faq/setup/>安装</a></li><li role=none><span role=treeitem class=current title=安全方面的常见问题。>安全</span></li><li role=none><a role=treeitem title="Mixer Q &amp; A。" href=/v1.2/zh/faq/mixer/>Mixer</a></li><li role=none><a role=treeitem title=度量和日志的常见问题。 href=/v1.2/zh/faq/metrics-and-logs/>度量和日志</a></li><li role=none><a role=treeitem title="遥测 Q &amp; A." href=/v1.2/zh/faq/telemetry/>遥测</a></li><li role=none><a role=treeitem title=分布式追踪问答。 href=/v1.2/zh/faq/distributed-tracing/>分布式追踪</a></li><li role=none><a role=treeitem title="流量管理 Q &amp; A。" href=/v1.2/zh/faq/traffic-management/>流量管理</a></li></ul></div></div></div></nav></div><div class=article-container><nav aria-label=Breadcrumb><ol><li><a href=/v1.2/zh/>Istio</a></li><li><a href=/v1.2/zh/faq/ title=关于Istio的常见问题。>FAQ</a></li><li>安全</li></ol></nav><article aria-labelledby=title><div class=title-area><i class=title-icon><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#faq"/></svg></i><div><h1 id=title>安全方面的常见问题</h1></div></div><nav class="toc-inlined toc-forced"><hr><div class=directory role=directory><nav id=InlineTableOfContents><ol><li role=none aria-label="安装 Istio 之后如何启用或者禁用双向 TLS"><a href=#enabling-disabling-mtls>安装 Istio 之后如何启用或者禁用双向 TLS</a></li><li role=none aria-label="如何检查服务是否启动了双向 TLS"><a href=#check-policy>如何检查服务是否启动了双向 TLS</a></li><li role=none aria-label="同一集群中是否可以仅对部分服务启用双向 TLS "><a href=#auth-mix-and-match>同一集群中是否可以仅对部分服务启用双向 TLS </a></li><li role=none aria-label="如果全局启用了双向 TLS非 Istio 服务可以访问 Istio 服务吗?"><a href=#non-istio-to-istio>如果全局启用了双向 TLS非 Istio 服务可以访问 Istio 服务吗?</a></li><li role=none aria-label="如何使用 Istio 的服务访问非 Istio 服务?"><a href=#accessing-non-istio-services>如何使用 Istio 的服务访问非 Istio 服务?</a></li><li role=none aria-label="当启用双向 TLS 认证时应该如何使用 Kubernetes liveness 和 readiness 对服务进行健康检查?"><a href=#k8s-health-checks>当启用双向 TLS 认证时应该如何使用 Kubernetes liveness 和 readiness 对服务进行健康检查?</a></li><li role=none aria-label="如何配置 Istio 证书的有效期?"><a href=#cert-lifetime-config>如何配置 Istio 证书的有效期?</a></li><li role=none aria-label="Istio 是否支持授权和鉴权?"><a href=#does-istio-support-authorization>Istio 是否支持授权和鉴权?</a></li><li role=none aria-label="Istio 权限认证是否使用了 Kubernetes secrets?"><a href=#use-k8s-secrets>Istio 权限认证是否使用了 Kubernetes secrets?</a></li><li role=none aria-label=工作负载中的密钥和证书是加密存储的么?><a href=#secret-encryption>工作负载中的密钥和证书是加密存储的么?</a></li><li role=none aria-label="Istio 中如何配置 Ingress 令其仅接受 TLS 连接?"><a href=#secure-ingress>Istio 中如何配置 Ingress 令其仅接受 TLS 连接?</a></li><li role=none aria-label="我可以为 HTTPS 服务安装 Istio sidecar 吗?"><a href=#https-overlay>我可以为 HTTPS 服务安装 Istio sidecar 吗?</a></li></ol></nav></div><hr></nav><div class=faq><h5 id=enabling-disabling-mtls class=question>安装 Istio 之后如何启用或者禁用双向 TLS</h5><div class=answer><p>可以利用<a href=/v1.2/zh/docs/concepts/security/#认证策略>认证策略</a><a href=/v1.2/zh/docs/concepts/traffic-management/#目标规则>目标规则</a>随时为服务设置双向 TLS 认证。请阅读<a href=/v1.2/zh/docs/tasks/security/authn-policy/>认证策略任务</a>以获取更多相关细节。</p></div><h5 id=check-policy class=question>如何检查服务是否启动了双向 TLS</h5><div class=answer><p><code>istioctl</code> 工具为此提供了一个选项,你可以像下面那样做:</p><pre><code class=language-bash data-expandlinks=true>$ istioctl authn tls-check $CLIENT_POD httpbin.default.svc.cluster.local
HOST:PORT STATUS SERVER CLIENT AUTHN POLICY DESTINATION RULE
httpbin.default.svc.cluster.local:8000 OK mTLS mTLS default/ default/istio-system
</code></pre><p>其中 <code>$CLIENT_POD</code> 是作为客户端服务运行的 Pods 中任意一个的 ID。</p><p>更多详细信息,请参见<a href=/v1.2/zh/docs/tasks/security/mutual-tls/#检查-istio-双向-tls-认证的配置>检查双向 TLS 配置</a></p></div><h5 id=auth-mix-and-match class=question>同一集群中是否可以仅对部分服务启用双向 TLS </h5><div class=answer><p><a href=/v1.2/zh/docs/concepts/security/#认证策略>认证策略</a>可以是网格范围的(对网格中的所有服务都有效)、命名空间范围的(对同一命名空间中的所有服务都有效)或者是针对特定服务的。在集群中可以用任何需要的方式来为服务设置双向 TLS 策略。</p></div><h5 id=non-istio-to-istio class=question>如果全局启用了双向 TLS非 Istio 服务可以访问 Istio 服务吗?</h5><div class=answer><p>非 Istio 服务无法与 Istio 服务进行通信,除非它们可以提供有效证书,而这种证书也很难提供。这正是<em>双向 TLS</em> 功能的目的。但是,你可以覆盖特定命名空间或服务的全局标志 (global flag)。有关详细信息,请参阅<a href=/v1.2/zh/docs/tasks/security/authn-policy>任务</a></p></div><h5 id=accessing-non-istio-services class=question>如何使用 Istio 的服务访问非 Istio 服务?</h5><div class=answer><p>当全局启用双向 TLS 时,全局目标规则 (<em>global</em> destination rule) 匹配群集中的所有服务,无论这些服务是否具有 Istio sidecar。 这包括 Kubernetes API 服务器,以及集群中的任何非 Istio 服务。 要让这些非 Istio 服务与有 Istio sidecar 的服务进行通信,你需要设置目标规则以免除服务。 例如:</p><pre><code class=language-bash data-expandlinks=true>$ kubectl apply -f - &lt;&lt;EOF
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: &#34;api-server&#34;
spec:
host: &#34;kubernetes.default.svc.cluster.local&#34;
trafficPolicy:
tls:
mode: DISABLE
EOF
</code></pre><div><aside class="callout tip"><div class=type><svg class="large-icon"><use xlink:href="/v1.2/img/icons.svg#callout-tip"/></svg></div><div class=content>这个目标规则已作为 Istio 安装的一部分添加到系统中,并具有默认的双向 TLS</div></aside></div><p>同样,您可以为其他非 Istio 服务添加目标规则。 有关更多示例,请参阅<a href=/v1.2/docs/tasks/security/authn-policy/#request-from-istio-services-to-non-istio-services>任务</a></p></div><h5 id=k8s-health-checks class=question>当启用双向 TLS 认证时应该如何使用 Kubernetes liveness 和 readiness 对服务进行健康检查?</h5><div class=answer><p>如果启用了双向 TLS 认证,则来自 kubelet 的 http 和 tcp 健康检查将不能正常工作,因为 kubelet 没有 Istio 颁发的证书。</p><p>从 Istio 1.0 开始,针对服务新增了 <a href=/v1.2/docs/tasks/security/mtls-migration><code>PERMISSIVE</code> 模式</a>
,因此当这个模式打开时他们可以接受 http 和双向 TLS 流量。这可以解决健康检查问题。
请记住,双向 TLS 没有强制执行,因为其他服务可以使用 http 流量与该服务进行通信。</p><p>您可以使用单独的端口进行健康检查,并只在常规服务端口上启用双向 TLS。请参阅 <a href=/v1.2/zh/docs/ops/setup/app-health-check/>Istio 服务的健康检查</a>了解更多信息。</p><p>由于存在新功能的风险,我们默认情况下不会启用上述功能。未来的推出计划将在 <a href=https://github.com/istio/istio/issues/10357>GitHub 问题</a>上进行跟踪。</p><p>为了降低风险,另一种解决方法是对健康检查使用 <a href=https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-a-liveness-command>liveness 命令</a>,例如,可以在服务 Pod 中安装 <code>curl</code> 并在 Pod 内对自身执行 <code>curl</code> 操作。</p><p>一个 readiness 探针的例子:</p><pre><code class=language-yaml data-expandlinks=true>livenessProbe:
exec:
command:
- curl
- -f
- http://localhost:8080/healthz # Replace port and URI by your actual health check
initialDelaySeconds: 10
periodSeconds: 5
</code></pre></div><h5 id=cert-lifetime-config class=question>如何配置 Istio 证书的有效期?</h5><div class=answer><p>对于在 Kubernetes 上运行的工作负载来说,它们的 Istio 证书有效期是受到 Citadel 的 <code>workload-cert-ttl</code> 标志控制的。缺省值是 90 天。这个值不能大于 Citadel 的 <code>max-workload-cert-ttl</code></p><p>Citadel 使用标志 <code>max-workload-cert-ttl</code> 对 Istio 签发给工作负载的证书的有效期进行控制。缺省值是 90 天。如果 Citadel 或者 Node agent 中的 <code>workload-cert-ttl</code> 大于 <code>max-workload-cert-ttl</code>Citadel 的证书签发就会失败。</p><p>可以对文件 <code>istio-demo-auth.yaml</code> 进行修改,从而对 Citadel 配置进行定制。下面的修改过程,让 Istio 为 Kubernetes 工作负载签发有效期为一小时的证书。并且 Istio 签发证书的最长有效期被设置为 48 小时。</p><pre><code class=language-plain data-expandlinks=true>...
kind: Deployment
...
metadata:
name: istio-citadel
namespace: istio-system
spec:
...
template:
...
spec:
...
containers:
- name: citadel
...
args:
- --workload-cert-ttl=1h # 签发给 Kubernetes 工作负载的证书的有效期。
- --max-workload-cert-ttl=48h # Citadel 签发给 Kubernetes 工作负载的证书的最大有效期。
</code></pre><p>对于运行于物理机或者虚拟机上的工作负载来说,他们的 Istio 证书有效期是由每个 Node agent 的 <code>workload-cert-ttl</code> 决定的。其缺省值同样也是 90 天,这个值也不允许超出 Citadel 的 <code>max-workload-cert-ttl</code> 选项的值。</p><p>要定制这一配置,要在完成<a href=/v1.2/zh/docs/setup/kubernetes/additional-setup/mesh-expansion/#setting-up-the-machines>设置虚拟机</a>步骤之后,对 Node agent 服务(<code>/lib/systemd/system/istio-auth-node-agent.service</code>)的参数进行修改。</p><pre><code class=language-plain data-expandlinks=true>...
[Service]
ExecStart=/usr/local/bin/node_agent --workload-cert-ttl=24h # 设置本机的证书有效时间。
Restart=always
StartLimitInterval=0
RestartSec=10
...
</code></pre><p>上面的配置中要求 Istio 为虚拟机或物理机上运行的工作负载签发 24 小时有效期的证书。完成服务配置之后,需要重新启动 Node agent 服务。</p></div><h5 id=does-istio-support-authorization class=question>Istio 是否支持授权和鉴权?</h5><div class=answer><p>是的。 Istio 为网格中的 HTTP 和普通 TCP 服务提供授权功能。
<a href=/v1.2/zh/docs/concepts/security/#授权>了解更多</a></p></div><h5 id=use-k8s-secrets class=question>Istio 权限认证是否使用了 Kubernetes secrets?</h5><div class=answer><p>是的。Istio 权限认证中密钥和证书的分发是基于 <a href=https://kubernetes.io/docs/concepts/configuration/secret/>Kubernetes secrets</a></p><p>Secrets 有已知的 <a href=https://kubernetes.io/docs/concepts/configuration/secret/#risks>安全风险</a>。Kubernetes 团队正在开发 <a href=https://docs.google.com/document/d/1T2y-9geg9EfHHtCDYTXptCa-F4kQ0RyiH-c_M1SyD0s>几个功能特性</a> 来提高 Kubernetes secret 的安全性,从 secret 的加密到节点级别的访问控制。并且 Kubernetes 从 1.6 版本引入了 <a href=https://kubernetes.io/docs/reference/access-authn-authz/rbac/>RBAC authorization</a> ,提供了细力度的 secrets 管理。</p></div><h5 id=secret-encryption class=question>工作负载中的密钥和证书是加密存储的么?</h5><div class=answer><p>缺省情况下,这些数据会进行 Base64 编码,但是并没有加密。然而 Kubernetes 中的 <a href=https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/>Secret 资源加密功能</a>是可以用来进行加密的。</p><p>注意 Google 容器引擎GKE中这一功能还未启用。因此 Master 节点上运行 ETCD 中的数据可能未被加密,而 Master 节点自身是加密的,请阅读 <a href=https://cloud.google.com/security/encryption-at-rest/default-encryption/#encryption_of_data_at_rest>GKE 相关文档</a>了解更多相关细节。</p></div><h5 id=secure-ingress class=question>Istio 中如何配置 Ingress 令其仅接受 TLS 连接?</h5><div class=answer><p>依照<a href=/v1.2/zh/docs/tasks/traffic-management/secure-ingress>用 HTTPS 加密 Gateway</a> 任务中的陈述进行配置,能够让 Istio Ingress 只接受 TLS 流量。</p></div><h5 id=https-overlay class=question>我可以为 HTTPS 服务安装 Istio sidecar 吗?</h5><div class=answer><p>是的,你可以这么做。它可以在启用和禁用双向 TLS 的情况下工作。更多详细信息,请参阅<a href=/v1.2/zh/docs/tasks/security/https-overlay/>双向 TLS 如何与 HTTPS 服务配合使用</a></p></div></div></article><nav class=pagenav><div class=left><a title="安装 Q &amp; A。" href=/v1.2/zh/faq/setup/><svg class="icon"><use xlink:href="/v1.2/img/icons.svg#left-arrow"/></svg>安装</a></div><div class=right><a title="Mixer Q &amp; A。" href=/v1.2/zh/faq/mixer/>Mixer<svg class="icon"><use xlink:href="/v1.2/img/icons.svg#right-arrow"/></svg></a></div></nav><div id=endnotes-container aria-hidden=true><h2>链接</h2><ol id=endnotes></ol></div></div></main><footer><div class=user-links><a class=channel title="Go download Istio 1.2.5 now" href=https://github.com/istio/istio/releases/tag/1.2.5 aria-label="Download Istio"><span>download</span><svg class="icon"><use xlink:href="/v1.2/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.2/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.2/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.2/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.2/img/icons.svg#twitter"/></svg></a><div class=tag>对于用户</div></div><div class=info><p class=copyright>中文内容由 ServiceMesher 社区维护,部分文档可能稍微滞后于英文版本,同步工作持续进行中<br>Istio 归档
1.2.5<br>&copy; 2019 Istio Authors, <a href=https://policies.google.com/privacy>隐私政策</a><br>归档于 2019年9月12日</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.2/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.2/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.2/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.2/img/icons.svg#top"/></svg></button></div></body></html>