如何在Kubernetes中使用搜索域

时间:2018-10-10 03:24:32

标签: ssl kubernetes tls1.2

我在foo.example.com上有一个在Kubernetes(GKE)上运行的应用程序部署。入口定义如下:

 spec:
  tls:
  - hosts:
    - "foo.example.com"
    secretName: foo-example-com
  rules:
  - host: "foo.example.com"
    http:
      paths:
      - path: /*
        backend:
          serviceName: web
          servicePort: 80

当我导航到http://foo.example.com/时,我(正确)被重定向到https://foo.example.com/并具有适当的证书。

但是,我的搜索域中有example.com。因此,ping foo可以正确解析为Kubernetes入口。

但是当我在浏览器中转到https://foo/时,在Chrome中收到以下错误消息:

Your connection is not private
Attackers might be trying to steal your information from foo (for example, passwords, messages, or credit cards). Learn more
NET::ERR_CERT_AUTHORITY_INVALID
Subject: Kubernetes Ingress Controller Fake Certificate
Issuer: Kubernetes Ingress Controller Fake Certificate
Expires on: Oct 1, 2019
Current date: Oct 9, 2018

您将如何工作?

很明显,如果没有一些我不会尝试的自签名黑客,我将无法获得foo的证书。

2 个答案:

答案 0 :(得分:0)

即使在Kubernetes之外,此方法也一样。 首先,每个网络浏览器(包括Chrome浏览器)都开箱即用提供了一个权限列表: enter image description here

,依此类推。

您的CA证书(在您的机密中)是由您自己的证书颁发机构自签名的,该证书颁发机构不受Chrome信任,因此您会看到此错误。您可能可以将CA导入Chrome,而您的Chrome实例将信任它,但是... 如您所知,通常为特定域或通配符(CN)颁发的TLS(SSL)证书,因此foo可能与证书的通配符表达式不匹配,并且您还会看到另一个SSL错误:{{1} }。 因此,您将必须使用重写规则才能使其正常工作。

答案 1 :(得分:0)

所以我解决此问题的方法是添加重定向入口:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: redirect-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: "false"
    ingress.kubernetes.io/configuration-snippet: |
      if ($host ~ ^foo$) {
        return 301 https://foo.example.com$request_uri;
      }
spec:
  rules:
  - host: "foo"
    http:
      paths:
      - backend:
          serviceName: web
          servicePort: 80

我不确定它是否是最佳选择,但它确实起作用。