eve-hub 0.16.8 → 0.16.10
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/hub-oidc.d.mts +1 -0
- package/hub-oidc.mjs +20 -9
- package/package.json +1 -1
package/hub-oidc.d.mts
CHANGED
|
@@ -2,4 +2,5 @@ export type TeamClaims = { iss: string; owner_id: string; project_id?: string; e
|
|
|
2
2
|
export function looksLikeJwt(token: string | null | undefined): boolean;
|
|
3
3
|
export function verifyIssuerToken(token: string, options: { iss: string; jwksUrl?: string; audience?: string; fetchImpl?: typeof fetch; now?: number }): Promise<Record<string, unknown> | undefined>;
|
|
4
4
|
export function verifyTeamToken(token: string, own: string, options?: { fetchImpl?: typeof fetch; now?: number; audience?: string }): Promise<TeamClaims | undefined>;
|
|
5
|
+
export function projectOf(token: string): string | undefined;
|
|
5
6
|
export function isHubRequest(request: Request, own: () => Promise<string>, options?: { env?: Record<string, string | undefined>; fetchImpl?: typeof fetch; now?: number }): Promise<boolean>;
|
package/hub-oidc.mjs
CHANGED
|
@@ -48,22 +48,33 @@ export async function verifyTeamToken(token, own, { fetchImpl = fetch, now = Dat
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** The project a Vercel OIDC token was issued to (`project_id`), unverified: for reading one's own token. */
|
|
52
|
+
export const projectOf = (token) => { const id = decodeJwt(token).project_id; return typeof id === "string" ? id : undefined; };
|
|
53
|
+
|
|
51
54
|
/**
|
|
52
55
|
* Whether `request` comes from the hub. A call carrying `x-hub-oidc-token` is decided by that token alone: it is of this team's,
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
+
* and either this deployment's own project's (the workspace's hub service deploys in the project with its bots, so its token
|
|
57
|
+
* is the project's own, in the same environment) or the central hub project's production deployment (HUB_PROJECT_ID; a
|
|
58
|
+
* preview of it is any branch push). Either way it is issued for this deployment's own project as audience. Both serve until the central hub
|
|
59
|
+
* stops serving the workspace plane. A call without one (a hub that does not send it yet) is the workspace's BOT_TOKEN.
|
|
60
|
+
* `own` is this deployment's own token.
|
|
56
61
|
*/
|
|
57
62
|
export async function isHubRequest(request, own, { env = process.env, ...options } = {}) {
|
|
58
63
|
const token = request.headers.get("x-hub-oidc-token");
|
|
59
64
|
if (!token) return isBotToken(request.headers.get("authorization"), env.BOT_TOKEN);
|
|
60
|
-
|
|
61
|
-
let claims;
|
|
65
|
+
let mine, claims;
|
|
62
66
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
claims = await verifyTeamToken(token, mine, { ...options, audience });
|
|
67
|
+
mine = await own();
|
|
68
|
+
claims = await verifyTeamToken(token, mine, options);
|
|
66
69
|
}
|
|
67
70
|
catch (error) { console.error(`[eve-hub] could not check the hub's token: ${error?.message}`); return false; }
|
|
68
|
-
|
|
71
|
+
if (claims === undefined) return false;
|
|
72
|
+
const { project_id: project, environment } = decodeJwt(mine);
|
|
73
|
+
if (typeof project !== "string") return false;
|
|
74
|
+
const sameProject = claims.project_id === project && claims.environment === environment;
|
|
75
|
+
const central = env.HUB_PROJECT_ID && claims.project_id === env.HUB_PROJECT_ID && claims.environment === "production";
|
|
76
|
+
if (!sameProject && !central) return false;
|
|
77
|
+
// Either hub's token names this project as its audience; the default audience (what AI Gateway and Connect take) is not it.
|
|
78
|
+
const aud = claims.aud;
|
|
79
|
+
return aud === project || (Array.isArray(aud) && aud.includes(project));
|
|
69
80
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eve-hub",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.10",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Bot-side code shared by every hub agent: registry tools, the roster hook, the eve channel, the host sandbox and browser, and model helpers.",
|
|
6
6
|
"type": "module",
|