返回资讯中心
外部精选
软件工程
#开发者实时流

The VPN Manager I want to build: let different apps use their own VPNs

I want to develop VPN Manager: plan independent VPN Instances for different apps and services, native Linux isolation, fail-closed behavior, Provider bootstrapping and traffic monitoring.

Hacker News 最新dennysora-main2026/11/1 · 16 天前30 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

I want to develop VPN Manager: plan independent VPN Instances for different apps and services, native Linux isolation, fail-closed behavior, Provider bootstrapping and traffic monitoring.

Published November 1, 2026·About 21 min read·Reviewed translation

Copy link

On this pageWhat I first wanted to build

Current operating interface

01The backbone of the system

Complete component ownership

02VPN Instance architecture

The difference between managed Apps, Gateway, and Port Forward

App isolation on macOS is more troublesome

03Linux: making sure there is “no way back” at the OS layer

04Instance startup and fault-recovery flow

Connection state cannot be only Connected/Disconnected

Startup, fail-closed behavior, and automatic recovery: START/ACTIVATE sequence diagram

05How is the first Provider created? This is a bootstrap problem

What should the Provider Adapter be responsible for?

PROVIDER first-bootstrap sequence diagram

06I want to see every VPN's traffic and resource use clearly

VPN MANAGER / Development notes

The host's original network stays unchanged. Designated apps use only their designated exits.

I first wanted to build VPN Manager because most ordinary VPN clients seem geared toward switching the whole computer together. But that is not what I need. I want to specify which apps use which VPN, while unmanaged programs keep using the host's original network.

For example, I may have a browser, a downloader and other apps open at the same time. The browser goes to Instance A, the downloader goes to Instance B, and the others use the original network. A and B each have their own WireGuard identity, DNS, Gateway, connection resources and lifecycle.

If A disconnects, I would rather the browser lose its network connection outright. It must not automatically move to B, much less fall back to the ISP's original exit.

If A disconnects: The browser has no network. Instance B and unmanaged programs keep working normally, without having to switch along with it.

I also want to manage accounts, Profiles and Gateways from different VPN providers in the same system. Ideally, designated apps or services should be isolated directly at the OS network layer, without Docker or changing the whole computer's default route.

Traffic information is another feature I want to build. I want to see how much traffic each Instance uses, which Gateways are congested, how long DNS takes and which process consumes the most CPU or memory. A single Connected indicator does not mean much to me.

People have already built similar things, and many assemble their own environments using netns, proxies and firewalls. But I want to bring multi-VPN management, app isolation, failure recovery and monitoring together, without having to wire a pile of things together each time.

Start with the overall system architecture.

Figure 1 | The whole VPN Manager system: control, data, persistence and observation

Web resource service

Serves React static assets / same origin

React user interface

Core operations / providers / performance panel

Static assets

HTTP/SSE

VPN provider manager

Mullvad / AIRVPN adapters

Each provider's IP egress checks

Candidate profiles and status

VPN controller VPN Core/Web API

VPN platform control coordinator

Profile validation / Store helper

Only coordinates operation intent

Security policy manager

DNS profile validation

Firewall policies / automatic blocking

IP blocklist policy

Profiles Policies

Performance manager

Analysis / benchmark sessions

Comparisons / performance reports

Instance manager

Sole lifecycle ownership / outer monitoring

Generations, resource leases and automatic recovery

Platform manager

Linux / macOS system adapters

OS privileges / sandbox / resource control

Typed lifecycle intent

Explicitly authorized performance tests

Test leases

OS requests

Metrics service Metrics collector

Metrics compression module

VPN Instance A … N

Each owns complete internal services

Independent GotaTun / DNS / Gateway

App traffic bypasses Controller

Store helper

Shared type-safe persistence client

Configure / start / activate / stop

File descriptors (FDs)

Monitoring metrics

Bounded data queries

Persisted metrics and reports always go through Store helper

Store storage service

Sole SQLite accessor / internal modules

SQLite

Control database + metrics database

Managed app Gateway client

VPN peer

Encrypted WireGuard UDP

Blue: control Green: data Yellow: OS resources Purple: observation

All persistence goes through Store helper; secrets use a separate private delivery channel.

Figure 1Complete VPN Manager system architectureControl plane, data plane, observation and persistence are separate.(scroll horizontally to inspect the full diagram)

The overall control path is initially planned as follows:

React UI→ VPN Web API / VPN Core→ Instance Manager→ Instance Controller

Here I make Instance Manager a separate process. It handles starting, stopping, generation, resource leases and recovery for all Instances. Controller only receives operation intent from the UI/API; it does not forward apps' TCP/UDP data.

Anything that needs OS privileges goes to Platform Manager. It handles network namespaces, process sandboxes, FDs, firewall policies and macOS capture/deny. I do not want other components changing system network settings directly just because it is convenient.

Store persists state, Metrics collects data, and Performance Manager handles analysis and authorized tests. These things should not sit in the app packet path. For example, slower Metrics or database writes must not queue packets already being transmitted; new state changes still follow the original fail-closed rules.

I first classify components by who manages them and who has authority to operate them. Drawing a pile of boxes alone is not useful. What matters is who is affected when a process dies, and who can restart it.

Component ownership | Grouped by execution boundary and privilege responsibility

React user interface (UI - React)

· Core UI

· Performance Panel

· Provider management panel

VPN Controller · VPN Core · VPN Web API

· VPN platform control coordinator

· VPN profile validator

· Store helper (storage adapter)

Platform Manager

· Linux system adapter

· Process manager · Process sandbox

· Network resource control

· macOS system adapter

· Process manager · Process sandbox

· Network resource control

Provider manager (VPN Provide Manager)

· Mullvad provider adapter

· Mullvad IP egress checker

· AIRVPN provider adapter

· AIRVPN IP egress checker

Security Manager

· DNS profile validator

· Firewall profile

· Automatic block detector

Metrics Service

· Metrics collector

· Metrics compression module

Performance Manager

Storage service (Store)

· Configuration data helper

· Secret data helper

· Security policy helper

· DNS profile helper

· Provider data helper

· Mullvad data helper

· AIRVPN data helper

· Metrics storage helper

Instance Manager

· Outer Instance watchdog

· VPN Instance (single Profile)

· Instance controller

· Instance DNS controller

· Instance port controller

· Port forwarding

· Instance metrics

· Inner Instance watchdog

· Gateway manager

· Gateway service

· Gateway metrics

· GotaTun

Web static resource service

Execution locations are determined by component ownership, privileges, and fault-isolation boundaries.

Component ownership diagramAll components and their responsibility ownershipGrouped by parent/owner, showing the components inside the UI, Controller, Platform, Store, and each Instance.(scroll horizontally to inspect the full diagram)

02VPN Instance architecture

The complete internals and data path of a single Instance

Each Instance contains its own Controller, DNS, Port, Gateway, Metrics, Watchdog, and GotaTun. The inner Watchdog can block traffic, but cannot rebuild or unblock on its own.

Figure 2|A single VPN Instance: independent services and data paths

Instance manager

Commands/execution generation/resource leases

VPN Instance|Independent Rust Worker

Instance Controller

Controls only this Instance

Gateway Manager Gateway Service × N Gateway Metrics

Instance DNS Controller

Independent cache/connection pool/resolver

DNS only through the VPN tunnel

Instance Port Controller

Port forwarding(Port forward)

Only Apps in the same Instance are allowed

Designated managed App

Proxy client/ Protected process

Port forwarding goes only to Apps in the same Instance

TCP/IP handling+GotaTun

Linux kernel/macOS Rust protocol stack

Independent WireGuard device and keys

Instance Metrics

Local counters/latency distributions

Instance Watchdog

Tunnel/DNS/platform policy health

VPN peer

Peer-restricted encrypted WireGuard UDP

Platform manager

Process sandbox/TUN/

Restricted UDP FD

Metrics service

Bounded snapshot transfer

Apps cannot obtain the host Underlay, secrets, Store, or namespace descriptors.

Figure 2The services and data paths of a single VPN InstanceEach Instance owns its own runtime, controller, Gateway, DNS, Metrics, and Watchdog.(scroll horizontally to inspect the full diagram)

Each Instance has its own GotaTun, DNS Controller, Port Controller, Gateway Manager, Metrics, and Watchdog. WireGuard identity, DNS cache, sockets, buffers, and queues also need to be separate. CPU, NIC, and OS can be shared, but A's execution state should not be mixed with B's.

There is one point I want to make clear first.

GotaTun is a WireGuard engine, not a complete TCP/IP socket stack in itself. So connecting GotaTun does not mean that all TCP/UDP connection handling is already there. That part still needs to be handled separately.

On Linux, I lean toward directly using the kernel TCP/IP stack inside an isolated network namespace. For an explicit Proxy on macOS, each Instance uses its own smoltcp along with GotaTun. Their sockets, buffers, and queues also need to be independent. Controller SQL or Provider HTTP calls must not hold up actual network traffic.

DNS also needs to follow its Instance. If resolution fails, report failure. Do not quietly switch to asking the host resolver. After receiving HTTP CONNECT or SOCKS5 TCP/UDP, the Gateway must actually hand it to its own Instance to establish the destination connection. Port Forward can only forward to a verified App endpoint within the same Instance. It must not take the shortcut of connecting directly to the host's 127.0.0.1.

I divide traffic entry points into three types.

Managed app must first enter an isolated environment and cannot choose the host network on its own.

Gateway only handles traffic explicitly handed to the HTTP/SOCKS Proxy. Connections the App establishes separately are not automatically protected.

Port Forward is traffic arriving from the VPN. It can only be delivered to an App within the same Instance that has a valid AppEndpointLease .

DNS and IPv6 cannot be exceptions either. If the Instance's DNS path is unavailable, do not query. If IPv6 has no verifiable tunnel path, it must not automatically be allowed onto the host network either.

The macOS side is actually more troublesome. An explicit Proxy is possible, but it only handles traffic actually

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →