Separate Zapier, web, API, and leaf access planes with NATS authz
Some checks are pending
offline / test (push) Waiting to run
Some checks are pending
offline / test (push) Waiting to run
Zapier is one ingress. Direct web, customer API, and S2S leaf nodes are their own services. Every hop to an internal subject must pass verae.access.authz.check (default deny by plane).
This commit is contained in:
parent
ac38676645
commit
1b199ca4d4
117 changed files with 2640 additions and 105 deletions
38
packages/verae-access-authz/src/client.js
Normal file
38
packages/verae-access-authz/src/client.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/** Call verae.access.authz.check then the internal subject. Fail closed. */
|
||||
import { SUBJECTS } from './subjects.js';
|
||||
|
||||
export async function authorizeThenRequest(nc, sc, { plane, subject, principal, payload, timeout = 2000 }) {
|
||||
const kind = payload?.kind;
|
||||
const checkMsg = await nc.request(
|
||||
SUBJECTS.AUTHZ_CHECK,
|
||||
sc.encode(JSON.stringify({ plane, subject, principal, kind, payload })),
|
||||
{ timeout },
|
||||
);
|
||||
const decision = JSON.parse(sc.decode(checkMsg.data) || '{}');
|
||||
if (!decision.allow) {
|
||||
const err = new Error(decision.reason || 'denied');
|
||||
err.decision = decision;
|
||||
throw err;
|
||||
}
|
||||
const internal = decision.subject;
|
||||
const body = { ...payload, plane, principal, traceId: payload?.traceId };
|
||||
const m = await nc.request(internal, sc.encode(JSON.stringify(body)), { timeout });
|
||||
return { decision, body: JSON.parse(sc.decode(m.data) || '{}') };
|
||||
}
|
||||
|
||||
export async function authorizeThenPublish(nc, sc, { plane, subject, principal, payload, timeout = 2000 }) {
|
||||
const kind = payload?.kind;
|
||||
const checkMsg = await nc.request(
|
||||
SUBJECTS.AUTHZ_CHECK,
|
||||
sc.encode(JSON.stringify({ plane, subject, principal, kind, payload })),
|
||||
{ timeout },
|
||||
);
|
||||
const decision = JSON.parse(sc.decode(checkMsg.data) || '{}');
|
||||
if (!decision.allow) {
|
||||
const err = new Error(decision.reason || 'denied');
|
||||
err.decision = decision;
|
||||
throw err;
|
||||
}
|
||||
nc.publish(decision.subject, sc.encode(JSON.stringify({ ...payload, plane, principal })));
|
||||
return { decision };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue