fix: remove account instance count cap

dev
admin 1 month ago
parent 13aacd7636
commit d3bba00f14

@ -42,6 +42,7 @@ cp config/.config.php.example config/config.php
- `db_prefix` 留空,网站域名、HTTPS Cookie、Redis/Valkey、账户安全、SMTP 按 venix 设置。
- `cloud_*` 默认路径适配 `/home/virt-cloud`,私有密钥自动生成;宿主机凭据稍后在页面设置。
- `cloud_max_renewal_periods_ahead` 限制单台实例可排队的未来续费账期,默认 24;不要设成无限值。
- 账户固定实例数量上限已删除。旧 `config.php` 若仍保留账户实例数量上限配置项,该项已不再读取,可在维护窗口手动删除;宿主机资源调度中的 `max_instances` 仍是有效的单宿主机容量策略。
- `cloud_introspection_url` 必须指向 PHP 网站,不是引擎 8000。默认 `http://127.0.0.1/api/internal/cloud/session-introspection`;多虚拟主机可设置 `cloud_introspection_host` 为网站域名,或改为正确的本机 HTTPS URL。
在**两个全新空数据库**分别导入,替换命令中的地址、端口、账号、库名;`-p` 提示密码,不把密码写入历史:

@ -40,7 +40,7 @@ PHP 不直接解密 Python 记录或执行任意 virsh 命令。主库与日志
## 购买状态机
1. 用户选择启用套餐、已有系统来源、公钥/强 root 密码,提交幂等键。
2. PHP 事务校验库存、宿主机与实例配额,保存不可由浏览器改写的规格快照和加密创建载荷,预留有限库存并生成开通账单;此时不扣钱、不创建引擎任务。
2. PHP 事务校验销售库存、宿主机面板容量与公网 IP 账本,保存不可由浏览器改写的规格快照和加密创建载荷,预留有限库存并生成开通账单;此时不扣钱、不创建引擎任务。账户不设固定实例数量上限。
3. 余额或在线支付结清账单后,同一事务才扣减钱包并创建唯一队列任务。未支付开通账单 30 分钟后失效,释放库存并清除其加密凭据载荷;晚到的在线付款只保留为账户余额。
4. 独立 `cloudWorker` 获取租约,携带唯一 `operation_id` 请求引擎。只有已支付且经过签名的开通上下文可以创建 VM。
5. 成功关联实例和凭据;确认创建失败且无残留时只退款、恢复库存一次。超时、引擎中断或残留无法确认时保持待核对,只查询原操作,不重复创建或盲目退款。

@ -7,6 +7,12 @@
- saleCatalog SQLite/WASM 首屏 smoke 通过;部署 SSR、资源调度、IP ledger、宿主机网络池/调度、模板编译、虚拟化资产和 Node JS 语法检查通过。完整财务流程继续执行到既有 reconciliation 场景后失败,不能把该失败归因于本次缺失列修复。
- 代码修复提交为 `e7230ff`,随后补充部署 smoke 与验证记录文档;提交链已推送到远端 `venix`。真实 PHP-FPM、MariaDB、浏览器和宿主机仍需部署验收;上线后应同时检查 `/user/cloud/deploy`、`/api/v1/catalog` 和 PHP-FPM 错误日志。
## 2026-10-07:移除账户实例数量上限
- 删除账户实例数量配置、购买事务中的账户级 409 检查,以及金融测试中依赖该限制的场景;账户实例数量现在只受销售库存、宿主机面板容量、reservation 和具体公网 IP 账本约束。
- 全仓精确搜索未发现该配置键或账户上限错误文案的 CSS、JS、SQL 残留;`cloud_host_capacity_policies.max_instances` 保留为单宿主机调度容量,分页大小和快照/防火墙等其他实例上限也未误删。
- 账户上限相关的财务流程已越过,完整金融测试仍在既有 reconciliation fixture 处失败;具体契约、模板、JS 语法和 `git diff --check` 通过。真实 PHP-FPM、MariaDB 和并发购买仍需部署环境验收。
## 2026-10-07:面板资源账本取代宿主机盘点
- 调度、创建放置和网络选项现在只读取面板配置的容量策略、活动资源池、reservation 账本和 `cloud_public_ips`;不再要求容量快照、盘点新鲜度、宿主机 `host/network-options` 或 VM discovery 结果。
@ -57,7 +63,7 @@
2026-09-27,集成代码的隔离验证,不代表生产验收。
- 当前 macOS 工作区 Python 3.12 回归:515 passed、10 skipped、55 subtests passed。覆盖原虚拟化逻辑及私有 API、签名/重放、多宿主机归属、持久幂等、一次性 VNC、退出后断权、带宽 XML、救援上传摘要,以及到期断网/恢复、同实例变更串行、多网卡 live+config 断网/恢复、退出救援保持计费断网、流量累计检查点和破坏性操作结果核对。生产仍按部署文档使用 Python 3.12 或更新的受支持版本复测。
- 隔离 PHP 8.5.10 验证源码语法、Smarty 模板、路由目标、精确金额/HMAC、SQLite 购买开通/退款/超时核对/配额/租户隔离、Cookie/Redis 会话撤销及内省、统一用户资源和 noVNC 模块。本次账期与生命周期用例应覆盖提前续费、精确扣款幂等、RX+TX 额度、断网不关机、下期恢复、到期仅断网、3 天宽限期内续费恢复,以及宽限期结束后的实例与受管磁盘删除;当前 macOS 工作区没有 PHP 可执行文件时,需在下方 PHP 8.5 环境命令中复跑。
- 隔离 PHP 8.5.10 验证源码语法、Smarty 模板、路由目标、精确金额/HMAC、SQLite 购买开通/退款/超时核对、宿主机面板容量/IP 账本、租户隔离、Cookie/Redis 会话撤销及内省、统一用户资源和 noVNC 模块;账户固定实例数量上限已删除。本次账期与生命周期用例应覆盖提前续费、精确扣款幂等、RX+TX 额度、断网不关机、下期恢复、到期仅断网、3 天宽限期内续费恢复,以及宽限期结束后的实例与受管磁盘删除;当前 macOS 工作区没有 PHP 可执行文件时,需在下方 PHP 8.5 环境命令中复跑。
- Chrome 使用模拟 API 检查套餐购买、VM 详情/指标/凭据、公钥、重装/救援、后台宿主机/镜像操作与 CSRF;用户账户及登录等页面进行桌面/手机布局检查。不连接真实数据库或宿主机。
- PHP 隔离环境不提供 sodium:`CloudSecretsTest` 明确跳过,原 Paytaro/易支付密钥加密测试因同一缺失无法运行;财务/会话测试的加密存储仅用明确标注的测试替身,不作为实际加密验证。生产必须安装 sodium,没有弱加密回退。
- Python 的跳过项需要真实 libvirt/网络环境。没有验证真实 MariaDB 并发、AlmaLinux systemd、宿主机 VM 操作、SMTP、支付和大文件上传。

@ -57,13 +57,6 @@ final class CloudOrderService
}
return $existing;
}
$maximum = max(1, (int) \App\Services\Config::get('cloud_max_instances_per_user', 20));
$active = CloudInstance::where('user_id', $user->id)->where('status', '<>', 'deleted')->count();
$reserved = CloudOrder::where('user_id', $user->id)->whereIn('status',
['awaiting_payment', 'queued', 'running', 'uncertain'])->count();
if ($active + $reserved >= $maximum) {
throw new CloudError('已达到账户虚拟机数量上限', 409);
}
// Generate only after an idempotency replay has been resolved, so
// retries return the original order and its original display name.
$name = $requestedName ?? self::automaticName($user);

@ -50,8 +50,6 @@ $System_Config['cloud_update_php_fpm_unit'] = 'php-fpm.service';
# VNC 持续检查 PHP 会话。设为面板服务器本机可访问的网站 URL,不要指向宿主机。
$System_Config['cloud_introspection_url'] = 'http://127.0.0.1/api/internal/cloud/session-introspection';
$System_Config['cloud_introspection_host'] = '';
# 每个账户最多持有的非删除实例数。
$System_Config['cloud_max_instances_per_user'] = 20;
# 单台实例最多排队的未来续费账期,防止免费套餐或自动化请求无限写入数据库。
$System_Config['cloud_max_renewal_periods_ahead'] = 24;
# redis

@ -0,0 +1,44 @@
<?php
// The account-wide instance cap was retired. Keep this boundary test small
// and static so it does not need a database or an engine fixture.
$root = dirname(__DIR__);
$orderService = file_get_contents($root . '/app/Services/Cloud/CloudOrderService.php');
$configExample = file_get_contents($root . '/config/.config.php.example');
$schema = file_get_contents($root . '/sql/cloud.sql');
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$retiredKey = implode('', ['cloud_max_', 'instances_per_user']);
$retiredMessage = implode('', ['已达到', '账户虚拟机数量上限']);
$assert(is_string($orderService) && is_string($configExample) && is_string($schema),
'Account instance-limit contract could not read its source boundaries.');
$assert(!str_contains($orderService, $retiredKey)
&& !str_contains($orderService, $retiredMessage),
'CloudOrderService still contains the retired account-wide instance cap.');
$assert(!str_contains($configExample, $retiredKey),
'The retired account-wide instance-cap setting remains in the example config.');
$assert(!str_contains($schema, $retiredKey)
&& str_contains($schema, 'max_instances INT UNSIGNED NOT NULL DEFAULT 0'),
'SQL must not add an account cap while retaining host capacity policy.');
foreach ([$root . '/public', $root . '/resources'] as $directory) {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS)
);
foreach ($files as $file) {
$extension = strtolower($file->getExtension());
if (!in_array($extension, ['css', 'js', 'tpl'], true)) {
continue;
}
$contents = file_get_contents($file->getPathname());
$assert(is_string($contents) && !str_contains($contents, $retiredKey),
'A frontend/template asset still references the retired account cap: '
. $file->getPathname());
}
}
echo "Account instance-limit removal contract passed.\n";

@ -2,7 +2,7 @@
// Financial/state-machine tests only. The isolated keyring double is NOT encryption and is never loaded by production.
namespace App\Services {
final class Config {
public static array $values = ['cloud_max_instances_per_user' => 20, 'cloud_engine_url' => 'http://127.0.0.1:8000', 'super_admin' => '99'];
public static array $values = ['cloud_engine_url' => 'http://127.0.0.1:8000', 'super_admin' => '99'];
public static function get($name, $default = null) { return self::$values[$name] ?? $default; }
}
final class Auth { public static $user; public static function getUser() { return self::$user; } }
@ -422,21 +422,11 @@ namespace {
&& CloudPublicIp::find($openingReservation->public_ip_id)->state === 'assigned',
'A late uncertainty marker rolled a committed reservation or assigned IP backward.');
// One active instance plus one unpaid reservation must exhaust a limit of
// two. Expiry releases finite stock and the encrypted credential exactly
// once without ever entering the worker queue or touching the wallet.
\App\Services\Config::$values['cloud_max_instances_per_user'] = 2;
// An unpaid provisioning reservation expires without entering the worker
// queue, changing the wallet, or retaining its encrypted credential.
$abandoned = CloudOrderService::purchase(array_replace($input, [
'name' => 'vm-abandoned', 'idempotency_key' => 'test-request-key-abandoned',
]), $actor);
try {
CloudOrderService::purchase(array_replace($input, [
'name' => 'vm-over-limit', 'idempotency_key' => 'test-request-key-over-limit',
]), $actor);
throw new RuntimeException('Unpaid provisioning reservation bypassed the instance limit.');
} catch (CloudError $e) {
$assert($e->httpStatus === 409, 'Reserved instance limit returned the wrong status.');
}
$abandonedInvoice = CloudInvoice::where('order_id', $abandoned->id)->first();
$abandonedInvoice->due_at = time() - 1;
$abandonedInvoice->save();
@ -449,8 +439,6 @@ namespace {
&& User::find(1)->money === '90.01'
&& CloudOffer::find(1)->stock === 9,
'Expired opening invoice queued work, changed money, retained credentials, or released stock more than once.');
\App\Services\Config::$values['cloud_max_instances_per_user'] = 20;
$assert(CloudAccess::instance((string) $instance->id, $actor)->id === $instance->id, 'Owner denied own VM.');
$other = array_replace($actor, ['user_id' => 2]);
try { CloudAccess::instance((string) $instance->id, $other); throw new RuntimeException('Tenant isolation failed.'); } catch (CloudError $e) { $assert($e->httpStatus === 404, 'Nonowner information leaked.'); }
@ -519,9 +507,6 @@ namespace {
&& User::find(1)->money === '80.02'
&& CloudMailOutbox::where('kind', 'provision_succeeded')->count() === 2,
'Reconciliation did not recover exactly once or queue its success email.');
\App\Services\Config::$values['cloud_max_instances_per_user'] = 2;
try { CloudOrderService::purchase(array_replace($input, ['name' => 'vm-four', 'idempotency_key' => 'test-request-key-0004']), $actor); throw new RuntimeException('Quota bypass.'); } catch (CloudError $e) { $assert($e->httpStatus === 409, 'Quota response incorrect.'); }
$assert(User::find(1)->money === '80.02' && CloudOrder::count() === 4, 'Rejected order altered finance.');
$actionJob = CloudJobService::enqueue($instance, $actor, 'action', 'POST', '/actions', ['action' => 'reboot']);
$mock->append(new Response(200, [], '{"status":"succeeded","uuid":"11111111-1111-4111-8111-111111111111","state":"running"}')); $worker->tick();
$last = end($history)['request']; $signedActor = json_decode(base64_decode(strtr($last->getHeaderLine('X-Cloud-Actor'), '-_', '+/')), true);
@ -1146,7 +1131,6 @@ namespace {
// Provider callbacks credit the wallet before the invoice bridge runs.
// That credit must be consumed once, queue one create job, and remain
// idempotent when the payment provider retries its callback.
\App\Services\Config::$values['cloud_max_instances_per_user'] = 20;
$providerOrder = CloudOrderService::purchase(array_replace($input, [
'name' => 'vm-provider-payment',
'idempotency_key' => 'test-request-key-provider-payment',
@ -1189,7 +1173,6 @@ namespace {
// A blank optional label is normalized before hashing, but generated only
// for a genuinely new order. Replaying the same request with an explicit
// empty field must therefore return the original generated display name.
\App\Services\Config::$values['cloud_max_instances_per_user'] = 100;
$automaticInput = array_replace($input, [
'idempotency_key' => 'test-request-key-automatic-name',
]);

Loading…
Cancel
Save