Skip to content

Commit 99bf82c

Browse files
authored
Merge pull request #856 from teluq-pbrideau/feat/restrict_api
2 parents e49f470 + 3961a00 commit 99bf82c

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

manifests/init.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
# @param ldap_reqcert Specifies what checks to perform on a server certificate
7575
# @param zabbix_api_user Name of the user which the api should connect to. Default: Admin
7676
# @param zabbix_api_pass Password of the user which connects to the api. Default: zabbix
77+
# @param zabbix_api_access Which host has access to the api. Default: no restriction
7778
# @param listenport Listen port for the zabbix-server. Default: 10051
7879
# @param sourceip Source ip address for outgoing connections.
7980
# @param logfile Name of log file.
@@ -250,6 +251,7 @@
250251
Optional[Enum['never', 'allow', 'try', 'demand', 'hard']] $ldap_reqcert = $zabbix::params::ldap_reqcert,
251252
$zabbix_api_user = $zabbix::params::server_api_user,
252253
$zabbix_api_pass = $zabbix::params::server_api_pass,
254+
Optional[Array[Stdlib::Host,1]] $zabbix_api_access = $zabbix::params::server_api_access,
253255
$listenport = $zabbix::params::server_listenport,
254256
$sourceip = $zabbix::params::server_sourceip,
255257
Enum['console', 'file', 'system'] $logtype = $zabbix::params::server_logtype,
@@ -364,6 +366,7 @@
364366
apache_listenport_ssl => $apache_listenport_ssl,
365367
zabbix_api_user => $zabbix_api_user,
366368
zabbix_api_pass => $zabbix_api_pass,
369+
zabbix_api_access => $zabbix_api_access,
367370
database_host => $database_host,
368371
database_name => $database_name,
369372
database_schema => $database_schema,

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
$ldap_reqcert = undef
185185
$server_api_pass = 'zabbix'
186186
$server_api_user = 'Admin'
187+
$server_api_access = undef
187188
$server_database_double_ieee754 = false
188189
$saml_sp_key = undef
189190
$saml_sp_cert = undef

manifests/web.pp

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
# @param apache_listenport_ssl The port for the apache SSL vhost.
4343
# @param zabbix_api_user Name of the user which the api should connect to. Default: Admin
4444
# @param zabbix_api_pass Password of the user which connects to the api. Default: zabbix
45+
# @param zabbix_api_access Which host has access to the api. Default: no restriction
4546
# @param database_host Database host name.
4647
# @param database_name Database name.
4748
# @param database_schema Schema name. used for ibm db2.
@@ -114,6 +115,7 @@
114115
Variant[Array[Stdlib::Port], Stdlib::Port] $apache_listenport_ssl = $zabbix::params::apache_listenport_ssl,
115116
$zabbix_api_user = $zabbix::params::server_api_user,
116117
$zabbix_api_pass = $zabbix::params::server_api_pass,
118+
Optional[Array[Stdlib::Host,1]] $zabbix_api_access = $zabbix::params::server_api_access,
117119
$database_host = $zabbix::params::server_database_host,
118120
$database_name = $zabbix::params::server_database_name,
119121
$database_schema = $zabbix::params::server_database_schema,
@@ -391,9 +393,10 @@
391393
$apache_listen_port = $apache_listenport
392394
}
393395

394-
# Apache >= 2.4
395-
$directory_allow = { 'require' => 'all granted', }
396-
$directory_deny = { 'require' => 'all denied', }
396+
$location_api_access = $zabbix_api_access ? {
397+
undef => 'all granted',
398+
default => $zabbix_api_access.map |$host| { "host ${host}" },
399+
}
397400

398401
apache::vhost { $zabbix_url:
399402
docroot => '/usr/share/zabbix',
@@ -402,29 +405,37 @@
402405
default_vhost => $default_vhost,
403406
add_listen => true,
404407
directories => [
405-
merge(
406-
merge({
407-
path => '/usr/share/zabbix',
408-
provider => 'directory',
409-
}, $directory_allow),
410-
$fcgi_filematch
411-
),
412-
merge({
413-
path => '/usr/share/zabbix/conf',
414-
provider => 'directory',
415-
}, $directory_deny),
416-
merge({
417-
path => '/usr/share/zabbix/api',
418-
provider => 'directory',
419-
}, $directory_deny),
420-
merge({
421-
path => '/usr/share/zabbix/include',
422-
provider => 'directory',
423-
}, $directory_deny),
424408
merge({
425-
path => '/usr/share/zabbix/include/classes',
409+
path => '/usr/share/zabbix',
426410
provider => 'directory',
427-
}, $directory_deny),
411+
require => 'all granted',
412+
}, $fcgi_filematch
413+
),
414+
{
415+
path => '/usr/share/zabbix/conf',
416+
provider => 'directory',
417+
require => 'all denied',
418+
},
419+
{
420+
path => '/usr/share/zabbix/api',
421+
provider => 'directory',
422+
require => 'all denied',
423+
},
424+
{
425+
path => '/usr/share/zabbix/include',
426+
provider => 'directory',
427+
require => 'all denied',
428+
},
429+
{
430+
path => '/usr/share/zabbix/include/classes',
431+
provider => 'directory',
432+
require => 'all denied',
433+
},
434+
{
435+
path => '/api_jsonrpc.php',
436+
provider => 'location',
437+
require => $location_api_access,
438+
},
428439
],
429440
custom_fragment => $apache_vhost_custom_fragment,
430441
rewrites => [

spec/classes/web_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,20 @@
235235
it { is_expected.to contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(%r{^\$SSO\['IDP_CERT'\] = '/etc/zabbix/web/idp.cert'}) }
236236
it { is_expected.to contain_file('/etc/zabbix/web/zabbix.conf.php').with_content(%r{^\$SSO\['SETTINGS'\] = \[ \n "strict" => true,\n "baseurl" => "http://example.com/sp/",\n "security" => \[\n "signatureAlgorithm" => "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384",\n "digestAlgorithm" => "http://www.w3.org/2001/04/xmldsig-more#sha384",\n "singleLogoutService" => \[\n "responseUrl" => ""\n \]\n \]\n\];}) }
237237
end
238+
239+
describe 'with restriction to api access' do
240+
let :params do
241+
super().merge(
242+
zabbix_api_access: ['127.0.0.1']
243+
)
244+
end
245+
246+
it {
247+
is_expected.to contain_concat__fragment('zabbix.example.com-directories').with(
248+
content: %r{^\s+Require host 127\.0\.0\.1$}
249+
)
250+
}
251+
end
238252
end
239253
end
240254
end

0 commit comments

Comments
 (0)