From fc46e677b9a9c61c13907901601ea983a72c5b39 Mon Sep 17 00:00:00 2001 From: Mkkbeydoun Date: Tue, 13 Oct 2026 13:54:01 -0400 Subject: [PATCH] Keep synced guides readable when the scheduler runs as root, release 1.0.1 --- CHANGELOG.md | 4 ++++ extension.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/Services/GuideSync.php | 36 ++++++++++++++++++++++++++++++++++++ tests/guides.php | 13 +++++++++++++ 6 files changed, 57 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be79461..f9f1a5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.0.1 + +- Fixed guides breaking after the first scheduled sync on a standard install. The panel's scheduler runs from root's crontab, so the synced copy was owned by root and the web server could not read it ("Permission denied" on Sync now). Synced files now belong to the same user as the panel's storage folder. After updating, the next scheduled sync fixes the folder on its own. + ## 1.0.0 - First release: a Guides tab on every server with help articles for its game, grouped into general guides and the ones for the server's mod framework, with the server's name, address, IP, port and domain filled in. Guides come from the community repo (Rustix-Development/pterodactyl-egg-guides) and any GitHub repos you add above it, public or private, synced on a schedule into the panel's own copy. An admin page lists the repos, sync status and skipped files, and lets you pin a guide folder to any egg or turn guides off for it. Subusers need the new **View guides** permission. diff --git a/extension.json b/extension.json index 64cdf2d..832b48b 100644 --- a/extension.json +++ b/extension.json @@ -2,7 +2,7 @@ "$schema": "./node_modules/@pterodactyl/sdk/manifest.schema.json", "id": "guides", "name": "Server Guides", - "version": "1.0.0", + "version": "1.0.1", "description": "A Guides tab on every server with help articles for its game and mod framework, synced from GitHub repos the community writes together.", "author": "RustixDev", "icon": "book-open", diff --git a/package-lock.json b/package-lock.json index 42b0997..9082752 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "guides", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "guides", - "version": "1.0.0", + "version": "1.0.1", "devDependencies": { "@base-ui/react": "^1.6.0", "@pterodactyl/sdk": "file:./sdk/pterodactyl-sdk-2.0.0-beta.4.tgz", diff --git a/package.json b/package.json index e5bf05d..2b56c52 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "guides", "private": true, - "version": "1.0.0", + "version": "1.0.1", "type": "module", "scripts": { "build": "vite build", diff --git a/src/Services/GuideSync.php b/src/Services/GuideSync.php index c933e47..58d4ddc 100644 --- a/src/Services/GuideSync.php +++ b/src/Services/GuideSync.php @@ -91,6 +91,7 @@ public function syncRepo(Repo $repo): string { $root = self::root(); File::ensureDirectoryExists($root, 0750); + self::matchStorageOwner($root); $archive = $root.DIRECTORY_SEPARATOR.'download-'.Str::lower(Str::random(16)).'.zip'; $name = Str::lower(Str::random(20)); $target = $root.DIRECTORY_SEPARATOR.$name; @@ -100,6 +101,7 @@ public function syncRepo(Repo $repo): string $this->source->download($repo->repo, $repo->branch, $repo->token, $archive); $revision = ArchiveExtractor::revision($archive); $problems = $this->extractor->extract($archive, $target); + self::matchStorageOwner($target); $parsed = $this->parser->parse($target); $problems = array_slice([...$problems, ...$parsed['problems']], 0, self::MAX_PROBLEMS); @@ -149,6 +151,40 @@ public function syncRepo(Repo $repo): string } } + /** + * The panel's scheduler usually runs from root's crontab, while the web server + * reads the synced copy as its own user. Files written by root would then be + * unreadable to the panel, so hand them to whoever owns storage/app. + */ + public static function matchStorageOwner(string $path): void + { + if (! function_exists('posix_geteuid') || posix_geteuid() !== 0 || ! file_exists($path)) { + return; + } + $owner = @fileowner(storage_path('app')); + $group = @filegroup(storage_path('app')); + if ($owner === false || $group === false || $owner === 0) { + return; + } + + $paths = [$path]; + if (is_dir($path)) { + $items = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), + \RecursiveIteratorIterator::SELF_FIRST, + ); + foreach ($items as $item) { + if (! $item->isLink()) { + $paths[] = $item->getPathname(); + } + } + } + foreach ($paths as $item) { + @chown($item, $owner); + @chgrp($item, $group); + } + } + /** Copies no repo points at any more: removed repos, or a sync that died halfway. */ private function removeStaleCopies(): void { diff --git a/tests/guides.php b/tests/guides.php index 53b4df4..4bb5ac8 100644 --- a/tests/guides.php +++ b/tests/guides.php @@ -309,6 +309,19 @@ function throws(callable $fn, ?string $contains = null): bool check('sync: only one at a time', throws(fn () => $sync->syncAll(), 'already running')); $lock->release(); +// Run as root (cron) with storage owned by the web user: synced files must end up the web user's. +if (function_exists('posix_geteuid') && posix_geteuid() === 0 && ($web = posix_getpwnam('www-data')) !== false) { + chown($tmp.'/storage/app', $web['uid']); + $sync->syncRepo($host->fresh()->forceFill(['repo' => 'myhost/host-guides'])); + $copy = (string) GuideSync::directory($host->fresh()); + $owners = [fileowner(GuideSync::root()), fileowner($copy)]; + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($copy, FilesystemIterator::SKIP_DOTS)) as $item) { + $owners[] = $item->getOwner(); + } + check('sync as root: files belong to the storage owner', array_unique($owners) === [$web['uid']], json_encode(array_unique($owners))); + chown($tmp.'/storage/app', 0); +} + EggRule::query()->create(['egg_id' => 1, 'mode' => 'off']); check('egg rules are read', GuideCatalog::ruleFor(1) === ['mode' => 'off', 'folder' => null] && GuideCatalog::ruleFor(2) === null);