Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 38 additions & 37 deletions platform/meta/design-docs/0095-security-audits.md

Large diffs are not rendered by default.

35 changes: 29 additions & 6 deletions platform/meta/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,26 @@ The `deploy` and `deploy:staging` scripts in `platform/package.json` target thes

### GitHub Actions

| Workflow | Purpose |
| ----------------------------- | ------------------------------------------------------------ |
| `platform-ci.yml` | Source validation and database schema compatibility checks |
| `platform-deploy.yml` | Production deployment from `prod` |
| `platform-deploy-staging.yml` | Staging deployment from `main` |
| `platform-smoke-test.yml` | Deploy and exercise a disposable kitchen-sink app in staging |
| Workflow | Purpose |
| -------------------------------------- | ----------------------------------------------------------------- |
| `platform-ci.yml` | Source validation and database schema compatibility checks |
| `platform-deploy.yml` | Production deployment from `prod` |
| `platform-deploy-staging.yml` | Staging deployment from `main` |
| `platform-smoke-test.yml` | Deploy and exercise a disposable kitchen-sink app in staging |
| `platform-security-scanner-images.yml` | Publish the Engine A / C security scanner images to ghcr (manual) |

These deployment and smoke-test workflows target Void Cloud, from `prod` for production or `main` for staging, with `VOID_PLATFORM_DEPLOY_ENABLED=true`. They use the `Prod` and `Staging` GitHub environments. Restrict those environments to the same refs and appropriate reviewers, and keep deployment credentials in environment secrets. Forks use their own source-runtime release workflow.

Both deploy workflows serialize deployments without cancelling an active rollout. Advancing `prod` requests a production deployment. A failed or interrupted deployment needs inspection before another rollout, particularly when database migrations already ran.

Hosted API and email gateway deploys report the release version from `packages/platform/package.json` as `PLATFORM_VERSION`. The `void` CLI refuses platforms older than its minimum platform version, so release in this order: advance `prod` and wait for the production deployment to succeed, then push the release tag that publishes the npm packages.

When `platform/packages/security-scanner` changes, also before advancing `prod`:

1. Run "Publish Security Scanner Images" with `gh workflow run platform-security-scanner-images.yml --ref main`.
2. Commit the two digests from the run summary to `platform/packages/api/src/security/scanner-images.json`.
3. After staging deploys that commit, run the security smoke test against staging: `node platform/scripts/security-smoke-test.ts` (see [its README](../scripts/security-smoke-test.md)).

Consult the workflow files for their current inputs. Store credentials in the
selected GitHub environment and the deployment owner's secret manager. Keep
secret-manager locations, account access assignments and credential-issuance
Expand Down Expand Up @@ -148,6 +155,22 @@ openssl pkcs8 -topk8 -nocrypt -in github-app-pkcs1.pem -out github-app-pkcs8.pem

Container builds use the configured `BuildManager` or `BuildManagerLarge` class for the project's plan. GitHub Actions builds run in the repository's Actions environment and authenticate through `/auth/github-oidc`. Follow build logs with `void platform build logs <build-id> --follow`.

## Security audits on Void Cloud

Hosted has the `securityAudits` capability on. Scan defaults to Off; an admin sets it on the admin Security page. The first move away from Off runs the probe and creates the scanner (controller Worker, gate, copy namespace, container apps, image copies). This can take a few minutes; the page waits for it.

The runtime `CF_API_TOKEN` needs:

| Permission | Used for |
| ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| Account → Containers → Edit, Account → Cloudchamber → Edit | Container apps, image preparation, registry credentials for the Engine A / C image copy |
| Account → Workers Scripts → Edit | Controller Worker, copy sandbox, dispatch namespace, gate and runtime copy scripts |
| Account → D1 → Edit, Workers KV Storage → Edit, Workers R2 Storage → Edit | Runtime copy stores, the live D1 schema read, and the hourly copy sweep |
| Account → Workers AI → Read | `openai/*` and `anthropic/*` calls through AI Gateway (`/ai/v1`) |
| Account → Account Analytics → Read | Gateway cost of ended scans (GraphQL) |

`@cf/*` models use the API Worker's `AI` binding. Engines A and C (`anthropic/*`, `openai/*`) also need Unified Billing credits on the account or saved BYOK keys. The pull request comment needs the GitHub App permission described in [GitHub Deployment Integration](#github-deployment-integration).

## Email

The dedicated email gateway receives inbound mail and dispatches bounded requests to tenant handlers. The proxy handles outbound sends and receipt verification. The API owns zone connections, exact domain assignments, policy, quota reservations, and durable operation and delivery records in PostgreSQL.
Expand Down
1 change: 1 addition & 0 deletions platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@void/platform": "workspace:*",
"playwright": "catalog:",
"typescript": "catalog:",
"undici": "^7.30.2",
"valibot": "^1.5.0",
"vite-plus": "catalog:",
"void": "workspace:*"
Expand Down
4 changes: 2 additions & 2 deletions platform/packages/api/src/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const HOSTED_CAPABILITIES: PlatformCapabilities = {
googleOAuth: true,
managedBuilds: true,
sandbox: true,
// Off until hosted turns it on in wrangler.jsonc (AI binding) and here.
securityAudits: false,
// The admin Security page turns scanning on (Scan defaults to Off).
securityAudits: true,
};

const CAPABILITY_NAMES = Object.keys(HOSTED_CAPABILITIES) as Array<keyof PlatformCapabilities>;
Expand Down
6 changes: 5 additions & 1 deletion platform/packages/api/src/security/maintenance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ export async function runSecurityMaintenance(
releaseStrandedSecurityScanReserves(db),
);
// After the reaper, so a copy of a scan it just ended goes in the same run.
const copiesReaped = await step('runtime copies', 0, () => deps.reapCopies());
// A copy needs the scanner, which only the probe sets up and records as the entitlement.
// Before the first probe (hosted with Scan never turned on) skip the Cloudflare listing.
const copiesReaped = await step('runtime copies', 0, () =>
policy.entitlement ? deps.reapCopies() : Promise.resolve(0),
);
// Ended scans keep their cost row while the policy is Off too (Scans screen, spec §16).
const gatewayCosts = await step('gateway cost', 0, () => deps.gatewayCosts(now));
// Email rows wait for the alarm whatever the policy says: a lost poke is retried here.
Expand Down
4 changes: 2 additions & 2 deletions platform/packages/api/src/security/scanner-images.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"agent_sdk": {
"repository": "ghcr.io/voidzero-dev/void-security-scanner-engine-a",
"digest": null
"digest": "sha256:1a8de2bbcc745fb68b91d20b2c2fbef2cff001b83e0208911932997574eb6cbb"
},
"codex_sdk": {
"repository": "ghcr.io/voidzero-dev/void-security-scanner-engine-c",
"digest": null
"digest": "sha256:363b46158a2becba2c53243e16af655d43f2205342227ba122d03167dc58e1fc"
}
}
12 changes: 7 additions & 5 deletions platform/packages/api/test/integration/admin-dashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1388,9 +1388,11 @@ describe('GET /admin/ (dashboard)', () => {
heading.textContent?.startsWith('Builds ('),
)!.parentElement!;
const zeroTrust = document.getElementById('zero-trust')!;
// Security audits are on in the hosted test env: its section sits in between.
const security = document.getElementById('security')!;
const team = document.getElementById('team')!;
const ownership = document.getElementById('owner-transfer')!;
const sections = [builds, zeroTrust, team, ownership];
const sections = [builds, zeroTrust, security, team, ownership];
return sections.slice(1).map((section, index) => {
const previous = sections[index].getBoundingClientRect();
return section.getBoundingClientRect().top - previous.bottom;
Expand All @@ -1410,11 +1412,11 @@ describe('GET /admin/ (dashboard)', () => {
const configure = (await zeroTrust
.getByRole('link', { name: 'Configure Zero Trust' })
.boundingBox())!;
const teamHeading = (await page
.locator('#team')
.getByRole('heading', { name: 'Team members (1)' })
const nextHeading = (await page
.locator('#security')
.getByRole('heading', { name: 'Security' })
.boundingBox())!;
expect(teamHeading.y - (configure.y + configure.height)).toBeCloseTo(32, 0);
expect(nextHeading.y - (configure.y + configure.height)).toBeCloseTo(32, 0);
expect(configure.width).toBeLessThan((await zeroTrust.boundingBox())!.width);
const teamTables = page.locator('.void-admin-team-table-scroll');
expect(await teamTables.count()).toBe(2);
Expand Down
8 changes: 5 additions & 3 deletions platform/packages/api/test/integration/admin-security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
liveProject,
saveSecurityPolicy,
securityBindings,
securityOff,
storedSecurityPolicy,
} from './security-fixtures.ts';
import { askPublic, setupGate } from './security-gate-fixtures.ts';
Expand Down Expand Up @@ -91,18 +92,19 @@ async function readPolicy(): Promise<SecurityPolicy> {
describe('admin security pages', () => {
it('capability off: shows the install command, hides the nav item, refuses every write (I13)', async () => {
const { project } = await liveProject(env);
expect(text(await (await get('/admin/security', env)).text())).toContain(
const offEnv = securityOff(env);
expect(text(await (await get('/admin/security', offEnv)).text())).toContain(
'void platform upgrade --security-audits',
);
expect(text(await (await get('/admin/users', env)).text())).not.toContain('/admin/security');
expect(text(await (await get('/admin/users', offEnv)).text())).not.toContain('/admin/security');
for (const path of [
'/admin/security/policy',
'/admin/security/budget',
'/admin/security/probe',
`/admin/projects/${project.id}/security/model`,
`/admin/projects/${project.id}/security/rescan`,
]) {
expect([path, (await post(path, {}, env)).status]).toEqual([path, 501]);
expect([path, (await post(path, {}, offEnv)).status]).toEqual([path, 501]);
}
expect(await env.db.select().from(operatorEvents)).toEqual([]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
insertSecurityFinding,
projectWithRoles,
saveSecurityPolicy,
securityOff,
securityOn,
} from './security-fixtures.ts';
import {
Expand Down Expand Up @@ -170,7 +171,7 @@ describe('project security routes', () => {
body,
bindings,
});
expect((await put({ model: '@cf/zai-org/glm-5.3' }, env)).status).toBe(501);
expect((await put({ model: '@cf/zai-org/glm-5.3' }, securityOff(env))).status).toBe(501);
expect(await env.db.select().from(projectSecuritySettings)).toEqual([]);

const needsNotice = await put({ model: FOREIGN });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
liveProject,
saveSecurityPolicy,
securityBindings,
securityOff,
} from './security-fixtures.ts';
import { askPublic, setupGate } from './security-gate-fixtures.ts';

Expand Down Expand Up @@ -97,7 +98,7 @@ describe('operator security routes', () => {
).toBe(409);
const written = await call('/security/budget', { body });
expect(written.body).toMatchObject({ ok: true, revision: 5 });
expect((await call('/security/budget', { body, bindings: env })).status).toBe(501);
expect((await call('/security/budget', { body, bindings: securityOff(env) })).status).toBe(501);
});

it('resolves and reopens a finding as the installation admin, with a preview first', async () => {
Expand Down
13 changes: 10 additions & 3 deletions platform/packages/api/test/integration/security-enqueue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ import {
teardownEnv,
} from './helpers.ts';
import type { TestEnv } from './helpers.ts';
import { saveSecurityPolicy, securityBindings, seedProtectedProject } from './security-fixtures.ts';
import {
saveSecurityPolicy,
securityBindings,
securityOff,
seedProtectedProject,
} from './security-fixtures.ts';

let env: TestEnv;
let onEnv: TestEnv;
Expand Down Expand Up @@ -165,7 +170,9 @@ describe('enqueue in the go-live transaction (I1)', () => {
await savePolicy(kind === 'policy' ? 'disabled' : 'all');
const { project } = await setup();
const deployment = await createTestDeployment(env.db, project.id);
expect(await enqueue(project.id, deployment.id, kind === 'off' ? env : onEnv)).toBeNull();
expect(
await enqueue(project.id, deployment.id, kind === 'off' ? securityOff(env) : onEnv),
).toBeNull();
expect(await scans(project.id)).toEqual([]);
});

Expand Down Expand Up @@ -291,7 +298,7 @@ describe('real deploys', () => {

it('nothing changes with the capability off (I13)', async () => {
await savePolicy('all');
const { project, operation } = await deployQueued(env);
const { project, operation } = await deployQueued(securityOff(env));
expect(operation).toMatchObject({ inputs_deleted: true });
expect(await scans(project.id)).toEqual([]);
expect(pokes).toBe(0);
Expand Down
5 changes: 5 additions & 0 deletions platform/packages/api/test/integration/security-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export function securityOn(env: TestEnv, capabilities: Record<string, boolean> =
};
}

/** The bindings with the security audits capability off (hosted has it on). */
export function securityOff(env: TestEnv): TestEnv {
return securityOn(env, { securityAudits: false });
}

/** A scheduler namespace whose stub answers `fetch` with ok, plus the given methods. */
export function schedulerStub(
methods: Record<string, unknown> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
saveSecurityPolicy,
scanResult,
securityBindings,
securityOff,
} from './security-fixtures.ts';

const CF = '@cf/deepseek-ai/deepseek-v4.1-flash-1017';
Expand Down Expand Up @@ -124,7 +125,9 @@ describe('local checks (I12)', () => {
const { archive, request } = tree();
const path = `/projects/${project.id}/security/checks`;
expect((await call(path, reader.jwt, { body: request })).status).toBe(403);
expect((await call(path, owner.jwt, { body: request, bindings: env })).status).toBe(501);
expect(
(await call(path, owner.jwt, { body: request, bindings: securityOff(env) })).status,
).toBe(501);

const response = await call(path, owner.jwt, { body: request });
expect(response.status).toBe(201);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { afterAll, beforeAll, beforeEach, expect, it, vi } from 'vite-plus/test';
import type { MockInstance } from 'vite-plus/test';
import type { ApiEnv } from '../../src/env.ts';
import { CF_API_BASE } from '../../src/provisioning/cloudflare-api.ts';
import { securityScannerNames } from '../../src/provisioning/security-scanner.ts';
import { runSecurityMaintenance } from '../../src/security/maintenance.ts';
import { runtimeCopyScriptName } from '../../src/security/runtime-copy-names.ts';
import { clearTables, setupEnv, teardownEnv } from './helpers.ts';
import type { TestEnv } from './helpers.ts';
import { freshEntitlement, saveSecurityPolicy, securityBindings } from './security-fixtures.ts';

let env: TestEnv;
let fetchSpy: MockInstance<typeof fetch>;

beforeAll(async () => {
env = await setupEnv();
});
afterAll(teardownEnv);
beforeEach(async () => {
await clearTables(env.db);
vi.restoreAllMocks();
});

/** Fake Cloudflare API: the copy namespace lists `scripts`; every other call is empty. */
function cloudflare(scripts: Array<string> = []) {
fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const url = String(input instanceof Request ? input.url : input);
const result = url.endsWith('/scripts') ? scripts.map((id) => ({ id })) : [];
return Response.json({ success: true, errors: [], result });
});
}

const onEnv = () => securityBindings(env) as unknown as ApiEnv['Bindings'];
const calls = () => fetchSpy.mock.calls.map(([input, init]) => `${init?.method ?? 'GET'} ${input}`);

// Hosted has the capability on with Scan Off: the hourly run must not list the account.
it('makes no Cloudflare call before the scanner was ever set up', async () => {
cloudflare();
const report = await runSecurityMaintenance(onEnv(), env.db, Date.now());
expect(report).toMatchObject({ copiesReaped: 0, gatewayCosts: 0, probed: false });
expect(fetchSpy).not.toHaveBeenCalled();
});

// Scan rows go with their project, so a copy can outlive every scan row.
it('sweeps left-over runtime copies once the scanner was set up, even with no scan row', async () => {
await saveSecurityPolicy(env, { mode: 'disabled', entitlement: freshEntitlement() });
const names = await securityScannerNames('void-api');
const leftover = runtimeCopyScriptName(names.copyPrefix, 'ss_gone', 1);
cloudflare([leftover]);
const report = await runSecurityMaintenance(onEnv(), env.db, Date.now());
expect(report).toMatchObject({ copiesReaped: 1 });
const scripts = `${CF_API_BASE}/${env.CF_ACCOUNT_ID}/workers/dispatch/namespaces/${names.copyNamespace}/scripts`;
expect(calls()).toContain(`DELETE ${scripts}/${leftover}?force=true`);
});
Loading