Skip to content

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

improvement: add support for more regions when chooseing the user based replication policy

adilson5c82e5c38f77
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index f06b332844..45a526c229 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -3194,7 +3194,9 @@ export const SecretSyncs = {
GCP: {
scope: "The Google project scope that secrets should be synced to.",
projectId: "The ID of the Google project secrets should be synced to.",
- locationId: 'The ID of the Google project location secrets should be synced to (ie "us-west4").'
+ locationId: 'The ID of the Google project location secrets should be synced to (ie "us-west4").',
+ userReplicaLocationIds:
+ 'The Google project locations to replicate secrets to under user-managed replication (global scope, ie ["us-west4"]).'
},
DATABRICKS: {
scope: "The Databricks secret scope that secrets should be synced to."
diff --git a/backend/src/services/secret-sync/gcp/gcp-sync-fns.ts b/backend/src/services/secret-sync/gcp/gcp-sync-fns.ts
index 9fc901c341..98afb00d35 100644
--- a/backend/src/services/secret-sync/gcp/gcp-sync-fns.ts
+++ b/backend/src/services/secret-sync/gcp/gcp-sync-fns.ts
@@ -16,9 +16,12 @@ import {
TGcpSyncWithCredentials
} from "./gcp-sync-types";
-const getGlobalReplication = (locationId?: string) => {
- if (locationId) {
- return { userManaged: { replicas: [{ location: locationId }] } };
+const getGlobalReplication = (userReplicaLocationIds?: string[], locationId?: string) => {
+ // eslint-disable-next-line no-nested-ternary
+ const locations = userReplicaLocationIds?.length ? userReplicaLocationIds : locationId ? [locationId] : [];
+
+ if (locations.length) {
+ return { userManaged: { replicas: locations.map((location) => ({ location })) } };
}
return { automatic: {} };
};
@@ -130,7 +133,7 @@ export const GcpSyncFns = {
{
replication:
destinationConfig.scope === GcpSyncScope.Global
- ? getGlobalReplication(destinationConfig.locationId)
+ ? getGlobalReplication(destinationConfig.userReplicaLocationIds, destinationConfig.locationId)
: undefined
},
{
diff --git a/backend/src/services/secret-sync/gcp/gcp-sync-schemas.ts b/backend/src/services/secret-sync/gcp/gcp-sync-schemas.ts
index 71e04dc7d7..68858c42a4 100644
--- a/backend/src/services/secret-sync/gcp/gcp-sync-schemas.ts
+++ b/backend/src/services/secret-sync/gcp/gcp-sync-schemas.ts
@@ -23,7 +23,13 @@ const GcpSyncDestinationConfigSchema = z.discriminatedUnion("scope", [
locationId: z
.nativeEnum(GCPSecretManagerLocation)
.optional()
- .describe(SecretSyncs.DESTINATION_CONFIG.GCP.locationId)
+ .describe(SecretSyncs.DESTINATION_CONFIG.GCP.locationId),
+ userReplicaLocationIds: z
+ .nativeEnum(GCPSecretManagerLocation)
+ .array()
+ .optional()
+ .default([])
+ .describe(SecretSyncs.DESTINATION_CONFIG.GCP.userReplicaLocationIds)
})
.describe(
JSON.stringify({
diff --git a/backend/src/services/secret-sync/secret-sync-maps.ts b/backend/src/services/secret-sync/secret-sync-maps.ts
index 6db9133daf..61f80b9621 100644
--- a/backend/src/services/secret-sync/secret-sync-maps.ts
+++ b/backend/src/services/secret-sync/secret-sync-maps.ts
@@ -159,7 +159,7 @@ export const SECRET_SYNC_SKIP_FIELDS_MAP: Record<SecretSync, string[]> = {
[SecretSync.AWSParameterStore]: [],
[SecretSync.AWSSecretsManager]: ["mappingBehavior"],
[SecretSync.GitHub]: [],
- [SecretSync.GCPSecretManager]: ["scope", "locationId"],
+ [SecretSync.GCPSecretManager]: ["scope", "locationId", "userReplicaLocationIds"],
[SecretSync.AzureKeyVault]: [],
[SecretSync.AzureAppConfiguration]: ["label"],
[SecretSync.AzureDevOps]: ["devopsProjectName"],
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GcpSyncFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GcpSyncFields.tsx
index 74bbbc054e..b0648a973b 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GcpSyncFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncDestinationFields/GcpSyncFields.tsx
@@ -1,6 +1,6 @@
import { useEffect } from "react";
import { Controller, useFormContext, useWatch } from "react-hook-form";
-import { SingleValue } from "react-select";
+import { MultiValue, SingleValue } from "react-select";
import { Info } from "lucide-react";
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
@@ -46,6 +46,11 @@ export const GcpSyncFields = () => {
const connectionId = useWatch({ name: "connection.id", control });
const projectId = useWatch({ name: "destinationConfig.projectId", control });
const selectedScope = useWatch({ name: "destinationConfig.scope", control });
+ const locationId = useWatch({ name: "destinationConfig.locationId", control });
+ const userReplicaLocationIds = useWatch({
+ name: "destinationConfig.userReplicaLocationIds",
+ control
+ });
const { data: projects, isPending } = useGcpConnectionListProjects(connectionId, {
enabled: Boolean(connectionId)
@@ -62,12 +67,21 @@ export const GcpSyncFields = () => {
if (!selectedScope) setValue("destinationConfig.scope", GcpSyncScope.Global);
}, []);
+ useEffect(() => {
+ if (selectedScope === GcpSyncScope.Global && locationId && !userReplicaLocationIds?.length) {
+ setValue("destinationConfig.userReplicaLocationIds", [locationId], {
+ shouldDirty: false
+ });
+ }
+ }, [selectedScope, locationId, userReplicaLocationIds, setValue]);
+
return (
<FieldGroup>
<SecretSyncConnectionField
onChange={() => {
setValue("destinationConfig.projectId", "");
setValue("destinationConfig.locationId", "");
+ setValue("destinationConfig.userReplicaLocationIds", []);
}}
/>
<Controller
@@ -95,6 +109,7 @@ export const GcpSyncFields = () => {
value={projects?.find((project) => project.id === value) ?? null}
onChange={(option) => {
setValue("destinationConfig.locationId", "");
+ setValue("destinationConfig.userReplicaLocationIds", []);
onChange((option as SingleValue<TGcpProject>)?.id ?? null);
}}
options={projects}
@@ -144,6 +159,7 @@ export const GcpSyncFields = () => {
onValueChange={(val) => {
onChange(val);
setValue("destinationConfig.locationId", "");
+ setValue("destinationConfig.userReplicaLocationIds", []);
}}
disabled={!projectId}
>
@@ -163,41 +179,64 @@ export const GcpSyncFields = () => {
</Field>
)}
/>
- {(selectedScope === GcpSyncScope.Region || selectedScope === GcpSyncScope.Global) && (
+ {selectedScope === GcpSyncScope.Region && (
<Controller
name="destinationConfig.locationId"
control={control}
render={({ field: { value, onChange }, fieldState: { error } }) => (
<Field>
- <FieldLabel>
- Region
- {selectedScope === GcpSyncScope.Global && (
- <Tooltip>
- <TooltipTrigger asChild>
- <Info />
- </TooltipTrigger>
- <TooltipContent className="max-w-md">
- Optionally specify a region for user-managed replication. If not set,
- automatic replication will be used.
- </TooltipContent>
- </Tooltip>
- )}
- </FieldLabel>
+ <FieldLabel>Region</FieldLabel>
<FieldContent>
<FilterableSelect
isLoading={areLocationsPending && Boolean(projectId)}
isDisabled={!projectId}
- isClearable={selectedScope === GcpSyncScope.Global}
value={locations?.find((option) => option.locationId === value) ?? null}
onChange={(option) =>
onChange((option as SingleValue<TGcpLocation>)?.locationId ?? "")
}
options={locations}
- placeholder={
- selectedScope === GcpSyncScope.Global
- ? "Automatic replication"
- : "Select a region..."
+ placeholder="Select a region..."
+ getOptionValue={(option) => option.locationId}
+ formatOptionLabel={formatOptionLabel}
+ />
+ <FieldError errors={[error]} />
+ </FieldContent>
+ </Field>
+ )}
+ />
+ )}
+ {selectedScope === GcpSyncScope.Global && (
+ <Controller
+ name="destinationConfig.userReplicaLocationIds"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>
+ Replica Regions
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Info />
+ </TooltipTrigger>
+ <TooltipContent className="max-w-md">
+ Optionally specify one or more regions for user-managed replication. If none are
+ set, automatic replication will be used.
+ </TooltipContent>
+ </Tooltip>
+ </FieldLabel>
+ <FieldContent>
+ <FilterableSelect
+ isMulti
+ isLoading={areLocationsPending && Boolean(projectId)}
+ isDisabled={!projectId}
+ isClearable
+ value={
+ locations?.filter((option) => (value || []).includes(option.locationId)) ?? []
}
+ onChange={(option) =>
+ onChange((option as MultiValue<TGcpLocation>).map((o) => o.locationId))
+ }
+ options={locations}
+ placeholder="Automatic replication"
getOptionValue={(option) => option.locationId}
formatOptionLabel={formatOptionLabel}
/>
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/GcpSyncReviewFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/GcpSyncReviewFields.tsx
index 0ea76d671a..d848f95846 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/GcpSyncReviewFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncReviewFields/GcpSyncReviewFields.tsx
@@ -21,13 +21,19 @@ export const GcpSyncReviewFields = () => {
<DetailLabel>Scope</DetailLabel>
<DetailValue className="capitalize">{destinationConfig.scope}</DetailValue>
</Detail>
- {(destinationConfig.scope === GcpSyncScope.Region ||
- (destinationConfig.scope === GcpSyncScope.Global && destinationConfig.locationId)) && (
+ {destinationConfig.scope === GcpSyncScope.Region && (
<Detail>
<DetailLabel>Region</DetailLabel>
<DetailValue>{destinationConfig.locationId}</DetailValue>
</Detail>
)}
+ {destinationConfig.scope === GcpSyncScope.Global &&
+ Boolean(destinationConfig.userReplicaLocationIds?.length) && (
+ <Detail>
+ <DetailLabel>Replica Regions</DetailLabel>
+ <DetailValue>{destinationConfig.userReplicaLocationIds?.join(", ")}</DetailValue>
+ </Detail>
+ )}
</>
);
};
diff --git a/frontend/src/components/secret-syncs/forms/schemas/gcp-sync-destination-schema.ts b/frontend/src/components/secret-syncs/forms/schemas/gcp-sync-destination-schema.ts
index 6d1a73384c..cebcda9df6 100644
--- a/frontend/src/components/secret-syncs/forms/schemas/gcp-sync-destination-schema.ts
+++ b/frontend/src/components/secret-syncs/forms/schemas/gcp-sync-destination-schema.ts
@@ -11,10 +11,8 @@ export const GcpSyncDestinationSchema = BaseSecretSyncSchema().merge(
z.object({
scope: z.literal(GcpSyncScope.Global),
projectId: z.string().min(1, "Project ID required"),
- locationId: z
- .string()
- .optional()
- .transform((val) => val || undefined)
+ locationId: z.string().optional(),
+ userReplicaLocationIds: z.string().array().optional().default([])
}),
z.object({
scope: z.literal(GcpSyncScope.Region),
diff --git a/frontend/src/hooks/api/secretSyncs/types/gcp-sync.ts b/frontend/src/hooks/api/secretSyncs/types/gcp-sync.ts
index 178f7e0b39..928c7a2c8b 100644
--- a/frontend/src/hooks/api/secretSyncs/types/gcp-sync.ts
+++ b/frontend/src/hooks/api/secretSyncs/types/gcp-sync.ts
@@ -14,6 +14,7 @@ export type TGcpSync = TRootSecretSync & {
scope: GcpSyncScope.Global;
projectId: string;
locationId?: string;
+ userReplicaLocationIds?: string[];
}
| {
scope: GcpSyncScope.Region;
diff --git a/frontend/src/pages/secret-manager/IntegrationsListPage/components/SecretSyncsTab/SecretSyncTable/helpers/index.ts b/frontend/src/pages/secret-manager/IntegrationsListPage/components/SecretSyncsTab/SecretSyncTable/helpers/index.ts
index 8fec85b6f0..2a31553ca6 100644
--- a/frontend/src/pages/secret-manager/IntegrationsListPage/components/SecretSyncsTab/SecretSyncTable/helpers/index.ts
+++ b/frontend/src/pages/secret-manager/IntegrationsListPage/components/SecretSyncsTab/SecretSyncTable/helpers/index.ts
@@ -54,8 +54,8 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
case SecretSync.GCPSecretManager:
primaryText = destinationConfig.projectId;
if (destinationConfig.scope === GcpSyncScope.Global) {
- secondaryText = destinationConfig.locationId
- ? `Global - ${destinationConfig.locationId}`
+ secondaryText = destinationConfig.userReplicaLocationIds?.length
+ ? `Global - ${destinationConfig.userReplicaLocationIds.join(", ")}`
: "Global";
} else {
secondaryText = destinationConfig.locationId;
diff --git a/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncDestinationSection/GcpSyncDestinationSection.tsx b/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncDestinationSection/GcpSyncDestinationSection.tsx
index fe8876ff9e..a16eb7a004 100644
--- a/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncDestinationSection/GcpSyncDestinationSection.tsx
+++ b/frontend/src/pages/secret-manager/SecretSyncDetailsByIDPage/components/SecretSyncDestinationSection/GcpSyncDestinationSection.tsx
@@ -18,13 +18,19 @@ export const GcpSyncDestinationSection = ({ secretSync }: Props) => {
<DetailLabel>Scope</DetailLabel>
<DetailValue>{destinationConfig.scope}</DetailValue>
</Detail>
- {(destinationConfig.scope === GcpSyncScope.Region ||
- (destinationConfig.scope === GcpSyncScope.Global && destinationConfig.locationId)) && (
+ {destinationConfig.scope === GcpSyncScope.Region && (
<Detail>
<DetailLabel>Region</DetailLabel>
<DetailValue>{destinationConfig.locationId}</DetailValue>
</Detail>
)}
+ {destinationConfig.scope === GcpSyncScope.Global &&
+ Boolean(destinationConfig.userReplicaLocationIds?.length) && (
+ <Detail>
+ <DetailLabel>Replica Regions</DetailLabel>
+ <DetailValue>{destinationConfig.userReplicaLocationIds?.join(", ")}</DetailValue>
+ </Detail>
+ )}
</>
);
};