Skip to content

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

fix(secret-syncs): accept KMS key IDs and ARNs in AWS sync KMS picker (#9057)

Andrew Huangbf6e6abd54aa
diff --git a/docs/integrations/secret-syncs/aws-parameter-store.mdx b/docs/integrations/secret-syncs/aws-parameter-store.mdx
index 2959db2aef..a02fc81de3 100644
--- a/docs/integrations/secret-syncs/aws-parameter-store.mdx
+++ b/docs/integrations/secret-syncs/aws-parameter-store.mdx
@@ -50,7 +50,7 @@ description: "Learn how to configure an AWS Parameter Store Sync for Infisical."
<Note>
We highly recommend using a Key Schema to ensure that Infisical only manages the specific keys you intend, keeping everything else untouched.
</Note>
- - **KMS Key**: The AWS KMS key ID or alias to encrypt parameters with.
+ - **KMS Key**: The AWS KMS key to encrypt parameters with, as an alias from the list or a key ID or key ARN you enter
- **Tags**: Optional resource tags to add to parameters synced by Infisical.
- **Sync Secret Metadata as Resource Tags**: If enabled, metadata attached to secrets will be added as resource tags to parameters synced by Infisical.
<Note>
diff --git a/docs/integrations/secret-syncs/aws-secrets-manager.mdx b/docs/integrations/secret-syncs/aws-secrets-manager.mdx
index 4cfbe7a9b7..369a2ebd8f 100644
--- a/docs/integrations/secret-syncs/aws-secrets-manager.mdx
+++ b/docs/integrations/secret-syncs/aws-secrets-manager.mdx
@@ -49,7 +49,7 @@ description: "Learn how to configure an AWS Secrets Manager Sync for Infisical."
<Note>
We highly recommend using a Key Schema to ensure that Infisical only manages the specific keys you intend, keeping everything else untouched.
</Note>
- - **KMS Key**: The AWS KMS key ID or alias to encrypt secrets with.
+ - **KMS Key**: The AWS KMS key to encrypt secrets with, as an alias from the list or a key ID or key ARN you enter (enter the key ARN if your IAM policy uses the `secretsmanager:KmsKeyId` condition key to require a specific key)
- **Tags**: Optional tags to add to secrets synced by Infisical.
- **Sync Secret Metadata as Tags**: If enabled, metadata attached to secrets will be added as tags to secrets synced by Infisical.
<Note>
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AwsParameterStoreSyncOptionsFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AwsParameterStoreSyncOptionsFields.tsx
index 31703c363f..06566336ee 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AwsParameterStoreSyncOptionsFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AwsParameterStoreSyncOptionsFields.tsx
@@ -26,6 +26,7 @@ import { useListAwsConnectionKmsKeys } from "@app/hooks/api/appConnections/aws";
import { SecretSync } from "@app/hooks/api/secretSyncs";
import { TSecretSyncForm } from "../schemas";
+import { isAwsKmsKeyIdentifier } from "./aws-kms-key";
const AwsTagsEditor = () => {
const { control } = useFormContext<
@@ -168,14 +169,23 @@ export const AwsParameterStoreSyncOptionsFields = () => {
<TooltipTrigger asChild>
<CircleHelp className="size-3 cursor-help text-muted" />
</TooltipTrigger>
- <TooltipContent>The AWS KMS key to encrypt parameters with.</TooltipContent>
+ <TooltipContent>
+ The AWS KMS key to encrypt parameters with: an alias, key ID, or ARN.
+ </TooltipContent>
</Tooltip>
</FieldLabel>
<FieldContent>
<Combobox
isLoading={isKmsKeysPending && Boolean(connectionId && region)}
isDisabled={!connectionId}
- value={kmsKeys.find((org) => org.alias === value) ?? null}
+ value={
+ value
+ ? (kmsKeys.find((kmsKey) => kmsKey.alias === value) ?? {
+ alias: value,
+ id: value
+ })
+ : null
+ }
onValueChange={(option) => onChange(option.alias ?? null)}
onClear={() => onChange(undefined)}
clearAriaLabel="Clear KMS key"
@@ -184,6 +194,12 @@ export const AwsParameterStoreSyncOptionsFields = () => {
inputValue ? "No KMS keys match your search." : "No KMS keys found."
}
options={kmsKeys}
+ creation={{
+ onCreate: (inputValue) => onChange(inputValue.trim()),
+ formatLabel: (inputValue) => `Use "${inputValue}"`,
+ isDuplicate: (inputValue, option) => option.alias === inputValue,
+ isValid: isAwsKmsKeyIdentifier
+ }}
placeholder="Leave blank to use default KMS key"
searchPlaceholder="Search KMS keys..."
searchAriaLabel="Search KMS keys"
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AwsSecretsManagerSyncOptionsFields.tsx b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AwsSecretsManagerSyncOptionsFields.tsx
index 876f39a957..8099a040e6 100644
--- a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AwsSecretsManagerSyncOptionsFields.tsx
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/AwsSecretsManagerSyncOptionsFields.tsx
@@ -28,6 +28,7 @@ import { SecretSync } from "@app/hooks/api/secretSyncs";
import { AwsSecretsManagerSyncMappingBehavior } from "@app/hooks/api/secretSyncs/types/aws-secrets-manager-sync";
import { TSecretSyncForm } from "../schemas";
+import { isAwsKmsKeyIdentifier } from "./aws-kms-key";
const AwsTagsEditor = () => {
const { control } = useFormContext<
@@ -175,8 +176,8 @@ export const AwsSecretsManagerSyncOptionsFields = () => {
<CircleHelp className="size-3 cursor-help text-muted" />
</TooltipTrigger>
<TooltipContent className="max-w-sm">
- The AWS KMS key to encrypt secrets with. Custom keys require{" "}
- <Code>kms:ListAliases</Code>, <Code>kms:DescribeKey</Code>,{" "}
+ The AWS KMS key to encrypt secrets with: an alias, key ID, or ARN. Custom keys
+ require <Code>kms:ListAliases</Code>, <Code>kms:DescribeKey</Code>,{" "}
<Code>kms:Encrypt</Code>, and <Code>kms:Decrypt</Code> on the selected IAM
role.
</TooltipContent>
@@ -186,7 +187,14 @@ export const AwsSecretsManagerSyncOptionsFields = () => {
<Combobox
isLoading={isKmsKeysPending && Boolean(connectionId && region)}
isDisabled={!connectionId}
- value={kmsKeys.find((org) => org.alias === value) ?? null}
+ value={
+ value
+ ? (kmsKeys.find((kmsKey) => kmsKey.alias === value) ?? {
+ alias: value,
+ id: value
+ })
+ : null
+ }
onValueChange={(option) => onChange(option.alias ?? null)}
onClear={() => onChange(undefined)}
clearAriaLabel="Clear KMS key"
@@ -195,6 +203,12 @@ export const AwsSecretsManagerSyncOptionsFields = () => {
inputValue ? "No KMS keys match your search." : "No KMS keys found."
}
options={kmsKeys}
+ creation={{
+ onCreate: (inputValue) => onChange(inputValue.trim()),
+ formatLabel: (inputValue) => `Use "${inputValue}"`,
+ isDuplicate: (inputValue, option) => option.alias === inputValue,
+ isValid: isAwsKmsKeyIdentifier
+ }}
placeholder="Leave blank to use default KMS key"
searchPlaceholder="Search KMS keys..."
searchAriaLabel="Search KMS keys"
diff --git a/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/aws-kms-key.ts b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/aws-kms-key.ts
new file mode 100644
index 0000000000..e1394a7fb1
--- /dev/null
+++ b/frontend/src/components/secret-syncs/forms/SecretSyncOptionsFields/aws-kms-key.ts
@@ -0,0 +1,9 @@
+const KMS_KEY_ID =
+ "(?:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|mrk-[0-9a-f]{32})";
+const KMS_ALIAS = "alias/[a-zA-Z0-9/_-]+";
+
+const AWS_KMS_KEY_IDENTIFIER_REGEX = new RegExp(
+ `^(?:${KMS_KEY_ID}|${KMS_ALIAS}|arn:aws[a-z-]*:kms:[a-z0-9-]+:\\d{12}:(?:key/${KMS_KEY_ID}|${KMS_ALIAS}))$`
+);
+
+export const isAwsKmsKeyIdentifier = (value: string) => AWS_KMS_KEY_IDENTIFIER_REGEX.test(value);
diff --git a/frontend/src/components/secret-syncs/forms/schemas/aws-parameter-store-sync-destination-schema.ts b/frontend/src/components/secret-syncs/forms/schemas/aws-parameter-store-sync-destination-schema.ts
index 21b84f005a..30fc11f357 100644
--- a/frontend/src/components/secret-syncs/forms/schemas/aws-parameter-store-sync-destination-schema.ts
+++ b/frontend/src/components/secret-syncs/forms/schemas/aws-parameter-store-sync-destination-schema.ts
@@ -5,7 +5,11 @@ import { SecretSync } from "@app/hooks/api/secretSyncs/enums";
export const AwsParameterStoreSyncDestinationSchema = BaseSecretSyncSchema(
z.object({
- keyId: z.string().optional(),
+ keyId: z
+ .string()
+ .max(256, "KMS key must be 256 characters or fewer")
+ .regex(/^[a-zA-Z0-9:/_-]+$/, "KMS key can only contain letters, numbers, and : / _ -")
+ .optional(),
tags: z
.object({
key: z
diff --git a/frontend/src/components/secret-syncs/forms/schemas/aws-secrets-manager-sync-destination-schema.ts b/frontend/src/components/secret-syncs/forms/schemas/aws-secrets-manager-sync-destination-schema.ts
index 2c972986d2..16ed464f36 100644
--- a/frontend/src/components/secret-syncs/forms/schemas/aws-secrets-manager-sync-destination-schema.ts
+++ b/frontend/src/components/secret-syncs/forms/schemas/aws-secrets-manager-sync-destination-schema.ts
@@ -6,7 +6,11 @@ import { AwsSecretsManagerSyncMappingBehavior } from "@app/hooks/api/secretSyncs
export const AwsSecretsManagerSyncDestinationSchema = BaseSecretSyncSchema(
z.object({
- keyId: z.string().optional(),
+ keyId: z
+ .string()
+ .max(256, "KMS key must be 256 characters or fewer")
+ .regex(/^[a-zA-Z0-9:/_-]+$/, "KMS key can only contain letters, numbers, and : / _ -")
+ .optional(),
tags: z
.object({
key: z