|
| 1 | +# Setting up a free TLS certificate for testing HTTPS connections on OCI Load Balancer |
| 2 | + |
| 3 | +Owner: Paul Toal |
| 4 | + |
| 5 | +Within OCI, the [Load Balancer Service](https://docs.oracle.com/en-us/iaas/Content/Balance/Concepts/balanceoverview.htm) enables you to create resilient connections to backend resources such as web servers. |
| 6 | + |
| 7 | +Sometimes when you are testing backend services it is necessary to use a HTTPS connection. Normally, TLS certificates are issued against fully qualified domain names. However, it isn't always possible or quick and easy to register your testing resources with a domain. |
| 8 | + |
| 9 | +In this tutorial, I will walk you through the process of quickly enabling HTTPS connection through the OCI load balancer, using a free TLS certificate generated by [ZeroSSL](https://app.zerossl.com/dashboard), and generated against an IP address. |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | + - An OCI tenancy. |
| 14 | + - An OCI Administrator with appropriate permissions to create and manage load balancers and associated resources. |
| 15 | + - Created a sample web site deployed on OCI. |
| 16 | + |
| 17 | + > **Note** For this tutorial, I have created a compute instance called **apache** and installed and configured the Apache HTTPD service on it, running on port 80. |
| 18 | +
|
| 19 | +# Create the Load Balancer |
| 20 | + |
| 21 | +Initially, we will create the load balancer and configure the HTTP listener on port 80. This will enable us to obtain the public IP address of the load balancer, which we will need to create the IP address-based TLS certificate. |
| 22 | + |
| 23 | +> **Note** If you are planning on using a reserved IP address and already know the public IP address, you can skip the creation of the HTTP listener and configure the HTTPS listener from the start. |
| 24 | +
|
| 25 | +1. Login to your OCI console and navigate to **Networking**, then **Load Balancer** from the **Load Balancers** menu. |
| 26 | + |
| 27 | +2. Select the appropriate compartment and click `Create Load Balancer`. |
| 28 | + |
| 29 | +3. In the **Add details** screen, provide the following information: |
| 30 | + |
| 31 | + - Load balancer name: `lb-for-apache` |
| 32 | + |
| 33 | + Leave the following values as their defaults: |
| 34 | + |
| 35 | + - Choose visibility type: `Public` |
| 36 | + - Assign a public IP address: `Ephemeral IP address` |
| 37 | + - Choose the minimum bandwidth: `10` |
| 38 | + - Choose the maximum bandwidth: `10` |
| 39 | + - Choose networking |
| 40 | + -> VCN: Choose your VCN |
| 41 | + -> Subnet: Choose your public subnet |
| 42 | + |
| 43 | +4. Leave all other values as default and click `Next'. |
| 44 | + |
| 45 | +5. On the **Choose backends** screen, click `Add backends`. |
| 46 | + |
| 47 | +6. Select the checkbox next to your compute instance (in my case `apache`) from the list of instances. |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +7. Click `Add selected backends`. |
| 52 | + |
| 53 | +8. Leave the port for your backend as port 80. |
| 54 | + |
| 55 | +9. Leave the health check policy as default. |
| 56 | + |
| 57 | +10. Click `Next`. |
| 58 | + |
| 59 | +11. On the **Configure listener** screen, provide the following information: |
| 60 | + |
| 61 | + - Name: `listener-http` |
| 62 | + - Specify the type of traffic your listener handles: `HTTP` |
| 63 | + - Specify the port your listener monitors for ingress traffic: `80` |
| 64 | + |
| 65 | +12. Click `Next`. |
| 66 | + |
| 67 | +13. Since, this is a test, disable **Error logs** and **Access Logs** (if enabled). |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +14. Click `Submit`. |
| 72 | + |
| 73 | +Your load balancer will be created after a few moments. |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +> **Note** If you have enabled the network traffic to your HTTPD server, and if it is running, **Backend sets health** shoudl be showing as **OK**. If not, check your networking and security lists. |
| 78 | +
|
| 79 | +15. Make a note of the public IP address of your load balancer. |
| 80 | + |
| 81 | +# Test the Load Balancer |
| 82 | + |
| 83 | +Before we enable a HTTPS connection to the web server, let's check out load balancer is working and routing traffic correctly. |
| 84 | + |
| 85 | +1. Open a browser and navigate to `http://<your LB public IP address>/`, accepting the HTTP warning issued by your browser. |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +# Generate the TLS certificate |
| 90 | + |
| 91 | +Now that we have our load balancer listening on HTTP with a public IP address, we can generate an IP-based TLS certificate. |
| 92 | + |
| 93 | +For this tutorial, i'm using [ZeroSSL](https://app.zerossl.com/dashboard), primarily because they offer the ability to generate up to three, 90-day certificates for free, and will generate certificates based on IP addresses, not just domain names. |
| 94 | + |
| 95 | +1. Navigate to `https://app.zerossl.com/dashboard`. |
| 96 | + |
| 97 | +2. If you don't already have one, register for a free account and login. |
| 98 | + |
| 99 | +3. Click on `New Certificate` to start the certificate generation wizard. |
| 100 | + |
| 101 | +4. Enter the IP address of your load balancer in the **Domain Name** field. |
| 102 | + |
| 103 | +The IP will be validated as shown by the green tick. |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +5. Click **Next Step ->** |
| 108 | + |
| 109 | +4. Under **Validity**, select `90-Day Certificate`. |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +5. Click **Next Step ->** |
| 114 | + |
| 115 | +6. Don't select any add-ons. |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | +7. Click **Next Step ->** |
| 120 | + |
| 121 | +8. On the **CSR & Contact** screen, ensure `Auto-Generate CSR` is enabled. |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | +9. Click **Next Step ->** |
| 126 | + |
| 127 | +10. Under **Finalize Your Order**, leave `Free` selected. |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | +11. Click **Next Step ->** |
| 132 | + |
| 133 | +Before ZeroSSL will issue a certificate, you must verify that you control the IP address that you have requested a certificate for. Since this is a free, 90-day certificate, the only method of validation is to upload a temporary file to your web server. |
| 134 | + |
| 135 | +12. Follow the instructions to upload the pki-validation file to your web server into the folder specified by ZeroSSL. |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | +13. Once the file is in place, click **Verify Domain** to start the verification process. |
| 140 | + |
| 141 | +After successful verification, your certificate will be generated. |
| 142 | + |
| 143 | +14. Click **Download Certificate (.zip)** to obtain the necessary certificate and key files from ZeroSSL. |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | +15. Extract the zip file to a suitable folder on your local machine. It contains three files: |
| 148 | + |
| 149 | + - **certificate.crt** - is the actual X.509 certificate |
| 150 | + - **ca_bundle.crt** - is the signing certificate |
| 151 | + - **private.key** - is the private key for your certificate |
| 152 | + |
| 153 | + We will need all three in the next step. |
| 154 | + |
| 155 | +# Create the HTTPS listener |
| 156 | + |
| 157 | +Now that we have our 90-day TLS certificate from ZeroSSL, we can create a HTTPS listener on our load balancer. |
| 158 | + |
| 159 | +1. Back in the OCI console, navigate back to your load balancer at **Networking**, then **Load Balancer** from the **Load Balancers** menu. |
| 160 | + |
| 161 | +2. Select your **lb-for-apache** load balancer. |
| 162 | + |
| 163 | +Before creating the HTTPS listener, we need to import our new certificate. |
| 164 | + |
| 165 | +3. From the **Resources** left-hand menu, select **Certificates**. |
| 166 | + |
| 167 | +4. Change the **Certificate Resources** to `Load balancer managed certificate`. |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | +5. Click **Add certificate**. |
| 172 | + |
| 173 | +6. Provide a name for your certificate such as its IP address. |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +7. Under **Choose SSL certificate file**, drop your `certificate.crt` file into the box. |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | +8. Check the **Specify CA certificate** check box. |
| 182 | + |
| 183 | +9. Under **Choose CA certificate file**, drop your `ca_bundle.crt` file into the box. |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | +8. Check the **Specify private key** check box. |
| 188 | + |
| 189 | +9. Under **Choose CA private key file**, drop your `private.key` file into the box. |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | +10. Click **Add certificate** to to finalise the addition of the certificate. |
| 194 | + |
| 195 | +11. Click **Close** on the **Work Request** and wait for the new certificat to appear in the list of certificates (a new moments). |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | +Now that we have our certificate imported, we can create the new listener. |
| 200 | + |
| 201 | +12. From the **Resources** left-hand menu, select **Listeners**. |
| 202 | + |
| 203 | +13. Click **Create listener**. |
| 204 | + |
| 205 | +14. Provide following values on the **Create listener screen: |
| 206 | + |
| 207 | + - Name: `listener-https` |
| 208 | + - Protocol: `HTTPS` |
| 209 | + - Port: `443` |
| 210 | + - Use SSL: Checked |
| 211 | + - SSL certificate |
| 212 | + - Certificate resource: `Load balancer managed certificate` |
| 213 | + - Certificate name: `<your LB public IP address>` (or the name you specified in step 6 above) |
| 214 | + - Backend set: Select your backend set from the dropdown list |
| 215 | + |
| 216 | +15. Click **Create listener**. |
| 217 | + |
| 218 | +16. Click **Close** on the **Work request submitted** screen and wait for the new listener to appear. |
| 219 | + |
| 220 | +# Testing our new listener |
| 221 | + |
| 222 | +Now that we have created the HTTPS listener, we can test it. |
| 223 | + |
| 224 | +1. Open a browser and navigate to `https://<your LB public IP address>/`. |
| 225 | + |
| 226 | +You will see that you now have a secure connection to your web server, as indicated by the padlock in your browser address bar. |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | +This completes the lab. |
| 231 | + |
| 232 | +# License |
| 233 | + |
| 234 | +Copyright (c) 2024 Oracle and/or its affiliates. |
| 235 | + |
| 236 | +Licensed under the Universal Permissive License (UPL), Version 1.0. |
| 237 | + |
| 238 | +See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details. |
0 commit comments