繁体   English   中英

当客户端使用不安全时,为什么入口 nginx 无法代理 grpc?

[英]why ingress nginx cannot proxy grpc when client using insecure?

路径: go-client --> ingress-nginx --> grpc pod

因为所有流量都在我们的私有网络中,所以我们没有购买公共证书,而是使用自签名证书。 发生的事情是下面的第一个代码运行良好,但第二个代码失败了。 我不知道为什么,我想知道insecure的确切含义。

运行良好的代码:

    cert, _ := credentials.NewClientTLSFromFile("./example.pem", "example.com")
    conn, err := grpc.DialContext(
        ctx,
        "example.com:443",
        grpc.WithTransportCredentials(cert),
        grpc.WithBlock(),
    )

收到 400 错误请求的代码

    conn, err := grpc.DialContext(
        ctx,
        "example.com:443",
        grpc.WithTransportCredentials(insecure.NewCredentials()),
        grpc.WithBlock(),
    )

错误请求的 nginx 访问日志

"PRI * HTTP/2.0" 400

入口yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
spec:
  ingressClassName: nginx
  tls:
  - hosts: example.com
    secretName: example-tls
  rules:
  - host: example.com
    http:
      paths:
      - path: /foo/bar
        pathType: Prefix
        backend:
          service: grpc-svc
          port:
            name: grpc-port

insecure提供了一个禁用传输安全性的credentials.TransportCredentials接口的实现。 更具体地说,它不执行任何 TLS 握手或使用任何证书。

gRPC 要求用户在尝试创建ClientConn时向其传递一些凭据。 如果您的部署不使用任何证书并且您知道它是安全的(基于任何原因),那么insecure的包将是您的朋友。 但是,如果您使用的是自签名证书,它们仍然是证书,并且需要在此处进行 TLS 握手。 因此,在这种情况下,您应该继续使用您在问题顶部提到的代码。 希望这可以帮助。

暂无
暂无

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

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