Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit 596df6c

Browse files
committed
Fix for bug #1295006 Introduce more secure location of PHP script configs to harden a Cacti setup
1 parent 1ff37b1 commit 596df6c

File tree

9 files changed

+59
-24
lines changed

9 files changed

+59
-24
lines changed

Changelog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2014-03-20: version 1.1.3
2+
-------------------------
3+
* Introduced more secure location of PHP script configs to harden a Cacti setup (bug #1295006)
4+
15
2014-03-14: version 1.1.2
26
-------------------------
37
* Added Nagios plugin and Cacti template for Amazon RDS

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.2
1+
1.1.3

cacti/scripts/ss_get_by_ssh.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@
6161
# ============================================================================
6262
# Include settings from an external config file.
6363
# ============================================================================
64-
if ( file_exists(__FILE__ . '.cnf' ) ) {
65-
debug("Found configuration file " . __FILE__ . ".cnf");
64+
if ( file_exists('/etc/cacti/' . basename(__FILE__) . '.cnf' ) ) {
65+
require('/etc/cacti/' . basename(__FILE__) . '.cnf');
66+
debug('Found configuration file /etc/cacti/' . basename(__FILE__) . '.cnf');
67+
}
68+
elseif ( file_exists(__FILE__ . '.cnf' ) ) {
6669
require(__FILE__ . '.cnf');
70+
debug('Found configuration file ' . __FILE__ . '.cnf');
6771
}
6872

6973
# Make this a happy little script even when there are errors.
@@ -1213,7 +1217,7 @@ function openvz_parse ( $options, $output ) {
12131217
# An intro line or a dummy line
12141218
continue;
12151219
}
1216-
else if ( $words[0] === 'uid' ) {
1220+
elseif ( $words[0] === 'uid' ) {
12171221
# It's the header row. Get the headers into the header array,
12181222
# except for the UID header, which we don't need, and the resource
12191223
# header, which just defines the leftmost header that's in every

cacti/scripts/ss_get_mysql_stats.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@
6161
$version = '$VERSION$';
6262

6363
# ============================================================================
64-
# Include settings from an external config file (issue 39).
64+
# Include settings from an external config file.
6565
# ============================================================================
66-
if ( file_exists(__FILE__ . '.cnf' ) ) {
67-
debug("Found configuration file " . __FILE__ . ".cnf");
66+
if ( file_exists('/etc/cacti/' . basename(__FILE__) . '.cnf' ) ) {
67+
require('/etc/cacti/' . basename(__FILE__) . '.cnf');
68+
debug('Found configuration file /etc/cacti/' . basename(__FILE__) . '.cnf');
69+
}
70+
elseif ( file_exists(__FILE__ . '.cnf' ) ) {
6871
require(__FILE__ . '.cnf');
72+
debug('Found configuration file ' . __FILE__ . '.cnf');
6973
}
7074

7175
# Make this a happy little script even when there are errors.
@@ -195,9 +199,9 @@ function usage($message) {
195199
196200
--host MySQL host
197201
--items Comma-separated list of the items whose data you want
198-
--user MySQL username; defaults to $mysql_user if not given
199-
--pass MySQL password; defaults to $mysql_pass if not given
200-
--port MySQL port; defaults to $mysql_port if not given
202+
--user MySQL username
203+
--pass MySQL password
204+
--port MySQL port
201205
--server-id Server id to associate with a heartbeat if heartbeat usage is enabled
202206
--nocache Do not cache results in a file
203207
--help Show usage

docs/cacti/hardening-cacti-setup.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Unfortunately, the folder ``/usr/share/cacti/scripts/`` is not closed by default
2525
We strongly recommend to close any access from the web for these additional directories or files:
2626

2727
* /usr/share/cacti/scripts/
28+
* /usr/share/cacti/site/scripts/ (for Debian systems)
2829
* /usr/share/cacti/cli/
29-
* /usr/share/cacti/.ssh/
3030
* /usr/share/cacti/.boto
3131

3232
Here is an example of httpd configuration that can harden your setup (goes to ``/etc/httpd/conf.d/cacti.conf``)::
3333

34-
<Directory ~ "/usr/share/cacti/(log|rra|scripts|cli|\.ssh|\.boto|.*\.cnf)">
34+
<Directory ~ "/usr/share/cacti/(log|rra|scripts|site/scripts|cli|\.boto|\.ssh|.*\.cnf)">
3535
<IfModule mod_rewrite.c>
3636
Redirect 404 /
3737
</IfModule>
@@ -48,3 +48,8 @@ Here is an example of httpd configuration that can harden your setup (goes to ``
4848

4949
Even if you fully password-protected your Cacti installation using HTTP authentication, it is still recommended to double-secure the directories and files listed above.
5050

51+
Outlining the basic rules:
52+
53+
* keep your PHP config files ``ss_get_mysql_stats.php.cnf`` and ``ss_get_by_ssh.php.cnf`` outside the web directory ``/usr/share/cacti/scripts/``. The recommended location is ``/etc/cacti/``.
54+
* do not put any SSH keys under cacti user home directory which is still the web directory.
55+
* avoid placing ``.boto`` file under ``~cacti/``, use ``/etc/boto.cfg`` instead (that's for RDS plugins).

docs/cacti/installing-templates.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ A Configuration File
152152
--------------------
153153

154154
If you don't want to store the configuration options directly into the PHP
155-
script file, you can create another file with the same name and the filename
156-
extension ``.cnf``. Place this in the same directory as the PHP script file,
157-
and ensure it is valid PHP. This file will be included by the PHP script file,
155+
script file or you want to preserve your settings after the package update,
156+
you can create another file with the same name and the filename
157+
extension ``.cnf``. Place this under ``/etc/cacti/`` and ensure it is valid PHP.
158+
This file will be included by the PHP script file,
158159
so you can define the same configuration options there that you might define in
159160
the PHP script file. For example, you might create
160-
``scripts/ss_get_mysql_stats.php.cnf`` with the following contents::
161+
``/etc/cacti/ss_get_mysql_stats.php.cnf`` with the following contents::
161162

162163
<?php
163164
$mysql_user = "root";
@@ -179,7 +180,11 @@ A MySQL user should be configured with :ref:`the proper privileges
179180

180181
Securing Your Setup
181182
-------------------
182-
Ensure that any files under ``scripts/`` are not accessible from Web.
183+
You can also place ``.cnf`` file in the same directory as the PHP script file
184+
(just to keep the backward compatibility)
185+
but this is a security risk as ``scripts/`` folder falls under the web directory.
186+
So ``/etc/cacti/`` is the recommended location for ``.cnf`` file.
187+
In any case, ensure that any files under ``scripts/`` are not accessible from Web.
183188
Check out :ref:`Hardening Cacti setup <hardening_cacti_setup>` guide.
184189

185190
Passing Command-Line Arguments

docs/cacti/rds-templates.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ should have permissions to read the config /etc/boto.cfg or ~cacti/.boto.
2424

2525
For example::
2626

27-
[root@centos6 ~]# cat ~cacti/.boto
27+
[root@centos6 ~]# cat /etc/boto.cfg
2828
[Credentials]
2929
aws_access_key_id = THISISATESTKEY
3030
aws_secret_access_key = thisisatestawssecretaccesskey
31-
[root@centos6 ~]# chown cacti ~cacti/.boto
32-
[root@centos6 ~]# chmod 600 ~cacti/.boto
3331

34-
**IMPORTANT:** Ensure the file ``.boto`` is not accessible from Web.
32+
If you do not use this config with other tools such as our Nagios plugin,
33+
you can secure this file the following way::
34+
35+
[root@centos6 ~]# chown cacti /etc/boto.cfg
36+
[root@centos6 ~]# chmod 600 /etc/boto.cfg
37+
38+
**IMPORTANT:** If you decide to create ``~cacti/.boto`` instead, which is not secure
39+
as it falls under the web directory, ensure this file is not accessible from Web.
3540
Check out :ref:`Hardening Cacti setup <hardening_cacti_setup>` guide.
3641

3742
Test the script assuming DB instance identifier is ``blackbox``::

docs/cacti/ssh-based-templates.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ and set the proper configuration variables. This example shows how to do it
120120
with an external configuration file, but you can do it any way you please::
121121

122122
debian:~# cp scripts/ss_get_by_ssh.php /usr/share/cacti/site/scripts/
123-
debian:~# cat > /usr/share/cacti/site/scripts/ss_get_by_ssh.php.cnf
123+
debian:~# cat > /etc/cacti/ss_get_by_ssh.php.cnf
124124
<?php
125125
$ssh_user = 'cacti';
126126
$ssh_iden = '-i /etc/cacti/id_rsa';
127-
?>
127+
128128
CTRL-D
129129

130130
If you need a more complex configuration setup, such as connecting to a
@@ -133,7 +133,11 @@ the data templates and accept input in each data source.
133133

134134
Securing Your Setup
135135
-------------------
136-
Ensure that any files under ``scripts/`` are not accessible from Web.
136+
You can also place ``.cnf`` file in the same directory as the PHP script file
137+
(just to keep the backward compatibility)
138+
but this is a security risk as ``scripts/`` folder falls under the web directory.
139+
So ``/etc/cacti/`` is the recommended location for ``.cnf`` file.
140+
In any case, ensure that any files under ``scripts/`` are not accessible from Web.
137141
Check out :ref:`Hardening Cacti setup <hardening_cacti_setup>` guide.
138142

139143
Testing the Setup

nagios/bin/pmp-check-aws-rds.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ def main():
295295
[Credentials]
296296
aws_access_key_id = THISISATESTKEY
297297
aws_secret_access_key = thisisatestawssecretaccesskey
298+
299+
If you do not use this config with other tools such as our Cacti script,
300+
you can secure this file the following way:
301+
298302
[root@centos6 ~]# chown nagios /etc/boto.cfg
299303
[root@centos6 ~]# chmod 600 /etc/boto.cfg
300304

0 commit comments

Comments
 (0)