import http from 'node:http'; import https from 'node:https'; const consoleURL = process.env.SEA_CONSOLE_URL?.trim(); const connectHost = process.env.SEA_CONSOLE_CONNECT_HOST?.trim(); const adminEmail = process.env.SEA_ADMIN_EMAIL?.trim(); const adminPassword = process.env.SEA_ADMIN_PASSWORD; if (!consoleURL || !connectHost || !adminEmail || !adminPassword) process.exit(2); const base = new URL(consoleURL); if (base.protocol !== 'https:') throw new Error('production verification requires HTTPS'); function request(pathname, { method = 'GET', body, cookie, expected, protocol = 'https:' } = {}) { const payload = body === undefined ? undefined : Buffer.from(JSON.stringify(body)); const secure = protocol === 'https:'; const client = secure ? https : http; const port = secure ? Number(base.port || 443) : 80; const headers = { Accept: 'application/json', Host: base.host }; if (payload) { headers['Content-Type'] = 'application/json'; headers['Content-Length'] = payload.length; } if (cookie) headers.Cookie = cookie; return new Promise((resolve, reject) => { const req = client.request({ hostname: connectHost, port, path: pathname, method, headers, timeout: 20_000, ...(secure ? { servername: base.hostname, rejectUnauthorized: true } : {}), }, (response) => { let text = ''; response.setEncoding('utf8'); response.on('data', (chunk) => { text += chunk; }); response.on('end', () => { let decoded; try { decoded = text ? JSON.parse(text) : undefined; } catch { decoded = undefined; } const accepted = expected ? expected.includes(response.statusCode) : response.statusCode >= 200 && response.statusCode < 300; if (!accepted) return reject(new Error(`${method} ${pathname} returned HTTP ${response.statusCode}`)); resolve({ status: response.statusCode, headers: response.headers, payload: decoded, text }); }); }); req.on('timeout', () => req.destroy(new Error(`${method} ${pathname} timed out`))); req.on('error', reject); req.end(payload); }); } const health = await request('/healthz'); if (health.payload?.status !== 'ok') throw new Error('health endpoint did not report ok'); const setup = await request('/api/v1/setup/status'); if (setup.payload?.required !== false) throw new Error('setup endpoint is still open'); const login = await request('/api/v1/auth/login', { method: 'POST', body: { identifier: adminEmail, password: adminPassword } }); const cookie = login.headers['set-cookie']?.[0]?.split(';', 1)[0]; if (!cookie?.startsWith('sea_session=')) throw new Error('administrator session cookie is missing'); const [tenants, plans, approval, management, settings, home] = await Promise.all([ request('/api/v1/admin/tenants', { cookie }), request('/api/v1/admin/plans', { cookie }), request('/api/v1/admin/settings/domain-approval', { cookie }), request('/api/v1/admin/overview', { cookie }), request('/api/v1/admin/settings', { cookie }), request('/'), ]); if (!Array.isArray(management.payload?.users) || !Array.isArray(management.payload?.projects) || !Array.isArray(management.payload?.domains) || !Array.isArray(management.payload?.ipAddresses) || !Array.isArray(management.payload?.logs)) throw new Error('management overview shape is invalid'); if (settings.payload?.graceDays !== 3 || settings.payload?.recycleDays !== 7 || settings.payload?.backupRetentionDays !== 14 || settings.payload?.oidc?.bindingOnly !== true || settings.payload?.oidc?.passwordLogin !== true) throw new Error('management settings are invalid'); if ('secret' in (settings.payload?.smtp || {}) || 'secret' in (settings.payload?.oidc || {})) throw new Error('management settings exposed a stored secret'); const redirect = await request('/', { protocol: 'http:', expected: [301, 308] }); const location = String(redirect.headers.location || ''); if (!location.startsWith(`https://${base.hostname}`)) throw new Error('HTTP does not redirect to the management HTTPS origin'); for (const name of ['strict-transport-security', 'content-security-policy', 'x-content-type-options', 'x-frame-options']) { if (!home.headers[name]) throw new Error(`security header is missing: ${name}`); } console.log(JSON.stringify({ result: 'success', consoleURL: base.toString(), health: health.payload.status, setupClosed: true, administratorLogin: true, tenantCount: tenants.payload?.tenants?.length ?? null, planCount: plans.payload?.plans?.length ?? null, domainApproval: approval.payload?.enabled, managementOverview: true, lifecycle: `${settings.payload.graceDays}/${settings.payload.recycleDays}/${settings.payload.backupRetentionDays}`, ssoBindingOnly: true, httpsRedirect: true, securityHeaders: true, }, null, 2));