docs: document and verify Cacti 1.2.x deployment hardening (#325)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
This commit is contained in:
Thomas Vincent authored and GitHub committed 2026-12-03 00:15:34 -08:00
1 parent 4c60d90b57
commit 8f58504a4a
1 file changed
+265 -26
+265 -26
View File
@@ -1,38 +1,277 @@
# Harden a Cacti installation
Apply these checks to the main server and to each remote collector. Start
with the service accounts and paths from your distribution's installation
guide. Test changes on a representative host while you can still restore
the previous configuration.
Start with one collector, two test users and two graphs. When the installation
is ready, a viewer should be able to open their own graph, a second team's
graph should be inaccessible to them, and the poller should still produce
fresh data. Run the checks again after changing authentication, a plugin,
the web server or the collector topology.
## Separate runtime data from application files
## Why These Controls Matter
Identify the web, scheduler and poller accounts. Give the process that
writes each RRD or log directory access to that directory. Keep PHP
application files and plugin code writable by the deployment account.
Restrict the database configuration files to the accounts that read them.
After changing ownership, confirm that a web login succeeds, a fresh poll
produces a log entry, and an existing graph gets a new data point.
A Cacti installation holds device credentials, network inventory and years
of measurements. Different processes need different access to that data.
Before changing a live system, record the public URL and proxy path, the
web and poller service accounts, the database and RRD locations, and any
remote collectors. Save the working configuration and identify who can
restore access if a change prevents sign-in or polling.
## Limit network access
## Secure sign-in and graph access
Allow the web interface over HTTPS for its intended users. Restrict
database access to the hosts that require it, including both connection
directions for [remote collectors](How-To-Setup-Remote-Pollers.md). Use
read-only device credentials for polling. Keep install packages, database
exports and backups outside the web root.
1. Serve the console and graph pages over HTTPS with a certificate trusted
by the intended clients. If a reverse proxy handles TLS or authentication,
restrict the application listener to that proxy and trusted administration
paths. Have the proxy replace any client-supplied identity headers it
uses. Verify the browser sees the expected hostname and HTTPS on redirects.
2. Replace initial administrator credentials during commissioning. Use named
accounts for routine work. Keep an independently tested recovery method
and a working administrator session while changing the login provider.
For shared workstations, review **Support Authentication Cookies** and
whether persistent sign-in is appropriate.
3. For [LDAP authentication](Settings-Auth-LDAP.md), use LDAPS or
StartTLS with certificate validation and a read-only lookup account.
If using [Web Basic authentication](Settings-Auth-Basic.md), require
authentication at the web server and allow only its trusted identity
to reach Cacti. Apply MFA at the upstream provider where supported.
4. For a private installation, set **Guest User** to **No User** under
[Authentication](Settings-Auth.md). If public graphs are intentional,
grant a dedicated guest identity access only to the published graphs.
Review the template and group memberships assigned to newly provisioned
accounts. Test with a newly provisioned viewer.
5. Grant realms for the actions a person needs and review the effective
graph, device and template grants under
[User Management](User-Management.md).
With the permissive graph policy, a grant on a shared template can expose
graphs from several devices. Graph trees organize navigation. Test
access to a graph by direct URL as well as through the tree.
## Verify the web server configuration
| Test identity | Action | Expected result for a private installation |
| --- | --- | --- |
| Signed-out browser | Open a saved private graph URL. | No graph image or data is disclosed. |
| Team A viewer | Open an A graph, then a B graph by its saved URL. | A renders and B is denied. Repeat in the other direction as a B viewer. |
| Team A viewer | Open user management and plugin administration. | Administrative actions are unavailable. Check plugin dashboards separately. |
| Administrator | Sign in again in a separate browser session. | Intended administration functions work before the original session is closed. |
The distribution includes Apache access rules for directories such as
`cli/` and `log/`. Confirm the deployed virtual host enforces the
restrictions. Nginx needs equivalent location rules. Request the path to
an existing CLI script or log from a test client and verify that access is
denied. Then open a normal graph page and verify that it still renders.
## Protect collector and database connections
Use the [Enterprise Linux](Install-Under-Enterprise-Linux-LAMP.md) or
[Ubuntu/Debian](Installing-Under-Ubuntu-Debian.md) installation guide for
the service configuration on your platform.
### Limit network access
| Connection | Configuration | How to verify |
| --- | --- | --- |
| Cacti and Spine to the database | Use dedicated service accounts scoped to the Cacti database and expected source hosts. Grant additional documented privileges individually. Protect Cacti and Spine configuration files. | Confirm a normal web login and a completed poll. For a remote TLS connection, check the negotiated cipher on that connection and verify server identity using the configured CA. |
| Main server and remote collectors | Limit firewall access to the actual peers. Remote pollers connect to the primary database, and the primary connects back for synchronization. Configure TLS or a protected management network for both directions. | On a remote test device, compare the last local poll time with the latest sample visible centrally. Check synchronization after a configuration change. |
| Collector to devices | Use a read-only SNMPv3 account with authentication and privacy where supported. Limit the permitted collector addresses and SNMP view. Scope any necessary legacy community to its devices and management network. | From the assigned collector, read one expected counter and verify the corresponding graph advances over two polls. |
For remote collectors, follow the [remote poller instructions][remote].
Select algorithms supported by both the poller and the device under
[SNMP Options](SNMP-Options.md). Keep credentials out of graph titles,
command histories, exported examples and support attachments. Rotate a
credential on one pilot device and verify polling before rolling it out.
## 1. File Permissions
### Separate runtime data from application files
Identify the process that writes each runtime path. Keep PHP source, plugins,
scripts and configuration owned by the deployment account. Give the web
handler and poller read access where needed, and grant writes to the actual
runtime directories used by each service. Package layouts can put RRDs and
logs outside the web root. Plugins can have additional output directories.
| Item | Access to establish |
| --- | --- |
| `include/config.php`, Spine configuration, private keys and external secrets | Readable by the services that need them and by authorized administrators. Check file and parent-directory permissions. |
| RRDs, logs, cache and plugin output | Writable by the designated producer. Give any separate reader only the access it needs. |
| Application, plugin and script code | Writable during controlled deployment. Review temporary write access needed for installation or import and remove it when finished. |
| SQL dumps, archived configurations and backup copies | Store outside the web root. Restrict backup readers and protect encryption keys separately. |
Before changing ownership or modes, record their current values. A
recursive permission change across the installation can expose credentials
or break the next polling cycle. On Linux, the following read-only checks
work with the actual service accounts and absolute paths from your inventory.
```sh
sudo -u "$WEB_USER" test -r "$CACTI_ROOT/include/config.php"
sudo -u "$POLLER_USER" test -w "$RRD_DIR"
sudo -u "$WEB_USER" test ! -w "$CACTI_ROOT/include/config.php"
```
Each command should exit zero for this layout. If an RRD cache daemon owns
the files, substitute its service account for the write check. Verify the
real operation too by opening a graph and observing the next completed poll.
## 2. Web Server — Block Direct Access to Scripts and Resources
Apply these examples inside the virtual host that actually serves Cacti.
Substitute its filesystem path, URL prefix and aliases. The examples block
private directory trees, direct access to database configuration, and PHP
files under `resource/`, while allowing normal UI assets. Apply equivalent
rules to every public entry point.
### Apache
Place the following in the Apache 2.4 virtual host. The directory
expressions use the filesystem path, including when Cacti is served by
an alias.
```apache
<DirectoryMatch "^/var/www/html/cacti/(bin|cli|contrib|log|mibs|rra|scripts|tests)(/|$)">
Require all denied
</DirectoryMatch>
<DirectoryMatch "^/var/www/html/cacti/cache/(boost|mibcache|purifier|realtime|spikekill)(/|$)">
Require all denied
</DirectoryMatch>
<Directory "/var/www/html/cacti/include">
<Files "config.php">
Require all denied
</Files>
</Directory>
<Directory "/var/www/html/cacti/resource">
<FilesMatch "(?i)\.php$">
Require all denied
</FilesMatch>
</Directory>
```
### Nginx
Place these rules in the Cacti server block before the general PHP regular
expression location. Check existing prefix locations. A conflicting
`^~` location can prevent evaluation of regular expression locations.
A deployment at the web root needs patterns without the `/cacti` prefix.
```nginx
location ~* ^/cacti/(bin|cli|contrib|log|mibs|rra|scripts|tests)(/|$) {
return 403;
}
location ~* ^/cacti/cache/(boost|mibcache|purifier|realtime|spikekill)(/|$) {
return 403;
}
location ~* ^/cacti/include/config\.php(/|$) {
return 403;
}
location ~* ^/cacti/resource/.*\.php(/|$) {
return 403;
}
```
### Directories That Cacti Denies by Default
Review the `.htaccess` files shipped with your Cacti release, including
those in private cache directories. Apache honors them only when its
override configuration permits it. Nginx requires server-level rules.
Keep backup and editor copies of configuration files outside the document
root, even when a rule protects the live filename.
### Verify the web server configuration
Validate the active configuration with `apachectl configtest` or `nginx -t`
before reloading. In staging, place a temporary plain-text marker with no
secrets in a protected log directory. Request it through the normal browser
URL. With the example rules it should return **403**. Remove the marker,
open an authorized graph and confirm its image and styles still load.
A 404 for a file that never existed cannot verify the access rule.
## 3. PHP-FPM Pool Hardening
If the installation uses PHP-FPM, give Cacti a dedicated pool identity
and restrict the pool socket to the front end. Keep production PHP errors
in a restricted log. Limit executable script extensions to those the
application uses. Review environment variables passed to the pool. Cacti
uses external programs such as RRDtool, so test graph rendering and any
plugin helpers after changing PHP execution restrictions. The CLI poller
can use a different PHP configuration from the web handler.
## 4. SELinux (RHEL / AlmaLinux / Rocky Linux)
Keep SELinux enforcing. Use the distribution's packaged policy as the
starting point and verify which process domain handles each workload.
### File Contexts
Inspect current labels with `ls -Zd` on the actual application and
runtime paths. Use persistent file-context mappings for custom paths.
For example, a site using the standard httpd policy may allow a
web-written cache under `httpd_sys_rw_content_t` while keeping PHP code
under `httpd_sys_content_t`. Use `restorecon -nRv` on the chosen path
to preview relabeling before applying it.
### Database Network Access
If web requests fail to reach a remote database, compare the database
listener, firewall rules and SELinux audit log. On systems using
the httpd policy, inspect `getsebool httpd_can_network_connect_db`.
Evaluate the effect on all processes in the affected domain before
changing the setting.
### Poller Systemd Drop-in
Find the unit or cron entry that actually starts the poller. Inspect
its account, domain and recent denials before adjusting a unit override.
Confirm SNMP collection and an RRD update from that service context.
Changing an httpd boolean can leave a separate poller domain unaffected.
## 5. AppArmor (Debian / Ubuntu)
### Attach the Profile to the php-fpm Service
Check `aa-status` for the profile applied to the running web or PHP
service. Record which other sites share that service before changing its
confinement. Use a staging host to exercise login, graph rendering, cache
writes and enabled plugin features. Review the resulting denials, refine
the profile to the required paths and helper binaries, then retest in
enforce mode. Verify the scheduler separately under its own service identity.
## Update plugins and rehearse recovery
Inventory installed core, Spine and plugin versions. Use the
[core security advisories][advisories] and each installed plugin's
upstream release notes to identify the fixed version for your branch.
Take a recoverable backup, apply the update on a staging copy, and repeat
the sign-in, graph and polling checks before rolling it out to production.
Confirm the deployed version on the main server and each remote collector.
Install packages and plugins from a trusted source,
review their scripts and dependencies, and grant plugin management and
template import only to designated maintainers. Disable unused plugins.
Review what an uninstall removes before deleting one.
Keep the database, RRDs, configuration, external keys and plugin-owned
files together in the recovery plan. Encrypt backups that contain
credentials and restrict access to their decryption keys. Restore a backup
on an isolated host with mail and production polling disabled. Check one
historical graph, one newly polled lab device and a viewer's allowed
and denied graphs
before recording the drill as successful. See [Upgrading Cacti][upgrade]
for the branch's update procedure.
## 6. Verification Checklist
| After a change | Acceptance check |
| --- | --- |
| Web server or proxy | HTTPS login, required static assets and an authorized graph work. A protected marker is denied through the public route. |
| Authentication or group mapping | A newly provisioned user receives the intended role. The signed-out, authorized and unauthorized graph tests produce the expected results. |
| Collector network or credentials | A real poll finishes on the assigned collector and a finite sample reaches the expected graph. |
| Plugin update or permission change | Its normal page and scheduled work succeed. A viewer cannot manage the plugin. |
| Backup or restore | The recovery copy opens historical graphs and can collect a fresh test sample. |
Review the [Cacti log](Cacti-Log.md), web and authentication logs, and
database or collector errors after each change. Set a retention period
and restrict who can read or export them. Assign someone to investigate
repeated login failures, unexpected administrator changes and collectors
that stop reporting. If compromise is suspected, preserve timestamps and
relevant logs, isolate the affected service, and replace exposed credentials
from a trusted system. Use the project's [security policy][policy] for a
private report concerning Cacti or a plugin.
## See Also
- [Enterprise Linux installation](Install-Under-Enterprise-Linux-LAMP.md)
- [Ubuntu and Debian installation](Installing-Under-Ubuntu-Debian.md)
- [Security standards for contributors](Standards-Security.md)
[advisories]: <https://github.com/Cacti/cacti/security/advisories>
[policy]: <https://github.com/Cacti/cacti/security/policy>
[remote]: How-To-Setup-Remote-Pollers.md
[upgrade]: Upgrading-Cacti.md
---