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
add notification to indicate stack is not ready
Matheus Nogueira4e0900f0604a
diff --git a/backend/src/ee/routes/v1/honey-token-router.ts b/backend/src/ee/routes/v1/honey-token-router.tsindex 968b03e01e..ec73951a73 100644--- a/backend/src/ee/routes/v1/honey-token-router.ts+++ b/backend/src/ee/routes/v1/honey-token-router.ts@@ -48,13 +48,17 @@ export const registerHoneyTokenRouter = async (server: FastifyZodProvider) => {secretsMapping: z.unknown(),createdAt: z.date(),updatedAt: z.date()+ }),+ stackDeployment: z.object({+ deployed: z.boolean(),+ status: z.string().nullable()})})}},handler: async (req) => {- const { honeyToken } = await server.services.honeyTokenCrud.create(req.body, req.permission);- return { honeyToken };+ const { honeyToken, stackDeployment } = await server.services.honeyTokenCrud.create(req.body, req.permission);+ return { honeyToken, stackDeployment };}});diff --git a/backend/src/ee/services/honey-token/honey-token-service.ts b/backend/src/ee/services/honey-token/honey-token-service.tsindex 84c2428c38..8adef11a1d 100644--- a/backend/src/ee/services/honey-token/honey-token-service.ts+++ b/backend/src/ee/services/honey-token/honey-token-service.ts@@ -1,12 +1,7 @@import crypto from "node:crypto";-import {- CreateAccessKeyCommand,- CreateUserCommand,- DeleteAccessKeyCommand,- DeleteUserCommand,- IAMClient-} from "@aws-sdk/client-iam";+import { CloudFormationClient, DescribeStacksCommand } from "@aws-sdk/client-cloudformation";+import { CreateAccessKeyCommand, CreateUserCommand, DeleteAccessKeyCommand, DeleteUserCommand, IAMClient } from "@aws-sdk/client-iam";import { ForbiddenError } from "@casl/ability";import { ActionProjectType, SecretType, TableName } from "@app/db/schemas";@@ -14,6 +9,7 @@ import { TLicenseServiceFactory } from "@app/ee/services/license/license-serviceimport { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";import { ProjectPermissionSecretActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";import { BadRequestError, NotFoundError } from "@app/lib/errors";+import { logger } from "@app/lib/logger";import { OrderByDirection, 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";@@ -38,8 +34,10 @@ import { THoneyTokenConfigDALFactory } from "./honey-token-config-dal";import { THoneyTokenDALFactory } from "./honey-token-dal";import { HoneyTokenStatus, HoneyTokenType } from "./honey-token-enums";import { THoneyTokenEventDALFactory } from "./honey-token-event-dal";+import { AwsHoneyTokenConfigSchema } from "./honey-token-types";const HONEY_TOKEN_IAM_USER_PREFIX = "inf_ht_";+const CF_COMPLETE_STATUSES = new Set(["CREATE_COMPLETE", "UPDATE_COMPLETE", "IMPORT_COMPLETE"]);type THoneyTokenServiceFactoryDep = {honeyTokenDAL: THoneyTokenDALFactory;@@ -88,6 +86,43 @@ export const honeyTokenServiceFactory = ({snapshotService,secretQueueService}: THoneyTokenServiceFactoryDep) => {+ const verifyStackDeployment = async ({+ connectionId,+ stackName+ }: {+ connectionId: string;+ stackName: string;+ }): Promise<{ deployed: boolean; status: string | null }> => {+ try {+ const appConnection = await appConnectionDAL.findById(connectionId);+ 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 CloudFormationClient({ credentials: awsCredentials, region: "us-east-1" });+ const res = await cfn.send(new DescribeStacksCommand({ StackName: stackName }));+ const stack = res.Stacks?.[0];++ if (!stack) return { deployed: false, status: null };++ return {+ deployed: CF_COMPLETE_STATUSES.has(stack.StackStatus ?? ""),+ status: stack.StackStatus ?? null+ };+ } catch (err) {+ const awsCode = (err as { code?: string }).code;++ if (awsCode === "ValidationError") {+ return { deployed: false, status: null };+ }++ logger.warn({ err, connectionId, stackName }, "Failed to verify honey token CloudFormation stack deployment");+ return { deployed: false, status: null };+ }+ };+const create = async ({projectId,@@ -147,6 +182,16 @@ export const honeyTokenServiceFactory = ({});}+ const { decryptor: configDecryptor } = await kmsService.createCipherPairWithDataKey({+ type: KmsDataKey.Organization,+ orgId: actor.orgId+ });+ const stackName = orgConfig.encryptedConfig+ ? AwsHoneyTokenConfigSchema.parse(+ JSON.parse(configDecryptor({ cipherTextBlob: orgConfig.encryptedConfig }).toString()) as unknown+ ).stackName+ : "infisical-honey-tokens";+const folder = await folderDAL.findBySecretPath(projectId, environment, secretPath);if (!folder) {@@ -283,6 +328,11 @@ export const honeyTokenServiceFactory = ({excludeReplication: true});+ const stackDeployment = await verifyStackDeployment({+ connectionId: orgConfig.connectionId,+ stackName+ });+return {honeyToken: {id: honeyToken.id,@@ -294,7 +344,8 @@ export const honeyTokenServiceFactory = ({secretsMapping: honeyToken.secretsMapping,createdAt: honeyToken.createdAt,updatedAt: honeyToken.updatedAt- }+ },+ stackDeployment};};diff --git a/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx b/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsxindex fc133baf2d..cead681301 100644--- a/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx+++ b/frontend/src/components/honey-tokens/forms/HoneyTokenForm.tsx@@ -2,10 +2,12 @@ import { useState } from "react";import { FormProvider, useForm } from "react-hook-form";import { Tab } from "@headlessui/react";import { zodResolver } from "@hookform/resolvers/zod";+import { Link } from "@tanstack/react-router";import { createNotification } from "@app/components/notifications";+import { ROUTE_PATHS } from "@app/const/routes";+import { useOrganization, useProject } from "@app/context";import { Button } from "@app/components/v3";-import { useProject } from "@app/context";import { HONEY_TOKEN_DEFAULT_SECRET_NAMES, HONEY_TOKEN_MAP } from "@app/helpers/honeyTokens";import { useCreateHoneyToken, useUpdateHoneyToken } from "@app/hooks/api/honeyTokens";import { HoneyTokenType } from "@app/hooks/api/honeyTokens/enums";@@ -50,6 +52,7 @@ export const HoneyTokenForm = ({const createHoneyToken = useCreateHoneyToken();const updateHoneyToken = useUpdateHoneyToken();const { currentProject } = useProject();+ const { currentOrg } = useOrganization();const { name: tokenTypeName } = HONEY_TOKEN_MAP[type];const isUpdate = Boolean(honeyToken);@@ -85,18 +88,43 @@ export const HoneyTokenForm = ({description: formData.description,secretsMapping: formData.secretsMapping});++ createNotification({+ text: `Successfully updated ${tokenTypeName} Honey Token`,+ type: "success"+ });} else {- await createHoneyToken.mutateAsync({+ const { stackDeployment } = await createHoneyToken.mutateAsync({...formData,environment: environment.slug,projectId: currentProject.id});- }- createNotification({- text: `Successfully ${honeyToken ? "updated" : "created"} ${tokenTypeName} Honey Token`,- type: "success"- });+ if (!stackDeployment.deployed) {+ const isDeploying = stackDeployment.status?.endsWith("_IN_PROGRESS");+ createNotification({+ text: isDeploying+ ? "Token was created, but stack is still deploying."+ : "Token was created, but stack is not deployed yet.",+ callToAction: (+ <Link+ className="inline-flex h-7 items-center rounded border border-mineshaft-500 px-2 text-xs text-primary transition-colors hover:bg-mineshaft-700 hover:text-primary"+ to={ROUTE_PATHS.Organization.SettingsPage.path}+ params={{ orgId: currentOrg.id }}+ search={{ selectedTab: "product-settings" }}+ >+ Go to settings+ </Link>+ ),+ type: "warning"+ });+ } else {+ createNotification({+ text: `Successfully created ${tokenTypeName} Honey Token`,+ type: "success"+ });+ }+ }onComplete();};diff --git a/frontend/src/hooks/api/honeyTokens/mutations.tsx b/frontend/src/hooks/api/honeyTokens/mutations.tsxindex b03581b42a..09c529289d 100644--- a/frontend/src/hooks/api/honeyTokens/mutations.tsx+++ b/frontend/src/hooks/api/honeyTokens/mutations.tsx@@ -6,6 +6,7 @@ import { dashboardKeys } from "@app/hooks/api/dashboard/queries";import {TCreateHoneyTokenDTO,THoneyToken,+ TCreateHoneyTokenResponse,TRevokeHoneyTokenDTO,TUpdateHoneyTokenDTO} from "./types";@@ -13,9 +14,9 @@ import {export const useCreateHoneyToken = () => {const queryClient = useQueryClient();- return useMutation<THoneyToken, object, TCreateHoneyTokenDTO>({+ return useMutation<TCreateHoneyTokenResponse, object, TCreateHoneyTokenDTO>({mutationFn: async (dto) => {- const { data } = await apiRequest.post<THoneyToken>("/api/v1/honey-tokens", dto);+ const { data } = await apiRequest.post<TCreateHoneyTokenResponse>("/api/v1/honey-tokens", dto);return data;},onSuccess: () => {diff --git a/frontend/src/hooks/api/honeyTokens/types.ts b/frontend/src/hooks/api/honeyTokens/types.tsindex 340eb74d69..47c5c78c0f 100644--- a/frontend/src/hooks/api/honeyTokens/types.ts+++ b/frontend/src/hooks/api/honeyTokens/types.ts@@ -2,6 +2,7 @@ export type {TAwsHoneyToken,TAwsHoneyTokenCredentialsResponse,TAwsHoneyTokenOption,+ TCreateHoneyTokenResponse,TCreateHoneyTokenDTO,TDashboardAwsHoneyToken,TDashboardHoneyToken,diff --git a/frontend/src/hooks/api/honeyTokens/types/index.ts b/frontend/src/hooks/api/honeyTokens/types/index.tsindex 13a89231e9..0898ffe318 100644--- a/frontend/src/hooks/api/honeyTokens/types/index.ts+++ b/frontend/src/hooks/api/honeyTokens/types/index.ts@@ -33,6 +33,14 @@ export type TCreateHoneyTokenDTO = {secretPath: string;};+export type TCreateHoneyTokenResponse = {+ honeyToken: THoneyToken;+ stackDeployment: {+ deployed: boolean;+ status: string | null;+ };+};+export type TUpdateHoneyTokenDTO = {honeyTokenId: string;projectId: string;