fix(core,admin_basic): 정적 게시 재게시 누락 3건 수정 + 관리자 수동 복구 UI + sudo core:update 소유권 정합

- 템플릿 update 는 레이아웃 변경 여부와 무관하게 캐시 버전을 올리고(실패 복원 뒤에도), 자산 주소 방식 전환 3경로도 bump 한다
- config:cache 가 컨테이너 인스턴스를 덮어 이후 terminating 재게시가 사라지던 결함을 복원 헬퍼로 차단
- custom/ 변경 감지와 게시가 같은 열거자(재귀·크기 포함)를 쓰고, 서명은 호스트별로 저장
- 캐시 버전·서명 키를 만료시키지 않는다(기본 TTL 24h 로 매일 전체 재생성되던 문제)
- 관리자 > 환경설정 > 일반 「초기 화면 정적 파일」 카드: 상태 조회 + 지금 다시 만들기(확인 모달), 대시보드 알림 버튼 연결, CLI 와 같은 statusReport 소비
- sudo core:update 경로의 root 소유 잔존(설정 디렉토리·임시 폴더·로그·업그레이드 마이그레이션 산출물) 상속·정합화, ext-static 명령 root 경고와 sudo -u 힌트
- 안내·문서·트러블슈팅 4건·audit 룰 ext-cache-version-raw-read·ja 언어팩 동기
This commit is contained in:
HeuJung committed 2026-09-06 15:22:52 +09:00
1 parent d263f74cae
commit de18159986
105 files changed
+4055 -208

No files matched your search

+6
View File
@@ -2215,6 +2215,12 @@ class CoreUpdateService
storage_path('framework/cache'),
base_path('bootstrap/cache'),
storage_path('app/ext-bundles'),
// 확장 업데이트의 다운로드·추출 임시 폴더. 부모 `storage/app/temp` 가 sudo 업데이트에서 root 로
// 최초 생성되면 이후 관리자 화면의 확장 업데이트가 임시 폴더를 만들지 못한다 (#651 F14).
storage_path('app/temp'),
// `restore_ownership` 은 `storage/logs` 를 포함하지만 그 복원은 흐름 **중간**(Step 11)이라,
// 그 뒤에 만들어지는 daily 롤오버·신규 로그 파일은 root 로 남는다 (#651 F15).
storage_path('logs'),
];
foreach ($targets as $dir) {
+22 -4
View File
@@ -2,8 +2,8 @@
namespace App\Services;
use App\Contracts\Extension\CacheInterface;
use App\Exceptions\CustomAssetOperationException;
use App\Extension\Helpers\FilePermissionHelper;
use App\Extension\HookManager;
use App\Extension\Traits\ClearsTemplateCaches;
use App\Rules\AllowedTemplateFileType;
@@ -279,7 +279,9 @@ class CustomAssetService
CustomAssets::flushCache();
try {
app(CacheInterface::class)->forget(CustomAssets::SIGNATURE_CACHE_KEY);
// 서명을 쓰는 뷰 컴포저와 **같은 통로**(고정 스토어·코어 네임스페이스)로 지운다 —
// 다른 통로로 지우면 그쪽 서명이 남아 다음 렌더가 같은 변경을 한 번 더 bump 한다.
self::customSignatureCache()->forget(CustomAssets::SIGNATURE_CACHE_KEY);
} catch (\Exception $e) {
Log::warning('사용자 추가 에셋 서명 캐시 삭제 실패', ['error' => $e->getMessage()]);
}
@@ -385,8 +387,24 @@ class CustomAssetService
return;
}
if (! @mkdir($directory, 0755, true) && ! is_dir($directory)) {
throw new CustomAssetOperationException('custom_assets.errors.directory_failed', ['path' => $directory]);
// 확보는 코어 공통 프리미티브가 맡는다 — 소유권 상속·그룹 쓰기까지 정합화하고, 실패는 예외가 아니라
// 사유로 올라온다. `custom/` 은 지연 생성이라 `deploy:deploy 0755` 로 배포된 확장 디렉토리에서
// 첫 저장이 여기서 실패하는데, 경로만 적으면 운영자가 무엇을 고쳐야 하는지 알 수 없다(#651 D6).
// 사유·소유자·권한·실행 계정·조치 예시를 함께 싣는다 (정적 게시 프리플라이트와 같은 식).
if (FilePermissionHelper::ensureWritableDirectory($directory, 0775, $failure)) {
return;
}
$failedPath = (string) ($failure['path'] ?? $directory);
$reason = (string) ($failure['reason'] ?? 'create_failed');
throw new CustomAssetOperationException('custom_assets.errors.directory_failed', [
'path' => $directory,
'reason' => __('custom_assets.errors.reason.'.$reason),
'owner' => (string) (@fileowner($failedPath) ?: 'unknown'),
'perms' => file_exists($failedPath) ? substr(sprintf('%o', @fileperms($failedPath)), -4) : 'absent',
'process_user' => ExtensionStaticCacheService::currentProcessUser(),
'hint' => __('custom_assets.errors.directory_failed_hint', ['path' => $failedPath]),
]);
}
}
+206 -10
View File
@@ -531,6 +531,166 @@ class ExtensionStaticCacheService
return (bool) config('core.static_cache.enabled', true);
}
/**
* 지금 이 설치에서 게시가 의미 있는지 판정합니다 — kill-switch 켜짐 + 프로덕션.
*
* `publishCurrent()` 자체에는 환경 게이트가 없다(명시적 `ext-static:publish` 가 어느 환경에서든
* 돌 수 있어야 하므로). 환경 판정은 자가 치유(`AssetUrl::staticExtBase`)와 terminating 예약
* (`schedulePublishOnTerminate`)에만 있었는데, 관리자 화면의 수동 복구는 두 판정을 **한 값**으로
* 보여 줘야 하므로 여기서 묶는다. 비프로덕션은 blade 가 정적 URL 을 방출하지 않아 게시해도
* 아무도 참조하지 않는다.
*
* @return bool 게시가 실제로 쓰이는 환경이면 true
*/
public function isPublishable(): bool
{
return $this->isEnabled() && app()->environment('production');
}
/**
* 게시 상태 보고서 — CLI(`ext-static:status`)·관리자 API·화면이 **같은 판정**을 소비한다.
*
* 판정을 소비처마다 다시 쓰면 한 곳만 어긋나도 서로 다른 답을 내놓는다(`TrustedProxyDiagnostic`
* 이 CLI·대시보드·API 에 같은 판정을 공급하는 것과 같은 패턴). 문구·힌트는 소비처가 정한다.
*
* @return array{
* enabled: bool,
* publishable: bool,
* environment: string,
* version: int,
* published: bool,
* files: int,
* published_at: string|null,
* tree_writable: bool,
* process_user: string,
* failure: array{version:int, at:string, reason:string, count:int, message:string}|null,
* retained_versions: array<int, int>
* } 상태 보고서
*/
public function statusReport(): array
{
$version = self::getExtensionCacheVersion();
$base = $this->baseDir();
unset($this->publishedMemo[$version]);
$published = $this->isPublished($version);
$files = 0;
$publishedAt = null;
if ($published) {
$manifest = json_decode((string) @file_get_contents($this->versionDir($version).DIRECTORY_SEPARATOR.self::MANIFEST_FILE), true);
if (is_array($manifest)) {
$files = count($manifest['files'] ?? []);
$publishedAt = is_string($manifest['published_at'] ?? null) ? $manifest['published_at'] : null;
}
}
return [
'enabled' => $this->isEnabled(),
'publishable' => $this->isPublishable(),
'environment' => (string) app()->environment(),
'version' => $version,
'published' => $published,
'files' => $files,
'published_at' => $publishedAt,
'tree_writable' => $this->isPublishTreeWritable($base),
'process_user' => self::currentProcessUser(),
'failure' => self::failureMarker(),
'retained_versions' => $this->publishedVersions($base),
];
}
/**
* 관리자 수동 복구 — 캐시 버전을 올리고 현재 버전을 **강제** 재게시합니다.
*
* 자동 경로(수명주기 bump → terminating 게시 · blade 자가 치유)가 놓친 갱신을 운영자가 즉시
* 되돌리는 통로다. 캐시 버전이 만료로 재생성되지 않으므로(`PERSISTENT_TTL_SECONDS`) 재게시
* 누락은 무기한 stale 이 되는데, 이 복구가 그 안전망이다.
*
* - 게시가 쓰이지 않는 환경(kill-switch 꺼짐 / 비프로덕션)이면 bump 하지 않고 사유만 돌려준다.
* - `force: true` 가 필수다 — 직전 게시와 같은 초면 버전이 같아 manifest 존재로 skip 되어
* 아무것도 다시 만들지 않는다.
* - 게시 실패는 예외가 아니라 결과다(`republished=false` + 실패 마커). 사이트는 API 폴백으로 정상.
* - 715파일·40MB 복사 + 번들 재병합이 웹 요청 안에서 돈다 — 게시 락 TTL(300초)만큼 실행 시간을
* 확보하고, 클라이언트가 끊어도 게시는 끝낸다(중간에 죽으면 `.tmp` 만 남고 다음 GC 가 치운다).
*
* @return array<string, mixed> `republished`·`version_changed`·`previous_version` + `statusReport()`
*/
public function republish(): array
{
$previous = self::getExtensionCacheVersion();
if (! $this->isPublishable()) {
return [
'republished' => false,
'version_changed' => false,
'previous_version' => $previous,
'reason' => $this->isEnabled() ? 'not_production' : 'disabled',
] + $this->statusReport();
}
@set_time_limit(300);
@ignore_user_abort(true);
$this->incrementExtensionCacheVersion();
$republished = $this->publishCurrent(force: true);
$current = self::getExtensionCacheVersion();
return [
'republished' => $republished,
'version_changed' => $current !== $previous,
'previous_version' => $previous,
'reason' => $republished ? null : (self::failureMarker()['reason'] ?? 'publish_failed'),
] + $this->statusReport();
}
/**
* 게시 트리에 쓸 수 있는지(없으면 만들 수 있는지) 판정합니다.
*
* @param string $base 게시 루트 절대 경로
* @return bool 쓰기 가능 여부
*/
private function isPublishTreeWritable(string $base): bool
{
if (File::isDirectory($base)) {
return is_writable($base);
}
$parent = dirname($base);
return File::isDirectory($parent) && is_writable($parent);
}
/**
* 게시 루트에 남아 있는 버전 디렉토리 목록을 반환합니다 (오름차순).
*
* @param string $base 게시 루트 절대 경로
* @return array<int, int> 버전 목록
*/
private function publishedVersions(string $base): array
{
if (! File::isDirectory($base)) {
return [];
}
$versions = [];
foreach (File::directories($base) as $dir) {
$name = basename($dir);
if (ctype_digit($name)) {
$versions[] = (int) $name;
}
}
sort($versions);
return $versions;
}
/**
* 한 버전의 게시를 실제 수행합니다 (tmp 쓰기 → rename → manifest → GC).
*
@@ -556,6 +716,10 @@ class ExtensionStaticCacheService
File::deleteDirectory($tmp);
$this->makeDirectory($tmp);
// custom 열거 메모를 비우고 디스크를 다시 읽는다 — 게시는 요청 뒤(terminating)나 장수 프로세스에서
// 돌 수 있어, 앉아 있는 메모가 이미 지워진 파일을 가리키면 복사가 실패해 게시 전체가 중단된다.
CustomAssets::flushCache();
$files = [];
$this->writeHtaccess($tmp, $files);
@@ -909,17 +1073,48 @@ class ExtensionStaticCacheService
// URL 은 **public 아래 실제 파일일 때만** 200 이 되므로, 문서가 안내하는
// "폰트·이미지를 custom/ 에 두고 상대 경로로 참조" 를 성립시키는 방법은 게시뿐이다.
//
// 갱신 축은 확장 자산과 동일하다 — 운영자가 파일을 고치면 `CustomAssets` 가
// 갱신 축은 확장 자산과 동일하다 — 운영자가 파일을 고치면 `CollectsCustomAssets` 가
// 그것을 감지해 `ext.cache_version` 을 올리고, 그 단일 지점이 재게시까지 예약한다.
$this->publishDistAssets(
base_path("templates/{$identifier}/".CustomAssets::DIRECTORY),
// 게시 집합은 감지와 **같은 열거자**(`CustomAssets::publishableFiles`)가 정한다.
$this->publishCustomAssets(
'templates',
$identifier,
$templateDir.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.CustomAssets::DIRECTORY,
$files,
$tmp,
excludeCustom: false
$tmp
);
}
/**
* 확장 하나의 운영자 소유 디렉토리(`custom/`)를 게시합니다.
*
* 파일 집합은 `CustomAssets::publishableFiles()` 가 정한다 — 변경 감지(`CollectsCustomAssets`)
* 와 같은 열거자다. 게시와 감지가 서로 다른 코드로 범위를 정하면 어긋나고, 그 어긋남은
* "글꼴을 바꿨는데 반영되지 않는다" 로만 나타난다(#651 F7).
*
* @param string $extensionType `templates` | `modules` | `plugins`
* @param string $identifier 확장 식별자
* @param string $targetDir 게시 대상 절대 경로 (`…/assets/custom`)
* @param array<string> $files 기록된 상대 경로 누적 (참조)
* @param string $tmp tmp 루트 (상대 경로 계산용)
*/
private function publishCustomAssets(
string $extensionType,
string $identifier,
string $targetDir,
array &$files,
string $tmp
): void {
foreach (CustomAssets::publishableFiles($extensionType, $identifier) as $file) {
$this->copyFile(
$file['absolute'],
$targetDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file['relative']),
$files,
$tmp
);
}
}
/**
* 템플릿 dist 디렉토리를 재귀 복사합니다 (허용 확장자만, 소스맵 제외).
*
@@ -927,7 +1122,8 @@ class ExtensionStaticCacheService
* @param string $targetDir 게시 대상 절대 경로
* @param array<string> $files 기록된 상대 경로 누적 (참조)
* @param string $tmp tmp 루트 (상대 경로 계산용)
* @param bool $excludeCustom 원본 안의 `custom/` 하위를 건너뛸지 (dist 원본에서만 참)
* @param bool $excludeCustom 원본 안의 `custom/` 하위를 건너뛸지 (dist 원본은 참 — `custom/` 은
* `publishCustomAssets()` 가 공유 열거자로 따로 게시한다)
*/
private function publishDistAssets(
string $sourceDir,
@@ -1064,13 +1260,13 @@ class ExtensionStaticCacheService
continue;
}
$this->publishDistAssets(
base_path("{$root}/{$identifier}/".CustomAssets::DIRECTORY),
$this->publishCustomAssets(
$root,
$identifier,
$tmp.DIRECTORY_SEPARATOR.$root.DIRECTORY_SEPARATOR.$identifier
.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.CustomAssets::DIRECTORY,
$files,
$tmp,
excludeCustom: false
$tmp
);
}
}
+3 -1
View File
@@ -1135,7 +1135,9 @@ class LayoutService
}
$identifier = $template->identifier;
$cacheVersion = (int) $this->cache->get('ext.cache_version', 0);
// 원시 키 읽기는 `cache:clear` 직후 0 을 돌려주어 `.v0` 키를 지우고 실제 키는 남긴다 —
// 트레이트 게터는 부재 시 재생성하므로 실제 서빙 키와 같은 버전을 본다.
$cacheVersion = self::getExtensionCacheVersion();
// PublicLayoutController::serve() 가 일반 응답과 편집 모드(`with_source_meta=1`) 응답을
// 별도 캐시 키로 저장한다 (`.meta` 접미사). 본 PR Phase 3 S5a-1 에서 편집 모드 응답 캐시
+32
View File
@@ -6,6 +6,7 @@ use App\Contracts\Extension\CacheInterface;
use App\Contracts\Repositories\AttachmentRepositoryInterface;
use App\Contracts\Repositories\ConfigRepositoryInterface;
use App\Extension\HookManager;
use App\Extension\Traits\ClearsTemplateCaches;
use App\Http\Resources\AttachmentResource;
use App\Seo\Contracts\SeoCacheManagerInterface;
use App\Support\ConfigCacheHelper;
@@ -28,6 +29,10 @@ use Illuminate\Validation\ValidationException;
*/
class SettingsService
{
// 자산 URL 방식 변경 시 확장 캐시 버전 bump 용. 주입된 `$this->cache` 로 직접 put 하지
// 않는다 — 트레이트가 고정 `CoreCacheDriver` + 메모이즈 스토어를 쓰는 이유가 그 안에 있다.
use ClearsTemplateCaches;
public function __construct(
private ConfigRepositoryInterface $configRepository,
private AttachmentRepositoryInterface $attachmentRepository,
@@ -706,6 +711,7 @@ class SettingsService
// CLI(`g7:asset-url-mode`)와 동일한 처리 (계획서 §알려진 한계).
if ($assetUrlModeChanged) {
$this->clearSeoCacheForAssetUrlMode();
$this->bumpExtensionCacheForAssetUrlMode();
}
// drivers 탭은 queue/broadcasting/cache 등 long-running worker에 영향
@@ -1090,6 +1096,7 @@ class SettingsService
if ($assetUrlModeChanged) {
$this->clearSeoCacheForAssetUrlMode();
$this->bumpExtensionCacheForAssetUrlMode();
}
if (str_starts_with($key, 'drivers.') || $key === 'drivers') {
@@ -1126,17 +1133,42 @@ class SettingsService
*/
public function restoreSettings(string $backupPath): bool
{
// 자산 URL 방식은 복원 **전**에 읽어 둔다 — 복원 뒤에는 이전 값을 알 수 없어
// 변경 여부를 판별할 수 없다 (saveSettings/setSetting 과 같은 사유).
$previousAssetUrlMode = $this->configRepository->get('general.asset_url_mode');
$result = $this->configRepository->restore($backupPath);
if ($result) {
// 복원도 설정 전체를 갈아엎는 쓰기다 — 캐시만 비우고 미러를 두면
// 같은 프로세스가 복원 전 값을 계속 읽는다 (저장 경로와 동일 결함, 공개이슈 #109).
$this->invalidateSettingsCache();
// 복원으로 자산 URL 방식이 바뀌었으면 두 저장 경로와 동일하게 처리한다 —
// SEO 프리렌더와 병합 번들 CSS 양쪽에 구워진 URL 형태가 어긋난다.
if ($this->configRepository->get('general.asset_url_mode') !== $previousAssetUrlMode) {
$this->clearSeoCacheForAssetUrlMode();
$this->bumpExtensionCacheForAssetUrlMode();
}
}
return $result;
}
/**
* 자산 URL 방식이 바뀌었을 때 확장 캐시 버전을 올립니다 (정적 게시본 재생성).
*
* 병합 번들 CSS 는 내부 `url()` 참조가 그 시점의 자산 URL **형태**(확장자 / `?file=`)로
* 본문에 구워진다(`ExtensionBundleService` 의 `AssetCssUrlRewriter`). 디스크 번들과 정적
* 게시본은 캐시 버전으로 키드되어 있어, 버전이 오르지 않으면 모드를 바꿔도 옛 형태의
* URL 이 남고 그 참조(글꼴·이미지)가 서버에서 404 가 된다(#651 F5). bump 단일 지점이
* 번들 재병합과 정적 재게시를 함께 예약한다.
*/
private function bumpExtensionCacheForAssetUrlMode(): void
{
$this->incrementExtensionCacheVersion();
}
/**
* 테스트 메일을 발송합니다.
*