-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an example recipe that can be used as a base for secur HAProxy Signed-off-by: Dan Webb <[email protected]>
- Loading branch information
Showing
6 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Test recipe for security configuration | ||
haproxy_install 'package' | ||
|
||
# Configure global settings | ||
haproxy_config_global 'global' do | ||
user 'haproxy' | ||
group 'haproxy' | ||
log '/dev/log syslog info' | ||
log_tag 'haproxy' | ||
daemon true | ||
quiet true | ||
stats_socket '/var/run/haproxy.sock user haproxy group haproxy' | ||
stats_timeout '2m' | ||
maxconn 1000 | ||
pidfile '/var/run/haproxy.pid' | ||
end | ||
|
||
# Configure defaults | ||
haproxy_config_defaults 'defaults' do | ||
timeout_client '10s' | ||
timeout_server '10s' | ||
timeout_connect '10s' | ||
log 'global' | ||
mode 'http' | ||
balance 'roundrobin' | ||
option %w(httplog dontlognull redispatch tcplog) | ||
end | ||
|
||
# Configure frontend | ||
haproxy_frontend 'http-in' do | ||
bind '0.0.0.0:80' | ||
default_backend 'servers' | ||
end | ||
|
||
# Configure backend | ||
haproxy_backend 'servers' do | ||
server ['server1 127.0.0.1:8000 maxconn 32'] | ||
end | ||
|
||
# Ensure config file permissions | ||
file '/etc/haproxy/haproxy.cfg' do | ||
owner 'haproxy' | ||
group 'haproxy' | ||
mode '0640' | ||
end |
62 changes: 62 additions & 0 deletions
62
test/integration/security/controls/secure_defaults_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
title 'HAProxy Secure Configuration Checks' | ||
|
||
# Include common HAProxy tests | ||
include_controls 'common' | ||
|
||
# Security Baseline for HAProxy Configuration | ||
describe 'HAProxy Security Defaults' do | ||
# Global Security Checks | ||
describe file('/etc/haproxy/haproxy.cfg') do | ||
# Basic configuration | ||
its('content') { should match(/^\s*user\s+haproxy/) } | ||
its('content') { should match(/^\s*group\s+haproxy/) } | ||
its('content') { should match(/^\s*daemon/) } | ||
|
||
# Logging configuration | ||
its('content') { should match(/^\s*log\s+\/dev\/log\s+syslog\s+info/) } | ||
its('content') { should match(/^\s*log-tag\s+haproxy/) } | ||
its('content') { should_not match(/^\s*log-send-hostname/) } | ||
|
||
# Stats socket configuration | ||
its('content') { should match(/^\s*stats\s+socket\s+\/var\/run\/haproxy\.sock\s+user\s+haproxy\s+group\s+haproxy/) } | ||
its('content') { should match(/^\s*stats\s+timeout\s+2m/) } | ||
|
||
# Connection settings | ||
its('content') { should match(/^\s*maxconn\s+1000/) } | ||
|
||
# Default timeouts | ||
its('content') { should match(/^\s*timeout\s+client\s+10s/) } | ||
its('content') { should match(/^\s*timeout\s+server\s+10s/) } | ||
its('content') { should match(/^\s*timeout\s+connect\s+10s/) } | ||
|
||
# Default options | ||
its('content') { should match(/^\s*option\s+httplog/) } | ||
its('content') { should match(/^\s*option\s+dontlognull/) } | ||
its('content') { should match(/^\s*option\s+redispatch/) } | ||
its('content') { should match(/^\s*option\s+tcplog/) } | ||
|
||
# Mode and balance | ||
its('content') { should match(/^\s*mode\s+http/) } | ||
its('content') { should match(/^\s*balance\s+roundrobin/) } | ||
|
||
# File permissions | ||
it { should be_owned_by 'haproxy' } | ||
it { should be_grouped_into 'haproxy' } | ||
its('mode') { should cmp '0640' } | ||
end | ||
|
||
# Service Configuration | ||
describe service('haproxy') do | ||
it { should be_enabled } | ||
it { should be_running } | ||
end | ||
end | ||
|
||
# Additional Security Recommendations | ||
describe 'Security Recommendations' do | ||
# Validate service configuration | ||
describe service('haproxy') do | ||
it { should be_enabled } | ||
it { should be_running } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
name: security | ||
title: HAProxy Security Profile | ||
version: 0.1.0 | ||
supports: | ||
- os-family: linux | ||
depends: | ||
- name: common | ||
path: test/integration/common |