You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
7.0 KiB

  1. # Installation Guide
  2. - [Installation Guide](#installation-guide)
  3. - [Kubernetes TLS Root CA Certificate/Key Secret](#kubernetes-tls-root-ca-certificatekey-secret)
  4. - [Securing Ingress Resources](#securing-ingress-resources)
  5. - [Create New TLS Root CA Certificate and Key](#create-new-tls-root-ca-certificate-and-key)
  6. - [Install Cloudflare PKI/TLS `cfssl` Toolkit.](#install-cloudflare-pkitls-cfssl-toolkit)
  7. - [Create Root Certificate Authority (CA) Configuration File](#create-root-certificate-authority-ca-configuration-file)
  8. - [Create Certficate Signing Request (CSR) Configuration File](#create-certficate-signing-request-csr-configuration-file)
  9. - [Create TLS Root CA Certificate and Key](#create-tls-root-ca-certificate-and-key)
  10. Cert-Manager is a native Kubernetes certificate management controller. It can help with issuing certificates from a variety of sources, such as Let’s Encrypt, HashiCorp Vault, Venafi, a simple signing key pair, or self signed. It will ensure certificates are valid and up to date, and attempt to renew certificates at a configured time before expiry.
  11. The Kubespray out-of-the-box cert-manager deployment uses a TLS Root CA certificate and key stored as the Kubernetes `ca-key-pair` secret consisting of `tls.crt` and `tls.key`, which are the base64 encode values of the TLS Root CA certificate and key respectively.
  12. Integration with other PKI/Certificate management solutions, such as HashiCorp Vault will require some further development changes to the current cert-manager deployment and may be introduced in the future.
  13. ## Kubernetes TLS Root CA Certificate/Key Secret
  14. If you're planning to secure your ingress resources using TLS client certificates, you'll need to create and deploy the Kubernetes `ca-key-pair` secret consisting of the Root CA certificate and key to your K8s cluster.
  15. If these are already available, simply update `templates\secret-cert-manager.yml.j2` with the base64 encoded values of your TLS Root CA certificate and key prior to enabling and deploying cert-manager.
  16. e.g.
  17. ```shell
  18. $ cat ca.pem | base64 -w 0
  19. LS0tLS1CRUdJTiBDRVJU...
  20. $ cat ca-key.pem | base64 -w 0
  21. LS0tLS1CRUdJTiBSU0Eg...
  22. ```
  23. For further information, read the official [Cert-Manager CA Configuration](https://cert-manager.io/docs/configuration/ca/) doc.
  24. Once the base64 encoded values have been added to `templates\secret-cert-manager.yml.j2`, cert-manager can now be enabled by editing your K8s cluster addons inventory e.g. `inventory\sample\group_vars\k8s_cluster\addons.yml` and setting `cert_manager_enabled` to true.
  25. ```ini
  26. # Cert manager deployment
  27. cert_manager_enabled: true
  28. ```
  29. If you don't have a TLS Root CA certificate and key available, you can create these by following the steps outlined in section [Create New TLS Root CA Certificate and Key](#create-new-tls-root-ca-certificate-and-key) using the Cloudflare PKI/TLS `cfssl` toolkit. TLS Root CA certificates and keys can also be created using `ssh-keygen` and OpenSSL, if `cfssl` is not available.
  30. ## Securing Ingress Resources
  31. A common use-case for cert-manager is requesting TLS signed certificates to secure your ingress resources. This can be done by simply adding annotations to your Ingress resources and cert-manager will facilitate creating the Certificate resource for you. A small sub-component of cert-manager, ingress-shim, is responsible for this.
  32. To enable the Nginx Ingress controller as part of your Kubespray deployment, simply edit your K8s cluster addons inventory e.g. `inventory\sample\group_vars\k8s_cluster\addons.yml` and set `ingress_nginx_enabled` to true.
  33. ```ini
  34. # Nginx ingress controller deployment
  35. ingress_nginx_enabled: true
  36. ```
  37. For example, if you're using the Nginx ingress controller, you can secure the Prometheus ingress by adding the annotation `cert-manager.io/cluster-issuer: ca-issuer` and the `spec.tls` section to the `Ingress` resource definition.
  38. ```yaml
  39. apiVersion: networking.k8s.io/v1
  40. kind: Ingress
  41. metadata:
  42. name: prometheus-k8s
  43. namespace: monitoring
  44. labels:
  45. prometheus: k8s
  46. annotations:
  47. kubernetes.io/ingress.class: "nginx"
  48. cert-manager.io/cluster-issuer: ca-issuer
  49. spec:
  50. tls:
  51. - hosts:
  52. - prometheus.example.com
  53. secretName: prometheus-dashboard-certs
  54. rules:
  55. - host: prometheus.example.com
  56. http:
  57. paths:
  58. - path: /
  59. pathType: ImplementationSpecific
  60. backend:
  61. service:
  62. name: prometheus-k8s
  63. port:
  64. name: web
  65. ```
  66. Once deployed to your K8s cluster, every 3 months cert-manager will automatically rotate the Prometheus `prometheus.example.com` TLS client certificate and key, and store these as the Kubernetes `prometheus-dashboard-certs` secret.
  67. For further information, read the official [Cert-Manager Ingress](https://cert-manager.io/docs/usage/ingress/) doc.
  68. ### Create New TLS Root CA Certificate and Key
  69. #### Install Cloudflare PKI/TLS `cfssl` Toolkit
  70. e.g. For Ubuntu/Debian distributions, the toolkit is part of the `golang-cfssl` package.
  71. ```shell
  72. sudo apt-get install -y golang-cfssl
  73. ```
  74. #### Create Root Certificate Authority (CA) Configuration File
  75. The default TLS certificate expiry time period is `8760h` which is 5 years from the date the certificate is created.
  76. ```shell
  77. $ cat > ca-config.json <<EOF
  78. {
  79. "signing": {
  80. "default": {
  81. "expiry": "8760h"
  82. },
  83. "profiles": {
  84. "kubernetes": {
  85. "usages": ["signing", "key encipherment", "server auth", "client auth"],
  86. "expiry": "8760h"
  87. }
  88. }
  89. }
  90. }
  91. EOF
  92. ```
  93. #### Create Certficate Signing Request (CSR) Configuration File
  94. The TLS certificate `names` details can be updated to your own specific requirements.
  95. ```shell
  96. $ cat > ca-csr.json <<EOF
  97. {
  98. "CN": "Kubernetes",
  99. "key": {
  100. "algo": "rsa",
  101. "size": 2048
  102. },
  103. "names": [
  104. {
  105. "C": "US",
  106. "L": "Portland",
  107. "O": "Kubernetes",
  108. "OU": "CA",
  109. "ST": "Oregon"
  110. }
  111. ]
  112. }
  113. EOF
  114. ```
  115. #### Create TLS Root CA Certificate and Key
  116. ```shell
  117. $ cfssl gencert -initca ca-csr.json | cfssljson -bare ca
  118. ca.pem
  119. ca-key.pem
  120. ```
  121. Check the TLS Root CA certificate has the correct `Not Before` and `Not After` dates, and ensure it is indeed a valid Certificate Authority with the X509v3 extension `CA:TRUE`.
  122. ```shell
  123. $ openssl x509 -text -noout -in ca.pem
  124. Certificate:
  125. Data:
  126. Version: 3 (0x2)
  127. Serial Number:
  128. 6a:d4:d8:48:7f:98:4f:54:68:9a:e1:73:02:fa:d0:41:79:25:08:49
  129. Signature Algorithm: sha256WithRSAEncryption
  130. Issuer: C = US, ST = Oregon, L = Portland, O = Kubernetes, OU = CA, CN = Kubernetes
  131. Validity
  132. Not Before: Jul 10 15:21:00 2020 GMT
  133. Not After : Jul 9 15:21:00 2025 GMT
  134. Subject: C = US, ST = Oregon, L = Portland, O = Kubernetes, OU = CA, CN = Kubernetes
  135. Subject Public Key Info:
  136. ...
  137. X509v3 extensions:
  138. X509v3 Key Usage: critical
  139. Certificate Sign, CRL Sign
  140. X509v3 Basic Constraints: critical
  141. CA:TRUE
  142. X509v3 Subject Key Identifier:
  143. D4:38:B5:E2:26:49:5E:0D:E3:DC:D9:70:73:3B:C4:19:6A:43:4A:F2
  144. ...
  145. ```