All Projects → pires → Go Proxyproto

pires / Go Proxyproto

Licence: apache-2.0
A Go library implementation of the PROXY protocol, versions 1 and 2.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Go Proxyproto

Fullstack
Full-stack DevOps demo
Stars: ✭ 19 (-87.42%)
Mutual labels:  haproxy
Voyager
🚀 Secure HAProxy Ingress Controller for Kubernetes
Stars: ✭ 1,276 (+745.03%)
Mutual labels:  haproxy
Haproxy Configs
80+ HAProxy Configs for Hadoop, Big Data, NoSQL, Docker, Elasticsearch, SolrCloud, HBase, MySQL, PostgreSQL, Apache Drill, Hive, Presto, Impala, Hue, ZooKeeper, SSH, RabbitMQ, Redis, Riak, Cloudera, OpenTSDB, InfluxDB, Prometheus, Kibana, Graphite, Rancher etc.
Stars: ✭ 106 (-29.8%)
Mutual labels:  haproxy
Lethean Vpn
Lethean Virtual Private Network (VPN)
Stars: ✭ 29 (-80.79%)
Mutual labels:  haproxy
Ansible Haproxy
Ansible role to set up (the latest version of) HAProxy in Ubuntu systems
Stars: ✭ 83 (-45.03%)
Mutual labels:  haproxy
Ansible Haproxy
Installs and configure HAProxy
Stars: ✭ 93 (-38.41%)
Mutual labels:  haproxy
Haproxy Ingress
HAProxy Ingress
Stars: ✭ 702 (+364.9%)
Mutual labels:  haproxy
Haproxy
Development repository for the haproxy cookbook
Stars: ✭ 138 (-8.61%)
Mutual labels:  haproxy
Docker Cloud Platform
使用Docker构建云平台,Docker云平台系列共三讲,Docker基础、Docker进阶、基于Docker的云平台方案。OpenStack+Docker+RestAPI+OAuth/HMAC+RabbitMQ/ZMQ+OpenResty/HAProxy/Nginx/APIGateway+Bootstrap/AngularJS+Ansible+K8S/Mesos/Marathon构建/探索微服务最佳实践。
Stars: ✭ 86 (-43.05%)
Mutual labels:  haproxy
Rpm Haproxy
HAproxy RPM spec and builds for CentOS 6/7
Stars: ✭ 103 (-31.79%)
Mutual labels:  haproxy
Ansible Config encoder filters
Ansible role used to deliver the Config Encoder Filters.
Stars: ✭ 48 (-68.21%)
Mutual labels:  haproxy
Haproxy Rest
REST interface for HAproxy written in GO
Stars: ✭ 79 (-47.68%)
Mutual labels:  haproxy
Haproxy
🏎 Built-from-source container image of the HAProxy proxy and load balancer
Stars: ✭ 100 (-33.77%)
Mutual labels:  haproxy
Kanary
Kubernetes Operator to manage canary deployment using HAProxy
Stars: ✭ 14 (-90.73%)
Mutual labels:  haproxy
Redishappy
Redis Sentinel high availabillity daemon
Stars: ✭ 111 (-26.49%)
Mutual labels:  haproxy
Rotating Proxy
Rotating TOR proxy with Docker
Stars: ✭ 739 (+389.4%)
Mutual labels:  haproxy
Haproxyadmin
A python library to interact with HAProxy over UNIX socket
Stars: ✭ 87 (-42.38%)
Mutual labels:  haproxy
Nuster
A high performance HTTP proxy cache server and RESTful NoSQL cache server based on HAProxy
Stars: ✭ 1,825 (+1108.61%)
Mutual labels:  haproxy
Ansible Role Haproxy
Ansible Role - HAProxy
Stars: ✭ 112 (-25.83%)
Mutual labels:  haproxy
Kubernetes Pfsense Controller
Integrate Kubernetes and pfSense
Stars: ✭ 100 (-33.77%)
Mutual labels:  haproxy

go-proxyproto

Actions Status Coverage Status Go Report Card

A Go library implementation of the PROXY protocol, versions 1 and 2, which provides, as per specification:

(...) a convenient way to safely transport connection information such as a client's address across multiple layers of NAT or TCP proxies. It is designed to require little changes to existing components and to limit the performance impact caused by the processing of the transported information.

This library is to be used in one of or both proxy clients and proxy servers that need to support said protocol. Both protocol versions, 1 (text-based) and 2 (binary-based) are supported.

Installation

$ go get -u github.com/pires/go-proxyproto

Usage

Client

package main

import (
	"io"
	"log"
	"net"

	proxyproto "github.com/pires/go-proxyproto"
)

func chkErr(err error) {
	if err != nil {
		log.Fatalf("Error: %s", err.Error())
	}
}

func main() {
	// Dial some proxy listener e.g. https://github.com/mailgun/proxyproto
	target, err := net.ResolveTCPAddr("tcp", "127.0.0.1:2319")
	chkErr(err)

	conn, err := net.DialTCP("tcp", nil, target)
	chkErr(err)

	defer conn.Close()

	// Create a proxyprotocol header or use HeaderProxyFromAddrs() if you
	// have two conn's
	header := &proxyproto.Header{
		Version:            1,
		Command:            proxyproto.PROXY,
		TransportProtocol:  proxyproto.TCPv4,
		SourceAddr: &net.TCPAddr{
			IP:   net.ParseIP("10.1.1.1"),
			Port: 1000,
		},
		DestinationAddr: &net.TCPAddr{
			IP:   net.ParseIP("20.2.2.2"),
			Port: 2000,
		},
	}
	// After the connection was created write the proxy headers first
	_, err = header.WriteTo(conn)
	chkErr(err)
	// Then your data... e.g.:
	_, err = io.WriteString(conn, "HELO")
	chkErr(err)
}

Server

package main

import (
	"log"
	"net"

	proxyproto "github.com/pires/go-proxyproto"
)

func main() {
	// Create a listener
	addr := "localhost:9876"
	list, err := net.Listen("tcp", addr)
	if err != nil {
		log.Fatalf("couldn't listen to %q: %q\n", addr, err.Error())
	}

	// Wrap listener in a proxyproto listener
	proxyListener := &proxyproto.Listener{Listener: list}
	defer proxyListener.Close()

	// Wait for a connection and accept it
	conn, err := proxyListener.Accept()
	defer conn.Close()

	// Print connection details
	if conn.LocalAddr() == nil {
		log.Fatal("couldn't retrieve local address")
	}
	log.Printf("local address: %q", conn.LocalAddr().String())

	if conn.RemoteAddr() == nil {
		log.Fatal("couldn't retrieve remote address")
	}
	log.Printf("remote address: %q", conn.RemoteAddr().String())
}

Special notes

AWS

AWS Network Load Balancer (NLB) does not push the PPV2 header until the client starts sending the data. This is a problem if your server speaks first. e.g. SMTP, FTP, SSH etc.

By default, NLB target group attribute proxy_protocol_v2.client_to_server.header_placement has the value on_first_ack_with_payload. You need to contact AWS support to change it to on_first_ack, instead.

Just to be clear, you need this fix only if your server is designed to speak first.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].