@agenticprimitives/admission 0.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +63 -0
- package/dist/digests.d.ts +46 -0
- package/dist/digests.d.ts.map +1 -0
- package/dist/digests.js +164 -0
- package/dist/digests.js.map +1 -0
- package/dist/engine.d.ts +51 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +224 -0
- package/dist/engine.js.map +1 -0
- package/dist/execution.d.ts +53 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +166 -0
- package/dist/execution.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/invariants.d.ts +80 -0
- package/dist/invariants.d.ts.map +1 -0
- package/dist/invariants.js +288 -0
- package/dist/invariants.js.map +1 -0
- package/dist/ports.d.ts +149 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +9 -0
- package/dist/ports.js.map +1 -0
- package/dist/request-proof.d.ts +61 -0
- package/dist/request-proof.d.ts.map +1 -0
- package/dist/request-proof.js +175 -0
- package/dist/request-proof.js.map +1 -0
- package/dist/transport-policy.d.ts +47 -0
- package/dist/transport-policy.d.ts.map +1 -0
- package/dist/transport-policy.js +95 -0
- package/dist/transport-policy.js.map +1 -0
- package/dist/types.d.ts +430 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Signed Agentic request proof (spec 339 §13 — Phase 4).
|
|
2
|
+
//
|
|
3
|
+
// WHAT THIS IS FOR. An OAuth bearer proves someone once obtained a token. It does not prove that THIS
|
|
4
|
+
// request came from the party the token was issued to, was not altered in flight, and has not been
|
|
5
|
+
// sent before. A signed proof does, by committing to the things a replayer would have to change.
|
|
6
|
+
//
|
|
7
|
+
// THE BINDING SET IS THE SECURITY PROPERTY. Each field closes one move:
|
|
8
|
+
//
|
|
9
|
+
// http.method + authority + pathAndQuery captured proof cannot be aimed at another endpoint
|
|
10
|
+
// http.bodySha256 cannot be re-used with a different payload
|
|
11
|
+
// audience cannot be presented to a different boundary
|
|
12
|
+
// replayId cannot be sent twice
|
|
13
|
+
// expiresAt cannot be held and used later
|
|
14
|
+
// accessTokenSha256 cannot be paired with a different OAuth token
|
|
15
|
+
// transportConfirmation cannot be lifted off its certificate (RFC 8705)
|
|
16
|
+
//
|
|
17
|
+
// Drop any one and the proof still verifies — it just stops meaning what it looks like it means. That
|
|
18
|
+
// is why verification below checks all of them rather than only the signature, and why every check
|
|
19
|
+
// returns a reason code instead of a boolean.
|
|
20
|
+
//
|
|
21
|
+
// ORDERING: cheap structural checks first, then the replay CONSUME, then the signature. Consume before
|
|
22
|
+
// verify is deliberate — a replayed proof must be spent even if it would have verified, or an attacker
|
|
23
|
+
// can probe with a valid captured proof indefinitely by making the signature fail.
|
|
24
|
+
import { canonicalizeJson } from '@agenticprimitives/types';
|
|
25
|
+
const enc = new TextEncoder();
|
|
26
|
+
async function sha256Hex(bytes) {
|
|
27
|
+
const input = typeof bytes === 'string' ? enc.encode(bytes) : bytes;
|
|
28
|
+
const d = await crypto.subtle.digest('SHA-256', input);
|
|
29
|
+
return [...new Uint8Array(d)].map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
30
|
+
}
|
|
31
|
+
/** `sha256:<hex>` over raw bytes — for `http.bodySha256` and `accessTokenSha256`. */
|
|
32
|
+
export async function sha256Of(bytes) {
|
|
33
|
+
return `sha256:${await sha256Hex(bytes)}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The canonical body a proof signature covers.
|
|
37
|
+
*
|
|
38
|
+
* Every claim is included. There is no "unsigned extras" slot, deliberately: a field outside the
|
|
39
|
+
* signature is a field an intermediary can rewrite, and the whole point of this object is that nobody
|
|
40
|
+
* between the signer and the boundary can change what it says.
|
|
41
|
+
*/
|
|
42
|
+
export function requestProofBody(claims) {
|
|
43
|
+
return {
|
|
44
|
+
schemaVersion: claims.schemaVersion,
|
|
45
|
+
principalAgentId: claims.principalAgentId,
|
|
46
|
+
actingAgentId: claims.actingAgentId,
|
|
47
|
+
runtimeId: claims.runtimeId,
|
|
48
|
+
sessionKeyId: claims.sessionKeyId,
|
|
49
|
+
delegationRefs: [...claims.delegationRefs].sort(),
|
|
50
|
+
audience: claims.audience,
|
|
51
|
+
issuedAt: claims.issuedAt,
|
|
52
|
+
expiresAt: claims.expiresAt,
|
|
53
|
+
replayId: claims.replayId,
|
|
54
|
+
http: {
|
|
55
|
+
method: claims.http.method.toUpperCase(),
|
|
56
|
+
authority: claims.http.authority.toLowerCase(),
|
|
57
|
+
pathAndQuery: claims.http.pathAndQuery,
|
|
58
|
+
bodySha256: claims.http.bodySha256,
|
|
59
|
+
},
|
|
60
|
+
a2a: {
|
|
61
|
+
protocolVersion: claims.a2a.protocolVersion,
|
|
62
|
+
protocolBinding: claims.a2a.protocolBinding,
|
|
63
|
+
operation: claims.a2a.operation,
|
|
64
|
+
taskId: claims.a2a.taskId ?? null,
|
|
65
|
+
contextId: claims.a2a.contextId ?? null,
|
|
66
|
+
requestedCapabilityId: claims.a2a.requestedCapabilityId ?? null,
|
|
67
|
+
a2aSkillId: claims.a2a.a2aSkillId ?? null,
|
|
68
|
+
},
|
|
69
|
+
accessTokenSha256: claims.accessTokenSha256 ?? null,
|
|
70
|
+
transportConfirmation: claims.transportConfirmation ?? null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** The digest the session key signs. */
|
|
74
|
+
export async function requestProofDigest(claims) {
|
|
75
|
+
return `sha256:${await sha256Hex(canonicalizeJson(requestProofBody(claims)))}`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Verify a request proof against what actually arrived.
|
|
79
|
+
*
|
|
80
|
+
* Never throws. A rejected proof returns a precise reason code for the AUDIT LOG; the public response
|
|
81
|
+
* is a generic authentication failure (§26.2), because these codes are a map of exactly how to
|
|
82
|
+
* construct a valid proof.
|
|
83
|
+
*/
|
|
84
|
+
export async function verifyRequestProof(input) {
|
|
85
|
+
const c = input.claims;
|
|
86
|
+
const nowMs = (input.now ?? new Date()).getTime();
|
|
87
|
+
const skewMs = (input.clockSkewSeconds ?? 60) * 1000;
|
|
88
|
+
const fail = (code, detail) => ({
|
|
89
|
+
ok: false,
|
|
90
|
+
code,
|
|
91
|
+
detail,
|
|
92
|
+
});
|
|
93
|
+
if (c.schemaVersion !== '1')
|
|
94
|
+
return fail('REQUEST_PROOF_INVALID', 'unknown proof schema version');
|
|
95
|
+
// ── Freshness ────────────────────────────────────────────────────────────
|
|
96
|
+
if (c.expiresAt * 1000 <= nowMs)
|
|
97
|
+
return fail('REQUEST_PROOF_EXPIRED', 'proof has expired');
|
|
98
|
+
if (c.issuedAt * 1000 > nowMs + skewMs) {
|
|
99
|
+
// A future-dated proof extends its own lifetime past what the signer intended.
|
|
100
|
+
return fail('REQUEST_PROOF_INVALID', 'proof is issued in the future beyond allowed clock skew');
|
|
101
|
+
}
|
|
102
|
+
if (c.expiresAt <= c.issuedAt)
|
|
103
|
+
return fail('REQUEST_PROOF_INVALID', 'proof expires before it is issued');
|
|
104
|
+
// ── Addressed to us ──────────────────────────────────────────────────────
|
|
105
|
+
if (c.audience !== input.expectedAudience) {
|
|
106
|
+
return fail('REQUEST_AUDIENCE_MISMATCH', 'proof is addressed to a different boundary');
|
|
107
|
+
}
|
|
108
|
+
// ── About THIS request ───────────────────────────────────────────────────
|
|
109
|
+
const o = input.observed;
|
|
110
|
+
if (c.http.method.toUpperCase() !== o.method.toUpperCase()) {
|
|
111
|
+
return fail('REQUEST_PROOF_INVALID', 'proof covers a different HTTP method');
|
|
112
|
+
}
|
|
113
|
+
if (c.http.authority.toLowerCase() !== o.authority.toLowerCase()) {
|
|
114
|
+
return fail('REQUEST_PROOF_INVALID', 'proof covers a different authority');
|
|
115
|
+
}
|
|
116
|
+
if (c.http.pathAndQuery !== o.pathAndQuery) {
|
|
117
|
+
return fail('REQUEST_PROOF_INVALID', 'proof covers a different path');
|
|
118
|
+
}
|
|
119
|
+
const observedBody = await sha256Of(o.rawBody);
|
|
120
|
+
if (c.http.bodySha256 !== observedBody) {
|
|
121
|
+
// The payload changed after signing. Its own code because it is the one an intermediary causes.
|
|
122
|
+
return fail('REQUEST_BODY_DIGEST_MISMATCH', 'request body does not match the signed digest');
|
|
123
|
+
}
|
|
124
|
+
// ── Bound to the credentials it travelled with ───────────────────────────
|
|
125
|
+
if (c.accessTokenSha256) {
|
|
126
|
+
if (!o.accessToken) {
|
|
127
|
+
return fail('REQUEST_PROOF_INVALID', 'proof is token-bound but no access token was presented');
|
|
128
|
+
}
|
|
129
|
+
if ((await sha256Of(o.accessToken)) !== c.accessTokenSha256) {
|
|
130
|
+
return fail('REQUEST_PROOF_INVALID', 'proof is bound to a different access token');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (c.transportConfirmation) {
|
|
134
|
+
if (c.transportConfirmation.type !== 'x5t#S256') {
|
|
135
|
+
return fail('REQUEST_PROOF_INVALID', 'unsupported transport confirmation method');
|
|
136
|
+
}
|
|
137
|
+
if (c.transportConfirmation.certificateThumbprint !== o.clientCertificateSha256) {
|
|
138
|
+
return fail('CERTIFICATE_TOKEN_BINDING_MISMATCH', 'proof is bound to a different client certificate');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// ── Single use, BEFORE the signature check ───────────────────────────────
|
|
142
|
+
// Spend it even if the signature would fail. Otherwise a captured valid proof becomes an unlimited
|
|
143
|
+
// probing oracle: flip one signature byte, learn everything else, and the replay id is never spent.
|
|
144
|
+
const digest = await requestProofDigest(c);
|
|
145
|
+
let replay;
|
|
146
|
+
try {
|
|
147
|
+
replay = await input.replayStore.consume({
|
|
148
|
+
namespace: input.replayNamespace,
|
|
149
|
+
replayId: c.replayId,
|
|
150
|
+
digest,
|
|
151
|
+
expiresAt: new Date(c.expiresAt * 1000).toISOString(),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// A replay store we cannot reach has not told us this is fresh (ADR-0013).
|
|
156
|
+
return fail('POLICY_DEPENDENCY_UNAVAILABLE', 'replay store unavailable — cannot establish freshness');
|
|
157
|
+
}
|
|
158
|
+
if (replay === 'REPLAY')
|
|
159
|
+
return fail('REQUEST_REPLAY_DETECTED', 'replay id already consumed');
|
|
160
|
+
if (replay === 'CONFLICT') {
|
|
161
|
+
return fail('REQUEST_REPLAY_DETECTED', 'replay id reused across different proof digests');
|
|
162
|
+
}
|
|
163
|
+
// ── Signature last ───────────────────────────────────────────────────────
|
|
164
|
+
let valid = false;
|
|
165
|
+
try {
|
|
166
|
+
valid = await input.verifySignature({ keyId: input.keyId, digest, signature: input.signature });
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
valid = false;
|
|
170
|
+
}
|
|
171
|
+
if (!valid)
|
|
172
|
+
return fail('REQUEST_PROOF_INVALID', 'signature did not verify');
|
|
173
|
+
return { ok: true, proofDigest: digest };
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=request-proof.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-proof.js","sourceRoot":"","sources":["../src/request-proof.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,EAAE;AACF,sGAAsG;AACtG,mGAAmG;AACnG,iGAAiG;AACjG,EAAE;AACF,wEAAwE;AACxE,EAAE;AACF,gGAAgG;AAChG,wFAAwF;AACxF,yFAAyF;AACzF,kEAAkE;AAClE,2EAA2E;AAC3E,2FAA2F;AAC3F,6FAA6F;AAC7F,EAAE;AACF,sGAAsG;AACtG,mGAAmG;AACnG,8CAA8C;AAC9C,EAAE;AACF,uGAAuG;AACvG,uGAAuG;AACvG,mFAAmF;AAEnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAK5D,MAA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IAAI,CAAC;QACH,MAAM,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC;YACvC,SAAS,EAAE,KAAK,CAAC,eAAe;YAChC,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,MAAM;YACN,SAAS,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE;SACtD,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;QAC3E,OAAO,IAAI,CAAC,+BAA+B,EAAE,uDAAuD,CAAC,CAAC;IACxG,CAAC;IACD,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,yBAAyB,EAAE,4BAA4B,CAAC,CAAC;IAC9F,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,yBAAyB,EAAE,iDAAiD,CAAC,CAAC;IAC5F,CAAC;IAED,4EAA4E;IAC5E,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,CAAC;QACH,KAAK,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAClG,CAAC;IAAC,MAAM,CAAC;QACP,KAAK,GAAG,KAAK,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC,uBAAuB,EAAE,0BAA0B,CAAC,CAAC;IAE7E,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AdmissionPolicyEvaluator } from './ports.js';
|
|
2
|
+
import type { AdmissionConstraint, AdmissionObligation, AdmissionRequest, TransportAssurance } from './types.js';
|
|
3
|
+
/** Is `observed` at least `required`? */
|
|
4
|
+
export declare function meetsTransportAssurance(observed: TransportAssurance, required: TransportAssurance): boolean;
|
|
5
|
+
export interface TransportAssuranceRule {
|
|
6
|
+
/**
|
|
7
|
+
* The minimum this request must have reached.
|
|
8
|
+
*
|
|
9
|
+
* Omit (or return `undefined` from `requirementFor`) and there is NO requirement — that is the
|
|
10
|
+
* optional baseline, and it is the default rather than something to opt into.
|
|
11
|
+
*/
|
|
12
|
+
minimumAssurance?: TransportAssurance;
|
|
13
|
+
/**
|
|
14
|
+
* Constraints attached when the request is BELOW `preferredAssurance`.
|
|
15
|
+
*
|
|
16
|
+
* The mechanism for "you may proceed over plain HTTPS, but not for more than X". Constraints
|
|
17
|
+
* narrow; they never widen, so a stronger transport can only ever have fewer of them.
|
|
18
|
+
*/
|
|
19
|
+
preferredAssurance?: TransportAssurance;
|
|
20
|
+
constraintsBelowPreferred?: AdmissionConstraint[];
|
|
21
|
+
obligationsBelowPreferred?: AdmissionObligation[];
|
|
22
|
+
}
|
|
23
|
+
export interface TransportAssurancePolicyOptions {
|
|
24
|
+
contributorId?: string;
|
|
25
|
+
policyVersion?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Resolve the rule for this request — by target agent, capability, environment, whatever the
|
|
28
|
+
* deployment keys on. Returning `undefined` means "no transport requirement", which is the correct
|
|
29
|
+
* answer for most traffic.
|
|
30
|
+
*/
|
|
31
|
+
requirementFor: (request: AdmissionRequest) => TransportAssuranceRule | undefined;
|
|
32
|
+
/** Local-only diagnostics. */
|
|
33
|
+
observe?: (o: {
|
|
34
|
+
observed: TransportAssurance;
|
|
35
|
+
required?: TransportAssurance;
|
|
36
|
+
effect: string;
|
|
37
|
+
}) => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* An evaluator that turns transport evidence into an admission contribution.
|
|
41
|
+
*
|
|
42
|
+
* ALLOW here means "transport did not disqualify this request". It is one vote among relationship,
|
|
43
|
+
* delegation, capability, entitlement and situation — and because the engine denies on any DENY, this
|
|
44
|
+
* evaluator can only ever make admission harder, never easier. That asymmetry is the whole design.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createTransportAssuranceEvaluator(opts: TransportAssurancePolicyOptions): AdmissionPolicyEvaluator;
|
|
47
|
+
//# sourceMappingURL=transport-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-policy.d.ts","sourceRoot":"","sources":["../src/transport-policy.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EAEnB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAKpB,yCAAyC;AACzC,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,kBAAkB,EAC5B,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAET;AAED,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IAEtC;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,yBAAyB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAClD,yBAAyB,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACnD;AAED,MAAM,WAAW,+BAA+B;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,sBAAsB,GAAG,SAAS,CAAC;IAElF,8BAA8B;IAC9B,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE;QAAE,QAAQ,EAAE,kBAAkB,CAAC;QAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACxG;AAED;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,+BAA+B,GACpC,wBAAwB,CAiE1B"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Transport assurance as an admission INPUT (spec 339 §9.4, §10 — Phase 5).
|
|
2
|
+
//
|
|
3
|
+
// This is where "mTLS is optional" stops being a slogan and becomes a decision. Optional means three
|
|
4
|
+
// distinct things, and this evaluator is what keeps them distinct:
|
|
5
|
+
//
|
|
6
|
+
// 1. A request that presents no client certificate is NORMAL. It is not an error, not a warning,
|
|
7
|
+
// and not a lower-priority citizen — the baseline profile is the common case.
|
|
8
|
+
// 2. A deployment MAY require mTLS for a particular target or capability. That requirement is
|
|
9
|
+
// POLICY, expressed here, never a property of the transport layer deciding for itself.
|
|
10
|
+
// 3. Stronger transport MAY relax a CONSTRAINT — a spend ceiling, a rate bucket — but it may never
|
|
11
|
+
// remove a STAGE. Relationship, delegation, capability and entitlement are unaffected by how the
|
|
12
|
+
// bytes arrived.
|
|
13
|
+
//
|
|
14
|
+
// THE INVERSION THIS EXISTS TO PREVENT. Without an explicit evaluator, "mTLS matters" gets implemented
|
|
15
|
+
// as an `if` somewhere in a request handler, and the natural shape of that `if` is
|
|
16
|
+
// `if (mtls) { skip }` rather than `if (required && !mtls) { deny }`. One is a policy; the other is a
|
|
17
|
+
// bypass wearing a policy's clothes. Making the requirement a named, ordered contribution means the
|
|
18
|
+
// only thing transport can do is RAISE the bar.
|
|
19
|
+
//
|
|
20
|
+
// It reads `observedTransportAssurance`, not the request's self-reported label, so a caller cannot
|
|
21
|
+
// claim its way past a requirement.
|
|
22
|
+
import { observedTransportAssurance } from './invariants.js';
|
|
23
|
+
/** Ordering of the ladder. Higher is strictly more evidence — never more authority. */
|
|
24
|
+
const RANK = { HTTPS: 0, MTLS: 1, SPIFFE_MTLS: 2 };
|
|
25
|
+
/** Is `observed` at least `required`? */
|
|
26
|
+
export function meetsTransportAssurance(observed, required) {
|
|
27
|
+
return RANK[observed] >= RANK[required];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An evaluator that turns transport evidence into an admission contribution.
|
|
31
|
+
*
|
|
32
|
+
* ALLOW here means "transport did not disqualify this request". It is one vote among relationship,
|
|
33
|
+
* delegation, capability, entitlement and situation — and because the engine denies on any DENY, this
|
|
34
|
+
* evaluator can only ever make admission harder, never easier. That asymmetry is the whole design.
|
|
35
|
+
*/
|
|
36
|
+
export function createTransportAssuranceEvaluator(opts) {
|
|
37
|
+
const contributorId = opts.contributorId ?? 'transport-assurance';
|
|
38
|
+
const policyVersion = opts.policyVersion ?? '1.0';
|
|
39
|
+
return {
|
|
40
|
+
contributorId,
|
|
41
|
+
async evaluate(request) {
|
|
42
|
+
const evaluatedAt = new Date().toISOString();
|
|
43
|
+
// What was VALIDATED, never what was claimed. A request asserting SPIFFE_MTLS with an
|
|
44
|
+
// unverified certificate observes as HTTPS here and is measured against that.
|
|
45
|
+
const observed = observedTransportAssurance(request.authentication.optionalTransportEvidence);
|
|
46
|
+
let rule;
|
|
47
|
+
try {
|
|
48
|
+
rule = opts.requirementFor(request);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// A policy source that threw did not tell us this request is exempt.
|
|
52
|
+
opts.observe?.({ observed, effect: 'INDETERMINATE' });
|
|
53
|
+
return {
|
|
54
|
+
contributorId,
|
|
55
|
+
policyVersion,
|
|
56
|
+
effect: 'INDETERMINATE',
|
|
57
|
+
reasonCodes: ['POLICY_DEPENDENCY_UNAVAILABLE'],
|
|
58
|
+
evaluatedAt,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// ── No requirement: the optional baseline, and the common case ───────
|
|
62
|
+
if (!rule) {
|
|
63
|
+
opts.observe?.({ observed, effect: 'ALLOW' });
|
|
64
|
+
return { contributorId, policyVersion, effect: 'ALLOW', reasonCodes: [], evaluatedAt };
|
|
65
|
+
}
|
|
66
|
+
// ── A requirement that is not met is a DENY, not a downgrade ─────────
|
|
67
|
+
if (rule.minimumAssurance && !meetsTransportAssurance(observed, rule.minimumAssurance)) {
|
|
68
|
+
// ADR-0013: no silent fallback. A profile requiring mTLS does not quietly serve the request
|
|
69
|
+
// over plain HTTPS with a note in the log.
|
|
70
|
+
opts.observe?.({ observed, required: rule.minimumAssurance, effect: 'DENY' });
|
|
71
|
+
return {
|
|
72
|
+
contributorId,
|
|
73
|
+
policyVersion,
|
|
74
|
+
effect: 'DENY',
|
|
75
|
+
reasonCodes: ['MTLS_REQUIRED_FOR_PROFILE'],
|
|
76
|
+
evaluatedAt,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// ── Below preferred: proceed, but narrower ───────────────────────────
|
|
80
|
+
const belowPreferred = rule.preferredAssurance !== undefined &&
|
|
81
|
+
!meetsTransportAssurance(observed, rule.preferredAssurance);
|
|
82
|
+
opts.observe?.({ observed, required: rule.minimumAssurance, effect: 'ALLOW' });
|
|
83
|
+
return {
|
|
84
|
+
contributorId,
|
|
85
|
+
policyVersion,
|
|
86
|
+
effect: 'ALLOW',
|
|
87
|
+
reasonCodes: [],
|
|
88
|
+
constraints: belowPreferred ? (rule.constraintsBelowPreferred ?? []) : [],
|
|
89
|
+
obligations: belowPreferred ? (rule.obligationsBelowPreferred ?? []) : [],
|
|
90
|
+
evaluatedAt,
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=transport-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-policy.js","sourceRoot":"","sources":["../src/transport-policy.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,qGAAqG;AACrG,mEAAmE;AACnE,EAAE;AACF,mGAAmG;AACnG,mFAAmF;AACnF,gGAAgG;AAChG,4FAA4F;AAC5F,qGAAqG;AACrG,sGAAsG;AACtG,sBAAsB;AACtB,EAAE;AACF,uGAAuG;AACvG,mFAAmF;AACnF,sGAAsG;AACtG,oGAAoG;AACpG,gDAAgD;AAChD,EAAE;AACF,mGAAmG;AACnG,oCAAoC;AAEpC,OAAO,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