Deployment and usage of acme2certifier under Kubernetes with a Microsoft PKI

In short
  • Encryption is everywhere in the enterprise, including on internal networks.
  • acme2certifier: an ACME proxy in front of a Microsoft PKI.
  • Installation and deployment under Kubernetes.
  • Demonstration with Cert-Manager; configuration files are available.

Introduction

Nowadays, it has become more risky to connect a PC to a network than to drive the wrong way on the highway. Therefore, encrypting information and controlling our digital communications is now a priority, especially in businesses (with a little help from marketing and consulting...).

It is a standard, especially for web access (but not only), to enforce encryption for all types of access.

Whether it's accessing the company's local intranet via the internal network, or the institutional website exposed publicly on the internet...or through the many inter-service communications: frontend with backend, backend with database, web service with API...all communications must be protected.

Only legitimate participants in a connection are supposed to know the content and nature of the information exchanged (even if seeing a small padlock next to a URL doesn't mean you shouldn't ask questions).

To address this, we didn't wait for the hype (and the cost) of cybersecurity to offer solutions.

One of the preferred methods for authenticating and encrypting communications has changed very little, except for improvements in the algorithms used: the use of certificates!

I won't go into an explanation of how certificates work, but it is still one of the main solutions for:

  • Guaranteeing the identity of the people or services with whom we are communicating.
  • Encrypting communications so that only the legitimate recipient of the information can decrypt the data.

Certificates themselves are simply implementations of cryptographic methods such as asymmetric encryption, involving the well-known concepts of Alice and Bob.

Principles of certificates and asymmetric key encryption (source: https://www.lex-persona.com/certificat-numerique/).

Click the image to enlarge.

In addition, there are protocols that are often mixed together: SSL/TLS/HTTPS...

It is worth remembering that even the old SSL, in its version 3.0, is no longer considered secure; we should rather refer to TLS in each case.

HTTPS uses TLS (and formerly SSL) to secure communications between a client (browser) and a server.

Aspect SSL TLS HTTPS
Type Obsolete encryption protocol Modern encryption protocol Application protocol secured by SSL/TLS
Main function Securing communications (formerly) Securing communications (currently) Secure data transfer on the web
Status Obsolete Active (current standard) Uses TLS to function
Example of use Old HTTPS Modern HTTPS, emails Secure websites

Even though the current trend is to raise concerns about quantum computers, for now, implementing all of this through a certificate logic remains the most common practice.

However, with the explosion in the number of assets, microservice architectures, and increasingly stringent cybersecurity requirements, certificate management has become complex.

The lifespans of these certificates must be reduced; generic certificates that can cover entire domain suffixes should no longer be used.

With all this, even for small ecosystems, we quickly reach a large number of certificates. Their management becomes a real production concern.

The ACME protocol

The introduction of the ACME protocol (Automatic Certificate Management Environment) in 2015 greatly improved things.

Introduced with the Let's Encrypt project, initiated by the Internet Security Research Group (ISRG), it has helped to standardize and automate certificate management.

The operation of ACME is as follows:

  1. The client (meaning the entity that wants to obtain a certificate) generates a private key and submits a CSR (Certificate Signing Request) to a certification authority (CA) that supports the ACME protocol.
  2. The certification authority sends a challenge to the client to prove that the client is indeed the owner of the service for which it is requesting a certificate. This challenge can be offered in three forms:
    • HTTP-01: The client must place a specific file on a web server accessible via a URL that can be verified by the certification authority associated with the DNS name covered by the requested certificate. The content of the file must match what the certification authority submitted to the client.
    • DNS-01: The client adds a TXT record of type DNS in the zone corresponding to the service for which the certificate is requested.
    • TLS-ALPN-01: The client configures a temporary TLS certificate on the server, linked to an expectation from the certification authority (I'm not very familiar with this method).

    The nature of the challenge chosen depends on the client's configuration and the ACME implementation it has selected.

  3. If the challenge is successful, the CA issues the certificate.
Principles of ACME

Click the image to enlarge.

So far, I have described the classic mechanism for obtaining a certificate, except that with ACME, all of this is automated. The generation of the CSR, the negotiation of the challenge, the configuration of the client to respond to the challenge, and the issuance of the certificate up to its final implementation on the service are all completely automatic.

Subsequently, the certificate's lifecycle is also managed automatically, with a renewal that occurs automatically before the certificate expires.

Let's Encrypt

When we talk about ACME, we often talk about Let's Encrypt. This public and free certification authority (CA) is now responsible for many certificates.

letsencrypt.webp logo

Click the image to enlarge.

It is extremely popular, but it remains an external CA. Its use requires a public exposure of the domain and a challenge logic that is accessible from the outside.

This is not a problem for a company when covering, for example, its institutional website published on the web, but it is more problematic for purely internal uses. It is not always possible to communicate with an external CA like Let's Encrypt.

Private CA (Certificate Authority)

Companies often have an internal certification authority (CA). This CA is part of a PKI (Public Key Infrastructure), although it is not public, but the advantage is that the 'P' works, even with the word 'private'.

The certificates they issue are not recognized outside the company's assets, but this is perfectly usable for private exchanges between specific applications and devices managed by the company. These devices are configured to recognize certificates issued by the private CA.

In addition to one or more Certificate Authorities (CAs), a PKI includes a whole set of tools and services to simplify and centralize certificate management.

Microsoft PKI (Public Key Infrastructure)

This PKI can be deployed under the management of one or more Microsoft Windows Servers. I already see the die-hard Linux enthusiasts crying foul, but it must be acknowledged that Microsoft's CA is indeed used.

It is rarely standalone, but often part of the Active Directory/DNS combination. Indeed, Microsoft offers deep integration of its PKI service into Active Directory. This is not the only possible configuration, but it is the most common. For example, a CA registered in the MS directory automatically makes the certificates it issues recognized on all devices in the domain.

Microsoft Enterprise Certificate Authority

Click the image to enlarge.

However, despite the fact that ACME has existed since 2015, Microsoft has never, to my knowledge, had the idea of making its Microsoft Enterprise Certificate Authority compatible with the protocol.

acme2certifier

That's a shame, especially when you have a Kubernetes cluster on which you have deployed CertManager.

I have already had the opportunity to discuss this fantastic tool called CertManager in this article. I present how to use CertManager, Let's Encrypt, and ACME to automate the provisioning and lifecycle of your certificates on your K8S cluster.

Unfortunately, all of this only works for my applications in the DMZ. Internally, I cannot (do not want to) rely on Let's Encrypt and therefore cannot take advantage of CertManager's ACME support.

However, thanks to the acme2certifier project, it is possible to overcome this limitation.

acme2certifier is a fantastic open-source tool that acts as an ACME proxy. It provides the ability to use ACME even if your private CA does not support it. acme2certifier handles the communication with CertManager, making it believe that it is the CA itself.

It will handle the backend exchange with the final PKI CA that does not support ACME, using a compatible method to retrieve the certificate and deliver it to CertManager if the ACME challenge is successful.

In my example, I will use acme2certifier to take advantage of an internal MS PKI and be able to use it to generate certificates for my applications hosted on my Kubernetes worker nodes deployed on the LAN.

Microsoft Enterprise Certificate Authority is not the only CA considered by acme2certifier; other CAs are compatible, and a list of these can be found directly on the project's GitHub repository.

List of CAs compatible with acme2certifier

Click the image to enlarge.

I won't necessarily go into detail for every step, especially regarding the Windows PKI part, because the goal isn't to create a dedicated tutorial. However, I will try to make it understandable, and even if you are not a user of the MS CA, you should be able to use this article to deploy acme2certifier and adapt it to your needs.

Here is a summary of the components and logic to be deployed:

Overall diagram of the tutorial

Click the image to enlarge.

Note that for acme2certifier to function, the Windows server hosting the CA must have all these components installed at the Active Directory Certificate Services role level.

List of MS dependencies to install

Click the image to enlarge.

Installation

Prerequisites

Creating the service account

I will start by creating an Active Directory (AD) service account. This account will be used to communicate with the MS CA from acme2certifier (I am arbitrarily naming it svc_k8s_cert).

Creating the service account

Click the image to enlarge.

Creating the template

Next, I create a certificate template named TPL-SRV-WEB-K8S from my MS server that acts as the CA.

Certificate template

Click the image to enlarge.

A template provides a set of parameters and compatibility information supported/required by the certificate to be issued.

It is at the template level that we decide, for example, on the desired encryption type, the constraints for obtaining the certificate, and the functions that will be supported.

It is important to note that a certificate can be used for various purposes: securing and authenticating a web server (the client ensures it is communicating with the correct server), identifying a client (the server ensures it is communicating with the correct client), signing code, issuing Kerberos tickets... in short, we can have multiple templates within our PKI to meet different needs.

It is also at the template level that we define the validity periods of the certificates.

On the MS side, it is also in the template that we declare which device or user can request a certificate issued by it.

In my case, I authorize my service account svc_k8s_cert.

Authorization on the template

Click the image to enlarge.

Very important: I enforce the encryption parameters. For example, I want an encryption key of at least 4096 bits and use the RSA algorithm (and a SHA256 fingerprint). We haven't talked about the latter yet.

Configuration of constraints on the algorithms and protocols supported by the template

Click the image to enlarge.

RSA, formed from the initials of its three creators Rivest, Shamir, and Adleman, is an asymmetric encryption algorithm used by SSL and TLS protocols.

These can be based on RSA to establish a secure communication channel between a client and a server.

RSA is still widely used, although in TLS 1.3 it is replaced by ECDHE (Elliptic-curve Diffie–Hellman).

My goal is to have a template that enforces a minimum standard for good security while maintaining good compatibility. It's important to remember that if your certificate imposes overly strict algorithmic constraints, it may not be supported by the servers that will present it, or by the clients that will need to validate it.

Similarly, the encryption algorithms used have an impact on performance. Encrypting communications involves increased resource consumption on both the server and client sides, although today, there is often ample capacity available so that differences are not noticeable. However, on a large scale, this can be significant.

I also allow this template to be offered internally by my PKI.

Certificate chain associated with the private CA

Before working on acme2certifier, I retrieve the public certificate associated with my MS CA; this is located in the certificate store of all my devices registered on my AD domain (coolcorp.priv).

You only need to go to Trusted Root Certification (under Windows) to export the certificate for my CA as base64 into a file. I save this in a file named CA-COOLCORP.pem.

Retrieval of the public certificate from the CA

Click the image to enlarge.

Retrieval of the public certificate from the CA

Click the image to enlarge.

Note that in my example, I only have one root CA. In reality, this configuration is not recommended.

Generally, at least one intermediate CA is used. The logic is to have a root CA, which is only used to generate certificates for the intermediate CAs, and then this root CA is shut down to avoid any risk of compromise.

Only the intermediates are kept active, and they are responsible for issuing the certificates.

In this case, we would need the entire certificate chain, that is, the root public certificate plus the intermediate certificate(s). By working in base64, we can group everything into a single file.

This hierarchy helps to avoid keeping the root CA online.

Indeed, this remains a weakness of certificate solutions. We remain dependent on a third-party and centralized component, specifically the highest-level Certificate Authority (CA). For a private CA, it's an internal server; for a public CA, it's the organization from which you requested the certificate (e.g., Let's Encrypt).

If a CA is compromised, the entire chain based on that CA is compromised, and therefore all associated certificates are also compromised.

Ultimately, we trust the root CA. As a best practice, this trust is then delegated to intermediate CAs. We then assume that any certificate originating from this chain is a valid certificate, and therefore we can trust the content of the server using that certificate.

With intermediate CAs, if one were to become corrupted, we would restart the root CA and revoke the certificate of the compromised CA. The list of revoked certificates (which remains online) is updated, and all certificates generated by that corrupted intermediate CA are automatically invalidated.

The root CA, however, remains reliable, and we can redeploy a new certificate for a new intermediate CA before taking the root CA offline again.

The best practice is even to use a three-tier architecture

Architecture of a three-tier PKI (source Microsoft)

Click the image to enlarge.

I'm probably getting a bit sidetracked, but it's important to understand that at this level of the tutorial with acme2certifier, you will need the complete certificate chain associated with the CA that you will subsequently query with acme2certifier. In my example, and for simplicity, my chain is reduced to a root CA.

Deploying acme2certifier

We can now proceed with deploying acme2certifier

acme_srv.cfg

To do this, we prepare a configuration file acme_srv.cfg.

For me, its content is adapted for a Microsoft CA; feel free to consult the project documentation to retrieve the configuration associated with your target PKI.

[DEFAULT]
debug: False

[Nonce]
# disable nonce check. THIS IS A SEVERE SECURTIY ISSUE! Please do only for testing/debugging purposes
nonce_check_disable: False

[CAhandler]
handler_file: examples/ca_handler/mscertsrv_ca_handler.py
host: PRDMUTWIN501.coolcorp.priv
user: svc_k8s_cert
password: mon_password
ca_bundle: /var/www/acme2certifier/config/CA-COOLCORP.pem
auth_method: gssapi
template: TPL-SRV-WEB-K8S
krb5_config: /var/www/acme2certifier/config/krb5.conf

[DBhandler]
#dbfile: /var/lib/acme/db.sqlite3

[Certificate]
revocation_reason_check_disable: False

[Challenge]
# when true disable challenge validation. Challenge will be set to 'valid' without further checking
# THIS IS A SEVERE SECURTIY ISSUE! Please do only for testing/debugging purposes
challenge_validation_disable: False

[Order]
tnauthlist_support: False
  

For MS, you need to specify:

  • The DNS name that points to the server or where the CA is installed. In my example, my CA is on the server PRDMUTWIN501.coolcorp.priv. It's important that this DNS name is consistent with the public certificate in base64 retrieved previously.
  • The service account to use when connecting to the CA. In my case, it's svc_k8s_cert.
  • The password for this account: a weak point of the configuration, a plain text password. Therefore, be careful when handling this configuration file and its storage (no Git 😊).
  • ca_bundle: This specifies the file containing the public certification chain. In my case, it's the certificate I retrieved earlier, which contains the base64-encoded public certificate of my CA root. The path used will be visible within the context of the acme2certifier container because, of course, we are running acme2certifier in a container and under Kubernetes.
  • template: This is the name of the template to use with the PKI. I'm using the one I created previously: TPL-SRV-WEB-K8S
  • auth_method: This specifies the authentication method to use when connecting to the MS CA. It is preferable to use gssapi, which implies the use of Kerberos, which is more secure and, importantly, still supported by MS, whereas NTLM has been deprecated for years.
  • krb5_config: This is the Kerberos configuration file that will contain the data needed for the protocol to authenticate using this method with the service account.

krb5.conf

We are now looking at the krb5.conf file. Its contents are as follows:

[libdefaults]
default_realm = COOLCORP.PRIV
[realms]
COOLCORP.PRIV = {
  kdc = PRDMUTWIN501.coolcorp.priv
  admin_server = PRDMUTWIN501.coolcorp.priv
  default_domain = COOLCORP.PRIV
}
[domain_realm]
.coolcorp.priv = COOLCORP.PRIV
coolcorp.priv = COOLCORP.PRIV    

This is a standard configuration when using Kerberos on a Linux OS. It includes the domain names to use and the domain controllers to contact.

In my case, the domain is coolcorp.priv, and since I only have one DC (remember, this is a lab), I specify my domain controller: PRDMUTWIN501.coolcorp.priv (which is also my CA, for those who noticed... again, it's a lab... in the real world, it is strictly prohibited to deploy this type of service on a DC...).

NFS share

I will place this configuration file krb5.conf, along with the public certificate of my CA CA-COOLCORP.pem, on my NAS (Network-attached storage), in a folder that will be accessible via an NFS (Network File System) share, which is accessible to my Kubernetes worker nodes.

Making the files available on the NFS share

Click the image to enlarge.

Kubernetes Objects

The deployment of acme2certifier will be done under K8S.

01-pv-acme2certifier-default.yml

I'm going to start by creating the PersistentVolume (PV) associated with my NFS share to make the two previous files accessible to my pod.

Here is the content of the file 01-pv-acme2certifier-default.yml. I won't go into detail; I invite you to follow my Kubernetes cookbook if you are not familiar with K8S and its objects.

---
apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
    pv.kubernetes.io/provisioned-by: nfs.csi.k8s.io
  name: pv-acme2certifier-default
  namespace: inf-cert-lan
  labels:
    environment: prd
    network: lan
    app: acme2certifier
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  csi:
    driver: nfs.csi.k8s.io
    volumeHandle: /Volume1/nfsshare/kub.coolcorp.priv/namespaces/inf-cert-lan/acme2certifier
    volumeAttributes:
      server: 192.168.10.152
      share: /Volume1/nfsshare/kub.coolcorp.priv/namespaces/inf-cert-lan/acme2certifier
    

We deploy using the command kubectl apply -f 01-pv-acme2certifier-default.yml.

Feel free to read my article about the CSI (Container Storage Interface) NFS, as that is what I am using in my PV.

Please note that I am using the namespace inf-cert-lan, which already exists and was created by me for my CertManager installation.

Indeed, I arbitrarily decided to deploy acme2certifier in the same namespace as the core components of CertManager. This way, I group everything related to certificates for my cluster.

02-pvc-acme2certifier-default.yml

Next, we proceed with the PersistentVolumeClaim (PVC) using the file 02-pvc-acme2certifier-default.yml.

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-cme2certifier-default
  namespace: inf-cert-lan
  labels:
    environment: prd
    network: lan
    application: acme2certifier
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  volumeName: pv-acme2certifier-default
  storageClassName: ""
  share: /Volume1/nfsshare/kub.coolcorp.priv/namespaces/inf-cert-lan/acme2certifier

We deploy using the command kubectl apply -f 02-pvc-acme2certifier-default.yml.

Similarly, I won't go into detail here; this article will provide you with more information about how storage works in Kubernetes.

Applying the Persistent Volume and Persistent Volume Claim

Click the image to enlarge.

ConfigMap cm-acme2certifier

Before proceeding with the deployment, we will first create a ConfigMap (CM). This is a native object of Kubernetes that is responsible for storing the configuration of an application running within a pod. Instead of presenting a configuration file, we store this file in a CM and then map that CM into the pod.

A CM does not encrypt its contents and presents them in plain text. Therefore, be careful about the elements you include in it. If they are too sensitive, it is preferable to use a Secret object instead, although this is not much better protected since it only encodes the data in base64.

The CM will allow us to store the acme_srv.cfg configuration file that was prepared previously, even if it contains a password. I know this isn't ideal, but if you limit access to the namespace containing CertManager by using custom Kubernetes roles, you can reduce the risk.

Navigate to the location where the acme_srv.cfg file is located and type the following command:

kubectl create configmap cm-acme2certifier --from-file=acme_srv.cfg -n inf-cert-lan

Creating the ConfigMap for acme2certifier configuration

Click the image to enlarge.

The CM object cm-acme2certifier will be created in the namespace inf-cert-lan based on the contents of acme_srv.cfg.

03-deploy-acme2certifier-default.yml

We can then proceed with the Deployment using the file 03-deploy-acme2certifier-default.yml.

The file is very basic and only creates a single pod that deploys the image 2certifier:0.36-nginx-wsgi (the version may change over time).

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: acme2certifier
  namespace: inf-cert-lan
  labels:
    environment: prd
    network: lan
    app: acme2certifier
spec:
  replicas: 1
  selector:
    matchLabels:
      environment: prd
      network: lan
      app: acme2certifier
  template:
    metadata:
      labels:
        environment: prd
        network: lan
        app: acme2certifier
    spec:
      containers:
      - name: acme2certifier
        image: grindsa/acme2certifier:0.36-nginx-wsgi
        ports:
        - containerPort: 80
        volumeMounts:
              - name: pv-democsishare-nfs
                mountPath: "/var/www/acme2certifier/config"
              - name: acme2certifier-conf
                mountPath: "/var/www/acme2certifier/acme_srv/acme_srv.cfg" 
                subPath: acme_srv.cfg 
      volumes:
        - name: acme2certifier-conf
          configMap:
            name: cm-acme2certifier
        - name: pv-democsishare-nfs
          persistentVolumeClaim:
            claimName: pvc-cme2certifier-default   
    

We provide the pod with a pv-democsishare-nfs volume for access to files hosted on NFS. We ensure that the paths correspond to what was specified in the acme_srv.cfg file.

We also provide the CM from the acme_srv.cfg file so that the configuration file is mapped under that name within the pod.

We deploy using the command kubectl apply -f 03-deploy-acme2certifier-default.yml.

Deploying acme2certifier

Click the image to enlarge.

At this stage, we can verify whether the acme2certifier pod is running correctly.

kubectl get pod -n inf-cert-lan

Checking the deployment

Click the image to enlarge.

This is indeed the case; we can continue.

04-svc-acme2certifier-default.yml

acme2certifier must be accessible within the cluster, so you need to declare a service (svc) via the file 04-svc-acme2certifier-default.yml.

---
  kind: Service
  apiVersion: v1
  metadata:
    name: svc-acme2certifier-default
    namespace: inf-cert-lan
    labels:
      environment: prd
      network: lan
      application: acme2certifier
  spec:
    ports:
      - name: http
        port: 80
        protocol: TCP
        targetPort: 80
    selector:
      environment: prd
      network: lan
      app: acme2certifier
    

There's nothing special to say here; as usual, pay attention to the label used in the selector section so that the service is properly connected to the acme2certifier pod on port 80.

We deploy using the command kubectl apply -f 04-svc-acme2certifier-default.yml.

Deploying the service

Click the image to enlarge.

05-clusterissuer-acme2certifier.yml

Next comes the file 05-clusterissuer-acme2certifier.yml.

This one is a bit special, as it deploys a ClusterIssuer.

It's an object that is cross-namespace and associated with CertManager.

This component will be responsible for communicating with acme2certifier. I invite you to read my article on CertManager, where I explain what an issuer is. I had already created one to associate it with Let's Encrypt.

kubectl get clusterissuer

ClusterIssuer for Let's Encrypt

Click the image to enlarge.

Here, I want to associate it with acme2certifier, so here's the content of the file:

---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: clusterissuer-acme2certifier
spec:
  acme:
    email: [email protected]
    server: http://svc-acme2certifier-default.inf-cert-lan/directory
    privateKeySecretRef:
      # Secret resource that will be used to store the account's private key.
      name: clusterissuer-acme2certifier-account-key
    solvers:
    - http01:
        ingress:
          ingressClassName: traefik-lan
          podTemplate:
            metadata:
              labels:
                network: lan
          ingressTemplate:
            metadata:
              labels:
                network: lan     
  

I will include the URL of the service that I deployed just before, making acme2certifier accessible internally within the cluster. This is what is specified in the 'server' option in the ClusterIssuer specifications. I use the full name of the service, including the namespace.

I also define the ACME challenge type that I want to use, which is http-01.

To be able to process this challenge, CertManager, via this ClusterIssuer, will need to provision a pod responsible for hosting the challenge file.

The URL targeted will always be associated with the URL of the service covered by the application that requests a certificate.

Therefore, you need to create an Ingress under the control of an IngressController. If this doesn't make sense to you, I invite you to follow this article where I explain what an Ingress is and, more importantly, how to deploy the IngressController solution Traefik. Basically, it allows the service associated with the pod to be accessible from outside the cluster.

If you don't specify anything at this level, CertManager uses the default IngressController.

In my cluster, I have two IngressControllers, one for the LAN and one for the DMZ. In this case, for this tutorial, I need to use the one on the LAN.

To ensure that the pod and the ingress that will be dynamically mounted to respond to the http-01 challenge are correct, I set the correct labels.

Then, simply deploy the ClusterIssuer: kubectl apply -f 05-clusterissuer-acme2certifier.yml.

At this level, the interesting thing to observe is the log of acme2certifier (kubectl logs nom_pod_acme2certifier -n inf-cert-lan).

Viewing the logs of the acme2certifier pod

Click the image to enlarge.

When the ClusterIssuer is deployed, we observe that it registers with acme2certifier using the email address specified in the YAML file.

Therefore, we have an Issuer communicating with acme2certifier via ACME, and acme2certifier responds as if it were a CA supporting the protocol.

The cluster issuer is online

Click the image to enlarge.

Demonstration

Now, we can verify that the entire system is functioning correctly.

Test application

To do this, I will reuse my demo application that I previously set up to demonstrate the proper functioning of CertManager.

In the original article, I used Let's Encrypt and an exposure in a DMZ; here, I will use exactly the same base: a simple Nginx server, but I will deploy it in a namespace dev-demoacme2certifier-lan (the namespace is created using the command kubectl create ns dev-demoacme2certifier-lan).

I won't go into detail about the file 01-deploy-demoacme2certifier-front.yaml, which describes the Deployment object

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-demoacme2certifier-front
  namespace: dev-demoacme2certifier-lan
  labels:
    environment: dev
    network: lan
    application: demoacme2certifier
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      environment: dev
      network: lan
      application: demoacme2certifier
  template:
    metadata:
      labels:
        environment: dev
        network: lan
        application: demoacme2certifier
    spec:
      containers:
      - name: demo-nginx-traefik-lan
        image: nginx:1.27
        resources:
          requests:
            memory: "8Mi"
            cpu: "250m"
          limits: 
            memory: "256Mi"
            cpu: 1  
        ports:
        - containerPort: 80
      

Nor will I describe the file 02-svc-demoacme2certifier-front.yaml for the service object.

---
  kind: Service
  apiVersion: v1
  metadata:
    name: svc-demoacme2certifier-front
    namespace: dev-demoacme2certifier-lan
    labels:
      environment: dev
      network: lan
      application: demoacme2certifier
  spec:
    ports:
      - name: http
        port: 80
        protocol: TCP
        targetPort: 80
    selector:
      environment: dev
      network: lan
      application: demoacme2certifier
    

I will focus a bit on the file 03-ing-demoacme2certifier-front.yaml.

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ing-demoacme2certifier-default
  namespace: dev-demoacme2certifier-lan
  labels:
      environment: dev
      network: lan
      application: demoacme2certifier
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: web,websecure
    ingressClassName: traefik-lan
    traefik.ingress.kubernetes.io/router.tls: "true"
spec:
  ingressClassName: traefik-lan
  tls:
  - hosts:
    - demoacme2certifier.coolcorp.priv
    secretName: sec-certificate-demoacme2certifier
  rules:
  - host: demoacme2certifier.coolcorp.priv
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: svc-demoacme2certifier-front
            port:
              number: 80
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: cert-demoacme2certifier-front
  namespace: dev-demoacme2certifier-lan
  labels:
      environment: dev
      network: lan
      application: demoacme2certifier 
spec:
  dnsNames:
    - demoacme2certifier.coolcorp.priv
  commonName: demoacme2certifier.coolcorp.priv
  secretName: sec-certificate-demoacme2certifier
  privateKey:
    algorithm: RSA
    size: 4096
  issuerRef:
    name: clusterissuer-acme2certifier 
    kind: ClusterIssuer
  

As in the article about Traefik or in the final article of my cookbook, I create an Ingress object.

This is configured to use the Traefik ingress controller (traefik-lan). Feel free to check out the tutorial about Traefik to fully understand this point.

The ingress must respond to the external URL at demoacme2certifier.coolcorp.priv.

It must forward requests to the service svc-demoacme2certifier-front and offer a certificate contained in the secret sec-certificate-demoacme2certifier.

This certificate is declared a bit further down via the object cert-demoacme2certifier-front.

It includes, in its characteristics, the dnsname and the commonname corresponding to the URL of the demo site: demoacme2certifier.coolcorp.priv.

It also includes the characteristics of the associated key, which will be generated, namely 4096 bits, and the use of the RSA algorithm. This must be consistent with the certificate template of the PKI explained in the prerequisites.

If we don't specify anything at this level, the certificate will be requested with the default options. For example, a key of 2048 bits... which will not correspond to the minimum size imposed by the template created previously at the Windows CA level.

The most interesting part is the issuerRef section, as this is where you specify which Issuer should be contacted to obtain the certificate. We will therefore populate the ClusterIssuer created just before, which is registered with acme2certifier.

Don't forget to create the DNS record so that the URL https://demoacme2certifier.coolcorp.priv correctly points to the HAproxy VIP that exposes the Traefik instances (more details here).

Creating the DNS record

Click the image to enlarge.

Now, just run the command kubectl apply -f .\dev-demoacme2certifier-lan\ to create all the K8S objects (all YAML files will be processed at once; dev-demoacme2certifier-lan is the directory where I placed all the YAML files) and let the magic happen.

Deploying the test application

Click the image to enlarge.

Control and explanations

If everything goes well, after a few minutes, you should see a "true" appear next to the output of the command:

kubectl get certificate -n dev-demoacme2certifier-lan

Checking the certificate

Click the image to enlarge.

If that's the case, it means the certificate is ready and available. You can verify this by visiting the URL https://demoacme2certifier.coolcorp.priv.

Checking the certificate

Click the image to enlarge.

We have a certificate! And when we look at the CA that issued it, we see my MS CA.

In fact, if you look at the management console of the CA in question, in the issued certificates section, you will find the trace of the certificate, with the name of the service account that requested it and the attached template: everything is consistent 😊.

Checking the certificate at the CA level

Click the image to enlarge.

So, what exactly happened? Well, we can see that with the following command:

kubectl get event -n dev-demoacme2certifier-lan

Starting from the bottom of the command output, we can trace everything that happened.

List of events in the namespace

Click the image to enlarge.

  1. The NGINX pod representing the demo application was deployed, and the container started.
  2. Then, the creation of a certificate request was automatically generated by CertManager.
  3. This request was submitted to the ClusterIssuer.
  4. The http-01 challenge was initiated, which resulted in the creation of a pod based on the image quay.io/jetstack/CertManager-acmesolver:v1.16.1. This pod is only there to create a web server that hosts the challenge file by responding to a request at the URL https://demoacme2certifier.coolcorp.priv, followed by a subdirectory /.well-known/acme-challenge/. It is this subdirectory that allows Traefik to redirect the request to the pod dynamically created by CertManager. If you are quick enough, you can see the associated ingress in the Traefik console.
  5. Appearance of the ingress

    Click the image to enlarge.

  6. acme2certifier will query this URL to verify the challenge, and if successful, it will request the certificate from the Windows Certificate Authority (CA) and return it to CertManager so that it can be stored in the appropriate secret and made available for use by the final ingress.
  7. Once the certificate has been obtained, the dynamic certmanager pod (and the ingress) is removed.

Conclusion

acme2certifier is a typical example of a small but valuable tool offered voluntarily by developers, who themselves rely on other open-source projects from other developers to provide a service that compensates for a functional limitation in a tool we have in our architecture.

The use of certificates, even though it's not new, remains a challenge for companies. Every year, the constraints become stricter, requiring regular reviews of certificate issuance policies.

The pressure from browser vendors like Google, which sometimes announces the end of support for certain protocols or algorithms in its flagship Chrome browser, requires us to be able to reissue a whole set of certificates based on new standards... otherwise, we risk blocking Chrome updates.

This will soon make your CISO (Chief Information Security Officer) unhappy, as security patches for browsers are released more frequently than rain in Normandy (a very beautiful region, by the way).

Having automated certificate management has become a necessity. Basing strategies on ACME is clearly a good solution... However, it's important to be able to use it with your legacy systems, and that's where the Kubernetes ecosystem, with tools like CertManager, provides real added value, especially when talented developers offer applications like acme2certifier! There's no more excuse for manually generating certificates 😊

For those who wish, a version of the configuration files and YAMLs used in this article is available in my GitHub repository