{
    "version": "https://jsonfeed.org/version/1.1",
    "title": "Sysadmin  dade",
    "description": "  Sysadmin  dade",
    "home_page_url": "https://0xda.de/",
    "feed_url": "https://0xda.de/tags/sysadmin/index.json",
    "language": "en",
    "authors": [
        {
            "name": "0xdade",
            "url": "https://0xda.de",
            "avatar": "https://0xda.de/img/dade-transparent-logo.png"
        }
    ],
    "items": [
        {
            "title": "Managing My Servers",
            "date_published": "2026-02-20T17:30:52-08:00",
            "date_modified": "2026-02-20T17:43:52-08:00",
            "id": "https://0xda.de/blog/2026/02/managing-my-servers/",
            "url": "https://0xda.de/blog/2026/02/managing-my-servers/",
            "content_html": "\u003cp\u003eI\u0026rsquo;ve been spending a fair amount of time building out documentation around my home network as well as my various services I\u0026rsquo;m running on the internet. Drawing architecture diagrams, mapping out what services are on which servers, documenting backup processes for each service, that sort of thing. But one thing that I keep coming back to is trying to understand the criteria for my perfect server. Sure I have TrueNAS running my storage server, and it\u0026rsquo;s great at what it does. But what about the compute?\u003c/p\u003e\n\u003cp\u003eProfessionally, I\u0026rsquo;ve long been an advocate of the \u0026ldquo;Servers are cattle, not pets\u0026rdquo; mentality \u0026ndash; though maybe I\u0026rsquo;d like to figure out a better way to express this. But the idea is that no server should be a snowflake, and that servers should be easily disposed of and replaced. This seems to be the underlying mentality powering the rise of Kubernetes, which does a great job at decoupling the workload from the underlying server.\u003c/p\u003e\n\u003ch2 id=\"kubernetes\"\u003eKubernetes\u003c/h2\u003e\n\u003cp\u003eKubernetes, though, is a matryoshka doll of complexity. Under every stone is another layer of complexity to manage. Plus, while there are various projects like Flux to enable gitops for kubernetes, a lot of the workflows seem to be heavily based on running commands to install software. \u003ccode\u003ehelm install \u0026lt;blahblahblah\u0026gt;\u003c/code\u003e. Everything is configured with yaml files everywhere, which makes me feel like it\u0026rsquo;s reasonably declarative. Yet still the seemingly standard process is \u0026ldquo;just helm install it, bro.\u0026rdquo; So it becomes easy for a cluster to quickly separate from a purely declarative abstract machine, and instead it accumulates a bunch of state. Which is okay because it\u0026rsquo;s made up of multiple nodes and the state has some consensus mechanism and redundancy so that any node failing is considered safe. But it just feels too imperative to me. Too much like managing an Ubuntu VM, but with way more moving parts.\u003c/p\u003e\n\u003cp\u003eFundamentally, Kubernetes solves a bunch of problems that I want to care about. A bunch of problems that I do care about, at work. Load balancing, horizontal scaling, security policies, everything is a container. Neat. But at home, it kind of sucks. There\u0026rsquo;s a bunch of complexity, a bunch of imperative configuration, and the gitops workflow feels pretty clunky and slow. This might be a user error, so if you love gitops for kubernetes, please write a rebuttal and send it to me. I would genuinely love to be better educated on it.\u003c/p\u003e\n\u003cp\u003eThat doesn\u0026rsquo;t even hit on one of my most important things \u0026ndash; managing a k8s cluster is an added layer of complexity on top of managing the underlying nodes. So you still need to make sure the underlying nodes are updating regularly, have access secured, offload the logs to centralized logging, etc. One promising candidate to relieve this overhead is \u003ca href=\"https://www.talos.dev/\"\u003eTalos\u003c/a\u003e, a very minimal operating system designed purely for running kubernetes. Managing talos nodes is, again, imperative. You run commands to update things. But if you\u0026rsquo;re already going all in on kubernetes, Talos does seem like a really nice way to minimize attack surface and alleviate overhead around patching and access control. I have a 4-node Talos cluster in my closet right now.\u003c/p\u003e\n\u003ch2 id=\"nixos\"\u003eNixOS\u003c/h2\u003e\n\u003cp\u003eSo then I think, maybe I should just install NixOS on all my servers. I really like the declarative nature of Nix, and if you do it right you can pretty easily decouple services from servers, allowing you to redeploy a service to any of your servers, or deploy it in parallel to multiple of your servers. But you don\u0026rsquo;t really get any sort of scaling with this, and keeping services available is a bit harder and more manual. Plus, if I\u0026rsquo;m being brutally honest, the \u003ca href=\"https://jade.fyi/blog/pinning-packages-in-nix/\"\u003edependency management story for NixOS kind of sucks\u003c/a\u003e. Pinning a package to a specific version is difficult. Stable can quickly get out of date, and unstable is often some random release candidate. While you can absolutely override versions for individual packages, it\u0026rsquo;s definitely not very intuitive and it is either a lot of overhead, or has a high risk of breaking randomly in the future. I would love something more like python\u0026rsquo;s dependency declarations for packages. The package namespace in nixpkgs seems globally unique, so in theory I should be able to just do \u003ccode\u003elistmonk~=6.0\u003c/code\u003e and have a high degree of confidence that redeploying gives me the latest version but without going up to \u003ccode\u003e7.0\u003c/code\u003e. I understand why NixOS doesn\u0026rsquo;t have this, but I can still wish.\u003c/p\u003e\n\u003cp\u003ePlus, running containers on NixOS is an interesting situation. You can enable docker, but it doesn\u0026rsquo;t seem like you can very easily define which containers you want to launch. I\u0026rsquo;d love to be able to just point NixOS at my docker compose files that I already have, and have that get built into the next deployment. It handles the restart conditions, the container dependencies, etc. Many people will say that you don\u0026rsquo;t need docker if you\u0026rsquo;re using NixOS because it achieves many of the same goals. That\u0026rsquo;s totally fair. Except I already have a bunch of docker compose files, and most of the apps I want to install ship with a docker compose file, very few of them ship with a nix file I can just import. There are tools like \u003ca href=\"https://github.com/aksiksi/compose2nix\"\u003ecompose2nix\u003c/a\u003e which can take a compose file and output nix files, which could meet my needs, but then I\u0026rsquo;m introducing this intermediary tool anytime I want to deploy a new service, and that just feels kind of clunky.\u003c/p\u003e\n\u003cp\u003eMaybe the answer here is that I need to go all-in on NixOS and just configure my services entirely as Nix and accept the adoption costs as one-time costs to get things configured. I mean, I\u0026rsquo;m still kind of at the mercy of nixpkgs configurations, but it\u0026rsquo;s a git repo and if something sucks, I can just open a PR to improve it. But this high adoption cost combined with the kinda bad dependency management experience does make me reconsider if this is the route I want to go. I do appreciate how tightly nix flakes are integrated with GitOps, and I also appreciate the NixOS configuration management story (certainly more than configuration management on ubuntu or any other operating system that isn\u0026rsquo;t designed to be completely declarative or completely ephemeral).\u003c/p\u003e\n\u003ch2 id=\"coreos\"\u003eCoreOS\u003c/h2\u003e\n\u003cp\u003eThere\u0026rsquo;s another option, one I haven\u0026rsquo;t experimented with so I can\u0026rsquo;t speak first hand to it yet, but that looks somewhat promising. That is \u003ca href=\"https://fedoraproject.org/coreos/\"\u003eCoreOS\u003c/a\u003e, a container optimized operating system. It is a minimal operating system that auto-updates. Pretty easy to treat this as a dumb and ephemeral underlying operating system. My first introduction to CoreOS was a post by Thomas Letan called \u0026ldquo;\u003ca href=\"https://soap.coffee/~lthms/posts/i-cannot-ssh-into-my-server-anymore.html\"\u003eI cannot SSH into my servers anymore (and that\u0026rsquo;s fine)\u003c/a\u003e\u0026rdquo;, and it looks fairly promising.\u003c/p\u003e\n\u003cp\u003eBut the caveat with this is that it has a similar problem to the NixOS problem \u0026ndash; I pretty much will always have to translate service definitions into podman\u0026rsquo;s quadlet syntax.  Updating containers would have to be entirely manual, since \u003ca href=\"https://docs.github.com/en/code-security/reference/supply-chain-security/supported-ecosystems-and-repositories\"\u003eDependabot does support docker-compose\u003c/a\u003e but doesn\u0026rsquo;t support podman-quadlet. While I don\u0026rsquo;t necessarily want every container to automatically update, I would like to have a better solution for being alerted when a service needs updating.\u003c/p\u003e\n\u003ch2 id=\"tradeoffs\"\u003eTradeoffs\u003c/h2\u003e\n\u003cp\u003eIt\u0026rsquo;s funny, this whole exercise has been weighing on my mind. When I\u0026rsquo;m at work, I am very aware that we have to make tradeoffs for different things. I also accept that using managed container runtimes in cloud providers gives businesses the need to not have to care about this stuff. I loved ECS Fargate for this reason. Git Repo + Terraform + CodePipeline + Fargate and everything was declarative, automatically updatable from Dependabot, and I never had to manage a server.\u003c/p\u003e\n\u003cp\u003eBut at home, I feel passionately about managing my infrastructure and not relying on the cloud. I mostly run everything from a dedicated server I pay for, which is still renting my internet presence, but feels less like renting than the modern cloud. I want to have my own autonomous system some day. I think it would be fun to own my own /24, run my own BGP routers, and be a proper citizen of the internet. There\u0026rsquo;s just something alluring about not being a serf in someone else\u0026rsquo;s kingdom, you know? But I also feel like if I\u0026rsquo;m doing this as a hobby, I want to look for the perfect solution. I know there\u0026rsquo;s no such thing as the perfect solution, but I still can\u0026rsquo;t help but look for it.\u003c/p\u003e\n\u003cp\u003eIn the meantime, I think I\u0026rsquo;m going to continue pursuing my NixOS servers. There\u0026rsquo;s a higher adoption cost to it, but I do really appreciate the simplicity of it, and I don\u0026rsquo;t really need all the complexity of being a one-man devops team. Maybe some day I can have an \u003ca href=\"https://oxide.computer/\"\u003eOxide\u003c/a\u003e rack in my closet and have cloud-native computing at the tip of my fingers. Until then, I guess I\u0026rsquo;ll just have to settle for what I can cobble together.\u003c/p\u003e\n"
        },
        {
            "title": "Can You Grok It",
            "date_published": "2024-04-13T20:13:38-07:00",
            "date_modified": "2025-03-17T21:26:18-07:00",
            "id": "https://0xda.de/blog/2024/04/can-you-grok-it/",
            "url": "https://0xda.de/blog/2024/04/can-you-grok-it/",
            "content_html": "\u003cp\u003eMy friend sent me a tunnel link where he had to manually set it up with socat and his nginx ingress controller in his k8s cluster. He made an offhand comment about needing a better way to setup tunnels and it got me thinking. This post is the result of a long night of hacking away at my own tunnel solution.\u003c/p\u003e\n\u003cp\u003eIf you want to jump into the nitty gritty of how it works, you can skip to \u003ca href=\"#roll-your-own-tunnel\"\u003eRoll Your Own Tunnel\u003c/a\u003e. If you want to skip the nitty gritty and figure it out yourself, \u003ca href=\"#putting-it-all-together\"\u003ePutting It All Together\u003c/a\u003e is where you want to be.\u003c/p\u003e\n\u003cp\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  \n  \n    \n    \n    \n    \n    \n    \n    \n    \n  \u003cpicture\u003e\n    \u003csource srcset=\"/blog/2024/04/can-you-grok-it/img/gronk_hu_31dcd0cceac18932.webp\" type=\"image/webp\" /\u003e\n  \u003cimg class=\"img\" src=\"/blog/2024/04/can-you-grok-it/img/gronk.6e943441cc81a6a519cba39bb9fbac13.jpeg\" alt=\"pull the lever, ngrok\" loading=\"lazy\" height=\"1184\" width=\"867\" /\u003e\n\u003c/picture\u003e\n\u003c/p\u003e\n\u003ch2 id=\"criteria\"\u003eCriteria\u003c/h2\u003e\n\u003cp\u003eI had a handful of criteria that I wanted to consider for a functional solution.\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eI wanted it to run on my own infrastructure - I was likely going to be doing TLS termination at the public web server, since my development servers aren\u0026rsquo;t going to be using publicly trusted TLS certificates.\u003c/li\u003e\n\u003cli\u003eI wanted the tunnels to be created under my own domain. I chose \u003ccode\u003edev.0xda.de\u003c/code\u003e to be the parent of the tunnels \u0026ndash; any new tunnel should be available underneath \u003ccode\u003e.dev.0xda.de\u003c/code\u003e.\u003c/li\u003e\n\u003cli\u003eI didn\u0026rsquo;t want to leak the links to new tunnels automatically and invite automated scanning \u0026ndash; dev services are often running in debug or development mode, which may leak sensitive information even in simple cases like a 404 response. This is an important distinction for one particular solution I looked at, which we\u0026rsquo;ll cover in the next section.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eWith these criteria in mind, I looked at existing solutions. Unfortunately while looking for solutions I could potentially self host, I mostly was reading awesome-selfhosted which didn\u0026rsquo;t seem to have a good section on tunnels. It turns out there\u0026rsquo;s a whole separate list called \u003ca href=\"https://github.com/anderspitman/awesome-tunneling\"\u003eawesome-tunneling\u003c/a\u003e, which has a handful of criteria that are somewhat similar to mine. But I didn\u0026rsquo;t know about this list until after I spent my whole night working on this, so I won\u0026rsquo;t really be touching on any items from that list.\u003c/p\u003e\n\u003ch2 id=\"solutions-i-considered\"\u003eSolutions I Considered\u003c/h2\u003e\n\u003ch3 id=\"ngrok\"\u003eNgrok\u003c/h3\u003e\n\u003cp\u003eI have been using \u003ca href=\"https://ngrok.com/\"\u003engrok\u003c/a\u003e off and on for years. It is okay \u0026ndash; it\u0026rsquo;s convenient to spin up tunnels quickly, and even the free tier allows you to reserve one static domain that you can reuse. This makes testing development of flows like OAuth2 login easier, especially on providers that restrict the redirect URI to publicly routable domains.\u003c/p\u003e\n\u003cp\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  \n  \n    \n    \n    \n    \n    \n    \n    \n    \n  \u003cpicture\u003e\n    \u003csource srcset=\"/blog/2024/04/can-you-grok-it/img/ngrok-pricing_hu_c33776d33d83bf49.webp\" type=\"image/webp\" /\u003e\n  \u003cimg class=\"img\" src=\"/blog/2024/04/can-you-grok-it/img/ngrok-pricing.a0c71c19601c3e38e05cabe57e57188b.png\" alt=\"ngrok pricing page\" loading=\"lazy\" height=\"495\" width=\"1145\" /\u003e\n\u003c/picture\u003e\n\u003c/p\u003e\n\u003cp\u003eTo get a custom domain, you have to use the $10/mo or $96/yr \u0026ldquo;Personal\u0026rdquo; plan. This is fairly reasonable, if I\u0026rsquo;m being honest. But it doesn\u0026rsquo;t meet my first requirement \u0026ndash; Ngrok controls the TLS termination before forwarding the request to my service. Ngrok can potentially see whatever I\u0026rsquo;m developing, can potentially see secrets that leak in debug pages, etc. I have no reason to really worry about this, but in the pursuit of my ideals, I moved on to another option.\u003c/p\u003e\n\u003ch3 id=\"tailscale-funnel\"\u003eTailscale Funnel\u003c/h3\u003e\n\u003cp\u003eI love \u003ca href=\"https://tailscale.com/\"\u003eTailscale\u003c/a\u003e. I\u0026rsquo;ve been a free tier user for over a year now, setting it up is incredibly easy, and I can use the Wireguard mesh network to easily connect my phone to my home services while I\u0026rsquo;m on the go. On top of this, I can even use Tailscale to restrict my administrative ports on web servers, such that you have to either connect through my tailnet or connect through my bastion host.\u003c/p\u003e\n\u003cp\u003eTailscale offers a feature called \u003ca href=\"https://tailscale.com/kb/1223/funnel\"\u003eFunnel\u003c/a\u003e, which works similarly to ngrok as a way to route internet traffic into your local service. It doesn\u0026rsquo;t meet the self-hosted criteria or hosting on my own domain, but I was already using Tailscale so it was easy to test out.\u003c/p\u003e\n\u003cp\u003eOne of the cool things about Tailscale Funnel is that it handles the \u003cstrong\u003eTLS termination on your device\u003c/strong\u003e \u0026ndash; this is an improvement over ngrok\u0026rsquo;s basic proxy service, since I know that the only people who can see the traffic are my local service and the client requesting it. But this comes with an important caveat that I was surprised to learn about.\u003c/p\u003e\n\u003cp\u003eWithin minutes of running my tailscale funnel, my Django service I was running for testing was being bombarded by internet scanning noise. This was surprising to me, but in hindsight it makes perfect sense.\u003c/p\u003e\n\u003cp\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  \n  \n    \n    \n    \n    \n    \n    \n    \n    \n  \u003cpicture\u003e\n    \u003csource srcset=\"/blog/2024/04/can-you-grok-it/img/scanning-traffic_hu_685d01bf021825a1.webp\" type=\"image/webp\" /\u003e\n  \u003cimg class=\"img\" src=\"/blog/2024/04/can-you-grok-it/img/scanning-traffic.311aba8b85990431e17242ca9ea3dd10.png\" alt=\"automated scanning traffic\" loading=\"lazy\" height=\"264\" width=\"1208\" /\u003e\n\u003c/picture\u003e\n\u003c/p\u003e\n\u003cp\u003eWithout too much detail about the Tailscale product, you have a \u0026ldquo;tailnet\u0026rdquo; address of \u003ccode\u003e\u0026lt;unique-tailnet\u0026gt;.ts.net\u003c/code\u003e. For simplicity sake, let\u0026rsquo;s say my tailnet is named \u003ccode\u003eellingson-mineral.ts.net\u003c/code\u003e. This address can be used as the parent domain of all devices on your tailnet, so you can access the Gibson by visiting \u003ccode\u003egibson.ellingson-mineral.ts.net\u003c/code\u003e from any device connected to your tailnet.\u003c/p\u003e\n\u003cp\u003eRemember how I said that Tailscale funnel handles TLS termination on your device? Well in order to do that, your device has to control the keys for the certificate. And since you want it to be publicly available, you need a certificate that is trusted. So Tailscale fetches a certificate from LetsEncrypt for your host.\u003c/p\u003e\n\u003cp\u003eSo the first time you set up a Tailscale funnel, your tailnet address shows up in Certificate Transparency Logs (CTL). \u003ca href=\"https://crt.sh/?q=%25.ts.net\"\u003e\u003cem\u003eA LOT\u003c/em\u003e\u003c/a\u003e of tailnet addresses are in CTL.\u003c/p\u003e\n\u003cp\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  \n  \n    \n    \n    \n    \n    \n    \n    \n    \n  \u003cpicture\u003e\n    \u003csource srcset=\"/blog/2024/04/can-you-grok-it/img/crt-sh-truncated-results_hu_f196091b4dd60839.webp\" type=\"image/webp\" /\u003e\n  \u003cimg class=\"img\" src=\"/blog/2024/04/can-you-grok-it/img/crt-sh-truncated-results.deff177fa5404d802d7096030ff3b6a4.png\" alt=\"crt.sh truncated results for .ts.net\" loading=\"lazy\" height=\"169\" width=\"824\" /\u003e\n\u003c/picture\u003e\n\u003c/p\u003e\n\u003cp\u003eThis could explain how my service started getting scanned minutes after being made available online.\u003c/p\u003e\n\u003cp\u003eWhile this service is really easy to use and really powerful for exposing services indirectly, I think I\u0026rsquo;m not a huge fan of it being immediately available and scannable online, especially if it\u0026rsquo;s a development service. It also doesn\u0026rsquo;t allow me to create tunnels with specific names \u0026ndash; the tunnel will always just be \u003ccode\u003egibson.ellingson-mineral.ts.net\u003c/code\u003e.\u003c/p\u003e\n\u003ch3 id=\"vs-code-developer-tunnels\"\u003eVS Code Developer Tunnels\u003c/h3\u003e\n\u003cp\u003eI already use VS Code for most of my development, and they released a public preview of \u003ca href=\"https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/overview\"\u003eDev Tunnels\u003c/a\u003e back in November 2023. This allows easily hooking up a development tunnel to a port on your local computer, allows persistent URLs for as long as you need, and it\u0026rsquo;s secure by default \u0026ndash; the tunnels default to only being accessible to your own Microsoft or Github account. This is especially cool if you want to test things across your own devices, and it does appear to offer more \u003ca href=\"https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/cli-commands#advanced-manage-dev-tunnel-access\"\u003egranular access controls\u003c/a\u003e if you so desire them.\u003c/p\u003e\n\u003cp\u003eEither way, this service is cool but it relies on the generosity of Microsoft, tunnels my traffic through their relays, and I can\u0026rsquo;t really control the domain I want to use.\u003c/p\u003e\n\u003cp\u003eI didn\u0026rsquo;t spend a lot of time testing this, I\u0026rsquo;ve used it before and it\u0026rsquo;s okay. But I really just like the idea of being able to send someone a link on my own domain.\u003c/p\u003e\n\u003ch2 id=\"roll-your-own-tunnel\"\u003eRoll Your Own Tunnel\u003c/h2\u003e\n\u003cp\u003eSo I was settling into rolling my own ngrok-like service. I spent maybe half an hour thinking about doing it with a simple HTTP application built with FastAPI that would broker a tunnel between clients and the server. I could front the API with nginx and write a simple client. But as I started considering proxying all traffic through websockets, I realized I didn\u0026rsquo;t need to write any of my own code to make this work.\u003c/p\u003e\n\u003cp\u003eWhile looking around, I found a post by Vallard called \u0026ldquo;\u003ca href=\"https://benincosa.com/?p=3755\"\u003emy own ngrok\u003c/a\u003e\u0026rdquo;. This uses a simple nginx configuration and an ssh reverse proxy. These are both things I\u0026rsquo;ve used a great deal in the past. In Vallard\u0026rsquo;s post, he uses a single reusable hostname, and a single port. This works great for simplicity, and for most people this is probably more than enough. But I thought I could make it just a little bit better.\u003c/p\u003e\n\u003ch3 id=\"wildcard-domains\"\u003eWildcard Domains\u003c/h3\u003e\n\u003cp\u003eFirst I wanted to tackle the ability to have arbitrary subdomains for tunnels. Some years ago, I figured out that you can do \u003ca href=\"https://gist.github.com/0xdade/d6dd7dadba2c48295dde0b3260d072d2\"\u003ewildcard server_name blocks in nginx\u003c/a\u003e while I was trying to bypass the Twitter ban on sharing links to ddosecrets.com.\u003c/p\u003e\n\u003cp\u003eTo make this work, we have to do a couple things.\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eCreate a wildcard A record in your DNS zone. E.g. \u003ccode\u003e*.dev 10800 IN A 51.81.64.16\u003c/code\u003e routes all subdomains of \u003ccode\u003e*.dev.0xda.de\u003c/code\u003e to the host that is serving this website.\u003c/li\u003e\n\u003cli\u003eCreate a wildcard TLS certificate with \u003ca href=\"https://community.letsencrypt.org/t/acme-v2-production-environment-wildcards/55578\"\u003eLets Encrypt\u003c/a\u003e \u0026ndash; you\u0026rsquo;ll want to make sure this can auto-renew, which will require some extra work on your part. We\u0026rsquo;re not going to cover the auto-renewal in this post.\u003c/li\u003e\n\u003cli\u003eCreate the following nginx config. This is loosely modified from Vallard\u0026rsquo;s post referenced above, to account for my domain name and my wildcard server_name.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-fallback\" data-lang=\"fallback\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eserver {\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    listen 443 ssl;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    listen [::]:443 ssl;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    server_name ~^(.*)\\.dev\\.0xda\\.de$;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    ssl_certificate /etc/letsencrypt/live/dev.0xda.de/fullchain.pem;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    ssl_certificate_key /etc/letsencrypt/live/dev.0xda.de/privkey.pem;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    location / {\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        include proxy_params;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        proxy_pass http://localhost:7070;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        error_page 502 /no-tunnel.html;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    }\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    location /no-tunnel.html {\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        return 404 \u0026#34;\u0026lt;center\u0026gt;No such tunnel...\u0026lt;/center\u0026gt;\u0026#34;;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    }\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e}\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eNow, we can have arbitrary tunnel names without leaking them to cert transparency logs.\u003c/p\u003e\n\u003ch3 id=\"enabling-multiple-simultaneous-tunnels\"\u003eEnabling Multiple Simultaneous Tunnels\u003c/h3\u003e\n\u003cp\u003eOne major drawback with the configuration so far is that we can only setup one tunnel \u0026ndash; our SSH reverse tunnel binds on port 7070, and our nginx config is routing all traffic to that port.\u003c/p\u003e\n\u003cp\u003eTo fix this, we\u0026rsquo;re going to use a feature of ssh reverse tunnels that is probably a little bit lesser known. See, of course you can proxy to TCP ports like 7070. But you can also establish reverse proxies to a unix domain socket, which is just a file on disk.\u003c/p\u003e\n\u003cp\u003eThis gives us a pretty cool capability to define a name for our tunnel on the client and have that name be available on the server as a unix domain socket.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003essh user@example.com -R /tmp/test.dev.0xda.de.socket:127.0.0.1:8000\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eThe important bit here is the \u003ccode\u003e/tmp/test.dev.0xda.de.socket\u003c/code\u003e. We define this on the client, and it creates a file at \u003ccode\u003e/tmp/test.dev.0xda.de.socket\u003c/code\u003e on the server.\u003c/p\u003e\n\u003cp\u003eWe can then combine this with a slight modification to our nginx server block to have nginx send traffic to the \u003ccode\u003e/tmp/test.dev.0xda.de.socket\u003c/code\u003e socket.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-fallback\" data-lang=\"fallback\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e[...]\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    location / {\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        include proxy_params;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        proxy_pass /tmp/$host.socket; # this is the important change\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        error_page 502 /no-tunnel.html;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    }\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e[...]\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eWe\u0026rsquo;re making use of the \u003ccode\u003e$host\u003c/code\u003e variable in nginx to pass to a named socket on disk. So if our request is to \u003ccode\u003ehttps://test.dev.0xda.de\u003c/code\u003e, then nginx will match this server block and then pass the request to \u003ccode\u003e/tmp/test.dev.0xda.de.socket\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThere\u0026rsquo;s one glaring problem with this, though.\u003c/p\u003e\n\u003ch3 id=\"linux-permissions\"\u003eLinux Permissions\u003c/h3\u003e\n\u003cp\u003eWe\u0026rsquo;re sshing to our server as our own user, but our nginx server workers are running as \u003ccode\u003ewww-data\u003c/code\u003e. When our socket gets created, only our own user can interact with it.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e$ ls -la /tmp/test.dev.0xda.de.socket\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003esrw------- \u003cspan style=\"color:#ef9f76\"\u003e1\u003c/span\u003e dade dade \u003cspan style=\"color:#ef9f76\"\u003e0\u003c/span\u003e Apr \u003cspan style=\"color:#ef9f76\"\u003e14\u003c/span\u003e 02:04 /tmp/test.dev.0xda.de.socket\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eWe need to let \u003ccode\u003ewww-data\u003c/code\u003e read and write to this socket. There are a handful of things I tried, and the one that is probably the sketchiest is also the one I ended up selecting. But let\u0026rsquo;s take a look at the options first.\u003c/p\u003e\n\u003ch4 id=\"giving-www-data-ssh-authorized_keys\"\u003eGiving www-data ssh \u003ccode\u003eauthorized_keys\u003c/code\u003e\u0026hellip;\u003c/h4\u003e\n\u003cp\u003e\u0026hellip; and then having my local tunnel command ssh in as the \u003ccode\u003ewww-data\u003c/code\u003e user. This worked, sorta, but usually if I see \u003ccode\u003ewww-data\u003c/code\u003e running ssh, or anything, really, I get pretty sketched out. And plus, the user\u0026rsquo;s shell defaults to \u003ccode\u003e/usr/sbin/nologin\u003c/code\u003e \u0026ndash; so the shell immediately terminates after ssh authenticates.\u003c/p\u003e\n\u003ch4 id=\"make-a-group-that-my-user-and-www-data-belong-to\"\u003eMake a group that my user and www-data belong to\u003c/h4\u003e\n\u003cp\u003eThis probably could work, but I was having trouble with it because whenever I tried to \u003ccode\u003echown dade:grok /tmp/test.dev.0xda.de.socket\u003c/code\u003e, I was met with a \u003ccode\u003eOperation not permitted\u003c/code\u003e error. I \u003cem\u003esuspect\u003c/em\u003e this is probably something we could overcome, and is better than the alternative options if it does work, because we can enable only our user and \u003ccode\u003ewww-data\u003c/code\u003e to talk to the socket.\u003c/p\u003e\n\u003ch4 id=\"chmod-ogw\"\u003echmod o+gw\u003c/h4\u003e\n\u003cp\u003eWhat I ultimately ended up doing is the dumbest possible solution. We can just run \u003ccode\u003echmod o+rw /tmp/test.dev.0xda.de.socket\u003c/code\u003e and allow any user, any process on the server to communicate with this socket. Since ultimately I\u0026rsquo;m granting \u003cem\u003ethe internet\u003c/em\u003e read/write access to this socket anyways, I decided I was okay with this for now. If I was in a shared hosting environment with other users, I might reconsider \u0026ndash; but in that scenario, I\u0026rsquo;d also probably not be able to make the nginx config changes necessary, so maybe that scenario is irrelevant.\u003c/p\u003e\n\u003cp\u003eBut I don\u0026rsquo;t want to have to run this every time I start the tunnel, that\u0026rsquo;s annoying.\u003c/p\u003e\n\u003ch3 id=\"the-worlds-sketchiest-automation\"\u003eThe world\u0026rsquo;s sketchiest automation\u003c/h3\u003e\n\u003cp\u003eTo automatically run a command when we ssh in to establish the tunnel, we have a bunch of options. We could set it up to run a non-interactive ssh session and run a pre-defined bash script, for instance. But for reasons I don\u0026rsquo;t remember, this didn\u0026rsquo;t really work well for me. We could also use our various shell rc files to attempt it whenever our shell starts up. But this also isn\u0026rsquo;t my favorite option, since I could start shells inside of \u003ccode\u003escreen\u003c/code\u003e or \u003ccode\u003etmux\u003c/code\u003e, for instance.\u003c/p\u003e\n\u003cp\u003eInstead, I specifically only want to run this bit of code when I establish a new ssh session. Enter my old persistence friend \u003ccode\u003e~/.ssh/rc\u003c/code\u003e. This is an ssh-specific configuration file that runs when you establish a new ssh connection \u0026ndash; both for interactive logins as well as remote commands.\u003c/p\u003e\n\u003cp\u003eOur naïve solution for this can begin with the following:\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003echmod o+rw /tmp/*.dev.0xda.de.socket 2\u0026gt;/dev/null\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eBut this runs every time, even when I don\u0026rsquo;t specify a tunnel. It also blanket runs across all dev sockets in the tmp directory, rather than only running against the specific tunnel we\u0026rsquo;re establishing with our ssh session.\u003c/p\u003e\n\u003cp\u003eWhat we need is to pass the tunnel domain to the server, that way the process on the server knows the exact domain name to use. This will also be helpful when we talk about cleaning up the tunnel afterwards.\u003c/p\u003e\n\u003cp\u003eIn ssh, you can use an option called \u003ccode\u003eSendEnv\u003c/code\u003e to send an environment variable from the local environment to your remote environment. The sshd server must be configured to support this, and I\u0026rsquo;m probably about to make some unix grey-beards very angry with my next suggestion.\u003c/p\u003e\n\u003cp\u003eOn my Ubuntu 20.04 server, \u003ccode\u003esshd_config\u003c/code\u003e allows certain variables to be sent by default.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-gdscript3\" data-lang=\"gdscript3\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#737994;font-style:italic\"\u003e# Allow client to pass locale environment variables\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eAcceptEnv LANG LC_\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e*\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eThat wildcard \u003ccode\u003eLC_*\u003c/code\u003e is our saving grace here. \u003cem\u003eANY\u003c/em\u003e environment variable that begins with\u003ccode\u003eLC_\u003c/code\u003e can be sent from a client to the server, should the client so choose. So let\u0026rsquo;s abuse that with a new variable called \u003ccode\u003eLC_GROKDOMAIN\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eSo now our ssh command to start the tunnel looks like this:\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#99d1db\"\u003eexport\u003c/span\u003e \u003cspan style=\"color:#f2d5cf\"\u003eLC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003etest.dev.0xda.de\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003essh user@example.com -o \u003cspan style=\"color:#f2d5cf\"\u003eSendEnv\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003eLC_GROKDOMAIN -R /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket:127.0.0.1:8000\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eAnd we can update our \u003ccode\u003e~/.ssh/rc\u003c/code\u003e file to only run with this new information.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003eif\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e[\u003c/span\u003e -n \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e]\u003c/span\u003e; \u003cspan style=\"color:#ca9ee6\"\u003ethen\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    chmod o+rw /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket 2\u0026gt;/dev/null\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003eecho\u003c/span\u003e \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;You can now visit https://\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e in your browser\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003efi\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch4 id=\"cleaning-up-the-socket\"\u003eCleaning up the socket\u003c/h4\u003e\n\u003cp\u003eNow that we have the automation setup to automatically give nginx the ability to read/write to our socket when we establish our ssh connection, we have one more annoying thing that happens on the server to contend with. Cleaning up.\u003c/p\u003e\n\u003cp\u003eWhen we\u0026rsquo;re done with our socket, we want to remove the file from \u003ccode\u003e/tmp/\u003c/code\u003e \u0026ndash; otherwise if we try to reuse the socket next time, the forward will fail since the file already exists.\u003c/p\u003e\n\u003cp\u003eMy really hacky way to do this was to add a conditional block to my \u003ccode\u003e~/.bash_logout\u003c/code\u003e. This works well enough when I close the session when I\u0026rsquo;m done with it.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003eif\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e[\u003c/span\u003e -n \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e]\u003c/span\u003e; \u003cspan style=\"color:#ca9ee6\"\u003ethen\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    rm /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket 2\u0026gt;/dev/null\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003efi\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003e\u003cstrong\u003eNote:\u003c/strong\u003e This unfortunately leaves the socket file hanging around in the event that your ssh connection dies through anything other than a clean exit. There is almost certainly room for improvement here, but I was at the end of my knowledge for code that automatically gets executed in my ssh sessions. Failure to clean up the socket will result in the next attempt to establish the tunnel failing until you remove the socket file and re-connect.\u003c/p\u003e\n\u003ch3 id=\"streamlining-the-client-experience\"\u003eStreamlining the Client Experience\u003c/h3\u003e\n\u003cp\u003eOkay so far so good. We can run a single ssh command and have a new tunnel set up on our infrastructure, on our domain, and we haven\u0026rsquo;t even introduced any new code. We already had nginx, and we already had ssh. We can have as many tunnels as we can have unix domain sockets and nginx will handle routing requests to the appropriate tunnel.\u003c/p\u003e\n\u003cp\u003eBut the command is kind of clunky and not easy to use. We have to export the domain variable, we have to write out a long ssh command, it\u0026rsquo;s just not fun. Let\u0026rsquo;s write a wrapper that simplifies things.\u003c/p\u003e\n\u003cp\u003eConsider our current process for setting up a new tunnel:\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#99d1db\"\u003eexport\u003c/span\u003e \u003cspan style=\"color:#f2d5cf\"\u003eLC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003etest.dev.0xda.de\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003essh user@example.com -o \u003cspan style=\"color:#f2d5cf\"\u003eSendEnv\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003eLC_GROKDOMAIN -R /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket:127.0.0.1:8000\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eDoing this manually also leaves \u003ccode\u003eLC_GROKDOMAIN\u003c/code\u003e hanging around in our shell, which might cause some confusion the next time we want to open a tunnel. It\u0026rsquo;s also just a lot to type out.\u003c/p\u003e\n\u003cp\u003eWe want our interface to be simple. \u003ccode\u003egrok \u0026lt;port\u0026gt; [\u0026lt;name\u0026gt;]\u003c/code\u003e \u0026ndash; port is required, and name is optional. We \u003cem\u003ehave\u003c/em\u003e to know what port to forward the traffic to, but we don\u0026rsquo;t necessarily \u003cem\u003ehave\u003c/em\u003e to designate a name.\u003c/p\u003e\n\u003cp\u003eA simple bash script later, and we\u0026rsquo;ve got exactly what we need.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#737994;font-style:italic\"\u003e#!/bin/bash\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egrok\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e()\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e{\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#f2d5cf\"\u003eTOP_LEVEL_DOMAIN\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;dev.0xda.de\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#ca9ee6\"\u003eif\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e[\u003c/span\u003e -z \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$1\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e]\u003c/span\u003e; \u003cspan style=\"color:#ca9ee6\"\u003ethen\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        \u003cspan style=\"color:#99d1db\"\u003eecho\u003c/span\u003e \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;Usage: grok \u0026lt;port\u0026gt; [\u0026lt;name\u0026gt;]\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        \u003cspan style=\"color:#ca9ee6\"\u003ereturn\u003c/span\u003e \u003cspan style=\"color:#ef9f76\"\u003e1\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#ca9ee6\"\u003efi\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003elocal\u003c/span\u003e \u003cspan style=\"color:#f2d5cf\"\u003eport\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$1\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003elocal\u003c/span\u003e \u003cspan style=\"color:#f2d5cf\"\u003ename\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$2\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#ca9ee6\"\u003eif\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e[\u003c/span\u003e -z \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$name\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e]\u003c/span\u003e; \u003cspan style=\"color:#ca9ee6\"\u003ethen\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        \u003cspan style=\"color:#737994;font-style:italic\"\u003e# Generate a random 12-digit hexadecimal string\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        \u003cspan style=\"color:#f2d5cf\"\u003ename\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#ca9ee6\"\u003e$(\u003c/span\u003eopenssl rand -hex 6\u003cspan style=\"color:#ca9ee6\"\u003e)\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#ca9ee6\"\u003efi\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003eecho\u003c/span\u003e \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;Setting up \u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e${\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003ename\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e}\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e${\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003eTOP_LEVEL_DOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e}\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003eexport\u003c/span\u003e \u003cspan style=\"color:#f2d5cf\"\u003eLC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e${\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003ename\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e}\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e${\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003eTOP_LEVEL_DOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e}\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    ssh user@example.com -o \u003cspan style=\"color:#f2d5cf\"\u003eControlPath\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003enone -o \u003cspan style=\"color:#f2d5cf\"\u003eSendEnv\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003eLC_GROKDOMAIN -R /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket:127.0.0.1:\u003cspan style=\"color:#f2d5cf\"\u003e$port\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e}\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egrok \u003cspan style=\"color:#f2d5cf\"\u003e$@\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eI put this in \u003ccode\u003e.local/bin/grok\u003c/code\u003e, which is in my path, and now I can just run \u003ccode\u003egrok 8000 test\u003c/code\u003e. I also added in a feature that will generate a random 12 digit hexadecimal tunnel name if we don\u0026rsquo;t specify one. I also explicitly disable \u003ccode\u003eControlPath\u003c/code\u003e in my command \u0026ndash; I noticed that our tunnels don\u0026rsquo;t reliably close if you make use of \u003ccode\u003eControlMaster\u003c/code\u003e at all.\u003c/p\u003e\n\u003ch2 id=\"limitations\"\u003eLimitations\u003c/h2\u003e\n\u003cp\u003eThere are some limitations to this method that I feel are important to address.\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eIf the socket stays behind on the remote host, our tunnel will fail next time and we have to manually connect in and delete it, then disconnect and reconnect our ssh session. (Technically we can do this with control sequences, but that\u0026rsquo;s also a topic for a different time)\u003c/li\u003e\n\u003cli\u003eOur current implementation keeps the interactive session open the whole time \u0026ndash; it would be cool if we could skip the interactive session but keep the session open until we close it. Due to the first limitation, the interactive session is just more useful right now.\u003c/li\u003e\n\u003cli\u003eThis version of this project can\u0026rsquo;t handle arbitrary TCP tunneling \u0026ndash; the nginx block is in an \u003ccode\u003ehttp\u003c/code\u003e block. We can technically setup an arbitrary named TCP tunneling service, but that\u0026rsquo;s definitely a topic for another day\u003c/li\u003e\n\u003cli\u003eThe HTTP logs for basic web servers can\u0026rsquo;t distinguish between clients \u0026ndash; E.g. \u003ccode\u003epython3 -m http.server 8080\u003c/code\u003e results in all requests having a client IP of \u003ccode\u003e127.0.0.1\u003c/code\u003e. I think this can be handled in the nginx config, but I haven\u0026rsquo;t looked further into it yet.\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"putting-it-all-together\"\u003ePutting It All Together\u003c/h2\u003e\n\u003cp\u003eThis should be everything you need to replicate this configuration. Adjust domain names and paths appropriately.\u003c/p\u003e\n\u003cp\u003e(Remote) \u003ccode\u003e/etc/nginx/sites-available/dev.0xda.de.conf\u003c/code\u003e\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-fallback\" data-lang=\"fallback\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eserver {\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    listen 443 ssl;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    listen [::]:443 ssl;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    server_name ~^(.*)\\.dev\\.0xda\\.de$;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    ssl_certificate /etc/letsencrypt/live/dev.0xda.de/fullchain.pem;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    ssl_certificate_key /etc/letsencrypt/live/dev.0xda.de/privkey.pem;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    location / {\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        include proxy_params;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        proxy_pass /tmp/$host.socket;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        error_page 502 /no-tunnel.html;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    }\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    location /no-tunnel.html {\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        return 404 \u0026#34;\u0026lt;center\u0026gt;No such tunnel...\u0026lt;/center\u0026gt;\u0026#34;;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    }\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e}\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003e(Remote) \u003ccode\u003e~/.ssh/rc\u003c/code\u003e\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003eif\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e[\u003c/span\u003e -n \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e]\u003c/span\u003e; \u003cspan style=\"color:#ca9ee6\"\u003ethen\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    chmod o+rw /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket 2\u0026gt;/dev/null\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003eecho\u003c/span\u003e \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;You can now visit https://\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e in your browser\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003efi\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003e(Remote) \u003ccode\u003e~/.bash_logout\u003c/code\u003e\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#737994;font-style:italic\"\u003e# rest of your config here ...\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003eif\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e[\u003c/span\u003e -n \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e]\u003c/span\u003e; \u003cspan style=\"color:#ca9ee6\"\u003ethen\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    rm /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket 2\u0026gt;/dev/null\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003efi\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003e(Local) \u003ccode\u003e~/.local/bin/grok\u003c/code\u003e \u0026ndash; Make sure \u003ccode\u003e~/.local/bin\u003c/code\u003e is in your \u003ccode\u003e$PATH\u003c/code\u003e\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#737994;font-style:italic\"\u003e#!/bin/bash\n\u003c/span\u003e\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egrok\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e()\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e{\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#f2d5cf\"\u003eTOP_LEVEL_DOMAIN\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;dev.0xda.de\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#ca9ee6\"\u003eif\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e[\u003c/span\u003e -z \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$1\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e]\u003c/span\u003e; \u003cspan style=\"color:#ca9ee6\"\u003ethen\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        \u003cspan style=\"color:#99d1db\"\u003eecho\u003c/span\u003e \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;Usage: grok \u0026lt;port\u0026gt; [\u0026lt;name\u0026gt;]\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        \u003cspan style=\"color:#ca9ee6\"\u003ereturn\u003c/span\u003e \u003cspan style=\"color:#ef9f76\"\u003e1\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#ca9ee6\"\u003efi\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003elocal\u003c/span\u003e \u003cspan style=\"color:#f2d5cf\"\u003eport\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$1\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003elocal\u003c/span\u003e \u003cspan style=\"color:#f2d5cf\"\u003ename\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$2\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#ca9ee6\"\u003eif\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e[\u003c/span\u003e -z \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$name\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e]\u003c/span\u003e; \u003cspan style=\"color:#ca9ee6\"\u003ethen\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        \u003cspan style=\"color:#737994;font-style:italic\"\u003e# Generate a random 12-digit hexadecimal string\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e        \u003cspan style=\"color:#f2d5cf\"\u003ename\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#ca9ee6\"\u003e$(\u003c/span\u003eopenssl rand -hex 6\u003cspan style=\"color:#ca9ee6\"\u003e)\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#ca9ee6\"\u003efi\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003eecho\u003c/span\u003e \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;Setting up \u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e${\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003ename\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e}\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e${\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003eTOP_LEVEL_DOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e}\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003eexport\u003c/span\u003e \u003cspan style=\"color:#f2d5cf\"\u003eLC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e${\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003ename\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e}\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e.\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e${\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003eTOP_LEVEL_DOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e}\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    ssh user@example.com -o \u003cspan style=\"color:#f2d5cf\"\u003eControlPath\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003enone -o \u003cspan style=\"color:#f2d5cf\"\u003eSendEnv\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003eLC_GROKDOMAIN -R /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket:127.0.0.1:\u003cspan style=\"color:#f2d5cf\"\u003e$port\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e}\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003egrok \u003cspan style=\"color:#f2d5cf\"\u003e$@\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"conclusion\"\u003eConclusion\u003c/h2\u003e\n\u003cp\u003eI have been using this quite a bit since building it and the quirks definitely make the experience a little less than ideal. But I also don\u0026rsquo;t have to run any new applications on my server, don\u0026rsquo;t have new credentials to worry about, and it works well enough that it\u0026rsquo;s easy for me to quickly send someone a customized link to a development tunnel.\u003c/p\u003e\n\u003cp\u003eShould you use this? I\u0026rsquo;m not sure, really. It feels kinda sketchy to pass the Host header directly to the filesystem, and I\u0026rsquo;m not particularly happy with giving the whole server read/write to the socket file either.\u003c/p\u003e\n\u003cp\u003eBut it was fun to piece these two pieces of technology together in this surprisingly useful way, using knowledge that isn\u0026rsquo;t particularly arcane but also isn\u0026rsquo;t particularly common.\u003c/p\u003e\n\u003cp\u003ePlease \u003ca href=\"https://twitter.com/intent/tweet?text=%400xdade%20re%3A%20grok%20-%20\"\u003etweet me\u003c/a\u003e with ways you\u0026rsquo;d improve this. You can also message me on Bluesky (\u003ca href=\"https://bsky.app/profile/0xda.de\"\u003e@0xda.de\u003c/a\u003e) or Mastodon (\u003ca href=\"https://crime.st/@dade\"\u003e@dade@crime.st\u003c/a\u003e).\u003c/p\u003e\n\u003ch2 id=\"errata\"\u003eErrata\u003c/h2\u003e\n\u003ch3 id=\"improving-socket-cleanup\"\u003eImproving socket cleanup\u003c/h3\u003e\n\u003cp\u003eHN User \u003ca href=\"https://news.ycombinator.com/item?id=40035922\"\u003emcint\u003c/a\u003e recommended using bash\u0026rsquo;s trap command to cleanup the socket on disconnect. By itself this didn\u0026rsquo;t work because it automatically removed the socket when \u003ccode\u003e.ssh/rc\u003c/code\u003e finished running. But in awful, inelegant fashion, I combined it with an infinite sleep loop and was able to get a much more reliable cleanup mechanism.\u003c/p\u003e\n\u003cp\u003eThis seems to clean up no matter what \u0026ndash; I can \n\n\u003ckbd\u003ectrl\u003c/kbd\u003e\u003cspan\u003e+\u003c/span\u003e\u003ckbd\u003ec\u003c/kbd\u003e\n and it\u0026rsquo;ll clean up. I can kill the ssh connection and it\u0026rsquo;ll clean up. I can kill the ssh connection through my bastion host, get a broken pipe, and it\u0026rsquo;ll clean up. It\u0026rsquo;s a considerably more robust cleanup, and equally as hacky to boot.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003eif\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e[\u003c/span\u003e -n \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e\u0026#34;\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e]\u003c/span\u003e; \u003cspan style=\"color:#ca9ee6\"\u003ethen\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    chmod o+rw /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket 2\u0026gt;/dev/null\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    clean_socket\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e()\u003c/span\u003e \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e{\u003c/span\u003e rm /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket 2\u0026gt;/dev/null; \u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e}\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003eecho\u003c/span\u003e \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;You can now visit https://\u003c/span\u003e\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e\u003cspan style=\"color:#a6d189\"\u003e in your browser\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#99d1db\"\u003etrap\u003c/span\u003e clean_socket EXIT INT HUP;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e    \u003cspan style=\"color:#ca9ee6\"\u003ewhile\u003c/span\u003e true; \u003cspan style=\"color:#ca9ee6\"\u003edo\u003c/span\u003e sleep 60; \u003cspan style=\"color:#ca9ee6\"\u003edone\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\u003cspan style=\"color:#ca9ee6\"\u003efi\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eYou can also change your \u003ccode\u003egrok\u003c/code\u003e script\u0026rsquo;s ssh command to cleanup the output with this in mind, as long as you \u003cem\u003edon\u0026rsquo;t\u003c/em\u003e want an interactive ssh session combined with your dev tunnel.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-bash\" data-lang=\"bash\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003essh user@example.com -o \u003cspan style=\"color:#f2d5cf\"\u003eControlPath\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003enone -o \u003cspan style=\"color:#f2d5cf\"\u003eSendEnv\u003c/span\u003e\u003cspan style=\"color:#99d1db;font-weight:bold\"\u003e=\u003c/span\u003eLC_GROKDOMAIN -T -R /tmp/\u003cspan style=\"color:#f2d5cf\"\u003e$LC_GROKDOMAIN\u003c/span\u003e.socket:127.0.0.1:\u003cspan style=\"color:#f2d5cf\"\u003e$port\u003c/span\u003e \u003cspan style=\"color:#99d1db\"\u003eecho\u003c/span\u003e \u003cspan style=\"color:#a6d189\"\u003e\u0026#34;hello\u0026#34;\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eThis adds \u003ccode\u003e-T\u003c/code\u003e, which disables the pseudo-tty allocation. It\u0026rsquo;s designed to run simple commands on a remote host without a full shell environment. Hence, \u003ccode\u003eecho \u0026quot;hello\u0026quot;\u003c/code\u003e at the end of the command now. But what that command is is irrelevant, because our \u003ccode\u003e.ssh/rc\u003c/code\u003e is now infinitely looping and will never let that code execute. It has the added benefit of not printing out the MOTD, so your shell output is quieter:\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-fallback\" data-lang=\"fallback\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e➜ grok 8080 test\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eSetting up test.dev.0xda.de\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eEnter passphrase for key \u0026#39;/home/dade/.ssh/id_ed25519\u0026#39;:\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eYou can now visit https://test.dev.0xda.de in your browser\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch3 id=\"security-of-passing-user-input-to-the-filesystem-path\"\u003eSecurity of passing user input to the filesystem path\u003c/h3\u003e\n\u003cp\u003eI also had a couple people ask me about whether or not it was safe to use the \u003ccode\u003e$host\u003c/code\u003e variable in a path to my filesystem. My understanding of this, based on \u003ca href=\"https://nginx.org/en/docs/http/request_processing.html\"\u003ehow nginx processes a request\u003c/a\u003e, is yes. The TL;DR of it is that \u003ccode\u003e$host\u003c/code\u003e should be guaranteed to match my \u003ccode\u003eserver_name\u003c/code\u003e regex by the time it reaches the \u003ccode\u003eproxy_pass\u003c/code\u003e directive, so long as my dev tunnel server block isn\u0026rsquo;t also the default server block.\u003c/p\u003e\n\u003cp\u003eHypothetically, it might be possible to try to access something like \u003ccode\u003eHost: ../etc/passwd.dev.0xda.de.socket\u003c/code\u003e \u0026ndash; however as long as I\u0026rsquo;m pretty reasonable about not renaming arbitrary important system files with this naming pattern, it\u0026rsquo;s probably pretty safe. Also I\u0026rsquo;m \u003cem\u003efairly\u003c/em\u003e sure, but haven\u0026rsquo;t looked at the source to confirm, that \u003ccode\u003e/\u003c/code\u003e isn\u0026rsquo;t valid in a \u003ccode\u003eHost\u003c/code\u003e header. Attempting to send one to my nginx server results in a 400 bad request instead of a 502 bad gateway, suggesting that it isn\u0026rsquo;t matching the server block.\u003c/p\u003e\n"
        },
        {
            "title": "Docker Desktop \u0026 WSL Randomly Breaks",
            "date_published": "2024-04-10T21:41:40-07:00",
            "date_modified": "2024-04-10T21:44:34-07:00",
            "id": "https://0xda.de/blog/2024/04/docker-desktop-wsl-randomly-breaks/",
            "url": "https://0xda.de/blog/2024/04/docker-desktop-wsl-randomly-breaks/",
            "content_html": "\u003cp\u003eHas your docker connection in WSL2 suddenly stopped working after updating Docker Desktop? Or maybe after a windows update? Or maybe after rebooting?\u003c/p\u003e\n\u003cp\u003eYou\u0026rsquo;re not crazy. You\u0026rsquo;ve experienced this before. Others have experienced this before, and sometimes even worse variants, like the \u003ca href=\"https://github.com/docker/for-win/issues/13990\"\u003eWSL integration stops working on reboot\u003c/a\u003e. You might be tempted to think something complicated is broken, with dangling symlinks or something. You might see some stack overflow posts that would leave you to believe that you need to be running systemd. \u003cstrong\u003eYou do not.\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThe fix is easy and with any luck you\u0026rsquo;ll check your own notes before you scour the internet trying to fix this again next time.\u003c/p\u003e\n\u003cp\u003eIn Docker Desktop configuration, there is a setting in the \u0026ldquo;General\u0026rdquo; section about \u0026ldquo;Use the WSL 2 based engine\u0026rdquo; \u0026ndash; You will probably think this is the setting you need to toggle off and back on for your WSL integration to start working again. \u003cstrong\u003eYou would be wrong.\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eWhat you actually want is to click on \u0026ldquo;Resources\u0026rdquo; and then when the sidebar menu expands, click on \u0026ldquo;WSL integration.\u0026rdquo; It is here that your setting has probably been messed up. Make sure that WSL integration is turned on for the WSL distribution you\u0026rsquo;re using.\u003c/p\u003e\n\u003cp\u003eClick \u0026ldquo;Apply \u0026amp; restart.\u0026rdquo;\u003c/p\u003e\n\u003cp\u003eCarry on with your actual projects instead of spending half an hour getting pissed off at computers, telling yourself you\u0026rsquo;re going to sell everything you own and open that beach bar in Costa Rica you\u0026rsquo;ve been talking about for 10 years. You don\u0026rsquo;t even drink that much, and sand will get in your underwear. You don\u0026rsquo;t want that, do you? Just fix docker and go back to that project you\u0026rsquo;ll never finish, nerd.\u003c/p\u003e\n"
        },
        {
            "title": "NixOS, ESXi, \u0026 Secure Boot",
            "date_published": "2024-03-04T23:15:38-08:00",
            "date_modified": "2024-03-17T13:11:03-07:00",
            "id": "https://0xda.de/blog/2024/03/nixos-esxi-secure-boot/",
            "url": "https://0xda.de/blog/2024/03/nixos-esxi-secure-boot/",
            "content_html": "\u003cp\u003eI spent a fair bit of time this evening trying to get \u003ca href=\"https://nixos.org/\"\u003eNixOS\u003c/a\u003e installed in a VM on my ESXi server, and this note just captures the silly problem \u003ca href=\"https://technowizardry.net\"\u003eAdam\u003c/a\u003e and I had.\u003c/p\u003e\n\u003cp\u003eWhen setting up a new VM in ESXi, you get prompted fairly early on for what type of guest OS the VM is going to be. Historically, all of my VMs were just Ubuntu, so I had only ever used Ubuntu (64-bit) as my selection here. But with NixOS, that felt like the wrong thing, so I selected Other 4.x or later Linux (64-bit) and went on my way. VMXNET3 adapter with a manually set mac address so I can hook it up to my IP block from OVH. Boot from a Datastore ISO file that contains the NixOS minimal installer. We\u0026rsquo;re off to the races.\u003c/p\u003e\n\u003cp\u003eOr so I thought.\u003c/p\u003e\n\u003cp\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  \n  \n    \n    \n    \n    \n    \n    \n    \n    \n  \u003cpicture\u003e\n    \u003csource srcset=\"/blog/2024/03/nixos-esxi-secure-boot/img/nixos-esxi-secureboot-1_hu_b58d627cee15076a.webp\" type=\"image/webp\" /\u003e\n  \u003cimg class=\"img\" src=\"/blog/2024/03/nixos-esxi-secure-boot/img/nixos-esxi-secureboot-1.e59369f9bee94b887bb6153ae1ae93ee.png\" alt=\"Unsuccessful boot\" loading=\"lazy\" height=\"699\" width=\"1027\" /\u003e\n\u003c/picture\u003e\n\u003c/p\u003e\n\u003cp\u003eThe boot failed from the CDROM drive. I\u0026rsquo;d not had this happen before, because I always selected Ubuntu and always subsequently installed Ubuntu.\u003c/p\u003e\n\u003cp\u003eWe tried again and again to boot it. Made sure the hash of the ISO was the same to make sure it didn\u0026rsquo;t get corrupted while being uploaded. Nothing was wrong, it just wouldn\u0026rsquo;t boot.\u003c/p\u003e\n\u003cp\u003eBack to the beginning, I made a new VM, but this time selected \u0026ldquo;Other Linux (64-bit).\u0026rdquo; This option annoyed me because I didn\u0026rsquo;t know that I couldn\u0026rsquo;t use VMXNET3 on this guest OS, and \u003ca href=\"https://www.lewan.com/blog/choosing-the-right-vmware-nic-should-you-replace-your-e1000-with-the-vmxnet3\"\u003eusing the E1000 driver has performance impact\u003c/a\u003e. But I moved on, set the boot from the ISO, and started it up.\u003c/p\u003e\n\u003cp\u003eAnd we were booted.\u003c/p\u003e\n\u003cp\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  \n  \n    \n    \n    \n    \n    \n    \n    \n    \n  \u003cpicture\u003e\n    \u003csource srcset=\"/blog/2024/03/nixos-esxi-secure-boot/img/nixos-esxi-secureboot-2_hu_aaa55a5d1905d771.webp\" type=\"image/webp\" /\u003e\n  \u003cimg class=\"img\" src=\"/blog/2024/03/nixos-esxi-secure-boot/img/nixos-esxi-secureboot-2.c2f9a4f302e14e4d425305c07dfc96fa.png\" alt=\"NixOS installer\" loading=\"lazy\" height=\"760\" width=\"1017\" /\u003e\n\u003c/picture\u003e\n\u003c/p\u003e\n\u003cp\u003eWeird. Why did simply changing this Guest OS setting during setup change the ability of the installer to run? It\u0026rsquo;s not like it was starting up the installer and then failing partway through, it was just failing immediately.\u003c/p\u003e\n\u003cp\u003eI went back to the first VM, shut it down, and tried to change the guest OS type to \u0026ldquo;Other Linux (64-bit).\u0026rdquo; Booted it up, and it failed again. The same way. What the heck.\u003c/p\u003e\n\u003ch2 id=\"comparing-the-vmx-files\"\u003eComparing the VMX files\u003c/h2\u003e\n\u003cp\u003eThe next thing I tried was to take the \u003ccode\u003e.vmx\u003c/code\u003e files from both VMs and comparing them to see what the difference could be. I downloaded the \u003ccode\u003e.vmx\u003c/code\u003e file for each VM from the datastore and tossed them into \u003ca href=\"https://www.diffchecker.com/\"\u003ediffchecker\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eNot to my surprise, at this point, there were numerous differences. The ones that I thought might play a part are included below.\u003c/p\u003e\n\u003ch3 id=\"functional-vmx\"\u003eFunctional VMX\u003c/h3\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-fallback\" data-lang=\"fallback\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eide0:0.deviceType = \u0026#34;cdrom-image\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eide0:0.fileName = \u0026#34;/vmfs/volumes/5edb1eff-36987c5f-a604-002590893b4a/ISOs/nixos-minimal-23.11.4976.79baff8812a0-x86_64-linux.iso\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eide0:0.present = \u0026#34;TRUE\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003edisplayName = \u0026#34;adam-nixos\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eguestOS = \u0026#34;otherlinux-64\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch3 id=\"non-functional-vmx\"\u003eNon-functional VMX\u003c/h3\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-fallback\" data-lang=\"fallback\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003esata0:0.deviceType = \u0026#34;cdrom-image\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003esata0:0.fileName = \u0026#34;/vmfs/volumes/5edb1eff-36987c5f-a604-002590893b4a/ISOs/nixos-minimal-23.11.4976.79baff8812a0-x86_64-linux.iso\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003esata0:0.present = \u0026#34;TRUE\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003edisplayName = \u0026#34;dade-nixos\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eguestOS = \u0026#34;other4xlinux-64\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003euefi.secureBoot.enabled = \u0026#34;TRUE\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eI wondered if the NixOS installer didn\u0026rsquo;t work correctly on a SATA CDROM device. This seemed like a dumb thing to wonder, in hindsight. I was on the right track, just looking at the wrong setting.\u003c/p\u003e\n\u003cp\u003eThe important bit here was that last line.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-fallback\" data-lang=\"fallback\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003euefi.secureBoot.enabled = \u0026#34;TRUE\u0026#34;\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003ch2 id=\"secure-boot\"\u003eSecure Boot\u003c/h2\u003e\n\u003cp\u003eIt turns out, NixOS doesn\u0026rsquo;t support \u003ca href=\"https://en.wikipedia.org/wiki/UEFI#SECURE-BOOT\"\u003esecure boot\u003c/a\u003e out of the box. \u003ca href=\"https://nixos.wiki/wiki/Secure_Boot\"\u003eNixOS Wiki\u003c/a\u003e has a page about this, and recommends the \u003ca href=\"https://github.com/nix-community/lanzaboote\"\u003eLanzaboote\u003c/a\u003e project if you\u0026rsquo;re interested in enabling Secure Boot for your NixOS installation.\u003c/p\u003e\n\u003cp\u003eThat\u0026rsquo;s great and all, but what I\u0026rsquo;m interested in is a functional virtual machine live installer experience. Maybe we can turn secure boot on later, who knows. But for now, let\u0026rsquo;s change that setting and see if it works. I powered off the broken machine, went into the edit menu, selected \u0026ldquo;VM Options\u0026rdquo; at the top, and then went into \u0026ldquo;Boot Options.\u0026rdquo; From here, I toggled off the \u0026ldquo;Enable UEFI secure boot\u0026rdquo; option.\u003c/p\u003e\n\u003cp\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n  \n  \n    \n    \n    \n    \n    \n    \n    \n    \n  \u003cpicture\u003e\n    \u003csource srcset=\"/blog/2024/03/nixos-esxi-secure-boot/img/nixos-esxi-secureboot-3_hu_1d2a84594a77a82d.webp\" type=\"image/webp\" /\u003e\n  \u003cimg class=\"img\" src=\"/blog/2024/03/nixos-esxi-secure-boot/img/nixos-esxi-secureboot-3.152a52ec147c3e653cbf1169b697fb26.png\" alt=\"ESXi Secure Boot boolean option\" loading=\"lazy\" height=\"631\" width=\"779\" /\u003e\n\u003c/picture\u003e\n\u003c/p\u003e\n\u003cp\u003eI saved my changes and fired up the VM again. The live installer works, but now with a VMXNET3 adapter. Huzzah!\u003c/p\u003e\n\u003cp\u003eNow to face the bigger problem: How do I install NixOS?\u003c/p\u003e\n"
        },
        {
            "title": "Helm to Mailinabox",
            "date_published": "2022-12-26T23:12:20-08:00",
            "date_modified": "2024-03-17T13:11:03-07:00",
            "id": "https://0xda.de/blog/2022/12/helm-to-mailinabox/",
            "url": "https://0xda.de/blog/2022/12/helm-to-mailinabox/",
            "content_html": "\u003cp\u003eI\u0026rsquo;ve been using a personal email server called Helm for the past few years to run my mail, and I\u0026rsquo;ve loved it. It did come with an annual fee of $99, which was used to pay for the \u0026ldquo;Gateway\u0026rdquo; server that they ran in AWS, along with support costs etc. But the mail lived in my apartment had a public IP address that trafficked all of my connections and all of my email. I liked the idea of having my mail in my apartment, and Helm made it really easy to do so.\u003c/p\u003e\n\u003cp\u003eUnfortunately, Helm is shutting down in a few days, and I have to migrate all of my mail off of it. Despite running the server in my apartment for the last several years, it wasn\u0026rsquo;t really \u003cem\u003emy\u003c/em\u003e server, in that I don\u0026rsquo;t have a shell on it. I\u0026rsquo;m sure I could have started working to figure out how to pull that off when I got the shut down notice, but instead I said \u0026ldquo;Eh I\u0026rsquo;ll have plenty of time.\u0026rdquo; And here we are, shutdown is in 4 days.\u003c/p\u003e\n\u003cp\u003eInstead of trying to break into my own little triangle server of email, I decided I\u0026rsquo;d use this as an opportunity to run a mail-in-a-box server and try to migrate my mail to it. Mail-in-a-box has been around for some time and claims to be very easy to setup, albeit not supporting many configuration options. But having manually run a mail server before, I\u0026rsquo;ll take easy over highly customizable any day. I\u0026rsquo;m quite familiar with setting up SPF, DKIM, DMARC, the importance of a PTR record, etc. Hell, I\u0026rsquo;m even familiar with setting up MTA-STS. But it\u0026rsquo;s a chore, and easy sounds nice.\u003c/p\u003e\n\u003cp\u003eUnfortunately, since I don\u0026rsquo;t have a shell on my Helm server, I can\u0026rsquo;t just use doveadm to sync the mailbox to a new server and keep it synced while transferring DNS (both helm and mail-in-a-box insist on managing DNS themselves, which does make management easier but also makes migration kind of annoying). Instead, I\u0026rsquo;ll have to sync my mailboxes one at a time.\u003c/p\u003e\n\u003ch2 id=\"setting-up-mail-in-a-box\"\u003eSetting up Mail-in-a-box\u003c/h2\u003e\n\u003cp\u003eThis process really was as easy as it says on the tin. I was one curl | sudo bash away from a functional mail server. The experience was a little clunky at first, since it didn\u0026rsquo;t tell me to setup DNS during the installation (I couldn\u0026rsquo;t have, anyways, at least not yet), so I had to access via the IP address directly. A few sudo failed to resolve hostname errors later, and I was in the mail-in-a-box web admin panel.\u003c/p\u003e\n\u003cp\u003eI added my mailboxes as new users in mail-in-a-box, and then, without logging into those mailboxes, I took to my terminal to get doveadm prepared.\u003c/p\u003e\n\u003ch2 id=\"migrating-over-imap-with-doveadm\"\u003eMigrating over IMAP with doveadm\u003c/h2\u003e\n\u003cp\u003eThe documentation provided by dovecot is a little iffy on this topic. It\u0026rsquo;s technically all there, and technically all correct. But if you\u0026rsquo;ve never done it before, then it seems to make a few assumptions that I struggled to understand at first. The documentation gives some config settings to set, but doesn\u0026rsquo;t really tell you where to set them. After some googling and reviewing the config file of the version of dovecot I was running, I decided I should put the config in \u003ccode\u003e/etc/dovecot/conf.d/dovecot-migration.conf\u003c/code\u003e. After putting the file in the right place and setting my client configuration up to talk to the Helm server, I was ready to \u003ccode\u003esystemctl reload dovecot\u003c/code\u003e and get ready to run the command.\u003c/p\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cpre tabindex=\"0\" style=\"color:#c6d0f5;background-color:#303446;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"\u003e\u003ccode class=\"language-fallback\" data-lang=\"fallback\"\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eroot@box:/etc/dovecot# cat conf.d/dovecot-migration.conf\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e# these are supported by standard adhering servers\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eimapc_features = rfc822.size fetch-headers\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e# If the old IMAP server uses INBOX. namespace prefix, set:\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e#imapc_list_prefix = INBOX\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e# Remote hostname\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eimapc_host = helm.\u0026lt;mydomain\u0026gt;.org\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e## if you are using TLS\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eimapc_ssl = imaps\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eimapc_port = 993\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003email_prefetch_count = 20\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e#imapc_ssl_verify = no\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e## these default to system\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003essl_client_ca_dir = /etc/ssl/certs\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e# or\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e#ssl_client_ca_file = /etc/ssl/certs/ca-certificates.crt\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eimapc_user = %u\n\u003c/span\u003e\u003c/span\u003e\u003cspan style=\"display:flex;\"\u003e\u003cspan\u003eimapc_password = \u0026lt;my_old_password_from_the_helm\u0026gt;\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eProvided the configuration is correct and dovecot loaded it, all that\u0026rsquo;s left is to backup the mail to my new server.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003edoveadm -o mail_fsync=never backup -R -u dade@\u0026lt;mydomain\u0026gt;.org imapc:\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eAfter this command completes, I can head over to the roundcube app provided by mail-in-a-box and make sure that my emails are all present. I repeated this step for each mailbox I needed to migrate, by just changing the username and password as necessary.\u003c/p\u003e\n\u003ch2 id=\"finishing-setup-for-mail-in-a-box\"\u003eFinishing setup for mail-in-a-box\u003c/h2\u003e\n\u003cp\u003eAfter migrating my mail, it was just about time to cut over my DNS. Technically a few emails could come in between when I did the backup and when I cut over DNS, but we\u0026rsquo;ll worry about that later.\u003c/p\u003e\n\u003cp\u003eThe mail-in-a-box admin panel has a very handy status page that lists out the things that still need to be configured. So first, I\u0026rsquo;ll head over to Gandi and set the glue records\u003csup id=\"fnref:1\"\u003e\u003ca href=\"#fn:1\" class=\"footnote-ref\" role=\"doc-noteref\"\u003e1\u003c/a\u003e\u003c/sup\u003e for \u003ccode\u003ens1.box.\u0026lt;mydomain\u0026gt;.org\u003c/code\u003e and \u003ccode\u003ens2.box.\u0026lt;mydomain\u0026gt;.org\u003c/code\u003e, and then update my nameservers to no longer point at AWS and instead point at my glue records. The glue records point to my mail-in-a-box server.\u003c/p\u003e\n\u003cp\u003eAfter updating DNS, I sat back for a little while, chatting with a friend about IP based mail reputation and \u003ca href=\"https://chown.me/blog/getting-my-own-asn\"\u003egetting our own ASNs\u003c/a\u003e, until DNS did its thing and then mail-in-a-box was able to resolve all the DNS names correctly. Once mail-in-a-box became the nameserver, it also became the mail server. All new mail should be going to the new mail server and not to my helm any longer. We can test this by sending a quick email and making sure we receive it via roundcube on the mail-in-a-box server.\u003c/p\u003e\n\u003ch2 id=\"retrieving-the-automatic-backups\"\u003eRetrieving the automatic backups\u003c/h2\u003e\n\u003cp\u003eI try to keep most of my servers fairly locked down, which includes setting up administrative services (such as ssh) to only accept connections from a bastion server. I also don\u0026rsquo;t like services on my home network to be listening on the internet (e.g. I don\u0026rsquo;t want to port forward for my NAS). But I need to get the automatic backups that are being created by the mail-in-a-box provided duplicity service, and I need to be able to do it on a regular schedule, so that even if the server goes down, I can recover my mail. Mail-in-a-box supports many backup destinations, but I don\u0026rsquo;t really want to pay for additional commercial services, especially when I have tens of terabytes of free space at home.\u003c/p\u003e\n\u003cp\u003eEnter Tailscale. I\u0026rsquo;ve been using tailscale for my personal devices for several months now and have been pleased with how easy it makes it to connect my devices. Installing tailscale and getting the server added to my tailnet was remarkably easy, following the instructions for \u003ca href=\"https://tailscale.com/kb/1187/install-ubuntu-2204/\"\u003esetting up tailscale on ubuntu 20.04\u003c/a\u003e, then I added another ufw firewall rule for allowing incoming traffic from my tailnet, via \u003ccode\u003esudo ufw allow in on tailscale0\u003c/code\u003e. Now I can reach the server over the internet via my bastion, or via my tailnet.\u003c/p\u003e\n\u003cp\u003eMy Synology DiskStation is also running tailscale, so now I can setup a scheduled task on my Synology to automatically rsync from the server to a local shared folder. I chose to go this direction because it was going to be easier to setup than having the mail-in-a-box rsync to the Synology, since the Synology doesn\u0026rsquo;t seem to support setting an SSH key for rsync users, and also rsync seems to require that users be Synology administrators to use it?? Absolutely trash tier design, so instead we\u0026rsquo;ll make the synology pull the encrypted backups from the remote service daily.\u003c/p\u003e\n\u003cp\u003eAnother important thing, before going any further, is to save the secret key used by mail-in-a-box (i.e. duplicity) to a safe place, since I\u0026rsquo;ll need that to decrypt the backups in the future. I saved mine to my password manager vault.\u003c/p\u003e\n\u003cp\u003eI haven\u0026rsquo;t finished setting up automatic backups to my personal NAS yet, but I\u0026rsquo;ll update this page if/when I do. It should be pretty simple, just need to actually spend the time working through it.\u003c/p\u003e\n\u003cdiv class=\"footnotes\" role=\"doc-endnotes\"\u003e\n\u003chr\u003e\n\u003col\u003e\n\u003cli id=\"fn:1\"\u003e\n\u003cp\u003eGlue records are a way to associate a hostname with an IP address at the registry level. This is necessary if your domain is going to be hosting it\u0026rsquo;s own nameservers, since otherwise resolvers would get stuck in a loop.\u0026#160;\u003ca href=\"#fnref:1\" class=\"footnote-backref\" role=\"doc-backlink\"\u003e\u0026#x21a9;\u0026#xfe0e;\u003c/a\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003c/div\u003e\n"
        }
        ]
}
