managed-deepagents 0.5.3-dev.112 → 0.5.3-dev.113
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/README.md +32 -18
- package/dist/channels/manifest.d.ts +0 -2
- package/dist/channels/manifest.d.ts.map +1 -1
- package/dist/extension.d.ts +2 -2
- package/dist/extension.js +2 -2
- package/dist/identity/index.d.ts +2 -4
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +8 -55
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/options.js +5 -0
- package/dist/identity/options.js.map +1 -1
- package/dist/identity/supabase.d.ts.map +1 -1
- package/dist/identity/supabase.js +2 -0
- package/dist/identity/supabase.js.map +1 -1
- package/dist/identity/types.d.ts +8 -60
- package/dist/identity/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/namespaces.d.ts +0 -6
- package/dist/namespaces.d.ts.map +1 -1
- package/dist/namespaces.js +0 -6
- package/dist/namespaces.js.map +1 -1
- package/dist/runtime/auth.d.ts +11 -14
- package/dist/runtime/auth.d.ts.map +1 -1
- package/dist/runtime/auth.js +15 -54
- package/dist/runtime/auth.js.map +1 -1
- package/dist/runtime/cors.d.ts +4 -4
- package/dist/runtime/cors.d.ts.map +1 -1
- package/dist/runtime/cors.js +4 -8
- package/dist/runtime/cors.js.map +1 -1
- package/dist/runtime/identity-runtime.d.ts +2 -10
- package/dist/runtime/identity-runtime.d.ts.map +1 -1
- package/dist/runtime/identity-runtime.js +2 -38
- package/dist/runtime/identity-runtime.js.map +1 -1
- package/dist/runtime/index.d.ts +15 -3
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +8 -9
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/managed-middleware.d.ts +2 -3
- package/dist/runtime/managed-middleware.d.ts.map +1 -1
- package/dist/runtime/managed-middleware.js +12 -12
- package/dist/runtime/managed-middleware.js.map +1 -1
- package/dist/runtime/managed-tools.d.ts +4 -11
- package/dist/runtime/managed-tools.d.ts.map +1 -1
- package/dist/runtime/managed-tools.js +11 -18
- package/dist/runtime/managed-tools.js.map +1 -1
- package/dist/runtime/memory/context-io.d.ts +0 -1
- package/dist/runtime/memory/context-io.d.ts.map +1 -1
- package/dist/runtime/memory/context-io.js +0 -10
- package/dist/runtime/memory/context-io.js.map +1 -1
- package/dist/runtime/memory/mounts.d.ts.map +1 -1
- package/dist/runtime/memory/mounts.js +0 -10
- package/dist/runtime/memory/mounts.js.map +1 -1
- package/dist/runtime/validated-token.d.ts.map +1 -1
- package/dist/runtime/validated-token.js +7 -1
- package/dist/runtime/validated-token.js.map +1 -1
- package/package.json +15 -14
- package/types/index.d.ts +6 -0
- package/types/markdown-md.d.ts +14 -0
- package/dist/channels/index.d.ts +0 -25
- package/dist/channels/index.d.ts.map +0 -1
- package/dist/channels/index.js +0 -18
- package/dist/channels/index.js.map +0 -1
- package/dist/identity/credential-resolvers.d.ts +0 -21
- package/dist/identity/credential-resolvers.d.ts.map +0 -1
- package/dist/identity/credential-resolvers.js +0 -31
- package/dist/identity/credential-resolvers.js.map +0 -1
- package/dist/identity/github/credentials-store.d.ts +0 -76
- package/dist/identity/github/credentials-store.d.ts.map +0 -1
- package/dist/identity/github/credentials-store.js +0 -270
- package/dist/identity/github/credentials-store.js.map +0 -1
- package/dist/identity/github/credentials.d.ts +0 -85
- package/dist/identity/github/credentials.d.ts.map +0 -1
- package/dist/identity/github/credentials.js +0 -183
- package/dist/identity/github/credentials.js.map +0 -1
- package/dist/identity/github/index.d.ts +0 -5
- package/dist/identity/github/index.d.ts.map +0 -1
- package/dist/identity/github/index.js +0 -5
- package/dist/identity/github/index.js.map +0 -1
- package/dist/runtime/credentials.d.ts +0 -68
- package/dist/runtime/credentials.d.ts.map +0 -1
- package/dist/runtime/credentials.js +0 -235
- package/dist/runtime/credentials.js.map +0 -1
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { importPKCS8, SignJWT } from "jose";
|
|
2
|
-
import { fetchWithTimeout, PROVIDER_HTTP_TIMEOUT_MS, } from "../../runtime/http.js";
|
|
3
|
-
import { getGitHubCredentialStore } from "./credentials-store.js";
|
|
4
|
-
const DEFAULT_READ_CHAIN = ["installation", "pat"];
|
|
5
|
-
const DEFAULT_WRITE_CHAIN = ["user"];
|
|
6
|
-
const GITHUB_API_VERSION = "2022-11-28";
|
|
7
|
-
const USER_AGENT = "managed-deepagents";
|
|
8
|
-
/**
|
|
9
|
-
* Build a custom credential resolver for GitHub connection targets.
|
|
10
|
-
*
|
|
11
|
-
* Use this through the GitHub namespace:
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { defineIdentity, github } from "managed-deepagents";
|
|
15
|
-
*
|
|
16
|
-
* export const identity = defineIdentity({
|
|
17
|
-
* credentials: credentials.github({ repositories: ["acme/*"] }),
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* User-token chains read from `resolveUserToken`, which defaults to the GitHub
|
|
22
|
-
* credential store.
|
|
23
|
-
*/
|
|
24
|
-
export function credentials(options = {}) {
|
|
25
|
-
validateGithubCredentialsOptions(options);
|
|
26
|
-
return {
|
|
27
|
-
async resolve({ identity, target }) {
|
|
28
|
-
if (target.name !== "github") {
|
|
29
|
-
throw new Error(`credentials.github(...) can only resolve target name "github" (received "${target.name}").`);
|
|
30
|
-
}
|
|
31
|
-
const repo = repoFromTarget(target) ?? defaultRepoFromPatterns(options.repositories);
|
|
32
|
-
assertRepoAllowed(repo, options.repositories);
|
|
33
|
-
const chain = target.intent === "write"
|
|
34
|
-
? (options.write ?? DEFAULT_WRITE_CHAIN)
|
|
35
|
-
: (options.read ?? DEFAULT_READ_CHAIN);
|
|
36
|
-
for (const source of chain) {
|
|
37
|
-
const credential = await resolveSource(source, { identity, target }, options);
|
|
38
|
-
if (credential) {
|
|
39
|
-
return credential;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
throw new Error(`credentials.github(...) could not resolve a GitHub credential for target "${target.name}".`);
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function validateGithubCredentialsOptions(options) {
|
|
47
|
-
validateChain("read", options.read);
|
|
48
|
-
validateChain("write", options.write);
|
|
49
|
-
if (options.repositories) {
|
|
50
|
-
for (const pattern of options.repositories) {
|
|
51
|
-
if (!isAllowedRepoPattern(pattern)) {
|
|
52
|
-
throw new Error(`credentials.github(...) repository allowlist entry "${pattern}" must look like "owner/repo" or "owner/*".`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function validateChain(name, chain) {
|
|
58
|
-
if (chain === undefined)
|
|
59
|
-
return;
|
|
60
|
-
if (!Array.isArray(chain) || chain.length === 0) {
|
|
61
|
-
throw new Error(`credentials.github(...) \`${name}\` must be a non-empty token source list.`);
|
|
62
|
-
}
|
|
63
|
-
for (const source of chain) {
|
|
64
|
-
if (source !== "user" && source !== "installation" && source !== "pat") {
|
|
65
|
-
throw new Error(`credentials.github(...) unknown token source "${String(source)}".`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async function resolveSource(source, ctx, options) {
|
|
70
|
-
if (source === "pat") {
|
|
71
|
-
const token = options.pat ?? process.env.GITHUB_TOKEN ?? process.env.GITHUB_PAT;
|
|
72
|
-
return token ? bearer(token) : undefined;
|
|
73
|
-
}
|
|
74
|
-
if (source === "user") {
|
|
75
|
-
const resolve = options.resolveUserToken ?? defaultResolveUserToken;
|
|
76
|
-
const token = await resolve({
|
|
77
|
-
identity: ctx.identity,
|
|
78
|
-
scopes: ["repo"],
|
|
79
|
-
});
|
|
80
|
-
return token ? bearer(token) : undefined;
|
|
81
|
-
}
|
|
82
|
-
return installationCredential(ctx.target, options);
|
|
83
|
-
}
|
|
84
|
-
async function installationCredential(target, options) {
|
|
85
|
-
const appId = options.appId ?? process.env.GITHUB_APP_ID;
|
|
86
|
-
const privateKey = options.privateKey ?? process.env.GITHUB_APP_PRIVATE_KEY;
|
|
87
|
-
const installationId = stringMetadata(target, "installationId") ?? options.installationId;
|
|
88
|
-
if (!installationId) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
if (!appId || !privateKey) {
|
|
92
|
-
throw new Error('credentials.github(...) token source "installation" requires `appId` and `privateKey` (or GITHUB_APP_ID / GITHUB_APP_PRIVATE_KEY).');
|
|
93
|
-
}
|
|
94
|
-
const appJwt = options.createAppJwt
|
|
95
|
-
? await options.createAppJwt({ appId, privateKey })
|
|
96
|
-
: await createGitHubAppJwt({ appId, privateKey });
|
|
97
|
-
const fetchImpl = options.fetch ?? fetch;
|
|
98
|
-
const response = await fetchWithTimeout(`https://api.github.com/app/installations/${encodeURIComponent(installationId)}/access_tokens`, {
|
|
99
|
-
method: "POST",
|
|
100
|
-
headers: {
|
|
101
|
-
Accept: "application/vnd.github+json",
|
|
102
|
-
Authorization: `Bearer ${appJwt}`,
|
|
103
|
-
"User-Agent": USER_AGENT,
|
|
104
|
-
"X-GitHub-Api-Version": GITHUB_API_VERSION,
|
|
105
|
-
},
|
|
106
|
-
}, PROVIDER_HTTP_TIMEOUT_MS, fetchImpl);
|
|
107
|
-
if (!response.ok) {
|
|
108
|
-
throw new Error(`credentials.github(...) GitHub installation token request failed with ${response.status}.`);
|
|
109
|
-
}
|
|
110
|
-
const body = (await response.json());
|
|
111
|
-
if (typeof body.token !== "string" || body.token.length === 0) {
|
|
112
|
-
throw new Error("credentials.github(...) GitHub installation token response did not include `token`.");
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
...bearer(body.token),
|
|
116
|
-
...(typeof body.expires_at === "string"
|
|
117
|
-
? { expiresAt: body.expires_at }
|
|
118
|
-
: {}),
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
async function createGitHubAppJwt({ appId, privateKey, }) {
|
|
122
|
-
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
123
|
-
const key = await importPKCS8(privateKey, "RS256");
|
|
124
|
-
return new SignJWT({})
|
|
125
|
-
.setProtectedHeader({ alg: "RS256" })
|
|
126
|
-
.setIssuedAt(nowSeconds - 60)
|
|
127
|
-
.setExpirationTime(nowSeconds + 9 * 60)
|
|
128
|
-
.setIssuer(appId)
|
|
129
|
-
.sign(key);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Default user-token lookup: GitHub credential store keyed by user id.
|
|
133
|
-
* Returns undefined when no stored GitHub token exists for the user.
|
|
134
|
-
*/
|
|
135
|
-
export async function defaultResolveUserToken(args) {
|
|
136
|
-
const record = await getGitHubCredentialStore().getByUserId(args.identity.user.id);
|
|
137
|
-
return record?.accessToken;
|
|
138
|
-
}
|
|
139
|
-
function bearer(token) {
|
|
140
|
-
return { headers: { Authorization: `Bearer ${token}` } };
|
|
141
|
-
}
|
|
142
|
-
function repoFromTarget(target) {
|
|
143
|
-
const repo = stringMetadata(target, "repo");
|
|
144
|
-
if (repo)
|
|
145
|
-
return repo;
|
|
146
|
-
const owner = stringMetadata(target, "owner");
|
|
147
|
-
const name = stringMetadata(target, "repository");
|
|
148
|
-
return owner && name ? `${owner}/${name}` : undefined;
|
|
149
|
-
}
|
|
150
|
-
function stringMetadata(target, key) {
|
|
151
|
-
const value = target.metadata?.[key];
|
|
152
|
-
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
153
|
-
}
|
|
154
|
-
function assertRepoAllowed(repo, patterns) {
|
|
155
|
-
if (!patterns || patterns.length === 0)
|
|
156
|
-
return;
|
|
157
|
-
if (!repo) {
|
|
158
|
-
throw new Error("credentials.github(...) target metadata must include `repo` when repositories allowlist is configured (or include an exact owner/repo entry to default).");
|
|
159
|
-
}
|
|
160
|
-
if (!patterns.some((pattern) => repoMatches(repo, pattern))) {
|
|
161
|
-
throw new Error(`credentials.github(...) repository "${repo}" is not allowed by the configured repositories allowlist.`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/** First exact `owner/repo` pattern, used when callers omit `metadata.repo`. */
|
|
165
|
-
function defaultRepoFromPatterns(patterns) {
|
|
166
|
-
if (!patterns)
|
|
167
|
-
return undefined;
|
|
168
|
-
for (const pattern of patterns) {
|
|
169
|
-
if (!pattern.endsWith("/*"))
|
|
170
|
-
return pattern;
|
|
171
|
-
}
|
|
172
|
-
return undefined;
|
|
173
|
-
}
|
|
174
|
-
function repoMatches(repo, pattern) {
|
|
175
|
-
if (pattern.endsWith("/*")) {
|
|
176
|
-
return repo.startsWith(`${pattern.slice(0, -2)}/`);
|
|
177
|
-
}
|
|
178
|
-
return repo === pattern;
|
|
179
|
-
}
|
|
180
|
-
function isAllowedRepoPattern(pattern) {
|
|
181
|
-
return /^[A-Za-z0-9_.-]+\/(?:[A-Za-z0-9_.-]+|\*)$/.test(pattern);
|
|
182
|
-
}
|
|
183
|
-
//# sourceMappingURL=credentials.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../../src/identity/github/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE5C,OAAO,EACL,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AA8ElE,MAAM,kBAAkB,GAAwB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;AACxE,MAAM,mBAAmB,GAAwB,CAAC,MAAM,CAAC,CAAC;AAC1D,MAAM,kBAAkB,GAAG,YAAY,CAAC;AACxC,MAAM,UAAU,GAAG,oBAAoB,CAAC;AAExC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,WAAW,CACzB,OAAO,GAA6B,EAAE;IAEtC,gCAAgC,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO;QACL,KAAK,CAAC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A4D,CACxG,CAAC;IACJ,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,SAAS,uBAAuB,CAC9B,QAA8B;IAE9B,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,OAAO,CAAC;IAC9C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,OAAe;IAChD,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,IAAI,KAAK,OAAO,CAAC;AAC1B,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAe;IAC3C,OAAO,2CAA2C,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identity/github/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,WAAW,EACX,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/identity/github/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,WAAW,GAKZ,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { CredentialTarget, IdentityConfig, ResolvedCredential, RuntimeIdentity } from "../identity/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Component 5 — Credentials, custom mode.
|
|
4
|
-
*
|
|
5
|
-
* The escape hatch Agent Auth can't cover: bespoke per-caller credential minting
|
|
6
|
-
* via an in-process resolver callback or a hosted token-exchange endpoint. It
|
|
7
|
-
* runs in the worker (not the shared ingress auth handler), applies the output
|
|
8
|
-
* to downstream calls, and caches per `(user, target)` until the credential's
|
|
9
|
-
* `expiresAt`. Secrets live only in this in-memory cache keyed by identity —
|
|
10
|
-
* never in thread state or traces.
|
|
11
|
-
*
|
|
12
|
-
* Managed credential modes (`"user"` / `"agent"`) select downstream credential
|
|
13
|
-
* ownership on the identity axis; only `custom` builds a
|
|
14
|
-
* {@link CredentialsProvider} here.
|
|
15
|
-
*/
|
|
16
|
-
/** Env var holding the HMAC secret MDA signs the endpoint assertion with. */
|
|
17
|
-
export declare const CREDENTIAL_SIGNING_SECRET_ENV = "MDA_TOKEN_EXCHANGE_SECRET";
|
|
18
|
-
/** Per-call options for {@link CredentialsProvider.for}. */
|
|
19
|
-
export interface CredentialForOptions {
|
|
20
|
-
/** Skip the cache and force a fresh mint (e.g. after a downstream 401). */
|
|
21
|
-
forceRefresh?: boolean;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* The per-run credential surface a tool receives as `runtime.credentials`.
|
|
25
|
-
* Tools call `runtime.credentials.for(target)` and attach the returned headers
|
|
26
|
-
* to their downstream request.
|
|
27
|
-
*/
|
|
28
|
-
export interface CredentialsProvider {
|
|
29
|
-
for(target: CredentialTarget, options?: CredentialForOptions): Promise<ResolvedCredential>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Side effects the executor depends on, injectable so resolution is
|
|
33
|
-
* deterministic under test (no real clock, network, or signing key).
|
|
34
|
-
*/
|
|
35
|
-
export interface CredentialDeps {
|
|
36
|
-
fetch: typeof fetch;
|
|
37
|
-
now: () => number;
|
|
38
|
-
/** Signs the assertion MDA presents to a hosted token-exchange endpoint. */
|
|
39
|
-
signAssertion: (identity: RuntimeIdentity, target: CredentialTarget) => Promise<string>;
|
|
40
|
-
}
|
|
41
|
-
/** Default TTL when a resolver omits `expiresAt` (15 minutes). */
|
|
42
|
-
export declare const DEFAULT_CREDENTIAL_TTL_MS: number;
|
|
43
|
-
/** Soft cap on cached credentials per process. */
|
|
44
|
-
export declare const MAX_CREDENTIAL_CACHE_ENTRIES = 1024;
|
|
45
|
-
/**
|
|
46
|
-
* TTL cache for resolved credentials, keyed by `(user, target)` so
|
|
47
|
-
* per-repo/per-install tokens never collide. Kept out of thread state. Entries
|
|
48
|
-
* expire at the credential's `expiresAt`, or after a default TTL when omitted.
|
|
49
|
-
* The cache is soft-capped to bound memory in long-lived workers.
|
|
50
|
-
*/
|
|
51
|
-
export declare class CredentialCache {
|
|
52
|
-
private readonly defaultTtlMs;
|
|
53
|
-
private readonly maxEntries;
|
|
54
|
-
private readonly entries;
|
|
55
|
-
constructor(defaultTtlMs?: number, maxEntries?: number);
|
|
56
|
-
get(key: string, nowMs: number): ResolvedCredential | undefined;
|
|
57
|
-
set(key: string, value: ResolvedCredential, nowMs?: number): void;
|
|
58
|
-
clear(): void;
|
|
59
|
-
}
|
|
60
|
-
/** Clear the process-level credential cache. Test-only. */
|
|
61
|
-
export declare function clearCredentialCacheForTests(): void;
|
|
62
|
-
/**
|
|
63
|
-
* Build the `runtime.credentials` provider for a run, or `undefined` when the
|
|
64
|
-
* deployment isn't in custom-credentials mode. The provider is bound to the
|
|
65
|
-
* run's resolved identity; every `for(target)` call is scoped to that actor.
|
|
66
|
-
*/
|
|
67
|
-
export declare function createCredentialsProvider(cfg: IdentityConfig, identity: RuntimeIdentity | undefined, deps?: Partial<CredentialDeps>, cache?: CredentialCache): CredentialsProvider | undefined;
|
|
68
|
-
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/runtime/credentials.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAGV,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D,wBAAgB,4BAA4B,IAAI,IAAI,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,cAAc,EACnB,QAAQ,EAAE,eAAe,GAAG,SAAS,EACrC,IAAI,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,EAC9B,KAAK,GAAE,eAA8B,GACpC,mBAAmB,GAAG,SAAS,CA8BjC"}
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { SignJWT } from "jose";
|
|
2
|
-
import { credentialTargetNames, isSingleCredentialResolver, } from "../identity/index.js";
|
|
3
|
-
import { fetchWithTimeout, PROVIDER_HTTP_TIMEOUT_MS } from "./http.js";
|
|
4
|
-
/**
|
|
5
|
-
* Component 5 — Credentials, custom mode.
|
|
6
|
-
*
|
|
7
|
-
* The escape hatch Agent Auth can't cover: bespoke per-caller credential minting
|
|
8
|
-
* via an in-process resolver callback or a hosted token-exchange endpoint. It
|
|
9
|
-
* runs in the worker (not the shared ingress auth handler), applies the output
|
|
10
|
-
* to downstream calls, and caches per `(user, target)` until the credential's
|
|
11
|
-
* `expiresAt`. Secrets live only in this in-memory cache keyed by identity —
|
|
12
|
-
* never in thread state or traces.
|
|
13
|
-
*
|
|
14
|
-
* Managed credential modes (`"user"` / `"agent"`) select downstream credential
|
|
15
|
-
* ownership on the identity axis; only `custom` builds a
|
|
16
|
-
* {@link CredentialsProvider} here.
|
|
17
|
-
*/
|
|
18
|
-
/** Env var holding the HMAC secret MDA signs the endpoint assertion with. */
|
|
19
|
-
export const CREDENTIAL_SIGNING_SECRET_ENV = "MDA_TOKEN_EXCHANGE_SECRET";
|
|
20
|
-
/** How long a signed endpoint assertion is valid, in seconds. */
|
|
21
|
-
const ASSERTION_TTL_SECONDS = 60;
|
|
22
|
-
/** Default TTL when a resolver omits `expiresAt` (15 minutes). */
|
|
23
|
-
export const DEFAULT_CREDENTIAL_TTL_MS = 15 * 60 * 1000;
|
|
24
|
-
/** Soft cap on cached credentials per process. */
|
|
25
|
-
export const MAX_CREDENTIAL_CACHE_ENTRIES = 1024;
|
|
26
|
-
/**
|
|
27
|
-
* TTL cache for resolved credentials, keyed by `(user, target)` so
|
|
28
|
-
* per-repo/per-install tokens never collide. Kept out of thread state. Entries
|
|
29
|
-
* expire at the credential's `expiresAt`, or after a default TTL when omitted.
|
|
30
|
-
* The cache is soft-capped to bound memory in long-lived workers.
|
|
31
|
-
*/
|
|
32
|
-
export class CredentialCache {
|
|
33
|
-
defaultTtlMs;
|
|
34
|
-
maxEntries;
|
|
35
|
-
entries = new Map();
|
|
36
|
-
constructor(defaultTtlMs = DEFAULT_CREDENTIAL_TTL_MS, maxEntries = MAX_CREDENTIAL_CACHE_ENTRIES) {
|
|
37
|
-
this.defaultTtlMs = defaultTtlMs;
|
|
38
|
-
this.maxEntries = maxEntries;
|
|
39
|
-
}
|
|
40
|
-
get(key, nowMs) {
|
|
41
|
-
const hit = this.entries.get(key);
|
|
42
|
-
if (!hit) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
if (nowMs >= hit.expiresAtMs) {
|
|
46
|
-
this.entries.delete(key);
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
return hit.value;
|
|
50
|
-
}
|
|
51
|
-
set(key, value, nowMs = Date.now()) {
|
|
52
|
-
let expiresAtMs;
|
|
53
|
-
if (value.expiresAt) {
|
|
54
|
-
const parsed = Date.parse(value.expiresAt);
|
|
55
|
-
expiresAtMs = Number.isNaN(parsed) ? nowMs + this.defaultTtlMs : parsed;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
expiresAtMs = nowMs + this.defaultTtlMs;
|
|
59
|
-
}
|
|
60
|
-
if (!this.entries.has(key)) {
|
|
61
|
-
while (this.entries.size >= this.maxEntries) {
|
|
62
|
-
const oldest = this.entries.keys().next().value;
|
|
63
|
-
if (oldest === undefined) {
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
this.entries.delete(oldest);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
this.entries.set(key, { value, expiresAtMs });
|
|
70
|
-
}
|
|
71
|
-
clear() {
|
|
72
|
-
this.entries.clear();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/** Process-level cache shared across runs for the lifetime of the deployment. */
|
|
76
|
-
const defaultCache = new CredentialCache();
|
|
77
|
-
/** Clear the process-level credential cache. Test-only. */
|
|
78
|
-
export function clearCredentialCacheForTests() {
|
|
79
|
-
defaultCache.clear();
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Build the `runtime.credentials` provider for a run, or `undefined` when the
|
|
83
|
-
* deployment isn't in custom-credentials mode. The provider is bound to the
|
|
84
|
-
* run's resolved identity; every `for(target)` call is scoped to that actor.
|
|
85
|
-
*/
|
|
86
|
-
export function createCredentialsProvider(cfg, identity, deps, cache = defaultCache) {
|
|
87
|
-
if (cfg.scope.credentials !== "custom" || !cfg.credentials) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
const resolved = {
|
|
91
|
-
fetch: deps?.fetch ?? fetch,
|
|
92
|
-
now: deps?.now ?? (() => Date.now()),
|
|
93
|
-
signAssertion: deps?.signAssertion ?? defaultSignAssertion,
|
|
94
|
-
};
|
|
95
|
-
return {
|
|
96
|
-
async for(target, options) {
|
|
97
|
-
if (!identity) {
|
|
98
|
-
throw new Error("runtime.credentials.for(...) requires a resolved identity, but none " +
|
|
99
|
-
"was available for this run.");
|
|
100
|
-
}
|
|
101
|
-
const key = cacheKey(identity, target);
|
|
102
|
-
if (!options?.forceRefresh) {
|
|
103
|
-
const hit = cache.get(key, resolved.now());
|
|
104
|
-
if (hit) {
|
|
105
|
-
return hit;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
// Fail-closed: a resolver/endpoint error propagates and nothing is cached.
|
|
109
|
-
const out = await resolveCredential(cfg, identity, target, resolved);
|
|
110
|
-
cache.set(key, out);
|
|
111
|
-
return out;
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
async function resolveCredential(cfg, identity, target, deps) {
|
|
116
|
-
const creds = cfg.credentials;
|
|
117
|
-
if (!creds) {
|
|
118
|
-
throw new Error("No credentials resolver is configured for this deployment.");
|
|
119
|
-
}
|
|
120
|
-
return resolveOne(selectResolver(creds, target), identity, target, deps, creds);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Pick the resolver for this target: the single one, or the map entry whose key
|
|
124
|
-
* matches `target.name`.
|
|
125
|
-
*/
|
|
126
|
-
function selectResolver(creds, target) {
|
|
127
|
-
if (isSingleCredentialResolver(creds)) {
|
|
128
|
-
return creds;
|
|
129
|
-
}
|
|
130
|
-
const entry = Object.hasOwn(creds, target.name)
|
|
131
|
-
? creds[target.name]
|
|
132
|
-
: undefined;
|
|
133
|
-
if (!entry) {
|
|
134
|
-
const configured = credentialTargetNames(creds).join(", ");
|
|
135
|
-
throw new Error(`runtime.credentials.for(...) has no resolver for target "${target.name}". ` +
|
|
136
|
-
`Configured targets: ${configured}.`);
|
|
137
|
-
}
|
|
138
|
-
return entry;
|
|
139
|
-
}
|
|
140
|
-
async function resolveOne(config, identity, target, deps, creds) {
|
|
141
|
-
const label = isSingleCredentialResolver(creds)
|
|
142
|
-
? "resolver"
|
|
143
|
-
: `resolver for "${target.name}"`;
|
|
144
|
-
if ("resolve" in config) {
|
|
145
|
-
return normalizeResolved(await config.resolve({ identity, target }), label);
|
|
146
|
-
}
|
|
147
|
-
const assertion = await deps.signAssertion(identity, target);
|
|
148
|
-
return callTokenExchange(config.endpoint.url, assertion, deps);
|
|
149
|
-
}
|
|
150
|
-
async function callTokenExchange(url, assertion, deps) {
|
|
151
|
-
const response = await fetchWithTimeout(url, {
|
|
152
|
-
method: "POST",
|
|
153
|
-
headers: {
|
|
154
|
-
"content-type": "application/json",
|
|
155
|
-
authorization: `Bearer ${assertion}`,
|
|
156
|
-
},
|
|
157
|
-
body: JSON.stringify({ assertion }),
|
|
158
|
-
}, PROVIDER_HTTP_TIMEOUT_MS, deps.fetch);
|
|
159
|
-
if (!response.ok) {
|
|
160
|
-
throw new Error(`Credential token-exchange endpoint ${url} responded ${response.status}.`);
|
|
161
|
-
}
|
|
162
|
-
return normalizeResolved(await response.json(), `endpoint ${url}`);
|
|
163
|
-
}
|
|
164
|
-
async function defaultSignAssertion(identity, target) {
|
|
165
|
-
const secret = process.env[CREDENTIAL_SIGNING_SECRET_ENV];
|
|
166
|
-
if (!secret) {
|
|
167
|
-
throw new Error(`A hosted credential endpoint requires a signing secret. Set ` +
|
|
168
|
-
`${CREDENTIAL_SIGNING_SECRET_ENV} in the deployment environment.`);
|
|
169
|
-
}
|
|
170
|
-
const issuedAt = Math.floor(Date.now() / 1000);
|
|
171
|
-
return new SignJWT({
|
|
172
|
-
user_id: identity.user.id,
|
|
173
|
-
user_kind: identity.user.kind,
|
|
174
|
-
target: { kind: target.kind, name: target.name, intent: target.intent },
|
|
175
|
-
})
|
|
176
|
-
.setProtectedHeader({ alg: "HS256" })
|
|
177
|
-
.setSubject(identity.user.id)
|
|
178
|
-
.setIssuedAt(issuedAt)
|
|
179
|
-
.setExpirationTime(issuedAt + ASSERTION_TTL_SECONDS)
|
|
180
|
-
.sign(new TextEncoder().encode(secret));
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* The cache key that discriminates a minted credential: the user it belongs to,
|
|
184
|
-
* plus the target's kind/name/intent/thread and metadata.
|
|
185
|
-
*/
|
|
186
|
-
function cacheKey(identity, target) {
|
|
187
|
-
return stableStringify([
|
|
188
|
-
identity.user.id,
|
|
189
|
-
target.kind,
|
|
190
|
-
target.name,
|
|
191
|
-
target.intent ?? null,
|
|
192
|
-
target.threadId ?? null,
|
|
193
|
-
target.metadata ?? null,
|
|
194
|
-
]);
|
|
195
|
-
}
|
|
196
|
-
/** Deterministic JSON with object keys sorted, so the cache key is stable. */
|
|
197
|
-
function stableStringify(value) {
|
|
198
|
-
if (value === null || typeof value !== "object") {
|
|
199
|
-
return JSON.stringify(value) ?? "null";
|
|
200
|
-
}
|
|
201
|
-
if (Array.isArray(value)) {
|
|
202
|
-
return `[${value.map(stableStringify).join(",")}]`;
|
|
203
|
-
}
|
|
204
|
-
const obj = value;
|
|
205
|
-
return `{${Object.keys(obj)
|
|
206
|
-
.sort()
|
|
207
|
-
.map((key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`)
|
|
208
|
-
.join(",")}}`;
|
|
209
|
-
}
|
|
210
|
-
/** Validate a resolver/endpoint result into a {@link ResolvedCredential}. */
|
|
211
|
-
function normalizeResolved(value, sourceLabel) {
|
|
212
|
-
if (!value || typeof value !== "object") {
|
|
213
|
-
throw new Error(`Credential ${sourceLabel} returned a non-object result.`);
|
|
214
|
-
}
|
|
215
|
-
const { headers, expiresAt } = value;
|
|
216
|
-
if (!headers || typeof headers !== "object" || Array.isArray(headers)) {
|
|
217
|
-
throw new Error(`Credential ${sourceLabel} result is missing a headers object.`);
|
|
218
|
-
}
|
|
219
|
-
const normalizedHeaders = {};
|
|
220
|
-
for (const [name, headerValue] of Object.entries(headers)) {
|
|
221
|
-
if (typeof headerValue !== "string") {
|
|
222
|
-
throw new Error(`Credential ${sourceLabel} header "${name}" must be a string.`);
|
|
223
|
-
}
|
|
224
|
-
normalizedHeaders[name] = headerValue;
|
|
225
|
-
}
|
|
226
|
-
const result = { headers: normalizedHeaders };
|
|
227
|
-
if (expiresAt !== undefined) {
|
|
228
|
-
if (typeof expiresAt !== "string") {
|
|
229
|
-
throw new Error(`Credential ${sourceLabel} \`expiresAt\` must be an ISO string.`);
|
|
230
|
-
}
|
|
231
|
-
result.expiresAt = expiresAt;
|
|
232
|
-
}
|
|
233
|
-
return result;
|
|
234
|
-
}
|
|
235
|
-
//# sourceMappingURL=credentials.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/runtime/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,E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