fix(adapters): scope agent secrets to run owner in shared Spaces
Agent secrets are owner-managed via the API but the executor loaded every secret in the Space and injected decrypted values into shell environment variables for any member's bot run. Co-authored-by: cynarAI <cynarAI@users.noreply.github.com>
This commit is contained in:
parent
8ae36763a7
commit
be9c310e1e
@ -1,11 +1,19 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import {
|
import {
|
||||||
|
agentSecretScopeForRun,
|
||||||
decryptAgentEnvironment,
|
decryptAgentEnvironment,
|
||||||
formatAgentEnvironmentInstruction,
|
formatAgentEnvironmentInstruction,
|
||||||
redactAgentCommandResult,
|
redactAgentCommandResult,
|
||||||
} from "./agent-environment.js";
|
} from "./agent-environment.js";
|
||||||
|
|
||||||
describe("agent-environment", () => {
|
describe("agent-environment", () => {
|
||||||
|
it("scopes agent secrets to the run owner in shared Spaces", () => {
|
||||||
|
expect(agentSecretScopeForRun("shared-ws", "member-user")).toEqual({
|
||||||
|
spaceId: "shared-ws",
|
||||||
|
createdByUserId: "member-user",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("decrypts named agent secrets", () => {
|
it("decrypts named agent secrets", () => {
|
||||||
const env = decryptAgentEnvironment(
|
const env = decryptAgentEnvironment(
|
||||||
[
|
[
|
||||||
|
|||||||
@ -10,6 +10,10 @@ type SecretLoader = {
|
|||||||
load(ciphertext: string, recordId: string): string;
|
load(ciphertext: string, recordId: string): string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function agentSecretScopeForRun(spaceId: string, userId: string) {
|
||||||
|
return { spaceId, createdByUserId: userId };
|
||||||
|
}
|
||||||
|
|
||||||
export function decryptAgentEnvironment(
|
export function decryptAgentEnvironment(
|
||||||
rows: EncryptedAgentSecret[],
|
rows: EncryptedAgentSecret[],
|
||||||
secrets: SecretLoader,
|
secrets: SecretLoader,
|
||||||
|
|||||||
@ -108,6 +108,7 @@ import {
|
|||||||
respondAgentConnection,
|
respondAgentConnection,
|
||||||
} from "./agent-connections.js";
|
} from "./agent-connections.js";
|
||||||
import {
|
import {
|
||||||
|
agentSecretScopeForRun,
|
||||||
decryptAgentEnvironment,
|
decryptAgentEnvironment,
|
||||||
formatAgentEnvironmentInstruction,
|
formatAgentEnvironmentInstruction,
|
||||||
redactAgentCommandResult,
|
redactAgentCommandResult,
|
||||||
@ -1029,7 +1030,7 @@ export function createRunExecutor(deps: ExecutorDeps) {
|
|||||||
userId: run.userId,
|
userId: run.userId,
|
||||||
}),
|
}),
|
||||||
deps.prisma.agentSecret.findMany({
|
deps.prisma.agentSecret.findMany({
|
||||||
where: { spaceId: run.spaceId },
|
where: agentSecretScopeForRun(run.spaceId, run.userId),
|
||||||
select: {
|
select: {
|
||||||
name: true,
|
name: true,
|
||||||
secret: { select: { id: true, ciphertext: true } },
|
secret: { select: { id: true, ciphertext: true } },
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user