PlanB: a HTTP and websocket proxy backed by Redis and inspired by Hipache.

PlanB: a distributed HTTP and websocket proxy

Linter Tests Coverage Status

What Is It?

PlanB is a HTTP and websocket proxy backed by Redis and inspired by Hipache.

It aims to be fully compatible with Hipache when Redis is used as a backend. The same format is used for all keys stored in Redis so migrating from Hipache to PlanB should be completely seamless. The process should be as simple as replacing Hipache's executable for PlanB.

Scripts

  • make start: Build and run the planb binary
  • make build-docker : Build the latest docker image with image name: planb and tag: latest
  • make clean : Remove planb binary
  • make release : Create the docker image and push to vm-provider project with the latest tag of the git release for prod
  • make release-dev : Create the docker image and push to vm-provider-dev project with the latest tag of the git release for dev
  • make test : Runs the tests and updates the coverage report

Start-up flags

The following flags are available for configuring PlanB on start-up:

  • --listen value, -l value: Address to listen (default: "0.0.0.0:8989")
  • --tls-listen value: Address to listen with tls
  • --tls-preset value: Preset containing supported TLS versions and cyphers, according to https://wiki.mozilla.org/Security/Server_Side_TLS. Possible values are [modern, intermediate, old] (default: "modern")
  • --metrics-address value: Address to expose prometheus /metrics
  • --load-certificates-from value: Path where certificate will found. If value equals 'redis' certificate will be loaded from redis service. (default: "redis")
  • --read-redis-network value: Redis address network, possible values are "tcp" for tcp connection and "unix" for connecting using unix sockets (default: "tcp")
  • --read-redis-host value: Redis host address for tcp connections or socket path for unix sockets (default: "127.0.0.1")
  • --read-redis-port value: Redis port (default: 6379)
  • --read-redis-sentinel-addrs value: Comma separated list of redis sentinel addresses
  • --read-redis-sentinel-name value: Redis sentinel name
  • --read-redis-password value: Redis password
  • --read-redis-db value: Redis database number (default: 0)
  • --write-redis-network value: Redis address network, possible values are "tcp" for tcp connection and "unix" for connecting using unix sockets (default: "tcp")
  • --write-redis-host value: Redis host address for tcp connections or socket path for unix sockets (default: "127.0.0.1")
  • --write-redis-port value: Redis port (default: 6379)
  • --write-redis-sentinel-addrs value: Comma separated list of redis sentinel addresses
  • --write-redis-sentinel-name value: Redis sentinel name
  • --write-redis-password value: Redis password
  • --write-redis-db value: Redis database number (default: 0)
  • --access-log value: File path where access log will be written. If value equals 'syslog' log will be sent to local syslog. The value 'none' can be used to disable access logs. (default: "./access.log")
  • --request-timeout value: Total backend request timeout in seconds (default: 30)
  • --dial-timeout value: Dial backend request timeout in seconds (default: 10)
  • --client-read-timeout value: Maximum duration for reading the entire request, including the body (default: 0s)
  • --client-read-header-timeout value: Amount of time allowed to read request headers (default: 0s)
  • --client-write-timeout value: Maximum duration before timing out writes of the response (default: 0s)
  • --client-idle-timeout value: Maximum amount of time to wait for the next request when keep-alives are enabled (default: 0s)
  • --dead-backend-time value: Time in seconds a backend will remain disabled after a network failure (default: 30)
  • --flush-interval value: Time in milliseconds to flush the proxied request (default: 10)
  • --request-id-header value: Header to enable message tracking
  • --active-healthcheck: Enable active healthcheck on dead backends once they are marked as dead. Enabling this flag will result in dead backends only being enabled again once the active healthcheck routine is able to reach them.
  • --engine value: Reverse proxy engine, options is 'native'
  • --backend-cache: Enable caching backend results for 2 seconds. This may cause temporary inconsistencies.
  • --help, -h: show help
  • --version, -v: print the version

The --read-redis-* flags refer to the Redis server used for read-only operations (reading the backends for each frontend).

The --write-redis-* flags refer to the Redis server used for write operations (marking and publishing dead backends).

Separating the read and write servers is not mandatory but is useful for improving performance. A common scenario is having a slave Redis server on localhost configured as --read-redis and a remote Redis master configured as --write-redis.

Features

  • Load-Balancing
  • Dead Backend Detection
  • Dynamic Configuration
  • WebSocket
  • TLS

VHOST Configuration

The configuration is managed by Redis that makes possible to update the configuration dynamically and gracefully while the server is running, and have that state shared across workers and even across instances.

Let's take an example to proxify requests to 2 backends for the hostname www.tsuru.io. The 2 backends IP are 192.168.0.42 and 192.168.0.43 and they serve the HTTP traffic on the port 80.

redis-cli is the standard client tool to talk to Redis from the terminal.

Follow these steps:

Create the frontend:

$ redis-cli rpush frontend:www.tsuru.io mywebsite
(integer) 1

The frontend identifer is mywebsite, it could be anything.

Add the 2 backends:

$ redis-cli rpush frontend:www.tsuru.io http://192.168.0.42:80
(integer) 2
$ redis-cli rpush frontend:www.tsuru.io http://192.168.0.43:80
(integer) 3

Review the configuration:

$ redis-cli lrange frontend:www.tsuru.io 0 -1
1) "mywebsite"
2) "http://192.168.0.42:80"
3) "http://192.168.0.43:80"

TLS Configuration using redis (optional)

$ redis-cli -x hmset tls:www.tsuru.io certificate < server.crt
$ redis-cli -x hmset tls:www.tsuru.io key < server.key

$ redis-cli -x hmset tls:*.tsuru.com certificate < wildcard.crt
$ redis-cli -x hmset tls:*.tsuru.io key < wildcard.key

TLS Configuration using FS (optional)

create directory following this structure

cd certficates
ls
*.domain-wildcard.com.key
*.domain-wildcard.com.crt
absolute-domain.key
absolute-domain.crt

While the server is running, any of these steps can be re-run without messing up with the traffic.

Debbugging and Troubleshooting

One way to debug/toubleshoot planb is by analyzing the running goroutines.

Planb is able to handle the USR1 signal to dump goroutines in its execution screen:

$ kill -s USR1 
   

   
Owner
vinay badhan
Interested in implementation of technologies in real life. Also love to contribute to open source projects.
vinay badhan
Similar Resources

NotifyTool - A message forwarding service for http to websocket

notifyTool this is a message forwarding service for http to websocket task webso

Jan 3, 2022

HTTP tunnel over Websocket

HTTP tunnel over Websocket

WS PROXY This is a reverse HTTP proxy over websockets. The aim is to securely make call to internal APIs from outside. How does it works a WSP client

Nov 12, 2022

TCP over HTTP/WebSocket

Introduction toh is tcp over http. short words: proxy your network over websocket Table of contents ToH server Caddy or Nginx wrap ToH server with TLS

May 6, 2023

DHCP backed by Tink server

dhcp DHCP is a dhcp server backed by Tink server. All IP addresses are served as DHCP reservations. There are no leases. Definitions DHCP Reservation:

Mar 23, 2022

Easy proxy for redis sentinel

sentinel-proxy Easy proxy for redis sentinel. Main purpose of the proxy is easy work with redis sentinel without changing the client code. Especially

Sep 6, 2022

A Redis proxy built on TiKV for golang

redis-proxy A Redis proxy built on TiKV How to use Build the proxy: go build -o

Dec 24, 2021

An experimental Tor-Proxy serivce written in Go using Go-proxy and Go-libtor.

tor-proxy An experimental standalone tor-proxy service built with Go, using go-proxy, go-libtor and bine. This is a simple replacement to Tor's origin

Nov 9, 2022

IP2Proxy Go package allows users to query an IP address to determine if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.

IP2Proxy Go Package This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data

Sep 15, 2022

Battlesnake-logging-proxy - A little proxy between the internet and your battlesnake

battlesnake-logging-proxy a little proxy between the internet and your battlesna

Feb 11, 2022
Related tags
Um chat feito em go utilizando gorilla/websocket, go-redis/redis,golang-jwt/jwte labstack/echo.

go-chat Um chat feito em go utilizando gorilla/websocket, go-redis/redis,golang-jwt/jwte labstack/echo. Why Eu gostaria de aprender algumas ferramenta

Jul 14, 2022
Http-logging-proxy - A HTTP Logging Proxy For Golang

http-logging-proxy HTTP Logging Proxy Description This project builds a simple r

Aug 1, 2022
HTTP, HTTP2, HTTPS, Websocket debugging proxy
HTTP, HTTP2, HTTPS, Websocket debugging proxy

English | 简体中文 We recommend updating whistle and Node to ensure that you receive important features, bugfixes and performance improvements. Some versi

Dec 31, 2022
Pubsub-go - Go-redis pubsub with websocket

go-redis pubsub with websocket # start a local dev server $ make dev

Jan 28, 2022
A simple tool to convert socket5 proxy protocol to http proxy protocol

Socket5 to HTTP 这是一个超简单的 Socket5 代理转换成 HTTP 代理的小工具。 如何安装? Golang 用户 # Required Go 1.17+ go install github.com/mritd/s2h@master Docker 用户 docker pull m

Jan 2, 2023
websocket proxy,简单的websocket反向代理实现,支持ws、wss
websocket proxy,简单的websocket反向代理实现,支持ws、wss

websocket proxy 100行代码实现轻量的websocket代理库,不依赖其他三方库,支持ws、wss代理 使用示例 Install go get github.com/pretty66/websocketproxy import ( "github.com/pretty66/w

Dec 27, 2022
Websocket proxy component
Websocket proxy component

Proxy server component Task description Task description is in DESCRIPTION.md Issues found in task description and fixed signal.Notify wasn't cathing

Dec 1, 2022
SFTP backed by LDAP and S3-compatible object stores

RainSFTP RainSFTP is an implementaion of the Secure File Transfer Protocol backed by LDAP for authentication and an S3-compatible object store. This m

Nov 8, 2022
Go-http-sleep: Delayed response http server, useful for testing various timeout issue for application running behind proxy

delayed response http server, useful for testing various timeout issue for application running behind proxy

Jan 22, 2022
开箱即用的基于命令的消息处理框架,让 websocket 和 tcp 开发就像 http 那样简单

Cmd Srv 开箱即用的基于命令的消息处理框架,让 websocket 和 tcp 开发就像 http 那样简单

Sep 25, 2022