diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index dce47e4..e5e7109 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -63,7 +63,7 @@ jobs: run: | set -euo pipefail php -v - for f in *.php include/*.php locales/*.php tests/bin/*.php; do + for f in *.php include/*.php locales/*.php scripts/*.php tests/bin/*.php; do php -l "$f" done # The node read script runs under whatever /bin/sh a node has. @@ -372,7 +372,8 @@ jobs: php plugins/pfs/tests/bin/page-check.php http://127.0.0.1:8080/cacti/ \ index.php host.php graph_view.php graphs.php data_sources.php plugins.php \ settings.php utilities.php user_admin.php \ - plugins/pfs/pfs.php plugins/pfs/pfs_admin.php plugins/pfs/pfs_health.php + plugins/pfs/pfs.php plugins/pfs/pfs_admin.php plugins/pfs/pfs_health.php \ + plugins/pfs/pfs_operator.php if grep -E "Fatal error|Parse error|Uncaught" "$RUNNER_TEMP/php-server.log"; then exit 1 fi diff --git a/docs/security-review.md b/docs/security-review.md index 4004417..9e7cfde 100644 --- a/docs/security-review.md +++ b/docs/security-review.md @@ -46,7 +46,10 @@ No issue found. ### Permissions -- Two realms: **Parallel Filesystem View** (`pfs.php`) and **Parallel Filesystem Admin** (`pfs_admin.php`, `pfs_health.php`). Every page checks its realm, and every page and admin action on a record tied to a device checks `is_device_allowed()` before reading or writing it; lists and the export are filtered the same way. This was tightened in milestone 3 after a coordinator audit, and a restricted-admin case is in the permission suite (`tests/bin/device-permissions.php`). +- Three realms: **Parallel Filesystem View** (`pfs.php`), **Parallel Filesystem Operator** (`pfs_operator.php`), and **Parallel Filesystem Admin** (`pfs_admin.php`, `pfs_health.php`). The Operator realm is never granted automatically. +- Inheritance is resolved per request and adds no stored grant: `pfs_auth_alternate_realms()` (setup.php) maps `pfs.php` and `pfs_operator.php` onto the Admin realm id for a user who holds Admin, and `pfs.php` onto the Operator realm id for a user who holds Operator, by rewriting Cacti's `$user_auth_realm_filenames` for that request only. +- Before a session exists, Cacti runs this hook ahead of cookie and Basic authentication. For `pfs.php` and `pfs_operator.php` only, the hook then sets the page's core realm id to -1, so core skips its realm check, and restores the real id on the next call. The page's own guard does the check instead: `pfs_page_start()` calls `pfs_page_allowed()`, which resolves inheritance again against the now authenticated user and requires `api_plugin_user_realm_auth()` for the page. Every deferred page must call `pfs_page_start()` before it reads data or acts; `tests/Security/SourceRulesTest.php` checks that each page the hook defers does so first. +- Every page checks its realm, and every page and admin action on a record tied to a device checks `is_device_allowed()` before reading or writing it; lists and the export are filtered the same way. This was tightened in milestone 3 after a coordinator audit, and a restricted-admin case is in the permission suite (`tests/bin/device-permissions.php`). - State-changing actions are POST only, behind Cacti's CSRF protection; the page suite checks that GET does not change state. - Realms are granted only from the Plugins page (install and `check_config`); a repair triggered by any page load never grants a realm. @@ -80,7 +83,7 @@ None in this pass. The device-permission gap found in milestone 3 was fixed then 3. Debugfs access: whatever the site does to let the reader read OST `stats` (a debugfs mount option, group, or a privileged helper) and whether it widens access. 4. `SshNodeSource::argv()` and `ProcRunner`: option injection through any setting or node field, and the child's environment and file descriptors. 5. `LustreBackend::parse()` with crafted input: memory and time at the size limits. -6. The permission suite results (`tests/bin/page-permissions.php`, `tests/bin/device-permissions.php`) and the realm and `is_device_allowed()` checks in `pfs.php`, `pfs_admin.php`, and `pfs_health.php`. +6. The permission suite results (`tests/bin/page-permissions.php`, `tests/bin/device-permissions.php`) and the realm and `is_device_allowed()` checks in `pfs.php`, `pfs_operator.php`, `pfs_admin.php`, and `pfs_health.php`, and the realm deferral in `pfs_auth_alternate_realms()`. 7. The query file copy and uninstall removal, including the symbolic link refusal and the temporary file and rename. 8. Remote data collectors are phase 2 and out of scope here; `remote_agent` actions do not exist yet. diff --git a/tests/Security/SourceRulesTest.php b/tests/Security/SourceRulesTest.php index a8a6ac8..f4b3147 100644 --- a/tests/Security/SourceRulesTest.php +++ b/tests/Security/SourceRulesTest.php @@ -312,6 +312,29 @@ function pfs_code(string $file): string { } }); +it('runs pfs_page_start() first in every page whose realm check setup.php defers', function () { + // Before a session exists, pfs_auth_alternate_realms() sets these pages' + // core realm to -1, so core skips its check and the page's own guard is + // the only one. Nothing may read data or act before it. + expect(preg_match('/in_array\(\$page, array\(([^)]*)\)/', pfs_code('setup.php'), $m))->toBe(1); + $pages = array_map(static fn (string $p): string => trim($p, " '"), explode(',', $m[1])); + + expect($pages)->not->toBeEmpty(); + + foreach ($pages as $page) { + $code = pfs_code($page); + $guard = strpos($code, "if (!pfs_page_start()) {\n\texit;\n}"); + + expect($guard)->not->toBeFalse($page); + + // Only the opening tag, use statements, chdir() and the includes + // that define pfs_page_start() may come before the guard. + $before = preg_replace('/^\s*(<\?php|use [\w\\\\]+;|chdir\(\'[^\']*\'\);|include(_once)?\(\'[^\']*\'\);)\s*$/m', '', substr($code, 0, (int) $guard)); + + expect(trim((string) $before))->toBe('', $page); + } +}); + it('ships the node read script with its SPDX header after the shebang', function () { $lines = file(pfs_root() . '/node/pfs-read.sh', FILE_IGNORE_NEW_LINES) ?: [];