Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

ghostunnel

> 安全
Open source

A simple TLS proxy with mutual authentication for securing non-TLS services.

2.2K stars0 likes0 views
WebsiteGitHub

About

A simple TLS proxy with mutual authentication for securing non-TLS services.

Ghostunnel

Ghostunnel is a simple TLS proxy with mutual authentication support for securing non-TLS backend applications.

Ghostunnel supports two modes, client mode and server mode. Ghostunnel in server mode runs in front of a backend server and accepts TLS-secured connections, which are then proxied to the (insecure) backend. A backend can be a TCP host/port or a UNIX domain socket. Ghostunnel in client mode accepts (insecure) connections through a TCP or UNIX domain socket and proxies them to a TLS-secured service.

Supported platforms: Ghostunnel is developed & tested on Linux, macOS, and Windows but also runs on most other UNIX systems that are supported by Go such as FreeBSD, OpenBSD, and NetBSD.

Key Features

Authentication & Authorization: Enforces mutual TLS authentication by requiring valid client certificates. Supports fine-grained access control checks on certificate fields (CN, OU, DNS/URI SAN), and declarative authorization policies via Open Policy Agent (OPA).

Certificate Hotswapping: Reload certificates without restarting via SIGHUP/SIGUSR1 or timed reload intervals, enabling use of short-lived certificates.

Flexible Certificate Sources: Load certificates and keys from PEM/PKCS#12 files, ACME (Let's Encrypt), hardware security modules (PKCS#11), macOS Keychain, Windows Certificate Store, or the SPIFFE Workload API.

Secure by Default: Listeners and targets are restricted to localhost and UNIX sockets unless explicitly overridden with --unsafe-listen or --unsafe-target, preventing accidental exposure. On Linux, Landlock sandboxing is enabled by default to limit process privileges.

Metrics & Profiling: Built-in status port with JSON and Prometheus metrics endpoints, plus optional pprof profiling.

Ghostunnel also supports UNIX domain sockets, PROXY protocol v2, systemd/launchd socket activation, Windows service management (SCM), and more.

Getting Started

To get started and play around with Ghostunnel you will need X.509 client and server certificates. If you already maintain a PKI, you can use your existing certificates. Otherwise, you can use tools like mkcert or cloudflare/cfssl to build one.

For quick testing and development, you can also generate throwaway test certificates using the built-in generator:

# Generate test certificates and keys
go tool mage test:keys

This will create a test-keys directory with all the necessary certificates and keys for testing. Note: These are test certificates only and should NOT be used in production.

Install

Ghostunnel is available through GitHub releases and through Docker Hub.

Please note that the official release binaries are best-effort, and are usually built directly via GitHub Actions on the latest available images. If you need compatibility for specific OS versions we recommend building yourself.

Ghostunnel uses the mage build system, a make/rake-like build tool using Go. Mage is available as a Go tool dependency (no separate install needed). You can build Ghostunnel with the commands shown below.

# Compile binary
go tool mage go:build

# Build containers
go tool mage docker:build

You can also run go tool mage -l to view all build targets and add -v to mage commands to get more verbose output.

Develop

Ghostunnel has an extensive suite of integration tests. Our integration test suite requires Python 3.

To run tests:

# Option 1: run unit & integration tests locally
go tool mage test:all

# Option 2: run unit & integration tests in a Docker container
# This also runs PKCS#11 integration tests using SoftHSM in the container
go tool mage test:docker

# Open coverage information in browser
go tool cover -html coverage/all.profile

For more information on how to contribute, please see the CONTRIBUTING file.

Usage

To see available commands and flags, run ghostunnel --help. You can get more information about a command by adding --help to the command, like ghostunnel server --help or ghostunnel client --help. Man pages are also available for Linux and macOS.

By default, Ghostunnel runs in the foreground and logs to stdout. You can set --syslog to log to syslog instead of stdout. If you want to run Ghostunnel in the background, we recommend using a service manager.

Certificates

Ghostunnel accepts certificates in multiple different file formats.

The --keystore flag can take a PKCS#12 keystore or a combined PEM file with the certificate chain and private key as input (format is auto-detected). JCEKS/JKS keystores are also supported for legacy use cases. The --cert / --key flags can be used to load a certificate chain and key from separate PEM files (instead of a combined one).

Ghostunnel also supports loading identities from the macOS keychain or the SPIFFE Workload API and having private keys backed by PKCS#11 modules, see the "Advanced Features" section below for more information.

Server mode

This is an example for how to launch Ghostunnel in server mode, listening for incoming TLS connections on localhost:8443 and forwarding them to localhost:8080. Note that while we use TCP sockets on localhost in this example, both the listen and target flags can also accept paths to UNIX domain sockets as their argument.

To set allowed clients, you must specify at least one of --allow-all, --allow-cn, --allow-ou, --allow-dns, --allow-uri, or --allow-policy. All checks are made against the certificate of the client. Multiple flags are treated as a logical disjunction (OR), meaning clients can connect as long as any of the flags matches. Alternatively, --allow-spki-pin authenticates clients by out-of-band SPKI key pinning. See ACCESS-FLAGS for more information. In this example, we assume that the CN of the client cert we want to accept connections from is client.

Note: Before running the examples below, make sure you have generated the test certificates by running go tool mage test:keys (see the Getting Started section above).

Start a backend server:

nc -l localhost 8080

Start a Ghostunnel in server mode to proxy connections:

bash
ghostunnel server \
    --listen localhost:8443 \
    --target localhost:8080 \
    --keystore test-keys/server-keystore.p12 \
    --cacert test-keys/cacert.pem \
    --allow-cn client

Verify that clients can connect with their client certificate:

bash
openssl s_client \
    -connect localhost:8443 \
    -cert test-keys/client-combined.pem \
    -key test-keys/client-combined.pem \
    -CAfile test-keys/cacert.pem

Now we have a TLS proxy running for our backend service. We terminate TLS in Ghostunnel and forward the connections to the insecure backend.

Client mode

This is an example for how to launch Ghostunnel in client mode, listening on localhost:8080 and proxying requests to a TLS server on localhost:8443.

By default, Ghostunnel in client mode verifies targets based on the hostname. Various access control flags exist to perform additional verification on top of the regular hostname verification. See ACCESS-FLAGS for more information.

Start a backend TLS server:

bash
openssl s_server \
    -accept 8443 \
    -cert test-keys/server-combined.pem \
    -key test-keys/server-combined.pem \
    -CAfile test-keys/cacert.pem

Start a Ghostunnel with a client certificate to forward connections:

bash
ghostunnel client \
    --listen localhost:8080 \
    --target localhost:8443 \
    --keystore test-keys/client-combined.pem \
    --cacert test-keys/cacert.pem

Verify that we can connect to 8080:

nc -v localhost 8080

Now we have a TLS proxy running for our client. We take insecure local connections, wrap them in TLS, and forward them to the secure backend.

Full tunnel (client plus server)

We can combine the above two examples to get a full tunnel. Note that you can start the tunnels in either order.

Start netcat on port 8001:

nc -l localhost 8001

Start the Ghostunnel server:

bash
ghostunnel server \
    --listen localhost:8002 \
    --target localhost:8001 \
    --keystore test-keys/server-combined.pem \
    --cacert test-keys/cacert.pem \
    --allow-cn client

Start the Ghostunnel client:

bash
ghostunnel client \
    --listen localhost:8003 \
    --target localhost:8002 \
    --keystore test-keys/client-keystore.p12 \
    --cacert test-keys/cacert.pem

Verify that we can connect to 8003:

nc -v localhost 8003

Now we have a full tunnel running. We take insecure client connections, forward them to the server side of the tunnel via TLS, and finally terminate and proxy the connection to the insecure backend.

Docker Images

Docker images are published to Docker Hub on each release. Three variants are available:

Image Tag
Alpine ghostunnel/ghostunnel:latest-alpine, ghostunnel/ghostunnel:v1.x.x-alpine
Debian ghostunnel/ghostunnel:latest-debian, ghostunnel/ghostunnel:v1.x.x-debian
Distroless ghostunnel/ghostunnel:latest-distroless, ghostunnel/ghostunnel:v1.x.x-distroless

The latest tags always point to the most recent release. The bare ghostunnel/ghostunnel:latest and ghostunnel/ghostunnel:v1.x.x tags are aliases for the Alpine variant.

See DOCKER for details.

Advanced Features

Access Control Flags

Ghostunnel supports different types of access control flags in both client and server modes to enforce authorization checks. Ghostunnel can check various attributes of peer certificates directly, including a SPIFFE ID from a peer using a SPIFFE X.509 SVIDs. In addition to this, Ghostunnel also supports implementing authorization checks via Open Policy Agent (OPA) policies for maximum flexibility. Policies can be reloaded at runtime much like certificates.

See ACCESS-FLAGS for details.

Logging Options

You can silence specific types of log messages using the --quiet=... flag, such as --quiet=conns or --quiet=handshake-errs. You can pass this flag repeatedly if you want to silence multiple different kinds of log messages.

Supported values are:

  • all: silences all log messages
  • conns: silences log messages about new and closed connections.
  • conn-errs: silences log messages about connection errors encountered (post handshake).
  • handshake-errs: silences log messages about failed handshakes.

In particular we recommend setting --quiet=handshake-errs if you are running TCP health checks in Kubernetes on the listening port, and you want to avoid seeing error messages from aborted connections on each health check.

Certificate Hotswapping

To trigger a reload, simply send SIGHUP (or SIGUSR1) to the process or set a time-based reloading interval with the --timed-reload flag. This will cause Ghostunnel to reload the certificate, private key, and CA bundle from the

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gocryptogohsmkeychain

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category安全
PricingOpen source

> Related tools

O
OWASP ZAP
开源 Web 应用安全扫描器
O
owasp-wstg-tracker
Simple web app to track OWASP WSTG security testing progress
H
homebridge-mi-gateway-security
XiaoMi Gateway Security plugin for HomeBridge.