Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/decisions/0009-command-allowlist-and-privileges.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 0009. Run three allowlisted tools with fixed arguments; no smpquery, no sudo, no ibdiagnet

Status: Accepted (2026-11-15)
Status: Accepted (2026-11-15); allowlisted tool files added to the sweep check (2026-11-19)

## Context

Expand All @@ -19,7 +19,7 @@ Status: Accepted (2026-11-15)
- A test enumerates every vector the builder produces.
- Commands run without a shell. They run with `PATH` and `LC_ALL` only, from `/`, with standard input from `/dev/null`, and with a time and output limit. Output that is cut short is never parsed. A failure is recorded as an error, never as a zero.
- No `smpquery`. A link below best is reported as below best with the cause unknown, and its degraded value is unknown (`U`) until the UFM backend supplies enabled values.
- `sudo` is never used and never documented. The documented grant is a dedicated group with mode 0660 on `umad*`. The plugin records on its health page when it runs as root, set-ID, from a tool directory others can write to, or with a world-accessible UMAD node. The tool directory itself must be an absolute, canonical path to a real directory with no symbolic link in it, owned by root, and writable by neither group nor others. The settings form refuses any other directory, and each sweep checks it again and runs nothing when it fails.
- `sudo` is never used and never documented. The documented grant is a dedicated group with mode 0660 on `umad*`. The plugin records on its health page when it runs as root, set-ID, from a tool directory others can write to, or with a world-accessible UMAD node. The tool directory itself must be an absolute, canonical path to a real directory with no symbolic link in it, owned by root, and writable by neither group nor others. The settings form refuses any other directory, and each sweep checks it again and runs nothing when it fails. Each allowlisted tool present in it must also be owned by root, writable by neither group nor others, and not set-ID; a sweep that finds one that is not runs nothing, because whoever can write the file chooses what the poller runs. The health page still records these conditions as warnings.
- `ibdiagnet` is excluded from phases 1 to 3.

## Consequences
Expand Down
7 changes: 4 additions & 3 deletions lib/PrivilegeProbe.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@

/**
* Why no tool may run from the directory, checked again before every
* sweep because the directory can change after the setting was saved.
* Null when it passes ToolDirectory's checks.
* sweep because the directory or a tool can change after the setting was
* saved. Null when the directory and every allowlisted tool in it pass
* ToolDirectory's checks.
*/
public function refusal(): ?string {
return ToolDirectory::problem($this->toolDir, $this->toolOwner);
return ToolDirectory::problem($this->toolDir, $this->toolOwner) ?? ToolDirectory::toolProblem($this->toolDir, $this->toolOwner);

Check warning on line 48 in lib/PrivilegeProbe.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Split this 130 characters long line (which is greater than 120 authorized).

See more on https://sonarcloud.io/project/issues?id=somethingwithproof_plugin_fabric&issues=AaH3LCMzcQKH9g0IeaZz&open=AaH3LCMzcQKH9g0IeaZz&pullRequest=81
}

/**
Expand Down
50 changes: 43 additions & 7 deletions lib/ToolDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* writable by neither its group nor others.
*/
final class ToolDirectory {
public const CODES = ['path', 'missing', 'symlink', 'owner', 'writable'];
public const CODES = ['path', 'missing', 'symlink', 'owner', 'writable', 'tool_owner', 'tool_writable', 'tool_setid'];

/**
* @param int $owner the required owner; root except in tests, which
Expand Down Expand Up @@ -64,14 +64,50 @@
return ($stat['mode'] & 0o022) !== 0 ? 'writable' : null;
}

/**
* The first check an allowlisted tool inside the directory fails, or
* null. A directory that passes still lets a tool be replaced in place
* by whoever can write the file, and a set-ID tool runs as someone else.
* A tool that does not exist is not a problem here; running it fails
* and is recorded as such. A symbolic link is judged by its target.
*/
public static function toolProblem(string $dir, int $owner = 0): ?string {

Check warning on line 74 in lib/ToolDirectory.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this open curly brace to the beginning of the next line.

See more on https://sonarcloud.io/project/issues?id=somethingwithproof_plugin_fabric&issues=AaH3LCK2cQKH9g0IeaZy&open=AaH3LCK2cQKH9g0IeaZy&pullRequest=81
foreach (Tool::cases() as $tool) {
$path = $dir . '/' . $tool->value;

clearstatcache(true, $path);

if (!is_file($path) || ($stat = stat($path)) === false) {
continue;
}

if ($stat['uid'] !== $owner) {
return 'tool_owner';
}

if (($stat['mode'] & 0o022) !== 0) {
return 'tool_writable';
}

if (($stat['mode'] & 0o6000) !== 0) {
return 'tool_setid';
}
}

return null;
}

public static function message(string $code): string {
return match ($code) {
'path' => __('The tool directory must be an absolute path of letters, digits, dots, dashes, underscores, and slashes, with no trailing slash.', 'fabric'),
'missing' => __('The tool directory does not exist or is not a directory.', 'fabric'),
'symlink' => __('The tool directory path contains a symbolic link. Enter the real path.', 'fabric'),
'owner' => __('The tool directory is not owned by root.', 'fabric'),
'writable' => __('The tool directory can be written by its group or by others.', 'fabric'),
default => __('Unknown warning', 'fabric'),
'path' => __('The tool directory must be an absolute path of letters, digits, dots, dashes, underscores, and slashes, with no trailing slash.', 'fabric'),
'missing' => __('The tool directory does not exist or is not a directory.', 'fabric'),
'symlink' => __('The tool directory path contains a symbolic link. Enter the real path.', 'fabric'),
'owner' => __('The tool directory is not owned by root.', 'fabric'),
'writable' => __('The tool directory can be written by its group or by others.', 'fabric'),
'tool_owner' => __('A diagnostics tool is not owned by root.', 'fabric'),
'tool_writable' => __('A diagnostics tool can be written by its group or by others.', 'fabric'),
'tool_setid' => __('A diagnostics tool has the setuid or setgid bit. The plugin never needs it.', 'fabric'),
default => __('Unknown warning', 'fabric'),
};
}
}
Binary file modified locales/LC_MESSAGES/ar-SA.mo
Binary file not shown.
Binary file modified locales/LC_MESSAGES/es-419.mo
Binary file not shown.
Binary file modified locales/LC_MESSAGES/es-ES.mo
Binary file not shown.
Binary file modified locales/LC_MESSAGES/hi-IN.mo
Binary file not shown.
Binary file modified locales/LC_MESSAGES/zh-CN.mo
Binary file not shown.
10 changes: 9 additions & 1 deletion locales/po/ar-SA.po
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ msgstr "عرض Fabric"
msgid "The sweep runs as root. Run the poller as an unprivileged account with read access to the umad devices through a group."
msgstr "يعمل الفحص بصلاحيات root. شغّل المُستطلِع بحساب غير ذي امتيازات يملك حق قراءة أجهزة umad عبر مجموعة."

#: lib/PrivilegeProbe.php
#: lib/PrivilegeProbe.php lib/ToolDirectory.php
msgid "A diagnostics tool has the setuid or setgid bit. The plugin never needs it."
msgstr "تحتوي إحدى أدوات التشخيص على بت setuid أو setgid. لا تحتاج الإضافة إليهما مطلقًا."

Expand Down Expand Up @@ -957,6 +957,14 @@ msgstr "دليل الأدوات غير مملوك لـ root."
msgid "The tool directory can be written by its group or by others."
msgstr "يمكن للمجموعة أو للآخرين الكتابة إلى دليل الأدوات."

#: lib/ToolDirectory.php
msgid "A diagnostics tool is not owned by root."
msgstr "إحدى أدوات التشخيص غير مملوكة لـ root."

#: lib/ToolDirectory.php
msgid "A diagnostics tool can be written by its group or by others."
msgstr "يمكن للمجموعة أو للآخرين الكتابة إلى إحدى أدوات التشخيص."

#: setup.php
#, php-format
msgid "The Fabric plugin requires PHP %s or later. This server runs PHP %s, so the plugin was not installed or enabled."
Expand Down
10 changes: 9 additions & 1 deletion locales/po/cacti.pot
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ msgstr ""
msgid "The sweep runs as root. Run the poller as an unprivileged account with read access to the umad devices through a group."
msgstr ""

#: lib/PrivilegeProbe.php
#: lib/PrivilegeProbe.php lib/ToolDirectory.php
msgid "A diagnostics tool has the setuid or setgid bit. The plugin never needs it."
msgstr ""

Expand Down Expand Up @@ -959,6 +959,14 @@ msgstr ""
msgid "The tool directory can be written by its group or by others."
msgstr ""

#: lib/ToolDirectory.php
msgid "A diagnostics tool is not owned by root."
msgstr ""

#: lib/ToolDirectory.php
msgid "A diagnostics tool can be written by its group or by others."
msgstr ""

#: setup.php
#, php-format
msgid "The Fabric plugin requires PHP %s or later. This server runs PHP %s, so the plugin was not installed or enabled."
Expand Down
10 changes: 9 additions & 1 deletion locales/po/es-419.po
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ msgstr "Vista de Fabric"
msgid "The sweep runs as root. Run the poller as an unprivileged account with read access to the umad devices through a group."
msgstr "La consulta se ejecuta como root. Ejecute el sondeador con una cuenta sin privilegios que tenga acceso de lectura a los dispositivos umad mediante un grupo."

#: lib/PrivilegeProbe.php
#: lib/PrivilegeProbe.php lib/ToolDirectory.php
msgid "A diagnostics tool has the setuid or setgid bit. The plugin never needs it."
msgstr "Una herramienta de diagnóstico tiene el bit setuid o setgid. El complemento nunca lo necesita."

Expand Down Expand Up @@ -957,6 +957,14 @@ msgstr "El directorio de herramientas no pertenece a root."
msgid "The tool directory can be written by its group or by others."
msgstr "El grupo u otros usuarios pueden escribir en el directorio de herramientas."

#: lib/ToolDirectory.php
msgid "A diagnostics tool is not owned by root."
msgstr "Una herramienta de diagnóstico no pertenece a root."

#: lib/ToolDirectory.php
msgid "A diagnostics tool can be written by its group or by others."
msgstr "El grupo u otros usuarios pueden escribir en una herramienta de diagnóstico."

#: setup.php
#, php-format
msgid "The Fabric plugin requires PHP %s or later. This server runs PHP %s, so the plugin was not installed or enabled."
Expand Down
10 changes: 9 additions & 1 deletion locales/po/es-ES.po
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ msgstr "Vista de Fabric"
msgid "The sweep runs as root. Run the poller as an unprivileged account with read access to the umad devices through a group."
msgstr "La consulta se ejecuta como root. Ejecute el sondeador con una cuenta sin privilegios que tenga acceso de lectura a los dispositivos umad mediante un grupo."

#: lib/PrivilegeProbe.php
#: lib/PrivilegeProbe.php lib/ToolDirectory.php
msgid "A diagnostics tool has the setuid or setgid bit. The plugin never needs it."
msgstr "Una herramienta de diagnóstico tiene el bit setuid o setgid. El complemento nunca lo necesita."

Expand Down Expand Up @@ -957,6 +957,14 @@ msgstr "El directorio de herramientas no pertenece a root."
msgid "The tool directory can be written by its group or by others."
msgstr "El grupo u otros usuarios pueden escribir en el directorio de herramientas."

#: lib/ToolDirectory.php
msgid "A diagnostics tool is not owned by root."
msgstr "Una herramienta de diagnóstico no pertenece a root."

#: lib/ToolDirectory.php
msgid "A diagnostics tool can be written by its group or by others."
msgstr "El grupo u otros usuarios pueden escribir en una herramienta de diagnóstico."

#: setup.php
#, php-format
msgid "The Fabric plugin requires PHP %s or later. This server runs PHP %s, so the plugin was not installed or enabled."
Expand Down
10 changes: 9 additions & 1 deletion locales/po/hi-IN.po
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ msgstr "Fabric दृश्य"
msgid "The sweep runs as root. Run the poller as an unprivileged account with read access to the umad devices through a group."
msgstr "सर्वेक्षण root के रूप में चलता है। पोलर को ऐसे गैर-विशेषाधिकार खाते से चलाएँ जिसे समूह के माध्यम से umad डिवाइस पढ़ने की अनुमति हो।"

#: lib/PrivilegeProbe.php
#: lib/PrivilegeProbe.php lib/ToolDirectory.php
msgid "A diagnostics tool has the setuid or setgid bit. The plugin never needs it."
msgstr "किसी निदान उपकरण पर setuid या setgid बिट सेट है। प्लगइन को इसकी कभी आवश्यकता नहीं होती।"

Expand Down Expand Up @@ -957,6 +957,14 @@ msgstr "उपकरण निर्देशिका का स्वामी
msgid "The tool directory can be written by its group or by others."
msgstr "उपकरण निर्देशिका को उसका समूह या अन्य उपयोगकर्ता लिख सकते हैं।"

#: lib/ToolDirectory.php
msgid "A diagnostics tool is not owned by root."
msgstr "कोई निदान उपकरण root के स्वामित्व में नहीं है।"

#: lib/ToolDirectory.php
msgid "A diagnostics tool can be written by its group or by others."
msgstr "किसी निदान उपकरण को उसका समूह या अन्य उपयोगकर्ता लिख सकते हैं।"

#: setup.php
#, php-format
msgid "The Fabric plugin requires PHP %s or later. This server runs PHP %s, so the plugin was not installed or enabled."
Expand Down
10 changes: 9 additions & 1 deletion locales/po/zh-CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ msgstr "Fabric 查看"
msgid "The sweep runs as root. Run the poller as an unprivileged account with read access to the umad devices through a group."
msgstr "扫描以 root 身份运行。请使用非特权账户运行采集器,并通过组授予其 umad 设备读取权限。"

#: lib/PrivilegeProbe.php
#: lib/PrivilegeProbe.php lib/ToolDirectory.php
msgid "A diagnostics tool has the setuid or setgid bit. The plugin never needs it."
msgstr "某个诊断工具设置了 setuid 或 setgid 位。插件永远不需要这些位。"

Expand Down Expand Up @@ -957,6 +957,14 @@ msgstr "工具目录不属于 root。"
msgid "The tool directory can be written by its group or by others."
msgstr "工具目录可由其所属组或其他用户写入。"

#: lib/ToolDirectory.php
msgid "A diagnostics tool is not owned by root."
msgstr "某个诊断工具的所有者不是 root。"

#: lib/ToolDirectory.php
msgid "A diagnostics tool can be written by its group or by others."
msgstr "某个诊断工具可由其所属组或其他用户写入。"

#: setup.php
#, php-format
msgid "The Fabric plugin requires PHP %s or later. This server runs PHP %s, so the plugin was not installed or enabled."
Expand Down
13 changes: 12 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,22 @@
$menu[__('Management')]['plugins/fabric/' . $file] = $title;
}

if (in_array(get_current_page(), \Somethingwithproof\Fabric\Pages::upgradeTriggers(), true)) {
if (fabric_repair_on_page(get_current_page())) {
plugin_fabric_upgrade();
}
}

/**
* Whether config_arrays may repair the install on this page. Core fires
* config_arrays before include/auth.php checks the session, so a request
* that is about to be redirected to the login page gets here too. Only a
* request that already carries a user may start the migrations and the
* template import; an anonymous one leaves them to the next page load.
*/
function fabric_repair_on_page(string $page): bool {

Check warning on line 336 in setup.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this open curly brace to the beginning of the next line.

See more on https://sonarcloud.io/project/issues?id=somethingwithproof_plugin_fabric&issues=AaH3LCNacQKH9g0IeaZ0&open=AaH3LCNacQKH9g0IeaZ0&pullRequest=81

Check warning on line 336 in setup.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename function "fabric_repair_on_page" to match the regular expression ^[a-z][a-zA-Z0-9]*$.

See more on https://sonarcloud.io/project/issues?id=somethingwithproof_plugin_fabric&issues=AaH3LCNacQKH9g0IeaZ1&open=AaH3LCNacQKH9g0IeaZ1&pullRequest=81
return !empty($_SESSION['sess_user_id']) && in_array($page, \Somethingwithproof\Fabric\Pages::upgradeTriggers(), true);
}

function fabric_config_settings(): void {
global $tabs, $settings;

Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/BootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,25 @@
'device_remove' => 'fabric_device_remove',
]);
});

// core fires config_arrays before auth.php checks the session
it('repairs the install from config_arrays only for a request that carries a user', function () {
$saved = $_SESSION ?? null;

try {
$_SESSION = [];
expect(fabric_repair_on_page('plugins.php'))->toBeFalse()
->and(fabric_repair_on_page('fabric.php'))->toBeFalse();

$_SESSION = ['sess_user_id' => 3];
expect(fabric_repair_on_page('plugins.php'))->toBeTrue()
->and(fabric_repair_on_page('fabric.php'))->toBeTrue()
->and(fabric_repair_on_page('graphs.php'))->toBeFalse();
} finally {
if ($saved === null) {
unset($_SESSION);
} else {
$_SESSION = $saved;
}
}
});
32 changes: 32 additions & 0 deletions tests/Unit/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,38 @@
}
});

it('refuses a tool that is not root-owned, is writable by group or others, or is set-ID', function () {
$scratch = new Somethingwithproof\Fabric\Tests\Scratch();

try {
$dir = (string) realpath($scratch->dir);
$owner = (int) fileowner($dir);
chmod($dir, 0755);
$tool = $scratch->file('perfquery', '#!/bin/sh', 0755);

$probe = new Somethingwithproof\Fabric\PrivilegeProbe($dir, toolOwner: $owner);

// An absent tool is not a refusal; running it fails and is recorded.
expect($probe->refusal())->toBeNull();

foreach ([0775 => 'tool_writable', 0757 => 'tool_writable', 04755 => 'tool_setid', 02755 => 'tool_setid', 0755 => null] as $mode => $code) {
chmod($tool, $mode);
expect($probe->refusal())->toBe($code);
}

expect((new Somethingwithproof\Fabric\PrivilegeProbe($dir, toolOwner: $owner + 1))->refusal())->toBe('owner');

// The directory passes for its owner; the tool is judged on its own owner.
expect(ToolDirectory::toolProblem($dir, $owner + 1))->toBe('tool_owner');

$scratch->file('iblinkinfo', '#!/bin/sh', 0777);
chmod($tool, 0755);
expect($probe->refusal())->toBe('tool_writable');
} finally {
$scratch->remove();
}
});

it('reads settings with defaults, bounds, and safe paths', function () {
$defaults = Settings::fromRow([]);

Expand Down