<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><generator uri="https://gohugo.io/" version="0.156.0">Hugo</generator><title type="html">Vpn on Marcin Jasion - Pragmatic DevOps</title><link href="https://6f95e4af.mjasion.pages.dev/tags/vpn/" rel="alternate" type="text/html" title="html"/><link href="https://6f95e4af.mjasion.pages.dev/tags/vpn/index.xml" rel="alternate" type="application/rss+xml" title="rss"/><updated>2022-06-29T00:00:00+02:00</updated><id>https://6f95e4af.mjasion.pages.dev/tags/vpn/</id><entry><title type="html">How to setup AWS Site-to-Site VPN with Unifi UDM 🔒</title><link href="https://6f95e4af.mjasion.pages.dev/posts/cloud/how-to-setup-aws-site-to-site-vpn-with-unifi-udm/?utm_source=atom_feed" rel="alternate" type="text/html"/><link href="https://6f95e4af.mjasion.pages.dev/posts/kubernetes/how-to-debug-istio-upstream-reset/?utm_source=atom_feed" rel="related" type="text/html" title="How to debug Istio Upstream Reset 502 UPE (old 503 UC)"/><id>https://6f95e4af.mjasion.pages.dev/posts/cloud/how-to-setup-aws-site-to-site-vpn-with-unifi-udm/</id><author><name>Marcin Jasion</name></author><published>2022-06-29T00:00:00+02:00</published><updated>2022-06-29T00:00:00+02:00</updated><content type="html"><![CDATA[<blockquote>Site-to-Site VPN allows connecting local network with AWS VPC. This blog is a step-by-step instruction to establish connection</blockquote><p>By default resources, you launch on the cloud (EC2, RDS, and others) cannot communicate with your local networks like home or office. To allow this you can create a Site-to-Site VPN. This VPN connection will be established between your router and AWS VPC.</p>
<p>Creating VPN between networks is <a href="https://docs.aws.amazon.com/vpn/latest/s2svpn/SetUpVPNConnections.html" target="_blank" rel="noopener">well documented</a>. However, you can have issues configuring your home router. At home, I have a Unifi Dream Machine router, which is designed for small networks, but has features that match advanced routers for offices. One of them is a Site-to-Site VPN using the IPSec protocol.</p>
<h2 id="setup-vpn-on-aws-">Setup VPN on AWS ☁️</h2>
<p>The first step is to create a VPN connection on AWS. For this blog I will use&hellip; the default VPC 🙂. To configure it AWS requires to define 3 components: Customer Gateway, Virtual Private Gateway and VPN connection.</p>
<p>The Customer Gateway is basically just an entity that holds the information about your home router - public IP.
The Virtual Private Gateway is the virtual entity on the VPC side, that allows configuring routing to that gateway. That VPG is attached to the VPN. So the last entity is the VPN connection which brings it all together and establishes the VPN tunnels between your home or office and VPC.</p>
<h3 id="create-base-components-">Create base components 🏗️</h3>
<p>To start your VPN connection start by defining Customer Gateway.
Go to the <strong>VPC</strong> tab, find the <strong>Customer Gateway</strong> panel and click the button to <strong>Create</strong>. The required field is IP address. Write here your public IP address where your router is running. Also, it is good to name this gateway. I named mine <code>home</code>.</p>
<blockquote>
<p>To quickly check you public IP you can open  <a href="https://ifconfig.co" target="_blank" rel="noopener">https://ifconfig.co</a></p>
</blockquote>
<p>The next step is to create a Virtual Private Gateway. Go to the <strong>Virtual Private Gateway</strong> panel and click <strong>Create</strong>. It just asks for a name. Let&rsquo;s name it also <code>home</code>. The VPG state will be detached. I will come back to it later.
<img src="/posts/cloud/how-to-setup-aws-site-to-site-vpn-with-unifi-udm/virtual_gateway_notassigned.png" alt=""></p>
<h3 id="create-a-vpn-connection-">Create a VPN connection 🔒</h3>
<p>This is the time to start defining VPN. Open the <strong>Site-to-Site VPN connection</strong> panel and click <strong>Create VPN Connection</strong>. The form will have 3 panels: details and tunnel options.</p>
<p><strong>Details</strong> start from defining the gateway on the VPC side. Choose <strong>Virtual private gateway</strong> and in the form select your VPG.</p>
<p>Next select <strong>Customer gateway</strong>. Here you define with which router the VPN will be established.</p>
<p>There is the last configuration to set: routing. It is a section where you can define which local networks the VPN will be used for. On the screenshot, I marked this as a point <strong>1</strong>.</p>
<p>AWS allows for two options: dynamic routing based on BGP, and statically defined. In my case, I am using static.
In the prefixes, I am putting my local network prefixes(like <code>192.168.1.0/24</code>). You are allowed to put multiple networks here.</p>
<p><img src="/posts/cloud/how-to-setup-aws-site-to-site-vpn-with-unifi-udm/create_vpn.png" alt=""></p>
<h3 id="configure-tunnel-options-">Configure Tunnel Options ⚙️</h3>
<p>Tunnel options allow defining the IPSec parameters. AWS creates 2 tunnels, to which you can connect and each of them you can configure differently. Or the same 🙂.</p>
<p>What I am always choosing is:</p>
<ul>
<li><strong>Encryption algorithms</strong>: AES-256 (for both phases)</li>
<li><strong>Integrity algorithms</strong>: SHA2-256, SHA2-384, SHA2-512</li>
<li><strong>DH groups</strong>: all above 14</li>
<li><strong>IKE Version</strong>: ikev2</li>
</ul>
<p>Those parameters will be crucial for setting up our Unifi router.</p>
<p>When you finish these changes you can create the VPN and wait a few seconds. The VPN connection should be ready.
<img src="/posts/cloud/how-to-setup-aws-site-to-site-vpn-with-unifi-udm/vpn_ready.png" alt=""></p>
<h3 id="configure-vpc-routing-">Configure VPC Routing 🛣️</h3>
<p>Previously I mentioned that the Virtual Private Gateway state is not attached to any VPC. We can reassign the VPN connection between VPCs by changing attachments.</p>
<p>To attach go back to <strong>Virtual Private Gateway</strong> and select your VPG and in <strong>Actions</strong>, button find <strong>Attach to VPC</strong>. Select your VPC and your VPG should be available to configure routing on VPC.
<img src="/posts/cloud/how-to-setup-aws-site-to-site-vpn-with-unifi-udm/virtual_gateway_assigned.png.png" alt=""></p>
<p>On VPC the last thing to configure is routes. As we have assigned VPG, and networks from our home are known (configured on VPN with static routes), we can configure automated propagation of those rules to VPC route tables. To configure this perform:</p>
<ol>
<li>Go to <strong>Route tables</strong></li>
<li>Select routes assigned to VPC, or those which should have access to your home.</li>
<li>Select <strong>Actions</strong> button, and choose <strong>Edit route propagation</strong>,</li>
<li>Select Virtual private gateway</li>
</ol>
<p>After a few seconds, the new route should be added
<img src="/posts/cloud/how-to-setup-aws-site-to-site-vpn-with-unifi-udm/vpc_routes.png" alt="">
As you can see, the last route is &ldquo;Propagated&rdquo;, and its target is my virtual private gateway.</p>
<h2 id="setup-vpn-on-unifi-">Setup VPN on Unifi 🏠</h2>
<p>Having configured AWS VPC, the last part is to configure our router. In my home, I have Unifi Dream Machine, with the latest software (Network 7.1).</p>
<p>To create a VPN connection:</p>
<ul>
<li>Go to <strong>Settings</strong> &gt; <strong>Teleport &amp; VPN</strong>,</li>
<li>Scroll down to <strong>Site-to-Site VPN</strong> and click  <strong>Create</strong>,
<img src="/posts/cloud/how-to-setup-aws-site-to-site-vpn-with-unifi-udm/udm-ipsec.png" alt=""></li>
</ul>
<p>Start filling out the form. The Pre-Shared Key you could configure in Tunnel Options. If you have skipped this, go to the AWS VPN tab, and click <strong>Download Configuration</strong>. In this file you will find the PSK to fill in point 1 and the <strong>Remote IP Address</strong> (point 4).
In the <strong>Remote Gateway/Subnets</strong>(point 3) put AWS VPC network addressing. In my case, it was <code>172.31.0.0/16</code>.</p>
<p>To align encryption options with <strong>Tunnel Options</strong> on AWS, select <strong>Manual</strong> in Advanced configuration and customize. Configure your parameters according to how you have configured them on AWS. I recommend using <strong>AES-256</strong> and higher DH Groups and use the above image as an example.</p>



    


<div class="alert success">
    <span><i data-feather="check-circle"></i></span>
    <span><strong>The VPN connection should be established ❤️</strong></span>
</div>

<h2 id="last-step---testing-">Last step - testing 🪛</h2>
<p>To check if you have a working VPN connection create an EC2 instance on this VPC.</p>



    


<div class="alert warning">
    <span><i data-feather="alert-triangle"></i></span>
    <span><strong>Ensure your Security group allows for your home network. You can allow access to a single port, protocol, or whole traffic.</strong></span>
</div>

<p>I have created an instance with IP <code>172.31.34.95</code>. This instance has a Security Group rule allowing for <strong>All Traffic</strong> from my home network.
When the VPN works and instance is up, a simple <code>ping</code> can prove that everything is configured:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ ping 172.31.34.95 -c <span style="color:#ae81ff">5</span>
</span></span><span style="display:flex;"><span>PING 172.31.34.95 <span style="color:#f92672">(</span>172.31.34.95<span style="color:#f92672">)</span> 56<span style="color:#f92672">(</span>84<span style="color:#f92672">)</span> bytes of data.
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">64</span> bytes from 172.31.34.95: icmp_seq<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span> ttl<span style="color:#f92672">=</span><span style="color:#ae81ff">63</span> time<span style="color:#f92672">=</span>38.1 ms
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">64</span> bytes from 172.31.34.95: icmp_seq<span style="color:#f92672">=</span><span style="color:#ae81ff">2</span> ttl<span style="color:#f92672">=</span><span style="color:#ae81ff">63</span> time<span style="color:#f92672">=</span>38.2 ms
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">64</span> bytes from 172.31.34.95: icmp_seq<span style="color:#f92672">=</span><span style="color:#ae81ff">3</span> ttl<span style="color:#f92672">=</span><span style="color:#ae81ff">63</span> time<span style="color:#f92672">=</span>36.4 ms
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">64</span> bytes from 172.31.34.95: icmp_seq<span style="color:#f92672">=</span><span style="color:#ae81ff">4</span> ttl<span style="color:#f92672">=</span><span style="color:#ae81ff">63</span> time<span style="color:#f92672">=</span>38.3 ms
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">64</span> bytes from 172.31.34.95: icmp_seq<span style="color:#f92672">=</span><span style="color:#ae81ff">5</span> ttl<span style="color:#f92672">=</span><span style="color:#ae81ff">63</span> time<span style="color:#f92672">=</span>38.1 ms
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>--- 172.31.34.95 ping statistics ---
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">5</span> packets transmitted, <span style="color:#ae81ff">5</span> received, 0% packet loss, time 4005ms
</span></span><span style="display:flex;"><span>rtt min/avg/max/mdev <span style="color:#f92672">=</span> 36.380/37.810/38.285/0.718 ms
</span></span></code></pre></div><blockquote>
<p>If you are not sure that you are pinging EC2 take a look on ping response times. On local networks they are much lower.</p>
</blockquote>
<h2 id="summary-">Summary ☑️</h2>
<p>Setting up VPN allows making your infrastructure secure. You don&rsquo;t have to expose ports on the public internet to have access to cloud machines.</p>
<h2 id="faq-">FAQ ❓</h2>
<p><strong>I have two network VLANs at home, should I configure some firewall rules if I don&rsquo;t want to allow access from one of them?</strong></p>
<p>Let&rsquo;s assume you have two networks: <code>home</code> and <code>guest</code>.  If the <code>guest</code> network should not have access to resources to VPN, on AWS VPN,  in <strong>Static IP Prefixes</strong> configuration you have to set only <code>home</code> network subnet.</p>
<p>Another thing are Security Groups, where we define allowed networks. If you will not set too wide network range, then it will also block access.</p>
]]></content><category scheme="https://6f95e4af.mjasion.pages.dev/tags/aws" term="aws" label="aws"/><category scheme="https://6f95e4af.mjasion.pages.dev/tags/vpn" term="vpn" label="vpn"/><category scheme="https://6f95e4af.mjasion.pages.dev/tags/unifi" term="unifi" label="unifi"/><category scheme="https://6f95e4af.mjasion.pages.dev/tags/networking" term="networking" label="networking"/></entry></feed>