refactor(template): remove legacy source paths

go
codex 3 weeks ago
parent 5214b0da7c
commit f1d9e46421

@ -10,7 +10,7 @@ Virt Cloud 是 PHP 8.5 面板与宿主机 Go Agent 组成的虚拟机销售平
- Agent 以 `panel_url + agent_id + agent_secret` 主动建立 WSS 控制长连接。PHP 先持久化任务并立即向浏览器返回 `202 Accepted`,再通过面板本机 Go Agent Gateway 派发一次带 SHA-256、时间戳、nonce、操作者上下文和 HMAC-SHA256 签名的请求。断线、超时或重启都不会重新派发 mutation。维护迁移的数据不经过面板:同资源池宿主机的 Agent 在 `peer_migration_port`(默认 `9443/TCP`)之间使用 TLS 1.3、一次性票据和源证书 SHA-256 锁定进行目标拉取;该端口只提供路径隔离的 PeerMigration V3 清单和工件 Range 读取,不暴露 libvirt 或通用管理 API。
- 同地区 VPC 使用宿主机既有私网作为 direct L3 underlay。PHP 负责地区 CIDR 池、VPC/IPAM、逻辑端口、宿主机完整路由投影和迁移编排;Agent 只按签名期望状态管理专属 bridge、精确 `/32` 路由、nftables 隔离规则以及一张可选 VM 私网网卡。VPC 不提供跨地区互联、NAT 或二层广播,也不改变公网 `br0`、公网防火墙和公网流量计费边界。
- 所有虚拟机使用宿主机能力支持的 Q35 UEFI,并明确关闭 Secure Boot。不要硬编码某个发行版的 OVMF 路径。
- 每个云镜像版本拥有对象存储中的不可变主副本,并按地区/宿主机维护派生副本;可配置仅首次安装执行的启动脚本。创建任务会快照镜像代次和脚本版本;脚本成功、失败或中断后都不会自动重放,租户不能读取或覆盖脚本正文。删除先确认全部宿主机副本已清理,再删除主副本的精确对象版本;对象删除结果不明确时只做 HEAD 核对,不盲目重放 DELETE。
- 每个云镜像版本拥有对象存储中的不可变主副本,并按地区/宿主机维护派生副本;可配置仅首次安装执行的启动脚本。创建任务会快照镜像代次和脚本版本;脚本成功、失败或中断后都不会自动重放,租户不能读取或覆盖脚本正文。原始远程 URL 和旧的面板暂存下载路径不会写入模板目录,也不存在绕过主副本直接分发给 Agent 的兼容入口。删除先确认全部宿主机副本已清理,再删除主副本的精确对象版本;对象删除结果不明确时只做 HEAD 核对,不盲目重放 DELETE。
- 用户购买套餐开通一台 VM;每次购买或续费生成独立预付费账期及流量额度。新建实例账单的支付期限由后台按分钟配置,只影响之后生成的开通账单;续费账单的支付截止固定为其对应实例到期时间加三天,不会因账单延迟生成而顺延。额度用尽只断网、不关机;下一已付费账期恢复网络。最终到期只断网;未支付续费账单进入三天宽限期,之后永久删除 VM 定义和面板管理的磁盘。
- 用户页面及登录页保持原虚拟机面板样式,管理员页面保留 venix 主题。普通用户不获得宿主机管理、Agent 设置或退役节点管理入口。
- 任务只有执行中、成功和失败三种公开状态,终态只有 `succeeded` 或 `failed`;所有任务都有绝对截止时间。派发后超时或断线直接终态失败,并标记“效果可能已发生、不可重放原 operation ID”;任务不会停在“待核对”,也不会自动重试、退款或再次删除磁盘。实例设置可以用精确晚到回执,或 Agent 对同一 operation 的只读双标记证据,收敛 PHP 凭据/主机名账本与内部 effect fence;原任务仍保持失败,原宿主机 mutation 永不重放。不能可靠受 Go context 中止的 libvirt mutation 在独立子进程中执行,截止后由父 Agent 回收整个进程组。固定存储池配置是非破坏性的幂等例外:失败任务仍终止且不重放,但不保留跨任务资源栅栏;已定义的固定 pool 不做失败回滚,管理员可显式提交新任务核验或补全同路径固定池,绝不改绑、迁移或删除数据。

@ -95,9 +95,9 @@ php xcat cloudRepairInstanceMetadata --apply
后台 `/admin/object-storage` 可配置一个全局 S3 兼容对象存储应用,适用于 AWS S3、MinIO 及实现 AWS Signature Version 4 的兼容服务。该功能复用业务库已有的 `configurations` 表,不需要导入新表。Endpoint 必须是带有效证书的 HTTPS origin;MinIO 通常选择路径寻址,AWS S3 通常选择虚拟主机寻址。
Access Key ID 与 Secret Access Key 只在超级管理员提交时进入 PHP,使用 `cloud_data_key` 的独立用途密钥密封后保存,读取页面不会回显。修改任一配置或停用应用都会清除原就绪标记;必须重新执行“验证连接并启用”。连接验证只发送签名的 `HeadBucket` 请求,需要目标 Bucket 的 `s3:ListBucket` 权限,不上传、覆盖或删除对象。管理员虚拟机管理已接入完整系统盘备份和新实例恢复,目标可以是原宿主机或其他合格宿主机;用户自动备份使用同一对象存储,在实例设置中按每天或每周于 UTC 00:00 调度并保留最多两份。运行账户只需配置 `vm-backups/` 前缀范围内的 multipart 上传、`GetObject`、`HeadObject` 和 `DeleteObject` 权限;开启 Bucket 版本控制时还必须授予 `s3:GetObjectVersion` 与 `s3:DeleteObjectVersion`,让 HEAD 与删除准确绑定 `versionId`。维护迁移使用宿主机间 PeerMigration V3 直传,不创建 S3 迁移对象,也不需要 `vm-migrations/` 权限。当前不包含增量链和管理员手工备份的自动保留策略,具体安全边界见 `docs/PORTABLE_VM_BACKUPS.md`。
Access Key ID 与 Secret Access Key 只在超级管理员提交时进入 PHP,使用 `cloud_data_key` 的独立用途密钥密封后保存,读取页面不会回显。修改任一配置或停用应用都会清除原就绪标记;必须重新执行“验证连接并启用”。连接验证只发送签名的 `HeadBucket` 请求,需要目标 Bucket 的 `s3:ListBucket` 权限,不上传、覆盖或删除对象。管理员虚拟机管理已接入完整系统盘备份和新实例恢复,目标可以是原宿主机或其他合格宿主机;用户自动备份使用同一对象存储,在实例设置中按每天或每周于 UTC 00:00 调度并保留最多两份。云镜像导入还会先把经过校验的内容发布到 `cloud-templates/` 不可变主副本,再向宿主机签发该精确版本的只读地址;没有旧本地模板路径或直接暂存分发回退。运行账户需要在配置前缀下同时授予 `vm-backups/` 与 `cloud-templates/` 的上传、`GetObject`、`HeadObject` 和 `DeleteObject` 权限;开启 Bucket 版本控制时还必须授予 `s3:GetObjectVersion` 与 `s3:DeleteObjectVersion`,让 HEAD 与删除准确绑定 `versionId`。维护迁移使用宿主机间 PeerMigration V3 直传,不创建 S3 迁移对象,也不需要 `vm-migrations/` 权限。当前不包含增量链和管理员手工备份的自动保留策略,具体安全边界见 `docs/PORTABLE_VM_BACKUPS.md`。
生产 Bucket 必须把生命周期规则作为控制面之外的最后兜底:在短周期内终止未完成 multipart upload;开启版本控制时,按业务保留要求清理 `vm-backups/` 的非当前版本和过期删除标记。生命周期不得提前删除仍由面板目录引用的当前版本。面板会保存 HEAD 返回的 ETag 与 `version_id`,删除时精确定位该版本;删除结果不明时先进行两次间隔至少 60 秒的稳定 HEAD,只有对象身份完全一致才创建新的删除代次,每个自动周期最多三次。达到上限的对象进入后台“对象清理异常”,不再占用用户自动备份保留份数,但仍计入对象清理债务,必须由管理员核查后手动开启新的受控周期。
生产 Bucket 必须把生命周期规则作为控制面之外的最后兜底:在短周期内终止未完成 multipart upload;开启版本控制时,按业务保留要求清理 `vm-backups/` 的非当前版本和过期删除标记。生命周期不得提前删除仍由面板备份或云镜像目录引用的当前版本。面板会保存 HEAD 返回的 ETag 与 `version_id`,删除时精确定位该版本;删除结果不明时先进行间隔稳定 HEAD,只有对象身份完全一致才创建新的删除代次,每个自动周期最多三次。达到上限的对象进入后台人工核对,不再自动删除;云镜像的人工重试只恢复对象存储核对,不会再次删除宿主机副本。
生产环境应为面板创建独立服务账户,把权限限制到配置的 Bucket 和备份前缀。数据库备份必须与原始 `cloud_data_key` 一起保管,重新生成主密钥无法恢复全局配置及各备份冻结的对象存储凭据。

@ -84,10 +84,10 @@ Agent 在连接前注册并持续运行 libvirt event loop;每个连接 genera
- 域 XML 使用结构化类型生成并验证输入,所有变更按 UUID 定位。创建请求的 `name` 保留为面板/Guest 显示输入并写入 `display-name` metadata;libvirt 内部名称只能由已验签 actor 的 `user_id` 与最终 UUID 派生为 `<user_id>:vm-<前 12 位小写无连字符 UUID>`,不接受请求正文覆盖。部署每台宿主机时先查询 domain capabilities,把该机支持且不启用 Secure Boot 的 Q35/EFI loader 与 NVRAM template 写入本机 Agent 配置;创建请求不能传入任意固件路径。Agent 使用手工 loader/NVRAM XML 并保持 `secure="no"`、`SMM=off`,不混入只适用于固件自动选择的 feature 列表,也不在 PHP 中硬编码单一发行版 OVMF 路径。
- 宿主机网络接入由 PHP 面板统一保存:网页默认 Linux 网桥 `br0`,`default_network` 使用 `bridge:<名称>` 或 `network:<名称>`;Agent 配置不再接受 `network_selectors` 映射。Agent 只发现、验证和使用已存在且活动的 Linux 网桥或 libvirt network,不修改宿主机系统网络。`capabilities.network_selectors` 返回排序去重、最多 64 项的可用接入列表;面板所选值必须精确匹配,创建/换网时再次重验。
- Agent 配置使用 `revision`/`tested_revision` 就绪门闩。保存密钥、启用状态或宿主机 `default_network` 会推进 revision 并将 `tested_revision` 清零;只有同一 revision 经已认证出站会话完成 `/v1/health` 与 `/v1/capabilities` 且网络匹配,才记录为就绪。调度、Agent 客户端以及控制台路径均要求 `enabled=1`、`last_test_status=healthy` 且 `tested_revision=revision`。全新部署只接受规范的 `bridge:<名称>` 或 `network:<名称>`,不读取旧 alias、旧健康结果或已派发旧任务。
- 云镜像由 PHP 保存目录元数据、启动脚本以及对象存储中不可变主副本的精确身份,宿主机只保存可重建的派生副本。创建任务快照镜像 generation、revision 和脚本正文后签名发送给目标 Agent;删除后重新导入的同名镜像不能继承旧脚本。删除采用两阶段收敛:先证明全部宿主机副本已删除,再删除主副本的精确对象版本;主副本清理完成前目录和原聚合任务保持占用。
- 云镜像由 PHP 保存目录元数据、启动脚本以及对象存储中不可变主副本的精确身份,宿主机只保存可重建的派生副本。远程 URL 或管理员上传文件必须先由 PHP 校验并发布为主副本;目录不保存旧来源路径,上传暂存也不能再签发 `cloud-template` Agent 拉取能力。创建任务快照镜像 generation、revision 和脚本正文后签名发送给目标 Agent;删除后重新导入的同名镜像不能继承旧脚本。删除采用两阶段收敛:先证明全部宿主机副本已删除,再删除主副本的精确对象版本;主副本清理完成前目录和原聚合任务保持占用。
- 启动脚本仅用于新云镜像实例的首次安装,不用于普通重启、网络设置、重装、救援或用户 ISO。脚本限制 32 KiB UTF-8,拒绝 NUL,CRLF 规范化为 LF,空值表示禁用。
- Agent 将脚本以 root 私有文件写入 cloud-init seed,由一次性 runner 原子记录 started 状态。成功、失败和中断都不自动重放;VM 创建成功不等待脚本结束。
- 镜像下载始终使用独立 HTTPS 请求,WSS 只传递一次性下载 URL/token/摘要等任务元数据,不传镜像字节。面板暂存上传还会把已捕获文件的精确大小写入签名任务;即使代理改用 chunked 响应,Agent 也按该大小有界读取,并拒绝长度不符、多余字节、短读或摘要不符。远程 URL 没有面板大小快照,仍要求来源返回有效 `Content-Length`。Agent 限制来源、解析后的公网地址、全部跳转、大小、超时和摘要;校验 QCOW2 格式,拒绝 backing file、外部 data file、加密或 raw 内容。
- 镜像下载始终使用独立 HTTPS 请求,WSS 只传递一次性下载 URL/token/摘要等任务元数据,不传镜像字节。救援 ISO 的面板暂存上传会把已捕获文件的精确大小写入签名任务;即使代理改用 chunked 响应,Agent 也按该大小有界读取,并拒绝长度不符、多余字节、短读或摘要不符。云模板的远程 URL 只用于 PHP 形成不可变主副本,不会下发给 Agent;Agent 只读取主副本的精确版本只读地址,并继续校验大小、摘要及 QCOW2 格式,拒绝 backing file、外部 data file、加密或 raw 内容。
## 网络与账期

@ -20,6 +20,7 @@
- 旧节点列表、节点管理、代理订阅/流量/等级业务、旧客户端分发、签到、AI、社区聊天、DNS 策略、边缘配置和已退役监控入口。
- Material、Codex 等主题;只保留 venix 管理主题和既有用户面板样式。
- 旧账户哈希、旧代理字段、账户/等级到期、旧引擎表、旧宿主机表和旧任务载荷的导入。
- 云镜像原始来源路径、`source_type`/`sealed_source_url` 目录字段,以及面板暂存文件直接签发给 Agent 的 `cloud-template` 下载能力;新镜像必须先形成对象存储不可变主副本。
普通用户不得获得 `/admin/agents`、宿主机、资源池、网络池、镜像后台或系统日志管理能力。删除菜单不是授权边界;PHP 路由和服务层必须继续校验用户、资源所有权、管理员及超级管理员权限。

@ -92,6 +92,7 @@ jq empty deploy/*.json.example
- 模板/ISO 导入与删除 A 宿主已应用、B 明确未应用:保留失败审计,显示部分结果,清除父任务占用;新的显式删除仅派发至仍有副本的宿主。未知叶子、错绑副本和伪造投影仍拒绝解锁。
- 云镜像全部宿主机副本已删除但主副本仍存在:父任务不得提前发布成功,副本账本不得提前删除。对象 DELETE 明确成功或精确版本 HEAD 返回不存在后才原子退休目录;DELETE 结果不明确时原 operation 不重放,需两次间隔 HEAD 证明相同大小、ETag 和 version ID 后才生成新代次。连续三代仍不明确、对象身份变化或明确拒绝必须进入管理员核对;管理员重试只处理对象存储,不得再次调用 Agent。晚到宿主机成功回执也必须进入同一两阶段边界。
- 全新 schema 的 `cloud_templates` 不得包含 `source_type`、`sealed_source_url` 或其他旧来源路径;上传暂存服务必须拒绝 `cloud-template` purpose 和非 ISO 文件。远程与本地 QCOW2 导入均先发布对象存储主副本,后续所有宿主机补齐和修复只能使用该主副本生成的精确版本只读地址。
- 持续填充回执、叶子与聚合队列:三个通道均在有界 tick 内获得处理机会,空通道不能浪费整轮。
- Gateway 未监听及连接阶段超时且零字节发送:明确未执行并原子收尾;已发送后超时、连接复用、缺统计、多个传输中任一可能发送均不能当作未派发。开通任务只退款一次,不重复派发。
- 快照占用及各变更入口写入前校验失败:Journal 记录无副作用失败,同资源新 operation 可以进入;写调用之后及显式 uncertain 错误继续保留保护。

@ -8,7 +8,7 @@ use App\Services\Config;
/** Initializes only the clean-break PHP business and Agent log schemas. */
final class CloudSetup
{
private const SCHEMA_VERSION = 'go-agent-wss-v15-template-reconciliation';
private const SCHEMA_VERSION = 'go-agent-wss-v16-template-artifacts';
private const MAIN_TABLES = [
'cloud_regions', 'cloud_network_lines', 'cloud_resource_pools',
'cloud_hosts', 'cloud_host_agents',

@ -26,13 +26,11 @@ final class CloudUploadStagingController
if ($handle === false) {
throw new CloudError('上传暂存文件不可读', 503);
}
$name = (string) $file['purpose'] === 'cloud-template'
? 'image.qcow2' : 'rescue.iso';
return $response->withBody(new Stream($handle))
->withHeader('Content-Type', 'application/octet-stream')
->withHeader('Content-Length', (string) $file['size_bytes'])
->withHeader('Content-Disposition',
'attachment; filename="' . $name . '"')
'attachment; filename="rescue.iso"')
->withHeader('Digest', 'sha-256=' . base64_encode(
hex2bin((string) $file['sha256'])
))

@ -9,7 +9,7 @@ final class CloudTemplate extends Model
protected $primaryKey = 'id';
public $incrementing = false;
protected $keyType = 'string';
protected $hidden = ['startup_script', 'sealed_source_url'];
protected $hidden = ['startup_script'];
protected $casts = [
'is_default' => 'bool',
'image_bytes' => 'int',

@ -152,8 +152,6 @@ final class CloudTemplateCatalogService
$name,
$family,
$version,
'remote',
$url,
$file,
$runtime
);
@ -184,8 +182,6 @@ final class CloudTemplateCatalogService
$name,
$family,
$version,
'upload',
'',
$file,
CloudObjectStorageConfig::runtime(true)
);
@ -193,8 +189,7 @@ final class CloudTemplateCatalogService
/** @param array{path:string,size_bytes:int,sha256:string} $file */
private static function publishAndReserveImport(array $actor, string $name,
string $family, string $version, string $originType,
string $originUrl, array $file, array $runtime): array
string $family, string $version, array $file, array $runtime): array
{
$hosts = array_values(array_unique(array_map('intval',
CloudAgentSettingsService::enabledHostIds())));
@ -207,7 +202,7 @@ final class CloudTemplateCatalogService
$connection = (new CloudTemplate())->getConnection();
$template = $connection->transaction(static function () use (
$templateId, $generationToken, $name, $family, $version,
$originType, $originUrl, $file, $runtime
$file, $runtime
): CloudTemplate {
$now = time();
$template = new CloudTemplate();
@ -219,11 +214,6 @@ final class CloudTemplateCatalogService
$template->name = $name;
$template->os_family = $family;
$template->os_version = $version;
$template->source_type = 'object';
$template->sealed_source_url = CloudSecrets::encrypt([
'origin_type' => $originType,
'origin_url' => $originUrl,
], 'template-source');
$template->image_bytes = (int) $file['size_bytes'];
$template->sha256 = (string) $file['sha256'];
$template->startup_script = '';
@ -2453,7 +2443,6 @@ final class CloudTemplateCatalogService
'name' => (string) $row->name,
'os_family' => (string) $row->os_family,
'os_version' => (string) $row->os_version,
'source_type' => (string) $row->source_type,
'image_bytes' => (int) $row->image_bytes,
'sha256' => (string) $row->sha256,
'state' => (string) $row->state,

@ -94,9 +94,8 @@ final class CloudUploadStagingService
public static function issue(array $file, int $hostId,
string $purpose): array
{
if ($hostId < 1
|| !in_array($purpose,
['cloud-template', 'rescue-template'], true)
if ($hostId < 1 || $purpose !== 'rescue-template'
|| !str_ends_with((string) ($file['file_key'] ?? ''), '.iso')
|| !self::validFile($file)) {
throw new \InvalidArgumentException('Invalid staging record');
}
@ -148,8 +147,8 @@ final class CloudUploadStagingService
throw new CloudError('上传暂存凭据无效', 401);
}
$fileKey = (string) $row->file_key;
if (preg_match('/^[a-f0-9]{64}\.(?:qcow2|iso)$/D', $fileKey)
!== 1) {
if ((string) $row->purpose !== 'rescue-template'
|| preg_match('/^[a-f0-9]{64}\.iso$/D', $fileKey) !== 1) {
throw new CloudError('上传暂存记录损坏', 503);
}
$path = self::directory() . DIRECTORY_SEPARATOR . $fileKey;

@ -314,8 +314,6 @@ CREATE TABLE cloud_templates (
name VARCHAR(64) NOT NULL,
os_family VARCHAR(32) NOT NULL,
os_version VARCHAR(32) NOT NULL,
source_type VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
sealed_source_url LONGTEXT NOT NULL,
image_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
startup_script MEDIUMTEXT NOT NULL,

@ -200,8 +200,6 @@ namespace {
$table->string('name');
$table->string('os_family');
$table->string('os_version');
$table->string('source_type');
$table->text('sealed_source_url');
$table->integer('image_bytes');
$table->string('sha256');
$table->text('startup_script');
@ -572,8 +570,6 @@ SQL);
'name' => 'Aggregate projection ' . $parentId,
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'qcow2',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => $sha256,
'startup_script' => '',
@ -1694,8 +1690,6 @@ SQL);
'name' => 'Prepared import',
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'qcow2',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => $preparedSha,
'startup_script' => '',
@ -1825,8 +1819,6 @@ SQL);
'name' => 'Deadline import',
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'qcow2',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => $deadlineImportSha,
'startup_script' => '',
@ -1888,8 +1880,6 @@ SQL);
'name' => 'Deadline delete',
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'qcow2',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => $deadlineDeleteSha,
'startup_script' => '',
@ -2077,8 +2067,6 @@ SQL);
'name' => 'Invalid dispatch template',
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'qcow2',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => $invalidDispatchSha,
'startup_script' => '',
@ -2197,8 +2185,6 @@ SQL);
'name' => 'Normal settle gated',
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'qcow2',
'sealed_source_url' => 'test-only',
'image_bytes' => 8192,
'sha256' => $normalGateSha,
'startup_script' => '',
@ -2872,8 +2858,6 @@ SQL);
'name' => 'Historical fail open',
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'qcow2',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => $historicalSha,
'startup_script' => '',

@ -249,7 +249,7 @@ namespace {
$schema->create('cloud_host_capacity_policies', function (Blueprint $t) { $t->integer('host_id')->primary(); foreach (['configured_cpu_cores', 'configured_memory_mib', 'configured_disk_gib', 'safety_cpu_cores', 'safety_memory_mib', 'safety_disk_gib', 'max_instances', 'created_at', 'updated_at'] as $v) { $t->integer($v)->default(0); } });
$schema->create('cloud_public_ips', function (Blueprint $t) { $t->increments('id'); $t->integer('host_id'); $t->integer('public_ip_pool_id')->nullable(); $t->string('address')->unique(); $t->integer('prefix_length'); $t->string('state'); $t->integer('reservation_id')->nullable()->unique(); $t->integer('instance_id')->nullable(); $t->string('operation_id')->nullable()->unique(); $t->integer('created_at'); $t->integer('updated_at'); });
$schema->create('cloud_offers', function (Blueprint $t) { $t->increments('id'); $t->integer('plan_id'); $t->integer('resource_pool_id'); $t->string('code')->unique(); $t->string('name'); $t->string('price'); $t->string('backup_price')->default('0.00'); $t->string('currency')->default('USD'); $t->integer('price_version')->default(1); $t->integer('revision')->default(1); $t->integer('status')->default(1); $t->integer('stock')->default(-1); $t->integer('sort')->default(0); $t->integer('created_at'); $t->integer('updated_at'); $t->unique(['plan_id', 'resource_pool_id']); });
$schema->create('cloud_templates', function (Blueprint $t) { $t->string('id')->primary(); $t->string('catalog_key')->default('test-catalog'); $t->string('version_label')->default('test-version'); $t->boolean('is_default')->default(true); $t->string('name'); $t->string('os_family'); $t->string('os_version'); $t->string('source_type'); $t->text('sealed_source_url'); $t->integer('image_bytes'); $t->string('sha256'); $t->text('startup_script'); $t->integer('revision'); $t->string('generation_token'); $t->string('state'); $t->integer('active_job_id')->nullable(); $t->integer('created_at'); $t->integer('updated_at'); });
$schema->create('cloud_templates', function (Blueprint $t) { $t->string('id')->primary(); $t->string('catalog_key')->default('test-catalog'); $t->string('version_label')->default('test-version'); $t->boolean('is_default')->default(true); $t->string('name'); $t->string('os_family'); $t->string('os_version'); $t->integer('image_bytes'); $t->string('sha256'); $t->text('startup_script'); $t->integer('revision'); $t->string('generation_token'); $t->string('state'); $t->integer('active_job_id')->nullable(); $t->integer('created_at'); $t->integer('updated_at'); });
$schema->create('cloud_user_isos', function (Blueprint $t) { $t->string('id')->primary(); $t->integer('active_job_id')->nullable(); });
$schema->create('cloud_template_replicas', function (Blueprint $t) { $t->integer('host_id'); $t->string('template_id'); $t->integer('job_id')->nullable(); $t->integer('revision'); $t->string('generation_token'); $t->string('state')->default('pending'); $t->integer('image_bytes')->default(0); $t->string('sha256')->default(''); $t->string('operation_id')->default(''); $t->string('error_code')->default(''); $t->integer('created_at'); $t->integer('updated_at'); $t->primary(['host_id', 'template_id']); });
$schema->create('cloud_platform_test_policy_state', function (Blueprint $t) { $t->integer('id')->primary(); $t->integer('revision')->default(0); $t->integer('updated_by')->nullable(); $t->integer('updated_at')->default(0); });
@ -387,10 +387,6 @@ namespace {
$template->name = 'AlmaLinux 10';
$template->os_family = 'AlmaLinux';
$template->os_version = '10';
$template->source_type = 'remote';
$template->sealed_source_url = \App\Services\Cloud\CloudSecrets::encrypt([
'url' => 'https://example.invalid/alma10.qcow2',
], 'template-source');
$template->image_bytes = 1024;
$template->sha256 = str_repeat('a', 64);
$template->startup_script = '';
@ -404,10 +400,6 @@ namespace {
$reinstallTemplate->name = 'Debian 13';
$reinstallTemplate->os_family = 'Debian';
$reinstallTemplate->os_version = '13';
$reinstallTemplate->source_type = 'remote';
$reinstallTemplate->sealed_source_url = \App\Services\Cloud\CloudSecrets::encrypt([
'url' => 'https://example.invalid/debian13.qcow2',
], 'template-source');
$reinstallTemplate->image_bytes = 2048;
$reinstallTemplate->sha256 = str_repeat('c', 64);
$reinstallTemplate->startup_script = '';

@ -22,7 +22,7 @@ $assert(stripos($schema, 'compatibility import') === false
$assert(!preg_match('/\bengine_[A-Za-z0-9_]*\b/', $schema),
'cloud.sql retained an engine-prefixed identifier.');
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v15-template-reconciliation'")
"SCHEMA_VERSION = 'go-agent-wss-v16-template-artifacts'")
&& !str_contains($setup, "SCHEMA_VERSION = 'go-v1'"),
'Outbound Agent schema must reject the incompatible earlier Go database.');
$assert(str_contains($schema,
@ -60,6 +60,15 @@ $assert(str_contains($schema,
&& str_contains($setup, "'observed_state', 'observed_revision'")
&& str_contains($setup, "'cloud_template_replica_observed'"),
'Fresh schema is missing durable template observations or master-artifact validation.');
$templateTable = preg_match(
'/CREATE TABLE cloud_templates \((.*?)\n\) ENGINE=/s',
$schema,
$templateMatch
) === 1 ? $templateMatch[1] : '';
$assert($templateTable !== ''
&& !str_contains($templateTable, 'source_type')
&& !str_contains($templateTable, 'sealed_source_url'),
'Fresh cloud-template schema retained the retired direct-source path.');
$assert(str_contains($schema,
"phase VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'accepted'")
&& str_contains($schema,

@ -109,13 +109,32 @@ namespace {
$table->integer('created_at');
$table->integer('updated_at');
});
$schema->create('cloud_hosts', static function (Blueprint $table): void {
$table->integer('id')->primary();
$table->boolean('enabled');
$table->string('default_network');
});
$schema->create('cloud_host_agents', static function (Blueprint $table): void {
$table->integer('host_id')->primary();
$table->boolean('enabled');
$table->string('last_test_status');
$table->integer('revision');
$table->integer('tested_revision');
});
$schema->create('cloud_host_storage_configurations', static function (
Blueprint $table
): void {
$table->integer('host_id')->primary();
$table->string('state');
});
$schema->create('cloud_templates', static function (Blueprint $table): void {
$table->string('id')->primary();
$table->string('catalog_key')->default('test-catalog');
$table->string('version_label')->default('test-version');
$table->boolean('is_default')->default(true);
$table->string('name');
$table->text('sealed_source_url');
$table->integer('image_bytes');
$table->string('sha256');
$table->text('startup_script');
$table->integer('revision');
$table->string('generation_token');
@ -137,12 +156,21 @@ namespace {
$table->integer('updated_at');
$table->primary(['host_id', 'template_id']);
});
$capsule->getConnection('default')->table('cloud_hosts')->insert([
'id' => 7, 'enabled' => 1, 'default_network' => 'bridge:br0',
]);
$capsule->getConnection('default')->table('cloud_host_agents')->insert([
'host_id' => 7, 'enabled' => 1, 'last_test_status' => 'healthy',
'revision' => 1, 'tested_revision' => 1,
]);
$capsule->getConnection('default')->table(
'cloud_host_storage_configurations'
)->insert(['host_id' => 7, 'state' => 'applied']);
$capsule->getConnection('default')->table('cloud_templates')->insert([
'id' => 'debian-12',
'name' => 'Debian 12',
'sealed_source_url' => CloudSecrets::encrypt([
'url' => 'https://example.invalid/debian-12.qcow2',
], 'template-source'),
'image_bytes' => 4096,
'sha256' => hash('sha256', 'snapshot-template'),
'startup_script' => '',
'revision' => 1,
'generation_token' => str_repeat('a', 32),

@ -48,8 +48,6 @@ namespace {
$table->string('name');
$table->string('os_family');
$table->string('os_version');
$table->string('source_type');
$table->text('sealed_source_url');
$table->integer('image_bytes');
$table->string('sha256');
$table->text('startup_script');
@ -132,8 +130,6 @@ namespace {
'name' => 'Debian 13',
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'object',
'sealed_source_url' => '',
'image_bytes' => $bytes,
'sha256' => $sha256,
'startup_script' => '',

@ -39,8 +39,6 @@ $capsule->schema('default')->create('cloud_templates',
$table->string('name');
$table->string('os_family');
$table->string('os_version');
$table->string('source_type');
$table->text('sealed_source_url');
$table->integer('image_bytes');
$table->string('sha256');
$table->text('startup_script');
@ -203,8 +201,6 @@ foreach ([
'name' => 'Debian 12',
'os_family' => 'Debian',
'os_version' => '12',
'source_type' => 'remote',
'sealed_source_url' => 'test-only-sealed-template-source',
'image_bytes' => 1024,
'sha256' => str_repeat('a', 64),
'startup_script' => '',
@ -315,6 +311,8 @@ foreach (['startup_script', 'startup_script_configured', 'revision',
}
$assert($admin['startup_script_configured'] === false
&& !array_key_exists('startup_script', $admin)
&& !array_key_exists('source_type', $admin)
&& !array_key_exists('sealed_source_url', $admin)
&& count($adminCatalog['hosts']) === 2
&& $adminCatalog['hosts'][0]['eligible'] === true
&& $adminCatalog['hosts'][1]['eligible'] === false

@ -93,8 +93,6 @@ namespace {
$table->string('name');
$table->string('os_family');
$table->string('os_version');
$table->string('source_type');
$table->text('sealed_source_url');
$table->integer('image_bytes');
$table->string('sha256');
$table->text('startup_script');
@ -206,8 +204,7 @@ namespace {
'id' => $templateId, 'catalog_key' => 'debian-13',
'version_label' => $suffix, 'is_default' => 0,
'name' => 'Delete ' . $suffix, 'os_family' => 'Debian',
'os_version' => '13', 'source_type' => 'object',
'sealed_source_url' => '', 'image_bytes' => 4096,
'os_version' => '13', 'image_bytes' => 4096,
'sha256' => $sha, 'startup_script' => '', 'revision' => 1,
'generation_token' => $generation, 'state' => 'deleting',
'active_job_id' => $parentId, 'created_at' => $now,

@ -91,8 +91,10 @@ $assert(is_string($schema)
&& str_contains($schema, 'sealed_storage_runtime LONGTEXT NOT NULL')
&& str_contains($schema, 'delete_generation INT UNSIGNED NOT NULL')
&& str_contains($schema, 'cloud_template_artifact_delete_due')
&& str_contains($schema, 'sealed_source_url LONGTEXT NOT NULL')
&& !preg_match('/\bsource_url\s+(?:TEXT|LONGTEXT)/', $schema)
&& preg_match('/CREATE TABLE cloud_templates \((.*?)\n\) ENGINE=/s',
$schema, $templateTable) === 1
&& !str_contains($templateTable[1], 'source_type')
&& !str_contains($templateTable[1], 'sealed_source_url')
&& str_contains($schema, 'startup_script MEDIUMTEXT NOT NULL')
&& !preg_match('/CREATE TABLE cloud_template_(?:retirements|catalog_locks)/',
$schema),

@ -44,8 +44,6 @@ $schema->create('cloud_templates', static function (Blueprint $table): void {
$table->string('name');
$table->string('os_family');
$table->string('os_version');
$table->string('source_type');
$table->text('sealed_source_url');
$table->integer('image_bytes');
$table->string('sha256');
$table->text('startup_script');
@ -105,8 +103,6 @@ $template = static function (
'name' => $id,
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'object',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => $sha,
'startup_script' => '',

@ -50,8 +50,6 @@ $schema->create('cloud_templates', static function (Blueprint $table): void {
$table->string('name');
$table->string('os_family');
$table->string('os_version');
$table->string('source_type');
$table->text('sealed_source_url');
$table->integer('image_bytes');
$table->string('sha256');
$table->text('startup_script');
@ -113,8 +111,6 @@ $template = static function (string $id) use (
'name' => 'Template ' . $id,
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'object',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => $sha,
'startup_script' => '',

@ -106,8 +106,6 @@ $schema->create('cloud_templates', static function (Blueprint $table): void {
$table->string('name');
$table->string('os_family');
$table->string('os_version');
$table->string('source_type');
$table->text('sealed_source_url');
$table->integer('image_bytes');
$table->string('sha256');
$table->text('startup_script');
@ -190,8 +188,6 @@ foreach ([
'name' => 'Regional Linux',
'os_family' => 'Linux',
'os_version' => '1',
'source_type' => 'remote',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => str_repeat('b', 64),
'startup_script' => '',

@ -46,8 +46,6 @@ $schema->create('cloud_templates', static function (Blueprint $table): void {
$table->string('name');
$table->string('os_family');
$table->string('os_version');
$table->string('source_type');
$table->text('sealed_source_url');
$table->integer('image_bytes');
$table->string('sha256');
$table->text('startup_script');
@ -100,8 +98,6 @@ Capsule::table('cloud_templates')->insert([
'name' => 'Debian 13',
'os_family' => 'Debian',
'os_version' => '13',
'source_type' => 'object',
'sealed_source_url' => 'test-only',
'image_bytes' => 4096,
'sha256' => $sha,
'startup_script' => '',

@ -123,23 +123,44 @@ namespace {
$table->integer('created_at');
});
$payload = "qcow2\0test-image";
$capture = CloudUploadStagingService::capture(
$request($payload, 'application/octet-stream; charset=binary',
(string) strlen($payload)),
$qcowPayload = "qcow2\0test-image";
$qcowCapture = CloudUploadStagingService::capture(
$request($qcowPayload, 'application/octet-stream; charset=binary',
(string) strlen($qcowPayload)),
'qcow2', 1, 1024
);
$assert(is_file($capture['path'])
&& (int) $capture['size_bytes'] === strlen($payload)
&& hash_file('sha256', $capture['path']) === $capture['sha256']
$assert(is_file($qcowCapture['path'])
&& (int) $qcowCapture['size_bytes'] === strlen($qcowPayload)
&& hash_file('sha256', $qcowCapture['path'])
=== $qcowCapture['sha256']
&& preg_match('/^[a-f0-9]{64}\.qcow2$/D',
$capture['file_key']) === 1,
$qcowCapture['file_key']) === 1,
'Upload capture did not create a bounded, content-addressed private file.');
try {
CloudUploadStagingService::issue(
$qcowCapture,
11,
'cloud-template'
);
throw new RuntimeException(
'Retired direct-to-Agent cloud-template staging was accepted.'
);
} catch (InvalidArgumentException $expected) {
// Cloud templates now publish only through their immutable master.
}
CloudUploadStagingService::discard($qcowCapture);
$payload = "iso\0test-image";
$capture = CloudUploadStagingService::capture(
$request($payload, 'application/octet-stream',
(string) strlen($payload)),
'iso', 1, 1024
);
$first = CloudUploadStagingService::issue($capture, 11,
'cloud-template');
'rescue-template');
$second = CloudUploadStagingService::issue($capture, 12,
'cloud-template');
'rescue-template');
$assert($first['id'] !== $second['id']
&& $first['token'] !== $second['token']
&& (int) $first['size_bytes'] === strlen($payload)
@ -164,10 +185,10 @@ namespace {
$tamperCapture = CloudUploadStagingService::capture(
$request($tamperPayload, 'application/octet-stream',
(string) strlen($tamperPayload)),
'qcow2', 1, 1024
'iso', 1, 1024
);
$tamper = CloudUploadStagingService::issue($tamperCapture, 14,
'cloud-template');
'rescue-template');
file_put_contents($tamperCapture['path'],
str_repeat('x', strlen($tamperPayload)));
$expect(static fn () => CloudUploadStagingService::consume(
@ -187,7 +208,7 @@ namespace {
$first['id'], $first['token']
);
$assert($consumed['path'] === $capture['path']
&& $consumed['purpose'] === 'cloud-template'
&& $consumed['purpose'] === 'rescue-template'
&& CloudUploadStaging::find($first['id'])->consumed_at !== null,
'A valid bearer capability did not atomically consume its staging row.');
$expect(static fn () => CloudUploadStagingService::consume(
@ -239,6 +260,8 @@ namespace {
&& str_contains($controller,
"preg_match('/^Bearer ([A-Za-z0-9_-]{32,512})$/D'")
&& str_contains($controller, 'CloudUploadStagingService::consume(')
&& !str_contains($controller, "=== 'cloud-template'")
&& str_contains($controller, 'filename="rescue.iso"')
&& str_contains($controller, "->withHeader('Digest'")
&& str_contains($controller,
"->withHeader('Cache-Control', 'private, no-store, max-age=0')"),

@ -101,7 +101,7 @@ $assert(str_contains($jobs, 'vpc_id BIGINT UNSIGNED DEFAULT NULL')
'Cloud jobs cannot be correlated to VPC or VPC-port work.');
$assert(str_contains($setup,
"private const SCHEMA_VERSION = 'go-agent-wss-v15-template-reconciliation'")
"private const SCHEMA_VERSION = 'go-agent-wss-v16-template-artifacts'")
&& str_contains($setup, "'name' => 'cloud_vpc_enabled'")
&& str_contains($setup, "'value' => 'false'")
&& str_contains($setup,

Loading…
Cancel
Save