<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Cloudflared on Taras&#39; Blog on AI, Perf, Hacks</title>
    <link>/tags/cloudflared/</link>
    <description>Recent content in Cloudflared on Taras&#39; Blog on AI, Perf, Hacks</description>
    <image>
      <title>Taras&#39; Blog on AI, Perf, Hacks</title>
      <url>/images/papermod-cover.png</url>
      <link>/images/papermod-cover.png</link>
    </image>
    <generator>Hugo -- 0.147.0</generator>
    <language>en</language>
    <copyright>Taras Glek</copyright>
    <lastBuildDate>Sun, 10 Mar 2024 14:29:26 +0200</lastBuildDate>
    <atom:link href="/tags/cloudflared/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>ssh-via-cloudflare-tunnel: Alternative way to expose machines behind NAT</title>
      <link>/posts/cloudflare-ssh/</link>
      <pubDate>Sun, 10 Mar 2024 14:29:26 +0200</pubDate>
      <guid>/posts/cloudflare-ssh/</guid>
      <description>&lt;p&gt;I have an intermittent issue where one of my machines on a specifc network seems to be operational locally on network but not accessible over &lt;a href=&#34;https://netbird.io/&#34;&gt;netbird&lt;/a&gt; some of the time. I could not tell if the problem was due to the network the problematic machine was on or due to netbird.&lt;/p&gt;
&lt;p&gt;So to debug this I:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Setup a grafana node agent to report journald logs to &lt;a href=&#34;grafana.com&#34;&gt;https://grafana.com/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Setup to docker to log to journald&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Wrote &lt;a href=&#34;https://github.com/tarasglek/ssh-via-cloudflare-tunnel&#34;&gt;ssh-via-cloudflare-tunnel&lt;/a&gt; docker-compose stack to tunnel ssh over websocat to internet over &lt;a href=&#34;https://github.com/cloudflare/cloudflared&#34;&gt;cloudflared&lt;/a&gt;. Set docker compose to restart-on-failure.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Today netbird had some downtime (tailscale had theirs just a few days before that). I was able to log into grafana, look up the temporary hostname cloudflare assigned to me and ssh in using&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ssh -o ProxyCommand=&amp;quot;websocat -E --binary - -v %h&amp;quot; -o ServerAliveInterval=10 wss://library-won-nt-gauge.trycloudflare.com&lt;/code&gt;&lt;/p&gt;
&lt;h1 id=&#34;architecture&#34;&gt;Architecture&lt;/h1&gt;
&lt;pre&gt;&lt;code class=&#34;language-mermaid&#34;&gt;graph TD;
    A[ssh client] &amp;lt;--&amp;gt;|Invoke websocat over ProxyCommand| B[websocat client-mode]
    B &amp;lt;--&amp;gt;|WebSocket to Stdio| D(Cloudflare)
    D &amp;lt;--&amp;gt;|HTTPS to WebSocket| E[cloudflared Server]
    E &amp;lt;--&amp;gt;|Reverse proxy over HTTPS| F[websocat server-mode]
    F &amp;lt;--&amp;gt;|Stdio to SSH| G[sshd server]

    style A fill:#f9f,stroke:#333,stroke-width:2px
    style B fill:#dfd,stroke:#333,stroke-width:2px
    style D fill:#bbf,stroke:#333,stroke-width:2px,
    style E fill:#ddf,stroke:#333,stroke-width:2px,
    style F fill:#dfd,stroke:#333,stroke-width:2px
    style G fill:#f9f,stroke:#333,stroke-width:2px
&lt;/code&gt;&lt;/pre&gt;
&lt;h1 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;This turned out trivial to do. However it took me over 5 years of pondering, discovering ssh ProxyCommand, cloudflared, websocat and deciding to combine them to conveniently expose ssh over web.&lt;/p&gt;
&lt;p&gt;I think it&amp;rsquo;s pretty cool how Cloudflare allows one expose geographically distributed tunnels without requiring any signups. I wish their UX simpler so it was equally easy to expose tunnels with fixed dns. Cloudflare actually has something similar as an &lt;a href=&#34;https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/use-cases/ssh/#connect-to-ssh-server-with-cloudflared-access&#34;&gt;official ssh feature&lt;/a&gt;, but it requires more hoop jumping.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/vi/websocat&#34;&gt;websocat&lt;/a&gt; is amazing. I use websockets a lot more now that I have a robust way to utilize them without writing any code.&lt;/p&gt;
&lt;h1 id=&#34;why-would-i-want-to-do-this&#34;&gt;Why Would I Want To Do This?&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;As a fallback to tailscale/netbird that uses a completely different network topology as in this case&lt;/li&gt;
&lt;li&gt;To temporarily grant ssh to some machine without requiring end-users to install a vpn&lt;/li&gt;
&lt;li&gt;To bypass restrictive gsm/wifi networks that block access to ssh&lt;/li&gt;
&lt;li&gt;As an alternative to port-knocking to obscure ssh (eg hide ssh behind http basic-auth)&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;how-would-you-improve-this&#34;&gt;How would you improve this?&lt;/h1&gt;
&lt;p&gt;Checkout &lt;a href=&#34;https://github.com/tarasglek/ssh-via-cloudflare-tunnel&#34;&gt;ssh-via-cloudflare-tunnel&lt;/a&gt; on github.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
