Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(agent-vault): use the org ID as the AWS External ID and show it (#8375)

Saif Ur Rahmana60d051da7f9
diff --git a/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-storage-fns.test.ts b/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-storage-fns.test.ts
index 6de126dc8f..dfb10f856e 100644
--- a/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-storage-fns.test.ts
+++ b/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-storage-fns.test.ts
@@ -1,6 +1,7 @@
import { STSServiceException } from "@aws-sdk/client-sts";
import { describe, expect, test, vi } from "vitest";
+import { ProjectType } from "@app/db/schemas";
import { AppConnection, AWSRegion } from "@app/services/app-connection/app-connection-enums";
import { getAwsConnectionConfig } from "@app/services/app-connection/aws/aws-connection-fns";
@@ -15,6 +16,7 @@ vi.mock("@app/services/app-connection/app-connection-fns", () => ({
vi.mock("@app/services/app-connection/aws/aws-connection-fns", () => ({
getAwsConnectionConfig: vi.fn()
}));
+vi.mock("@app/lib/aws/s3", () => ({ createS3Bucket: vi.fn(() => ({})) }));
describe("buildSessionLogStorage", () => {
const config = { appConnectionId: "conn-1", bucket: "logs", region: AWSRegion.US_EAST_1, keyPrefix: null };
@@ -41,6 +43,26 @@ describe("buildSessionLogStorage", () => {
});
});
+ test("assumes the role with Agent Vault's External ID, for its own connections too", async () => {
+ vi.mocked(getAwsConnectionConfig).mockClear();
+ vi.mocked(getAwsConnectionConfig).mockResolvedValueOnce({
+ region: AWSRegion.US_EAST_1,
+ credentials: { accessKeyId: "access-key", secretAccessKey: "secret-key", sessionToken: undefined }
+ });
+ vi.mocked(deps.appConnectionDAL.findById).mockResolvedValueOnce({
+ id: "conn-1",
+ name: "av-logs",
+ orgId: "org-1",
+ projectId: "av-proj",
+ app: AppConnection.AWS
+ } as never);
+ await buildSessionLogStorage(config, "org-1", deps);
+ expect(getAwsConnectionConfig).toHaveBeenCalledWith(
+ expect.objectContaining({ projectType: ProjectType.AgentVault }),
+ config.region
+ );
+ });
+
test("keeps anything that is not from AWS out of the message", async () => {
vi.mocked(getAwsConnectionConfig).mockRejectedValueOnce(new Error("kms_keys row missing"));
await expect(buildSessionLogStorage(config, "org-1", deps)).rejects.toMatchObject({
diff --git a/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-storage-fns.ts b/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-storage-fns.ts
index b47fa4a970..acca30b155 100644
--- a/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-storage-fns.ts
+++ b/backend/src/ee/services/agent-vault-session-log/agent-vault-session-log-storage-fns.ts
@@ -1,5 +1,6 @@
import { STSServiceException } from "@aws-sdk/client-sts";
+import { ProjectType } from "@app/db/schemas";
import { createS3Bucket } from "@app/lib/aws/s3";
import { BadRequestError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
@@ -46,7 +47,11 @@ export const buildSessionLogStorage = async (
let credentials: Awaited<ReturnType<typeof getAwsConnectionConfig>>["credentials"];
try {
const connection = await decryptAppConnection(raw, kmsService as Parameters<typeof decryptAppConnection>[1]);
- ({ credentials } = await getAwsConnectionConfig(connection as unknown as TAwsConnectionConfig, config.region));
+ // Session logs only accept org connections or Agent Vault's own, and both assume the role with the org ID.
+ ({ credentials } = await getAwsConnectionConfig(
+ { ...connection, projectType: ProjectType.AgentVault } as unknown as TAwsConnectionConfig,
+ config.region
+ ));
} catch (err) {
logger.warn({ err }, `Agent Vault session logs could not use their AWS connection [appConnectionId=${raw.id}]`);
const reason =
diff --git a/backend/src/services/app-connection/aws/aws-connection-fns.test.ts b/backend/src/services/app-connection/aws/aws-connection-fns.test.ts
new file mode 100644
index 0000000000..866771efa8
--- /dev/null
+++ b/backend/src/services/app-connection/aws/aws-connection-fns.test.ts
@@ -0,0 +1,84 @@
+import { ProjectType } from "@app/db/schemas";
+import { AppConnection } from "@app/services/app-connection/app-connection-enums";
+
+import { AwsConnectionMethod } from "./aws-connection-enums";
+import { getAwsConnectionConfig } from "./aws-connection-fns";
+import { TAwsConnectionConfig } from "./aws-connection-types";
+
+const sts = vi.hoisted(() => ({
+ externalIds: [] as (string | undefined)[],
+ rejectionsLeft: 0
+}));
+
+vi.mock("@app/lib/config/env", () => ({ getConfig: () => ({}) }));
+vi.mock("@app/lib/crypto/cryptography", () => ({
+ crypto: { isFipsModeEnabled: () => false, nativeCrypto: { randomUUID: () => "session" } }
+}));
+vi.mock("@app/lib/aws/hashing", () => ({ CustomAWSHasher: function CustomAWSHasher() {} }));
+vi.mock("@app/lib/logger", () => ({
+ logger: { info: () => {}, warn: () => {}, error: () => {}, debug: () => {} }
+}));
+vi.mock("@aws-sdk/client-sts", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("@aws-sdk/client-sts")>();
+ return {
+ ...actual,
+ STSClient: class {
+ // eslint-disable-next-line class-methods-use-this
+ async send(command: { input: { ExternalId?: string } }) {
+ sts.externalIds.push(command.input.ExternalId);
+ if (sts.rejectionsLeft > 0) {
+ sts.rejectionsLeft -= 1;
+ throw new Error("not authorized to perform: sts:AssumeRole");
+ }
+ return { Credentials: { AccessKeyId: "access-key", SecretAccessKey: "secret-key", SessionToken: "token" } };
+ }
+ }
+ };
+});
+
+const assumeRoleConnection = (overrides: Partial<TAwsConnectionConfig>) =>
+ ({
+ app: AppConnection.AWS,
+ method: AwsConnectionMethod.AssumeRole,
+ credentials: { roleArn: "arn:aws:iam::123456789012:role/infisical" },
+ orgId: "org-1",
+ projectId: "proj-1",
+ version: 2,
+ ...overrides
+ }) as TAwsConnectionConfig;
+
+describe("getAwsConnectionConfig External ID", () => {
+ beforeEach(() => {
+ sts.externalIds = [];
+ sts.rejectionsLeft = 0;
+ });
+
+ test.each([
+ ["Agent Vault", { projectType: ProjectType.AgentVault }, ["org-1"]],
+ ["Certificate Manager", { projectType: ProjectType.CertificateManager }, ["org-1"]],
+ ["Secret Manager", { projectType: ProjectType.SecretManager }, ["proj-1"]],
+ ["organization", { projectId: null }, ["org-1"]],
+ ["legacy project", { version: 1, projectType: ProjectType.SecretManager }, ["org-1"]]
+ ])("%s connections assume the role with the expected External ID", async (_, overrides, expected) => {
+ await getAwsConnectionConfig(assumeRoleConnection(overrides));
+
+ expect(sts.externalIds).toEqual(expected);
+ });
+
+ test("Agent Vault connections do not retry with the project ID", async () => {
+ sts.rejectionsLeft = 1;
+
+ await expect(getAwsConnectionConfig(assumeRoleConnection({ projectType: ProjectType.AgentVault }))).rejects.toThrow(
+ "sts:AssumeRole"
+ );
+ expect(sts.externalIds).toEqual(["org-1"]);
+ });
+
+ test("Certificate Manager connections retry with the project ID", async () => {
+ sts.rejectionsLeft = 1;
+
+ await getAwsConnectionConfig(assumeRoleConnection({ projectType: ProjectType.CertificateManager }));
+
+ expect(sts.externalIds).toEqual(["org-1", "proj-1"]);
+ });
+});
diff --git a/backend/src/services/app-connection/aws/aws-connection-fns.ts b/backend/src/services/app-connection/aws/aws-connection-fns.ts
index bf41c638c8..c9ca6a3c3b 100644
--- a/backend/src/services/app-connection/aws/aws-connection-fns.ts
+++ b/backend/src/services/app-connection/aws/aws-connection-fns.ts
@@ -100,11 +100,14 @@ export const getAwsConnectionConfig = async (appConnection: TAwsConnectionConfig
// v1 (legacy) always used orgId; v2+ uses projectId when available, orgId otherwise.
// Certificate Manager connections try orgId first (the recommended ExternalID),
// then fall back to projectId for backwards compatibility with existing trust policies.
+ // Agent Vault's project is implicit and never shown to users, so its connections use orgId.
const externalIds: string[] = [];
if ((version ?? 1) >= 2) {
if (projectType === ProjectType.CertificateManager) {
externalIds.push(orgId);
if (projectId && projectId !== orgId) externalIds.push(projectId);
+ } else if (projectType === ProjectType.AgentVault) {
+ externalIds.push(orgId);
} else {
externalIds.push(projectId ?? orgId);
}
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AddAppConnectionModal.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AddAppConnectionModal.tsx
index a2e2c90096..88abf2fb0f 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AddAppConnectionModal.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AddAppConnectionModal.tsx
@@ -123,6 +123,7 @@ export const AddAppConnectionModal = ({
<AppConnectionForm
app={selectedApp}
projectId={projectId}
+ projectType={projectType}
onComplete={handleComplete}
onCancel={() => requestDiscardAction(closeSheet)}
onDirtyChange={setIsDirty}
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
index 26d9f9bf07..b6da15c46d 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
@@ -11,6 +11,7 @@ import {
useUpdateAppConnection
} from "@app/hooks/api/appConnections";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
+import { ProjectType } from "@app/hooks/api/projects/types";
import { DiscriminativePick } from "@app/types";
import { OnePassConnectionForm } from "./1PasswordConnectionForm";
@@ -168,12 +169,13 @@ type FormProps = {
type CreateFormProps = FormProps & {
app: AppConnection;
projectId?: string;
+ projectType?: ProjectType;
};
type UpdateFormProps = FormProps & {
appConnection: TAppConnection;
};
-const CreateForm = ({ app, onComplete, projectId }: CreateFormProps) => {
+const CreateForm = ({ app, onComplete, projectId, projectType }: CreateFormProps) => {
const [pendingFormData, setPendingFormData] = useState<AppConnectionFormData | null>(null);
const [isConfirmSubmitting, setIsConfirmSubmitting] = useState(false);
const createAppConnection = useCreateAppConnection();
@@ -202,7 +204,7 @@ const CreateForm = ({ app, onComplete, projectId }: CreateFormProps) => {
const renderForm = () => {
switch (app) {
case AppConnection.AWS:
- return <AwsConnectionForm onSubmit={onSubmit} />;
+ return <AwsConnectionForm onSubmit={onSubmit} projectType={projectType} />;
case AppConnection.GitHub:
return <GitHubConnectionForm projectId={projectId} onSubmit={onSubmit} />;
case AppConnection.GitHubRadar:
@@ -442,7 +444,13 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
const renderForm = () => {
switch (appConnection.app) {
case AppConnection.AWS:
- return <AwsConnectionForm appConnection={appConnection} onSubmit={onSubmit} />;
+ return (
+ <AwsConnectionForm
+ appConnection={appConnection}
+ onSubmit={onSubmit}
+ projectType={appConnection.project?.type}
+ />
+ );
case AppConnection.GitHub:
return (
<GitHubConnectionForm
@@ -712,12 +720,19 @@ type Props = {
onCancel: () => void;
onDirtyChange?: (isDirty: boolean) => void;
projectId?: string;
+ projectType?: ProjectType;
} & Pick<FormProps, "onComplete"> &
(
| { app: AppConnection; appConnection?: undefined }
| { app?: undefined; appConnection: TAppConnection }
);
-export const AppConnectionForm = ({ onCancel, onDirtyChange, projectId, ...props }: Props) => {
+export const AppConnectionForm = ({
+ onCancel,
+ onDirtyChange,
+ projectId,
+ projectType,
+ ...props
+}: Props) => {
const { app, appConnection } = props;
const contextValue = useMemo(() => ({ onCancel, onDirtyChange }), [onCancel, onDirtyChange]);
@@ -727,7 +742,7 @@ export const AppConnectionForm = ({ onCancel, onDirtyChange, projectId, ...props
{appConnection ? (
<UpdateForm {...props} appConnection={appConnection} />
) : (
- <CreateForm {...props} app={app} projectId={projectId} />
+ <CreateForm {...props} app={app} projectId={projectId} projectType={projectType} />
)}
</AppConnectionFormProvider>
);
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AwsConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AwsConnectionForm.tsx
index d455d6ca9a..468405edbb 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AwsConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AwsConnectionForm.tsx
@@ -4,9 +4,15 @@ import { Info } from "lucide-react";
import { z } from "zod";
import {
+ Code,
+ CopyButton,
Field,
+ FieldDescription,
FieldError,
FieldLabel,
+ HoverCard,
+ HoverCardContent,
+ HoverCardTrigger,
Input,
SecretInput,
Select,
@@ -18,9 +24,11 @@ import {
TooltipContent,
TooltipTrigger
} from "@app/components/v3";
+import { useOrganization } from "@app/context";
import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
import { AwsConnectionMethod, TAwsConnection } from "@app/hooks/api/appConnections";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
+import { ProjectType } from "@app/hooks/api/projects/types";
import { AppConnectionFormFooter } from "./AppConnectionFormFooter";
import {
@@ -31,6 +39,7 @@ import {
type Props = {
appConnection?: TAwsConnection;
onSubmit: (formData: FormData) => Promise<void>;
+ projectType?: ProjectType;
};
const rootSchema = genericAppConnectionFieldsSchema.extend({
@@ -63,7 +72,36 @@ const formSchema = z.discriminatedUnion("method", [
type FormData = z.infer<typeof formSchema>;
-export const AwsConnectionForm = ({ appConnection, onSubmit }: Props) => {
+const OrgExternalIdHint = () => {
+ const { currentOrg } = useOrganization();
+
+ return (
+ <FieldDescription>
+ Infisical sends your{" "}
+ <HoverCard openDelay={150} closeDelay={150}>
+ <HoverCardTrigger asChild>
+ <span className="cursor-help text-foreground underline decoration-muted decoration-dotted underline-offset-4">
+ organization ID
+ </span>
+ </HoverCardTrigger>
+ <HoverCardContent align="start" className="w-auto max-w-sm">
+ <p className="text-xs font-medium text-foreground">External ID</p>
+ <div className="mt-1 flex items-center gap-1">
+ <span className="font-mono text-xs">{currentOrg.id}</span>
+ <CopyButton value={currentOrg.id} ariaLabel="Copy organization ID" />
+ </div>
+ <p className="mt-2 text-xs text-muted">
+ Require it in the role&apos;s trust policy with the <Code>sts:ExternalId</Code>{" "}
+ condition.
+ </p>
+ </HoverCardContent>
+ </HoverCard>{" "}
+ as the External ID when it assumes this role.
+ </FieldDescription>
+ );
+};
+
+export const AwsConnectionForm = ({ appConnection, onSubmit, projectType }: Props) => {
const isUpdate = Boolean(appConnection);
const form = useForm<FormData>({
@@ -133,6 +171,7 @@ export const AwsConnectionForm = ({ appConnection, onSubmit }: Props) => {
value={value}
onChange={(e) => onChange(e.target.value)}
/>
+ {projectType === ProjectType.AgentVault && <OrgExternalIdHint />}
<FieldError id="app-connection-aws-role-arn-error" errors={[error]} />
</Field>
)}