HAproxy
HAproxy is fantastic reverse proxy with a massive amount of features. Knocknoc has supported HAproxy for years, and integrates with it natively. HAproxy can be a little confusing at first due to its wide array of options and implementations, for now we'll walk through some basic configuration for use in front of Confluence.
Note: If you are reading this page, you should already have your Knocknoc Knocknoc Server and Agent setup as this guide will assume you are at least aware of the features being addressed.
HAproxy Configuration via the Admin Socket
Knocknoc supports HAproxy's admin socket, this interaction is how the access control list (ACL) within HAproxy is updated to allow your users to access the protected application behind. For this guide we are going to make a few assumptions, the first is that you have a Linux based system and the second is the Knocknoc Agent and HAproxy is installed already.
First, we need to addAdd the knocknoc-agentuser,user to the haproxy group. This allows the knocknoc-agent toaccessread and modify theHAproxy socket.
ACL.
adduser knocknoc-agent haproxy
ThenEditwe need to map out athe HAproxy configurationfile with a few things to ensure we are looking at the right socket, are using an ACL and that ACL is in use for accessing confluence.
file.
vi /etc/haproxy/haproxy.cfg
The first thing to check and not here isCheck the socket configuration under the globalsection,section.thisThisitemsocketshouldis what the agent connects to, in order to control HAproxy, hence the need for permissions. The line will list the location of thesocket, the permissions setsocket andtheaccessuserpermissions.andForgroup that has access, for example.
example;
stats socket /run/haproxy/admin.sock mode 0666 level admin user haproxy group haproxy
This socket is what the agent connects to, in order to control haproxy, hence the need for permissions. You also need to copy and pasteCopy the path to the socket and paste into theKnocknoc-admin backendsocket path in the Knocknoc admin interface whensettingcreatingup an Haproxya backend.Next, we need to configure ourThe frontend definition, inour example we are protecting a Confluence instance. Inthisexampleexample,we areis listening forHTTPHTTP/s traffic on all interfaces on port 443 and HAproxy is providing the SSL verification from the certificates within the provided directory.
frontend https_frontend mode http bind *:443 ssl crt /etc/ssl/private/ alpn h2,http/1.1
ThereWithinarethe frontend definition, we have 3 ACL's defined here;s;-
acl is_confluence hdr(host) confluence.mycompany.com
any traffic hitting the url definedhereis marked with the ACL "is_confluence" -
acl is_http hdr(X-Forwarded-Proto) http
any traffic that is HTTP and not HTTPS is marked with the ACL "is_http" -
acl knoc_confluence src -u 500
lastly,is theinteractionACL-ID that Knocknoc-agent is interacting withKnocknoc,in thisACLexample.checksUsersthewhoadminhavesocketauthenticatedfromtostep 3 above. If a user has logged into knocknocKnocknoc andisviaatheirpartgroupsofarethegrantedsecurityaccessgrouptothatConfluenceiswillapproved for that ACLhave their IPwilladdedbetoreservedthat ACL-ID. Traffic from the IP's in that ACL-ID500 and traffic from those IP's isare marked with the ACL "knoc_confluence".acl is_confluence hdr(host) confluence.mycompany.com acl is_http hdr(X-Forwarded-Proto) http acl knoc_confluence src -u 500
-
- The
secondbelowtorulelast entry inwithin the frontend definitiontells HAproxy ifredirects trafficismarked with the ACL "is_http"redirectfromitHTTP to HTTPS. Forcing all traffic to be encrypted.is_httpis_http -
The last line, indicates trafficTraffic that is marked with the ACL's "is_confluence" and "knoc_confluence" isthedirecteduseto the backenddefinition"confluence_backend"use_backend confluence_backend if is_confluence knoc_confluence
TheAnylasttrafficthingnottothosedoACL's receives a 503 error.- Next is
definethe backend definitionwe are going to target intheaboveexamplefrontend. A few things to note;contains;Thebackend
this has to match thenameconfluence_backendnameuse_backend
usedconfluence_backendinfrom thefrontend.frontend definition.- The mode,
mode
,inhttpalmost all caseswhich should match thefrontend.mode from the frontend definition. - The server
definitionline;must- This contains a
name,recognizable name for the server,server confluence_server
for easy identification and logging. - The IP:Port
atoftheConfluencevery192.168.0.200:443
least.behind
contain - This contains a
In the following example, our server line contains the name confluence_server, with an IP and Port.Theadditionalcheck
configstatement,of "check ssl verify none"which tells HAproxy to checktheConfluencebackendisserverup and responding on theportIP:Port.ssl
this statement means HAproxy does not care if theseeverify noneserverConfluence SSL cert isalivevalid as SSL termination is happening between the user andtoHAproxy.ignore verifying the SSL certificate. This means SSL only need to be maintained on HAProxy, reducing management overhead.backend confluence_backend mode http server confluence_server 192.168.0.200:443 check ssl verify none
to
There is aA lot, lot more that can be done with HAProxyHAproxy the more familiar you become with it the more confident you will be to use it. Tied with Knocknoc's security integration it can become a fundamental cog in your security machine. Should you need further assistance feel free to reach out to one of our support partners.
Knocknoc Admin Interface Configuration for HAproxy
WithinClick Backends on theKnocknocleft.- Click
adminCreateinterface,Backend on the right.- Enter a
backendname that is sensible, for example Server name - HAProxy. - Select the Knocknoc-agent that is installed on this server.
- Backend Type will
needbetoHAProxy. - Command Protocol will be
created.UnixTheSocket - Address will be the
onelocationinstalledof the HAProxy socket from the HAProxy config.
agent - Enter a
- Click Create.
- Click on
thisACLsserver, andon theaddressleft. - Click
toCreate ACL on the right. - Under Groups on the left, Select the group that requires access to Confluence and click edit and check the box for the
socket.Confluence Then we need to create an ACL using the above backend. The ACL name needs to match the ACL ID used in the HAproxy config.Now we need to add a Security Group and add this ACL to the security group to allow the IP of the users within the group to be added to ACL 500. Now user
ACL.
Note: Group configuration varies, slightly depending on which Authentication source is being used. For guidance of Authentication, Groups and Users please review the documentation.
Additional HAProxy Configuration NotesInformation
HAproxy TCP Socket
The HAproxyHAProxy backend also supports a TCP socket, in which case it still expects to talk to the unixUnix socket, but it can do so via a TCP redirect. This is most easily accomplished with the spiped utility.
knocknoc-Knocknoc-agent ships with a script make-spiped-tunnel.sh which can walk you through making an spiped encrypted tunnel via spiped between your knocknoc-Knocknoc-agent machine and a remote haproxy.HAProxy. It is often easier to deploy knocknoc-Knocknoc-agent directly to a machine, but in case this isn't possible, you can use anthe spiped tunnel for this purpose.
Further documentation on this will be added in the near future.
Error Responses
HAproxy can easily send custom 403 or 503 responses to users who aren't allowed to access the backend resource. For example:
This is configured as the default_backend error response in the haproxyHAProxy config, so if the httpHTTP request doesn't match the right source IP or hostname, the above is showshown toin the browser. An admin can customisecustomize this to display whatever you like,anything, but keep in mind itsit's ana HTTP response, not an HTML page, so there are limitations. You could of course link people to your Knocknoc instance in the error message, depending on your users and risk profile.
Full
Further haproxy.cfgdocumentation exampleon this will be added in the near future.
Example HAProxy configuration file
Below is a full example of a basic default HAProxy configuration filefile. completedIt withcontains the settingsettings from above.above to allow a 1:1 comparison.
global
log /dev/log local0
log /dev/log local1 notice
stats socket /run/haproxy/admin.sock mode 0666 level admin user haproxy group haproxy
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL
ssl-default-bind-options no-sslv3
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl-default-server-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL
ssl-default-server-options no-sslv3
nbproc 1
# Defaults
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
# Userlist
# Resolvers
# Listen
frontend https_frontend
mode http
bind *:443 ssl crt /etc/ssl/private/ alpn h2,http/1.1
acl is_confluence hdr(host) confluence.mycompany.com
acl is_http hdr(X-Forwarded-Proto) http
acl knoc_confluence src -u 500
redirect scheme https if is_http
use_backend confluence_backend if is_confluence knoc_confluence
backend confluence_backend
mode http
server confluence_server 192.168.0.1:443 check ssl verify none