From e1a76934dbd689d6f871e096cfb6139baff359bd Mon Sep 17 00:00:00 2001 From: Tobias Herber <22559657+herber@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:41:20 +0200 Subject: [PATCH] Harden outpost key rotation --- packages/outpost-server/README.md | 12 ++++++++++-- packages/outpost-server/src/authenticate.test.ts | 5 +++-- packages/outpost-server/src/authenticate.ts | 9 +++++---- packages/outpost-server/src/resolver.ts | 1 + 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/outpost-server/README.md b/packages/outpost-server/README.md index 985b53b..4c0b05b 100644 --- a/packages/outpost-server/README.md +++ b/packages/outpost-server/README.md @@ -88,11 +88,17 @@ let outpostServer = createOutpostServer({ return { status: 'ok', manifest: await buildManifestFor(outpost) }; }, - async resolveInstanceAuthorization({ outpostId, instanceId, credentialId }) { + async resolveInstanceAuthorization({ + outpostId, + instanceId, + credentialId, + instancePublicKey + }) { let instance = await db.outpostInstance.findFirst({ where: { id: instanceId, outpostId, credentialId } }); if (!instance) return { status: 'unknown' }; + if (!sameBytes(instance.publicKey, instancePublicKey)) return { status: 'unknown' }; if (instance.status != 'active') return { status: 'instance_disabled' }; let outpost = await db.outpost.findUnique({ where: { id: outpostId } }); @@ -249,7 +255,9 @@ let authed = await verifyOutpostRequest({ tokens, service: 'my.service', resolve on its own (spec §42 Step 5): `resolver.resolveInstanceAuthorization` is also checked, rejecting with `instance_disabled`/`outpost_disabled` if either has since been disabled, or `invalid_instance_token` if the instance/credential/outpost combination in the token doesn't -correspond to any real, currently-matching registration. This is how a disabled or revoked +correspond to any real, currently-matching registration. The resolver also receives the token's +`instancePublicKey`; reporting `unknown` when it differs from the instance's current key locks out +a token issued before the instance re-registered with a new key. This is how a disabled or revoked Instance/Outpost is locked out immediately, without waiting for its (potentially long-lived) Instance Token to expire. Omit `resolver` where none is available (e.g. an intermediate Outpost relaying nested traffic with no local database) — the check is then left to whichever authority diff --git a/packages/outpost-server/src/authenticate.test.ts b/packages/outpost-server/src/authenticate.test.ts index f8c770f..8f479cd 100644 --- a/packages/outpost-server/src/authenticate.test.ts +++ b/packages/outpost-server/src/authenticate.test.ts @@ -392,7 +392,7 @@ describe('authenticate', () => { expect(res.status).toBe(200); }); - it('passes the resolver the outpost/instance/credential ids from the token', async () => { + it('passes the resolver the outpost/instance/credential ids and instance key from the token', async () => { let seen: any; let resolver = { resolveInstanceAuthorization: async ( @@ -408,7 +408,8 @@ describe('authenticate', () => { expect(seen).toEqual({ outpostId: OUTPOST_ID, instanceId: INSTANCE_ID, - credentialId: CREDENTIAL_ID + credentialId: CREDENTIAL_ID, + instancePublicKey: await Ed25519.exportPublicKey(instance.publicKey) }); }); diff --git a/packages/outpost-server/src/authenticate.ts b/packages/outpost-server/src/authenticate.ts index 5eaf5bf..957e7c4 100644 --- a/packages/outpost-server/src/authenticate.ts +++ b/packages/outpost-server/src/authenticate.ts @@ -80,11 +80,14 @@ export let verifyOutpostRequest = async ( throw new OutpostServerError('outpost_mismatch'); } + let instancePublicKeyBytes = base64url.decode(tokenData.instance_public_key); + if (options.resolver) { let authorization = await options.resolver.resolveInstanceAuthorization({ outpostId: tokenData.outpost_id, instanceId: tokenData.instance_id, - credentialId: tokenData.credential_id + credentialId: tokenData.credential_id, + instancePublicKey: instancePublicKeyBytes }); if (authorization.status == 'unknown') @@ -155,9 +158,7 @@ export let verifyOutpostRequest = async ( let scheme = forwardedProto || url.protocol.replace(/:$/, ''); let authority = forwardedHost || url.host; - let instancePublicKey = await Ed25519.importPublicKey( - base64url.decode(tokenData.instance_public_key) - ); + let instancePublicKey = await Ed25519.importPublicKey(instancePublicKeyBytes); let verifiedSignature = await verifyRequestSignature( instancePublicKey, diff --git a/packages/outpost-server/src/resolver.ts b/packages/outpost-server/src/resolver.ts index 8dc5099..0cfbdb6 100644 --- a/packages/outpost-server/src/resolver.ts +++ b/packages/outpost-server/src/resolver.ts @@ -44,5 +44,6 @@ export interface OutpostRegistrationResolver { outpostId: string; instanceId: string; credentialId: string; + instancePublicKey: Uint8Array; }): Promise; }