Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(eve): support Deployment Protection in vercelOidc (#2574)

Ben Pankow3274eee11c49
diff --git a/.changeset/fresh-vercel-agent-oidc.md b/.changeset/fresh-vercel-agent-oidc.md
new file mode 100644
index 000000000..32be4eab5
--- /dev/null
+++ b/.changeset/fresh-vercel-agent-oidc.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Send remote-agent Vercel OIDC credentials in both the bearer and trusted-OIDC headers so `vercelOidc()` can reach eve agents behind Vercel Deployment Protection.
diff --git a/docs/guides/remote-agents.md b/docs/guides/remote-agents.md
index a4ab1436d..11f3f8bfe 100644
--- a/docs/guides/remote-agents.md
+++ b/docs/guides/remote-agents.md
@@ -86,15 +86,32 @@ To require structured output, set an `outputSchema` on the agent definition for
## Outbound auth
-`auth` is an `OutboundAuthFn` from `eve/agents/auth` that attaches request headers to the outbound dispatch:
+Use `vercelOidc()` from `eve/agents/auth` when one Vercel-deployed eve agent calls another, as shown in the first example on this page.
+
+For calls between different Vercel projects, allow the calling project on the receiving agent's eve channel:
+
+```ts title="agent/channels/eve.ts"
+import { vercelOidc, vercelSubject } from "eve/channels/auth";
+import { eveChannel } from "eve/channels/eve";
+
+export default eveChannel({
+ auth: [
+ vercelOidc({
+ subjects: [
+ vercelSubject({
+ teamSlug: "acme",
+ projectName: "calling-agent",
+ environment: "production",
+ }),
+ ],
+ }),
+ ],
+});
+```
-| Helper | Header |
-| ------------------------------- | ---------------------------------------------------------------------------- |
-| `vercelOidc(opts?)` | `Authorization: Bearer <Vercel OIDC token>` (deployment-to-deployment trust) |
-| `bearer(token)` | `Authorization: Bearer <token>` (static or lazily resolved) |
-| `basic({ username, password })` | `Authorization: Basic …` |
+Set `teamSlug`, `projectName`, and `environment` to the calling deployment's Vercel OIDC subject. See [subject patterns and `vercelSubject(...)`](./auth-and-route-protection#subjects-patterns-and-vercelsubject) for other environments and wildcard matching.
-If you are calling another Vercel-deployed eve agent, reach for `vercelOidc()`. The remote verifies the OIDC token to authorize the caller. See [Auth & route protection](./auth-and-route-protection) for the receiving side.
+If [Vercel Deployment Protection](https://vercel.com/docs/deployment-protection) is active on the receiving project, also configure [Trusted Sources](https://vercel.com/docs/deployment-protection/methods-to-bypass-deployment-protection/trusted-sources) to allow the calling project and environment. The eve subject allowlist and Trusted Sources are separate checks; cross-project calls need both.
## Forwarding the caller identity
diff --git a/packages/eve/src/public/agents/auth.test.ts b/packages/eve/src/public/agents/auth.test.ts
new file mode 100644
index 000000000..20e744469
--- /dev/null
+++ b/packages/eve/src/public/agents/auth.test.ts
@@ -0,0 +1,41 @@
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("#compiled/@vercel/oidc/index.js", () => ({
+ getVercelOidcToken: vi.fn(),
+}));
+
+import { getVercelOidcToken } from "#compiled/@vercel/oidc/index.js";
+import { VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER } from "#client/types.js";
+import { vercelOidc } from "#public/agents/auth.js";
+
+describe("vercelOidc", () => {
+ afterEach(() => vi.resetAllMocks());
+
+ it("authenticates the eve route and Vercel Deployment Protection", async () => {
+ vi.mocked(getVercelOidcToken).mockResolvedValue("oidc-token");
+
+ const auth = vercelOidc({ project: "weather", team: "acme" });
+
+ await expect(auth()).resolves.toEqual({
+ headers: {
+ authorization: "Bearer oidc-token",
+ [VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER]: "oidc-token",
+ },
+ });
+ expect(getVercelOidcToken).toHaveBeenCalledWith({ project: "weather", team: "acme" });
+ });
+
+ it("resolves a fresh token for each request", async () => {
+ vi.mocked(getVercelOidcToken)
+ .mockResolvedValueOnce("first-token")
+ .mockResolvedValueOnce("second-token");
+ const auth = vercelOidc();
+
+ await expect(auth()).resolves.toMatchObject({
+ headers: { authorization: "Bearer first-token" },
+ });
+ await expect(auth()).resolves.toMatchObject({
+ headers: { authorization: "Bearer second-token" },
+ });
+ });
+});
diff --git a/packages/eve/src/public/agents/auth.ts b/packages/eve/src/public/agents/auth.ts
index d18bc0a19..36b073108 100644
--- a/packages/eve/src/public/agents/auth.ts
+++ b/packages/eve/src/public/agents/auth.ts
@@ -1,6 +1,6 @@
import { getVercelOidcToken } from "#compiled/@vercel/oidc/index.js";
-import type { TokenValue } from "#client/types.js";
+import { type TokenValue, VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER } from "#client/types.js";
/**
* Outbound request auth hook for remote agent dispatch. Runs once per
@@ -26,18 +26,26 @@ export interface VercelOidcOptions {
}
/**
- * Returns an {@link OutboundAuthFn} that emits a `Bearer` Vercel OIDC token for
- * outbound remote-agent requests. Reads the token from the request context or
- * the `VERCEL_OIDC_TOKEN` environment variable (refreshed in development when
- * expired). Pass {@link VercelOidcOptions} to scope the refresh to a team or
- * project; defaults to `{}`.
+ * Returns an {@link OutboundAuthFn} that emits a Vercel OIDC token in both the
+ * bearer and trusted-identity-provider headers for outbound remote-agent
+ * requests. The bearer authenticates the eve route, while the trusted header
+ * passes Vercel Deployment Protection.
+ *
+ * Reads the token from the request context or the `VERCEL_OIDC_TOKEN`
+ * environment variable (refreshed in development when expired). Pass
+ * {@link VercelOidcOptions} to scope the refresh to a team or project; defaults
+ * to `{}`.
*/
export function vercelOidc(options: VercelOidcOptions = {}): OutboundAuthFn {
- return async () => ({
- headers: {
- authorization: `Bearer ${await getVercelOidcToken(options)}`,
- },
- });
+ return async () => {
+ const token = await getVercelOidcToken(options);
+ return {
+ headers: {
+ authorization: `Bearer ${token}`,
+ [VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER]: token,
+ },
+ };
+ };
}
/**
diff --git a/packages/eve/src/public/channels/telegram/telegramChannel.ts b/packages/eve/src/public/channels/telegram/telegramChannel.ts
index 42c1f82fa..dafffc838 100644
--- a/packages/eve/src/public/channels/telegram/telegramChannel.ts
+++ b/packages/eve/src/public/channels/telegram/telegramChannel.ts
@@ -311,7 +311,7 @@ export function telegramChannel(config: TelegramChannelConfig = {}): TelegramCha
typeof receiveTarget.messageThreadId === "number"
? receiveTarget.messageThreadId
: undefined;
- const requestedConversationId = readOptionalString(receiveTarget.conversationId);
+ const requestedConversationId = readChatId(receiveTarget.conversationId);
const initialMessage = receiveTarget.initialMessage;
if (initialMessage !== undefined && requestedConversationId !== undefined) {
throw new Error(
@@ -697,9 +697,3 @@ function readChatId(value: unknown): string | undefined {
if (typeof value === "number" && Number.isFinite(value)) return String(value);
return undefined;
}
-
-function readOptionalString(value: unknown): string | undefined {
- if (typeof value === "string" && value.length > 0) return value;
- if (typeof value === "number" && Number.isFinite(value)) return String(value);
- return undefined;
-}