Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Implementing cert-manager in K8s

Implementing cert-manager in K8s

One of the best practices from a security point of view is to introduce the management of the certificates that we are going to use to support protocols such as SSL / TLS. In this talk we will explain cert-manager and his implementation in K8s as a native Kubernetes certificate management controller that allows us to manage connection certificates and secure communications through SSL/TLS protocols. Later I will explain the main functionalities and advantages that cert-manager provides, for example it allows us to validate that the certificates we are using in different environments are correct. Finally, some use cases are studied in which to use cert-manager and the integration with other services such as Let's Encrypt or HashiCorp Vault.

jmortegac

May 22, 2022
Tweet

More Decks by jmortegac

Other Decks in Technology

Transcript

  1. Title INDEX 1. Introduction to certificates and certification authorities (CA)

    2. Introduction to cert-manager 3. Cert-manager features 4. Integration with other tools and certificates from different sources
  2. Title K8s ingress with HTTPS apiVersion: networking.k8s.io/v1 kind: Ingress metadata:

    name: wordpress annotations: kubernetes.io/ingress.class: nginx spec: rules: - http: paths: - path: / pathType: Prefix backend: service: name: wordpress port: number: 80 tls: - hosts: - domain.com
  3. Title Cert-manager features • cert-manager can use multiple Issuers, including:

    ◦ self-signed ◦ cert-manager acting as a CA ◦ the ACME protocol ( used by Let's Encrypt) ◦ HashiCorp Vault • Multiple issuers can be configured simultaneously • Issuers can be available in a single namespace, or in the whole cluster (then we use the ClusterIssuer CRD)
  4. Title cert-manager in action • We will install cert-manager •

    We will create a ClusterIssuer to obtain certificates with Let's Encrypt (this will involve setting up an Ingress Controller) • We will create a Certificate request and cert-manager will create a TLS Secret
  5. Title Install Cert-manager with $ helm repo add jetstack https://charts.jetstack.io

    $ helm repo update $ helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
  6. Title Install Cert-manager with $ kubectl cert-manager help kubectl cert-manager

    is a CLI tool manage and configure cert-manager resources for Kubernetes Usage: kubectl cert-manager [command] Available Commands: approve Approve a CertificateRequest check Check cert-manager components convert Convert cert-manager config files between different API versions create Create cert-manager resources deny Deny a CertificateRequest experimental Interact with experimental features help Help about any command inspect Get details on certificate related resources renew Mark a Certificate for manual renewal status Get details on current status of cert-manager resources version Print the cert-manager CLI version and the deployed cert-manager version
  7. Title Install & configure Cert-manager $ kubectl create namespace cert-manager

    $ kubectl apply --validate=false -f https://github.com/cert-manager/cert-manager/releas es/download/v1.7.2/cert-manager.yaml
  8. Title Install & configure Cert-manager customresourcedefinition.apiextensions.k8s.io/certificaterequests.cert-manager.io created customresourcedefinition.apiextensions.k8s.io/certificates.cert-manager.io created customresourcedefinition.apiextensions.k8s.io/challenges.acme.cert-manager.io

    created customresourcedefinition.apiextensions.k8s.io/clusterissuers.cert-manager.io created . . . deployment.apps/cert-manager-webhook created mutatingwebhookconfiguration.admissionregistration.k8s.io/cert-manager-webhook created validatingwebhookconfiguration.admissionregistration.k8s.io/cert-manager-webhook created
  9. Title Install & configure Cert-manager $ kubectl get pods --namespace

    cert-manager NAME READY STATUS RESTARTS AGE cert-manager-5c47f46f57-jknnx 1/1 Running 0 27s cert-manager-cainjector-6659d6844d-j8cbg 1/1 Running 0 27s cert-manager-webhook-547567b88f-qks44 1/1 Running 0 27s
  10. Title Issuers • Issuers (and ClusterIssuers) represent a certificate authority

    from which signed x509 certificates can be obtained, such as Let’s Encrypt. • You will need at least one Issuer or ClusterIssuer to begin issuing certificates within your cluster.
  11. Title Issuer vs ClusterIssuers https://cert-manager.io/docs/concepts/issuer/ • Issuers only works on

    its Kubernetes cluster in a specific namespace • ClusterIssuers works for all namespaces
  12. Title Working with LetsEncryt staging apiVersion: cert-manager.io/v1 kind: ClusterIssuer metadata:

    name: letsencrypt-staging namespace: cert-manager spec: acme: # Email address used for ACME registration email: your-email-id-here server: https://acme-staging-v02.api.letsencrypt.org/directory privateKeySecretRef: # Name of a secret used to store the ACME account private key name: letsencrypt-staging-private-key # Add a single challenge solver, HTTP01 using nginx solvers: - http01: ingress: class: nginx
  13. Title Working with LetsEncryt production apiVersion: cert-manager.io/v1 kind: ClusterIssuer metadata:

    name: letsencrypt-production namespace: cert-manager spec: acme: # Email address used for ACME registration email: your-email-id-here server: https://acme-staging-v02.api.letsencrypt.org/directory privateKeySecretRef: # Name of a secret used to store the ACME account private key name: letsencrypt-production-private-key # Add a single challenge solver, HTTP01 using nginx solvers: - http01: ingress: class: nginx
  14. Title Adding Ingress TLS/SSL support • Create a Kubernetes secret

    with server.crt certificate and server.key private key file. • Add the TLS block to the ingress resource
  15. Title Kubernetes TLS Secret $ kubectl create secret tls app-tls

    \ --namespace dev \ --key server.key \ --cert server.crt
  16. Title Add TLS block to Ingress Object tls: - hosts:

    - your-domain.com secretName: app-tls
  17. Title Ingress && Cert-manager apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name:

    cert-ingress annotations: kubernetes.io/ingress.class: "nginx" cert-manager.io/cluster-issuer: "letsencrypt-staging" spec: tls: - hosts: - your-domain.com secretName: app-tls
  18. Title Install & configure Cert-manager $ kubectl apply -f cert_ingress.yaml

    ingress.networking.k8s.io/echo-ingress configured
  19. Title Install & configure Cert-manager $ kubectl get secrets NAME

    TYPE DATA AGE app-tls kubernetes.io/tls 3 1m
  20. Title Install & configure Cert-manager $ kubectl describe certificate Events:

    Type Reason Age From Message ---- ------ ---- ---- ------- Normal GeneratedKey 2m12s cert-manager Generated a new private key Normal Requested 2m12s cert-manager Created new CertificateRequest resource "echo-tls-3768100355" Normal Issued 47s cert-manager Certificate issued successfully
  21. Title Conclusions • Cert-manager facilitates certificate signing through the Kubernetes

    API: ◦ we create a Certificate object. ◦ cert-manager creates a private key ◦ it signs that key … ◦ ... or interacts with a certificate authority to obtain the signature ◦ it stores the resulting key+cert in a Secret resource • These Secret resources can be used in many places (Ingress, mTLS, ...)