Skip to content

Commit 78d507a

Browse files
feat: add option to restrict api access
1 parent e49f470 commit 78d507a

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
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::Fqdn]] $zabbix_api_access = $zabbix::params::server_api_acces,
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: 15 additions & 0 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::Fqdn]] $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,
@@ -395,6 +397,15 @@
395397
$directory_allow = { 'require' => 'all granted', }
396398
$directory_deny = { 'require' => 'all denied', }
397399

400+
$location_api_access = $zabbix_api_access ? {
401+
undef => $directory_allow,
402+
default => if versioncmp($apache::apache_version, '2.4') >= 0 {
403+
{ 'require' => $zabbix_api_access.map |$host| { "host ${host}" }, }
404+
} else {
405+
{ 'allow' => $zabbix_api_access, 'order' => 'Allow,Deny' }
406+
}
407+
}
408+
398409
apache::vhost { $zabbix_url:
399410
docroot => '/usr/share/zabbix',
400411
ip => $apache_listen_ip,
@@ -425,6 +436,10 @@
425436
path => '/usr/share/zabbix/include/classes',
426437
provider => 'directory',
427438
}, $directory_deny),
439+
merge({
440+
path => '/api_jsonrpc.php',
441+
provider => 'location',
442+
}, $location_api_access),
428443
],
429444
custom_fragment => $apache_vhost_custom_fragment,
430445
rewrites => [

0 commit comments

Comments
 (0)