ISTIO:网格外旧服务的目标

发布于 2025-02-12 19:23:53 字数 1626 浏览 0 评论 0原文

我在istio-system名称空间中部署了一个K8S群集,默认情况下,在另一个名为mesh-apps的名称空间中启用了SIDECAR注入。我也有第二个旧版名称空间,其中包含某些执行自己TLS终止的应用程序。我正在尝试在mesh-apps名称空间中运行的服务与logacy内部运行的服务设置MTLS访问。

为此,我完成了以下操作:

  1. 网格应用中创建了一个秘密包含客户端证书,键和cacert的命名空间,用于通过MTLS与Legacy连接。

  2. 将它们安装在mesh-apps中的POD内部定义明确的位置(Sleep pod)。

  3. 部署了一个应用程序Legacy,并使用群集服务曝光了mymtls-app在端口8443中。

  4. Legacy中部署了一个应用程序,并使用port 8443上的mymtls-app在 命名空间,希望这可以使MTLS从MESH-APPS Legacy

    访问。

      ----
    apiversion:networking.istio.io/v1alpha3
    KINT:目标列
    元数据:
      名称:起源-MTL
    规格:
      主机:mymtls-app.legacy.svc.cluster.local
      交通质量:
        portlevelSettings:
        - 港口:
            编号:8443
          TLS:
            模式:相互
            clientcertificate:/etc/sleep/tls/server.cert
            privateKey:/etc/sleep/tls/server.key
            cacertificates:/etc/sleep/tls/ca.pem
            SNI:mymtls-app.legacy.svc.cluster.local
     

现在,当我从sleep pod中运行以下命令时,我本来可以期望以上destination rule生效:

kubectl exec sleep-37893-foobar -c sleep -- curl http://mymtls-app.legacy.svc.cluster.local:8443/hello

但是我只会得到错误:

Client sent an HTTP request to an HTTPS server.

如果我添加https在URL中,这是错误:

curl: (56) OpenSSL SSL_read: error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate, errno 0
command terminated with exit code 56

I have a k8s cluster with Istio deployed in the istio-system namespace, and sidecar injection enabled by default in another namespace called mesh-apps. I also have a second legacy namespace which contains certain applications that do their own TLS termination. I am trying to setup mTLS access between services running inside the mesh-apps namespace and those running inside legacy.

For this purpose, I have done the following:

  1. Created a secret in the mesh-apps namespace containing the client cert, key and CAcert to be used to connect with an application in legacy via mTLS.

  2. Mounted these at a well-defined location inside a pod (the sleep pod in Istio samples actually) running in mesh-apps.

  3. Deployed an app inside legacy and exposed it using a ClusterIP service called mymtls-app on port 8443.

  4. Created the following destination rule in the mesh-apps namespace, hoping that this enables mTLS access from mesh-apps to legacy.

    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: DestinationRule
    metadata:
      name: originate-mtls
    spec:
      host: mymtls-app.legacy.svc.cluster.local
      trafficPolicy:
        portLevelSettings:
        - port:
            number: 8443
          tls:
            mode: MUTUAL
            clientCertificate: /etc/sleep/tls/server.cert
            privateKey: /etc/sleep/tls/server.key
            caCertificates: /etc/sleep/tls/ca.pem
            sni: mymtls-app.legacy.svc.cluster.local
    

Now when I run the following command from inside the sleep pod, I would have expected the above DestinationRule to take effect:

kubectl exec sleep-37893-foobar -c sleep -- curl http://mymtls-app.legacy.svc.cluster.local:8443/hello

But instead I just get the error:

Client sent an HTTP request to an HTTPS server.

If I add https in the URL, then this is the error:

curl: (56) OpenSSL SSL_read: error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate, errno 0
command terminated with exit code 56

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情徒 2025-02-19 19:23:53

我想知道自己的错误。我需要正确安装证书,私钥和CA链,而不是在应用程序容器中。为了将它们安装在边路上,我执行了以下操作:

  1. 用证书,私钥和CA链创建了一个秘密。

      kubectl创建秘密通用睡眠秘密-N网格 - 应用\
      -from-file = server.key =/home/johndoe/certs_mtls/client.key \
      -from-file = server.cert =/home/johndoe/certs_mtls/client.crt \
      -from-file = ca.pem =/home/johndoe/certs_mtls/server_ca.pem
     
  2. 修改了睡眠容器的部署表现:

     模板:
        元数据:
          注释:
            sidecar.istio.io/uservolumemount:'[{“ name”:“ secret-volume”,“ mountpath”:“/etc/sleep/sleep/tls”,“ readonly”:true}]'
            sidecar.istio.io/uservolume:'[{“ name”:“ secret-volume”,“ secret”:{“ secretname”:“ sleep-secret”}}}''''
     

实际上我已经较早地创建了秘密,但是它已安装在应用程序容器中(sleep),而不是SideCar,以此方式:

spec:
  volumes:
  - name: <secret_volume_name>
    secret:
      secretName: <secret_name>
      optional: true
  containers:
  - name: ...
    volumeMounts:
    - mountPath: ...
      name: <secret_volume_name>

I figured my own mistake. I needed to correctly mount the certificate, private key, and CA chain in the sidecar, not in the app container. In order to mount them in the sidecar, I performed the following actions:

  1. Created a secret with the cert, private key and CA chain.

    kubectl create secret generic sleep-secret -n mesh-apps \
      --from-file=server.key=/home/johndoe/certs_mtls/client.key \
      --from-file=server.cert=/home/johndoe/certs_mtls/client.crt \
      --from-file=ca.pem=/home/johndoe/certs_mtls/server_ca.pem
    
  2. Modified the deployment manifest for the sleep container thus:

      template:
        metadata:
          annotations:
            sidecar.istio.io/userVolumeMount: '[{"name": "secret-volume", "mountPath": "/etc/sleep/tls", "readonly": true}]'
            sidecar.istio.io/userVolume: '[{"name": "secret-volume", "secret": {"secretName": "sleep-secret"}}]'
    

Actually I had already created the secret earlier, but it was mounted in the app container (sleep) instead of the sidecar, in this way:

spec:
  volumes:
  - name: <secret_volume_name>
    secret:
      secretName: <secret_name>
      optional: true
  containers:
  - name: ...
    volumeMounts:
    - mountPath: ...
      name: <secret_volume_name>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文