Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HA PROXY v1 #22

Merged
merged 1 commit into from
Feb 4, 2016
Merged

Add support for HA PROXY v1 #22

merged 1 commit into from
Feb 4, 2016

Conversation

cfcs
Copy link

@cfcs cfcs commented Feb 3, 2016

Resolves #6

This commit adds a flag (--haproxy1) which causes tlstunnel to send
connection details to the destination upon connection.

This is useful if running nginx, Varnish or similar behind tlstunnel in order
to obtain the IP of the client.

Example of a TCP/IPv4 connection from 127.0.0.1:39837 to 127.0.0.1:4433:

PROXY TCP4 127.0.0.1 127.0.0.1 39837 4433

Relevant nginx documentation on how to use the PROXY protocol: https://www.nginx.com/resources/admin-guide/proxy-protocol/

@hannesm
Copy link
Owner

hannesm commented Feb 3, 2016

this looks great, thanks... I'll merge tomorrow after I tried it somehow

(* basically it looks like:
* PROXY TCP4 SOURCEIP DESTIP SRCPORT DESTPORT\r\n *)
let own_sockaddr = getsockname socket in
let peer_sockaddr = getpeername socket in
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they should both be Unix.getXname...

Resolves hannesm#6

This commit adds a flag (`--haproxy1`) which causes tlstunnel to send
connection details to the destination upon connection.

This is useful if running `nginx`, `Varnish` or similar behind `tlstunnel` in order
to obtain the IP of the client.

Example of a TCP/IPv4 connection from 127.0.0.1:39837 to 127.0.0.1:4433:
```
PROXY TCP4 127.0.0.1 127.0.0.1 39837 4433
```

Relevant `nginx` documentation on how to use the PROXY protocol: https://www.nginx.com/resources/admin-guide/proxy-protocol/
@cfcs
Copy link
Author

cfcs commented Feb 4, 2016

Example usage for testing:

Run tlstunnel:

user@localhost:~/tlsping (master)$ ../tlstunnel/tlstunnel.native --cert proxy.public.certificate --key proxy.secret.key --haproxy1
[2016-02-04T00:22:33Z] listener started on 0.0.0.0:4433, forwarding to 127.0.0.1:8080
[2016-02-04T00:22:52Z] 127.0.0.1:54508: connection established (TLS version 1.2, TLS_DHE_RSA_WITH_AES_256_CCM)

netcat listener:

user@localhost:~$ nc -v -l -p 8080
listening on [any] 8080 ...
connect to [127.0.0.1] from localhost [127.0.0.1] 50062
PROXY TCP4 127.0.0.1 127.0.0.1 54508 4433

connect using tlsclient:

user@localhost:~/tlsclient $ ./tlsclient.native localhost:4433

hannesm added a commit that referenced this pull request Feb 4, 2016
Add support for HA PROXY v1
@hannesm hannesm merged commit 85abd27 into hannesm:master Feb 4, 2016
@cfcs cfcs deleted the haproxy1 branch February 4, 2016 10:56
let header = String.concat " "
[ "PROXY" ; protocol_string ; peer_addr ; own_addr ; peer_port ; own_port ]
in
header ^ "\r\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be folded into the above String.concat

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give an example?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could:

String.concat " "
   [ "PROXY" ; protocol_string ; peer_addr ; own_addr ; peer_port ; own_port ^ "\r\n" ]

I'm undecided which is more readable...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right.
I'm fine with both, feel free to change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants