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
12 changes: 10 additions & 2 deletions packages/outpost-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/outpost-server/src/authenticate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
});
});

Expand Down
9 changes: 5 additions & 4 deletions packages/outpost-server/src/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/outpost-server/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ export interface OutpostRegistrationResolver {
outpostId: string;
instanceId: string;
credentialId: string;
instancePublicKey: Uint8Array;
}): Promise<ResolvedInstanceAuthorization>;
}
Loading