简体   繁体   English

了解 kubernetes Pod 的 Istio AuthN 和 authz

[英]Understanding Istio AuthN and authz for kubernetes Pods

I am bit confused about using Istio with EKS.我对将 Istio 与 EKS 结合使用感到有些困惑。 We have 2 spring boot microservices, one is a REST service provider and the other the consumer.我们有 2 个 spring boot 微服务,一个是 REST 服务提供者,另一个是消费者。 We want to implement Authn and authz using Istio.我们想使用 Istio 实现 Authn 和 authz。

FOr that: 1. On provider service side : I have the a VirtualService, a Destination Rule (stating that the TLS mode should be ISTIO_MUTUAL for incoming traffic) , an AuthorizationPolicy which basically whitelists the client serviceaccounts.为此: 1. 在提供者服务方面:我有一个 VirtualService,一个目标规则(声明 TLS 模式应该是 ISTIO_MUTUAL 传入流量),一个 AuthorizationPolicy 基本上将客户端服务帐户列入白名单。 I also have a AuthenticationPolicy as below:我还有一个 AuthenticationPolicy 如下:

apiVersion: "authentication.istio.io/v1alpha1"
kind: "Policy"
metadata:
  name: $APP_NAME-$FEATURE_NAME-authenticationpolicy
  namespace: $NAME_SPACE
spec:
  targets:
  - name: "$APP_NAME-$FEATURE_NAME"
  peers:
  - mtls:
      mode: STRICT

My understanding here is that this policy wont allow any incoming traffic which is non mtls.我的理解是,此策略不允许任何非 mtls 的传入流量。

Now I have a doubt that how do I configure my client pod to send all mtls outgoing traffic.I understand I have to create a ServiceAccount which is whitelisted at the provider side using Authz Policy.I am more concerned about my client pod here since I am not sure how to enable mtls at the pod level.现在我怀疑如何配置我的客户端 pod 以发送所有 mtls 传出流量。我知道我必须创建一个 ServiceAccount,它使用 Authz 策略在提供商端列入白名单。我更关心我的客户端 pod,因为我在这里我不确定如何在 pod 级别启用 mtls。 FYI, I dont want to enable mtls at the namespace level.I want to do it at the pod level using a yaml file.仅供参考,我不想在命名空间级别启用 mtls。我想使用 yaml 文件在 pod 级别执行此操作。

Is my understanding about the usage of the Destination rule, Authn and Authz policies correct?我对 Destination 规则、Authn 和 Authz 策略用法的理解是否正确? Is it correct that Destination rule, Authn and Authz policies have to be at the service provider level? Destination 规则、Authn 和 Authz 策略必须在服务提供商级别是否正确? And the client just has to enable MTLS for the communication to work successfully?客户端只需要启用 MTLS 即可成功进行通信? I have been go thru Istio documentation but this is where I have a doubt我一直在浏览 Istio 文档,但这是我有疑问的地方

My understanding here is that this policy wont allow any incoming traffic which is non mtls.我的理解是,此策略不允许任何非 mtls 的传入流量。

That's true, if you set the tls mode to strict then client cert must be presented, connection is in TLS.确实如此,如果您将 tls 模式设置为严格,则必须提供客户端证书,连接在 TLS 中。


I am more concerned about my client pod here since I am not sure how to enable mtls at the pod level.我更关心我的客户端 pod,因为我不确定如何在 pod 级别启用 mtls。

There is good article about how to make that work, specially the part一篇关于如何使其工作的好文章,特别是部分

Setting up mTLS for a single connection between two services为两个服务之间的单个连接设置 mTLS

As Bookinfo is the Hello World of Istio, I am going to use this to explain how to set up mTLS from productpage to details service as shown in the above graph snippet.由于 Bookinfo 是 Istio 的 Hello World,我将使用它来解释如何设置从产品页面到详细信息服务的 mTLS,如上图所示。

There are two parts to this:这有两个部分:

Install a Policy to tell Details that it wants to receive TLS traffic (only):安装一个 Policy 来告诉 Details 它想要接收 TLS 流量(仅限):

apiVersion: authentication.istio.io/v1alpha1
kind: Policy
metadata:
  name: details-receive-tls
spec:
  targets:
  - name: details
  peers:
  - mtls: {}
  1. Install a DestinationRule to tell clients (productpage) to talk TLS with details:安装 DestinationRule 以告诉客户端(productpage)与详细信息交谈 TLS:
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: details-istio-mtls
spec:
  host: details.bookinfo.svc.cluster.local
  trafficPolicy:
    tls:
      mode: ISTIO_MUTUAL

The following is a graphical representation of the involved services and where the previous two configuration documents apply.以下是所涉及服务的图形表示以及前两个配置文档的适用位置。

在此处输入图片说明

Now when you look closely at the Policy above you will see and entry for the peer authentication现在,当您仔细查看上面的策略时,您将看到对等身份验证的条目

peers:
- mtls: {}

This means that TLS verification is strict and Istio (or rather the Envoy proxy in the pod) requires TLS traffic and a valid certificate.这意味着 TLS 验证是严格的,并且 Istio(或者更确切地说是 Pod 中的 Envoy 代理)需要 TLS 流量和有效的证书。 We can pass a flag to get permissive mode:我们可以通过一个标志来获得许可模式:

peers:
- mtls: 
    mode: PERMISSIVE

Is it correct that Destination rule, Authn and Authz policies have to be at the service provider level? Destination 规则、Authn 和 Authz 策略必须在服务提供商级别是否正确?

As far as I know yes.据我所知是的。

And the client just has to enable MTLS for the communication to work successfully?客户端只需要启用 MTLS 即可成功进行通信?

I'm not sure about that, since MTLS works inside mesh, it depends on your application requirements.我不确定,因为 MTLS 在网格内工作,这取决于您的应用程序要求。


I want to do it at the pod level using a yaml file.我想使用 yaml 文件在 pod 级别执行此操作。

There is a link to istio documentation about authentication which include有一个指向有关身份验证的istio 文档的链接,其中包括

And another one from github另一个来自 github

Or you can extend your gateway's definition to support mutual TLS.或者您可以扩展网关的定义以支持双向 TLS。 Change the credentials of the ingress gateway by deleting its secret and creating a new one.通过删除其机密并创建新的机密来更改入口网关的凭据。 The server uses the CA certificate to verify its clients, and we must use the name cacert to hold the CA certificate.服务器使用 CA 证书来验证其客户端,我们必须使用名称 cacert 来保存 CA 证书。 You can use cert-manager to generate a client certificate.您可以使用 cert-manager 生成客户端证书。


I have found some tutorials which might be helpful, check it out.我找到了一些可能有用的教程,请查看。


Let me know if you have any more questions.如果您还有其他问题,请告诉我。

Thanks JT97.This is what I have implemented谢谢 JT97。这是我实现的

1) For authentication, I have implemented an Istio STRICT authn policy for incoming requests that will have to be MTLS enabled. 1) 对于身份验证,我为必须启用 MTLS 的传入请求实施了 Istio STRICT 身份验证策略。 Citadel should take care of identifying the client and service provider whether they are who they claim to be based on thier certificates. Citadel 应该根据他们的证书来确定客户和服务提供商是否是他们声称的人。

2) For authorization, I have created a Service account in the client and added a authorization policy on the server side to whitelist only those service accounts that I want to use my REST resources( PUT POST etc) 2)对于授权,我在客户端创建了一个服务帐户,并在服务器端添加了一个授权策略,只将那些我想使用我的 REST 资源(PUT POST 等)的服务帐户列入白名单

3) The one thing I have configured differently is the destination rule. 3)我配置不同的一件事是目标规则。 Ideally it should be at the client side where the client says I am declaring that my destination rule for provider destination is this.What I have done is declared the destination rule at the provider side so that it's communicated to the Istio mesh that it is ready with ISTIO_MUTUAL.理想情况下,它应该在客户端说我声明我的目的地规则提供者目的地是这个的客户端。与 ISTIO_MUTUAL。 Declaring the destination rule at the provider side doesn't make any difference in my opinion.在我看来,在提供者端声明目的地规则没有任何区别。

4.) I have declared the destination rule at the namespace level.Have to test now for clients coming in from outside the namespace but within the mesh. 4.) 我已经在命名空间级别声明了目标规则。现在必须测试来自命名空间之外但在网格内的客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM