feat(vpc): add control-plane schema foundation

go
codex 4 weeks ago
parent 966048cb5c
commit 54dcecd516

@ -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-v12-object-cleanup-v1';
private const SCHEMA_VERSION = 'go-agent-wss-v13-vpc-l3-v1';
private const MAIN_TABLES = [
'cloud_regions', 'cloud_network_lines', 'cloud_resource_pools',
'cloud_hosts', 'cloud_host_agents',
@ -18,8 +18,10 @@ final class CloudSetup
'cloud_rescue_template_imports', 'cloud_upload_staging',
'cloud_host_resource_pool_memberships',
'cloud_host_network_attachments', 'cloud_public_ip_pools',
'cloud_host_vpc_transports', 'cloud_vpc_cidr_pools',
'cloud_host_capacity_policies', 'cloud_public_ips', 'cloud_offers',
'cloud_instances', 'cloud_instance_firewalls',
'cloud_instances', 'cloud_vpcs', 'cloud_vpc_ports',
'cloud_vpc_host_states', 'cloud_instance_firewalls',
'cloud_instance_firewall_versions', 'cloud_instance_firewall_rules',
'cloud_platform_test_policy_state',
'cloud_platform_test_policy_rules', 'cloud_instance_snapshots',
@ -52,6 +54,7 @@ final class CloudSetup
'id', 'operation_id', 'request_idempotency_key',
'request_fingerprint', 'parent_job_id', 'user_id', 'host_id',
'backup_id', 'backup_restore_id', 'backup_recovery_id',
'vpc_id', 'vpc_port_id',
'kind', 'execution_mode', 'phase', 'outcome', 'status',
'attempts', 'dispatch_attempts', 'dispatch_deadline_at',
'dispatch_started_at', 'agent_accepted_at',
@ -62,6 +65,36 @@ final class CloudSetup
'lease_token', 'lease_until', 'available_at', 'error_code',
'result_json', 'created_at', 'updated_at',
],
'cloud_host_vpc_transports' => [
'host_id', 'transport_address', 'transport_prefix_length',
'transport_interface', 'transport_mode', 'mtu',
'desired_revision', 'observed_revision', 'sync_state',
'last_operation_id', 'last_error_code', 'last_verified_at',
'created_at', 'updated_at',
],
'cloud_vpc_cidr_pools' => [
'id', 'pool_key', 'region_id', 'name', 'cidr',
'prefix_length', 'allocation_prefix', 'state',
'created_at', 'updated_at',
],
'cloud_vpcs' => [
'id', 'vpc_key', 'user_id', 'region_id', 'cidr_pool_id',
'name', 'cidr', 'prefix_length', 'gateway', 'state',
'desired_revision', 'deleted_at', 'created_at', 'updated_at',
],
'cloud_vpc_ports' => [
'id', 'port_key', 'vpc_id', 'instance_id', 'user_id',
'private_ip', 'mac_address', 'active_claim', 'state',
'desired_revision', 'applied_revision', 'last_operation_id',
'last_error_code', 'attached_at', 'released_at',
'created_at', 'updated_at',
],
'cloud_vpc_host_states' => [
'id', 'vpc_id', 'host_id', 'desired_revision',
'applied_revision', 'desired_digest', 'applied_digest',
'sync_state', 'last_operation_id', 'last_error_code',
'last_success_at', 'last_failure_at', 'created_at', 'updated_at',
],
'cloud_agent_completion_events' => [
'event_id', 'host_id', 'operation_id', 'payload_sha256',
'outcome', 'effect_may_have_applied', 'safe_to_resubmit',
@ -171,6 +204,29 @@ final class CloudSetup
],
];
private const REQUIRED_CHECKS = [
'cloud_host_vpc_transports' => [
'chk_cloud_host_vpc_transport_prefix',
'chk_cloud_host_vpc_transport_mode',
'chk_cloud_host_vpc_transport_mtu',
'chk_cloud_host_vpc_transport_state',
'chk_cloud_host_vpc_transport_revision',
],
'cloud_vpc_cidr_pools' => [
'chk_cloud_vpc_cidr_pool_prefix',
'chk_cloud_vpc_cidr_pool_state',
],
'cloud_vpcs' => [
'chk_cloud_vpc_prefix', 'chk_cloud_vpc_state',
'chk_cloud_vpc_deleted_at',
],
'cloud_vpc_ports' => [
'chk_cloud_vpc_port_active_claim',
'chk_cloud_vpc_port_state', 'chk_cloud_vpc_port_release',
'chk_cloud_vpc_port_revision',
],
'cloud_vpc_host_states' => [
'chk_cloud_vpc_host_state', 'chk_cloud_vpc_host_revision',
],
'cloud_backup_subscriptions' => [
'chk_cloud_backup_subscription_frequency',
'chk_cloud_backup_subscription_weekday',
@ -203,12 +259,36 @@ final class CloudSetup
],
];
private const REQUIRED_INDEXES = [
'cloud_host_vpc_transports' => [
'PRIMARY', 'cloud_host_vpc_transport_operation',
'cloud_host_vpc_transport_state',
],
'cloud_vpc_cidr_pools' => [
'PRIMARY', 'cloud_vpc_cidr_pool_key',
'cloud_vpc_cidr_pool_region', 'cloud_vpc_cidr_pool_catalog',
],
'cloud_vpcs' => [
'PRIMARY', 'cloud_vpc_key', 'cloud_vpc_region_cidr',
'cloud_vpc_owner', 'cloud_vpc_region_state',
'cloud_vpc_pool_state',
],
'cloud_vpc_ports' => [
'PRIMARY', 'cloud_vpc_port_key', 'cloud_vpc_port_ip_claim',
'cloud_vpc_port_instance_claim', 'cloud_vpc_port_mac',
'cloud_vpc_port_operation', 'cloud_vpc_port_owner',
'cloud_vpc_port_vpc_state',
],
'cloud_vpc_host_states' => [
'PRIMARY', 'cloud_vpc_host_identity',
'cloud_vpc_host_operation', 'cloud_vpc_host_sync',
],
'cloud_jobs' => [
'PRIMARY', 'uniq_cloud_operation', 'uniq_cloud_job_request',
'uniq_cloud_job_completion_event', 'uniq_cloud_provision_order',
'cloud_job_poll', 'cloud_job_receipt_deadline',
'cloud_job_backup', 'cloud_job_backup_restore',
'cloud_job_backup_recovery',
'cloud_job_vpc', 'cloud_job_vpc_port',
],
'cloud_agent_completion_events' => [
'PRIMARY', 'uniq_cloud_completion_operation',
@ -395,6 +475,10 @@ final class CloudSetup
'name' => 'cloud_network_lines_enabled',
'value' => 'false',
]);
$connection->table('configurations')->insertOrIgnore([
'name' => 'cloud_vpc_enabled',
'value' => 'false',
]);
}
/** Refuse to mix the Go/Agent schema with any unmarked cloud database. */

@ -0,0 +1,22 @@
<?php
namespace App\Models;
final class CloudHostVpcTransport extends Model
{
protected $connection = 'default';
protected $table = 'cloud_host_vpc_transports';
protected $primaryKey = 'host_id';
public $incrementing = false;
protected $casts = [
'host_id' => 'int',
'transport_prefix_length' => 'int',
'mtu' => 'int',
'desired_revision' => 'int',
'observed_revision' => 'int',
'last_verified_at' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
}

@ -11,6 +11,8 @@ final class CloudJob extends Model
'backup_id' => 'int',
'backup_restore_id' => 'int',
'backup_recovery_id' => 'int',
'vpc_id' => 'int',
'vpc_port_id' => 'int',
];
/**

@ -0,0 +1,21 @@
<?php
namespace App\Models;
final class CloudVpc extends Model
{
protected $connection = 'default';
protected $table = 'cloud_vpcs';
protected $casts = [
'id' => 'int',
'user_id' => 'int',
'region_id' => 'int',
'cidr_pool_id' => 'int',
'prefix_length' => 'int',
'desired_revision' => 'int',
'deleted_at' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
}

@ -0,0 +1,18 @@
<?php
namespace App\Models;
final class CloudVpcCidrPool extends Model
{
protected $connection = 'default';
protected $table = 'cloud_vpc_cidr_pools';
protected $casts = [
'id' => 'int',
'region_id' => 'int',
'prefix_length' => 'int',
'allocation_prefix' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
}

@ -0,0 +1,21 @@
<?php
namespace App\Models;
final class CloudVpcHostState extends Model
{
protected $connection = 'default';
protected $table = 'cloud_vpc_host_states';
protected $casts = [
'id' => 'int',
'vpc_id' => 'int',
'host_id' => 'int',
'desired_revision' => 'int',
'applied_revision' => 'int',
'last_success_at' => 'int',
'last_failure_at' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
}

@ -0,0 +1,23 @@
<?php
namespace App\Models;
final class CloudVpcPort extends Model
{
protected $connection = 'default';
protected $table = 'cloud_vpc_ports';
protected $casts = [
'id' => 'int',
'vpc_id' => 'int',
'instance_id' => 'int',
'user_id' => 'int',
'active_claim' => 'bool',
'desired_revision' => 'int',
'applied_revision' => 'int',
'attached_at' => 'int',
'released_at' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
}

@ -0,0 +1,47 @@
<?php
namespace App\Services\Cloud;
use App\Models\Configurations;
/** Fail-closed presentation and mutation gate for the L3 VPC feature. */
final class CloudVpcFeature
{
public const CONFIG_KEY = 'cloud_vpc_enabled';
private static $cached = null;
public static function enabled(): bool
{
if (is_bool(self::$cached)) {
return self::$cached;
}
try {
$value = Configurations::where('name', self::CONFIG_KEY)
->value('value');
} catch (\Throwable $error) {
error_log('Unable to read the VPC feature switch: '
. get_class($error));
return self::$cached = false;
}
return self::$cached = self::valueIsEnabled($value);
}
public static function save(bool $enabled): void
{
$row = Configurations::where('name', self::CONFIG_KEY)->first();
if ($row === null) {
$row = new Configurations();
$row->name = self::CONFIG_KEY;
}
$row->value = $enabled ? 'true' : 'false';
$row->save();
self::$cached = $enabled;
}
private static function valueIsEnabled($value): bool
{
return in_array(strtolower(trim((string) $value)),
['1', 'true', 'yes', 'on'], true);
}
}

@ -147,6 +147,70 @@ CREATE TABLE cloud_host_network_attachments (
KEY cloud_network_attachment_sync (sync_state, updated_at, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- A host's existing private underlay remains operator-owned. The panel stores
-- only the selected address/interface and desired generation; the Agent
-- verifies the binding and applies tenant VPC routes without configuring the
-- physical address, bridge or upstream gateway itself.
CREATE TABLE cloud_host_vpc_transports (
host_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
transport_address VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
transport_prefix_length TINYINT UNSIGNED NOT NULL,
transport_interface VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
transport_mode VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'direct_l3',
mtu SMALLINT UNSIGNED NOT NULL DEFAULT 1500,
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
sync_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
last_verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
UNIQUE KEY cloud_host_vpc_transport_operation (last_operation_id),
KEY cloud_host_vpc_transport_state (sync_state, updated_at, host_id),
CONSTRAINT chk_cloud_host_vpc_transport_prefix CHECK (
transport_prefix_length BETWEEN 1 AND 32
),
CONSTRAINT chk_cloud_host_vpc_transport_mode CHECK (
transport_mode = 'direct_l3'
),
CONSTRAINT chk_cloud_host_vpc_transport_mtu CHECK (
mtu BETWEEN 576 AND 9216
),
CONSTRAINT chk_cloud_host_vpc_transport_state CHECK (
sync_state IN ('never','pending','applying','ready','failed','unknown')
),
CONSTRAINT chk_cloud_host_vpc_transport_revision CHECK (
observed_revision <= desired_revision
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Region-scoped IPv4 supernets are the only source of tenant VPC CIDRs. The
-- application locks one pool row while selecting a free child prefix, so
-- concurrent VPC creation cannot allocate overlapping networks.
CREATE TABLE cloud_vpc_cidr_pools (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
pool_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
region_id BIGINT UNSIGNED NOT NULL,
name VARCHAR(80) NOT NULL,
cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
prefix_length TINYINT UNSIGNED NOT NULL,
allocation_prefix TINYINT UNSIGNED NOT NULL DEFAULT 24,
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'active',
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
UNIQUE KEY cloud_vpc_cidr_pool_key (pool_key),
UNIQUE KEY cloud_vpc_cidr_pool_region (region_id, cidr),
KEY cloud_vpc_cidr_pool_catalog (region_id, state, id),
CONSTRAINT chk_cloud_vpc_cidr_pool_prefix CHECK (
prefix_length BETWEEN 8 AND 28
AND allocation_prefix BETWEEN prefix_length AND 28
),
CONSTRAINT chk_cloud_vpc_cidr_pool_state CHECK (
state IN ('active','disabled')
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- A public pool is an allocation boundary, not a compute resource pool. The
-- child cloud_public_ips rows remain the authoritative concrete-address
-- ledger used by payment-time placement and reconciliation.
@ -406,6 +470,115 @@ CREATE TABLE cloud_instances (
KEY cloud_instance_placement (resource_pool_id, host_id, status),
KEY cloud_instance_lifecycle (service_status, expires_at, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- One user-owned L3 VPC belongs to exactly one commercial region. V1 assigns
-- non-overlapping IPv4 prefixes from a region pool and exposes no cross-region
-- peering, NAT or L2 broadcast contract.
CREATE TABLE cloud_vpcs (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
vpc_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
user_id BIGINT UNSIGNED NOT NULL,
region_id BIGINT UNSIGNED NOT NULL,
cidr_pool_id BIGINT UNSIGNED NOT NULL,
name VARCHAR(80) NOT NULL,
cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
prefix_length TINYINT UNSIGNED NOT NULL,
gateway VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'provisioning',
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
deleted_at BIGINT UNSIGNED DEFAULT NULL,
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
UNIQUE KEY cloud_vpc_key (vpc_key),
UNIQUE KEY cloud_vpc_region_cidr (region_id, cidr),
KEY cloud_vpc_owner (user_id, state, id),
KEY cloud_vpc_region_state (region_id, state, id),
KEY cloud_vpc_pool_state (cidr_pool_id, state, id),
CONSTRAINT chk_cloud_vpc_prefix CHECK (
prefix_length BETWEEN 16 AND 28
),
CONSTRAINT chk_cloud_vpc_state CHECK (
state IN ('provisioning','active','degraded','deleting','deleted')
),
CONSTRAINT chk_cloud_vpc_deleted_at CHECK (
(state = 'deleted' AND deleted_at IS NOT NULL)
OR (state <> 'deleted' AND deleted_at IS NULL)
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- VPC ports retain an immutable allocation audit. active_claim is set to NULL
-- only after every affected Agent has confirmed removal; MySQL then permits a
-- later port to reuse the released instance/IP while keeping the old row.
CREATE TABLE cloud_vpc_ports (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
port_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
vpc_id BIGINT UNSIGNED NOT NULL,
instance_id BIGINT UNSIGNED NOT NULL,
user_id BIGINT UNSIGNED NOT NULL,
private_ip VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
mac_address CHAR(17) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
active_claim TINYINT UNSIGNED DEFAULT 1,
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'reserved',
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
applied_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
attached_at BIGINT UNSIGNED DEFAULT NULL,
released_at BIGINT UNSIGNED DEFAULT NULL,
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
UNIQUE KEY cloud_vpc_port_key (port_key),
UNIQUE KEY cloud_vpc_port_ip_claim (vpc_id, private_ip, active_claim),
UNIQUE KEY cloud_vpc_port_instance_claim (instance_id, active_claim),
UNIQUE KEY cloud_vpc_port_mac (mac_address),
UNIQUE KEY cloud_vpc_port_operation (last_operation_id),
KEY cloud_vpc_port_owner (user_id, state, id),
KEY cloud_vpc_port_vpc_state (vpc_id, state, id),
CONSTRAINT chk_cloud_vpc_port_active_claim CHECK (
active_claim IS NULL OR active_claim = 1
),
CONSTRAINT chk_cloud_vpc_port_state CHECK (
state IN ('reserved','preparing','attached','detaching',
'release_pending','released')
),
CONSTRAINT chk_cloud_vpc_port_release CHECK (
(state = 'released' AND active_claim IS NULL AND released_at IS NOT NULL)
OR (state <> 'released' AND active_claim IS NOT NULL
AND active_claim = 1 AND released_at IS NULL)
),
CONSTRAINT chk_cloud_vpc_port_revision CHECK (
applied_revision <= desired_revision
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Per-host desired/applied generations make one VPC reconciliation observable
-- without turning individual route commands into panel state. Unknown Agent
-- effects retain the original operation ID until an inspection converges.
CREATE TABLE cloud_vpc_host_states (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
vpc_id BIGINT UNSIGNED NOT NULL,
host_id BIGINT UNSIGNED NOT NULL,
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
applied_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
applied_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
sync_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
last_success_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
last_failure_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
UNIQUE KEY cloud_vpc_host_identity (vpc_id, host_id),
UNIQUE KEY cloud_vpc_host_operation (last_operation_id),
KEY cloud_vpc_host_sync (host_id, sync_state, updated_at, vpc_id),
CONSTRAINT chk_cloud_vpc_host_state CHECK (
sync_state IN ('pending','applying','ready','failed','unknown')
),
CONSTRAINT chk_cloud_vpc_host_revision CHECK (
applied_revision <= desired_revision
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Desired/applied host-enforced firewall state. The policy row is the current
-- tenant view, immutable versions retain idempotency/audit evidence, and rules
-- contain only the typed public DTO (never hypervisor XML or host commands).
@ -1024,6 +1197,8 @@ CREATE TABLE cloud_jobs (
backup_id BIGINT UNSIGNED DEFAULT NULL,
backup_restore_id BIGINT UNSIGNED DEFAULT NULL,
backup_recovery_id BIGINT UNSIGNED DEFAULT NULL,
vpc_id BIGINT UNSIGNED DEFAULT NULL,
vpc_port_id BIGINT UNSIGNED DEFAULT NULL,
user_id INT NOT NULL,
host_id BIGINT UNSIGNED DEFAULT NULL,
kind VARCHAR(32) NOT NULL,
@ -1139,6 +1314,8 @@ CREATE TABLE cloud_jobs (
KEY cloud_job_backup (backup_id, id),
KEY cloud_job_backup_restore (backup_restore_id, id),
KEY cloud_job_backup_recovery (backup_recovery_id, id),
KEY cloud_job_vpc (vpc_id, id),
KEY cloud_job_vpc_port (vpc_port_id, id),
KEY cloud_job_overview_state (kind, order_id, phase, outcome, terminal_at, created_at),
KEY cloud_job_owner (user_id, id),
KEY cloud_job_parent (parent_job_id, id)

@ -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-v12-object-cleanup-v1'")
"SCHEMA_VERSION = 'go-agent-wss-v13-vpc-l3-v1'")
&& !str_contains($setup, "SCHEMA_VERSION = 'go-v1'"),
'Outbound Agent schema must reject the incompatible earlier Go database.');
$assert(str_contains($schema,
@ -38,7 +38,9 @@ foreach (['cloud_host_agents', 'cloud_templates', 'cloud_hosts', 'cloud_instance
'cloud_backup_subscriptions', 'cloud_backup_period_entitlements',
'cloud_backup_restores',
'cloud_backup_recoveries', 'cloud_order_items', 'cloud_invoice_items',
'cloud_instance_migrations', 'cloud_peer_migration_artifacts'] as $table) {
'cloud_instance_migrations', 'cloud_peer_migration_artifacts',
'cloud_host_vpc_transports', 'cloud_vpc_cidr_pools', 'cloud_vpcs',
'cloud_vpc_ports', 'cloud_vpc_host_states'] as $table) {
$assert(str_contains($schema, 'CREATE TABLE ' . $table . ' ('),
'Missing fresh-install table: ' . $table);
}

@ -0,0 +1,114 @@
<?php
// Static VPC data-boundary checks. This test intentionally requires no
// database, Agent, network namespace or application bootstrap.
$root = dirname(__DIR__);
$schema = file_get_contents($root . '/sql/cloud.sql');
$setup = file_get_contents($root . '/app/Command/CloudSetup.php');
$feature = file_get_contents(
$root . '/app/Services/Cloud/CloudVpcFeature.php'
);
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
foreach ([
'cloud_host_vpc_transports',
'cloud_vpc_cidr_pools',
'cloud_vpcs',
'cloud_vpc_ports',
'cloud_vpc_host_states',
] as $table) {
$assert(str_contains($schema, 'CREATE TABLE ' . $table . ' ('),
'Missing VPC table: ' . $table);
$assert(str_contains($setup, "'" . $table . "'"),
'cloudInit does not require VPC table: ' . $table);
}
$assert(str_contains($schema,
'transport_address VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL')
&& str_contains($schema,
'transport_interface VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL')
&& str_contains($schema,
"transport_mode VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'direct_l3'")
&& str_contains($schema, 'observed_revision <= desired_revision')
&& str_contains($schema, 'cloud_host_vpc_transport_state'),
'Host VPC transport intent or convergence fields are incomplete.');
$assert(str_contains($schema, 'cloud_vpc_cidr_pool_region (region_id, cidr)')
&& str_contains($schema,
'allocation_prefix BETWEEN prefix_length AND 28')
&& str_contains($schema, 'cloud_vpc_region_cidr (region_id, cidr)')
&& str_contains($schema, 'cloud_vpc_pool_state (cidr_pool_id, state, id)'),
'Region-scoped VPC CIDR allocation is not protected.');
$assert(str_contains($schema,
'cloud_vpc_port_ip_claim (vpc_id, private_ip, active_claim)')
&& str_contains($schema,
'cloud_vpc_port_instance_claim (instance_id, active_claim)')
&& str_contains($schema, 'active_claim IS NULL OR active_claim = 1')
&& str_contains($schema,
"state = 'released' AND active_claim IS NULL AND released_at IS NOT NULL")
&& str_contains($schema, 'applied_revision <= desired_revision'),
'VPC port allocation, release or revision invariants are incomplete.');
$assert(str_contains($schema,
'cloud_vpc_host_identity (vpc_id, host_id)')
&& str_contains($schema,
'cloud_vpc_host_sync (host_id, sync_state, updated_at, vpc_id)')
&& str_contains($schema,
'UNIQUE KEY cloud_vpc_host_operation (last_operation_id)')
&& str_contains($schema,
"sync_state IN ('pending','applying','ready','failed','unknown')"),
'Per-host VPC desired/applied convergence ledger is incomplete.');
$jobsStart = strpos($schema, 'CREATE TABLE cloud_jobs (');
$jobsEnd = strpos($schema, ') ENGINE=InnoDB', $jobsStart);
$jobs = $jobsStart === false || $jobsEnd === false ? ''
: substr($schema, $jobsStart, $jobsEnd - $jobsStart);
$assert(str_contains($jobs, 'vpc_id BIGINT UNSIGNED DEFAULT NULL')
&& str_contains($jobs, 'vpc_port_id BIGINT UNSIGNED DEFAULT NULL')
&& str_contains($jobs, 'KEY cloud_job_vpc (vpc_id, id)')
&& str_contains($jobs, 'KEY cloud_job_vpc_port (vpc_port_id, id)'),
'Cloud jobs cannot be correlated to VPC or VPC-port work.');
$assert(str_contains($setup,
"private const SCHEMA_VERSION = 'go-agent-wss-v13-vpc-l3-v1'")
&& str_contains($setup, "'name' => 'cloud_vpc_enabled'")
&& str_contains($setup, "'value' => 'false'")
&& str_contains($setup, "'cloud_job_vpc', 'cloud_job_vpc_port'")
&& str_contains($setup, "'chk_cloud_vpc_port_release'"),
'cloudInit does not publish and validate the disabled VPC schema.');
$assert(str_contains($feature,
"public const CONFIG_KEY = 'cloud_vpc_enabled'")
&& str_contains($feature, 'public static function enabled(): bool')
&& str_contains($feature, 'return self::$cached = false;')
&& str_contains($feature, 'public static function save(bool $enabled): void'),
'The fail-closed VPC feature switch is incomplete.');
$models = [
'CloudHostVpcTransport' => 'cloud_host_vpc_transports',
'CloudVpcCidrPool' => 'cloud_vpc_cidr_pools',
'CloudVpc' => 'cloud_vpcs',
'CloudVpcPort' => 'cloud_vpc_ports',
'CloudVpcHostState' => 'cloud_vpc_host_states',
];
foreach ($models as $class => $table) {
$source = file_get_contents($root . '/app/Models/' . $class . '.php');
$assert($source !== false
&& str_contains($source, 'final class ' . $class . ' extends Model')
&& str_contains($source, "protected \$table = '" . $table . "';")
&& str_contains($source, 'protected $casts = ['),
'Missing or incomplete VPC model: ' . $class);
}
$jobModel = file_get_contents($root . '/app/Models/CloudJob.php');
$assert(str_contains($jobModel, "'vpc_id' => 'int'")
&& str_contains($jobModel, "'vpc_port_id' => 'int'"),
'CloudJob does not cast VPC correlations.');
echo "VPC schema, model and feature-switch contracts passed.\n";
Loading…
Cancel
Save