Skip to content

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

validate stack

Matheus Nogueira1b3fced35429
diff --git a/backend/src/ee/routes/v1/honey-token-router.ts b/backend/src/ee/routes/v1/honey-token-router.ts
index 158a0bd233..9bd531a57a 100644
--- a/backend/src/ee/routes/v1/honey-token-router.ts
+++ b/backend/src/ee/routes/v1/honey-token-router.ts
@@ -364,7 +364,7 @@ export const registerHoneyTokenRouter = async (server: FastifyZodProvider) => {
connectionId: z.string().nullable(),
createdAt: z.date().nullable(),
updatedAt: z.date().nullable(),
- decryptedConfig: z.object({ webhookSigningKey: z.string() }).nullable()
+ decryptedConfig: z.object({ webhookSigningKey: z.string(), stackName: z.string() }).nullable()
})
})
}
diff --git a/backend/src/ee/services/honey-token/honey-token-config-service.ts b/backend/src/ee/services/honey-token/honey-token-config-service.ts
index 15641465ab..80101271eb 100644
--- a/backend/src/ee/services/honey-token/honey-token-config-service.ts
+++ b/backend/src/ee/services/honey-token/honey-token-config-service.ts
@@ -1,6 +1,7 @@
import crypto from "node:crypto";
import { ForbiddenError } from "@casl/ability";
+import CloudFormation from "aws-sdk/clients/cloudformation.js";
import { OrganizationActionScope, OrgMembershipRole } from "@app/db/schemas";
import { getConfig as getAppConfig } from "@app/lib/config/env";
@@ -8,6 +9,10 @@ import { BadRequestError, NotFoundError, UnauthorizedError } from "@app/lib/erro
import { removeTrailingSlash } from "@app/lib/fn";
import { logger } from "@app/lib/logger";
import { OrgServiceActor } from "@app/lib/types";
+import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
+import { decryptAppConnection } from "@app/services/app-connection/app-connection-fns";
+import { getAwsConnectionConfig } from "@app/services/app-connection/aws";
+import { TAwsConnectionConfig } from "@app/services/app-connection/aws/aws-connection-types";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { KmsDataKey } from "@app/services/kms/kms-types";
import { TOrgDALFactory } from "@app/services/org/org-dal";
@@ -36,6 +41,7 @@ type THoneyTokenConfigServiceFactoryDep = {
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
+ appConnectionDAL: Pick<TAppConnectionDALFactory, "findById">;
orgDAL: Pick<TOrgDALFactory, "findOrgMembersByRole">;
projectDAL: Pick<TProjectDALFactory, "findById">;
smtpService: Pick<TSmtpService, "sendMail">;
@@ -43,6 +49,12 @@ type THoneyTokenConfigServiceFactoryDep = {
export type THoneyTokenConfigServiceFactory = ReturnType<typeof honeyTokenConfigServiceFactory>;
+const CF_COMPLETE_STATUSES = new Set([
+ "CREATE_COMPLETE",
+ "UPDATE_COMPLETE",
+ "IMPORT_COMPLETE"
+]);
+
export const honeyTokenConfigServiceFactory = ({
honeyTokenConfigDAL,
honeyTokenDAL,
@@ -50,6 +62,7 @@ export const honeyTokenConfigServiceFactory = ({
permissionService,
kmsService,
licenseService,
+ appConnectionDAL,
orgDAL,
projectDAL,
smtpService
@@ -63,7 +76,7 @@ export const honeyTokenConfigServiceFactory = ({
orgPermission: OrgServiceActor;
type: HoneyTokenType;
connectionId: string;
- config: { webhookSigningKey: string };
+ config: { webhookSigningKey: string; stackName?: string };
}) => {
const { permission } = await permissionService.getOrgPermission({
scope: OrganizationActionScope.Any,
@@ -85,6 +98,19 @@ export const honeyTokenConfigServiceFactory = ({
const validatedConfig = AwsHoneyTokenConfigSchema.parse(config);
+ const stackDeployment = await verifyStackDeployment({
+ connectionId,
+ stackName: validatedConfig.stackName
+ });
+
+ if (!stackDeployment.deployed) {
+ throw new BadRequestError({
+ message: stackDeployment.status
+ ? `CloudFormation stack "${validatedConfig.stackName}" is not ready (status: ${stackDeployment.status}). Wait for it to complete or fix the issue before saving.`
+ : `CloudFormation stack "${validatedConfig.stackName}" was not found. Deploy the stack before saving.`
+ });
+ }
+
const { encryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.Organization,
orgId: orgPermission.orgId
@@ -100,21 +126,18 @@ export const honeyTokenConfigServiceFactory = ({
});
if (existing) {
- const updated = await honeyTokenConfigDAL.updateById(existing.id, {
+ return honeyTokenConfigDAL.updateById(existing.id, {
connectionId,
encryptedConfig
});
- return updated;
}
- const created = await honeyTokenConfigDAL.create({
+ return honeyTokenConfigDAL.create({
orgId: orgPermission.orgId,
type,
connectionId,
encryptedConfig
});
-
- return created;
};
const getConfig = async ({ orgPermission, type }: { orgPermission: OrgServiceActor; type: HoneyTokenType }) => {
@@ -143,7 +166,7 @@ export const honeyTokenConfigServiceFactory = ({
connectionId: null,
createdAt: null,
updatedAt: null,
- decryptedConfig: { webhookSigningKey: generatedKey }
+ decryptedConfig: { webhookSigningKey: generatedKey, stackName: "infisical-honey-tokens" }
};
}
@@ -152,7 +175,7 @@ export const honeyTokenConfigServiceFactory = ({
orgId: orgPermission.orgId
});
- let decryptedConfig: { webhookSigningKey: string } | null = null;
+ let decryptedConfig: { webhookSigningKey: string; stackName: string } | null = null;
if (config.encryptedConfig) {
const decrypted = decryptor({
cipherTextBlob: config.encryptedConfig
@@ -330,6 +353,58 @@ export const honeyTokenConfigServiceFactory = ({
return { acknowledged: true };
};
+ const verifyStackDeployment = async ({
+ connectionId: connId,
+ stackName
+ }: {
+ connectionId: string;
+ stackName: string;
+ }): Promise<{ deployed: boolean; status: string | null }> => {
+ try {
+ const appConnection = await appConnectionDAL.findById(connId);
+ if (!appConnection) {
+ return { deployed: false, status: null };
+ }
+
+ const decryptedConnection = await decryptAppConnection(appConnection, kmsService);
+ const awsConfig = decryptedConnection as unknown as TAwsConnectionConfig;
+ const { credentials: awsCredentials } = await getAwsConnectionConfig(awsConfig);
+
+ const cfn = new CloudFormation({ credentials: awsCredentials, region: "us-east-1" });
+ const res = await cfn.describeStacks({ StackName: stackName }).promise();
+
+ const stack = res.Stacks?.[0];
+ if (!stack) {
+ return { deployed: false, status: null };
+ }
+
+ return {
+ deployed: CF_COMPLETE_STATUSES.has(stack.StackStatus),
+ status: stack.StackStatus
+ };
+ } catch (err) {
+ const awsCode = (err as { code?: string }).code;
+
+ if (awsCode === "AccessDenied" || awsCode === "ExpiredToken" || awsCode === "InvalidClientTokenId") {
+ throw new BadRequestError({
+ message:
+ "The AWS App Connection does not have permission to describe CloudFormation stacks. " +
+ "Ensure the connection's IAM role or credentials include the cloudformation:DescribeStacks permission."
+ });
+ }
+
+ if (awsCode === "ValidationError") {
+ return { deployed: false, status: null };
+ }
+
+ logger.warn(
+ { err, connectionId: connId, stackName },
+ `Failed to verify CloudFormation stack [stackName=${stackName}]`
+ );
+ return { deployed: false, status: null };
+ }
+ };
+
return {
upsertConfig,
getConfig,
diff --git a/backend/src/ee/services/honey-token/honey-token-types.ts b/backend/src/ee/services/honey-token/honey-token-types.ts
index 938b6f6e36..7e2905bbeb 100644
--- a/backend/src/ee/services/honey-token/honey-token-types.ts
+++ b/backend/src/ee/services/honey-token/honey-token-types.ts
@@ -32,7 +32,8 @@ export type THoneyTokenEventMetadata = z.infer<typeof HoneyTokenEventMetadataSch
// --- Config schemas (typed shape for the encrypted config blob per provider) ---
export const AwsHoneyTokenConfigSchema = z.object({
- webhookSigningKey: z.string().min(1)
+ webhookSigningKey: z.string().min(1),
+ stackName: z.string().min(1).max(128).default("infisical-honey-tokens")
});
export type TAwsHoneyTokenConfig = z.infer<typeof AwsHoneyTokenConfigSchema>;
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index f980367007..8ae3823761 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -965,6 +965,7 @@ export const registerRoutes = async (
permissionService,
kmsService,
licenseService,
+ appConnectionDAL,
orgDAL,
projectDAL,
smtpService
diff --git a/frontend/src/hooks/api/honeyToken/types.ts b/frontend/src/hooks/api/honeyToken/types.ts
index 4ff8e463c5..bfa3c26468 100644
--- a/frontend/src/hooks/api/honeyToken/types.ts
+++ b/frontend/src/hooks/api/honeyToken/types.ts
@@ -11,6 +11,7 @@ export type THoneyTokenConfig = {
updatedAt: string | null;
decryptedConfig: {
webhookSigningKey: string;
+ stackName: string;
} | null;
};
@@ -19,5 +20,6 @@ export type TUpsertHoneyTokenConfigDTO = {
connectionId: string;
config: {
webhookSigningKey: string;
+ stackName?: string;
};
};
diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx
index f26091eb62..10c5f69228 100644
--- a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx
@@ -8,13 +8,18 @@ import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions";
import {
+ Accordion,
+ AccordionContent,
+ AccordionItem,
+ AccordionTrigger,
Button,
Field,
FieldContent,
FieldError,
FieldLabel,
FilterableSelect,
- IconButton
+ IconButton,
+ Input
} from "@app/components/v3";
import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context";
import { useTimedReset, useToggle } from "@app/hooks";
@@ -29,9 +34,12 @@ import {
const CF_TEMPLATE_URL =
"https://s3.amazonaws.com/infisical-honeytokens/cfn/aws-honey-token-v1.yaml";
+const DEFAULT_STACK_NAME = "infisical-honey-tokens";
+
const schema = z.object({
connectionId: z.string().min(1, "AWS Connection is required"),
- webhookSigningKey: z.string().min(1, "Webhook Signing Key is required")
+ webhookSigningKey: z.string().min(1, "Webhook Signing Key is required"),
+ stackName: z.string().trim().min(1, "Stack name is required").max(128)
});
type FormData = z.infer<typeof schema>;
@@ -62,7 +70,8 @@ export const HoneyTokenSection = () => {
resolver: zodResolver(schema),
defaultValues: {
connectionId: "",
- webhookSigningKey: ""
+ webhookSigningKey: "",
+ stackName: DEFAULT_STACK_NAME
}
});
@@ -71,25 +80,27 @@ export const HoneyTokenSection = () => {
reset({
connectionId: existingConfig.connectionId ?? "",
- webhookSigningKey: existingConfig.decryptedConfig.webhookSigningKey
+ webhookSigningKey: existingConfig.decryptedConfig.webhookSigningKey,
+ stackName: existingConfig.decryptedConfig.stackName ?? DEFAULT_STACK_NAME
});
}, [existingConfig, reset]);
const webhookSigningKey = watch("webhookSigningKey");
+ const stackName = watch("stackName");
const cfCommand = useMemo(
() =>
[
"aws cloudformation create-stack \\",
" --region us-east-1 \\",
- " --stack-name infisical-honey-tokens \\",
+ ` --stack-name ${stackName || DEFAULT_STACK_NAME} \\`,
` --template-url ${CF_TEMPLATE_URL} \\`,
" --capabilities CAPABILITY_NAMED_IAM \\",
" --parameters \\",
` ParameterKey=WebhookUrl,ParameterValue=${webhookUrl} \\`,
` ParameterKey=WebhookSigningKey,ParameterValue=${webhookSigningKey}`
].join("\n"),
- [webhookSigningKey, webhookUrl]
+ [stackName, webhookSigningKey, webhookUrl]
);
const onSubmit = async (data: FormData) => {
@@ -98,7 +109,8 @@ export const HoneyTokenSection = () => {
type: HoneyTokenType.AWS,
connectionId: data.connectionId,
config: {
- webhookSigningKey: data.webhookSigningKey
+ webhookSigningKey: data.webhookSigningKey,
+ stackName: data.stackName
}
});
createNotification({
@@ -192,6 +204,36 @@ export const HoneyTokenSection = () => {
</div>
</div>
+ <Accordion type="single" collapsible variant="ghost" className="mb-4">
+ <AccordionItem value="advanced">
+ <AccordionTrigger>Advanced Options</AccordionTrigger>
+ <AccordionContent>
+ <div className="flex gap-4">
+ <div className="flex-1">
+ <Controller
+ control={control}
+ name="stackName"
+ render={({ field, fieldState: { error } }) => (
+ <Field>
+ <FieldLabel>CloudFormation Stack Name</FieldLabel>
+ <FieldContent>
+ <Input
+ {...field}
+ placeholder={DEFAULT_STACK_NAME}
+ isError={Boolean(error)}
+ />
+ <FieldError errors={[error]} />
+ </FieldContent>
+ </Field>
+ )}
+ />
+ </div>
+ <div className="flex-1" />
+ </div>
+ </AccordionContent>
+ </AccordionItem>
+ </Accordion>
+
<div className="mb-4 rounded-md border border-mineshaft-600 bg-bunker-800 p-4">
<div className="mb-3 flex items-center gap-2 text-sm text-mineshaft-300">
<FontAwesomeIcon icon={faTerminal} className="text-mineshaft-400" />