<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yoshiaki Senda on Medium]]></title>
        <description><![CDATA[Stories by Yoshiaki Senda on Medium]]></description>
        <link>https://medium.com/@panda1100?source=rss-f5a850722935------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ho0_q6_Vfc7eFcED</url>
            <title>Stories by Yoshiaki Senda on Medium</title>
            <link>https://medium.com/@panda1100?source=rss-f5a850722935------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 12:13:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@panda1100/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Quickly serve S3 objects using MinIO and Apptainer on Rocky Linux 9]]></title>
            <link>https://medium.com/@panda1100/quickly-serve-s3-object-using-minio-and-apptainer-on-rocky-linux-9-40e0fc1da795?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/40e0fc1da795</guid>
            <category><![CDATA[apptainer]]></category>
            <category><![CDATA[rockylinux]]></category>
            <category><![CDATA[minio]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Wed, 10 Aug 2022 11:33:26 GMT</pubDate>
            <atom:updated>2022-08-10T11:54:19.232Z</atom:updated>
            <content:encoded><![CDATA[<p>This short note shows you how to quickly serve S3 objects locally using <strong>MinIO</strong> and <strong>Apptainer </strong>on<strong> Rocky Linux 9.</strong></p><h3>Install Apptainer</h3><pre>$ sudo dnf install -y <a href="https://github.com/apptainer/apptainer/releases/download/v1.0.3/apptainer-1.0.3-1.x86_64.rpm">https://github.com/apptainer/apptainer/releases/download/v1.0.3/apptainer-1.0.3-1.x86_64.rpm</a></pre><h3>Build MinIO SIF image</h3><p>create minio/data directory</p><pre>$ mkdir -p ~/minio/data<br>$ cd ~/minio</pre><p>create minio.def</p><pre>Bootstrap: docker<br>From: minio/minio</pre><pre>%environment<br>  export MINIO_ROOT_USER=minio<br>  export MINIO_ROOT_PASSWORD=minio123</pre><pre>%runscript<br>  exec echo &quot;$@&quot;</pre><pre>%startscript<br>  minio server ~/minio/data --console-address &quot;:9001&quot;</pre><p>build MinIO SIF</p><pre>$ apptainer build <strong>minio.sif</strong> minio.def</pre><h3>Run MinIO Apptainer instance</h3><pre>$ apptainer instance start minio.sif minio1</pre><p>check open ports</p><pre>$ lsof -i:9000 -i:9001</pre><h4>access to <a href="http://localhost:9001/">http://localhost:9001</a> from your browser</h4><p>Login minio / minio123</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*G16TShpHPJyoJIRCkgqodA.png" /></figure><h3>Prepare S3 Object</h3><h4>create bucket</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DAEhfKMCpdWmKSEU2EyBCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*o1IQpIAVKFhHlJxHhqenHg.png" /></figure><h4>Upload file to demo bucket</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APJsMWsQKWTeG92u96rh4g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ppy0OwSyhIrI4vRF3BVXfQ.png" /></figure><h4>Create Service Account</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TR_hUhKd839whlJr8Nfoyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*iIlGCiu1foA9sDticasRZA.png" /></figure><p>Click Download for import to get json file that includes credentials. (<strong><em>You should keep your Secre Key secret. </em></strong>I didn’t mask Secret Key below for demo purpose.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*D--_dN22QjaTNGPkxV6u1g.png" /></figure><h3>Test with S3 Client</h3><p>Downlod MinIO client mc</p><pre>$ wget <a href="https://dl.min.io/client/mc/release/linux-amd64/mc">https://dl.min.io/client/mc/release/linux-amd64/mc</a><br>$ chmod +x mc</pre><p>Set alias to access MinIO with Service Account credentials</p><pre>./mc alias set minio <a href="http://localhost:9000/">http://localhost:9000</a> Xs5g23HdozPocyxL OFNSPopNTTsljIetxJICc2Q495yRWRCU</pre><p>list object in demo bucket</p><pre>./mc ls minio/demo<br>[2022-08-10 20:07:34 JST]  70MiB STANDARD minio.sif</pre><h3>References</h3><p><a href="https://docs.min.io/docs/minio-client-complete-guide.html">MinIO | The complete guide to the MinIO client</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40e0fc1da795" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quickly serve static files using Caddy and Apptainer on Rocky Linux 9]]></title>
            <link>https://medium.com/@panda1100/quickly-serve-static-files-using-caddy-and-apptainer-on-rocky-linux-9-7685d68f3288?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/7685d68f3288</guid>
            <category><![CDATA[caddy]]></category>
            <category><![CDATA[rockylinux]]></category>
            <category><![CDATA[apptainer]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Wed, 10 Aug 2022 02:32:09 GMT</pubDate>
            <atom:updated>2022-08-10T02:42:17.262Z</atom:updated>
            <content:encoded><![CDATA[<p>This short note shows you how to quickly (<strong><em>under a few minutes</em></strong>) serve static files locally using <strong>Caddy</strong> and <strong>Apptainer </strong>on<strong> Rocky Linux 9.</strong></p><h3>Install Apptainer</h3><pre>$ sudo dnf install -y <a href="https://github.com/apptainer/apptainer/releases/download/v1.0.3/apptainer-1.0.3-1.x86_64.rpm">https://github.com/apptainer/apptainer/releases/download/v1.0.3/apptainer-1.0.3-1.x86_64.rpm</a></pre><h3>Build Caddy SIF image</h3><p>move to your home directory</p><pre>$ cd ~/</pre><p>build Caddy SIF</p><pre>$ apptainer build <strong>caddy.sif</strong> docker://library/caddy</pre><h3>Serve static files</h3><h4>Prepare static file</h4><pre>$ cd <em>~/STATIC_FILES<br></em>$ touch ks.cfg</pre><h4>Serve static files</h4><pre>$ ~/caddy.sif caddy file-server --browse --listen :8080</pre><p>side note: You can ignore this ERROR since this is a one shot service</p><pre>ERROR unable to autosave config</pre><h4>Check with curl</h4><pre>$ curl localhost:8080/ks.cfg</pre><h4>or your browser</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*C2UQ208H3IFwr2j8A3D_zA.png" /></figure><p>Voila!</p><h3>References</h3><ul><li><a href="https://caddyserver.com/docs/quick-starts/static-files">Static files quick-start - Caddy Documentation</a></li><li><a href="https://apptainer.org/">Apptainer - Portable, Reproducible Containers</a></li></ul><h3>Appendix: using Podman</h3><p>Install Podman</p><pre>$ sudo dnf install podman</pre><p>Pull Official Caddy image (<a href="https://hub.docker.com/_/caddy">https://hub.docker.com/_/caddy</a>)</p><pre>$ podman pull docker.io/library/caddy</pre><p>Serve static files</p><pre>$ cd <em>~/STATIC_FILES<br></em>$ podman run -it -p 8080:80 -v ${PWD}:/srv caddy caddy file-server --browse --listen :80</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7685d68f3288" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Installation Guide of Vagrant and KVM on Rocky Linux 9.0]]></title>
            <link>https://medium.com/@panda1100/quick-installation-guide-of-vagrant-and-kvm-on-rocky-linux-9-0-991ad0f80f6c?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/991ad0f80f6c</guid>
            <category><![CDATA[libvirt]]></category>
            <category><![CDATA[rockylinux]]></category>
            <category><![CDATA[vagrant]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Mon, 25 Jul 2022 12:07:13 GMT</pubDate>
            <atom:updated>2022-07-25T12:07:13.444Z</atom:updated>
            <content:encoded><![CDATA[<p>This short note describes installation procedures of Vagrant and KVM on Rocky Linux 9.0. There are few changes from Rocky Linux 8. (1) libvirt-devel package move to <strong>crb</strong> repository. (2) NFS server does not accept UDP connection whether NFSv4 or NFSv3.</p><h3>Installation Procedures</h3><h4>Install KVM</h4><pre>sudo dnf group install -y &quot;virtualization hypervisor&quot;<br>sudo dnf group install -y &quot;virtualization tools&quot;<br>sudo systemctl enable --now libvirtd</pre><h4>Install Vagrant</h4><pre>sudo dnf config-manager --add-repo <a href="https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo">https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo</a><br>sudo dnf install -y vagrant</pre><pre><strong>sudo dnf config-manager --set-enabled crb</strong><br>sudo dnf install -y libvirt-devel</pre><pre>vagrant plugin install vagrant-libvirt</pre><h4>Create Vagrantfile</h4><p>If you use UDP for NFS v4, vagrant up failed with NFS mount error.</p><pre># -*- mode: ruby -*-<br># vi: set ft=ruby :</pre><pre>Vagrant.configure(&quot;2&quot;) do |config|<br>  config.vm.provider :libvirt do |libvirt|<br>    libvirt.cpu_mode = &quot;host-passthrough&quot;<br>    libvirt.cpus = 4<br>    libvirt.memory = 8192<br>    libvirt.machine_virtual_size = 40<br>  end</pre><pre>  config.vm.synced_folder &quot;.&quot;, &quot;/vagrant&quot;, type: &quot;nfs&quot;, nfs_version: 4, <strong>nfs_udp: false</strong></pre><pre>  config.vm.box = &quot;rockylinux/8&quot;<br>  config.vm.hostname = &quot;rocky8&quot;</pre><pre>  config.vm.provision &quot;shell&quot;, inline: &lt;&lt;-SHELL<br>    dnf install -y cloud-utils-growpart<br>    growpart /dev/vda 1<br>    xfs_growfs /dev/vda1<br>SHELL</pre><pre>end</pre><h4>Add user to libvirt group</h4><pre>sudo usermod -aG libvirt YOUR_USERNAME<br>newgrp</pre><h4>Vagrant up</h4><pre>vagrant up</pre><h3>References</h3><ul><li><a href="https://bugzilla.redhat.com/show_bug.cgi?id=1505245">1505245 - [mount.nfs] NFSv4 over UDP failed when mounting from rhel7 client but succeeded from rhel6 client</a></li><li><a href="https://github.com/vagrant-libvirt/vagrant-libvirt/issues/735">vagrant up stuck when mounting NFS shared folders · Issue #735 · vagrant-libvirt/vagrant-libvirt</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=991ad0f80f6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup NVIDIA GPU Driver on Rocky Linux 9.0]]></title>
            <link>https://medium.com/@panda1100/setup-nvidia-gpu-driver-on-rocky-linux-9-0-166d7ce111b2?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/166d7ce111b2</guid>
            <category><![CDATA[rockylinux]]></category>
            <category><![CDATA[nvidia-driver]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Mon, 25 Jul 2022 05:54:44 GMT</pubDate>
            <atom:updated>2022-07-25T10:52:33.911Z</atom:updated>
            <content:encoded><![CDATA[<p>This short note shows you an example procedures to setup proprietary version of NVIDIA GPU driver on Rocky Linux 9.0. Testing environment is Secure Boot disabled and fresh installation of Rocky Linux 9.0.</p><h3>Pre-installation Actions</h3><pre>sudo su -<br>dnf upgrade --refresh -y<br>dnf group install -y &quot;Development tools&quot;<br>dnf install -y epel-release<br>dnf install -y kernel-devel kernel-headers</pre><h3>Installation</h3><p>Disable Nouveau drivers</p><pre>cat &lt;&lt; EOS &gt; /etc/modprobe.d/blacklist-nouveau.conf<br>blacklist nouveau<br>options nouveau modeset=0<br>EOS</pre><pre>dracut --force</pre><p>Download run file installer from NVIDIA</p><pre>wget <a href="https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda_11.7.0_515.43.04_linux.run">https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda_11.7.0_515.43.04_linux.run</a></pre><p>Reboot into text mode</p><pre>systemctl set-default multi-user.target<br>reboot</pre><p>Install NVIDIA driver and CUDA toolkit with default settings</p><pre>sudo su -<br>sh cuda_11.7.0_515.43.04_linux.run</pre><p>Reboot into graphical mode</p><pre>systemctl set-default graphical.target<br>nvidia-xconfig<br>reboot</pre><h3>Verify</h3><p>Check loaded modules</p><pre>$ lsmod | grep -i nvidia<br>nvidia_drm             73728  3<br>nvidia_modeset       1155072  5 nvidia_drm<br>nvidia              39682048  229 nvidia_modeset<br>drm_kms_helper        311296  1 nvidia_drm<br>drm                   634880  7 drm_kms_helper,nvidia,nvidia_drm</pre><p>nvidia-smi</p><pre>$ nvidia-smi -L<br>GPU 0: NVIDIA GeForce RTX 3060</pre><h3>Note</h3><p>I tested <a href="https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#open-gpu-kernel-modules">NVIDIA Open GPU Kernel Modules</a> on Rocky Linux 9.0 with GeForce GTX 3060, and It doesn’t work even if I enabled experimental support for GeForce by following settings:</p><pre>echo &quot;options nvidia NVreg_OpenRmEnableUnsupportedGpus=1&quot; | sudo tee /etc/modprobe.d/nvidia-gsp.conf</pre><p><a href="https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#open-gpu-kernel-modules">Installation Guide Linux :: CUDA Toolkit Documentation</a></p><p>Official Runfile Installation Procedures</p><p><a href="https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#runfile">Installation Guide Linux :: CUDA Toolkit Documentation</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=166d7ce111b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Warewulf v4 iPXE Node Provisioning Explained]]></title>
            <link>https://medium.com/@panda1100/warewulf-v4-ipxe-node-provisioning-explained-189422b10486?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/189422b10486</guid>
            <category><![CDATA[ipxe]]></category>
            <category><![CDATA[provisioning]]></category>
            <category><![CDATA[hpc]]></category>
            <category><![CDATA[warewulf]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Fri, 08 Jul 2022 06:51:34 GMT</pubDate>
            <atom:updated>2022-07-09T10:03:20.752Z</atom:updated>
            <content:encoded><![CDATA[<p>In this short note, Warewulf v4 iPXE node provisioning process is briefly explained. At the time I wrote this article, Warewulf version 4.3.0 is already released, but I wrote this based on version 4.2.0.</p><p>This short note is based on my personal research as a Warewulf user, so if you find my misunderstanding of the provisioning process, please leave a comment below.</p><h3>Compute Node Provisioning Process</h3><p><a href="https://medium.com/@panda1100/warewulf-v4-sandboxing-environment-on-kvm-using-vagrant-f0e23fc1ce52">After setup Warewulf on your management node</a>, on DHCP server settings file /etc/dhcp/dhcpd.conf , there are following lines related to iPXE boot:</p><pre>if exists user-class and option user-class = &quot;iPXE&quot; {<br>    filename &quot;<a href="http://10.0.0.254:9873/ipxe/$%7Bmac:hexhyp"><strong>http://</strong>10.0.0.254:9873/ipxe/${mac:hexhyp</a>}&quot;;<br>} else {<br>    if option architecture-type = 00:0B {<br>        filename &quot;/warewulf/arm64.efi&quot;;<br>#    } elsif option architecture-type = 00:0A {<br># Still need to add this to staticfiles<br>#        filename &quot;/warewulf/arm32.efi&quot;;<br>    } elsif option architecture-type = 00:09 {<br>        filename &quot;/warewulf/x86.efi&quot;;<br>    } elsif option architecture-type = 00:07 {<br>        filename &quot;<strong>/warewulf/x86.efi</strong>&quot;;<br>    } elsif option architecture-type = 00:06 {<br>        filename &quot;/warewulf/i386.efi&quot;;<br>    } elsif option architecture-type = 00:00 {<br>        filename &quot;/warewulf/i386.kpxe&quot;;<br>    }<br>}</pre><p>When compute node initiated, PXE client access to DHCP server on Warewulf management node, and download iPXE client binary (UEFI bootloader) from TFTP server. /warewulf/x86.efi is iPXE client binary that built for x86/x86_64 architecture (usually called ipxe.efi).</p><p>If your motherboard’s UEFI firmware has iPXE client, above iPXE client downloading process is skipped.</p><p>After then, iPXE client connect to DHCP sever on Warewulf management node, and DHCP server tells iPXE client to access <a href="http://10.0.0.254:9873/ipxe/$%7Bmac:hexhyp%7D">http://10.0.0.254:9873/ipxe/${mac:hexhyp}</a> to download iPXE script. This iPXE script is based on template, that sits on /etc/warewulf/ipxe/default.ipxe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T8_MhYmg5hr9IBvsdC87kg.png" /></figure><p>This iPXE script boot your compute node with a specified kernel vmlinuz and layered initramfs. Layered initramfs consists of 3 components, 1) base container image rocky-8.img.gz, 2) kernel modules kmods.img and 3) system overlay. Those file are placed on /var/warewulf/provision .</p><pre>[root@httpsboot-srv warewulf]# tree /var/warewulf/provision/<br>provision/<br>├── container<br>│   └── <strong>rocky-8.img.gz</strong><br>└── <strong>kernel</strong><br>    └── <strong>4.18.0-348.20.1.el8_5.x86_64</strong><br>        ├── <strong>kmods.img</strong><br>        ├── version<br>        └── <strong>vmlinuz</strong></pre><pre>3 directories, 4 files</pre><p>After compute node successfully booted with above files, SystemD launches system services including wwclient. And then, wwclient pulls <strong>runtime overlay</strong> from Warewulf management node to complete compute node provisioning process 🎉</p><h3>Appendix</h3><p>Here is an example tree structure of default system/runtime overlay.</p><pre>[root@httpsboot-srv warewulf]# tree /var/warewulf/overlays<br>overlays<br>├── runtime<br>│   └── default<br>│       ├── etc<br>│       │   ├── group.ww<br>│       │   ├── hosts.ww<br>│       │   └── passwd.ww<br>│       └── root<br>└── system<br>    └── default<br>        ├── etc<br>        │   ├── fstab<br>        │   ├── hostname.ww<br>        │   ├── network<br>        │   │   ├── interfaces<br>        │   │   └── interfaces.d<br>        │   │       └── eth0.ww<br>        │   ├── ssh<br>        │   │   ├── ssh_host_dsa_key.pub.ww<br>        │   │   ├── ssh_host_dsa_key.ww<br>        │   │   ├── ssh_host_ecdsa_key.pub.ww<br>        │   │   ├── ssh_host_ecdsa_key.ww<br>        │   │   ├── ssh_host_ed25519_key.pub.ww<br>        │   │   ├── ssh_host_ed25519_key.ww<br>        │   │   ├── ssh_host_rsa_key.pub.ww<br>        │   │   └── ssh_host_rsa_key.ww<br>        │   ├── sysconfig<br>        │   │   ├── network-scripts<br>        │   │   │   ├── ifcfg-eth0.ww<br>        │   │   │   └── ifcfg-eth1.ww<br>        │   │   └── network.ww<br>        │   ├── systemd<br>        │   │   └── network<br>        │   │       └── 10-persistent-net.link.ww<br>        │   ├── warewulf<br>        │   │   └── warewulf.conf.ww<br>        │   └── wicked<br>        │       └── ifconfig<br>        │           └── ifcfg-eth0.xml.ww<br>        ├── init<br>        └── warewulf<br>            ├── bin<br>            │   └── wwclient<br>            ├── config.ww<br>            ├── init.d<br>            │   ├── 20-loopback<br>            │   ├── 50-ipmi<br>            │   ├── 75-vnfs_fixes<br>            │   ├── 80-wwclient<br>            │   └── 90-selinux<br>            └── wwinit</pre><pre>20 directories, 30 files</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=189422b10486" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Elastic Container Registry as Apptainer image registry]]></title>
            <link>https://medium.com/@panda1100/aws-elastic-container-registry-as-apptainer-image-registry-bc82eca59375?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc82eca59375</guid>
            <category><![CDATA[aor]]></category>
            <category><![CDATA[aws-ecr]]></category>
            <category><![CDATA[registry]]></category>
            <category><![CDATA[apptainer]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Tue, 28 Jun 2022 01:04:19 GMT</pubDate>
            <atom:updated>2022-06-28T01:06:54.066Z</atom:updated>
            <content:encoded><![CDATA[<p>This short note shows you how to push/pull your Apptainer SIF image to/from AWS ECR (Elastic Container Registry).</p><ol><li>Create your private repository called alpine on AWS Elastic Container Registry.</li><li>Create a SIF file for testing apptainer pull docker://alpine</li><li>Log-in to ECR using apptainer remote login. (AmazonEC2ContainerRegistryFullAccess is required.)</li></ol><pre>$ aws ecr get-login-password --region ap-northeast-1 | apptainer remote login --username <strong>AWS</strong> --password-stdin oras://XXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com</pre><p>4. Check your remote list</p><pre>$ apptainer remote list</pre><pre>Authenticated Logins<br>=================================</pre><pre>URI                                                       INSECURE<br>oras://XXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com  NO</pre><p>5. push your alpine_latest.sif to ECR</p><pre>apptainer push alpine_latest.sif oras://XXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/alpine:latest</pre><p>6. pull alpine:latest from ECR ( -F is for force overwrite an image file)</p><pre>apptainer pull -F oras://XXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/alpine:latest</pre><p>7. check pulled image</p><pre>$ ./alpine_latest.sif cat /etc/os-release<br>NAME=&quot;Alpine Linux&quot;<br>ID=alpine<br>VERSION_ID=3.16.0<br>PRETTY_NAME=&quot;Alpine Linux v3.16&quot;<br>HOME_URL=&quot;<a href="https://alpinelinux.org/">https://alpinelinux.org/</a>&quot;<br>BUG_REPORT_URL=&quot;<a href="https://gitlab.alpinelinux.org/alpine/aports/-/issues">https://gitlab.alpinelinux.org/alpine/aports/-/issues</a>&quot;</pre><p>Voila!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc82eca59375" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apptainer without root privilege]]></title>
            <link>https://medium.com/@panda1100/apptainer-without-root-privilege-b21695ecfc42?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/b21695ecfc42</guid>
            <category><![CDATA[non-root]]></category>
            <category><![CDATA[apptainer]]></category>
            <category><![CDATA[unprivileged]]></category>
            <category><![CDATA[squashfuse]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Mon, 20 Jun 2022 06:26:38 GMT</pubDate>
            <atom:updated>2022-06-21T03:34:29.494Z</atom:updated>
            <content:encoded><![CDATA[<h4>Through Installation of relocatable Apptainer to mounting/running SIF on unprivileged computing environment</h4><p>This article shows you what non-root user can do with SIF using Apptainer current main branch today without the help of root privilege.</p><h3>Background</h3><p>Apptainer supports unprivileged installation since a long time ago and became <strong>relocatable</strong> only for unprivileged installations since at the era of Singularity v3.8.</p><p>And now current main branch today (full SHA: <a href="https://github.com/apptainer/apptainer/tree/7add3046f12227d1d94a5401a8a6588cbfce4dd2">7add3046f12227d1d94a5401a8a6588cbfce4dd2</a>) supports <strong>mounting and running SIF without root privilege by using squashfuse</strong>.</p><p>Apptainer also supports building SIF without root privilege using fakeroot feature. To enable this feature for non-root user, we need to configure the system with apptainer config fakeroot command that needs root privilege for its execution. This article focused on non-root user workflow, so this topic does not cover in this article.</p><h3>Scenario</h3><p>You have own Rocky Linux 8 box that you have root privilege. And you have access to Rocky Linux 8 based HPC cluster that you don’t have root privilege and that unluckily lacks Apptainer from its setups.</p><p>Apptainer unprivileged installation is relocatable. So, we build Apptainer on our own box and copy that relocatable binaries to HPC cluster.</p><h3>Unprivileged Installation of relocatable Apptainer</h3><p>To build relocatable Apptainer, let’s install dependencies to your box <strong>using root privilege 😅</strong></p><pre>$ sudo yum update -y &amp;&amp; <strong>\</strong><br>     sudo yum groupinstall -y &#39;Development Tools&#39; &amp;&amp; <strong>\</strong><br>     sudo yum install -y <strong>\</strong><br>     openssl-devel <strong>\</strong><br>     libuuid-devel <strong>\</strong><br>     libseccomp-devel <strong>\</strong><br>     wget <strong>\</strong><br>     squashfs-tools <strong>\</strong><br>     cryptsetup</pre><p>Next, install Go</p><pre>$ export VERSION=1.18.1 OS=linux ARCH=amd64 &amp;&amp; \<br>    wget <a href="https://dl.google.com/go/go$VERSION.$OS-$ARCH.tar.gz">https://dl.google.com/go/go$VERSION.$OS-$ARCH.tar.gz</a> &amp;&amp; \<br>    sudo tar -C /usr/local -xzvf go$VERSION.$OS-$ARCH.tar.gz &amp;&amp; \<br>    rm go$VERSION.$OS-$ARCH.tar.gz</pre><p>Setup environmental variables</p><pre>$ echo &#39;export GOPATH=${HOME}/go&#39; &gt;&gt; ~/.bashrc &amp;&amp; \<br>    echo &#39;export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin&#39; &gt;&gt; ~/.bashrc &amp;&amp; \<br>    source ~/.bashrc</pre><p>Git clone main branch of Apptainer</p><pre>$ git clone <a href="https://github.com/apptainer/apptainer.git">https://github.com/apptainer/apptainer.git</a></pre><p>Change directory to apptainer</p><pre>$ cd apptainer</pre><p>Configure Apptainer as unprivileged mode (assumes your username is rocky )</p><pre>$ ./mconfig --without-suid --prefix=/home/rocky/apptainer &amp;&amp; \<br>    make -C ./builddir &amp;&amp; \<br>    make -C ./builddir install</pre><p>Archive apptainer to be ready for transfer</p><pre>$ tar zcvf apptainer.tgz /home/rocky/apptainer</pre><p>scp to HPC cluster from your box</p><pre>$ scp apptainer.tgz rocky@YOUR_AWESOME_ROCKY_BASED_HPC:/home/rocky</pre><p>On HPC cluster, unarchiving apptainr.tgz</p><pre>$ ssh rocky@YOUR_AWESOME_ROCKY_BASED_HPC<br>$ tar zxvf apptainer.tgz</pre><p>and setup environmental variables</p><pre>$ echo &#39;export PATH=~/apptainer/bin:$PATH&#39; &gt;&gt; ~/.bashrc &amp;&amp; \<br>$ source ~/.bashrc</pre><p>Verify</p><pre>$ apptainer --version</pre><h3>Building SIF</h3><p>Create lolcow.def as described below <strong>on your own box</strong>.</p><pre>BootStrap: docker<br>From: ubuntu:22.04</pre><pre>%post<br>    apt-get -y update<br>    apt-get -y install fortune cowsay lolcat</pre><pre>%environment<br>    export LC_ALL=C<br>    export PATH=/usr/games:$PATH</pre><pre>%runscript<br>    fortune | cowsay | lolcat</pre><p>Install “standard” Apptainer to your own box using official rpm package</p><pre>$ wget <a href="https://github.com/apptainer/apptainer/releases/download/v1.0.2/apptainer-1.0.2-1.x86_64.rpm">https://github.com/apptainer/apptainer/releases/download/v1.0.2/apptainer-1.0.2-1.x86_64.rpm</a><br>$ sudo dnf install apptainer-1.0.2-1.x86_64.rpm</pre><p>Build SIF with root privilege</p><pre>$ sudo apptainer build lolcow.sif lolcow.def</pre><p>scp to HPC cluster from your box</p><pre>$ scp lolcow.sif rocky@YOUR_AWESOME_ROCKY_BASED_HPC:/home/rocky</pre><h3>Running SIF</h3><p>Let’s run SIF using non-root version of Apptainer! 🎉</p><pre>$ ./lolcow.sif</pre><pre>/ Q: How do you save a drowning lawyer? \<br>\ A: Throw him a rock.                  /<br> ---------------------------------------<br>        \   ^__^<br>         \  (oo)\_______<br>            (__)\       )\/\<br>                ||----w |<br>                ||     ||</pre><p>Verbose mode and time command</p><pre>$ time apptainer -vvv run ./lolcow.sif</pre><p>If HPC cluster doesn’t have <strong>squashfuse</strong>, Apptainer automatically converts SIF to sandbox.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aebe29f61f22476879cef594862c614f/href">https://medium.com/media/aebe29f61f22476879cef594862c614f/href</a></iframe><p>If HPC cluster has <strong>squashfuse</strong>, Apptainer mounts SIF using squashfuse. A little bit faster than those without squashfuse even if lolcow.sif is just 78MB.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e84cdb684897038f367f573f602d175d/href">https://medium.com/media/e84cdb684897038f367f573f602d175d/href</a></iframe><p>With an official Apptainer binaries (setuid SIF mounts).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54c058aad499dd8dc8f93a81257aca4a/href">https://medium.com/media/54c058aad499dd8dc8f93a81257aca4a/href</a></iframe><p>[INFO] Above results are one-shot measurement.</p><h3>References</h3><p><a href="https://github.com/apptainer/apptainer/pull/386">Add internal squashfuse image driver by DrDaveD · Pull Request #386 · apptainer/apptainer</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b21695ecfc42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hands-on Guide to Netmaker v0.14.2]]></title>
            <link>https://medium.com/@panda1100/hands-on-guide-to-netmaker-v0-14-2-4e80d4ad0347?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e80d4ad0347</guid>
            <category><![CDATA[netmaker]]></category>
            <category><![CDATA[mesh-networks]]></category>
            <category><![CDATA[tls-passthrough]]></category>
            <category><![CDATA[wireguard]]></category>
            <category><![CDATA[traefik]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Fri, 03 Jun 2022 01:20:36 GMT</pubDate>
            <atom:updated>2022-06-07T00:14:17.573Z</atom:updated>
            <content:encoded><![CDATA[<h4>Wireguard Mesh Network</h4><h4>Traefik version</h4><p>This hands-on guide shows you how to set-up Office-Home Wireguard mesh network using <strong>Netmaker v0.14.2</strong>. New version utilizes less open port than <a href="https://medium.com/@panda1100/hands-on-guide-to-netmaker-v0-13-1-caec629a597d">previous version</a> (technical details, please read my article <a href="https://medium.com/@panda1100/a-solution-to-use-port-443-for-client-certificate-authentication-of-netmaker-v0-14-0-455777589b12">here</a>), 443/tcp for Netmaker components and 51821–51380/udp for Wireguard as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zmNLWhHzfK-TWc1n081wjA.png" /><figcaption>A Example System Architecture of Netmaker</figcaption></figure><h3>Scenario</h3><p>Office network has dynamic global IP that binds to office router and office workstation is behind a NAT. Home network also has dynamic global IP that binds to home router and home PC is behind a NAT. Netmaker (server) will place on cloud and static global IP is attached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*75zbjX0ItUCqlFn-.png" /></figure><h3>Installation of Netmaker</h3><p>Before install Netmaker, let’s create a VM on your preferred cloud. This guide will use Lightsail on AWS.</p><h3>VM preparation</h3><ul><li>Create a VM with 4GB of memory and 2 vCPU running Ubuntu 22.04</li><li>Attach static global IP to your VM</li><li>Add wildcard A record to your DNS that points to the public IP of your VM</li><li>Allow 8̶0̶/̶t̶c̶p̶, <strong>443/tcp</strong>, ̶8̶8̶8̶3̶/̶t̶c̶p̶, <strong>51821–51830/udp</strong> from 0.0.0.0/0</li><li>Install dependencies to your VM ( sudo apt update &amp;&amp; sudo apt install -y docker.io docker-compose wireguard)</li></ul><h3>Server-side Installation</h3><p>Once you booted up Ubuntu box, download docker-compose.yml file from Netmaker repository.</p><pre>$ sudo su -<br>$ wget -O docker-compose.yml \<br>https://raw.githubusercontent.com/gravitl/netmaker/v0.14.2/compose/<strong>docker-compose.traefik.yml</strong></pre><p>Set your e-mail address for creating/renewing certificate from Let’s Encrypt.</p><pre>$ sed -i &#39;s/YOUR_EMAIL/traefik@example.jp/g&#39; docker-compose.yml</pre><p>Set your base domain, this domain should be matched to wildcard A record that you added to your DNS. Here is the example command that assumes your wildcard A record looks like *.netmaker.example.jp A 54.XXX.YYY.ZZZ</p><pre>$ sed -i &#39;s/NETMAKER_BASE_DOMAIN/netmaker.example.jp/g&#39; docker-compose.yml</pre><p>Set your server IP (global IP).</p><pre>$ curl ifconfig.me<br>54.XXX.YYY.ZZZ<br>$ sed -i &#39;s/SERVER_PUBLIC_IP/54.XXX.YYY.ZZZ/g&#39; docker-compose.yml</pre><p>Set your CoreDNS IP. If you run VM on AWS, global IP is not directly bind to network interface of VM. In such a case, we need to set the IP of the default interface.</p><pre>$ (ip route get 1 | sed -n &#39;s/^.*src \([0-9.]*\) .*$/<strong>\1</strong>/p&#39;)<br>172.XXX.YYY.ZZZ<br>$ sed -i &#39;s/COREDNS_IP/172.XXX.YYY.ZZZ/g&#39; docker-compose.yml</pre><p>Generate a master key and populate it.</p><pre>$ tr -dc A-Za-z0-9 &lt;/dev/urandom | head -c 30 ; echo &#39;&#39;<br>8I9Ifom5xfiEVrcatsfsXXXXXXXXXX<br>sed -i &#39;s/REPLACE_MASTER_KEY/8I9Ifom5xfiEVrcatsfsXXXXXXXXXX/g&#39; docker-compose.yml</pre><p>Prepare MQ</p><pre>wget -O /root/mosquitto.conf \<br><a href="https://raw.githubusercontent.com/gravitl/netmaker/v0.13.1/docker/mosquitto.conf">https://raw.githubusercontent.com/gravitl/netmaker/v0.14.2/docker/mosquitto.conf</a></pre><p>Let’s spin up Netmaker</p><pre>docker-compose up -d</pre><h3>Web UI</h3><p>Open https://dashboard.netmaker.example.jp on your browser and create an admin user to get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*B6QaHLq2tasz_wqx.png" /></figure><p>Log-in to web UI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2kDbbjtTYQFfrXq4.png" /></figure><p>Create Network</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*txRzkldbl9q73NXi.png" /></figure><p>Create network called awesome</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GMdbuEBbpfPZ3ONa.png" /></figure><p>Click network name to configure this network</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wmOv7vZTPr-h4tPq.png" /></figure><p>Create Access Key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KUVIacCsDNiaVzBr.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ihTHDG_n3xxYQAfc.png" /></figure><p>Set number to Usesthat satisfies expected user volume</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4djBEgv_SdkzzYJE.png" /></figure><p>Keep open this page for later use of <strong>“Join Command”</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DtJdVxoPYTb2ygJ_vPcYrA.png" /></figure><p>Click “VIEW NETCLIENT INSTLL INSTRUCTIONS” to see client side installation procedure.</p><h3>Installation of Netclient (Office Workstation &amp; Home PC)</h3><h3>Install dependencies</h3><pre>sudo apt update &amp;&amp; sudo apt install -y wireguard</pre><h4>Install Netclient and Join to Netmaker network</h4><p>Open terminal to install netclient from official repository this procedure assumes Ubuntu as Office WS and Home PC)</p><pre>curl -sL &#39;https://apt.netmaker.org/gpg.key&#39; | sudo tee /etc/apt/trusted.gpg.d/netclient.asc<br>curl -sL &#39;https://apt.netmaker.org/debian.deb.txt&#39; | sudo tee /etc/apt/sources.list.d/netclient.list<br>sudo apt update<br>sudo apt install netclient</pre><p>Join to Netmaker network using <strong>“Join Command”</strong> above.</p><pre>netclient join -t eyJhcGljb25uc3RyaW5nIjoiYXBpLm5ldXXXXXXXXXXXXXX=</pre><p>You will see similar outputs as follows:</p><pre>[netclient] 2022-06-03 00:59:25 joining awesome at api.netmaker.example.jp:443<br>[netclient] 2022-06-03 00:59:25 starting wireguard<br>[netclient] 2022-06-03 00:59:28 certificates/key saved<br>[netclient] 2022-06-03 00:59:28 sent a node update to server for node ip-172-XXX-YYY-ZZZ ,  aaccb4a6-7f8c-4d43-a49f-XXXXXXXXXXX</pre><p>You can check your netclient status with:</p><pre>systemctl status netclient</pre><p>Let’s check IP of nm-awesome device on Office workstation.</p><pre>$ ip a<br><strong>nm-awesome</strong>: &lt;POINTOPOINT,NOARP,UP,LOWER_UP&gt; mtu 1280 qdisc noqueue state UNKNOWN group default qlen 1000<br>    link/none<br>    inet <strong>192.168.110.1/32</strong> scope global nm-awesome<br>       valid_lft forever preferred_lft forever<br><strong>bond0</strong>: &lt;BROADCAST,MULTICAST,MASTER,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP group default qlen 1000<br>    link/ether de:AA:BB:CC:DD:EE brd ff:ff:ff:ff:ff:ff<br>    inet <strong>10.0.0.254/20</strong> brd 10.0.0.1 scope global bond0<br>       valid_lft forever preferred_lft forever</pre><p>Check IP of nm-awesome device on Home PC</p><pre>$ ip a<br><strong>nm-awesome</strong>: &lt;POINTOPOINT,NOARP,UP,LOWER_UP&gt; mtu 1280 qdisc noqueue state UNKNOWN group default qlen 1000<br>    link/none<br>    inet <strong>192.168.110.2/32</strong> scope global nm-awesome<br>       valid_lft forever preferred_lft forever</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7_visYz7wecQOy2dON7BhA.png" /><figcaption>Wireguard Mesh Networking using Netmaker</figcaption></figure><p>Ping office workstation from home PC.</p><pre>$ ping 192.168.110.1</pre><p>If ping doesn’t reach, check wireguard connection with wg show on home PC.</p><pre>$ wg show<br>interface: nm-awesome<br>  public key: i3c2HJr+LpXBKv9d166OwPE7ZkMHOwsG/XXXXXXX=<br>  private key: (hidden)<br>  listening port: 43449peer: pvQRAMxKGh8Lzj4Mt3lHqYJesJZ2uXXXXXXX=<br>  endpoint: 54.XXX.YYY.ZZZ:51821<br>  allowed ips: 192.168.110.254/32, 192.168.110.0/24<br>  latest handshake: 50 seconds ago<br>  transfer: <strong>0 B received</strong>, 48.56 KiB sent<br>  persistent keepalive: every 20 seconds</pre><p>If you see 0B received that means wireguard connection is not established. Sometimes MTU is a cause, but since Netmaker’s default MTU is low enough, I’ll explain another possibility such as ”UDP hole punching doesn’t work” case.</p><h3>UDP hole punching</h3><p>When we create awesome network, we enabled UDP hole punching . This is convenient <strong>if your consumer grade router is UPnP enabled</strong> that automatically open UDP port to the public for you and map that port to your netclient installed PC.</p><p>If your router does not support or disabled UPnP, you need to configure your router manually. You need to open udp port to the public, for example 51821/udp, for wireguard connection and map that port to your PC that is netclient installed. If there is a firewall you also need to change that settings to allow wireguard connections.</p><p>But not always you can administer a router/firewall on both end. If you can’t change settings of office router/firewall, it’s time to make use of <strong>Relay</strong> functionality of Netmaker.</p><h3>Relay</h3><p>You can setup Netmaker server as a Relay. Open Nodes tab of Netmaker web UI. Click “Make Relay” of netmaker-1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ru4hPw84mOCYtoYFtOPq8Q.png" /></figure><p>Select office workstation , and click CREATE button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pWWqYkToKXhh-e-C.png" /></figure><p>Now your graph looks like below. If you connect to office workstation from home PC, all the traffic go through Netmaker server. If you place your Netmaker server on cloud, you need to watch transfer costs in some use cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uLZ0qFnNDMz2yNmVP2wQDg.png" /></figure><p>Ping may work now.</p><pre>$ ping 192.168.110.1</pre><h3>Egress Gateway</h3><p>To access office network (ex. 10.0.10.0/24) from home PC. Configure office PC as Egress Gateway. Before hands, check route of office PC.</p><pre>$ route<br><strong>10.0.0.0        0.0.0.0 255.255.240.0   U  0 0 0 bond0</strong><br>192.168.110.0   0.0.0.0 255.255.255.0   U  0 0 0 nm-awesome<br>home-pc.aweso   0.0.0.0 255.255.255.255 UH 0 0 0 nm-awesome<br>netmaker-1.awes 0.0.0.0 255.255.255.255 UH 0 0 0 nm-awesome</pre><p>Click Nodes &gt; Create Egress Gateway</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BPv5DOwfX0ONBDq5pNqXzg.png" /></figure><p>Set Egress Gateway Range, 10.0.10.0/24 , this could be a subnet in your office.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GvOqbyx5t84kxzQ2.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IO7RjBHF5MSDmfhK4tvZBQ.png" /></figure><h3>Access Office Network from Home PC</h3><p>Check route of home PC.</p><pre>$ route<br>10.0.10.0      0.0.0.0  255.255.255.0  U  0  0  0  nm-awesome<br>192.168.110.0  0.0.0.0  255.255.255.0  U  0  0  0  nm-awesome</pre><p>If route doesn’t appear, manually pull configuration from Netmaker. Then check route again.</p><pre>sudo netclient pull</pre><p>SSHing to PC (10.0.10.5) in office network from home PC through office workstation 🚀</p><pre>$ ssh 10.0.10.5 -l user -i .ssh/id_rsaWelcome to Ubuntu 20.04.2 LTS<br>user@ws5:~#</pre><h3>References</h3><p><a href="https://medium.com/@panda1100/a-solution-to-use-port-443-for-client-certificate-authentication-of-netmaker-v0-14-0-455777589b12">MQTT with TLS client authentication on port 443 using Traefik v2 TLS Passthrough applied to…</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e80d4ad0347" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Setup Layer 4 Reverse Proxy to Multiplex TLS Traffic with SNI Routing using Caddy-L4]]></title>
            <link>https://medium.com/@panda1100/how-to-setup-layer-4-reverse-proxy-to-multiplex-tls-traffic-with-sni-routing-a226c8168826?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/a226c8168826</guid>
            <category><![CDATA[netmaker]]></category>
            <category><![CDATA[sni-routing]]></category>
            <category><![CDATA[layer-4]]></category>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[tls-passthrough]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Fri, 27 May 2022 06:51:53 GMT</pubDate>
            <atom:updated>2022-05-27T10:11:45.814Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, how to setup a <strong>layer 4 reverse proxy</strong> to multiplex TLS traffic on port 443 with SNI routing is explained. <a href="https://www.netmaker.org/">Netmaker</a> deployment is used as an example. <a href="https://github.com/mholt/caddy-l4"><strong>mholt/caddy-l4</strong></a>, Layer 4 (TCP/UDP) app for <a href="https://caddyserver.com/">Caddy</a>, is employed as a layer 4 reverse proxy. (Traefik v2 version is <a href="https://medium.com/@panda1100/a-solution-to-use-port-443-for-client-certificate-authentication-of-netmaker-v0-14-0-455777589b12">here</a>.)</p><h3>1. Introduction</h3><p>Here is a schematic of Netmaker deployment example to give you an overview of this project. Before going into details, I’ll try to explain Netmaker briefly on next paragraph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nUkxPyayv3YEwYzaAQiFZA.png" /></figure><h4>Netmaker</h4><p>Netmaker is a tool to create Wireguard mesh networks at the speed of light. It consists of 2 major components, Netmaker and Netclient. Netmaker serves Wireguard peers information through Secure MQTT network and delivers client certificate and public key for securing transport layer and data layer through API.</p><h4>Netmaker System architecture</h4><p>Official example of Netmaker deployment consists of 5 components:</p><ol><li>API server on port 8081/tcp</li><li>Dashboard (Web UI for administer Netmaker network) on port 8082/tcp</li><li>Mosquitto broker on port 8883/tcp and it terminates TLS connection if client certificate authentication is succeeded</li><li>Backend database</li><li><strong>Layer 7 reverse proxy</strong> such as Caddy on port 443/tcp and it terminates TLS connection.</li></ol><p>Layer 7 reverse proxy stands in front of API server and Dashboard and waiting for connection on port 443/tcp from 0.0.0.0/0 . And that routes incoming requests to the backend such as API server and Dashboard by using its URL. And 8883/tcp is directly exposed to 0.0.0.0/0 , it’s not going through reverse proxy.</p><h3>2. Why Layer 4 Reverse Proxy and SNI routing?</h3><p>In some cases, access to 8883/tcp from 0.0.0.0/0 , this port is for secure MQTT, is not allowed by firewall policy. This can be a headache of Netmaker user and more generally IoT engineers.</p><p><a href="https://aws.amazon.com/jp/blogs/iot/mqtt-with-tls-client-authentication-on-port-443-why-it-is-useful-and-how-it-works/">The AWS IoT Core service is provide TLS client authentication on port 443 for its MQTT</a>. This is achieved by layer 4 reverse proxy (or layer 4 load balancer: L4LB). That doesn’t terminates TLS connection by itself but passthrough TLS handshake requests to its backend. If you serve multiple services on single global IP with on port 443, API server, Dashboard and Mosquitto broker in our case, you need to properly routes incoming TLS handshake requests on port 443/tcp to its backend. <strong>This is where SNI routing is coming in</strong>. SNI (Server Name Indication) is an extension to the Transport Layer Security protocol. SNI routing is routes incoming requests by using SNI that embedded in Client Hello message at the start of TLS handshake process.</p><h3>3. Setup Procedures</h3><h4>Server-side Installation</h4><h4>VM preparation</h4><p>Create a VM on your preferred cloud. This guide will use Lightsail on AWS.</p><ul><li>Create a VM with 4GB of memory and 2 vCPU running Ubuntu 22.04</li><li>Attach static global IP to your VM</li><li>Add wildcard A record to your DNS that points to the public IP of your VM</li><li>Allow 80/tcp, 443/tcp, ̶<strong>8̶8̶8̶3̶/̶t̶c̶p̶</strong>, 51821–51830/udp from 0.0.0.0/0</li><li>Install dependencies to your VM ( sudo apt update &amp;&amp; sudo apt install -y docker.io docker-compose wireguard)</li></ul><p>In the firewall settings, allow 443/tcp from 0.0.0.0/0 for Netmaker components, and allow 51821-51380/udp from 0.0.0.0/0 for Wireguard connection.</p><h4>Layer 4 Reverse Proxy</h4><p>Let’s setup layer 4 reverse proxy, we use <a href="https://github.com/mholt/caddy-l4">mholt/caddy-l4</a> at this time.</p><pre>$ sudo su -<br>$ mkdir -p /root/layer4_sni/caddy-l4</pre><p>Here is my multi-stage Dockerfile for caddy-l4. Place this file to /root/layer4_sni/caddy-l4/Dockerfile . This Dockerfile first builds Caddy with caddy-l4 app, and then copy its binary to runtime environment based on official Caddy Dockerfile.</p><pre># syntax=docker/dockerfile:1<br>FROM golang:1.18-alpine AS builder<br>RUN apk add --no-cache git ca-certificates<br>RUN go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest<br>RUN xcaddy build --with github.com/mholt/caddy-l4 --output /usr/bin/caddy &amp;&amp; chmod +x /usr/bin/caddy</pre><pre>FROM alpine:3.15<br>RUN apk add --no-cache ca-certificates mailcap<br>RUN set -eux; \<br>	mkdir -p \<br>		/config/caddy \<br>		/data/caddy \<br>		/etc/caddy \<br>		/usr/share/caddy# set up nsswitch.conf for Go&#39;s &quot;netgo&quot; implementation<br># - <a href="https://github.com/docker-library/golang/blob/1eb096131592bcbc90aa3b97471811c798a93573/1.14/alpine3.12/Dockerfile#L9">https://github.com/docker-library/golang/blob/1eb096131592bcbc90aa3b97471811c798a93573/1.14/alpine3.12/Dockerfile#L9</a><br>RUN [ ! -e /etc/nsswitch.conf ] &amp;&amp; echo &#39;hosts: files dns&#39; &gt; /etc/nsswitch.conf# See <a href="https://caddyserver.com/docs/conventions#file-locations">https://caddyserver.com/docs/conventions#file-locations</a> for details<br>ENV XDG_CONFIG_HOME /config<br>ENV XDG_DATA_HOME /dataEXPOSE 80<br>EXPOSE 443<br>EXPOSE 2019COPY --from=builder /usr/bin/caddy /usr/bin/caddyWORKDIR /srv<br>CMD [&quot;caddy&quot;, &quot;run&quot;, &quot;--config&quot;, &quot;config.json&quot;]</pre><h4>Netmaker</h4><p>Create docker-compose.yml for Netmaker and layer 4 reverse proxy and place it to /root/layer4_sni/docker-compose.yml .</p><pre>version: &quot;3.4&quot;</pre><pre>services:<br>  netmaker:<br>    container_name: netmaker<br>    build: netmaker<br>    image: panda1100/l4-netmaker<br>    volumes:<br>      - dnsconfig:/root/config/dnsconfig<br>      - sqldata:/root/data<br>      - ${PWD}/certs:/etc/netmaker/<br>    cap_add:<br>      - NET_ADMIN<br>      - NET_RAW<br>      - SYS_MODULE<br>    sysctls:<br>      - net.ipv4.ip_forward=1<br>      - net.ipv4.conf.all.src_valid_mark=1<br>      - net.ipv6.conf.all.disable_ipv6=0<br>      - net.ipv6.conf.all.forwarding=1<br>    restart: always<br>    environment:<br>      SERVER_NAME: &quot;broker.NETMAKER_BASE_DOMAIN&quot;<br>      SERVER_HOST: &quot;SERVER_PUBLIC_IP&quot;<br>      SERVER_API_CONN_STRING: &quot;api.NETMAKER_BASE_DOMAIN:443&quot;<br>      COREDNS_ADDR: &quot;SERVER_PUBLIC_IP&quot;<br>      DNS_MODE: &quot;on&quot;<br>      SERVER_HTTP_HOST: &quot;api.NETMAKER_BASE_DOMAIN&quot;<br>      API_PORT: &quot;8081&quot;<br>      CLIENT_MODE: &quot;on&quot;<br>      MASTER_KEY: &quot;REPLACE_MASTER_KEY&quot;<br>      CORS_ALLOWED_ORIGIN: &quot;*&quot;<br>      DISPLAY_KEYS: &quot;on&quot;<br>      DATABASE: &quot;sqlite&quot;<br>      NODE_ID: &quot;netmaker-server-1&quot;<br>      MQ_HOST: &quot;mq&quot;<br>      HOST_NETWORK: &quot;off&quot;<br>      VERBOSITY: &quot;1&quot;<br>      PORT_FORWARD_SERVICES: &quot;dns&quot;<br>      MANAGE_IPTABLES: &quot;on&quot;<br>    ports:<br>      - &quot;<strong>51821-51830:51821-51830/udp</strong>&quot;<br>      - &quot;<strong>18081</strong>:8081&quot;<br>  netmaker-ui:<br>    container_name: netmaker-ui<br>    depends_on:<br>      - netmaker<br>    image: gravitl/netmaker-ui:v0.14.1<br>    links:<br>      - &quot;netmaker:api&quot;<br>    ports:<br>      - &quot;<strong>18082</strong>:80&quot;<br>    environment:<br>      BACKEND_URL: &quot;https://api.NETMAKER_BASE_DOMAIN&quot;<br>    restart: always<br>  coredns:<br>    depends_on:<br>      - netmaker<br>    image: coredns/coredns<br>    command: -conf /root/dnsconfig/Corefile<br>    container_name: coredns<br>    restart: always<br>    volumes:<br>      - dnsconfig:/root/dnsconfig<br>  caddy:<br>    build: <strong>caddy-l4</strong><br>    image: panda1100/caddy-l4:latest<br>    container_name: caddy<br>    restart: unless-stopped<br>    <strong>network_mode: host</strong> # Wants ports 80 and 443!<br>    volumes:<br>      - ${PWD}/config.json:/srv/config.json<br>      - ${PWD}/certs/:/srv/certs/<br>      # - $PWD/site:/srv # you could also serve a static site in site folder<br>      - caddy_data:/data<br>      - caddy_conf:/config<br>  mq:<br>    image: eclipse-mosquitto:2.0.11-openssl<br>    depends_on:<br>      - netmaker<br>    container_name: mq<br>    restart: unless-stopped<br>    ports:<br>      - &quot;127.0.0.1:1883:1883&quot;<br>      - &quot;<strong>8883</strong>:8883&quot;<br>    volumes:<br>      - ${PWD}/mosquitto.conf:/mosquitto/config/mosquitto.conf<br>      - ${PWD}/certs/:/mosquitto/certs/<br>      - mosquitto_data:/mosquitto/data<br>      - mosquitto_logs:/mosquitto/log<br>volumes:<br>  caddy_data: {}<br>  caddy_conf: {}<br>  sqldata: {}<br>  dnsconfig: {}<br>  mosquitto_data: {}<br>  mosquitto_logs: {}</pre><p>Create configuration file for caddy-l4 and place it to /root/layer4_sni/config.json .</p><p><strong>SNI routing is configured in this file</strong>. <strong>layer4 apps</strong> is listening on443/tcp to route TLS handshake based on SNI. If SNI matched to one of the rule written in configuration,<strong> layer4 app</strong> doesn’t terminate TLS handshake but passthrough to the corresponding backend.</p><p><strong>http app</strong> is listening on corresponding local port and receive TLS handshake from <strong>layer4 app</strong>, and then terminates TLS handshake for API server and Dashboard by using Let’s Encrypt certificate. After that, <strong>http app </strong>is<strong> </strong>reverse proxying request to the corresponding backend such as netmaker container listening on port 8081 and netmaker-ui container listening on port 8082.</p><p>If SNI is matched to broker at the <strong>layer4 app</strong>, <strong>layer4 app</strong> doesn’t terminate TLS handshake but passthrough to the Mosquitto broker, and Mosquitto broker terminates TLS connection if client certificate authentication is succeeded.</p><pre>{<br>  &quot;logging&quot;: {<br>        &quot;sink&quot;: {<br>                &quot;writer&quot;: {&quot;output&quot;: &quot;stdout&quot;}<br>        },<br>        &quot;logs&quot;: {<br>                &quot;&quot;: {<br>                        &quot;writer&quot;: {&quot;output&quot;: &quot;stdout&quot;},<br>                        &quot;level&quot;: &quot;debug&quot;<br>                }<br>        }<br>  },<br>  &quot;apps&quot;: {<br>    &quot;layer4&quot;: {<br>      &quot;servers&quot;: {<br>        &quot;netmaker&quot;: {<br>          &quot;listen&quot;: [&quot;:443&quot;],<br>          &quot;routes&quot;: [<br>            {<br>              &quot;match&quot;: [{&quot;tls&quot;: {}}],<br>              &quot;handle&quot;: [{<br>                &quot;handler&quot;: &quot;subroute&quot;,<br>                <strong>&quot;routes&quot;: [<br>                  {<br>                    &quot;match&quot;: [{&quot;tls&quot;: {&quot;sni&quot;: [&quot;broker.NETMAKER_BASE_DOMAIN&quot;]}}],<br>                    &quot;handle&quot;: [{&quot;handler&quot;: &quot;proxy&quot;, &quot;upstreams&quot;: [{&quot;dial&quot;: [&quot;localhost:8883&quot;]}]}]<br>                  },<br>                  {<br>                    &quot;match&quot;: [{&quot;tls&quot;: {&quot;sni&quot;: [&quot;api.NETMAKER_BASE_DOMAIN&quot;]}}],<br>                    &quot;handle&quot;: [{&quot;handler&quot;: &quot;proxy&quot;, &quot;upstreams&quot;: [{&quot;dial&quot;: [&quot;localhost:8081&quot;]}]}]<br>                  },<br>                  {<br>                    &quot;match&quot;: [{&quot;tls&quot;: {&quot;sni&quot;: [&quot;dashboard.NETMAKER_BASE_DOMAIN&quot;]}}],<br>                    &quot;handle&quot;: [{&quot;handler&quot;: &quot;proxy&quot;, &quot;upstreams&quot;: [{&quot;dial&quot;: [&quot;localhost:8082&quot;]}]}]<br>                  }<br>                ]</strong><br>              }]<br>            }<br>          ]<br>        }<br>      }<br>    },<br>    &quot;http&quot;: {<br>        &quot;servers&quot;: {<br>            &quot;api&quot;: {<br>                &quot;listen&quot;: [&quot;:8081&quot;],<br>                &quot;routes&quot;: [<br>                    {<br>                    &quot;handle&quot;: [{<br>                        &quot;handler&quot;: &quot;reverse_proxy&quot;,<br>                        &quot;upstreams&quot;: [<br>                            {<br>                            &quot;dial&quot;: &quot;127.0.0.1:18081&quot;<br>                            }<br>                        ]<br>                    }],<br>                    &quot;match&quot;: [<br>                        {<br>                        &quot;host&quot;: [<br>                            &quot;api.NETMAKER_BASE_DOMAIN&quot;<br>                        ]<br>                        }<br>                    ],<br>                    &quot;terminal&quot;: true<br>                }]<br>            },<br>            &quot;dashboard&quot;: {<br>                &quot;listen&quot;: [&quot;:8082&quot;],<br>                &quot;routes&quot;: [<br>                    {<br>                    &quot;handle&quot;: [{<br>                        &quot;handler&quot;: &quot;reverse_proxy&quot;,<br>                        &quot;upstreams&quot;: [<br>                            {<br>                            &quot;dial&quot;: &quot;127.0.0.1:18082&quot;<br>                            }<br>                        ]<br>                    }],<br>                    &quot;match&quot;: [<br>                        {<br>                        &quot;host&quot;: [<br>                            &quot;dashboard.NETMAKER_BASE_DOMAIN&quot;<br>                        ]<br>                        }<br>                    ],<br>                    &quot;terminal&quot;: true<br>                }]<br>            }</pre><pre>}<br>    },<br>    &quot;tls&quot;: {<br>        &quot;automation&quot;: {<br>          &quot;policies&quot;: [<br>            {<br>              &quot;issuers&quot;: [<br>                {<br>                  &quot;email&quot;: &quot;<strong>traefik@example.jp</strong>&quot;,<br>                  &quot;module&quot;: &quot;acme&quot;<br>                },<br>                {<br>                  &quot;email&quot;: &quot;<strong>traefik@example.jp</strong>&quot;,<br>                  &quot;module&quot;: &quot;zerossl&quot;<br>                }<br>              ],<br>              &quot;subjects&quot;: [<br>                &quot;dashboard.NETMAKER_BASE_DOMAIN&quot;,<br>                &quot;api.NETMAKER_BASE_DOMAIN&quot;<br>              ]<br>            }<br>          ]<br>        }<br>    }<br>  }<br>}</pre><p>Clone git repository for this PoC project. The only difference from original repository is that MQTT broker port is changed. <a href="https://github.com/gravitl">gravitl</a>/<a href="https://github.com/gravitl/netmaker">netmaker</a> v0.14.2 will supports MQTT broker port configuration by environmental variable, hence this step can be skipped in near future.</p><pre>git clone -b tls_passthrough <a href="https://github.com/panda1100/netmaker.git">https://github.com/panda1100/netmaker.git</a></pre><p>Here is a diff from original repository to this branch tls_passthrough .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0CKzeyoEhBL6b4Z8.png" /></figure><p>Set your base domain, this domain should be matched to wildcard A record that you added to your DNS. Here is the example command that assumes your wildcard A record looks like *.netmaker.example.jp A 54.XXX.YYY.ZZZ</p><pre>$ sed -i &#39;s/NETMAKER_BASE_DOMAIN/netmaker.example.jp/g&#39; docker-compose.yml<br>$ sed -i &#39;s/NETMAKER_BASE_DOMAIN/netmaker.example.jp/g&#39; config.json</pre><p>Set your server IP (global IP).</p><pre>$ curl ifconfig.me<br>54.XXX.YYY.ZZZ<br>$ sed -i &#39;s/SERVER_PUBLIC_IP/54.XXX.YYY.ZZZ/g&#39; docker-compose.yml</pre><p>Set your CoreDNS IP. If you run VM on AWS, global IP is not directly bind to network interface of VM. In such a case, we need to set the IP of the default interface.</p><pre>$ (ip route get 1 | sed -n &#39;s/^.*src \([0-9.]*\) .*$/<strong>\1</strong>/p&#39;)<br>172.XXX.YYY.ZZZ<br>$ sed -i &#39;s/COREDNS_IP/172.XXX.YYY.ZZZ/g&#39; docker-compose.yml</pre><p>Generate a master key and populate it.</p><pre>$ tr -dc A-Za-z0-9 &lt;/dev/urandom | head -c 30 ; echo &#39;&#39;<br>8I9Ifom5xfiEVrcatsfsXXXXXXXXXX<br>sed -i &#39;s/REPLACE_MASTER_KEY/8I9Ifom5xfiEVrcatsfsXXXXXXXXXX/g&#39; docker-compose.yml</pre><p>Prepare MQ</p><pre>wget -O /root/mosquitto.conf \<br><a href="https://raw.githubusercontent.com/gravitl/netmaker/v0.13.1/docker/mosquitto.conf">https://raw.githubusercontent.com/gravitl/netmaker/v0.14.0/docker/mosquitto.conf</a></pre><p>Let’s spin up Netmaker</p><pre>docker-compose up -d</pre><p>Create Netmaker network by following <a href="https://medium.com/@panda1100/hands-on-guide-to-netmaker-v0-13-1-caec629a597d">Hands-On Guide</a>.</p><h3>Client-side Installation</h3><p>Open terminal of your client-side Ubuntu box. Install dependencies.</p><pre>sudo apt update &amp;&amp; sudo apt install -y git docker.io wireguard</pre><p>Clone git repository for this project.</p><pre>sudo su -<br>git clone -b tls_passthrough <a href="https://github.com/panda1100/netmaker.git">https://github.com/panda1100/netmaker.git</a><br>cd netmaker</pre><p>Build modified version of Netmaker v0.14.0 using Docker</p><pre>docker run -it --rm -v ${PWD}/:/root -w /root/netclient golang:1.18.2 go mod download all<br>docker run -it --rm -v ${PWD}/:/root -w /root/netclient golang:1.18.2 go build</pre><p>Install official client</p><pre>curl -sL &#39;https://apt.netmaker.org/gpg.key&#39; | sudo tee /etc/apt/trusted.gpg.d/netclient.asc<br>curl -sL &#39;https://apt.netmaker.org/debian.deb.txt&#39; | sudo tee /etc/apt/sources.list.d/netclient.list<br>sudo apt update<br>sudo apt install netclient</pre><p>And then overwrite netclient by the one we built</p><pre>cp netclient/netclient /sbin/netclient</pre><h3>SNI Routing Test</h3><h4>Secure MQTT</h4><p>Log-in to client side ubuntu box, and then join to the Netmaker network</p><pre>sudo su -<br>systemctl enable --now netclient<br>netclient join -t &lt;ACCESS_TOKEN&gt; -vvv</pre><p>Successfully joined to Netmaker network and pulling peer informations! 🙌 This means two things.</p><ol><li>SNI routing to Mosquitto broker is properly handled by <strong>layer4 app</strong>. And Mosquitto terminates TLS handshake with successful client certificate authentication</li><li>SNI routing to API server is properly handled by <strong>layer4 app</strong>. And <strong>http app </strong>properly terminates TLS handshake by using autogenerated Let’s Encrypt certificate and properly reverse proxy to the corresponding backend such as netmaker container.</li></ol><pre>[netclient] 2022-05-25 05:12:28 joining dev at api.netmaker.example.jp:443<br>[netclient] 2022-05-25 05:12:28 node created on remote server...updating configs<br>[netclient] 2022-05-25 05:12:28 starting wireguard<br>[netclient] 2022-05-25 05:12:30 waiting for interface...<br>[netclient] 2022-05-25 05:12:30 interface ready - netclient.. ENGAGE<br>[netclient] 2022-05-25 05:12:30 local port has changed from  0  to  40311<br>[netclient] 2022-05-25 05:12:30 sent a node update to server for node ip-172-26-14-171 ,  f00108a3-0efc-4407-a413-eee469cc2dee<br>[netclient] 2022-05-25 05:12:31 restarting netclient.service<br>[netclient] 2022-05-25 05:12:32 joined  dev</pre><h4>Dashboard</h4><p>Open https://dashboard.NETMAKER_BASE_DOMAIN on your browser. If you see this “Create an Admin” page, that means <strong>layer4 app</strong> properly handled SNI routing, <strong>http app </strong>properly terminates TLS handshake by using autogenerated Let’s Encrypt certificate and properly reverse proxy to the corresponding backend such as netmaker-ui container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*8dK0t7ovlECivYWT.png" /></figure><h3>References</h3><ul><li><a href="https://aws.amazon.com/jp/blogs/iot/mqtt-with-tls-client-authentication-on-port-443-why-it-is-useful-and-how-it-works/">MQTT with TLS client authentication on port 443: Why it is useful and how it works | Amazon Web Services</a></li><li><a href="https://www.nginx.com/blog/nginx-plus-iot-security-encrypt-authenticate-mqtt/">Improve IoT Security with NGINX Plus: Encrypt &amp; Authenticate MQTT</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a226c8168826" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MQTT with TLS client authentication on port 443 using Traefik v2 TLS Passthrough applied to…]]></title>
            <link>https://medium.com/@panda1100/a-solution-to-use-port-443-for-client-certificate-authentication-of-netmaker-v0-14-0-455777589b12?source=rss-f5a850722935------2</link>
            <guid isPermaLink="false">https://medium.com/p/455777589b12</guid>
            <category><![CDATA[tls-passthrough]]></category>
            <category><![CDATA[sni]]></category>
            <category><![CDATA[traefik]]></category>
            <category><![CDATA[mosquitto]]></category>
            <category><![CDATA[netmaker]]></category>
            <dc:creator><![CDATA[Yoshiaki Senda]]></dc:creator>
            <pubDate>Wed, 25 May 2022 06:18:31 GMT</pubDate>
            <atom:updated>2022-06-03T10:04:32.456Z</atom:updated>
            <content:encoded><![CDATA[<h3>MQTT with TLS client authentication on port 443 using Traefik v2 TLS Passthrough applied to Netmaker v0.14.0</h3><h3>Problem Description</h3><p>Netmaker today we need to allow access to 80/tcp , 443/tcp, 8883/tcp, and 51821–51380/udp from 0.0.0.0/0. But in some cases access to 8883/tcp from 0.0.0.0/0, this port is for MQTT over SSL, is not allowed by firewall policy.</p><h3>Concept</h3><p>This Proof-of-Concept project attempts to solve this firewall policy problem by using Traefik v2.6<strong> TLS passthrough</strong> <strong>for TCP</strong> and <strong>HostSNI </strong>feature. (Caddy layer4 app version is <a href="https://medium.com/@panda1100/how-to-setup-layer-4-reverse-proxy-to-multiplex-tls-traffic-with-sni-routing-a226c8168826">here</a>)</p><h3>Testing Environment</h3><p><a href="https://medium.com/@panda1100/hands-on-guide-to-netmaker-v0-13-1-caec629a597d">Last time</a> I used Caddy as a reverse proxy for Netmaker components. This time I used Traefik as a reverse proxy. <strong>Netmaker</strong> <strong>broker</strong> is behind Traefik. And Traefik routes ssl://broker.netmaker.example.jp:443 to mq:8883 . If this works, we can reduce an open port that sometimes cannot reachable from 0.0.0.0/0 such as 8883/tcp.</p><h3>VM preparation</h3><p>Create a VM on your preferred cloud for this test. This guide will use Lightsail on AWS.</p><ul><li>Create a VM with 4GB of memory and 2 vCPU running Ubuntu 22.04</li><li>Attach static global IP to your VM</li><li>Add wildcard A record to your DNS that points to the public IP of your VM</li><li>Allow 80/tcp, 443/tcp, ̶<strong>8̶8̶8̶3̶/̶t̶c̶p̶</strong>, 51821–51830/udp from 0.0.0.0/0</li><li>Install dependencies to your VM ( sudo apt update &amp;&amp; sudo apt install -y docker.io docker-compose wireguard)</li></ul><h3>Server-side Installation</h3><p>Once you booted up Ubuntu box, create directory tls_passthrough.</p><pre>$ sudo su -<br>$ mkdir -p /root/tls_passthrough/letsencrypt<br>$ cd /root/tls_passthrough</pre><p>Create docker network</p><pre>$ docker network create traefik</pre><p>Download docker-compose.yml file from Netmaker repository.</p><pre>$ wget -O docker-compose.yml \<br>https://raw.githubusercontent.com/gravitl/netmaker/v0.14.0/compose/docker-compose.yml</pre><p>Before populate your settings, we need to modify docker-compose.yml to meets PoC specification. This PoC uses <strong>TLS passthrough</strong> <strong>for TCP </strong>and <strong>HostSNI to split port 443 requests from client to api, dashboard and broker.</strong> Modified docker-compose.yml looks like following:</p><pre>version: &quot;3.4&quot;<br><br>services:<br>  <strong>reverse-proxy:<br>    image: traefik:v2.6<br>    restart: always<br>    ports:<br>      - &#39;80:80&#39; # http<br>      - &#39;443:443&#39; # https<br>    networks:<br>      - traefik<br>    volumes:<br>      - /var/run/docker.sock:/var/run/docker.sock<br>      - ./letsencrypt:/letsencrypt<br>    command:<br>      - &quot;--providers.docker=true&quot;<br>      - &quot;--providers.docker.exposedbydefault=false&quot;<br>      - &quot;--providers.docker.network=traefik&quot;<br>      - &quot;--entrypoints.websecure.address=:443&quot;<br>      - &quot;--entrypoints.web.address=:80&quot;<br>      - &quot;--entrypoints.web.http.redirections.entrypoint.to=websecure&quot;<br>      - &quot;--entrypoints.web.http.redirections.entrypoint.scheme=https&quot;<br>      - &quot;--certificatesresolvers.myresolver.acme.tlschallenge=true&quot;<br>      - &quot;--</strong><a href="/service/mailto:certificatesresolvers.myresolver.acme.email=senda@bakuhatsu.jp"><strong>certificatesresolvers.myresolver.acme.email=traefik@example.jp</strong></a><strong>&quot;<br>      - &quot;--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json&quot;</strong><br>  netmaker:<br>    container_name: netmaker<br>    <strong>build: netmaker<br>    image: panda1100/tls_passthrough</strong><br>    volumes:<br>      - dnsconfig:/root/config/dnsconfig<br>      - sqldata:/root/data<br>      - <strong>${PWD}/certs:/etc/netmaker/</strong><br>    cap_add: <br>      - NET_ADMIN<br>      - NET_RAW<br>      - SYS_MODULE<br>    sysctls:<br>      - net.ipv4.ip_forward=1<br>      - net.ipv4.conf.all.src_valid_mark=1<br>      - net.ipv6.conf.all.disable_ipv6=0<br>      - net.ipv6.conf.all.forwarding=1<br>    restart: always<br>    environment:<br>      SERVER_NAME: <strong>&quot;broker.NETMAKER_BASE_DOMAIN&quot;</strong><br>      SERVER_HOST: &quot;SERVER_PUBLIC_IP&quot;<br>      SERVER_API_CONN_STRING: &quot;api.NETMAKER_BASE_DOMAIN:443&quot;<br>      COREDNS_ADDR: &quot;SERVER_PUBLIC_IP&quot;<br>      DNS_MODE: &quot;on&quot;<br>      SERVER_HTTP_HOST: &quot;api.NETMAKER_BASE_DOMAIN&quot;<br>      API_PORT: &quot;8081&quot;<br>      CLIENT_MODE: &quot;on&quot;<br>      MASTER_KEY: &quot;REPLACE_MASTER_KEY&quot;<br>      CORS_ALLOWED_ORIGIN: &quot;*&quot;<br>      DISPLAY_KEYS: &quot;on&quot;<br>      DATABASE: &quot;sqlite&quot;<br>      NODE_ID: &quot;netmaker-server-1&quot;<br>      MQ_HOST: &quot;mq&quot;<br>      HOST_NETWORK: &quot;off&quot;<br>      VERBOSITY: &quot;1&quot;<br>      PORT_FORWARD_SERVICES: &quot;dns&quot;<br>      MANAGE_IPTABLES: &quot;on&quot;<br>    <strong>ports:<br>      - &quot;51821-51830:51821-51830/udp&quot;<br>    expose:<br>       - &quot;8081&quot;<br>    networks:<br>      - traefik<br>    labels:<br>      - traefik.enable=true<br>      - traefik.http.routers.api.rule=Host(`api.NETMAKER_BASE_DOMAIN`)<br>      - traefik.http.services.api.loadbalancer.server.port=8081<br>      - traefik.http.routers.api.entrypoints=websecure<br>      - traefik.http.routers.api.tls.certresolver=myresolver</strong><br>  netmaker-ui:<br>    container_name: netmaker-ui<br>    depends_on:<br>      - netmaker<br>    image: gravitl/netmaker-ui:v0.14.0<br>    links:<br>      - &quot;netmaker:api&quot;<br>    <strong>expose:<br>      - &quot;80&quot;</strong><br>    environment:<br>      BACKEND_URL: &quot;https://api.NETMAKER_BASE_DOMAIN&quot;<br>    restart: always<br>    <strong>networks:<br>      - traefik<br>    labels:<br>      - traefik.enable=true<br>      - traefik.http.routers.dashboard.rule=Host(`dashboard.NETMAKER_BASE_DOMAIN`)<br>      - traefik.http.services.dashboard.loadbalancer.server.port=80<br>      - traefik.http.routers.dashboard.entrypoints=websecure<br>      - traefik.http.routers.dashboard.tls.certresolver=myresolver</strong><br>  coredns:<br>    depends_on:<br>      - netmaker <br>    image: coredns/coredns<br>    command: -conf /root/dnsconfig/Corefile<br>    container_name: coredns<br>    restart: always<br>    volumes:<br>      - dnsconfig:/root/dnsconfig<br>    <strong>networks:<br>      - traefik</strong><br>  mq:<br>    image: eclipse-mosquitto:2.0.11-openssl<br>    depends_on:<br>      - netmaker<br>    container_name: mq<br>    restart: unless-stopped<br>    ports:<br>      - &quot;127.0.0.1:1883:1883&quot;<br>      <strong>- &quot;18883:8883&quot;</strong><br>    volumes:<br>      <strong>- ${PWD}/mosquitto.conf:/mosquitto/config/mosquitto.conf<br>      - ${PWD}/certs/:/mosquitto/certs/</strong><br>      - mosquitto_data:/mosquitto/data<br>      - mosquitto_logs:/mosquitto/log<br>    <strong>networks:<br>      - traefik<br>    labels:<br>      </strong>- traefik.enable=true<br>      <strong>- traefik.tcp.routers.mqtts.rule=HostSNI(`broker.NETMAKER_BASE_DOMAIN`)<br>      - traefik.tcp.routers.mqtts.tls.passthrough=true<br>      - traefik.tcp.services.mqtts-svc.loadbalancer.server.port=8883<br>      - traefik.tcp.routers.mqtts.service=mqtts-svc<br>      - traefik.tcp.routers.mqtts.entrypoints=websecure</strong><br>volumes:<br>  caddy_data: {}<br>  caddy_conf: {}<br>  sqldata: {}<br>  dnsconfig: {}<br>  mosquitto_data: {}<br>  mosquitto_logs: {}<br><strong>networks:<br>  traefik:<br>    external: true</strong></pre><p>Clone git repository for this PoC project.</p><pre>git clone -b tls_passthrough <a href="https://github.com/panda1100/netmaker.git">https://github.com/panda1100/netmaker.git</a></pre><p>Here is a diff from original to this branch tls_passthrough:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJMK6uWMcbNWC6xiCzklMw.png" /></figure><p>Set your base domain, this domain should be matched to wildcard A record that you added to your DNS. Here is the example command that assumes your wildcard A record looks like *.netmaker.example.jp A 54.XXX.YYY.ZZZ</p><pre>$ sed -i &#39;s/NETMAKER_BASE_DOMAIN/netmaker.example.jp/g&#39; docker-compose.yml</pre><p>Set your server IP (global IP).</p><pre>$ curl ifconfig.me<br>54.XXX.YYY.ZZZ<br>$ sed -i &#39;s/SERVER_PUBLIC_IP/54.XXX.YYY.ZZZ/g&#39; docker-compose.yml</pre><p>Set your CoreDNS IP. If you run VM on AWS, global IP is not directly bind to network interface of VM. In such a case, we need to set the IP of the default interface.</p><pre>$ (ip route get 1 | sed -n &#39;s/^.*src \([0-9.]*\) .*$/<strong>\1</strong>/p&#39;)<br>172.XXX.YYY.ZZZ<br>$ sed -i &#39;s/COREDNS_IP/172.XXX.YYY.ZZZ/g&#39; docker-compose.yml</pre><p>Generate a master key and populate it.</p><pre>$ tr -dc A-Za-z0-9 &lt;/dev/urandom | head -c 30 ; echo &#39;&#39;<br>8I9Ifom5xfiEVrcatsfsXXXXXXXXXX<br>sed -i &#39;s/REPLACE_MASTER_KEY/8I9Ifom5xfiEVrcatsfsXXXXXXXXXX/g&#39; docker-compose.yml</pre><p>Prepare MQ</p><pre>wget -O /root/mosquitto.conf \<br><a href="https://raw.githubusercontent.com/gravitl/netmaker/v0.13.1/docker/mosquitto.conf">https://raw.githubusercontent.com/gravitl/netmaker/v0.14.0/docker/mosquitto.conf</a></pre><p>Let’s spin up Netmaker</p><pre>docker-compose up -d</pre><p>Create Netmaker network by following <a href="https://medium.com/@panda1100/hands-on-guide-to-netmaker-v0-13-1-caec629a597d">Hands-On Guide</a>.</p><h3>Client-side Installation</h3><p>Open terminal of your client-side Ubuntu box. Install dependencies.</p><pre>sudo apt update &amp;&amp; sudo apt install -y git docker.io wireguard</pre><p>Clone git repository for this PoC project.</p><pre>sudo su -<br>git clone -b tls_passthrough <a href="https://github.com/panda1100/netmaker.git">https://github.com/panda1100/netmaker.git</a><br>cd netmaker</pre><p>Build modified version of Netmaker v0.14.0 using Docker</p><pre>docker run -it --rm -v ${PWD}/:/root -w /root/netclient golang:1.18.2 go mod download all<br>docker run -it --rm -v ${PWD}/:/root -w /root/netclient golang:1.18.2 go build</pre><p>Install official client</p><pre>curl -sL &#39;https://apt.netmaker.org/gpg.key&#39; | sudo tee /etc/apt/trusted.gpg.d/netclient.asc<br>curl -sL &#39;https://apt.netmaker.org/debian.deb.txt&#39; | sudo tee /etc/apt/sources.list.d/netclient.list<br>sudo apt update<br>sudo apt install netclient</pre><p>And then overwrite netclient by the one we built</p><pre>cp netclient/netclient /sbin/netclient</pre><p>Join to the Netmaker network</p><pre>systemctl enable --now netclient<br>netclient join -t &lt;ACCESS_TOKEN&gt; -vvv</pre><p>Successfully joined to Netmaker network and pulling peer informations! 🙌</p><pre>[netclient] 2022-05-25 05:12:28 joining dev at api.netmaker.example.jp:443<br>[netclient] 2022-05-25 05:12:28 node created on remote server...updating configs<br>[netclient] 2022-05-25 05:12:28 starting wireguard<br>[netclient] 2022-05-25 05:12:30 waiting for interface...<br>[netclient] 2022-05-25 05:12:30 interface ready - netclient.. ENGAGE<br>[netclient] 2022-05-25 05:12:30 local port has changed from  0  to  40311<br>[netclient] 2022-05-25 05:12:30 sent a node update to server for node ip-172-26-14-171 ,  f00108a3-0efc-4407-a413-eee469cc2dee<br>[netclient] 2022-05-25 05:12:31 restarting netclient.service<br>[netclient] 2022-05-25 05:12:32 joined  dev</pre><h3>Appendix A.</h3><p>Test with mosquitto_pub on client machine.</p><pre>sudo apt install -y mosquitto-clients<br><strong>cd /etc/netclient/broker.netmaker.example.jp</strong><br><strong>mosquitto_pub -h broker.netmaker.example.jp -p 443</strong> <strong>--cafile ./root.pem</strong> <strong>--cert ./client.pem</strong> <strong>--key /etc/netclient/client.key</strong> <strong>-m &quot;hello&quot; -t test -d</strong><br>Client mosq-gLyguZ5pj64tTkgaK0 sending CONNECT<br>Client mosq-gLyguZ5pj64tTkgaK0 received CONNACK (0)<br>Client mosq-gLyguZ5pj64tTkgaK0 sending PUBLISH (d0, q0, r0, m1, &#39;test&#39;, ... (5 bytes))<br>Client mosq-gLyguZ5pj64tTkgaK0 sending DISCONNECT</pre><h3>References</h3><p><a href="https://aws.amazon.com/jp/blogs/iot/mqtt-with-tls-client-authentication-on-port-443-why-it-is-useful-and-how-it-works/">MQTT with TLS client authentication on port 443: Why it is useful and how it works | Amazon Web Services</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=455777589b12" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>