简体   繁体   English

Lets-encrypt Ingress - NewOrder 请求没有包含足够短的 SAN 以适应 CN

[英]Lets-encrypt Ingress - NewOrder request did not include a SAN short enough to fit in CN

We have an EKS cluster in AWS.我们在 AWS 中有一个 EKS 集群。 After pointing to our eks cluster using following command,使用以下命令指向我们的 eks 集群后,

aws eks --region us-east-1 update-kubeconfig --name cluster-name . aws eks --region us-east-1 update-kubeconfig --name cluster-name

Then we deployed nginx for that cluster using following shell script.然后我们使用以下 shell 脚本为该集群部署了 nginx。

file: 1_cert_manager.sh

###Nginx
# This script install nginx and cert manager using helm install..

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install nginx-ingress ingress-nginx/ingress-nginx \
    --set controller.replicaCount=2 \
    --set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \
    --set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux

sleep 60
kubectl get service nginx-ingress-ingress-nginx-controller


###########
#Cert-manager
##########


# Label the cert-manager namespace to disable resource validation
kubectl label  cert-manager.io/disable-validation=true

# Add the Jetstack Helm repository
helm repo add jetstack https://charts.jetstack.io

# Update your local Helm chart repository cache
helm repo update

# Install the cert-manager Helm chart
helm install \
  cert-manager \
  --version v0.16.1 \
  --set installCRDs=true \
  --set nodeSelector."beta\.kubernetes\.io/os"=linux \
  jetstack/cert-manager

We ran the above script using我们使用运行上述脚本

chmod +x ./1_cert_manager.sh

sh ./1_cert_manager.sh

After installing nginx, we could see the nginx home page when we hit the DNS provided in the AWS load balancer.安装 nginx 后,我们可以在访问 AWS 负载均衡器中提供的 DNS 时看到 nginx 主页。

kubectl get services gave the DNS address of the load balancer. kubectl get services了负载均衡器的 DNS 地址。

The page is loaded with http.该页面使用 http 加载。 To enable support for https, we installed cert manager.为了启用对 https 的支持,我们安装了证书管理器。

We have installed letsencrypt-issuer ClusterIssuer.我们已经安装了letsencrypt-issuer ClusterIssuer。

File: 2_cluster-issuer.yaml

apiVersion: cert-manager.io/v1alpha2
kind: ClusterIssuer
metadata:
  name: letsencrypt-issuer
spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: mailid@gmail.com
    privateKeySecretRef:
      name: letsencrypt-issuer
    solvers:
    - http01:
        ingress:
          class: nginx
          podTemplate:
            spec:
              nodeSelector:
                "kubernetes.io/os": linux

We have installed Cluster issuer using following command.我们已经使用以下命令安装了 Cluster issuer。

kubectl apply -f 2_cluster-issuer.yaml

Then we installed a sample hello world service.然后我们安装了一个示例 hello world 服务。

file:3_service.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: console
spec:
  selector:
    matchLabels:
      app: console
      tier: console
      track: stable
  replicas: 1
  template:
    metadata:
      labels:
        app: console
        tier: console
        track: stable
    spec:
      containers:
        - name: console
          image: "gcr.io/google-samples/hello-go-gke:1.0"
          ports:
            - name: http
              containerPort: 80
---
---
apiVersion: v1
kind: Service
metadata:
  name: console
spec:
  selector:
    app: console
    tier: console
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

kubectl apply -f 3_service.yaml

We have 2-3 services which will run on different ports.我们有 2-3 个服务将在不同的端口上运行。 For testing purpose, we have installed only one service.出于测试目的,我们只安装了一项服务。

The service is installed successfully which we have verified using kubectl get pods and kubectl get services .该服务已成功安装,我们已使用kubectl get podskubectl get services进行了验证。

Then finally we deployed ingress yaml file to provide host detail and routing information.最后我们部署了入口 yaml 文件来提供主机详细信息和路由信息。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nandha-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/use-regex: "true"
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt-issuer
    nginx.ingress.kubernetes.io/cors-allow-headers: "Content-Type"
    nginx.ingress.kubernetes.io/cors-allow-methods: "GET, POST, PUT, DELETE, OPTIONS"
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    nginx.ingress.kubernetes.io/client-body-buffer-size: "16m"
    nginx.ingress.kubernetes.io/proxy-body-size: "16m"
    nginx.ingress.kubernetes.io/enable-modsecurity: "true"
spec:
  tls:
      - hosts:
        - a2e858295f1201234aab29d960a10bfa-41041144.us-east-1.elb.amazonaws.com
        secretName: tls-secret
  rules:
    - host: a2e858295f1201234aab29d960a10bfa-41041144.us-east-1.elb.amazonaws.com
      http:
        paths:
          - pathType: Prefix
            backend:
              service:
                name: console
                port:
                  number: 80
            path: /(.*)

kubectl apply -f 4_ingress.yaml

If the previous command executed successully we should have our tls-secret certificate ready.如果前面的命令成功执行,我们应该准备好我们的 tls-secret 证书。 (For GCP, it worked correctly). (对于 GCP,它工作正常)。

We debugged using我们调试使用

kubectl get certificates

kubectl describe certificates tls-secret

For the describe command we got the following error,对于 describe 命令,我们收到以下错误,

Failed to create Order: 400 urn:ietf:params:acme:error:rejectedIdentifier: NewOrder request did not include a SAN short enough to fit in CN无法创建订单:400 urn:ietf:params:acme:error:rejectedIdentifier:NewOrder 请求未包含足够短的 SAN 以适合 CN

When we searched about the error, we found that issue comes due to length of the DNS.当我们搜索错误时,我们发现问题出在 DNS 的长度上。 Length of AWS DNS is greater than 64. AWS DNS 的长度大于 64。

Current work around: We have created a CNAME mapping for the AWS DNS url and we have used that short mapped url in the 4th step instead of actual url.当前解决方法:我们为 AWS DNS url 创建了一个 CNAME 映射,我们在第 4 步中使用了该短映射 url,而不是实际 url。 This works as of now.到目前为止,这有效。 But we need to enable SSL for actual DNS also.但是我们还需要为实际的 DNS 启用 SSL。

How to enable SSL for AWS DNS value?如何为 AWS DNS 值启用 SSL?

This (a2e858295f1201234aab29d960a10bfa-41041144.us-east-1.elb.amazonaws.com) was our host when we had our EKS up.当我们启动 EKS 时,这 (a2e858295f1201234aab29d960a10bfa-41041144.us-east-1.elb.amazonaws.com) 是我们的主机。 Currently our EKS is terminated.目前我们的 EKS 已终止。

"Length of AWS DNS is greater than 64." “AWS DNS 的长度大于 64。”

No that is not the problem.不,这不是问题。 Each DNS label is restricted to 63 characters (bytes in fact) at most, and your first label is 42 long so it is fine.每个 DNS 标签最多限制为 63 个字符(实际上是字节),而您的第一个标签长度为 42,所以没问题。 The other rule is the full name must be at most 255 characters/bytes, but in practice 253. Which is also ok for your name.另一条规则是全名最多只能包含 255 个字符/字节,但实际上是 253。这对您的名字也可以。

The problem is elsewhere, as the LDAP/X520/certificate reference says the full CN must be less than 64 but it is unrelated to DNS (the CN was at the beginning typically individual or organization names, it just got hijacked later to put DNS names there, until the SAN extension got written, and which is now the default, the Subject for a DV-certificate is really not relevant anymore, and in part because of those limitations; names aka dnsName in SAN are defined to have a maximum left to the implementation but also defined to be valid domain names so in practice the rule above of 63 per label/255 total applies).问题出在其他地方,因为 LDAP/X520/certificate 参考说完整的 CN 必须小于 64,但它与 DNS 无关(CN 一开始通常是个人或组织名称,后来被劫持以放置 DNS 名称在那里,直到 SAN 扩展被写入(现在是默认设置),DV 证书的主题实际上不再相关,部分原因是这些限制;SAN 中的名称又名 dnsName 被定义为有一个最大值实现,但也定义为有效域名,因此在实践中,上述规则适用于每个标签 63/255 个总数)。

This is from where your problem comes.这就是您的问题所在。

Modern host based certificates only need a proper SAN, the CN is irrelevant to browsers now.现代基于主机的证书只需要一个适当的 SAN,CN 现在与浏览器无关。 So you need to generate your certificate with all good data in the SAN but another fake thing in the CN.因此,您需要在 SAN 中生成包含所有良好数据的证书,但在 CN 中生成另一个虚假数据。 Which seems to be what you did, but not sure to understand.这似乎是您所做的,但不确定是否理解。 The certificate is valid for all names in the SAN.该证书对 SAN 中的所有名称都有效。

See https://community.letsencrypt.org/t/a-certificate-for-a-63-character-domain/78870/6 for ideas.有关想法,请参阅https://community.letsencrypt.org/t/a-certificate-for-a-63-character-domain/78870/6 Basically add another name as first name, which is smaller and which you control too, to be able to get the validation to issue the certificate.基本上添加另一个名称作为名字,它更小并且您也可以控制,以便能够获得验证以颁发证书。

The real solution is just to get rid of the CN by CAs, as explained on https://github.com/letsencrypt/boulder/issues/2093 but this seems blocked by other standardization efforts elsewhere.正如https://github.com/letsencrypt/boulder/issues/2093所解释的那样,真正的解决方案只是让 CA 摆脱 CN,但这似乎被其他地方的其他标准化工作所阻止。

In the meantime, you should also ask your cloud provider for help on this.同时,您还应该向您的云提供商寻求帮助。

When checked with cloud support team, we got the following response.在与云支持团队核实后,我们得到了以下回复。 They suggested to create custom domain mapping and suggested to use it which we already doing.他们建议创建自定义域映射并建议使用我们已经在做的。

DNS is generated by combining load balancer name + random string + region + 'elb.amazonaws.com' . DNS 是通过组合load balancer name + random string + region + 'elb.amazonaws.com'

If we are able to give custom name for load balancer from helm installation means, we can solve our problem.如果我们能够从 helm 安装方式为负载均衡器提供自定义名称,我们就可以解决我们的问题。 Currently we are trying to do this step.目前我们正在尝试执行此步骤。

Attached the cloud support team's response.附上云支持团队的回复。

In compliance with RFC 5280 ( https://datatracker.ietf.org/doc/html/rfc5280 ), the length of the domain name (technically, the Common Name) that you enter in this step cannot exceed 64 octets (characters), including periods.根据 RFC 5280 ( https://datatracker.ietf.org/doc/html/rfc5280 ),您在此步骤中输入的域名(技术上是通用名称)的长度不能超过 64 个八位字节(字符),包括时期。 Each subsequent Subject Alternative Name (SAN) that you provide, as in the next step, can be up to 253 octets in length.您在下一步中提供的每个后续主题备用名称 (SAN) 的长度最多可达 253 个八位字节。

You are encountering this error as your host name ( a2e858295f1204618aab29d960a10bfa-41041143.us-east-1.elb.amazonaws.com ( http://a2e858295f1204618aab29d960a10bfa-41041143.us-east-1.elb.amazonaws.com/ ) ) is more than 64 characters.您遇到此错误,因为您的主机名 (a2e858295f1204618aab29d960a10bfa-41041143.us-east-1.elb.amazonaws.com ( http://a2e858295f1204618aab29d960a10bfa-41041143.us-east-1.elb.amazonaws.com/ ) is more)超过 64 个字符。

As to overcome this problem we can configure a custom domain name for your Load Balancer.为了克服这个问题,我们可以为您的负载均衡器配置一个自定义域名。 Each Classic Load Balancer receives a default Domain Name System (DNS) name.每个 Classic Load Balancer 都会收到一个默认域名系统 (DNS) 名称。 This DNS name includes the name of the AWS Region in which the load balancer is created.此 DNS 名称包括创建负载均衡器的 AWS 区域的名称。 For example, if you create a load balancer named my-loadbalancer in the US West (Oregon) Region, your load balancer receives a DNS name such as my-loadbalancer-1234567890.us-west-2.elb.amazonaws.com.例如,如果您在美国西部(俄勒冈)区域创建名为 my-loadbalancer 的负载均衡器,您的负载均衡器会收到一个 DNS 名称,例如 my-loadbalancer-1234567890.us-west-2.elb.amazonaws.com。

To access the website on your instances, you paste this DNS name into the address field of a web browser.要访问您的实例上的网站,请将此 DNS 名称粘贴到 Web 浏览器的地址字段中。 In our case this DNS is has more characters than the limit that is 64. If you'd prefer to use a friendly DNS name for your load balancer, such as www.example.com , instead of the default DNS name, you can create a custom domain name and associate it with the DNS name for your load balancer.在我们的示例中,此 DNS 的字符数超过了 64 的限制。如果您希望为负载均衡器使用友好的 DNS 名称,例如www.example.com ,而不是默认的 DNS 名称,您可以创建自定义域名并将其与负载均衡器的 DNS 名称相关联。 When a client makes a request using this custom domain name, the DNS server resolves it to the DNS name for your load balancer.当客户端使用此自定义域名发出请求时,DNS 服务器会将其解析为负载均衡器的 DNS 名称。 Then we can use this custom domain in the place of our host name while configuring the ingress file.然后我们可以在配置入口文件时使用这个自定义域来代替我们的主机名。

This workaround can be applied to achieve your use case.可以应用此解决方法来实现您的用例。 To associate your custom domain name with your load balancer name you have to register your domain name.要将您的自定义域名与您的负载均衡器名称相关联,您必须注册您的域名。 The Internet Corporation for Assigned Names and Numbers (ICANN) manages domain names on the internet.互联网名称与数字地址分配机构 (ICANN) 管理互联网上的域名。 You register a domain name using a domain name registrar, an ICANN-accredited organization that manages the registry of domain names.您使用域名注册商注册域名,该注册商是 ICANN 认可的管理域名注册的组织。 The website for your registrar will provide detailed instructions and pricing information for registering your domain name.您的注册商的网站将提供有关注册域名的详细说明和定价信息。

Next, use your DNS service, such as your domain registrar, to create a CNAME record to route queries to your load balancer.接下来,使用您的 DNS 服务(例如您的域名注册商)创建 CNAME 记录以将查询路由到您的负载均衡器。

Alternatively, you can use Route 53 as your DNS service.或者,您可以使用 Route 53 作为您的 DNS 服务。 You create a hosted zone, which contains information about how to route traffic on the internet for your domain, and an alias resource record set, which routes queries for your domain name to your load balancer.您创建一个托管区域,其中包含有关如何在 Internet 上为您的域路由流量的信息,以及一个别名资源记录集,它将对您的域名的查询路由到您的负载均衡器。 Route 53 doesn't charge for DNS queries for alias record sets, and you can use alias record sets to route DNS queries to your load balancer for the zone apex of your domain (for example, example.com). Route 53 不对别名记录集的 DNS 查询收费,您可以使用别名记录集将 DNS 查询路由到您的域顶点(例如,example.com)的负载均衡器。 For information about transferring DNS services for existing domains to Route 53, see Configuring Route 53 as your DNS service ( https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/dns-configuring.html ) in the Amazon Route 53 Developer Guide.有关将现有域的 DNS 服务转移到 Route 53 的信息,请参阅在 Amazon Route 中将 Route 53 配置为您的 DNS 服务 ( https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/dns-configuring.html ) 53 开发人员指南。

[#] https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/using-domain-names-with-elb.html [#] https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/using-domain-names-with-elb.html

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

相关问题 我可以使用 aws 的 ssl 而不是让地址(ip)本身加密吗? - Can I use ssl from aws instead of lets-encrypt for the address (ip) itself? 如何将 Let encrypt 添加到在 Elastic Beanstalk 上运行的多容器中 - How to add lets encrypt to a multi container running on Elastic Beanstalk 让我们在AWS Lightsail中的bitnami.conf中加密SSL设置 - Lets Encrypt SSL setup in bitnami.conf in AWS Lightsail haxe(php)https call:stream_socket_client()对等证书CN与预期的CN不匹配 - haxe (php) https call: stream_socket_client() Peer certificate CN did not match expected CN 无法执行HTTP请求:ec2.cn-north-1.amazonaws.com.cn无法响应 - Unable to execute HTTP request: ec2.cn-north-1.amazonaws.com.cn failed to respond 向Amazon KMS发送加密请求时访问被拒绝 - AccessDenied when sending Encrypt request to Amazon KMS 盐请求超时-奴才没有回来 - Salt request timed out - Minion did not return kubernetes 入口控制器`400 错误请求 - 普通 HTTP 请求发送到 HTTPS 端口` - kubernetes ingress-controller `400 Bad request - plain HTTP request sent to HTTPS port` 如何拒绝在短时间内发送两次相同的 POST 请求 - How to reject the same POST request sent twice in a short gap of time 为什么我的现货申请被自动取消了? - Why did my spot request get cancelled automatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM