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
151 changes: 142 additions & 9 deletions API/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9561,8 +9561,11 @@ paths:
/auth/delete-account:
get:
tags: [Auth]
summary: Open the first-party global account-deletion form
summary: Open the global or product account-deletion form
operationId: accountDeletionForm
parameters:
- { in: query, name: product, schema: { type: string }, description: Registered product policy identifier }
- { in: query, name: action, schema: { type: string, enum: [rejoin] }, description: Fresh product registration after completed erasure }
responses:
'200':
description: Account deletion request form.
Expand All @@ -9585,6 +9588,8 @@ paths:
additionalProperties: false
required: [email]
properties:
product: { type: string }
rejoin: { type: boolean }
email:
type: string
format: email
Expand All @@ -9608,7 +9613,7 @@ paths:
tags: [Auth]
summary: Confirm a deletion request using a mailbox code and any enrolled authenticator
operationId: confirmAccountDeletion
description: Requires the browser cookie issued by start. A successful request is queued for administrative review.
description: Requires the browser cookie issued by start. A global request enters administrative review. A product request returns its current impact for separate confirmation.
requestBody:
required: true
content:
Expand All @@ -9618,9 +9623,12 @@ paths:
additionalProperties: false
required: [challengeId, code]
properties:
product: { type: string }
rejoin: { type: boolean }
challengeId:
type: string
format: uuid
password: { type: string, format: password, description: Optional independent UOA password for managed product accounts }
code:
type: string
pattern: '^[0-9]{6}$'
Expand All @@ -9629,18 +9637,143 @@ paths:
pattern: '^[0-9]{6}$'
responses:
'200':
description: Confirmed request saved. No session is issued.
description: Global request accepted or product preview returned.
content:
application/json:
schema:
type: object
required: [submitted]
properties:
submitted:
type: boolean
enum: [true]
oneOf:
- { type: object, required: [submitted], properties: { submitted: { type: boolean, enum: [true] } } }
- { type: object, required: [digest, impact], properties: { digest: { type: string }, impact: { type: object } } }
'401':
description: The browser proof, mailbox code or required authenticator code could not be verified.
/auth/delete-account/product/{id}:
get:
tags: [Auth]
summary: Read the enabled product name and retention disclosure
parameters:
- { in: path, name: id, required: true, schema: { type: string } }
responses:
'200': { description: Product name and deletion disclosure }
'404': { description: Unknown or disabled product }
/auth/delete-account/submit-product:
post:
tags: [Auth]
summary: Confirm the exact product preview with the original browser cookie
requestBody:
required: true
content:
application/json:
schema:
type: object
additionalProperties: false
required: [product, challengeId, digest]
properties:
product: { type: string }
challengeId: { type: string, format: uuid }
digest: { type: string, pattern: '^[a-f0-9]{64}$' }
rejoin: { type: boolean }
container:
type: object
required: [scope, id]
properties:
scope: { type: string, enum: [TEAM, ORGANISATION] }
id: { type: string }
responses:
'200': { description: Receipt identifier and completion flag }
'401': { description: Missing or stale proof }
'409': { description: Refresh the preview or check the original request }
/auth/delete-account/receipt/{id}:
get:
tags: [Auth]
summary: Check an opaque deletion receipt after sign-out
parameters:
- { in: path, name: id, required: true, schema: { type: string, format: uuid } }
responses:
'200': { description: Plain text progress or completion }
'404': { description: Receipt unavailable }
/domain/product-participation:
get:
security: [{ domainHashBearer: [] }]
summary: Check the current product participation generation before accepting a saved session or sync write
parameters:
- { in: query, name: domain, required: true, schema: { type: string } }
- { in: query, name: subject, required: true, schema: { type: string } }
responses:
'200': { description: 'Product identifier, active flag and generation. Independently authenticate the subject.' }
/domain/product-erasure-jobs:
get:
security: [{ domainHashBearer: [] }]
summary: Pull pending personal erasure work for the authenticated backend
parameters:
- { in: query, name: domain, required: true, schema: { type: string } }
- { in: query, name: after, schema: { type: string, format: uuid } }
responses:
'200': { description: Up to 100 assigned jobs and a next cursor }
/domain/product-erasure-jobs/{id}/acknowledge:
post:
security: [{ domainHashBearer: [] }]
summary: Acknowledge committed product data cleanup
parameters:
- { in: path, name: id, required: true, schema: { type: string, format: uuid } }
- { in: query, name: domain, required: true, schema: { type: string } }
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [revision, outcome]
properties:
revision: { type: integer, minimum: 1 }
outcome: { type: string, enum: [PURGED, RETAINED_EVIDENCE] }
responses:
'200': { description: Acknowledgement recorded or exact replay accepted }
'409': { description: Conflicting acknowledgement }
/internal/admin/product-erasure:
get:
tags: [Internal Admin]
security: [{ adminBearer: [] }]
summary: List registered policies and outstanding work
responses:
'200': { description: Policies and outstanding jobs }
post:
tags: [Internal Admin]
security: [{ adminBearer: [] }]
summary: Save a product policy using its current revision
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [id, revision, name, mode, enabled, disclosure, domains, nativeApps, settings]
properties:
id: { type: string }
revision: { type: integer, minimum: 0 }
name: { type: string }
mode: { type: string, enum: [PERSONAL, ORGANISATION] }
enabled: { type: boolean }
disclosure: { type: string }
domains: { type: array, items: { type: string } }
nativeApps: { type: array, items: { type: string } }
settings: { type: array, items: { type: string } }
responses:
'200': { description: Saved policy and revision }
/internal/admin/product-erasure/{id}/container:
post:
tags: [Internal Admin]
security: [{ adminBearer: [] }]
summary: Review the exact requested container after checking external dependencies
parameters:
- { in: path, name: id, required: true, schema: { type: string, format: uuid } }
requestBody:
required: true
content:
application/json:
schema: { type: object, required: [decision], properties: { decision: { type: string, enum: [approve, preserve] } } }
responses:
'200': { description: Decision recorded }
'409': { description: Scope changed or review already closed }
/internal/admin/users:
post:
tags: [Internal Admin]
Expand Down
84 changes: 84 additions & 0 deletions API/prisma/migrations/20261120100000_product_erasure/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
BEGIN;
ALTER TABLE verification_tokens ADD COLUMN product_preview_digest text, ADD COLUMN product_factor_digest text, ADD COLUMN product_receipt_id text, ADD COLUMN product_selection text;
CREATE TABLE product_erasure_policies (
id text PRIMARY KEY, name text NOT NULL, mode text NOT NULL CHECK (mode IN ('PERSONAL','ORGANISATION')),
enabled boolean NOT NULL DEFAULT false, revision integer NOT NULL DEFAULT 1,
closed_bootstrap_domains text[] NOT NULL DEFAULT ARRAY[]::text[],
disclosure text NOT NULL, domains text[] NOT NULL, native_apps text[] NOT NULL, settings text[] NOT NULL
);
CREATE TABLE product_erasure_jobs (
id text PRIMARY KEY, policy_id text NOT NULL REFERENCES product_erasure_policies(id) ON DELETE RESTRICT,
container_preserved boolean NOT NULL DEFAULT false, requested_container jsonb, container_job_id text REFERENCES entity_deletion_jobs(id) ON DELETE RESTRICT,
rejoined_subject text, rejoined_at timestamp(3), notice_due_at timestamp(3) DEFAULT CURRENT_TIMESTAMP,
subject text NOT NULL, revision integer NOT NULL, impact jsonb NOT NULL,
created_at timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, completed_at timestamp(3),
UNIQUE(subject, policy_id)
);
CREATE INDEX product_erasure_generation_idx ON product_erasure_jobs(policy_id, rejoined_subject, rejoined_at);
CREATE INDEX product_erasure_notice_idx ON product_erasure_jobs(notice_due_at) WHERE completed_at IS NOT NULL;
CREATE TABLE product_erasure_receipts (
job_id text NOT NULL REFERENCES product_erasure_jobs(id) ON DELETE CASCADE, domain_id text NOT NULL,
acknowledged_at timestamp(3), outcome text CHECK (outcome IN ('PURGED','RETAINED_EVIDENCE')),
PRIMARY KEY(job_id, domain_id)
);
CREATE INDEX product_erasure_receipts_domain_id_acknowledged_at_idx ON product_erasure_receipts(domain_id, acknowledged_at);
-- Once every participant has acknowledged, the receipt and admission fence only
-- need the product, subject, revision, outcome and dates.
CREATE FUNCTION scrub_completed_product_erasure() RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN
NEW.impact := '{}'::jsonb;
NEW.requested_container := NULL;
RETURN NEW;
END $$;
CREATE TRIGGER scrub_completed_product_erasure BEFORE INSERT OR UPDATE ON product_erasure_jobs
FOR EACH ROW WHEN (NEW.completed_at IS NOT NULL) EXECUTE FUNCTION scrub_completed_product_erasure();

-- Requests, inventories and acknowledgements are visible only through the admin connection.
ALTER TABLE product_erasure_policies ENABLE ROW LEVEL SECURITY;
ALTER TABLE product_erasure_jobs ENABLE ROW LEVEL SECURITY;
ALTER TABLE product_erasure_receipts ENABLE ROW LEVEL SECURITY;

-- Tenant transactions get a denial bit, never an enumerable request or writable authority row.
CREATE FUNCTION product_erasure_admission(person text, client_domain text, native_app text)
RETURNS TABLE(denied boolean, bootstrap_closed boolean) LANGUAGE sql STABLE SECURITY DEFINER AS $$
SELECT EXISTS (SELECT 1 FROM product_erasure_jobs j
JOIN product_erasure_policies p ON p.id=j.policy_id
WHERE j.subject=person AND (client_domain=ANY(p.domains) OR native_app=ANY(p.native_apps))),
EXISTS (SELECT 1 FROM product_erasure_policies WHERE client_domain=ANY(closed_bootstrap_domains))
$$;

DO $$ BEGIN
EXECUTE format('ALTER FUNCTION %I.product_erasure_admission(text,text,text) SET search_path = pg_catalog,%I,pg_temp', current_schema(), current_schema());
END $$;

REVOKE ALL ON product_erasure_jobs,product_erasure_receipts,product_erasure_policies FROM uoa_app;
GRANT SELECT,INSERT,UPDATE,DELETE ON product_erasure_jobs,product_erasure_receipts,product_erasure_policies TO uoa_admin;
REVOKE ALL ON FUNCTION product_erasure_admission(text,text,text) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION product_erasure_admission(text,text,text) TO uoa_app,uoa_admin;

CREATE FUNCTION complete_product_container_erasure() RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN
UPDATE product_erasure_jobs j SET completed_at=CURRENT_TIMESTAMP
WHERE j.container_job_id=NEW.id AND j.completed_at IS NULL AND NOT EXISTS
(SELECT 1 FROM product_erasure_receipts r WHERE r.job_id=j.id AND r.acknowledged_at IS NULL);
RETURN NEW;
END $$;
CREATE TRIGGER complete_product_container_erasure AFTER UPDATE OF status ON entity_deletion_jobs
FOR EACH ROW WHEN (NEW.status='COMPLETE' AND OLD.status IS DISTINCT FROM NEW.status) EXECUTE FUNCTION complete_product_container_erasure();
-- All products may normally write shared settings. A stale sync from a different
-- client must also respect the erasure of an inventoried product key.
CREATE FUNCTION refuse_erased_product_setting() RETURNS trigger LANGUAGE plpgsql SECURITY DEFINER AS $$
BEGIN
IF EXISTS (SELECT 1 FROM product_erasure_jobs j JOIN product_erasure_policies p ON p.id=j.policy_id
WHERE j.subject=NEW.user_id AND (NEW.namespace || '/' || NEW.key)=ANY(p.settings)) THEN
RAISE EXCEPTION 'PRODUCT_ACCOUNT_DELETED' USING ERRCODE='23514';
END IF;
RETURN NEW;
END $$;
DO $$ BEGIN
EXECUTE format('ALTER FUNCTION %I.refuse_erased_product_setting() SET search_path = pg_catalog,%I,pg_temp', current_schema(), current_schema());
END $$;
CREATE TRIGGER refuse_erased_product_setting BEFORE INSERT OR UPDATE ON user_settings
FOR EACH ROW EXECUTE FUNCTION refuse_erased_product_setting();
REVOKE ALL ON FUNCTION refuse_erased_product_setting() FROM PUBLIC;
COMMIT;
51 changes: 51 additions & 0 deletions API/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ model AuthIdentity {
}

model VerificationToken {
productPreviewDigest String? @map("product_preview_digest")
productFactorDigest String? @map("product_factor_digest")
productReceiptId String? @map("product_receipt_id")
productSelection String? @map("product_selection")
id String @id @default(cuid())
type VerificationTokenType
email String
Expand Down Expand Up @@ -6510,3 +6514,50 @@ model BillingBrowserCancellation {
createdAt DateTime @default(now()) @map("created_at")
@@map("billing_browser_cancellations")
}

model ProductErasurePolicy {
id String @id
name String
mode String
enabled Boolean @default(false)
revision Int @default(1)
disclosure String
domains String[]
nativeApps String[] @map("native_apps")
settings String[]
closedBootstrapDomains String[] @default([]) @map("closed_bootstrap_domains")
jobs ProductErasureJob[]
@@map("product_erasure_policies")
}

model ProductErasureJob {
rejoinedSubject String? @map("rejoined_subject")
rejoinedAt DateTime? @map("rejoined_at")
noticeDueAt DateTime? @default(now()) @map("notice_due_at")
@@index([policyId, rejoinedSubject, rejoinedAt], map: "product_erasure_generation_idx")
id String @id @default(uuid())
policyId String @map("policy_id")
containerJobId String? @map("container_job_id")
containerPreserved Boolean @default(false) @map("container_preserved")
requestedContainer Json? @map("requested_container")
subject String
revision Int
impact Json
createdAt DateTime @default(now()) @map("created_at")
completedAt DateTime? @map("completed_at")
policy ProductErasurePolicy @relation(fields: [policyId], references: [id], onDelete: Restrict)
receipts ProductErasureReceipt[]
@@unique([subject, policyId])
@@map("product_erasure_jobs")
}

model ProductErasureReceipt {
jobId String @map("job_id")
domainId String @map("domain_id")
acknowledgedAt DateTime? @map("acknowledged_at")
outcome String?
job ProductErasureJob @relation(fields: [jobId], references: [id], onDelete: Cascade)
@@id([jobId, domainId])
@@index([domainId, acknowledgedAt])
@@map("product_erasure_receipts")
}
3 changes: 3 additions & 0 deletions API/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { startMachineEventDelivery } from './services/machine-delivery.service.j
import { pruneMachineBrowsers } from './services/machine-retention.service.js';
import { startEnterpriseRevocationDelivery } from './services/org-sso-delivery.service.js';
import { pruneEnterpriseRevocations } from './services/org-sso-revocation.service.js';
import { startProductDeletionNotices } from './services/product-erasure-notification.service.js';
import { startEnterpriseMaintenance } from './services/enterprise-maintenance.service.js';

export async function createApp(): Promise<FastifyInstance> {
Expand Down Expand Up @@ -287,6 +288,8 @@ export async function createApp(): Promise<FastifyInstance> {
app.addHook('onClose', async () => machineDelivery.stop());
const enterpriseDelivery = startEnterpriseRevocationDelivery(app.log);
app.addHook('onClose', async () => enterpriseDelivery.stop());
const deletionNotices = startProductDeletionNotices(app.log);
app.addHook('onClose', async () => deletionNotices.stop());
const enterpriseMaintenance = startEnterpriseMaintenance(app.log);
app.addHook('onClose', async () => enterpriseMaintenance.stop());

Expand Down
Loading
Loading