A VPN for one application v0.12.5

One application in the VPN. Only that one.

tube firefox connects one of your OpenVPN profiles and starts Firefox so that all of Firefox’s network goes through that VPN. Every other program keeps using the machine’s own network. On Linux it needs no root, no sudo, no system service and no installed openvpn.

Get started GitHub Documentation

go install github.com/rm4n0s/tube/cmd/tube@latest
The Status tab of gtube: Firefox through the profile Work, the address and the DNS server of the tunnel, the traffic, and the events of a connection that ended and came back gtube started for ping: three profiles, one selected, and the button Connect and run ping The Network tab of gtube while Firefox runs: five test profiles, one of them broken, Work in use, and the buttons Use and Disconnect The login page of gtube for the profile Work: a user name, a password drawn as dots, and two boxes to remember them The Output tab of gtube with the lines that the application printed, a field to type for it, and the buttons Send and Ctrl-C gtube alone: the applications of the desktop on the left, and on the right the selected one, its icon with Tube's logo on it, its name in the menu and the button Install

gtube is Tube with windows. Here Firefox runs through the profile Work, and the Status tab shows the tunnel, the traffic and what happened to the connection.

Select one of your OpenVPN profiles, and it connects and starts the application inside that VPN.

Change to another profile, or disconnect, while the application keeps running.

A profile that asks for a user name and a password gets a page for them, and remembers them if you say so.

The Output tab shows what the application prints, and sends it what you type.

Started alone, gtube lists the applications of your desktop and gives one a second menu entry that starts it through the VPN.

1 application

is in the VPN. Nothing of the machine’s network configuration changes

0 root

on Linux. No sudo, no system service and no installed openvpn

3 namespaces

are around the application on Linux, a private user, network and mount namespace

0 cgo

in tube and gtube. CGO_ENABLED=0 builds them too

  • All of its network

    TCP, UDP, ICMP and the looking up of names of the application go through the VPN. Its only way out is a TUN device, and Tube feeds that device from the VPN connection.

  • No network without the VPN

    When the VPN drops, the application keeps running with no network. Tube never lets it use the machine’s network in between, and connects the same profile again by itself.

  • An ordinary user is enough

    On Linux, Tube never uses sudo, a setuid helper or a capability on its binary. On macOS it has a helper that runs as root, which you install once.

How the application is kept in

On Linux the application runs in a private user, network and mount namespace. That namespace has two interfaces, its own loopback and the device tube0, and no route but into the tunnel.

  • Inside, /etc/resolv.conf names the DNS servers of the VPN, or the ones that you set for the profile
  • The application cannot add a route, an address or a device
  • A profile is only parsed. Tube never runs a program that a profile names, such as up or down.
  • Profiles and every file that holds a key have mode 0600, in folders of mode 0700
  • On macOS the helper makes a utun device and firewall (pf) rules that pick the application’s packets out by a group of its own
[Status]  Output  Network
Application   ping, running
VPN           test, connected for 00:00:00
Address       10.8.0.2/24
DNS servers   -
MTU           1500

↓ Received    168 B    2 packets   0 B/s
↑ Sent        168 B    2 packets   0 B/s
  Dropped     0 packets

What you do with it

Tube has a terminal UI in color, that you use with the keys or with the mouse, and a mode without it for scripts. gtube is the same with windows.

Three tabs

Select a profile, and watch the connection

tube firefox opens the list of your OpenVPN profiles. You add .ovpn files there from a list of your folders, look at them, change and delete them, and select one. The terminal UI stays open while Firefox runs, and closes by itself when you close Firefox. The picture shows the same in the window of gtube.

  • Status: the connection, its traffic, and what happened
  • Output: what the application prints. The keys you type go to the application.
  • Network: switch to another profile, or take the network away
  • Tube exits with the application’s exit status
The Status tab of gtube: Firefox through the profile Work, the address and the DNS server of the tunnel, the traffic, and the events of a connection that ended and came back

Scripts

One line, with no questions

--profile connects a profile and runs the application without the terminal UI. The application gets your terminal, so full-screen programs such as ssh and htop work. What a run is missing is asked on the terminal, or given as options.

  • --username, --password, --auth-file and --dns give the answers, and --save keeps them with the profile
  • --password can be seen by the other users of the machine. On a machine that you share, use --auth-file.
  • Where there is no terminal, Tube cannot ask, and ends with an error that names these options
# Add the profile once, and save everything (true does nothing)
tube -p ~/Downloads/work.ovpn --username ada \
     --password 'the password' --dns 10.0.0.53 --save true

# Every run after it needs no option and asks nothing
tube -p work curl https://example.com

# A program that needs the whole terminal
tube -p work ssh host

While it runs

Switch the VPN, or take the network away

On the Network tab you select another profile. Tube connects the new one first, and the application keeps the old one until the new one is connected. When the new one fails, nothing changes.

  • Disconnect leaves the application running, without network, until you choose a profile
  • When the VPN ends by itself, Tube tries again after 1, 2, 4, 8 and 15 seconds, and then every 30 seconds
  • When the server refuses the user name or the password, Tube stops trying, and the application stays without network
The Network tab of gtube while Firefox runs: five test profiles, one of them broken, Work in use, and the buttons Use and Disconnect

gtube

Firefox (Tube), in the menu of your desktop

gtube is a second program, for Linux. It lists the applications of your desktop. Select one and press Install, and the menu gets an entry such as Firefox (Tube), with Tube’s logo on the application’s icon. That entry starts the application through a VPN that you select in a window first.

  • It uses the profiles of tube, and keeps the same promises
  • The entry holds no profile, no key and no password. The VPN is selected in the window each time.
  • Closing the window does not stop the application. The window goes to the tray.
  • gtube writes only in your own folders, and removes only the files that it made
gtube alone: the applications of the desktop on the left, and on the right the selected one, its icon with Tube's logo on it, its name in the menu and the button Install

Firefox and Flatpak

A Firefox of its own

A second firefox asks the one that is already open to do the work, and that one is outside the VPN. So Tube starts Firefox and Thunderbird on a profile of their own, which Tube keeps. Your normal Firefox, open beside it, keeps using the machine’s own network.

  • Tube’s Firefox has its own history, logins, bookmarks and settings, and keeps them between runs
  • A Flatpak application runs through Tube with flatpak run, and gtube makes menu entries for it
  • Tube cannot know this for every other program. When you are not sure, quit the program everywhere before you start it with Tube.
# Apart from a Firefox that is already open
tube firefox

# On a Firefox profile of your choice. Tube then adds nothing
tube firefox -P work

# A Flatpak application
tube flatpak run org.mozilla.firefox

Linux and macOS

On macOS an ordinary user can make neither a network device nor a namespace, so Tube works there in another way, and some promises are weaker.

LinuxmacOS
RightsNone. No root, no sudo, no system serviceA helper that runs as root, installed once with sudo tube --install-helper
How the application is kept inA private user, network and mount namespaceA group of its own, _tube1 to _tube8, and pf rules that pick its packets out by that group
The deviceA TUN device, from /dev/net/tunA utun device, made by the helper for each run
In the VPNTCP, UDP, ICMP and the looking up of namesTCP and UDP. ICMP is not, and names only for the programs that use Tube’s proxy
Runs at onceSeveral, each with its own VPN connectionAt most 8
gtubeYes, on Wayland or X11No

Tube checks what it needs when it starts, and says what is missing. docs/GUIDE.md says what the kernel must allow on Linux and what the helper does on macOS, and docs/SECURITY.md says what Tube promises and how each promise is tested.

Or stay in the terminal

tube does the same from a terminal, with a terminal UI or without one for scripts. Before the VPN is connected, and after it has ended, the application has no network at all.

# Open your profiles, select one, and Firefox runs inside that VPN
$ tube firefox
# The same without the terminal UI. An .ovpn file is added the first time
$ tube -p ~/Downloads/work.ovpn curl https://example.com
tube: added the profile "work"
User name: ada
Password:
DNS servers (empty: the ones of the VPN): 10.0.0.53
Save the user name, the password and the DNS servers with the profile? [Y/n]

What Tube is built from

Tube connects to OpenVPN servers with gopenvpn-conn. The windows of gtube are drawn by Glutter, and Soft installs both programs with their entries in the menu of the desktop.

What Tube does not do

These are the limits that its README lists.

  • A program that hands its work to a process outside the namespace is not in the VPN. Firefox and Thunderbird would do so when one is already open, so for them Tube uses a profile of its own.
  • Services on the machine’s own 127.0.0.1 cannot be reached from the application.
  • Programs that need to gain rights (sudo, a setuid program) do not gain them inside.
  • IPv6 works only when the VPN gives an IPv6 address.
  • What gopenvpn-conn does not support is not supported: compression, proxies, static keys, encrypted private keys, and challenge/response logins.
  • In the terminal UI the application’s terminal shows plain lines. A full-screen program (vim, htop, ssh) is run with --profile.
  • Snap applications do not run through Tube, and gtube is for Linux only.
  • On macOS, programs that leave their network to a process that macOS starts (Safari and other WebKit programs, Mail, open) are not in the VPN. ICMP is not, so Tube refuses ping, traceroute and mtr there.
  • It does not hide the traffic from the VPN provider, as with any VPN.

Under the hood#

tube firefox opens a terminal UI with your OpenVPN profiles. Select one: Tube connects to it and starts Firefox so that all of Firefox’s network goes through that VPN. Before the VPN is connected, and after it has ended, the application has no network at all.

On Linux, Tube needs no root, no sudo, no system service and no installed openvpn. The application runs in a private user, network and mount namespace, and its only way out is a TUN device that Tube feeds from the VPN connection. Nothing of the machine’s network configuration changes.

On macOS, Tube has a helper that runs as root, which you install once. For each run the helper makes a utun device and puts rules into the firewall (pf) that send every TCP and UDP packet of the application, and only of it, into that device. Tube itself still never runs sudo.

gtube is a second program, for Linux: Tube with windows in place of the terminal UI. It puts entries such as Firefox (Tube) in the menu of your desktop.

Tube writes a log as JSON lines in its state folder. The log never has a key, a password or a line of a profile, and nothing is logged to the terminal.

Tube connects to OpenVPN servers with gopenvpn-conn. It is not OpenVPN’s own program and is not affiliated with OpenVPN Inc; OpenVPN is a trademark of OpenVPN Inc.

Kind
Tool
Language
Go
Runs on
Linux, macOS
License
GPL-2.0-only
Version
v0.12.5

Guides for Tube

The logo of Tube: a cat blows paper bullets through a tube

Start with one command

You need Go 1.27.3 or later, and an .ovpn file of your VPN provider. On Linux the kernel must let an ordinary user make user namespaces. Tube checks this when it starts, and says what is missing.

Run one application through a VPN with Tube Source on GitHub Documentation

# Install it
$ go install github.com/rm4n0s/tube/cmd/tube@latest
# On macOS, install the helper once
$ sudo tube --install-helper
# Run Firefox through a VPN
$ tube firefox
# On Linux, Tube with windows
$ go install github.com/rm4n0s/tube/cmd/gtube@latest
# Or let Soft install both, with their menu entries
$ soft install github.com/rm4n0s/tube