Skip to content

Commit f284cc9

Browse files
committed
Add a security test recipe
Adds an example recipe that can be used as a base for secur HAProxy Signed-off-by: Dan Webb <[email protected]>
1 parent 13a4b7c commit f284cc9

File tree

6 files changed

+146
-16
lines changed

6 files changed

+146
-16
lines changed

CHANGELOG.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ This file is used to list changes made in each version of the haproxy cookbook.
44

55
## Unreleased
66

7-
## 12.3.7 - *2024-11-18*
7+
- Added security test suite
88

9-
Standardise files with files in sous-chefs/repo-management
9+
## 12.3.7 - *2024-11-18*
1010

1111
Standardise files with files in sous-chefs/repo-management
1212

@@ -16,10 +16,6 @@ Standardise files with files in sous-chefs/repo-management
1616

1717
Standardise files with files in sous-chefs/repo-management
1818

19-
Standardise files with files in sous-chefs/repo-management
20-
21-
Standardise files with files in sous-chefs/repo-management
22-
2319
## 12.3.4 - *2024-05-03*
2420

2521
## 12.3.3 - *2024-05-03*
@@ -89,8 +85,6 @@ Standardise files with files in sous-chefs/repo-management
8985

9086
Standardise files with files in sous-chefs/repo-management
9187

92-
Standardise files with files in sous-chefs/repo-management
93-
9488
## 12.2.8 - *2023-02-14*
9589

9690
Standardise files with files in sous-chefs/repo-management
@@ -312,6 +306,14 @@ Standardise files with files in sous-chefs/repo-management
312306
- Documentation - clarify extra_options hash string => array option.
313307
- Clarify the supported platforms - add AmazonLinux 2, remove fedora & freebsd.
314308

309+
### Fixed
310+
311+
- Init script for Amazon Linux.
312+
313+
### BREAKING CHANGES
314+
315+
- This version removes `stats_socket`, `stats_uri` and `stats_timeout` properties from the `haproxy_global` and `haproxy_listen` resources in favour of using a hash to pass configuration options.
316+
315317
## [v6.2.7] (2019-01-10)
316318

317319
### Added
@@ -498,7 +500,13 @@ Standardise files with files in sous-chefs/repo-management
498500

499501
### Removed
500502

501-
- `default_backend` as a required property on the `frontend` resource.
503+
- Attributes from the metadata file as these are redundant
504+
- Broken tarball validation in the source recipe to prevented installs from completing
505+
506+
### Fixed
507+
508+
- Source installs not running if an older version was present on the node
509+
- Resolved all cookstyle and foodcritic warnings
502510

503511
## [v4.2.0] (2017-05-04)
504512

@@ -703,7 +711,7 @@ Standardise files with files in sous-chefs/repo-management
703711

704712
### Fixed
705713

706-
- CPU Tuning, corrects cpu_affinity resource triggers
714+
- Init script for Amazon Linux.
707715

708716
## v1.6.4
709717

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of
1515
## Requirements
1616

1717
* HAProxy `stable` or `LTS`
18-
* Chef 13.9+
18+
* Chef 16+
1919

2020
### Platforms
2121

2222
This cookbook officially supports and is tested against the following platforms:
2323

24-
* debian: 9 & 10
25-
* ubuntu: 20.04 & 21.04
26-
* centos: 7 & 8
27-
* centos-stream: 8
24+
* debian: 11 & 12
25+
* ubuntu: 20.04 & 22.04
26+
* centos-stream: 8 & 9
27+
* amazonlinux: 2023
2828
* fedora: latest
29-
* amazonlinux: 2
29+
* opensuseleap
3030

3131
PRs are welcome to add support for additional platforms.
3232

kitchen.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ suites:
4949
- name: source_openssl
5050
run_list:
5151
- recipe[test::source_openssl]
52+
- name: security
53+
run_list:
54+
- recipe[test::package]
55+
verifier:
56+
inspec_tests:
57+
- test/integration/security
5258
- name: config_2
5359
run_list:
5460
- recipe[test::config_2]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Test recipe for security configuration
2+
haproxy_install 'package'
3+
4+
# Configure global settings
5+
haproxy_config_global 'global' do
6+
user 'haproxy'
7+
group 'haproxy'
8+
log '/dev/log syslog info'
9+
log_tag 'haproxy'
10+
daemon true
11+
quiet true
12+
stats_socket '/var/run/haproxy.sock user haproxy group haproxy'
13+
stats_timeout '2m'
14+
maxconn 1000
15+
pidfile '/var/run/haproxy.pid'
16+
end
17+
18+
# Configure defaults
19+
haproxy_config_defaults 'defaults' do
20+
timeout_client '10s'
21+
timeout_server '10s'
22+
timeout_connect '10s'
23+
log 'global'
24+
mode 'http'
25+
balance 'roundrobin'
26+
option %w(httplog dontlognull redispatch tcplog)
27+
end
28+
29+
# Configure frontend
30+
haproxy_frontend 'http-in' do
31+
bind '0.0.0.0:80'
32+
default_backend 'servers'
33+
end
34+
35+
# Configure backend
36+
haproxy_backend 'servers' do
37+
server ['server1 127.0.0.1:8000 maxconn 32']
38+
end
39+
40+
# Ensure config file permissions
41+
file '/etc/haproxy/haproxy.cfg' do
42+
owner 'haproxy'
43+
group 'haproxy'
44+
mode '0640'
45+
end
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
title 'HAProxy Secure Configuration Checks'
2+
3+
# Include common HAProxy tests
4+
include_controls 'common'
5+
6+
# Security Baseline for HAProxy Configuration
7+
describe 'HAProxy Security Defaults' do
8+
# Global Security Checks
9+
describe file('/etc/haproxy/haproxy.cfg') do
10+
# Basic configuration
11+
its('content') { should match(/^\s*user\s+haproxy/) }
12+
its('content') { should match(/^\s*group\s+haproxy/) }
13+
its('content') { should match(/^\s*daemon/) }
14+
15+
# Logging configuration
16+
its('content') { should match(/^\s*log\s+\/dev\/log\s+syslog\s+info/) }
17+
its('content') { should match(/^\s*log-tag\s+haproxy/) }
18+
its('content') { should_not match(/^\s*log-send-hostname/) }
19+
20+
# Stats socket configuration
21+
its('content') { should match(/^\s*stats\s+socket\s+\/var\/run\/haproxy\.sock\s+user\s+haproxy\s+group\s+haproxy/) }
22+
its('content') { should match(/^\s*stats\s+timeout\s+2m/) }
23+
24+
# Connection settings
25+
its('content') { should match(/^\s*maxconn\s+1000/) }
26+
27+
# Default timeouts
28+
its('content') { should match(/^\s*timeout\s+client\s+10s/) }
29+
its('content') { should match(/^\s*timeout\s+server\s+10s/) }
30+
its('content') { should match(/^\s*timeout\s+connect\s+10s/) }
31+
32+
# Default options
33+
its('content') { should match(/^\s*option\s+httplog/) }
34+
its('content') { should match(/^\s*option\s+dontlognull/) }
35+
its('content') { should match(/^\s*option\s+redispatch/) }
36+
its('content') { should match(/^\s*option\s+tcplog/) }
37+
38+
# Mode and balance
39+
its('content') { should match(/^\s*mode\s+http/) }
40+
its('content') { should match(/^\s*balance\s+roundrobin/) }
41+
42+
# File permissions
43+
it { should be_owned_by 'haproxy' }
44+
it { should be_grouped_into 'haproxy' }
45+
its('mode') { should cmp '0640' }
46+
end
47+
48+
# Service Configuration
49+
describe service('haproxy') do
50+
it { should be_enabled }
51+
it { should be_running }
52+
end
53+
end
54+
55+
# Additional Security Recommendations
56+
describe 'Security Recommendations' do
57+
# Validate service configuration
58+
describe service('haproxy') do
59+
it { should be_enabled }
60+
it { should be_running }
61+
end
62+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: security
3+
title: HAProxy Security Profile
4+
version: 0.1.0
5+
supports:
6+
- os-family: linux
7+
depends:
8+
- name: common
9+
path: test/integration/common

0 commit comments

Comments
 (0)