You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/PanelBootstrapPermissionCon...

49 lines
2.1 KiB
PHP

<?php
// Static contract: the PHP panel bootstrap must not turn a configuration
// permission *audit* into a process-start gate. The web server still needs
// ordinary OS read permission to execute the selected PHP config file; this
// test only protects against adding a second mode/owner preflight that makes
// liveness depend on 0600/0700 bits. Secret-producing write paths keep their
// private-file guarantees and are tested separately by CloudSetup contracts.
$root = dirname(__DIR__);
$bootstrapPath = $root . '/bootstrap.php';
$bootstrap = file_get_contents($bootstrapPath);
if ($bootstrap === false) {
throw new RuntimeException('PHP panel bootstrap is missing or unreadable.');
}
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$assert(str_contains($bootstrap, "BASE_PATH . '/config/config.php'"),
'The primary panel config path is no longer selected.');
$assert(str_contains($bootstrap, "BASE_PATH . '/config/.config.php'"),
'The example/fallback panel config path is no longer selected.');
$assert(str_contains($bootstrap, 'require $configurationFile;'),
'The selected panel config is not loaded by the bootstrap.');
// These checks are intentionally limited to permission/ownership probes. A
// structural is_file() fallback check is fine; it does not reject a mode.
foreach ([
'fileperms(', 'stat(', 'lstat(', 'is_readable(', 'is_writable(',
'posix_geteuid(', 'posix_getpwuid(', 'chmod(', 'chown(',
'private_config(', 'CLOUD_ENGINE_CONFIG', 'cloud_engine_config_file',
] as $forbidden) {
$assert(!str_contains($bootstrap, $forbidden),
'Panel bootstrap added a configuration permission/startup gate: ' . $forbidden);
}
// The PHP panel must not load the retired Python engine configuration as part
// of its own liveness path. Agent enrollment/credentials are separate
// control-plane operations.
$assert(!str_contains($bootstrap, "engine.json")
&& !str_contains($bootstrap, 'create_engine'),
'Panel liveness unexpectedly depends on the retired Python engine config.');
echo "Panel bootstrap permission/liveness boundary passed.\n";