Skip to content

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

save org settings for aws honey tokens

Matheus Nogueiraac79af6b781b
diff --git a/backend/src/@types/fastify.d.ts b/backend/src/@types/fastify.d.ts
index 81a5972858..44985e17f5 100644
--- a/backend/src/@types/fastify.d.ts
+++ b/backend/src/@types/fastify.d.ts
@@ -23,6 +23,7 @@ import { TGatewayPoolServiceFactory } from "@app/ee/services/gateway-pool/gatewa
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
import { TGithubOrgSyncServiceFactory } from "@app/ee/services/github-org-sync/github-org-sync-service";
import { TGroupServiceFactory } from "@app/ee/services/group/group-service";
+import { THoneyTokenConfigServiceFactory } from "@app/ee/services/honey-token/honey-token-config-service";
import { TIdentityAuthTemplateServiceFactory } from "@app/ee/services/identity-auth-template";
import { TInsightsServiceFactory } from "@app/ee/services/insights/insights-service";
import { TKmipClientDALFactory } from "@app/ee/services/kmip/kmip-client-dal";
@@ -369,6 +370,7 @@ declare module "fastify" {
gatewayV2: TGatewayV2ServiceFactory;
gatewayPool: TGatewayPoolServiceFactory;
githubOrgSync: TGithubOrgSyncServiceFactory;
+ honeyToken: THoneyTokenConfigServiceFactory;
folderCommit: TFolderCommitServiceFactory;
pit: TPitServiceFactory;
secretScanningV2: TSecretScanningV2ServiceFactory;
diff --git a/backend/src/@types/knex.d.ts b/backend/src/@types/knex.d.ts
index 12fe095e2d..e6fb1621bd 100644
--- a/backend/src/@types/knex.d.ts
+++ b/backend/src/@types/knex.d.ts
@@ -188,6 +188,15 @@ import {
TGroups,
TGroupsInsert,
TGroupsUpdate,
+ THoneyTokenConfigs,
+ THoneyTokenConfigsInsert,
+ THoneyTokenConfigsUpdate,
+ THoneyTokenEvents,
+ THoneyTokenEventsInsert,
+ THoneyTokenEventsUpdate,
+ THoneyTokens,
+ THoneyTokensInsert,
+ THoneyTokensUpdate,
TIdentities,
TIdentitiesInsert,
TIdentitiesUpdate,
@@ -1503,6 +1512,21 @@ declare module "knex/types/tables" {
TGithubOrgSyncConfigsInsert,
TGithubOrgSyncConfigsUpdate
>;
+ [TableName.HoneyTokenConfig]: KnexOriginal.CompositeTableType<
+ THoneyTokenConfigs,
+ THoneyTokenConfigsInsert,
+ THoneyTokenConfigsUpdate
+ >;
+ [TableName.HoneyToken]: KnexOriginal.CompositeTableType<
+ THoneyTokens,
+ THoneyTokensInsert,
+ THoneyTokensUpdate
+ >;
+ [TableName.HoneyTokenEvent]: KnexOriginal.CompositeTableType<
+ THoneyTokenEvents,
+ THoneyTokenEventsInsert,
+ THoneyTokenEventsUpdate
+ >;
[TableName.FolderCommit]: KnexOriginal.CompositeTableType<
TFolderCommits,
TFolderCommitsInsert,
diff --git a/backend/src/ee/routes/v1/honey-token-router.ts b/backend/src/ee/routes/v1/honey-token-router.ts
new file mode 100644
index 0000000000..21bc2a20b0
--- /dev/null
+++ b/backend/src/ee/routes/v1/honey-token-router.ts
@@ -0,0 +1,83 @@
+import { z } from "zod";
+
+import { HoneyTokenConfigsSchema } from "@app/db/schemas";
+import { HoneyTokenType } from "@app/ee/services/honey-token/honey-token-enums";
+import { AwsHoneyTokenConfigSchema } from "@app/ee/services/honey-token/honey-token-types";
+import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
+import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
+import { AuthMode } from "@app/services/auth/auth-type";
+
+const SanitizedHoneyTokenConfigSchema = HoneyTokenConfigsSchema.pick({
+ id: true,
+ orgId: true,
+ type: true,
+ connectionId: true,
+ createdAt: true,
+ updatedAt: true
+});
+
+export const registerHoneyTokenRouter = async (server: FastifyZodProvider) => {
+ server.route({
+ url: "/configs",
+ method: "PUT",
+ config: {
+ rateLimit: writeLimit
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ schema: {
+ body: z.object({
+ type: z.nativeEnum(HoneyTokenType),
+ connectionId: z.string().uuid(),
+ config: AwsHoneyTokenConfigSchema
+ }),
+ response: {
+ 200: z.object({
+ config: SanitizedHoneyTokenConfigSchema
+ })
+ }
+ },
+ handler: async (req) => {
+ const config = await server.services.honeyToken.upsertConfig({
+ orgPermission: req.permission,
+ type: req.body.type,
+ connectionId: req.body.connectionId,
+ config: req.body.config
+ });
+
+ return { config };
+ }
+ });
+
+ server.route({
+ url: "/configs/:type",
+ method: "GET",
+ config: {
+ rateLimit: readLimit
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ schema: {
+ params: z.object({
+ type: z.nativeEnum(HoneyTokenType)
+ }),
+ response: {
+ 200: z.object({
+ config: SanitizedHoneyTokenConfigSchema.extend({
+ id: z.string().nullable(),
+ connectionId: z.string().nullable(),
+ createdAt: z.date().nullable(),
+ updatedAt: z.date().nullable(),
+ decryptedConfig: z.object({ secretToken: z.string() }).nullable()
+ })
+ })
+ }
+ },
+ handler: async (req) => {
+ const config = await server.services.honeyToken.getConfig({
+ orgPermission: req.permission,
+ type: req.params.type
+ });
+
+ return { config };
+ }
+ });
+};
diff --git a/backend/src/ee/routes/v1/index.ts b/backend/src/ee/routes/v1/index.ts
index 7ef91cddff..550672d9e4 100644
--- a/backend/src/ee/routes/v1/index.ts
+++ b/backend/src/ee/routes/v1/index.ts
@@ -21,6 +21,7 @@ import { registerGatewayPoolRouter } from "./gateway-pool-router";
import { registerGatewayRouter } from "./gateway-router";
import { registerGithubOrgSyncRouter } from "./github-org-sync-router";
import { registerGroupRouter } from "./group-router";
+import { registerHoneyTokenRouter } from "./honey-token-router";
import { registerIdentityProjectAdditionalPrivilegeRouter } from "./identity-project-additional-privilege-router";
import { registerIdentityTemplateRouter } from "./identity-template-router";
import { registerInsightsRouter } from "./insights-router";
@@ -119,6 +120,7 @@ export const registerV1EERoutes = async (server: FastifyZodProvider) => {
await server.register(registerGatewayPoolRouter, { prefix: "/gateway-pools" });
await server.register(registerRelayRouter, { prefix: "/relays" });
await server.register(registerGithubOrgSyncRouter, { prefix: "/github-org-sync-config" });
+ await server.register(registerHoneyTokenRouter, { prefix: "/honey-tokens" });
await server.register(registerInsightsRouter, { prefix: "/insights" });
diff --git a/backend/src/ee/services/honey-token/honey-token-config-dal.ts b/backend/src/ee/services/honey-token/honey-token-config-dal.ts
new file mode 100644
index 0000000000..9616854eb6
--- /dev/null
+++ b/backend/src/ee/services/honey-token/honey-token-config-dal.ts
@@ -0,0 +1,10 @@
+import { TDbClient } from "@app/db";
+import { TableName } from "@app/db/schemas";
+import { ormify } from "@app/lib/knex";
+
+export type THoneyTokenConfigDALFactory = ReturnType<typeof honeyTokenConfigDALFactory>;
+
+export const honeyTokenConfigDALFactory = (db: TDbClient) => {
+ const orm = ormify(db, TableName.HoneyTokenConfig);
+ return orm;
+};
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
new file mode 100644
index 0000000000..3dc458e5e5
--- /dev/null
+++ b/backend/src/ee/services/honey-token/honey-token-config-service.ts
@@ -0,0 +1,149 @@
+import crypto from "node:crypto";
+
+import { ForbiddenError } from "@casl/ability";
+
+import { OrganizationActionScope } from "@app/db/schemas";
+import { BadRequestError } from "@app/lib/errors";
+import { OrgServiceActor } from "@app/lib/types";
+import { TKmsServiceFactory } from "@app/services/kms/kms-service";
+import { KmsDataKey } from "@app/services/kms/kms-types";
+
+import { TLicenseServiceFactory } from "../license/license-service";
+import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";
+import { TPermissionServiceFactory } from "../permission/permission-service-types";
+import { THoneyTokenConfigDALFactory } from "./honey-token-config-dal";
+import { HoneyTokenType } from "./honey-token-enums";
+import { AwsHoneyTokenConfigSchema } from "./honey-token-types";
+
+type THoneyTokenConfigServiceFactoryDep = {
+ honeyTokenConfigDAL: THoneyTokenConfigDALFactory;
+ permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
+ kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
+ licenseService: Pick<TLicenseServiceFactory, "getPlan">;
+};
+
+export type THoneyTokenConfigServiceFactory = ReturnType<typeof honeyTokenConfigServiceFactory>;
+
+export const honeyTokenConfigServiceFactory = ({
+ honeyTokenConfigDAL,
+ permissionService,
+ kmsService,
+ licenseService
+}: THoneyTokenConfigServiceFactoryDep) => {
+ const upsertConfig = async ({
+ orgPermission,
+ type,
+ connectionId,
+ config
+ }: {
+ orgPermission: OrgServiceActor;
+ type: HoneyTokenType;
+ connectionId: string;
+ config: { secretToken: string };
+ }) => {
+ const { permission } = await permissionService.getOrgPermission({
+ scope: OrganizationActionScope.Any,
+ actor: orgPermission.type,
+ actorId: orgPermission.id,
+ orgId: orgPermission.orgId,
+ actorAuthMethod: orgPermission.authMethod,
+ actorOrgId: orgPermission.orgId
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Settings);
+
+ const plan = await licenseService.getPlan(orgPermission.orgId);
+ if (!plan.honeyTokens) {
+ throw new BadRequestError({
+ message: "Failed to save honey token configuration due to plan restriction. Upgrade plan to use honey tokens."
+ });
+ }
+
+ const validatedConfig = AwsHoneyTokenConfigSchema.parse(config);
+
+ const { encryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.Organization,
+ orgId: orgPermission.orgId
+ });
+
+ const encryptedConfig = encryptor({
+ plainText: Buffer.from(JSON.stringify(validatedConfig))
+ }).cipherTextBlob;
+
+ const existing = await honeyTokenConfigDAL.findOne({
+ orgId: orgPermission.orgId,
+ type
+ });
+
+ if (existing) {
+ const updated = await honeyTokenConfigDAL.updateById(existing.id, {
+ connectionId,
+ encryptedConfig
+ });
+ return updated;
+ }
+
+ const created = await honeyTokenConfigDAL.create({
+ orgId: orgPermission.orgId,
+ type,
+ connectionId,
+ encryptedConfig
+ });
+
+ return created;
+ };
+
+ const getConfig = async ({ orgPermission, type }: { orgPermission: OrgServiceActor; type: HoneyTokenType }) => {
+ const { permission } = await permissionService.getOrgPermission({
+ scope: OrganizationActionScope.Any,
+ actor: orgPermission.type,
+ actorId: orgPermission.id,
+ orgId: orgPermission.orgId,
+ actorAuthMethod: orgPermission.authMethod,
+ actorOrgId: orgPermission.orgId
+ });
+
+ ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Settings);
+
+ const config = await honeyTokenConfigDAL.findOne({
+ orgId: orgPermission.orgId,
+ type
+ });
+
+ if (!config) {
+ const generatedToken = `htk_live_${crypto.randomBytes(24).toString("hex")}`;
+ return {
+ id: null,
+ orgId: orgPermission.orgId,
+ type,
+ connectionId: null,
+ createdAt: null,
+ updatedAt: null,
+ decryptedConfig: { secretToken: generatedToken }
+ };
+ }
+
+ const { decryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.Organization,
+ orgId: orgPermission.orgId
+ });
+
+ let decryptedConfig: { secretToken: string } | null = null;
+ if (config.encryptedConfig) {
+ const decrypted = decryptor({
+ cipherTextBlob: config.encryptedConfig
+ });
+ decryptedConfig = AwsHoneyTokenConfigSchema.parse(JSON.parse(decrypted.toString()) as unknown);
+ }
+
+ return {
+ ...config,
+ decryptedConfig
+ };
+ };
+
+ 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 e70f627013..facac43bb8 100644
--- a/backend/src/ee/services/honey-token/honey-token-types.ts
+++ b/backend/src/ee/services/honey-token/honey-token-types.ts
@@ -32,8 +32,7 @@ export type THoneyTokenEventMetadata = z.infer<typeof HoneyTokenEventMetadataSch
// --- Config schemas (typed shape for the encrypted config blob per provider) ---
export const AwsHoneyTokenConfigSchema = z.object({
- secretToken: z.string().min(1),
- webhookUrl: z.string().url()
+ secretToken: z.string().min(1)
});
export type TAwsHoneyTokenConfig = z.infer<typeof AwsHoneyTokenConfigSchema>;
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 053908a5c1..70c89d1170 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -68,6 +68,8 @@ import { gatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-
import { orgGatewayConfigV2DalFactory } from "@app/ee/services/gateway-v2/org-gateway-config-v2-dal";
import { githubOrgSyncDALFactory } from "@app/ee/services/github-org-sync/github-org-sync-dal";
import { githubOrgSyncServiceFactory } from "@app/ee/services/github-org-sync/github-org-sync-service";
+import { honeyTokenConfigDALFactory } from "@app/ee/services/honey-token/honey-token-config-dal";
+import { honeyTokenConfigServiceFactory } from "@app/ee/services/honey-token/honey-token-config-service";
import { groupDALFactory } from "@app/ee/services/group/group-dal";
import { groupServiceFactory } from "@app/ee/services/group/group-service";
import { identityGroupMembershipDALFactory } from "@app/ee/services/group/identity-group-membership-dal";
@@ -660,6 +662,7 @@ export const registerRoutes = async (
const gatewayDAL = gatewayDALFactory(db);
const secretReminderRecipientsDAL = secretReminderRecipientsDALFactory(db);
const githubOrgSyncDAL = githubOrgSyncDALFactory(db);
+ const honeyTokenConfigDAL = honeyTokenConfigDALFactory(db);
const secretRotationV2DAL = secretRotationV2DALFactory(db, folderDAL);
const microsoftTeamsIntegrationDAL = microsoftTeamsIntegrationDALFactory(db);
@@ -950,6 +953,13 @@ export const registerRoutes = async (
membershipGroupDAL
});
+ const honeyTokenConfigService = honeyTokenConfigServiceFactory({
+ honeyTokenConfigDAL,
+ permissionService,
+ kmsService,
+ licenseService
+ });
+
// ldapService is created after loginService (below) due to dependency on processProviderCallback
const telemetryService = telemetryServiceFactory({
@@ -3250,6 +3260,7 @@ export const registerRoutes = async (
assumePrivileges: assumePrivilegeService,
insights: insightsService,
githubOrgSync: githubOrgSyncConfigService,
+ honeyToken: honeyTokenConfigService,
folderCommit: folderCommitService,
secretScanningV2: secretScanningV2Service,
reminder: reminderService,
diff --git a/frontend/src/hooks/api/honeyToken/index.ts b/frontend/src/hooks/api/honeyToken/index.ts
new file mode 100644
index 0000000000..7a7d58eceb
--- /dev/null
+++ b/frontend/src/hooks/api/honeyToken/index.ts
@@ -0,0 +1,4 @@
+export { useUpsertHoneyTokenConfig } from "./mutations";
+export { useGetHoneyTokenConfig } from "./queries";
+export type { THoneyTokenConfig, TUpsertHoneyTokenConfigDTO } from "./types";
+export { HoneyTokenType } from "./types";
diff --git a/frontend/src/hooks/api/honeyToken/mutations.ts b/frontend/src/hooks/api/honeyToken/mutations.ts
new file mode 100644
index 0000000000..865aa48a48
--- /dev/null
+++ b/frontend/src/hooks/api/honeyToken/mutations.ts
@@ -0,0 +1,20 @@
+import { useMutation, useQueryClient } from "@tanstack/react-query";
+
+import { apiRequest } from "@app/config/request";
+
+import { honeyTokenKeys } from "./queries";
+import { TUpsertHoneyTokenConfigDTO } from "./types";
+
+export const useUpsertHoneyTokenConfig = () => {
+ const queryClient = useQueryClient();
+
+ return useMutation({
+ mutationFn: async (dto: TUpsertHoneyTokenConfigDTO) => {
+ const { data } = await apiRequest.put("/api/v1/honey-tokens/configs", dto);
+ return data.config;
+ },
+ onSuccess: (_, dto) => {
+ queryClient.invalidateQueries({ queryKey: honeyTokenKeys.config(dto.type) });
+ }
+ });
+};
diff --git a/frontend/src/hooks/api/honeyToken/queries.ts b/frontend/src/hooks/api/honeyToken/queries.ts
new file mode 100644
index 0000000000..d17f7deeb0
--- /dev/null
+++ b/frontend/src/hooks/api/honeyToken/queries.ts
@@ -0,0 +1,32 @@
+import { useQuery, UseQueryOptions } from "@tanstack/react-query";
+
+import { apiRequest } from "@app/config/request";
+
+import { HoneyTokenType, THoneyTokenConfig } from "./types";
+
+export const honeyTokenKeys = {
+ config: (type: HoneyTokenType) => ["honey-token", "config", type] as const
+};
+
+export const useGetHoneyTokenConfig = (
+ type: HoneyTokenType,
+ options?: Omit<
+ UseQueryOptions<
+ THoneyTokenConfig,
+ unknown,
+ THoneyTokenConfig,
+ ReturnType<typeof honeyTokenKeys.config>
+ >,
+ "queryKey" | "queryFn"
+ >
+) =>
+ useQuery({
+ queryKey: honeyTokenKeys.config(type),
+ queryFn: async () => {
+ const { data } = await apiRequest.get<{ config: THoneyTokenConfig }>(
+ `/api/v1/honey-tokens/configs/${type}`
+ );
+ return data.config;
+ },
+ ...options
+ });
diff --git a/frontend/src/hooks/api/honeyToken/types.ts b/frontend/src/hooks/api/honeyToken/types.ts
new file mode 100644
index 0000000000..4a1c9120b5
--- /dev/null
+++ b/frontend/src/hooks/api/honeyToken/types.ts
@@ -0,0 +1,23 @@
+export enum HoneyTokenType {
+ AWS = "aws"
+}
+
+export type THoneyTokenConfig = {
+ id: string | null;
+ orgId: string;
+ type: HoneyTokenType;
+ connectionId: string | null;
+ createdAt: string | null;
+ updatedAt: string | null;
+ decryptedConfig: {
+ secretToken: string;
+ } | null;
+};
+
+export type TUpsertHoneyTokenConfigDTO = {
+ type: HoneyTokenType;
+ connectionId: string;
+ config: {
+ secretToken: string;
+ };
+};
diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx
index ee45db4b67..8e06a1c66b 100644
--- a/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/OrgProductSettingsTab/HoneyTokenSection.tsx
@@ -1,29 +1,34 @@
-import { useEffect, useMemo, useState } from "react";
+import { useEffect, useMemo } from "react";
import { Controller, useForm } from "react-hook-form";
-import { faCopy, faEye, faEyeSlash, faTerminal } from "@fortawesome/free-solid-svg-icons";
+import { faCheck, faCopy, faEye, faEyeSlash, faTerminal } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions";
-import { Button, FilterableSelect, FormControl, IconButton } from "@app/components/v2";
+import {
+ Button,
+ Field,
+ FieldContent,
+ FieldError,
+ FieldLabel,
+ FilterableSelect,
+ IconButton
+} from "@app/components/v3";
import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context";
-import { useToggle } from "@app/hooks";
+import { useTimedReset, useToggle } from "@app/hooks";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { useListAppConnections } from "@app/hooks/api/appConnections/queries";
+import {
+ HoneyTokenType,
+ useGetHoneyTokenConfig,
+ useUpsertHoneyTokenConfig
+} from "@app/hooks/api/honeyToken";
const CF_TEMPLATE_URL =
"https://s3.amazonaws.com/infisical-honeytokens/cfn/aws-honey-token-v1.yaml";
-const generateSecretToken = () => {
- const bytes = crypto.getRandomValues(new Uint8Array(24));
- const hex = Array.from(bytes)
- .map((b) => b.toString(16).padStart(2, "0"))
- .join("");
- return `htk_live_${hex}`;
-};
-
const schema = z.object({
connectionId: z.string().min(1, "AWS Connection is required"),
secretToken: z.string().min(1, "Secret Token is required")
@@ -34,9 +39,14 @@ type FormData = z.infer<typeof schema>;
export const HoneyTokenSection = () => {
const { currentOrg } = useOrganization();
const [isTokenVisible, setIsTokenVisible] = useToggle(false);
- const [isSaving, setIsSaving] = useState(false);
+ const [, isTokenCopied, setTokenCopied] = useTimedReset({ initialState: false });
+ const [, isCommandCopied, setCommandCopied] = useTimedReset({ initialState: false });
const { data: appConnections = [], isPending: isLoadingConnections } = useListAppConnections();
+ const { data: existingConfig } = useGetHoneyTokenConfig(HoneyTokenType.AWS, {
+ retry: false
+ });
+ const { mutateAsync: upsertConfig, isPending: isSaving } = useUpsertHoneyTokenConfig();
const awsConnections = useMemo(
() => appConnections.filter((conn) => conn.app === AppConnection.AWS),
@@ -48,13 +58,7 @@ export const HoneyTokenSection = () => {
return `${protocol}//${host}/api/v1/honey-tokens/${currentOrg?.id}/trigger`;
}, [currentOrg?.id]);
- const {
- control,
- handleSubmit,
- setValue,
- watch,
- formState: { errors }
- } = useForm<FormData>({
+ const { control, handleSubmit, watch, reset } = useForm<FormData>({
resolver: zodResolver(schema),
defaultValues: {
connectionId: "",
@@ -63,8 +67,13 @@ export const HoneyTokenSection = () => {
});
useEffect(() => {
- setValue("secretToken", generateSecretToken());
- }, [setValue]);
+ if (!existingConfig?.decryptedConfig) return;
+
+ reset({
+ connectionId: existingConfig.connectionId ?? "",
+ secretToken: existingConfig.decryptedConfig.secretToken
+ });
+ }, [existingConfig, reset]);
const secretToken = watch("secretToken");
@@ -72,42 +81,45 @@ export const HoneyTokenSection = () => {
() =>
[
"aws cloudformation create-stack \\",
+ " --region us-east-1 \\",
" --stack-name infisical-honey-tokens \\",
` --template-url ${CF_TEMPLATE_URL} \\`,
" --capabilities CAPABILITY_NAMED_IAM \\",
" --parameters \\",
- ` ParameterKey=SecretToken,ParameterValue=${secretToken} \\`,
- ` ParameterKey=WebhookUrl,ParameterValue=${webhookUrl}`
+ ` ParameterKey=WebhookUrl,ParameterValue=${webhookUrl} \\`,
+ ` ParameterKey=WebhookSigningKey,ParameterValue=${secretToken}`
].join("\n"),
[secretToken, webhookUrl]
);
const onSubmit = async (data: FormData) => {
- setIsSaving(true);
try {
- // TODO: call backend API to save honey token config with data + webhookUrl
- console.log("Honey token config", { ...data, webhookUrl });
+ await upsertConfig({
+ type: HoneyTokenType.AWS,
+ connectionId: data.connectionId,
+ config: {
+ secretToken: data.secretToken
+ }
+ });
createNotification({
text: "Honey token settings saved successfully",
type: "success"
});
- } finally {
- setIsSaving(false);
+ } catch {
+ createNotification({
+ text: "Failed to save honey token settings",
+ type: "error"
+ });
}
};
- const copyToClipboard = (text: string, label: string) => {
- navigator.clipboard.writeText(text);
- createNotification({ text: `${label} copied to clipboard`, type: "info" });
- };
-
return (
<div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-6">
<div className="mb-4">
<h2 className="text-xl font-medium text-mineshaft-100">Honey Token Settings</h2>
<p className="mt-1 text-sm text-mineshaft-400">
- Plant a decoy IAM credential in your AWS account. Infisical alerts on every access attempt
- via CloudTrail.
+ Plant a decoy IAM credential in your AWS account. Infisical alerts on every access
+ attempt.
</p>
</div>
<form onSubmit={handleSubmit(onSubmit)}>
@@ -116,60 +128,67 @@ export const HoneyTokenSection = () => {
<Controller
control={control}
name="connectionId"
- render={({ field }) => {
+ render={({ field, fieldState: { error } }) => {
const selectedConnection = awsConnections.find((conn) => conn.id === field.value);
return (
- <FormControl
- label="App Connection"
- isError={Boolean(errors.connectionId)}
- errorText={errors.connectionId?.message}
- >
- <FilterableSelect
- value={selectedConnection || null}
- onChange={(newValue) => {
- const singleValue = Array.isArray(newValue) ? newValue[0] : newValue;
- if (singleValue && "id" in singleValue) {
- field.onChange(singleValue.id);
- } else {
- field.onChange("");
- }
- }}
- isLoading={isLoadingConnections}
- options={awsConnections}
- placeholder="Select an AWS App Connection..."
- getOptionLabel={(option) => option.name}
- getOptionValue={(option) => option.id}
- />
- </FormControl>
+ <Field>
+ <FieldLabel>App Connection</FieldLabel>
+ <FieldContent>
+ <FilterableSelect
+ value={selectedConnection || null}
+ onChange={(newValue) => {
+ const singleValue = Array.isArray(newValue) ? newValue[0] : newValue;
+ if (singleValue && "id" in singleValue) {
+ field.onChange(singleValue.id);
+ } else {
+ field.onChange("");
+ }
+ }}
+ isError={Boolean(error)}
+ isLoading={isLoadingConnections}
+ options={awsConnections}
+ placeholder="Select an AWS App Connection..."
+ getOptionLabel={(option) => option.name}
+ getOptionValue={(option) => option.id}
+ />
+ <FieldError errors={[error]} />
+ </FieldContent>
+ </Field>
);
}}
/>
</div>
<div className="flex-1">
- <FormControl label="Secret Token">
- <div className="flex items-center gap-2">
- <div className="flex-1 overflow-hidden rounded-md border border-mineshaft-500 bg-mineshaft-900 px-3 py-[0.44rem] font-mono text-sm text-bunker-200">
- {isTokenVisible ? secretToken : "•".repeat(30)}
+ <Field>
+ <FieldLabel>Secret Token</FieldLabel>
+ <FieldContent>
+ <div className="flex items-center gap-2">
+ <div className="flex h-9 flex-1 items-center overflow-hidden rounded-md border border-mineshaft-500 bg-mineshaft-900 px-3 font-mono text-sm text-bunker-200">
+ {isTokenVisible ? secretToken : "•".repeat(30)}
+ </div>
+ <IconButton
+ aria-label="toggle secret token visibility"
+ variant="outline"
+ size="md"
+ onClick={() => setIsTokenVisible.toggle()}
+ >
+ <FontAwesomeIcon icon={isTokenVisible ? faEyeSlash : faEye} />
+ </IconButton>
+ <IconButton
+ aria-label="copy secret token"
+ variant="outline"
+ size="md"
+ onClick={() => {
+ navigator.clipboard.writeText(secretToken);
+ setTokenCopied(true);
+ }}
+ >
+ <FontAwesomeIcon icon={isTokenCopied ? faCheck : faCopy} />
+ </IconButton>
</div>
- <IconButton
- ariaLabel="toggle secret token visibility"
- variant="outline_bg"
- size="sm"
- onClick={() => setIsTokenVisible.toggle()}
- >
- <FontAwesomeIcon icon={isTokenVisible ? faEyeSlash : faEye} />
- </IconButton>
- <IconButton
- ariaLabel="copy secret token"
- variant="outline_bg"
- size="sm"
- onClick={() => copyToClipboard(secretToken, "Secret token")}
- >
- <FontAwesomeIcon icon={faCopy} />
- </IconButton>
- </div>
- </FormControl>
+ </FieldContent>
+ </Field>
</div>
</div>
@@ -188,13 +207,16 @@ export const HoneyTokenSection = () => {
{cfCommand}
</pre>
<IconButton
- ariaLabel="copy CloudFormation command"
- variant="outline_bg"
+ aria-label="copy CloudFormation command"
+ variant="outline"
size="xs"
className="absolute top-2 right-2"
- onClick={() => copyToClipboard(cfCommand, "Command")}
+ onClick={() => {
+ navigator.clipboard.writeText(cfCommand);
+ setCommandCopied(true);
+ }}
>
- <FontAwesomeIcon icon={faCopy} />
+ <FontAwesomeIcon icon={isCommandCopied ? faCheck : faCopy} />
</IconButton>
</div>
</div>
@@ -204,8 +226,8 @@ export const HoneyTokenSection = () => {
{(isAllowed) => (
<Button
type="submit"
- colorSchema="primary"
- isLoading={isSaving}
+ variant="outline"
+ isPending={isSaving}
isDisabled={!isAllowed || isSaving}
>
Save