Skip to content

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

feat: add validation on sync creation to make sure the region is the same when sts endpoint is added

adilson6a79e4463fc3
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 a3fa45a58e..306760f00b 100644
--- a/backend/src/services/app-connection/aws/aws-connection-fns.ts
+++ b/backend/src/services/app-connection/aws/aws-connection-fns.ts
@@ -1,5 +1,6 @@
import { AssumeRoleCommand, GetCallerIdentityCommand, STSClient, STSServiceException } from "@aws-sdk/client-sts";
import { AxiosError } from "axios";
+import { z } from "zod";
import { CustomAWSHasher } from "@app/lib/aws/hashing";
import { getConfig } from "@app/lib/config/env";
@@ -7,9 +8,12 @@ import { crypto } from "@app/lib/crypto/cryptography";
import { BadRequestError, InternalServerError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
import { AppConnection, AWSRegion } from "@app/services/app-connection/app-connection-enums";
+import { decryptAppConnectionCredentials } from "@app/services/app-connection/app-connection-fns";
import { TAppConnectionRaw } from "@app/services/app-connection/app-connection-types";
+import { TPreSaveTransformDestinationConfigFn } from "@app/services/secret-sync/secret-sync-types";
import { AwsConnectionMethod } from "./aws-connection-enums";
+import { AwsConnectionAssumeRoleCredentialsSchema } from "./aws-connection-schemas";
import { TAwsConnectionConfig } from "./aws-connection-types";
// Regional and VPC PrivateLink STS endpoints reject requests whose SigV4 credential scope region
@@ -133,8 +137,6 @@ export const validateAwsConnectionCredentials = async (appConnection: TAwsConnec
try {
const awsConfig = await getAwsConnectionConfig(appConnection);
- // honor the custom STS endpoint for the caller-identity check too, so validation
- // works in isolated environments where only the custom endpoint is reachable
const stsEndpoint =
appConnection.method === AwsConnectionMethod.AssumeRole ? appConnection.credentials.stsEndpoint : undefined;
@@ -175,3 +177,49 @@ export const validateAwsConnectionCredentials = async (appConnection: TAwsConnec
return appConnection.credentials;
};
+
+// For AWS secret syncs: if the linked connection pins a custom STS endpoint to a specific region,
+// the sync's destination region must match that endpoint's region. A custom STS endpoint is typically
+// used in isolated/VPC networks where other regions' data-plane endpoints aren't reachable, so a
+// mismatched region is a misconfiguration we reject up front. Region-less endpoints (the global
+// sts.amazonaws.com or non-AWS hosts) pin no region and impose no constraint.
+export const awsSyncPreSaveTransformDestinationConfig: TPreSaveTransformDestinationConfigFn = async (
+ { destinationConfig, connectionId },
+ { appConnectionDAL, kmsService }
+) => {
+ if (!destinationConfig) return destinationConfig;
+
+ const appConnection = await appConnectionDAL.findById(connectionId);
+
+ if (
+ !appConnection ||
+ appConnection.app !== AppConnection.AWS ||
+ appConnection.method !== AwsConnectionMethod.AssumeRole
+ ) {
+ return destinationConfig;
+ }
+
+ const { stsEndpoint } = (await decryptAppConnectionCredentials({
+ orgId: appConnection.orgId,
+ projectId: appConnection.projectId,
+ encryptedCredentials: appConnection.encryptedCredentials,
+ kmsService
+ })) as z.infer<typeof AwsConnectionAssumeRoleCredentialsSchema>;
+
+ if (!stsEndpoint) return destinationConfig;
+
+ const stsRegion = getStsSigningRegion(stsEndpoint);
+
+ // global / non-AWS endpoint pins no region, so any sync region is allowed
+ if (!stsRegion) return destinationConfig;
+
+ const region = destinationConfig.region as string | undefined;
+
+ if (region && region !== stsRegion) {
+ throw new BadRequestError({
+ message: `Secret sync region "${region}" must match the AWS connection's STS endpoint region from the app connection. Update the sync region or the connection's STS endpoint.`
+ });
+ }
+
+ return destinationConfig;
+};
diff --git a/backend/src/services/secret-sync/secret-sync-fns.ts b/backend/src/services/secret-sync/secret-sync-fns.ts
index 43b12173d7..c6ab03b6d7 100644
--- a/backend/src/services/secret-sync/secret-sync-fns.ts
+++ b/backend/src/services/secret-sync/secret-sync-fns.ts
@@ -8,6 +8,7 @@ import { TLicenseServiceFactory } from "@app/ee/services/license/license-service
import { CHEF_SYNC_LIST_OPTION, ChefSyncFns } from "@app/ee/services/secret-sync/chef";
import { OCI_VAULT_SYNC_LIST_OPTION, OCIVaultSyncFns } from "@app/ee/services/secret-sync/oci-vault";
import { BadRequestError } from "@app/lib/errors";
+import { awsSyncPreSaveTransformDestinationConfig } from "@app/services/app-connection/aws/aws-connection-fns";
import {
AWS_PARAMETER_STORE_SYNC_LIST_OPTION,
AwsParameterStoreSyncFns
@@ -141,7 +142,9 @@ const PRE_SAVE_TRANSFORM_SYNC_OPTIONS_MAP: Partial<Record<SecretSync, TPreSaveTr
};
const PRE_SAVE_TRANSFORM_DESTINATION_CONFIG_MAP: Partial<Record<SecretSync, TPreSaveTransformDestinationConfigFn>> = {
- [SecretSync.AzureEntraIdScim]: azureEntraIdScimPreSaveTransformDestinationConfig
+ [SecretSync.AzureEntraIdScim]: azureEntraIdScimPreSaveTransformDestinationConfig,
+ [SecretSync.AWSSecretsManager]: awsSyncPreSaveTransformDestinationConfig,
+ [SecretSync.AWSParameterStore]: awsSyncPreSaveTransformDestinationConfig
};
export const preSaveTransformSyncOptions = async (
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/AwsParameterStoreSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/AwsParameterStoreSyncFields.tsx
index 882300ce8f..1ec20252b3 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/AwsParameterStoreSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/AwsParameterStoreSyncFields.tsx
@@ -35,7 +35,18 @@ export const AwsParameterStoreSyncFields = () => {
name="destinationConfig.region"
render={({ field: { value, onChange }, fieldState: { error } }) => (
<Field>
- <FieldLabel>Region</FieldLabel>
+ <FieldLabel>
+ Region
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Info />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-md">
+ If a STS endpoint is set in the app connection, the region must match the STS
+ endpoint region.
+ </TooltipContent>
+ </Tooltip>
+ </FieldLabel>
<FieldContent>
<AwsRegionSelect value={value} onChange={onChange} />
<FieldError errors={[error]} />
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/AwsSecretsManagerSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/AwsSecretsManagerSyncFields.tsx
index 3b3a4724e8..abffd11f80 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/AwsSecretsManagerSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/AwsSecretsManagerSyncFields.tsx
@@ -37,7 +37,18 @@ export const AwsSecretsManagerSyncFields = () => {
<Controller
render={({ field: { value, onChange }, fieldState: { error } }) => (
<Field>
- <FieldLabel>Region</FieldLabel>
+ <FieldLabel>
+ Region
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Info />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-md">
+ If a STS endpoint is set in the app connection, the region must match the STS
+ endpoint region.
+ </TooltipContent>
+ </Tooltip>
+ </FieldLabel>
<FieldContent>
<AwsRegionSelect value={value} onChange={onChange} />
<FieldError errors={[error]} />