<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Infra on Louis&#39;s blog</title>
        <link>https://blog.louishhy.com/categories/infra/</link>
        <description>Recent content in Infra on Louis&#39;s blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-us</language>
        <copyright>Louis Huang</copyright>
        <lastBuildDate>Fri, 23 Aug 2024 07:46:59 +0000</lastBuildDate><atom:link href="https://blog.louishhy.com/categories/infra/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>Using cloudflare to setup the server SSL/TLS</title>
        <link>https://blog.louishhy.com/post/cloudflare-ssl-tls/</link>
        <pubDate>Fri, 23 Aug 2024 07:46:59 +0000</pubDate>
        
        <guid>https://blog.louishhy.com/post/cloudflare-ssl-tls/</guid>
        <description>&lt;h2 id=&#34;problem&#34;&gt;Problem
&lt;/h2&gt;&lt;p&gt;The motivation is simply to add a layer of SSL/TLS to the server to add HTTPS functionalities. HTTPS is the current standard de facto and it is a necessary step to setup a reachable server.&lt;/p&gt;
&lt;h2 id=&#34;available-solutions&#34;&gt;Available solutions
&lt;/h2&gt;&lt;p&gt;Usually we use something called a &lt;strong&gt;TLS termination proxy&lt;/strong&gt; to setup the SSL/TLS.&lt;/p&gt;
&lt;blockquote&gt;
    &lt;p&gt;A TLS termination proxy (or SSL termination proxy,[1] or SSL offloading[2]) is a proxy server that acts as an intermediary point between client and server applications, and is used to terminate and/or establish TLS (or DTLS) tunnels by decrypting and/or encrypting communications.&lt;/p&gt;&lt;span class=&#34;cite&#34;&gt;&lt;span&gt;― &lt;/span&gt;&lt;span&gt;Wikipedia, &lt;/span&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/TLS_termination_proxy&#34;&gt;&lt;cite&gt;TLS termination proxy&lt;/cite&gt;&lt;/a&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;h3 id=&#34;solution-1-nginx--certbot--lets-encrypt&#34;&gt;Solution 1: Nginx + Certbot + Let’s Encrypt
&lt;/h3&gt;&lt;p&gt;Certbot can help manage the Nginx reverse proxy and handle renewal for the server. To enable &lt;code&gt;certbot&lt;/code&gt; and &lt;code&gt;nginx&lt;/code&gt; containers share resources, sharing volumes in the &lt;code&gt;docker-compose&lt;/code&gt; may be a viable solution. The &lt;code&gt;certbot&lt;/code&gt; can access to Let’s encrypt which is a facility for issuing short-termed SSL/TLS CA certificates free of charge.&lt;/p&gt;
&lt;h3 id=&#34;solution-2-traefik&#34;&gt;Solution 2: Traefik
&lt;/h3&gt;&lt;p&gt;I actually got to know &lt;a class=&#34;link&#34; href=&#34;https://traefik.io/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;Traefik&lt;/a&gt; in the FastAPI documentations. It seems to be a modern alternative for Nginx which supports auto discovery and load balancing based on the architectures of the Docker Swarm or Kubernetes. It seems to use container tags to discover them. It also supports automatically renew the CA certificates, and has a beautiful control panel (although, impose security risks 🙁 )&lt;/p&gt;
&lt;p&gt;Nevertheless one important drawback is that it is sort of an overkill for small personal servers, since its &lt;strong&gt;high complexity&lt;/strong&gt; overweighs its benefit to automatic renewal which can be recognized by &lt;code&gt;certbot&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;solution-3-cloudflare--nginx&#34;&gt;Solution 3: Cloudflare + Nginx
&lt;/h3&gt;&lt;p&gt;If you set up your DNS with Cloudflare, they have an option for you to proxy your request and Cloudflare will handle the secure communication between the client server and its proxy. Additionally, they also provide you with a max. 15-years origin CA certificate which is bound to your domain. You only need to bound your original server’s Nginx to the origin CA certificate and you are done. In my opinion it is the most suitable and fast setup for small servers.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://blog.louishhy.com/post/cloudflare-ssl-tls/cloudflare.png&#34;
	width=&#34;1304&#34;
	height=&#34;382&#34;
	srcset=&#34;https://blog.louishhy.com/post/cloudflare-ssl-tls/cloudflare_hu13101409344664421711.png 480w, https://blog.louishhy.com/post/cloudflare-ssl-tls/cloudflare_hu5795773131068701151.png 1024w&#34;
	loading=&#34;lazy&#34;
	
		alt=&#34;Source: Cloudflare control panel.&#34;
	
	
		class=&#34;gallery-image&#34; 
		data-flex-grow=&#34;341&#34;
		data-flex-basis=&#34;819px&#34;
	
&gt;&lt;/p&gt;
&lt;h2 id=&#34;implementation&#34;&gt;Implementation
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Obtain a domain of your own from a domain provider.&lt;/li&gt;
&lt;li&gt;Login into Cloudflare and enable the DNS for your domain.
&lt;ul&gt;
&lt;li&gt;Be sure to select “Proxied” in the mode.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;SSL/TLS =&amp;gt; Overview&lt;/strong&gt; to enable &lt;strong&gt;Full (Strict)&lt;/strong&gt; mode.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;SSL/TLS =&amp;gt; Origin Server&lt;/strong&gt; to generate an &lt;strong&gt;origin certificate&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Load the origin certificate to your nginx.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;security-augmentation&#34;&gt;Security augmentation
&lt;/h3&gt;&lt;p&gt;Although not enabled by default, you can add another layer of security by &lt;strong&gt;Authenticated Origin Pull (mTLS)&lt;/strong&gt; which authenticates that the traffic is proxied from the cloudflare server, rather than directly accessed. This helps ensuring that the DDoS protection etc. from cloudflare is in effect.&lt;/p&gt;
&lt;p&gt;Check the official document for details:&lt;/p&gt;
&lt;p&gt;&lt;a class=&#34;link&#34; href=&#34;https://developers.cloudflare.com/ssl/origin-configuration/authenticated-origin-pull&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;https://developers.cloudflare.com/ssl/origin-configuration/authenticated-origin-pull&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That’s it! Your website now supports SSL/TLS.&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
