go-smart-proxy
CategorySoftware Packages
SubcategoryOther Software
Stars0
Local HTTP and SOCKS5 proxy that routes by network, destination rules and proxy chains, built for working behind NTLM proxies
About go-smart-proxy
This large README is shown as a plain-text preview. Read the full README at the source
# Go Smart Proxy
[](LICENSE)
[](https://github.com/apeironlab/go-smart-proxy/actions/workflows/ci.yml)
[](https://codecov.io/gh/apeironlab/go-smart-proxy)
[](https://pkg.go.dev/github.com/apeironlab/go-smart-proxy)
A local **HTTP/HTTPS and SOCKS5 proxy** with network-aware route selection, upstream
proxy chains, destination rules, and an optional **end-to-end encrypted relay**
that lets trusted contacts reach each other's networks without exposing services
to the internet.
The management UI is embedded in the binary and served on the proxy listener
(loopback only). The UI supports the 24 official languages of the European
Union, selected from the browser locale or manually from the header menu, with
English as fallback; code, comments and this README are in English.
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/images/proxy-connections-dark.png">
<img src="docs/images/proxy-connections-light.png" alt="Go Smart Proxy: live view of the connections, routes and traffic" width="880">
</picture>
</p>
> **Security first:** the configuration contains proxy credentials and can contain
> the relay private key. It is encrypted at rest with a master password
> (`config.yml.enc`). **The master password cannot be recovered.** Read
> [Security](#security) before using the relay.
---
## Screenshots
| | |
|---|---|
| <br>**Relay** — contacts, devices and route approvals | <br>**Protection** — ads, trackers and malware, plus your organization's rules |
| <br>**Rules** — pick the route by destination | <br>**Applications** — remote apps the relay offers you |
| <br>**Relay administration** — applications and gateways | <br>**Relay administration** — organization-wide blocking |
The interface follows the system theme (light or dark) and speaks the 24 EU languages.
---
## Table of contents
- [Screenshots](#screenshots)
- [Features](#features)
- [Architecture](#architecture)
- [Requirements](#requirements)
- [Quick start](#quick-start)
- [Configuration](#configuration)
- [Encrypted configuration and first run](#encrypted-configuration-and-first-run)
- [Master password and recovery key](#master-password-and-recovery-key)
- [Access token for the local interface (optional)](#access-token-for-the-local-interface-optional)
- [Configuration reference](#configuration-reference)
- [Routes and route selection](#routes-and-route-selection)
- [Proxy chains](#proxy-chains)
- [Destination rules](#destination-rules)
- [Hosts overrides](#hosts-overrides)
- [Using the proxy](#using-the-proxy)
- [Web UI and HTTP API](#web-ui-and-http-api)
- [Blocking ads, trackers and malicious sites](#blocking-ads-trackers-and-malicious-sites)
- [System integration](#system-integration)
- [Relay](#relay)
- [Relay client](#relay-client)
- [Devices](#devices)
- [Contacts and route approvals](#contacts-and-route-approvals)
- [Relay server](#relay-server)
- [Manual certificate provisioning](#manual-certificate-provisioning)
- [Enrollment over email](#enrollment-over-email)
- [Applications (remote access to protected apps)](#applications-remote-access-to-protected-apps)
- [Notifications and self-service revocation](#notifications-and-self-service-revocation)
- [Device certificates and automatic renewal](#device-certificates-and-automatic-renewal)
- [Health, metrics and logs](#health-metrics-and-logs)
- [Several relays (high availability)](#several-relays-high-availability)
- [Relay administration interface (optional)](#relay-administration-interface-optional)
- [Kubernetes deployment](#kubernetes-deployment)
- [Security](#security)
- [Environment variables](#environment-variables)
- [Development](#development)
- [Repository layout](#repository-layout)
- [Troubleshooting](#troubleshooting)
- [Limitations and roadmap](#limitations-and-roadmap)
- [Contributing](#contributing)
- [License](#license)
---
## Features
- **HTTP proxy** with absolute-form requests and HTTPS `CONNECT` tunnels.
- **SOCKS5 proxy** (no authentication, `CONNECT` only) sharing the same routing
configuration as the HTTP proxy.
- **Network-aware routes**: choose a route based on the current default gateway,
network interface, local network, or a PAC file.
- **Proxy chains**: HTTP, HTTPS (via `CONNECT`) and SOCKS5 hops, with NTLM/Basic
authentication support for HTTP proxies; PAC and dynamic rule-evaluation hops.
- **Destination rules** by domain, exact host, IP address, or CIDR block.
- **Rules-only routes and hops**: keep corporate/VPN/relay routes out of the
automatic selection and out of the manual route selectors.
- **Relay**: mTLS-authenticated rendezvous relay, contact address book, explicit
route approvals scoped per device, multiple devices per user (your own devices
are listed and usable without an invitation), and desktop notifications.
- **Several relays at once**, each with its own identity and address book, and
network context (a label and VPN flag) shared with contacts and usable in
routes and rules.
- **Sign-in methods for enrollment**: e-mail code, local passwords, LDAP, OpenID
Connect (public client with PKCE) and SAML, with a device confirmation code
against sign-in-link phishing.
- **Applications**: a relay can publish web apps and network services behind
gateways; users see their catalog and the proxy routes to it by itself.
- **Blocking** of ads, trackers and malware (hosts, domain and adblock lists),
with or without a relay; a relay can impose required rules.
- **Relay administration interface** (optional): overview, users, devices and
certificates, invitations, access rules, applications, blocking, audit log;
SQLite, PostgreSQL or MySQL/MariaDB.
- **Certificates per device, renewed automatically**; users are told by e-mail
of every new device and can revoke their own certificates.
- **Several relays behind a load balancer** sharing a PostgreSQL/MySQL database,
with health, Prometheus metrics and JSON logs.
- **Encrypted configuration** with a master password (PBKDF2 + AES-256-GCM),
changeable, with a recovery key; optional access token for the local interface.
On macOS the derived key can be stored in the Keychain and unlocked with
Touch ID; on Windows it is protected with DPAPI.
- **Complete web configuration**: listeners, SOCKS5, system integration, static
hosts, routes and route ordering, rules, credentials, relay settings and
certificates.
- **Internationalization**: the web UI (and the first-run setup page) support the
24 official languages of the European Union, selected from the browser locale or
manually from the header menu, with English as fallback.
- **System tray** with dynamic route selection and a web UI for configuration,
rules, credentials, connections, and relay management.
- **System integration**: system proxy configuration on every active interface
on macOS and Windows (untested there); desktop notifications on macOS, Linux
and Windows.
- **Transparent routing** (macOS): for VPN clients that forbid changing the
system proxy, the TCP traffic of the selected services or interfaces is
redirected to the proxy by the packet filter, on request and with a
privileged helper that lives only while it is needed.
- **PAC caching**: PAC files are fetched directly, cached, and never block
request handling.
- **Connection registry**: live connection log, byte counters, and fail-fast
recovery on network changes.
- **Single binary** with the web UI embedded (no external assets at runtime).
---
## Architecture

The proxy listens on one HTTP address (also serving the web UI and API on
loopback) and optionally on a SOCKS5 address. Every outgoing connection is first
checked against the blocking lists, then resolved through the route/rules engine;
the hosts of applications a relay publishes go to that relay by themselves. Several
relay servers can run behind a load balancer sharing one database (see *Several
relays*).
---
## Requirements
- **Go 1.24+**
- **Node.js 20+ / npm** to build the web UI (the built UI is embedded in the
binary)
- A C compiler/toolchain for the system tray:
- macOS: Xcode Command Line Tools
- Windows: Go toolchain (`build.bat` builds `proxy.exe`)
- Linux: the system tray library requires CGO plus GTK/AppIndicator
development packages; without them the tray part does not build
- For the relay server: no CGO is required (`make relay` builds with
`CGO_ENABLED=0`)
The project is primarily developed on macOS. Windows is supported for the core
proxy, SOCKS5, relay, encrypted configuration and tray. Linux supports the core
proxy, SOCKS5, relay, encrypted configuration, and tray when
the systray dependencies are installed. The macOS-only features are marked in
the relevant sections.
---
## Quick start
```bash
git clone https://github.com/apeironlab/go-smart-proxy.git
cd go-smart-proxy
# Build the web UI and the proxy binary
make build
# Start it: on first run it opens a browser setup page to choose the
# master password
./proxy
```
Then:
1. On first run, use the setup page that opens automatically at
`http://127.0.0.1:3128/?token=...` (the URL is also printed in the terminal).
Choose the master password. The proxy is created with:
- HTTP proxy + web UI: `127.0.0.1:3128`
- SOCKS5 proxy: `127.0.0.1:1080`
2. Click **Inizia a usare il proxy** in the welcome page.
3. Configure routes, rules, credentials, and relay from the web UI.
4. Point apps at the proxy:
```bash
# HTTP proxy
curl -x http://127.0.0.1:3128 https://example.com
# SOCKS5 (enabled by default on first run)
curl --socks5-hostname 127.0.0.1:1080 https://example.com
```
On macOS/Windows the same actions are available from the tray icon.
There is no configuration template to copy. On first start the proxy runs a
token-protected setup page on loopback: choose the master password there and the
proxy creates `config.yml.enc` with defaults (`127.0.0.1:3128` and SOCKS5
`127.0.0.1:1080`). If those ports are busy, the next free port is used and shown
on the page. From then on everything is managed from the web UI. For
headless/automatic first starts, set `PROXY_MASTER_PASSWORD` to skip the setup
page.
---
## Configuration
### Encrypted configuration and first run
The proxy stores its configuration in **`config.yml.enc`**, encrypted with a key
derived from a master password:
- KDF: **PBKDF2-HMAC-SHA256, 600,000 iterations**, random 16-byte salt
- Cipher: **AES-256-GCM**, random 12-byte nonce
- File format: `GSP1 | salt | nonce | ciphertext`
- File permissions: `0600` on Unix
At startup:
1. If `config.yml.enc` exists, the proxy unlocks it with the stored key.
Without a stored key it asks for the master password in the terminal, or
opens the **unlock page** on loopback when started from a desktop.
2. If only the legacy plaintext `config.yml` exists, the proxy:
- asks for a new master password (twice) in a terminal, or opens a
**migration page** in the browser,
- embeds the relay certificate, private key and CA into the configuration,
- writes and verifies `config.yml.enc`,
- removes the plaintext configuration and the plaintext relay private key.
3. If neither file exists, the proxy starts a **token-protected setup page** on
loopback (it opens the browser and prints the URL): choose the master
password there. It writes `config.yml.enc` with defaults
(`Address: 127.0.0.1:3128`, SOCKS5 `127.0.0.1:1080`). Set
`PROXY_MASTER_PASSWORD` to skip the setup page on headless machines.
4. After setup, a one-click welcome page confirms the working defaults; the
proxy is immediately usable.
5. Existing configurations are treated as already onboarded.
**Unlock sources**, in order:
1. The process already has the derived key (normal while running).
2. `PROXY_MASTER_PASSWORD` (useful for launchd/services/automation).
3. The system key store: Keychain on macOS (with Touch ID when available),
DPAPI on Windows.
4. An interactive master password prompt in a terminal, or the token-protected
unlock page in the browser when there is no terminal.
The browser setup page is used for a brand-new installation, the migration page
for a plaintext configuration, and the unlock page when the stored key is not
available; after that, the sources above unlock the existing configuration.
On macOS the **derived key** (not the password) is stored in the Keychain, under
the service `go-smart-proxy`, keyed by the configuration salt. The Keychain read
is gated by a `LocalAuthentication` Touch ID check when biometrics are
available. On Windows the derived key is stored in `config.key.dpapi` and
protected with `CryptProtectData` for the current user. Set
`PROXY_NO_KEYCHAIN=1` to disable both stores and always require the master
password.
> **Backups:** `config.yml.enc` is portable. On another machine the master
> password is enough; the Keychain/DPAPI entry is local. Keep an encrypted
> backup and the password in a password manager. **There is no password
> recovery.**
Saving from the web UI keeps the same salt and derived key, so the stored key
stays valid. The configuration is re-encrypted on every change.
**Data directory**: a portable run (archive extracted in a writable folder) keeps
`config.yml.enc`, `config.key.dpapi`, `relay_state.json` and `cache/` next to the
binary. When the binary is installed — a macOS app bundle, the Windows installer
(marked by `installed.marker` next to `proxy.exe`) or a Linux package — the
proxy uses the user configuration directory instead:
`~/Library/Application Support/go-smart-proxy` on macOS, `%AppData%\go-smart-proxy`
on Windows, `~/.config/go-smart-proxy` on Linux. On the first launch after an
upgrade, an existing configuration found in the old working directory is moved
to the new one. Set `PROXY_HOME` to force a specific directory.
### Master password and recovery key
The configuration (credentials, relay keys) is encrypted with a key derived from
the master password. **Configuration → Security** changes it: it asks for the
current password, re-encrypts the file under a new salt and key at once, and
replaces the key kept in the system keychain. Attempts are limited to five a
minute.
A **recovery key** is for the day the password is forgotten. It is a private key
made once and shown once (`GSPR-XXXX-XXXX-...`, with a checksum so a typing
mistake is noticed): keep it apart from the computer. The proxy keeps, in
`config.recovery`, the configuration key sealed to the matching public key.
Because sealing needs only the public key, the file is brought up to date after
every password change without the recovery key being at hand, and a crash
between the two writes is repaired at the next start. To use it, type the
recovery key where the master password is asked (terminal, unlock page or
`PROXY_MASTER_PASSWORD`); the proxy opens and then asks you to choose a new
password, without needing the old one. Making a new key invalidates the old
one; removing it deletes the file. Without the recovery key, `config.recovery`
reveals nothing.
### Access token for the local interface (optional)
The web interface and its API answer to anything that can reach `127.0.0.1`,
which on a computer with several users, or with untrusted programs, is more than
the owner. **Configuration → Security → Access token** (or a relay, see below)
turns on a token: every `/api/` call then needs it, as `Authorization: Bearer
<token>` or as the session cookie (`HttpOnly`, `SameSite=Strict`) that signing
in sets. The page that loads the interface is served without it, to show the
sign-in form. The proxy itself (the HTTP and SOCKS5 ports used by your programs)
is not affected.
The token is random (256 bits), kept in `api.token` next to the configuration,
readable by your user only. The tray's *Open management page* and the setup
pages open the interface at `http://127.0.0.1:3128/#token=...`: what follows `#`
is never sent anywhere, the page signs in with it and removes it from the
address bar. Wrong tokens are limited to ten a minute; sessions end after two
idle hours or twelve in all; *Make a new token* signs everybody else out.
**A relay can require it.** In the relay's **Blocking** page (or `require_local_auth: true` in the policy
file), *Require an access token for the proxy's local interface* applies to every
proxy connected to it. The user then cannot switch it off (the switch says so),
and it relaxes when the relay stops requiring it, back to the user's own choice.
### Configuration reference
The following is the *plaintext* schema. The encrypted file contains the same
YAML, plus embedded relay material.
```yaml
Address: 127.0.0.1:3128 # HTTP proxy + web UI/API listener
SocksAddress: 127.0.0.1:1080 # optional SOCKS5 listener; empty = disabled
Credentials:
- Name: corp
User: 'DOMAIN\alice'
Password: 'secret'
Routes:
- Name: office
Gateway: '' # optional: default gateway IP
IFace: utun4 # optional: default interface name (globs allowed: utun*)
Net: 10.0.0.0/8 # optional: local network/address
IFaceUp: tun* # optional: apply while a matching interface is in use
VPN: up # optional: up = only with a VPN, down = only without
RulesOnly: false # never selected or forced manually
Chain: # ordered upstream hops
- ProxyUrl: http://proxy.corp:8080
Credential: corp
RulesOnly: false # barrier for automatic/forced traffic
- ProxyUrl: socks5://other:1080
Credential: ''
# A PAC route is a single-hop chain:
# Chain:
# - PacUrl: http://config.corp/proxy.pac
# Credential: corp
# A dynamic hop must be the last one: at connection time it evaluates the
# destination rules and applies the selected route (or goes direct).
# Chain:
# - ProxyUrl: http://proxy.corp:8080
# - Dynamic: true
Rules:
- Name: intranet
Domains: [corp.local] # domain and all subdomains
Hosts: [intranet.corp.local]
Networks: [10.0.0.0/8, 192.168.1.5]
Route: office
Relays: # one entry per relay server; you can connect to several
- Name: office # a short name; hops use ?relay=office
Address: 'relay.example.com:8443'
# Manual certificate files (legacy) ...
Cert: relay/client.pem
Key: relay/client-key.pem
CA: relay/ca.pem
# ... or embedded PEMs (filled by the web UI enrollment)
# CertPEM: |
# -----BEGIN CERTIFICATE-----
# KeyPEM: |
# -----BEGIN PRIVATE KEY-----
# CAPEM: |
# -----BEGIN CERTIFICATE-----
Route: '' # optional route used to reach the relay
Device: quiet-otter-7f3a # auto-generated per installation
EnrollURL: https://proxy.intra.example.com
AllowLocal: false # let contacts reach services on this machine
NetworkLabel: elsewhere # default label shared with contacts (optional)Frequently Asked Questions
What is go-smart-proxy?
go-smart-proxy is a Software Packages library for the Go programming language. Local HTTP and SOCKS5 proxy that routes by network, destination rules and proxy chains, built for working behind NTLM proxies
How do I install go-smart-proxy?
Install go-smart-proxy with the Go module system using `go get apeironlab/go-smart-proxy`. Check the repository for the current installation instructions.
What category does go-smart-proxy belong to?
go-smart-proxy is listed under Software Packages, specifically Other Software.