Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(pki): use org ID as ExternalID for cert manager AWS connections (#6883)
Saif Ur Rahmanecc5311925c7
diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.tsindex 25136cf555..a972163e32 100644--- a/backend/src/services/app-connection/app-connection-service.ts+++ b/backend/src/services/app-connection/app-connection-service.ts@@ -483,9 +483,9 @@ export const appConnectionServiceFactory = ({scope: OrganizationActionScope.Any});- if (projectId) {- const project = await projectDAL.findProjectById(projectId);+ const project = projectId ? await projectDAL.findProjectById(projectId) : null;+ if (projectId) {if (!project) throw new BadRequestError({ message: `Could not find project with ID ${projectId}` });const { permission } = await permissionService.getProjectPermission({@@ -567,7 +567,8 @@ export const appConnectionServiceFactory = ({orgId: actor.orgId,projectId,version: 2,- gatewayId: validationGatewayId+ gatewayId: validationGatewayId,+ projectType: project?.type} as TAppConnectionConfig,gatewayService,gatewayV2Service,@@ -841,6 +842,8 @@ export const appConnectionServiceFactory = ({} Connection with method ${getAppConnectionMethodName(method)}`});+ const updateProject = appConnection.projectId ? await projectDAL.findProjectById(appConnection.projectId) : null;+updatedCredentials = await validateAppConnectionCredentials({app,@@ -849,7 +852,8 @@ export const appConnectionServiceFactory = ({version: appConnection.version,credentials: credentialsToValidate,method,- gatewayId: validationGatewayId+ gatewayId: validationGatewayId,+ projectType: updateProject?.type} as TAppConnectionConfig,gatewayService,gatewayV2Service,@@ -1137,9 +1141,13 @@ export const appConnectionServiceFactory = ({} Connection with ID ${connectionId} cannot be used to connect to ${APP_CONNECTION_NAME_MAP[app]}`});+ const connectionProject = appConnection.projectId+ ? await projectDAL.findProjectById(appConnection.projectId)+ : null;+const connection = await decryptAppConnection(appConnection, kmsService);- return connection as T;+ return { ...connection, projectType: connectionProject?.type } as unknown as T;};const validateAppConnectionUsageById = async (diff --git a/backend/src/services/app-connection/aws/aws-connection-fns.ts b/backend/src/services/app-connection/aws/aws-connection-fns.tsindex 3b0f222a43..555573496d 100644--- a/backend/src/services/app-connection/aws/aws-connection-fns.ts+++ b/backend/src/services/app-connection/aws/aws-connection-fns.ts@@ -2,6 +2,7 @@ import { AssumeRoleCommand, GetCallerIdentityCommand, STSClient, STSServiceExcepimport { AxiosError } from "axios";import { z } from "zod";+import { ProjectType } from "@app/db/schemas";import { CustomAWSHasher } from "@app/lib/aws/hashing";import { getConfig } from "@app/lib/config/env";import { crypto } from "@app/lib/crypto/cryptography";@@ -75,7 +76,7 @@ export const getAwsConnectionConfig = async (appConnection: TAwsConnectionConfiglet secretAccessKey: string;let sessionToken: undefined | string;- const { method, credentials, orgId, projectId, version } = appConnection;+ const { method, credentials, orgId, projectId, version, projectType } = appConnection;switch (method) {case AwsConnectionMethod.AssumeRole: {@@ -101,18 +102,42 @@ export const getAwsConnectionConfig = async (appConnection: TAwsConnectionConfig});// v1 (legacy) always used orgId; v2+ uses projectId when available, orgId otherwise.- const externalId = (version ?? 1) >= 2 ? (projectId ?? orgId) : orgId;-- const command = new AssumeRoleCommand({- RoleArn: credentials.roleArn,- RoleSessionName: `infisical-app-connection-${crypto.nativeCrypto.randomUUID()}`,- DurationSeconds: 900, // 15 mins- ExternalId: externalId- });+ // Certificate Manager connections try orgId first (the recommended ExternalID),+ // then fall back to projectId for backwards compatibility with existing trust policies.+ const externalIds: string[] = [];+ if ((version ?? 1) >= 2) {+ if (projectType === ProjectType.CertificateManager) {+ externalIds.push(orgId);+ if (projectId && projectId !== orgId) externalIds.push(projectId);+ } else {+ externalIds.push(projectId ?? orgId);+ }+ } else {+ externalIds.push(orgId);+ }- const assumeRes = await client.send(command);+ let assumeRes;+ let lastErr: unknown;+ for (const externalId of externalIds) {+ try {+ const command = new AssumeRoleCommand({+ RoleArn: credentials.roleArn,+ RoleSessionName: `infisical-app-connection-${crypto.nativeCrypto.randomUUID()}`,+ DurationSeconds: 900, // 15 mins+ ExternalId: externalId+ });+ // eslint-disable-next-line no-await-in-loop+ assumeRes = await client.send(command);+ lastErr = undefined;+ break;+ } catch (err) {+ lastErr = err;+ logger.info(`AssumeRole with ExternalId failed, trying next candidate [roleArn=${credentials.roleArn}]`);+ }+ }+ if (lastErr) throw lastErr as Error;- if (!assumeRes.Credentials?.AccessKeyId || !assumeRes.Credentials?.SecretAccessKey) {+ if (!assumeRes?.Credentials?.AccessKeyId || !assumeRes?.Credentials?.SecretAccessKey) {throw new BadRequestError({ message: "Failed to assume role - verify credentials and role configuration" });}@@ -142,7 +167,7 @@ export const getAwsConnectionConfig = async (appConnection: TAwsConnectionConfig};export const buildAwsConnectionConfig = (- connection: Pick<TAppConnectionRaw, "orgId" | "projectId" | "version" | "method">,+ connection: Pick<TAppConnectionRaw, "orgId" | "projectId" | "version" | "method"> & { projectType?: string },credentials: TAwsConnectionConfig["credentials"]): TAwsConnectionConfig =>({@@ -151,7 +176,8 @@ export const buildAwsConnectionConfig = (credentials,orgId: connection.orgId,projectId: connection.projectId,- version: connection.version+ version: connection.version,+ projectType: connection.projectType}) as TAwsConnectionConfig;export const validateAwsConnectionCredentials = async (appConnection: TAwsConnectionConfig) => {diff --git a/backend/src/services/app-connection/aws/aws-connection-types.ts b/backend/src/services/app-connection/aws/aws-connection-types.tsindex 24a396da24..e58a5befe9 100644--- a/backend/src/services/app-connection/aws/aws-connection-types.ts+++ b/backend/src/services/app-connection/aws/aws-connection-types.ts@@ -21,4 +21,5 @@ export type TAwsConnectionConfig = DiscriminativePick<TAwsConnectionInput, "methorgId: string;projectId?: string | null;version?: number;+ projectType?: string;};diff --git a/backend/src/services/pki-sync/pki-sync-queue.ts b/backend/src/services/pki-sync/pki-sync-queue.tsindex 6314cdc25d..9262f3a295 100644--- a/backend/src/services/pki-sync/pki-sync-queue.ts+++ b/backend/src/services/pki-sync/pki-sync-queue.ts@@ -435,6 +435,8 @@ export const pkiSyncQueueFactory = ({throw new Error(`App connection not found: ${connectionId}`);}+ const project = appConnectionProjectId ? await projectDAL.findById(appConnectionProjectId) : null;+const credentials = await decryptAppConnectionCredentials({orgId,encryptedCredentials: appConnection.encryptedCredentials,@@ -446,7 +448,8 @@ export const pkiSyncQueueFactory = ({...pkiSync,connection: {...pkiSync.connection,- credentials+ credentials,+ projectType: project?.type}} as TPkiSyncWithCredentials;@@ -739,6 +742,8 @@ export const pkiSyncQueueFactory = ({throw new Error(`App connection not found: ${connectionId}`);}+ const removeProject = appConnectionProjectId ? await projectDAL.findById(appConnectionProjectId) : null;+const credentials = await decryptAppConnectionCredentials({orgId,encryptedCredentials: appConnection.encryptedCredentials,@@ -753,7 +758,8 @@ export const pkiSyncQueueFactory = ({...pkiSync,connection: {...pkiSync.connection,- credentials+ credentials,+ projectType: removeProject?.type}} as TPkiSyncWithCredentials,Object.keys(certificateMap),diff --git a/docs/documentation/platform/pki/applications/certificate-syncs/aws-certificate-manager.mdx b/docs/documentation/platform/pki/applications/certificate-syncs/aws-certificate-manager.mdxindex 16361e5af1..7d4b0a8431 100644--- a/docs/documentation/platform/pki/applications/certificate-syncs/aws-certificate-manager.mdx+++ b/docs/documentation/platform/pki/applications/certificate-syncs/aws-certificate-manager.mdx@@ -19,6 +19,10 @@ Push certificates from your Application to AWS Certificate Manager (ACM). Certif- `acm:DeleteCertificate`- `acm:ListTagsForCertificate`+<Tip>+ If your AWS Connection uses the **Assume Role** method and is created within Certificate Manager, use your **Organization ID** as the External ID in your AWS IAM role trust policy. You can find the Organization ID in your organization settings. See the [AWS Connection docs](/integrations/app-connections/aws) for more details.+</Tip>+<Note>Certificates synced to ACM are stored as imported certificates, preserving both the certificate and private key.</Note>diff --git a/docs/documentation/platform/pki/applications/certificate-syncs/aws-elastic-load-balancer.mdx b/docs/documentation/platform/pki/applications/certificate-syncs/aws-elastic-load-balancer.mdxindex c876b11d27..9040152183 100644--- a/docs/documentation/platform/pki/applications/certificate-syncs/aws-elastic-load-balancer.mdx+++ b/docs/documentation/platform/pki/applications/certificate-syncs/aws-elastic-load-balancer.mdx@@ -16,6 +16,10 @@ Deploy certificates directly to your AWS Application Load Balancers (ALBs) and N- **ACM:** `acm:ListCertificates`, `acm:DescribeCertificate`, `acm:ImportCertificate`, `acm:DeleteCertificate`, `acm:ListTagsForCertificate`- **ELB:** `elasticloadbalancing:DescribeLoadBalancers`, `elasticloadbalancing:DescribeListeners`, `elasticloadbalancing:DescribeListenerCertificates`, `elasticloadbalancing:AddListenerCertificates`, `elasticloadbalancing:RemoveListenerCertificates`, `elasticloadbalancing:ModifyListener`+<Tip>+ If your AWS Connection uses the **Assume Role** method and is created within Certificate Manager, use your **Organization ID** as the External ID in your AWS IAM role trust policy. You can find the Organization ID in your organization settings. See the [AWS Connection docs](/integrations/app-connections/aws) for more details.+</Tip>+## Create an ELB Sync<Tabs>diff --git a/docs/documentation/platform/pki/applications/certificate-syncs/aws-secrets-manager.mdx b/docs/documentation/platform/pki/applications/certificate-syncs/aws-secrets-manager.mdxindex a750968cc3..dd33748394 100644--- a/docs/documentation/platform/pki/applications/certificate-syncs/aws-secrets-manager.mdx+++ b/docs/documentation/platform/pki/applications/certificate-syncs/aws-secrets-manager.mdx@@ -19,6 +19,10 @@ Store certificates in AWS Secrets Manager as JSON secrets for application retrie- `secretsmanager:DeleteSecret`- `secretsmanager:ListSecrets`+<Tip>+ If your AWS Connection uses the **Assume Role** method and is created within Certificate Manager, use your **Organization ID** as the External ID in your AWS IAM role trust policy. You can find the Organization ID in your organization settings. See the [AWS Connection docs](/integrations/app-connections/aws) for more details.+</Tip>+<Note>Certificates are stored as JSON secrets with configurable field names for certificate, private key, and chain.</Note>diff --git a/docs/integrations/app-connections/aws.mdx b/docs/integrations/app-connections/aws.mdxindex 12a8ec26d3..33ae28e997 100644--- a/docs/integrations/app-connections/aws.mdx+++ b/docs/integrations/app-connections/aws.mdx@@ -71,7 +71,7 @@ Infisical supports two methods for connecting to AWS.This precaution helps protect your AWS account against the [confused deputy problem](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html), a potential security vulnerability where Infisical could be tricked into performing actions on your behalf by an unauthorized actor.Infisical automatically sends the correct External ID based on the connection’s scope:- - **Project-scoped connections** use the **Project ID** as the External ID, restricting role access to a single project.+ - **Project-scoped connections** use the **Project ID** as the External ID, restricting role access to a single project. **Certificate Manager** connections use the **Organization ID** as the External ID.- **Organization-scoped connections** use the **Organization ID** as the External ID.<strong>Always enable "Require external ID" when setting up the IAM Role, and use the ID that matches your connection’s scope.</strong>