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: add optional sts host to support gov environments and custom aws environments
adilsoncb62e717a726
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex fc4cb18e50..676e5e63a0 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -2663,6 +2663,7 @@ export const AppConnections = {description: `An optional description for the ${appName} Connection.`,credentials: `The credentials used to connect with ${appName}.`,method: `The method used to authenticate with ${appName}.`,+ stsEndpoint: `An optional custom endpoint URL for the AWS STS API to use when connecting with ${appName}.`,isPlatformManagedCredentials: `Whether or not the ${appName} Connection credentials should be managed by Infisical. Once enabled this cannot be reversed.`,projectId: `The ID of the project to create the ${appName} Connection in.`,isAutoRotationEnabled: `Whether or not automatic credential rotation is enabled for the ${appName} Connection.`,@@ -2677,6 +2678,7 @@ export const AppConnections = {description: `The updated description of the ${appName} Connection.`,credentials: `The credentials used to connect with ${appName}.`,method: `The method used to authenticate with ${appName}.`,+ stsEndpoint: `An optional custom endpoint URL for the AWS STS API to use when connecting with ${appName}.`,isPlatformManagedCredentials: `Whether or not the ${appName} Connection credentials should be managed by Infisical. Once enabled this cannot be reversed.`,isAutoRotationEnabled: `Whether or not automatic credential rotation is enabled for the ${appName} Connection.`,rotation: `The updated credential rotation configuration for the ${appName} Connection.`diff --git a/backend/src/services/app-connection/aws/aws-connection-fns.ts b/backend/src/services/app-connection/aws/aws-connection-fns.tsindex ee439b895c..a3fa45a58e 100644--- a/backend/src/services/app-connection/aws/aws-connection-fns.ts+++ b/backend/src/services/app-connection/aws/aws-connection-fns.ts@@ -12,6 +12,29 @@ import { TAppConnectionRaw } from "@app/services/app-connection/app-connection-timport { AwsConnectionMethod } from "./aws-connection-enums";import { TAwsConnectionConfig } from "./aws-connection-types";+// Regional and VPC PrivateLink STS endpoints reject requests whose SigV4 credential scope region+// doesn't match the endpoint's region. In AWS STS hosts the region is the label following the "sts"+// (or "sts-fips") service label (e.g. sts.eu-west-1.amazonaws.com,+// vpce-0abc.sts.eu-west-1.vpce.amazonaws.com), so parse it out of the host. Returns undefined for the+// global endpoint (sts.amazonaws.com) and non-AWS hosts (e.g. LocalStack), where the caller's region+// is used and region scoping isn't enforced.+const getStsSigningRegion = (stsEndpoint?: string): string | undefined => {+ if (!stsEndpoint) return undefined;++ try {+ const { hostname } = new URL(stsEndpoint);++ const labels = hostname.split(".");+ const stsLabelIndex = labels.findIndex((label) => label === "sts" || label === "sts-fips");+ const region = stsLabelIndex === -1 ? undefined : labels[stsLabelIndex + 1];++ // the global endpoint (sts.amazonaws.com) has the domain in the region position, not a region+ return region === "amazonaws" ? undefined : region;+ } catch {+ return undefined;+ }+};+export const getAwsConnectionListItem = () => {const { INF_APP_CONNECTION_AWS_ACCESS_KEY_ID } = getConfig();@@ -35,9 +58,14 @@ export const getAwsConnectionConfig = async (appConnection: TAwsConnectionConfigswitch (method) {case AwsConnectionMethod.AssumeRole: {const client = new STSClient({- region,+ // when a custom STS endpoint is set, sign for the region embedded in that endpoint so the+ // request isn't rejected for being scoped to the wrong region; otherwise use the caller's region+ region: getStsSigningRegion(credentials.stsEndpoint) ?? region,useFipsEndpoint: crypto.isFipsModeEnabled(),sha256: CustomAWSHasher,+ // only override the endpoint when explicitly set; otherwise preserve the SDK's+ // default region/FIPS endpoint resolution so existing connections are unaffected+ ...(credentials.stsEndpoint ? { endpoint: credentials.stsEndpoint } : {}),credentials:appCfg.INF_APP_CONNECTION_AWS_ACCESS_KEY_ID && appCfg.INF_APP_CONNECTION_AWS_SECRET_ACCESS_KEY? {@@ -104,9 +132,16 @@ export const buildAwsConnectionConfig = (export const validateAwsConnectionCredentials = async (appConnection: TAwsConnectionConfig) => {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;+const sts = new STSClient({- region: awsConfig.region,- credentials: awsConfig.credentials+ region: getStsSigningRegion(stsEndpoint) ?? awsConfig.region,+ credentials: awsConfig.credentials,+ ...(stsEndpoint ? { endpoint: stsEndpoint } : {})});await sts.send(new GetCallerIdentityCommand({}));diff --git a/backend/src/services/app-connection/aws/aws-connection-schemas.ts b/backend/src/services/app-connection/aws/aws-connection-schemas.tsindex 7e8fd36a81..ebaa980652 100644--- a/backend/src/services/app-connection/aws/aws-connection-schemas.ts+++ b/backend/src/services/app-connection/aws/aws-connection-schemas.ts@@ -12,7 +12,14 @@ import { APP_CONNECTION_NAME_MAP } from "../app-connection-maps";import { AwsConnectionMethod } from "./aws-connection-enums";export const AwsConnectionAssumeRoleCredentialsSchema = z.object({- roleArn: z.string().trim().min(1, "Role ARN required")+ roleArn: z.string().trim().min(1, "Role ARN required"),+ stsEndpoint: z+ .string()+ .trim()+ .url("STS endpoint must be a valid URL")+ .startsWith("https://", "STS endpoint must use HTTPS")+ .optional()+ .describe(AppConnections.CREATE(AppConnection.AWS).stsEndpoint)});export const AwsConnectionAccessTokenCredentialsSchema = z.object({@@ -39,7 +46,7 @@ export const AwsConnectionSchema = z.intersection(export const SanitizedAwsConnectionSchema = z.discriminatedUnion("method", [BaseAwsConnectionSchema.extend({method: z.literal(AwsConnectionMethod.AssumeRole),- credentials: AwsConnectionAssumeRoleCredentialsSchema.pick({})+ credentials: AwsConnectionAssumeRoleCredentialsSchema.pick({ stsEndpoint: true })}).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.AWS]} (Assume Role)` })),BaseAwsConnectionSchema.extend({method: z.literal(AwsConnectionMethod.AccessKey),diff --git a/docs/integrations/app-connections/aws.mdx b/docs/integrations/app-connections/aws.mdxindex aa45a396f5..12a8ec26d3 100644--- a/docs/integrations/app-connections/aws.mdx+++ b/docs/integrations/app-connections/aws.mdx@@ -505,6 +505,13 @@ Infisical supports two methods for connecting to AWS.3. Select the **Assume Role** method option and provide the **AWS IAM Role ARN** obtained from the previous step and press **Connect to AWS**.+ <Note>+ The optional **STS Endpoint URL** field lets you override the default AWS STS endpoint that Infisical+ calls to assume the role. Provide an HTTPS URL (for example a VPC PrivateLink, GovCloud, China, FIPS,+ or region-pinned STS endpoint) when the default `https://sts.amazonaws.com` is not reachable or desired.+ Leave it blank to use AWS's default endpoint resolution.+ </Note>+4. Your **AWS Connection** is now available for use.</Tab>@@ -524,6 +531,7 @@ Infisical supports two methods for connecting to AWS."projectId": "7ffbb072-2575-495a-b5b0-127f88caef78","credentials": {"roleArn": "...",+ "stsEndpoint": "https://sts.amazonaws.com"}}'```diff --git a/frontend/src/hooks/api/appConnections/types/aws-connection.ts b/frontend/src/hooks/api/appConnections/types/aws-connection.tsindex 86074ca35f..a6216a629b 100644--- a/frontend/src/hooks/api/appConnections/types/aws-connection.ts+++ b/frontend/src/hooks/api/appConnections/types/aws-connection.ts@@ -18,6 +18,7 @@ export type TAwsConnection = TRootAppConnection & { app: AppConnection.AWS } & (method: AwsConnectionMethod.AssumeRole;credentials: {roleArn: string;+ stsEndpoint?: string;};});diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AwsConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AwsConnectionForm.tsxindex 4009cc4a31..46cba433d7 100644--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AwsConnectionForm.tsx+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AwsConnectionForm.tsx@@ -33,7 +33,15 @@ const formSchema = z.discriminatedUnion("method", [rootSchema.extend({method: z.literal(AwsConnectionMethod.AssumeRole),credentials: z.object({- roleArn: z.string().trim().min(1, "Role ARN required")+ roleArn: z.string().trim().min(1, "Role ARN required"),+ stsEndpoint: z+ .string()+ .trim()+ .url("Must be a valid URL")+ .startsWith("https://", "Must use HTTPS")+ .or(z.literal(""))+ .optional()+ .transform((val) => val || undefined)})}),rootSchema.extend({@@ -104,25 +112,47 @@ export const AwsConnectionForm = ({ appConnection, onSubmit }: Props) => {)}/>{selectedMethod === AwsConnectionMethod.AssumeRole ? (- <Controller- name="credentials.roleArn"- control={control}- shouldUnregister- render={({ field: { value, onChange }, fieldState: { error } }) => (- <FormControl- errorText={error?.message}- isError={Boolean(error?.message)}- label="Role ARN"- className="group"- >- <SecretInput- containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"- value={value}- onChange={(e) => onChange(e.target.value)}- />- </FormControl>- )}- />+ <>+ <Controller+ name="credentials.roleArn"+ control={control}+ shouldUnregister+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ errorText={error?.message}+ isError={Boolean(error?.message)}+ label="Role ARN"+ className="group"+ >+ <SecretInput+ containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"+ value={value}+ onChange={(e) => onChange(e.target.value)}+ />+ </FormControl>+ )}+ />+ <Controller+ name="credentials.stsEndpoint"+ control={control}+ shouldUnregister+ render={({ field: { value, onChange }, fieldState: { error } }) => (+ <FormControl+ errorText={error?.message}+ isError={Boolean(error?.message)}+ label="STS Endpoint URL"+ isOptional+ tooltipText="Override the default AWS STS endpoint Infisical calls to assume the role. Useful for VPC (PrivateLink), GovCloud, China, FIPS, or region-pinned endpoints. Leave blank to use the default AWS STS endpoint."+ >+ <Input+ placeholder="https://sts.amazonaws.com"+ value={value || ""}+ onChange={(e) => onChange(e.target.value)}+ />+ </FormControl>+ )}+ />+ </>) : (<><Controller