Skip to content

Commit aaaef5b

Browse files
committed
Allow configuring RemoteIPProxyProtocol at VHost level
The module currently support configuring RemoteIP PROXY Protocol at the system level, but the settings can also be used for specific virtual hosts. Allow to set `RemoteIPProxyProtocol` and `RemoteIPProxyProtocolExceptions` at the VHost level. For cosistency, une the same parameter names and types as the ones used for mod_remoteip configuration.
1 parent 925cd89 commit aaaef5b

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

manifests/vhost.pp

+22
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,11 @@
17051705
# @param userdir
17061706
# Instances of apache::mod::userdir
17071707
#
1708+
# @param proxy_protocol
1709+
# Enable or disable PROXY protocol handling
1710+
#
1711+
# @param proxy_protocol_exceptions
1712+
# Disable processing of PROXY header for certain hosts or networks
17081713
define apache::vhost (
17091714
Variant[Stdlib::Absolutepath, Boolean] $docroot,
17101715
Boolean $manage_docroot = true,
@@ -1966,6 +1971,8 @@
19661971
Apache::OIDCSettings $oidc_settings = {},
19671972
Optional[Variant[Boolean, String]] $mdomain = undef,
19681973
Optional[Variant[String[1], Array[String[1]]]] $userdir = undef,
1974+
Optional[Boolean] $proxy_protocol = undef,
1975+
Array[Stdlib::Host] $proxy_protocol_exceptions = [],
19691976
) {
19701977
# The base class must be included first because it is used by parameter defaults
19711978
if ! defined(Class['apache']) {
@@ -2955,6 +2962,21 @@
29552962
}
29562963
}
29572964

2965+
if $proxy_protocol != undef {
2966+
include apache::mod::remoteip
2967+
2968+
$proxy_protocol_params = {
2969+
proxy_protocol => $proxy_protocol,
2970+
proxy_protocol_exceptions => $proxy_protocol_exceptions,
2971+
}
2972+
2973+
concat::fragment { "${name}-proxy_protocol":
2974+
target => "${priority_real}${filename}.conf",
2975+
order => 400,
2976+
content => epp('apache/vhost/_proxy_protocol.epp', $proxy_protocol_params),
2977+
}
2978+
}
2979+
29582980
$file_footer_params = {
29592981
'define' => $define,
29602982
'passenger_pre_start' => $passenger_pre_start,

spec/defines/vhost_spec.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@
551551
'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8',
552552
'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd' },
553553
'mdomain' => 'example.com example.net auto',
554-
'userdir' => 'disabled'
554+
'userdir' => 'disabled',
555+
'proxy_protocol' => true,
556+
'proxy_protocol_exceptions' => ['127.0.0.1', '10.0.0.0/8'],
555557
}
556558
end
557559

@@ -968,6 +970,13 @@
968970
content: %r{^MDomain example\.com example\.net auto$},
969971
)
970972
}
973+
974+
it {
975+
expect(subject).to contain_concat__fragment('rspec.example.com-proxy_protocol')
976+
.with_content(%r{^RemoteIPProxyProtocol On$})
977+
.with_content(%r{^RemoteIPProxyProtocolExceptions 127\.0\.0\.1$})
978+
.with_content(%r{^RemoteIPProxyProtocolExceptions 10\.0\.0\.0/8$})
979+
}
971980
end
972981

973982
context 'vhost with proxy_add_headers true' do

templates/vhost/_proxy_protocol.epp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%- |
2+
Boolean $proxy_protocol,
3+
Array[Stdlib::Host] $proxy_protocol_exceptions,
4+
| -%>
5+
RemoteIPProxyProtocol <%= apache::bool2httpd($proxy_protocol) %>
6+
<% $proxy_protocol_exceptions.each |$exception| { -%>
7+
RemoteIPProxyProtocolExceptions <%= $exception %>
8+
<% } %>

0 commit comments

Comments
 (0)