eve-hub 0.8.2 → 0.9.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/CHANGELOG.md +12 -0
- package/hub-oidc.d.mts +1 -1
- package/hub-oidc.mjs +13 -7
- package/package.json +1 -1
- package/world.mjs +1307 -39831
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# eve-hub
|
|
2
2
|
|
|
3
|
+
## 0.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Hosted bots take a call as the hub's only if its `x-hub-oidc-token` is the hub project's production token, issued for this bots project as audience (a preview of the hub is any branch push). A call with no such header is judged by BOT_TOKEN as before.
|
|
8
|
+
|
|
9
|
+
## 0.9.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- The bots no longer write the hub's tables. A bot's append goes to its own session stream, and the hub folds that stream into turns and replies after a wake (`/api/fold`). Needs a hub that serves `/api/fold`.
|
|
14
|
+
|
|
3
15
|
## 0.8.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/hub-oidc.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type TeamClaims = { iss: string; owner_id: string; project_id?: string; environment?: string; user_id?: string; exp: number; [claim: string]: unknown };
|
|
2
2
|
export function looksLikeJwt(token: string | null | undefined): boolean;
|
|
3
|
-
export function verifyTeamToken(token: string, own: string, options?: { fetchImpl?: typeof fetch; now?: number }): Promise<TeamClaims | undefined>;
|
|
3
|
+
export function verifyTeamToken(token: string, own: string, options?: { fetchImpl?: typeof fetch; now?: number; audience?: string }): Promise<TeamClaims | undefined>;
|
|
4
4
|
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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Who a Vercel OIDC token says its caller is, for the hub and its bots to check each other with:
|
|
2
|
-
// a bot calls the hub with its bots project's token, the hub calls a bot with its own
|
|
2
|
+
// a bot calls the hub with its bots project's token, the hub calls a bot with its own, issued for that bots project
|
|
3
|
+
// as audience (`x-hub-oidc-token`): a copy of it is of no use against any other workspace's bot.
|
|
3
4
|
// A token counts when the team's keys signed it (RS256, JWKS at `<iss>/.well-known/jwks.json`), it is within
|
|
4
5
|
// its `nbf`/`exp`, and it comes from the checker's own team: both `iss` and `owner_id` equal those of the checker's
|
|
5
6
|
// own token, so nothing is configured. The caller then checks which project (`project_id`) it may be.
|
|
@@ -22,13 +23,13 @@ export const looksLikeJwt = (token) => /^[\w-]+\.[\w-]+\.[\w-]*$/.test(String(to
|
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* The verified claims of `token`, or undefined for any token that is not the checker's team's.
|
|
25
|
-
* `own` is the checker's own token (its `iss` and `owner_id` say which team to trust).
|
|
26
|
+
* `own` is the checker's own token (its `iss` and `owner_id` say which team to trust). With `audience`, the token's `aud` must be it.
|
|
26
27
|
*/
|
|
27
|
-
export async function verifyTeamToken(token, own, { fetchImpl = fetch, now = Date.now() } = {}) {
|
|
28
|
+
export async function verifyTeamToken(token, own, { fetchImpl = fetch, now = Date.now(), audience } = {}) {
|
|
28
29
|
const { iss, owner_id: owner } = decodeJwt(own);
|
|
29
30
|
if (!iss || !owner) return undefined;
|
|
30
31
|
try {
|
|
31
|
-
const { payload } = await jwtVerify(token, keysOf(iss, fetchImpl), { issuer: iss, algorithms: ["RS256"], requiredClaims: ["exp"], currentDate: new Date(now) });
|
|
32
|
+
const { payload } = await jwtVerify(token, keysOf(iss, fetchImpl), { issuer: iss, algorithms: ["RS256"], requiredClaims: ["exp"], ...(audience === undefined ? {} : { audience }), currentDate: new Date(now) });
|
|
32
33
|
return payload.owner_id === owner ? payload : undefined;
|
|
33
34
|
} catch (error) {
|
|
34
35
|
if (error instanceof errors.JOSEError && !KEY_FETCH_FAILED.has(error.code)) return undefined;
|
|
@@ -38,7 +39,8 @@ export async function verifyTeamToken(token, own, { fetchImpl = fetch, now = Dat
|
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* 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,
|
|
41
|
-
* from the hub project (HUB_PROJECT_ID
|
|
42
|
+
* from the hub project's production deployment (HUB_PROJECT_ID; a preview of it is any branch push), and issued for this
|
|
43
|
+
* deployment's own project as audience. A call without one
|
|
42
44
|
* (a hub that does not send it yet) is the workspace's BOT_TOKEN. `own` is this deployment's own token.
|
|
43
45
|
*/
|
|
44
46
|
export async function isHubRequest(request, own, { env = process.env, ...options } = {}) {
|
|
@@ -46,7 +48,11 @@ export async function isHubRequest(request, own, { env = process.env, ...options
|
|
|
46
48
|
if (!token) return isBotToken(request.headers.get("authorization"), env.BOT_TOKEN);
|
|
47
49
|
if (!env.HUB_PROJECT_ID) return false;
|
|
48
50
|
let claims;
|
|
49
|
-
try {
|
|
51
|
+
try {
|
|
52
|
+
const mine = await own(), audience = decodeJwt(mine).project_id;
|
|
53
|
+
if (typeof audience !== "string") return false;
|
|
54
|
+
claims = await verifyTeamToken(token, mine, { ...options, audience });
|
|
55
|
+
}
|
|
50
56
|
catch (error) { console.error(`[eve-hub] could not check the hub's token: ${error?.message}`); return false; }
|
|
51
|
-
return claims !== undefined && claims.project_id === env.HUB_PROJECT_ID &&
|
|
57
|
+
return claims !== undefined && claims.project_id === env.HUB_PROJECT_ID && claims.environment === "production";
|
|
52
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eve-hub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
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",
|