Skip to content

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

requested changes

Matheus Nogueira19d510ca9780
diff --git a/backend/src/ee/routes/v1/insights-router.ts b/backend/src/ee/routes/v1/insights-router.ts
index 4caa042b83..aa21313ce3 100644
--- a/backend/src/ee/routes/v1/insights-router.ts
+++ b/backend/src/ee/routes/v1/insights-router.ts
@@ -185,6 +185,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
z.object({
key: z.string(),
environment: z.string(),
+ environmentSlug: z.string(),
secretPath: z.string()
})
)
diff --git a/backend/src/ee/services/insights/insights-service.ts b/backend/src/ee/services/insights/insights-service.ts
index 767f957cc3..9d23701331 100644
--- a/backend/src/ee/services/insights/insights-service.ts
+++ b/backend/src/ee/services/insights/insights-service.ts
@@ -13,10 +13,13 @@ import { withCache } from "@app/lib/cache/with-cache";
import { BadRequestError } from "@app/lib/errors";
import { OrgServiceActor } from "@app/lib/types";
import { ActorType } from "@app/services/auth/auth-type";
+import { TKmsServiceFactory } from "@app/services/kms/kms-service";
+import { KmsDataKey } from "@app/services/kms/kms-types";
import { TProjectDALFactory } from "@app/services/project/project-dal";
import { TProjectBotServiceFactory } from "@app/services/project-bot/project-bot-service";
import { TReminderDALFactory } from "@app/services/reminder/reminder-dal";
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
+import { containsSecretReference } from "@app/services/secret-v2-bridge/secret-reference-fns";
import { TSecretV2BridgeDALFactory } from "@app/services/secret-v2-bridge/secret-v2-bridge-dal";
import { TUserDALFactory } from "@app/services/user/user-dal";
@@ -43,6 +46,7 @@ type TInsightsServiceFactoryDep = {
projectBotService: Pick<TProjectBotServiceFactory, "getBotKey">;
projectDAL: Pick<TProjectDALFactory, "findById">;
userDAL: Pick<TUserDALFactory, "find">;
+ kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
keyStore: Pick<TKeyStoreFactory, "setItemWithExpiry" | "getItem">;
};
@@ -93,6 +97,7 @@ export const insightsServiceFactory = ({
projectBotService,
projectDAL,
userDAL,
+ kmsService,
keyStore
}: TInsightsServiceFactoryDep) => {
const fetchReminders = async (projectId: string, startDate: Date, endDate: Date) => {
@@ -508,7 +513,9 @@ export const insightsServiceFactory = ({
if (!project.secretBlindIndexEnabled) {
return {
secretBlindIndexEnabled: false as const,
- groups: [] as { secrets: { key: string; environment: string; secretPath: string }[] }[]
+ groups: [] as {
+ secrets: { key: string; environment: string; environmentSlug: string; secretPath: string }[];
+ }[]
};
}
@@ -522,7 +529,20 @@ export const insightsServiceFactory = ({
limit: dto.limit ?? 50
});
- const folderIds = [...new Set(rawGroups.flatMap((g) => g.secrets.map((s) => s.folderId)))];
+ const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId: dto.projectId
+ });
+
+ const filteredGroups = rawGroups.filter((g) => {
+ if (!g.secrets.length) return false;
+ const firstSecret = g.secrets[0];
+ if (!firstSecret.encryptedValue) return true;
+ const decryptedValue = secretManagerDecryptor({ cipherTextBlob: firstSecret.encryptedValue }).toString();
+ return !containsSecretReference(decryptedValue);
+ });
+
+ const folderIds = [...new Set(filteredGroups.flatMap((g) => g.secrets.map((s) => s.folderId)))];
const foldersWithPath = folderIds.length
? await folderDAL.findSecretPathByFolderIds(dto.projectId, folderIds)
: [];
@@ -531,10 +551,11 @@ export const insightsServiceFactory = ({
if (f) folderRecord[f.id] = f.path;
});
- const groups = rawGroups.map((g) => ({
+ const groups = filteredGroups.map((g) => ({
secrets: g.secrets.map((s) => ({
key: s.key,
- environment: s.environment,
+ environment: s.environmentName,
+ environmentSlug: s.environment,
secretPath: folderRecord[s.folderId] ?? "/"
}))
}));
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index c526feace9..83c7802620 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -2617,6 +2617,7 @@ export const registerRoutes = async (
projectBotService,
projectDAL,
userDAL,
+ kmsService,
keyStore
});
diff --git a/backend/src/services/project/project-queue.ts b/backend/src/services/project/project-queue.ts
index 1c6d85e3f3..3edf83b657 100644
--- a/backend/src/services/project/project-queue.ts
+++ b/backend/src/services/project/project-queue.ts
@@ -20,6 +20,7 @@ import {
import { TSecretApprovalRequestDALFactory } from "@app/ee/services/secret-approval-request/secret-approval-request-dal";
import { TSecretApprovalRequestSecretDALFactory } from "@app/ee/services/secret-approval-request/secret-approval-request-secret-dal";
import { RequestState } from "@app/ee/services/secret-approval-request/secret-approval-request-types";
+import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";
import {
decryptIntegrationAuths,
decryptSecretApprovals,
@@ -31,8 +32,6 @@ import { crypto } from "@app/lib/crypto/cryptography";
import { logger } from "@app/lib/logger";
import { QueueJobs, QueueName, TQueueJobTypes, TQueueServiceFactory } from "@app/queue";
-import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";
-
import { TIntegrationAuthDALFactory } from "../integration-auth/integration-auth-dal";
import { TKmsServiceFactory } from "../kms/kms-service";
import { KmsDataKey } from "../kms/kms-types";
diff --git a/backend/src/services/secret-v2-bridge/secret-reference-fns.ts b/backend/src/services/secret-v2-bridge/secret-reference-fns.ts
index 92e9ed78ff..94d9e64b1f 100644
--- a/backend/src/services/secret-v2-bridge/secret-reference-fns.ts
+++ b/backend/src/services/secret-v2-bridge/secret-reference-fns.ts
@@ -10,6 +10,8 @@ import { TSecretV2BridgeDALFactory } from "./secret-v2-bridge-dal";
const INTERPOLATION_PATTERN_STRING = String.raw`\${([a-zA-Z0-9-_.]+)}`;
const INTERPOLATION_TEST_REGEX = new RE2(INTERPOLATION_PATTERN_STRING);
+export const containsSecretReference = (value: string) => INTERPOLATION_TEST_REGEX.test(value);
+
/**
* Grabs and processes nested secret references from a string
*
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
index 78685729ad..be6b12a252 100644
--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
@@ -1271,20 +1271,38 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
.select(
`${TableName.SecretV2}.key`,
`${TableName.SecretV2}.folderId`,
+ `${TableName.SecretV2}.encryptedValue`,
`${TableName.SecretV2}.secretValueBlindIndex`,
- `${TableName.Environment}.slug as environment`
+ `${TableName.Environment}.slug as environment`,
+ `${TableName.Environment}.name as environmentName`
)
.orderBy(`${TableName.SecretV2}.secretValueBlindIndex`);
- const groups: { secrets: { key: string; environment: string; folderId: string }[] }[] = [];
+ const groups: {
+ secrets: {
+ key: string;
+ environment: string;
+ environmentName: string;
+ folderId: string;
+ encryptedValue: Buffer | null;
+ }[];
+ }[] = [];
let currentIndex: string | null = null;
- let currentGroup: { key: string; environment: string; folderId: string }[] = [];
+ let currentGroup: {
+ key: string;
+ environment: string;
+ environmentName: string;
+ folderId: string;
+ encryptedValue: Buffer | null;
+ }[] = [];
for (const row of rows as {
key: string;
folderId: string;
+ encryptedValue: Buffer | null;
secretValueBlindIndex: string;
environment: string;
+ environmentName: string;
}[]) {
if (row.secretValueBlindIndex !== currentIndex) {
if (currentGroup.length > 0) {
@@ -1293,7 +1311,13 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
currentIndex = row.secretValueBlindIndex;
currentGroup = [];
}
- currentGroup.push({ key: row.key, environment: row.environment, folderId: row.folderId });
+ currentGroup.push({
+ key: row.key,
+ environment: row.environment,
+ environmentName: row.environmentName,
+ folderId: row.folderId,
+ encryptedValue: row.encryptedValue
+ });
}
if (currentGroup.length > 0) {
groups.push({ secrets: currentGroup });
diff --git a/frontend/src/hooks/api/secretInsights/types.ts b/frontend/src/hooks/api/secretInsights/types.ts
index bab6742218..f567959349 100644
--- a/frontend/src/hooks/api/secretInsights/types.ts
+++ b/frontend/src/hooks/api/secretInsights/types.ts
@@ -130,6 +130,7 @@ export type TGetSecretsDuplicationDTO = {
export type TDuplicatedSecretEntry = {
key: string;
environment: string;
+ environmentSlug: string;
secretPath: string;
};
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/DuplicatedSecretsCard.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/DuplicatedSecretsCard.tsx
index e0dffb4a06..26e663f3aa 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/DuplicatedSecretsCard.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/DuplicatedSecretsCard.tsx
@@ -15,6 +15,7 @@ import {
AccordionContent,
AccordionItem,
AccordionTrigger,
+ Badge,
Button,
Card,
CardContent,
@@ -41,16 +42,13 @@ import {
useGetSecretsDuplication
} from "@app/hooks/api/secretInsights";
-const ENVIRONMENT_COLOR_MAP: Record<string, string> = {
- production: "bg-green-500",
- staging: "bg-yellow-500",
- development: "bg-emerald-400",
- testing: "bg-blue-400"
+const ENV_BADGE_VARIANT: Record<string, "danger" | "warning" | "success" | "info"> = {
+ prod: "danger",
+ staging: "warning",
+ dev: "info",
};
-const getEnvironmentDotColor = (slug: string) => {
- return ENVIRONMENT_COLOR_MAP[slug] || "bg-primary";
-};
+const getEnvBadgeVariant = (slug: string) => ENV_BADGE_VARIANT[slug] || "neutral";
const overviewRoute =
"/organizations/$orgId/projects/secret-management/$projectId/overview" as const;
@@ -214,14 +212,13 @@ export const DuplicatedSecretsCard = () => {
className="group/row -mx-2 flex items-center gap-6 rounded-md px-2 py-1.5 text-sm hover:bg-container-hover"
>
<div className="flex w-72 shrink-0 items-center gap-2">
- <KeyRoundIcon className="size-3.5 text-muted" />
+ <KeyRoundIcon className="size-4 text-muted" />
<span className="truncate font-mono text-foreground">{entry.key}</span>
</div>
- <div className="flex w-28 shrink-0 items-center gap-2">
- <span
- className={`size-2 shrink-0 rounded-full ${getEnvironmentDotColor(entry.environment)}`}
- />
- <span className="truncate text-foreground">{entry.environment}</span>
+ <div className="w-28 shrink-0">
+ <Badge variant={getEnvBadgeVariant(entry.environmentSlug)} isTruncatable className="max-w-full">
+ <span>{entry.environment}</span>
+ </Badge>
</div>
<div className="flex min-w-0 flex-1 items-center gap-2 text-muted">
<FolderIcon className="size-3.5 shrink-0" />
@@ -243,7 +240,8 @@ export const DuplicatedSecretsCard = () => {
projectId
},
search: {
- secretPath: entry.secretPath
+ secretPath: entry.secretPath,
+ environments: [entry.environmentSlug]
}
})
}