Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(claude): scope Bedrock AWS credential stripping to Bedrock engines only

Thi9ed4f499f231
diff --git a/server/claude-bedrock.ts b/server/claude-bedrock.ts
index fdc97544bf..dc56da628f 100644
--- a/server/claude-bedrock.ts
+++ b/server/claude-bedrock.ts
@@ -1,6 +1,4 @@
-// Claude Code on Amazon Bedrock: the person names an AWS profile and region from this computer's own
-// ~/.aws config, and the instance runs with CLAUDE_CODE_USE_BEDROCK=1. The AWS SDK inside Claude Code
-// resolves that profile's SSO or credential_process itself; OpenMausBot stores no AWS secret.
+// The AWS SDK inside Claude Code resolves a profile's SSO or credential_process itself; OpenMausBot stores no AWS secret.
import { randomUUID } from "node:crypto";
import { join } from "node:path";
import { z } from "zod";
@@ -42,7 +40,6 @@ export const claudeBedrockUpdateSchema = z.object({
}).strict().refine((value) => Object.keys(value).length > 0, "No settings supplied");
type BedrockFields = z.infer<typeof claudeBedrockUpdateSchema>;
-/** Environment/model generation always runs once the profile and region are resolved. */
type ResolvedBedrockFields = BedrockFields & { awsProfile: string; awsRegion: string };
const TIERS = [
@@ -112,7 +109,6 @@ function defaultBedrockModels(): string[] {
return officialModels(false).map((id) => `global.anthropic.${id}`);
}
-/** The installed binary, not another account's environment: Bedrock routes through AWS, never a Claude login. */
function inheritedCli(instances: InstanceConfigMap): string | undefined {
for (const entry of Object.values(instances)) {
if (entry.driver !== "claudeAgent" || isClaudeBedrock(entry)) continue;
@@ -129,7 +125,6 @@ export function newClaudeBedrock(cfg: AppConfig, body: z.infer<typeof claudeBedr
const entry: InstanceConfig = {
driver: "claudeAgent",
displayName: body.displayName,
- // Its own credential: an AWS profile, never another Claude instance's sign-in state.
access: "custom",
config: {
...(cli ? { cli } : {}),
@@ -144,7 +139,6 @@ export function newClaudeBedrock(cfg: AppConfig, body: z.infer<typeof claudeBedr
return { instanceId, instances };
}
-/** Changes the Bedrock engine in place; an omitted field keeps its saved value. */
export function updateClaudeBedrock(cfg: AppConfig, instanceId: string, body: BedrockFields) {
const instances = persistableInstanceConfigs(cfg);
const entry = instances[instanceId];
diff --git a/server/claude-endpoints.test.ts b/server/claude-endpoints.test.ts
index 76c767926c..8e48b3d2f3 100644
--- a/server/claude-endpoints.test.ts
+++ b/server/claude-endpoints.test.ts
@@ -78,6 +78,21 @@ describe("custom Claude endpoint", () => {
expect((instances[instanceId].config as { cli?: string }).cli).toBe("/opt/claude/bin/claude");
});
+ it("never inherits a Bedrock engine's binary; falls back to whichever other account sets one", () => {
+ const bedrockOnly = newClaudeEndpoint({
+ instances: { bedrock: { driver: "claudeAgent", config: { cli: "/opt/bedrock/bin/claude", bedrock: true } } },
+ } as never, BASE);
+ expect((bedrockOnly.instances[bedrockOnly.instanceId].config as { cli?: string }).cli).toBeUndefined();
+
+ const withFallback = newClaudeEndpoint({
+ instances: {
+ bedrock: { driver: "claudeAgent", config: { cli: "/opt/bedrock/bin/claude", bedrock: true } },
+ "claude-work": { driver: "claudeAgent", config: { cli: "/opt/claude/bin/claude" } },
+ },
+ } as never, BASE);
+ expect((withFallback.instances[withFallback.instanceId].config as { cli?: string }).cli).toBe("/opt/claude/bin/claude");
+ });
+
it("reports only the address and models to a client, never the token", () => {
const { instanceId, instances } = newClaudeEndpoint(cfg(), BASE);
const info = claudeEndpointInfo(instances[instanceId]);
diff --git a/server/claude-endpoints.ts b/server/claude-endpoints.ts
index 80040ac739..e74d35eeba 100644
--- a/server/claude-endpoints.ts
+++ b/server/claude-endpoints.ts
@@ -115,7 +115,7 @@ function endpointModels(fields: EndpointFields): string[] {
/** The installed binary, not another account's environment: an endpoint has no login of its own. */
function inheritedCli(instances: InstanceConfigMap): string | undefined {
for (const entry of Object.values(instances)) {
- if (entry.driver !== "claudeAgent" || isClaudeEndpoint(entry)) continue;
+ if (entry.driver !== "claudeAgent" || isClaudeEndpoint(entry) || rawConfig(entry).bedrock === true) continue;
const cli = rawConfig(entry).cli;
if (typeof cli === "string" && cli) return cli;
}
diff --git a/server/drivers/claude-accounts.test.ts b/server/drivers/claude-accounts.test.ts
index fe1842eca1..1f7eaeb154 100644
--- a/server/drivers/claude-accounts.test.ts
+++ b/server/drivers/claude-accounts.test.ts
@@ -7,6 +7,7 @@ import type { ProviderInstance } from "../contracts.ts";
import { removeTempDir } from "../testing/cleanup.ts";
import { recordEvents } from "../testing/events.ts";
import { CLAUDE_ACCOUNT_ENV_KEYS, ClaudeDriver, resolveClaudeConfigDir } from "./claude.ts";
+import { AWS_CREDENTIAL_ENV_KEYS } from "./claude-bedrock-aws.ts";
// Reads synthetic account labels and records its spawn contract; never the real CLI, Keychain or network.
const FAKE_CLI = `#!/usr/bin/env node
@@ -16,7 +17,7 @@ import { createInterface } from "node:readline";
const args = process.argv.slice(2);
const configDir = process.env.CLAUDE_CONFIG_DIR || join(process.env.HOME, ".claude");
const auth = JSON.parse(readFileSync(join(configDir, "fixture-auth.json"), "utf8"));
-const keys = ${JSON.stringify(CLAUDE_ACCOUNT_ENV_KEYS)};
+const keys = ${JSON.stringify([...CLAUDE_ACCOUNT_ENV_KEYS, ...AWS_CREDENTIAL_ENV_KEYS, "AWS_PROFILE", "AWS_REGION"])};
appendFileSync(join(configDir, "calls.ndjson"), JSON.stringify({
args, configDir, home: process.env.HOME,
env: Object.fromEntries(keys.map(key => [key, process.env[key]]))
@@ -164,6 +165,36 @@ describe("Claude account configuration", () => {
});
});
+ it("keeps a named account's inherited AWS credentials, since only Bedrock engines are AWS-scoped", async () => {
+ const dir = account("named-with-bedrock-env");
+ vi.stubEnv("AWS_ACCESS_KEY_ID", "fixture-parent-AWS_ACCESS_KEY_ID");
+ vi.stubEnv("AWS_SECRET_ACCESS_KEY", "fixture-parent-AWS_SECRET_ACCESS_KEY");
+ const provider = await create(dir, { CLAUDE_CODE_USE_BEDROCK: "1" });
+ await provider.generateText?.("fixture review");
+ expect(calls(dir)[0]?.env).toMatchObject({
+ AWS_ACCESS_KEY_ID: "fixture-parent-AWS_ACCESS_KEY_ID",
+ AWS_SECRET_ACCESS_KEY: "fixture-parent-AWS_SECRET_ACCESS_KEY",
+ });
+ });
+
+ it("strips the parent shell's AWS credentials for a Bedrock engine, keeping its own profile", async () => {
+ const dir = account("bedrock-engine");
+ vi.stubEnv("AWS_ACCESS_KEY_ID", "fixture-parent-AWS_ACCESS_KEY_ID");
+ vi.stubEnv("AWS_SECRET_ACCESS_KEY", "fixture-parent-AWS_SECRET_ACCESS_KEY");
+ vi.stubEnv("AWS_SESSION_TOKEN", "fixture-parent-AWS_SESSION_TOKEN");
+ const provider = await create(
+ dir,
+ { CLAUDE_CODE_USE_BEDROCK: "1", AWS_PROFILE: "fixture-bedrock-profile", AWS_REGION: "us-east-1" },
+ { bedrock: true },
+ );
+ await provider.generateText?.("fixture review");
+ expect(calls(dir)[0]?.env).toEqual({
+ CLAUDE_CODE_USE_BEDROCK: "1",
+ AWS_PROFILE: "fixture-bedrock-profile",
+ AWS_REGION: "us-east-1",
+ });
+ });
+
it("publishes only bounded display identity from a successful auth status", async () => {
const dir = account("identity", {
loggedIn: true, email: " [email protected] ", orgName: " Team ",
diff --git a/server/drivers/claude-bedrock-aws.test.ts b/server/drivers/claude-bedrock-aws.test.ts
index c384a04836..0abea17dc1 100644
--- a/server/drivers/claude-bedrock-aws.test.ts
+++ b/server/drivers/claude-bedrock-aws.test.ts
@@ -13,7 +13,7 @@ describe("bedrockCredentialError", () => {
"API Error: Could not load AWS credentials · Could not load credentials from any providers. Check or refresh your AWS credentials and try again.",
]) {
expect(bedrockCredentialError(text, "bedrock-prod")).toBe(
- "AWS sign-in for profile bedrock-prod expired. Run `aws sso login --profile bedrock-prod` and try again."
+ "AWS credentials for profile bedrock-prod are missing or expired. If it uses SSO, run `aws sso login --profile bedrock-prod`; otherwise check ~/.aws, then try again."
);
}
});
@@ -35,7 +35,7 @@ describe("withBedrockCredentialError", () => {
it("replaces a credential failure on a Bedrock instance with the sign-in step", () => {
expect(withBedrockCredentialError(true, env, expired, { message: expired, text: { key: "x" } })).toEqual({
- message: "AWS sign-in for profile bedrock-prod expired. Run `aws sso login --profile bedrock-prod` and try again.",
+ message: "AWS credentials for profile bedrock-prod are missing or expired. If it uses SSO, run `aws sso login --profile bedrock-prod`; otherwise check ~/.aws, then try again.",
});
expect(bedrockResultError(true, env, expired)).toContain("aws sso login --profile bedrock-prod");
});
diff --git a/server/drivers/claude-bedrock-aws.ts b/server/drivers/claude-bedrock-aws.ts
index 79e8ab5400..6d151d5f0a 100644
--- a/server/drivers/claude-bedrock-aws.ts
+++ b/server/drivers/claude-bedrock-aws.ts
@@ -15,7 +15,7 @@ const BEDROCK_CREDENTIAL_ERROR =
/** A plain next step for an AWS profile that can no longer authenticate; null when the text is some other failure. */
export function bedrockCredentialError(text: string, awsProfile: string): string | null {
if (!BEDROCK_CREDENTIAL_ERROR.test(text)) return null;
- return `AWS sign-in for profile ${awsProfile} expired. Run \`aws sso login --profile ${awsProfile}\` and try again.`;
+ return `AWS credentials for profile ${awsProfile} are missing or expired. If it uses SSO, run \`aws sso login --profile ${awsProfile}\`; otherwise check ~/.aws, then try again.`;
}
/** The turn error to show: the AWS sign-in step when a Bedrock instance's profile failed, else `error` unchanged. */
diff --git a/server/drivers/claude.ts b/server/drivers/claude.ts
index 0b95de1570..4346ca48b6 100644
--- a/server/drivers/claude.ts
+++ b/server/drivers/claude.ts
@@ -84,7 +84,7 @@ export const CLAUDE_ACCOUNT_ENV_KEYS = [
"ANTHROPIC_CUSTOM_HEADERS",
"CLAUDE_CODE_USE_BEDROCK",
"CLAUDE_CODE_USE_VERTEX",
- "CLAUDE_CODE_USE_FOUNDRY", ...AWS_CREDENTIAL_ENV_KEYS,
+ "CLAUDE_CODE_USE_FOUNDRY",
] as const;
export function resolveClaudeConfigDir(configDir?: string, env: NodeJS.ProcessEnv = process.env): string {
@@ -113,13 +113,13 @@ function claudeEnvironment(
source: NodeJS.ProcessEnv = process.env,
configDir?: string,
instanceEnvironment: NodeJS.ProcessEnv = {},
- endpoint = false,
+ endpoint = false, bedrock = false,
): NodeJS.ProcessEnv {
const env: NodeJS.ProcessEnv = { BASH_MAX_TIMEOUT_MS: "600000", ...source, PATH: augmentedPath(), NPM_CONFIG_LOGLEVEL: "error" };
if (configDir?.trim()) env.CLAUDE_CONFIG_DIR = resolveClaudeConfigDir(configDir, env);
else if (env.CLAUDE_CONFIG_DIR) env.CLAUDE_CONFIG_DIR = resolveClaudeConfigDir(undefined, env);
- if (configDir?.trim() || endpoint) {
- for (const key of CLAUDE_ACCOUNT_ENV_KEYS) {
+ if (configDir?.trim() || endpoint || bedrock) {
+ for (const key of bedrock ? [...CLAUDE_ACCOUNT_ENV_KEYS, ...AWS_CREDENTIAL_ENV_KEYS] : CLAUDE_ACCOUNT_ENV_KEYS) {
// Subscription OAuth always comes from this account's own login, never the parent's.
if (key.startsWith("CLAUDE_CODE_OAUTH_") || key.endsWith("_FILE_DESCRIPTOR") || !Object.hasOwn(instanceEnvironment, key)) {
delete env[key];
@@ -272,7 +272,7 @@ export interface ClaudeConfig {
permissionMode: "acceptEdits" | "auto" | "bypassPermissions";
tools?: string[];
disallowedTools?: string[];
- requireApiKey?: boolean; bedrock?: boolean; // bedrock: Amazon Bedrock through an AWS profile, no secret of its own
+ requireApiKey?: boolean; bedrock?: boolean;
}
export { STATIC_CLAUDE_MODELS };
@@ -775,7 +775,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
async create(input: DriverCreateInput<ClaudeConfig>): Promise<ProviderInstance> {
const { instanceId, config } = input;
const environment = (model?: string | null) =>
- claudeEnvironment(config.managed ? undefined : model, { ...process.env, ...input.environment }, config.configDir, input.environment, Boolean(config.endpointModels));
+ claudeEnvironment(config.managed ? undefined : model, { ...process.env, ...input.environment }, config.configDir, input.environment, Boolean(config.endpointModels), config.bedrock === true);
const catalogEnv = environment();
if (inheritsUserConfig(catalogEnv)) {
console.error(`claude (${instanceId}): OMB_CLAUDE_INHERIT_USER_CONFIG=1 — bots inherit this machine's Claude Code MCP servers, skills, hooks and CLAUDE.md on every turn; remove it unless a bot needs a user-scope server`);