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
76 changes: 76 additions & 0 deletions docs/release-authenticated-admission-boundary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Authenticated admission boundary: proposed, not activated

The only viable admission boundary in the current Worker architecture is a
server-owned publisher route. Receipt JSON, owner stamps, a signed token, and a
successful workflow run individually do not grant release authority.

## Required evidence flow

1. Verify a fresh GitHub OIDC token on every mutating request against the existing
fixed issuer, audience, repository IDs, workflow and main restrictions. Bind
canonical run ID, run attempt and workflow SHA; do not accept request overrides.
2. The server acquires fixed-source run/attempt state, candidate source/tree,
validation jobs and original export artifact bytes/digest. Artifact ownership
by upload attempt needs independently established linkage, not a guessed
attempt from an artifact's containing run.
3. Independently verify semantic/coverage receipts and exact runtime/source/env,
engine, expected head/generation and policy revision. Unknown evidence holds.
4. Construct immutable admission decision/history server-side. Derive actor from
verified repository/workflow/run/attempt and allocate a monotonic epoch using
database CAS. The client cannot choose owner, epoch, state, target overrides or
an already-admitted boolean. Persist intent/results without erasing prior
denied, stopped or uncertain decisions when a new request arrives.
5. Permit bounded stamped preparation only under that preparing decision. Full
canonical payload and exact row/provenance readback precedes the admitted
transition. Owner, epoch, stop, head and immutable decision comparison must
share that transition's transaction.
6. The stamped promotion adapter inserts one admitted event. Database triggers
bind event, head and consumption atomically. Public-route/export verification
is a later independent outcome, not implied by the SQL commit.

The inactive promotion adapter in this slice handles the real SQL primitive,
full stored candidate/record validation, expected state and same-operation
reconciliation. It does not authenticate or create admission and is not imported
by a runtime route. Preparation and promotion are NOT combined into automatic
bootstrap. Unknown writes are reconciled; never blindly replayed.

## Threat model and actual host boundary

Current D1-binding code has unrestricted SQL capability. Triggers protect against
stale/legacy supported writers and races, not malicious or compromised code with
that binding or privileged database administrators. Readable stamps are not
secrets. A second authority host sharing the same writable DB does not fix this.

Stronger isolation would require platform-enforced write-capability separation:
only an authority service owns the write binding and other publishers use narrow
authenticated endpoints. Removing old direct write access and establishing a
reader-only service boundary are architecture/permission decisions, not changes
made by this draft. No read-only D1 binding capability is assumed available.

## Commissioning blockers, not implementation shortcuts

- Legitimate execution through the existing approved GitHub workflow, including a
real issuer token for read-only qualification. A prior rejected enable action
is not retried through a new workflow, token or proxy.
- Original export artifact upload-attempt linkage and independent semantic
authority. Neither the run observer nor a journal grants these facts.
- Authenticated stop/recovery administration, durable historical decisions and
transaction linkage between journal, admission and head.
- Exact deployed D1/runtime baseline, isolated hosted trigger/migration/rollback
qualification and separately approved production route/schema activation.

No live control, binding, credential, permission, workflow or deployment changes
are made here. The bundled public site remains untouched.

Reference reconciliation is deliberately limited to a retained matching admission
row. Replacing the channel admission makes an old-operation lookup fail closed,
even when its event survives. Production must archive immutable per-operation
admission separately from the current channel owner pointer; accepting an old
event alone would not recover the missing authority decision. A regression keeps
this limitation visible rather than silently reporting a reconciled operation.

This adapter supports initialized-head publish and explicitly admitted rollback
only. It rejects bootstrap: absent-head commissioning remains a separate guarded
operation. Return values separate the event's applied revision from a current-head
read, and set deliveryVerified and productionActionAllowed false. A later head
cannot be inferred from an earlier event or taken as public delivery evidence.
57 changes: 57 additions & 0 deletions tests/publication-core.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,60 @@ for(const race of ['stop','epoch'])test('stamped batch atomically rejects '+race
assert.equal(db.sql.prepare('SELECT COUNT(*) AS n FROM content_records WHERE revision_id=?').get(fresh.manifest.revision).n,50);
assert.equal(db.sql.prepare('SELECT completed FROM content_revisions WHERE id=?').get(fresh.manifest.revision).completed,0);
});
test('inactive stamped promotion integrates integrity validation and same-operation reconciliation',async t=>{
const {db,a,b}=await fenceFixture(t), op='pub-'+'9'.repeat(32);
const {promoteFenced}=await import('../tools/release-coordination/fenced-promotion-reference.mjs');
const request={...action(1,a,b),operationId:op}, identity={operationId:op,owner:'owner-a',epoch:1};
assert.equal((await promoteFenced(db,request,identity,{engineRevision:engine})).status,'applied');
assert.equal((await promoteFenced(db,request,identity,{engineRevision:engine})).status,'already-applied');
assert.equal(db.sql.prepare('SELECT COUNT(*) AS n FROM content_publication_events').get().n,1);
await assert.rejects(promoteFenced(db,request,{...identity,owner:'owner-b'},{engineRevision:engine}),/admission mismatch/);
});
for(const change of ['stop','epoch'])test('stamped promotion guards '+change+' immediately before atomic event',async t=>{
const {db,a,b,m}=await fenceFixture(t), op='pub-'+'9'.repeat(32), original=db.prepare.bind(db);
db.prepare=q=>{const statement=original(q);if(!q.startsWith('INSERT INTO content_publication_events'))return statement;return {bind:(...args)=>{const bound=statement.bind(...args);return {...bound,run:async()=>{db.sql.exec(change==='stop'?'UPDATE release_admission SET stopped=1':'UPDATE release_admission SET epoch=2');return bound.run()}}}}};
const {promoteFenced}=await import('../tools/release-coordination/fenced-promotion-reference.mjs');
await assert.rejects(promoteFenced(db,{...action(1,a,b),operationId:op},{operationId:op,owner:'owner-a',epoch:1},{engineRevision:engine}),/fence-/);
assert.equal((await m.readPublicationHead(db,engine)).revision,a.manifest.revision);
assert.equal(db.sql.prepare('SELECT COUNT(*) AS n FROM content_publication_events').get().n,0);
});
test('stamped promotion reconciles committed event after response loss without inserting again',async t=>{
const {db,a,b}=await fenceFixture(t), op='pub-'+'9'.repeat(32), original=db.prepare.bind(db);
let writes=0;db.prepare=q=>{const statement=original(q);if(!q.startsWith('INSERT INTO content_publication_events'))return statement;return {bind:(...args)=>{const bound=statement.bind(...args);return {...bound,run:async()=>{writes++;await bound.run();throw Error('injected-response-loss')}}}}};
const {promoteFenced}=await import('../tools/release-coordination/fenced-promotion-reference.mjs');
const request={...action(1,a,b),operationId:op},identity={operationId:op,owner:'owner-a',epoch:1};
await assert.rejects(promoteFenced(db,request,identity,{engineRevision:engine}),/response-loss/);
assert.equal((await promoteFenced(db,request,identity,{engineRevision:engine})).status,'already-applied');assert.equal(writes,1);
});
test('stamped promotion fails closed if current admission was replaced after commit',async t=>{
const {db,a,b}=await fenceFixture(t),op='pub-'+'9'.repeat(32);
const {promoteFenced}=await import('../tools/release-coordination/fenced-promotion-reference.mjs');
const request={...action(1,a,b),operationId:op},identity={operationId:op,owner:'owner-a',epoch:1};
await promoteFenced(db,request,identity,{engineRevision:engine});
db.sql.prepare('UPDATE release_admission SET operation_id=?').run('pub-'+'8'.repeat(32));
await assert.rejects(promoteFenced(db,request,identity,{engineRevision:engine}),/admission mismatch/);
assert.equal(db.sql.prepare('SELECT COUNT(*) AS n FROM content_publication_events').get().n,1);
});
for(const corruption of ['count','schema','digest','payload','provenance'])test('stamped promotion rejects corrupt '+corruption+' before event insertion',async t=>{
const {db,a,b}=await prepared(t),rev=b.manifest.revision,op='pub-'+'9'.repeat(32);
if(corruption==='count')db.sql.prepare('DELETE FROM content_records WHERE revision_id=? AND record_id=?').run(rev,b.catalog.records[0].id);
if(corruption==='schema')db.sql.prepare('UPDATE content_revisions SET schema_version=2 WHERE id=?').run(rev);
if(corruption==='digest')db.sql.prepare("UPDATE content_revisions SET digest=? WHERE id=?").run('f'.repeat(64),rev);
if(corruption==='payload')db.sql.prepare("UPDATE content_records SET payload_json='{}' WHERE revision_id=?").run(rev);
if(corruption==='provenance')db.sql.prepare('UPDATE content_publication_provenance SET commit_sha=? WHERE revision_id=?').run('f'.repeat(40),rev);
db.sql.exec(fs.readFileSync('tools/release-coordination/database-fence-reference.sql','utf8'));
db.sql.prepare('INSERT INTO release_admission VALUES(?,?,?,?,?,?,?,?,?,?,?,?)').run('engine:'+engine,op,'owner-a',1,rev,b.manifest.digest,commit,a.manifest.revision,0,'publish','admitted',0);
const {promoteFenced}=await import('../tools/release-coordination/fenced-promotion-reference.mjs');
await assert.rejects(promoteFenced(db,{...action(1,a,b),operationId:op},{operationId:op,owner:'owner-a',epoch:1},{engineRevision:engine}));
assert.equal(db.sql.prepare('SELECT COUNT(*) AS n FROM content_publication_events').get().n,0);
});
for(const scenario of ['legal-rollback','rollback-never-active','publish-formerly-active'])test('stamped promotion enforces '+scenario,async t=>{
const {db,a,b,c}=await fenceFixture(t),op='pub-'+'9'.repeat(32),next='pub-'+'8'.repeat(32);
const {promoteFenced}=await import('../tools/release-coordination/fenced-promotion-reference.mjs');
await promoteFenced(db,{...action(1,a,b),operationId:op},{operationId:op,owner:'owner-a',epoch:1},{engineRevision:engine});
const target=scenario==='rollback-never-active'?c:a,intent=scenario==='publish-formerly-active'?'publish':'rollback';
db.sql.prepare("UPDATE release_admission SET operation_id=?,epoch=2,target_revision=?,target_digest=?,expected_revision=?,expected_generation=1,mode=?,state='admitted'").run(next,target.manifest.revision,target.manifest.digest,b.manifest.revision,intent);
const request={...action(2,b,target,1,intent),operationId:next},identity={operationId:next,owner:'owner-a',epoch:2};
if(scenario==='legal-rollback'){const r=await promoteFenced(db,request,identity,{engineRevision:engine});assert.equal(r.current.revision,a.manifest.revision);assert.equal(r.deliveryVerified,false)}
else await assert.rejects(promoteFenced(db,request,identity,{engineRevision:engine}),/fence-/);
});
54 changes: 54 additions & 0 deletions tools/release-coordination/fenced-promotion-reference.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// INACTIVE integration slice: no runtime route or automatic admission issuer.
import { validateBundle, readPublicationHead, REPOSITORY } from '../../worker/publication-core.mjs';
const check = (ok, message) => { if (!ok) throw Error(message); };
export async function promoteFenced(db, action, identity, { engineRevision } = {}) {
action = action && JSON.parse(JSON.stringify(action));
identity = identity && JSON.parse(JSON.stringify(identity));
check(action && Object.keys(action).sort().join(',') === 'expectedGeneration,expectedRevision,intent,operationId,revision', 'Exact promotion fields required');
check(/^engine-[a-f0-9]{20}$/.test(engineRevision) && /^pub-[a-f0-9]{32}$/.test(action.operationId) &&
/^content-[a-f0-9]{24}$/.test(action.revision) && /^content-[a-f0-9]{24}$/.test(action.expectedRevision) &&
action.revision !== action.expectedRevision && ['publish','rollback'].includes(action.intent) &&
Number.isSafeInteger(action.expectedGeneration) && action.expectedGeneration >= 0 && action.expectedGeneration < Number.MAX_SAFE_INTEGER,
'Invalid promotion');
check(identity && identity.operationId === action.operationId && typeof identity.owner === 'string' &&
identity.owner.length > 0 && identity.owner.length <= 128 && Number.isSafeInteger(identity.epoch) && identity.epoch > 0, 'Writer identity required');
const channel = 'engine:' + engineRevision;
const admission = await db.prepare('SELECT * FROM release_admission WHERE operation_id=?').bind(action.operationId).first();
check(admission && admission.channel === channel && admission.owner === identity.owner && admission.epoch === identity.epoch &&
admission.target_revision === action.revision && admission.expected_revision === action.expectedRevision &&
admission.expected_generation === action.expectedGeneration && admission.mode === action.intent, 'Promotion admission mismatch');
const exactEvent = event => event && event.operation_id === action.operationId && event.channel === channel &&
event.from_revision === action.expectedRevision && event.to_revision === action.revision && event.generation === action.expectedGeneration + 1 &&
event.intent === action.intent && event.provenance_commit === admission.target_commit && event.writer_operation === action.operationId &&
event.writer_owner === identity.owner && event.writer_epoch === identity.epoch;
const existing = await db.prepare('SELECT * FROM content_publication_events WHERE operation_id=?').bind(action.operationId).first();
if (existing) {
check(exactEvent(existing) && admission.state === 'consumed', 'Applied operation identity mismatch');
return {status:'already-applied', applied:{revision:existing.to_revision,generation:existing.generation}, current:await readPublicationHead(db,engineRevision), deliveryVerified:false,productionActionAllowed:false};
}
check(admission.state === 'admitted' && admission.stopped === 0, 'Promotion not admitted');
const row = await db.prepare('SELECT * FROM content_revisions WHERE id=?').bind(action.revision).first();
check(row?.completed === 1, 'Complete target required');
const bundle = await validateBundle(JSON.parse(row.bundle_json),engineRevision), m = bundle.manifest;
check(m.revision === action.revision && m.digest === admission.target_digest && row.digest === m.digest &&
row.manifest_json === JSON.stringify(m) && row.engine === engineRevision && row.schema_version === m.schemaVersion && row.record_count === m.recordCount,
'Stored target identity mismatch');
const provenance = await db.prepare('SELECT * FROM content_publication_provenance WHERE revision_id=?').bind(action.revision).first();
check(provenance?.repository === REPOSITORY && provenance.commit_sha === admission.target_commit, 'Target provenance mismatch');
const {results} = await db.prepare('SELECT record_id,kind,dataset,payload_json FROM content_records WHERE revision_id=? LIMIT ?').bind(action.revision,m.recordCount+1).all();
const expected = new Map(bundle.catalog.records.map(r=>[r.id,r]));
check(Array.isArray(results) && results.length === m.recordCount && new Set(results.map(r=>r.record_id)).size === results.length && results.every(r=>{
const e=expected.get(r.record_id);return e && r.kind===e.kind && r.dataset===e.dataset && r.payload_json===JSON.stringify(e);
}), 'Target record integrity failed');
const current = await readPublicationHead(db,engineRevision);
check(current.revision===action.expectedRevision && current.generation===action.expectedGeneration,'Stale publication expectation');
// SQL guards repeat head/generation/history/ownership/stop checks atomically.
// No catch-and-retry: unknown outcomes require a separate same-operation readback.
const result=await db.prepare('INSERT INTO content_publication_events(operation_id,channel,generation,from_revision,to_revision,provenance_commit,intent,created_at,writer_operation,writer_owner,writer_epoch) VALUES(?,?,?,?,?,?,?,?,?,?,?)')
.bind(action.operationId,channel,action.expectedGeneration+1,action.expectedRevision,action.revision,admission.target_commit,action.intent,new Date().toISOString(),identity.operationId,identity.owner,identity.epoch).run();
check(result && result.success!==false,'Promotion outcome uncertain');
const event=await db.prepare('SELECT * FROM content_publication_events WHERE operation_id=?').bind(action.operationId).first();
const after=await db.prepare('SELECT state FROM release_admission WHERE operation_id=?').bind(action.operationId).first();
check(exactEvent(event) && after?.state==='consumed','Promotion outcome uncertain');
return {status:'applied',applied:{revision:event.to_revision,generation:event.generation},current:await readPublicationHead(db,engineRevision),deliveryVerified:false,productionActionAllowed:false};
}
Loading