Startseite 5 Techblog 5 Oracle OCI Load Balancer with Lets Encrypt (free) SSL certificates
Startseite 5 Techblog 5 Oracle OCI Load Balancer with Lets Encrypt (free) SSL certificates

Oracle OCI Load Balancer with Lets Encrypt (free) SSL certificates

5. Juli 2023

Johannes Michler PROMATIS Horus Oracle

Executive Vice President – Head of Platforms & Development

E-Business Suite Umgebung mit LetsEncrypt Zertifikat

Nowadays, all web traffic through the internet should be encrypted. For this to work, SSL certificates are required. These can be bought from commercial Certificate Authorities. Since around 2016, certificates are also provided for free by the nonprofit Certificate Authority Let's Encrypt. There are various tools to create these certificates, also with Oracle OCI, however, they usually require dedicated web servers for verification with a HTTP challenge or they need control over DNS. This blog post will show a very lightweight alternative using OCI Load Balancer, OCI Object Storage as well as the OCI Certificate Service.

Basic setup in OCI

First of all you have to create a new OCI Object Storage bucket (let's name it "acme") and make it "publicly" visible. Into this bucket, we put a dummy file acmetoken.txt:

Public Object Storage Bucket with dummy file

Note down the Object Storage namespace which is part of the URL of the file.

Then, we create an empty "rule set" (we name it acme) in the Load Balancer that we want to generate SSL certificates for:

OCI Load Balancer Rule set "acme"

We then have to assign that rule set to a listener (an existing one or a new one, if you use exclusively HTTPS for regular traffic as I do in the following case):

Dummy listener on Port 80 that is used only for SSL certificate generation

Note that it is NOT necessary to have a dedicated listener for that, since we will later only "intercept" the ACME challenge you can easily add it to an existing (HTTP) listener.

If you do not allow regular public internet traffic to port 80 (as I do in this case), you need to create a special security list "letsencrypt" and assign it to the Load Balancer subnet:

(Usually) empty security list to be assigned to the Load Balancer subnet

Note down the OCIDs of the Load Balancer, the security list as well as the compartment where you want to store the certificates.

Install certbot

You need to run certbot on an instance where you have OCI Command Line tools as well as a recent python3. I in my case use the E-Business Suite Cloud Manager VM for that purpose.

There, install certbot into a virtual environment as follows:

python3 -m venv /u01/install/APPS/certbot
/u01/install/APPS/certbot/bin/pip install --upgrade pip
/u01/install/APPS/certbot/bin/pip install certbot certbot
mkdir /u01/install/APPS/certbot/log
mkdir /u01/install/APPS/certbot/config
mkdir /u01/install/APPS/certbot/work

Create scripts for OCI interaction

Furthermore, create a in that folder (enter OCID_LB and OCID_SECLIST of your case):

oci --config-file $CONFIG_FILE network security-list update --security-list-id $OCID_SECLIST --ingress-security-rules '[{"description": "temporaryLetsEncrypt","icmp-options": null,"is-stateless": false,"protocol": "6","source": "","source-type": "CIDR_BLOCK","tcp-options": {"destination-port-range": {"max": 80,"min": 80},"source-port-range": null},"udp-options": null}]' --force --wait-for-state AVAILABLE
echo $CERTBOT_VALIDATION > acmetoken.txt
oci --config-file $CONFIG_FILE os object put --bucket-name acme --file acmetoken.txt --force
oci --config-file $CONFIG_FILE lb rule-set update --load-balancer-id $OCID_LB --rule-set-name acme --force --items "$ACME_JSON" --wait-for-state SUCCEEDED
wget -q -O - >http://${CERTBOT_DOMAIN}/.well-known/acme-challenge/${CERTBOT_TOKEN}

You can skip the first oci command if it is not necessary to open the network security-list.

And an acme.json as follows, where you have to replace with the Object Storage namespace:

        "action": "REDIRECT",
        "conditions": [
            "attribute-name": "PATH",
            "attribute-value": "/.well-known/acme-challenge/THIS_IS_THE_CHALLENGE",
            "operator": "EXACT_MATCH"
        "redirect-uri": {
          "host": "",
          "path": "/n//b/acme/o/acmetoken.txt",
          "port": 443,
          "protocol": "https",
          "query": ""
        "response-code": 302

Create an (fill in the COMPARTMENT_ID)

OCI_CERT_OCID=$(oci --config-file $CONFIG_FILE certs-mgmt certificate list --all --compartment-id $COMPARTMENT_ID --query "data.items[?subject.\"common-name\"=='${RENEWED_DOMAINS}'].id|join(',',@)"| tr -d '\""')
CERT_KEY=$(cat $RENEWED_LINEAGE/privkey.pem)
oci --config-file $CONFIG_FILE certs-mgmt certificate update-certificate-by-importing-config-details --certificate-id=$OCI_CERT_OCID --cert-chain-pem="$CERT_CHAIN" --certificate-pem="$CERT_PATH" --private-key-pem="$CERT_KEY"

And finally, (only if you need to open port 80; fill OCID of security list again):

oci --config-file $CONFIG_FILE network security-list update --security-list-id $OCID_SECLIST --ingress-security-rules '[]' --force --wait-for-state AVAILABLE

Then, give execution privs to the user:

chmod 755 /u01/install/APPS/certbot/
chmod 755 /u01/install/APPS/certbot/
chmod 755 /u01/install/APPS/certbot/

Create Certificate

With those preparations completed, we can now request a first certificate:

/u01/install/APPS/certbot/bin/certbot certonly \
--manual --preferred-challenges=http \
--manual-auth-hook /u01/install/APPS/certbot/ \
--manual-cleanup-hook /u01/install/APPS/certbot/ \
--logs-dir /u01/install/APPS/certbot/log \
--config-dir /u01/install/APPS/certbot/config \
--work-dir /u01/install/APPS/certbot/work \

This should, after some questions, give a result as follows:

Successfully received certificate
Certificate is saved at: /u01/install/APPS/certbot/config/live/XXXX_MYDOMAINNAME/fullchain.pem
Key is saved at:         /u01/install/APPS/certbot/config/live/XXXX_MYDOMAINNAME/privkey.pem
This certificate expires on 2023-08-16.
These files will be updated when the certificate renews..

Install Certificate into Certificate Management Service

Got to the OCI Certificate Management Service and create a new "Imported" certificate testaebsapp.

Letsencrypt Certificate Service

In Step 3 upload cert.pem, chain.pem and privkey.pem created in the previous step. Finally, you can use the certificate uploaded in the OCI Load Balancer and receive a properly signed SSL certificate.

Renew Certificates automatically

Let's encrypt certificates have a rather short lifetime. Luckily, the above process including the renewal of the certificate in the OCI Certificate Service can be easily automated with the following command:

/u01/install/APPS/certbot/bin/certbot renew \
--manual --preferred-challenges=http \
--manual-auth-hook /u01/install/APPS/certbot/ \
--manual-cleanup-hook /u01/install/APPS/certbot/ \
--logs-dir /u01/install/APPS/certbot/log -\
-config-dir /u01/install/APPS/certbot/config \
--work-dir /u01/install/APPS/certbot/work \
--deploy-hook /u01/install/APPS/certbot/

To test if everything is working, a renewal can be enforced by adding --force-renewal.


The above procedure shows a very lightweight approach on how SSL certificates from letsencrypt can be created for use in OCI (e.g. Load Balancer) services.

The approach described can also be used if you technically use the certificates for services that rely on internal hostnames and have a private IP assigned for XXXX_MYDOMAINNAME in the internal DNS server - as long as you assign a public IP in the public DNS for Let's Encrypt purposes. If you don't like this, I suggest you look into certbot-dns-oci.