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 {
|
||||
agentSecretScopeForRun,
|
||||
decryptAgentEnvironment,
|
||||
formatAgentEnvironmentInstruction,
|
||||
redactAgentCommandResult,
|
||||
} from "./agent-environment.js";
|
||||
|
||||
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", () => {
|
||||
const env = decryptAgentEnvironment(
|
||||
[
|
||||
|
||||
@ -10,6 +10,10 @@ type SecretLoader = {
|
||||
load(ciphertext: string, recordId: string): string;
|
||||
};
|
||||
|
||||
export function agentSecretScopeForRun(spaceId: string, userId: string) {
|
||||
return { spaceId, createdByUserId: userId };
|
||||
}
|
||||
|
||||
export function decryptAgentEnvironment(
|
||||
rows: EncryptedAgentSecret[],
|
||||
secrets: SecretLoader,
|
||||
|
||||
@ -108,6 +108,7 @@ import {
|
||||
respondAgentConnection,
|
||||
} from "./agent-connections.js";
|
||||
import {
|
||||
agentSecretScopeForRun,
|
||||
decryptAgentEnvironment,
|
||||
formatAgentEnvironmentInstruction,
|
||||
redactAgentCommandResult,
|
||||
@ -1029,7 +1030,7 @@ export function createRunExecutor(deps: ExecutorDeps) {
|
||||
userId: run.userId,
|
||||
}),
|
||||
deps.prisma.agentSecret.findMany({
|
||||
where: { spaceId: run.spaceId },
|
||||
where: agentSecretScopeForRun(run.spaceId, run.userId),
|
||||
select: {
|
||||
name: true,
|
||||
secret: { select: { id: true, ciphertext: true } },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user