I donāt think I have taken my personal MacBook Air outside of my home in over two years. My iPhone handles most of what I need and I do real work on my work laptop. However, I do sometimes find a reason to need to grab my personal MacBook. Maybe I left a file locally on it that I need, Iām using an iPad and I need the desktop version of a site, or I just want to write a longer response to an iMessage thread and prefer a keyboard.
Last summer, I wrote about running your own browser-based VS Code. I love the idea of moving more use cases into a browser. Any device with a modern can become part of your workflow with just a couple clicks. In todayās post, Iām going to go beyond just a single use case or application - instead, Iām going to walk through moving my entire Mac into a browser.
šÆ I have a few goals for this project:
šŗļø This walkthrough covers how to:
ā²ļøTime to complete: ~45 minutes
š I work there. I work at Cloudflare. Several of my posts on this blog that discuss Cloudflare focus on building things with Cloudflare Workers. Iām a Workers customer and pay my invoice to use it. However, this tutorial uses products where Iām on the team (Access and Tunnel).
I want to be the only person who can reach this device. To do that, Iām going to start by building a rule in Cloudflare Access, the access control layer of Cloudflareās Zero Trust portfolio.
Cloudflare Access follows a Zero Trust architecture: by default, Access assumes every connection or request is untrusted and forces the user (or service) to authenticate. This gives me the security posture I need to build a simple rule to only allow myself to reach this device.
For obscurity purposes, Iām building all of these rules and configuring the steps in this tutorial with a different hostname from what Iāll use long-term.
To begin, Iām going to navigate to the Cloudflare for Teams dashboard. Iāll choose Access
from the sidebar and Iāll click Add an application.
Iāll give the application a name and input the URL where the application will be available. Weāll create the DNS record for that URL later in this tutorial when we connect my Mac with Cloudflare Tunnel
Next, Iām going to create a rule that will only allow me to reach this destination. The action here is just Allow
. Thanks to the Zero Trust model in Cloudflare Access, everything not allowed will be denied by default so this is the only policy I need.
Iāll scroll down to the bottom of the page to define who is allowed by defining an Include
rule. in this case, itās a single email address. Iāll come back and add a Require
rule to force logins to use a hardkey as the multifactor method.
Alright, now the fun part. Iām first going to configure a custom logo for this application. Iāve found an Apple logo at a public URL that Iāll paste into the field here.
Next, I want to control the identity providers this application can use. As you can see, Iāve integrated several, but I will limit it to just a few options.
Finally, Iām going to set this to be a VNC
application on the last page of this configuration flow. Choosing VNC
will tell Cloudflare to render this non-HTTP use case in the browser.
Once saved, the application (and the custom logo) will appear in my Application list and I can begin connecting my Mac.
macOS devices can create VNC servers using its default āScreen Sharingā feature. To begin, Iāll navigate to my system settings and choose Sharing
. Once there, I need to toggle āScreen Sharingā to enabled.
Next, Iāll click āComputer Settingsā¦ā where I will add a password to allow viewers to control the screen.
Youāll probably notice that this requires a URL available on my local network. My local network in this case is just my home. Connecting still requires my device password, so itās not terribly different from someone already in my home walking over to my device and trying to type in my password. That said, itās something to keep in mind and a topic Iām going to address in a follow-up blog on home network security.
I mentioned earlier that I want the convenience of being able to reach this from the public Internet, but I do not want to expose any ports or IPs to the public Internet. Cloudflare Tunnel solves that for me.
Cloudflare Tunnel relies on a lightweight connector, cloudflared
, to create an outbound-only connection from my infrastructure (in this case my Mac) to Cloudflareās edge. I can run a single instance of cloudflared
to support multiple applications and hostnames, but in this example Iām just running it for this particular workflow.
Iām running
cloudflared
on my Mac as a manual process. In the āWhatās Next?ā section below, Iāll add instructions on running it as a service and my plans to put it on a Raspberry Pi in front of the Mac.
First, Iāll download cloudflared
on to the Mac that I want to reach. Iāll use the package manager brew
but you can also build cloudflared
yourself or download the latest release using its open-source repository.
brew install cloudflare/cloudflare/cloudflared
Next, I need to authenticate this instance of cloudflared
into my Cloudflare account. This step allows the connector to create connections and DNS records in my account.
cloudflared tunnel login
Iāll be prompted to sign in to my Cloudflare account in my browser and Cloudflare will return a certificate to my device.
I can now create the Tunnel in my acccount with the following command.
cloduflared tunnel create macbook
Once created, Cloudflare will generate a UUID and credentials file for the Tunnel. To run this Tunnel, at any time, all I need is that credentials file. I can delete the original authentication certificate after creating the DNS records if I want to do so.
Next, I want to configure cloudflared
to send traffic destined for the hostname I protected earlier to the VNC port on my target Mac.
The configuration file below takes the UUID of the Tunnel I created earlier, the credentials file for that Tunnel, and defines ingress for that Tunnel.
tunnel: 5493469b-01fe-8b3f-0003abb31654
credentials-file: /Users/samuelrhea/.cloudflared/5493469b-01fe-8b3f-0003abb31654.json
ingress:
- hostname: mac-browser.widgetcorp.tech
service: tcp://localhost:5900
- service: http_status:404
Once I save that configuration file, I need to tie the hostname I want to use to the Tunnel I just created. I can do that without leaving the command line. The command below will create a DNS record in my Cloudflare account and associate it with this Tunnel.
cloudflared tunnel route dns macbook mac-browser.widgetcorp.tech
And with that, I can go ahead and run the Tunnel and it will connect to two nearby data centers in Cloudflareās network.
cloudflared tunnel run macbook
I can now test this out. Iāll go to a different machine and visit the URL in my browser.
When I do, Iām prompted to authenticate with one of the three identity providers I allowed earlier.
Alternatively, I can go to my App Launcher where I can launch this application and any other Iām able to reach.
Either way, when I connect to the application Iāll be prompted to input the VNC password I created previously.
And, once Iāve input my password, I can remotely access my Mac in Chrome on a different device.
The steps described in this tutorial require that cloudflared
is running (in addition to the Mac itself). I can go go ahead and use launchtl
on macOS to run cloudflared
like a service, but what I really want to do is instead put cloudflared
on a Raspberry Pi in my home to serve this use case and others. Iāve promised that tutorial in past posts and Iāll get to it.
A couple of notes on set up and usage, though: