Haproxy Quick ACL Testing

This is just a very minor setup that I’m using that I thought I’d share for testing acl rules and such.

Ruby sinatra is a great and very quick way to spin up a tiny webservice. By default it’ll run webrick which is fine for this method of testing. Here’s what my app looks like:

require 'sinatra'
set :port, ARGV[1]
get '*' do
  "#{ARGV[0]}"
end

And then I have this spun up via a very tiny barely functional init script (we
use chef, I didn’t feel like spinning up a ruby environment, so I hacked into
chef’s embedded ruby):

#!/bin/bash
/opt/chef/embedded/bin/ruby /root/test-web-app.rb success 4567 >> /dev/null 2>&1 &
/opt/chef/embedded/bin/ruby /root/test-web-app.rb fail 4568 >> /dev/null 2>&1 &
RETVAL=$?
exit $RETVAL

And then when I need to test a rule in haproxy I set it up like so:

backend success_backend
  server localhost 127.0.0.1:4567 check
backend fail_backend
  server localhost 127.0.0.1:4568 check

Then in my frontend I can create acl’s and send them to either backend for quick testing.

acl successful url_beg /yay
use_backend success_backend if successful
default_backend fail_backend if failure

And then doing a test using curl we see that this worked well enough.

[root~]# curl http://localhost/yay
success
[root~]# curl http://localhost/aww
fail
[root~]#

This becomes limiting when you need to start messing with things like redirects or if you need to pay attention to headers and cookies. But for starting off, especially learning and getting the hang of haproxy, this was very ideal. Sinatra makes this incredibly easy for helping me test rewrites.

Resources:

John T Skarbek

John T Skarbek
Im an Infrastructure Engineer at CA Technologies in the Agile Business Unit. Reading and using the latest and greatest of technology is what I want to be doing. Blogging is not something I do on any regular basis (and it shows).

Demonstrating Memory Behavior for AWS Lambda Function Freezing

AWS indicates that when a function is executed, there are some things that getleftover between runs. The execution environment, which AW...… Continue reading

Openshift v3 Deployment Strategy

Published on April 23, 2016

Haproxy URL Rewrite Logging Double Take

Published on May 29, 2015