Skip to content

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

load secrets via API and ensure org has cross-project enabled

Matheus Nogueira7ddd163609c6
diff --git a/backend/src/ee/services/secret-replication/secret-replication-service.ts b/backend/src/ee/services/secret-replication/secret-replication-service.ts
index 557dad9497..381d4caacc 100644
--- a/backend/src/ee/services/secret-replication/secret-replication-service.ts
+++ b/backend/src/ee/services/secret-replication/secret-replication-service.ts
@@ -26,6 +26,7 @@ import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-fold
import { ReservedFolders } from "@app/services/secret-folder/secret-folder-types";
import { TSecretImportDALFactory } from "@app/services/secret-import/secret-import-dal";
import { fnSecretsFromImports, fnSecretsV2FromImports } from "@app/services/secret-import/secret-import-fns";
+import { TProjectGrantDALFactory } from "@app/services/project-grant/project-grant-dal";
import { TSecretTagDALFactory } from "@app/services/secret-tag/secret-tag-dal";
import { getAllSecretReferences } from "@app/services/secret-v2-bridge/secret-reference-fns";
import { TSecretV2BridgeDALFactory } from "@app/services/secret-v2-bridge/secret-v2-bridge-dal";
@@ -90,6 +91,7 @@ type TSecretReplicationServiceFactoryDep = {
projectBotService: Pick<TProjectBotServiceFactory, "getBotKey">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
folderCommitService: Pick<TFolderCommitServiceFactory, "createCommit">;
+ projectGrantDAL: Pick<TProjectGrantDALFactory, "find">;
};
export type TSecretReplicationServiceFactory = ReturnType<typeof secretReplicationServiceFactory>;
@@ -137,6 +139,7 @@ export const secretReplicationServiceFactory = ({
secretV2BridgeDAL,
kmsService,
folderCommitService,
+ projectGrantDAL,
resourceMetadataDAL
}: TSecretReplicationServiceFactoryDep) => {
const $getReplicatedSecrets = (
@@ -288,7 +291,16 @@ export const secretReplicationServiceFactory = ({
secretImportDAL,
decryptor: (value) => (value ? secretManagerDecryptor({ cipherTextBlob: value }).toString() : ""),
viewSecretValue: true,
- hasSecretAccess: () => true
+ hasSecretAccess: () => true,
+ projectId,
+ projectGrantDAL,
+ getProjectDecryptor: async (sourceProjectId: string) => {
+ const { decryptor: sourceDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId: sourceProjectId
+ });
+ return (value) => (value ? sourceDecryptor({ cipherTextBlob: value }).toString() : "");
+ }
});
// secrets that gets replicated across imports
const sourceDecryptedLocalSecrets = sourceLocalSecrets.map((el) => ({
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index fca2383c44..f69c44a919 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1827,7 +1827,8 @@ export const registerRoutes = async (
projectSlackConfigDAL,
projectMicrosoftTeamsConfigDAL,
microsoftTeamsService,
- telemetryService
+ telemetryService,
+ projectGrantDAL
});
const secretQueueService = secretQueueFactory({
@@ -1871,7 +1872,8 @@ export const registerRoutes = async (
membershipRoleDAL,
membershipUserDAL,
telemetryService,
- projectEventsService
+ projectEventsService,
+ projectGrantDAL
});
const projectService = projectServiceFactory({
@@ -1993,6 +1995,7 @@ export const registerRoutes = async (
projectGrantDAL,
folderDAL,
projectDAL,
+ orgDAL,
permissionService
});
const secretBlindIndexService = secretBlindIndexServiceFactory({
@@ -2023,7 +2026,8 @@ export const registerRoutes = async (
reminderService,
reminderDAL,
keyStore,
- secretValidationRuleService
+ secretValidationRuleService,
+ projectGrantDAL
});
const secretApprovalRequestService = secretApprovalRequestServiceFactory({
@@ -2179,7 +2183,8 @@ export const registerRoutes = async (
secretVersionV2TagBridgeDAL: secretVersionTagV2BridgeDAL,
secretVersionV2BridgeDAL,
resourceMetadataDAL,
- folderCommitService
+ folderCommitService,
+ projectGrantDAL
});
const integrationService = integrationServiceFactory({
@@ -2193,7 +2198,8 @@ export const registerRoutes = async (
secretV2BridgeDAL,
secretImportDAL,
secretDAL,
- kmsService
+ kmsService,
+ projectGrantDAL
});
const accessTokenQueue = accessTokenQueueServiceFactory({
diff --git a/backend/src/services/integration-auth/integration-delete-secret.ts b/backend/src/services/integration-auth/integration-delete-secret.ts
index 43ddd81f99..b08f908d68 100644
--- a/backend/src/services/integration-auth/integration-delete-secret.ts
+++ b/backend/src/services/integration-auth/integration-delete-secret.ts
@@ -17,6 +17,7 @@ import { TSecretDALFactory } from "../secret/secret-dal";
import { TSecretFolderDALFactory } from "../secret-folder/secret-folder-dal";
import { TSecretImportDALFactory } from "../secret-import/secret-import-dal";
import { fnSecretsV2FromImports } from "../secret-import/secret-import-fns";
+import { TProjectGrantDALFactory } from "../project-grant/project-grant-dal";
import { TSecretV2BridgeDALFactory } from "../secret-v2-bridge/secret-v2-bridge-dal";
import { IntegrationAuthMetadataSchema, TIntegrationAuthMetadata } from "./integration-auth-schema";
import { TIntegrationAuthServiceFactory } from "./integration-auth-service";
@@ -39,7 +40,9 @@ const getIntegrationSecretsV2 = async (
},
secretV2BridgeDAL: Pick<TSecretV2BridgeDALFactory, "find" | "findByFolderIds" | "findByFolderId">,
folderDAL: Pick<TSecretFolderDALFactory, "findByManySecretPath">,
- secretImportDAL: Pick<TSecretImportDALFactory, "find" | "findByFolderIds" | "findByIds">
+ secretImportDAL: Pick<TSecretImportDALFactory, "find" | "findByFolderIds" | "findByIds">,
+ kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">,
+ projectGrantDAL: Pick<TProjectGrantDALFactory, "find">
) => {
const content: Record<string, boolean> = {};
if (dto.depth > MAX_SYNC_SECRET_DEPTH) {
@@ -69,7 +72,16 @@ const getIntegrationSecretsV2 = async (
secretImportDAL,
secretImports,
hasSecretAccess: () => true,
- viewSecretValue: true
+ viewSecretValue: true,
+ projectId: dto.projectId,
+ projectGrantDAL,
+ getProjectDecryptor: async (sourceProjectId: string) => {
+ const { decryptor: sourceDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId: sourceProjectId
+ });
+ return (value) => (value ? sourceDecryptor({ cipherTextBlob: value }).toString() : "");
+ }
});
for (let i = importedSecrets.length - 1; i >= 0; i -= 1) {
@@ -284,7 +296,8 @@ export const deleteIntegrationSecrets = async ({
folderDAL,
secretDAL,
secretImportDAL,
- kmsService
+ kmsService,
+ projectGrantDAL
}: {
integration: Omit<TIntegrations, "envId"> & {
projectId: string;
@@ -303,6 +316,7 @@ export const deleteIntegrationSecrets = async ({
secretImportDAL: Pick<TSecretImportDALFactory, "find" | "findByFolderIds" | "findByIds">;
secretDAL: Pick<TSecretDALFactory, "findByFolderId">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
+ projectGrantDAL: Pick<TProjectGrantDALFactory, "find">;
}) => {
const { shouldUseSecretV2Bridge, botKey } = await projectBotService.getBotKey(integration.projectId);
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
@@ -340,7 +354,9 @@ export const deleteIntegrationSecrets = async ({
},
secretV2BridgeDAL,
folderDAL,
- secretImportDAL
+ secretImportDAL,
+ kmsService,
+ projectGrantDAL
)
: await getIntegrationSecretsV1(
{
diff --git a/backend/src/services/integration/integration-service.ts b/backend/src/services/integration/integration-service.ts
index faa1cccf1f..adb396badf 100644
--- a/backend/src/services/integration/integration-service.ts
+++ b/backend/src/services/integration/integration-service.ts
@@ -18,6 +18,7 @@ import { deleteIntegrationSecrets } from "../integration-auth/integration-delete
import { TKmsServiceFactory } from "../kms/kms-service";
import { KmsDataKey } from "../kms/kms-types";
import { TProjectBotServiceFactory } from "../project-bot/project-bot-service";
+import { TProjectGrantDALFactory } from "../project-grant/project-grant-dal";
import { TSecretDALFactory } from "../secret/secret-dal";
import { TSecretQueueFactory } from "../secret/secret-queue";
import { TSecretFolderDALFactory } from "../secret-folder/secret-folder-dal";
@@ -44,6 +45,7 @@ type TIntegrationServiceFactoryDep = {
secretImportDAL: Pick<TSecretImportDALFactory, "find" | "findByFolderIds" | "findByIds">;
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;
secretDAL: Pick<TSecretDALFactory, "findByFolderId">;
+ projectGrantDAL: Pick<TProjectGrantDALFactory, "find">;
};
export type TIntegrationServiceFactory = ReturnType<typeof integrationServiceFactory>;
@@ -59,7 +61,8 @@ export const integrationServiceFactory = ({
secretV2BridgeDAL,
secretImportDAL,
kmsService,
- secretDAL
+ secretDAL,
+ projectGrantDAL
}: TIntegrationServiceFactoryDep) => {
const createIntegration = async ({
app,
@@ -324,7 +327,8 @@ export const integrationServiceFactory = ({
folderDAL,
secretImportDAL,
secretDAL,
- kmsService
+ kmsService,
+ projectGrantDAL
});
}
diff --git a/backend/src/services/project-grant/project-grant-service.ts b/backend/src/services/project-grant/project-grant-service.ts
index 69900c0958..abc3801923 100644
--- a/backend/src/services/project-grant/project-grant-service.ts
+++ b/backend/src/services/project-grant/project-grant-service.ts
@@ -6,10 +6,14 @@ import {
ProjectPermissionProjectGrantActions,
ProjectPermissionSub
} from "@app/ee/services/permission/project-permission";
-import { BadRequestError, NotFoundError } from "@app/lib/errors";
+import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
+import { requestMemoKeys } from "@app/lib/request-context/memo-keys";
+import { requestMemoize } from "@app/lib/request-context/request-memoizer";
+import { TOrgDALFactory } from "@app/services/org/org-dal";
import { TProjectDALFactory } from "@app/services/project/project-dal";
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
+import { canUseCrossProjectSecretSharing } from "./project-grant-fns";
import { TProjectGrantDALFactory } from "./project-grant-dal";
import {
TCreateProjectGrantDTO,
@@ -24,6 +28,7 @@ type TProjectGrantServiceFactoryDep = {
projectGrantDAL: TProjectGrantDALFactory;
folderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath" | "findById">;
projectDAL: Pick<TProjectDALFactory, "findById">;
+ orgDAL: Pick<TOrgDALFactory, "findOrgById">;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
};
@@ -31,8 +36,15 @@ export const projectGrantServiceFactory = ({
projectGrantDAL,
folderDAL,
projectDAL,
+ orgDAL,
permissionService
}: TProjectGrantServiceFactoryDep) => {
+ const isCrossProjectEnabled = async (actorOrgId: string) => {
+ const org = await requestMemoize(requestMemoKeys.orgFindOrgById(actorOrgId), () =>
+ orgDAL.findOrgById(actorOrgId)
+ );
+ return canUseCrossProjectSecretSharing(actorOrgId) && (org?.allowCrossProjectSecretSharing ?? false);
+ };
const createGrant = async ({
actorId,
actor,
@@ -43,6 +55,10 @@ export const projectGrantServiceFactory = ({
secretPath,
targetProjectId
}: TCreateProjectGrantDTO) => {
+ if (!(await isCrossProjectEnabled(actorOrgId))) {
+ throw new ForbiddenRequestError({ message: "Cross-project secret sharing is not enabled for this organization" });
+ }
+
const { permission } = await permissionService.getProjectPermission({
actor,
actorId,
@@ -90,6 +106,10 @@ export const projectGrantServiceFactory = ({
grantId,
sourceProjectId
}: TDeleteProjectGrantDTO) => {
+ if (!(await isCrossProjectEnabled(actorOrgId))) {
+ throw new ForbiddenRequestError({ message: "Cross-project secret sharing is not enabled for this organization" });
+ }
+
const { permission } = await permissionService.getProjectPermission({
actor,
actorId,
@@ -118,6 +138,10 @@ export const projectGrantServiceFactory = ({
actorOrgId,
sourceProjectId
}: TListProjectGrantsDTO) => {
+ if (!(await isCrossProjectEnabled(actorOrgId))) {
+ return [];
+ }
+
const { permission } = await permissionService.getProjectPermission({
actor,
actorId,
@@ -142,6 +166,10 @@ export const projectGrantServiceFactory = ({
actorOrgId,
targetProjectId
}: TListProjectGrantsForTargetDTO) => {
+ if (!(await isCrossProjectEnabled(actorOrgId))) {
+ return [];
+ }
+
await permissionService.getProjectPermission({
actor,
actorId,
diff --git a/backend/src/services/secret-sync/secret-sync-queue.ts b/backend/src/services/secret-sync/secret-sync-queue.ts
index 5fbddee1fa..60b55ab0b5 100644
--- a/backend/src/services/secret-sync/secret-sync-queue.ts
+++ b/backend/src/services/secret-sync/secret-sync-queue.ts
@@ -23,6 +23,7 @@ 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 { TProjectBotDALFactory } from "@app/services/project-bot/project-bot-dal";
+import { TProjectGrantDALFactory } from "@app/services/project-grant/project-grant-dal";
import { TProjectMembershipDALFactory } from "@app/services/project-membership/project-membership-dal";
import { TResourceMetadataDALFactory } from "@app/services/resource-metadata/resource-metadata-dal";
import { TSecretDALFactory } from "@app/services/secret/secret-dal";
@@ -132,6 +133,7 @@ type TSecretSyncQueueFactoryDep = {
projectMicrosoftTeamsConfigDAL: Pick<TProjectMicrosoftTeamsConfigDALFactory, "getIntegrationDetailsByProject">;
microsoftTeamsService: Pick<TMicrosoftTeamsServiceFactory, "sendNotification">;
telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;
+ projectGrantDAL: Pick<TProjectGrantDALFactory, "find">;
};
type SecretSyncActionJob = Job<
@@ -183,7 +185,8 @@ export const secretSyncQueueFactory = ({
projectSlackConfigDAL,
projectMicrosoftTeamsConfigDAL,
microsoftTeamsService,
- telemetryService
+ telemetryService,
+ projectGrantDAL
}: TSecretSyncQueueFactoryDep) => {
const appCfg = getConfig();
@@ -329,7 +332,16 @@ export const secretSyncQueueFactory = ({
secretImportDAL,
secretImports,
hasSecretAccess: () => true,
- viewSecretValue: true
+ viewSecretValue: true,
+ projectId,
+ projectGrantDAL,
+ getProjectDecryptor: async (sourceProjectId: string) => {
+ const { decryptor: sourceDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId: sourceProjectId
+ });
+ return (value) => (value ? sourceDecryptor({ cipherTextBlob: value }).toString() : "");
+ }
});
for (let i = importedSecrets.length - 1; i >= 0; i -= 1) {
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts
index 3809f296cf..becdf79405 100644
--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts
+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts
@@ -55,6 +55,7 @@ import { TReminderDALFactory } from "../reminder/reminder-dal";
import { TReminderServiceFactory } from "../reminder/reminder-types";
import { TResourceMetadataDALFactory } from "../resource-metadata/resource-metadata-dal";
import { ResourceMetadataWithEncryptionDTO } from "../resource-metadata/resource-metadata-schema";
+import { TProjectGrantDALFactory } from "../project-grant/project-grant-dal";
import { TSecretQueueFactory } from "../secret/secret-queue";
import {
PersonalOverridesBehavior,
@@ -147,6 +148,7 @@ type TSecretV2BridgeServiceFactoryDep = {
reminderService: Pick<TReminderServiceFactory, "createReminder" | "getReminder" | "batchCreateReminders">;
reminderDAL: Pick<TReminderDALFactory, "findSecretReminders" | "delete">;
secretValidationRuleService: Pick<TSecretValidationRuleServiceFactory, "validateSecrets">;
+ projectGrantDAL: Pick<TProjectGrantDALFactory, "find">;
};
export type TSecretV2BridgeServiceFactory = ReturnType<typeof secretV2BridgeServiceFactory>;
@@ -176,7 +178,8 @@ export const secretV2BridgeServiceFactory = ({
keyStore,
reminderService,
reminderDAL,
- secretValidationRuleService
+ secretValidationRuleService,
+ projectGrantDAL
}: TSecretV2BridgeServiceFactoryDep) => {
const $validateSecretReferences = async (
projectId: string,
@@ -1604,6 +1607,15 @@ export const secretV2BridgeServiceFactory = ({
);
return viewSecretValue ? canDescribe && canReadValue : canDescribe;
+ },
+ projectId,
+ projectGrantDAL,
+ getProjectDecryptor: async (sourceProjectId: string) => {
+ const { decryptor: sourceDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId: sourceProjectId
+ });
+ return (value) => (value ? sourceDecryptor({ cipherTextBlob: value }).toString() : "");
}
});
@@ -1831,6 +1843,15 @@ export const secretV2BridgeServiceFactory = ({
secretName: expandSecretKey,
secretTags: expandSecretTags
});
+ },
+ projectId,
+ projectGrantDAL,
+ getProjectDecryptor: async (sourceProjectId: string) => {
+ const { decryptor: sourceDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId: sourceProjectId
+ });
+ return (value) => (value ? sourceDecryptor({ cipherTextBlob: value }).toString() : "");
}
});
diff --git a/backend/src/services/secret/secret-queue.ts b/backend/src/services/secret/secret-queue.ts
index 46b42e79ac..ec23a38fd8 100644
--- a/backend/src/services/secret/secret-queue.ts
+++ b/backend/src/services/secret/secret-queue.ts
@@ -60,6 +60,7 @@ import { TResourceMetadataDALFactory } from "../resource-metadata/resource-metad
import { ResourceMetadataDTO } from "../resource-metadata/resource-metadata-schema";
import { TSecretFolderDALFactory } from "../secret-folder/secret-folder-dal";
import { TSecretImportDALFactory } from "../secret-import/secret-import-dal";
+import { TProjectGrantDALFactory } from "../project-grant/project-grant-dal";
import { fnSecretsV2FromImports } from "../secret-import/secret-import-fns";
import { expandSecretReferencesFactory, getAllSecretReferences } from "../secret-v2-bridge/secret-reference-fns";
import { TSecretV2BridgeDALFactory } from "../secret-v2-bridge/secret-v2-bridge-dal";
@@ -127,6 +128,7 @@ type TSecretQueueFactoryDep = {
projectEventsService: TProjectEventsService;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;
+ projectGrantDAL: Pick<TProjectGrantDALFactory, "find">;
};
export type TGetSecrets = {
@@ -194,7 +196,8 @@ export const secretQueueFactory = ({
licenseService,
membershipUserDAL,
membershipRoleDAL,
- telemetryService
+ telemetryService,
+ projectGrantDAL
}: TSecretQueueFactoryDep) => {
const integrationMeter = opentelemetry.metrics.getMeter("Integrations");
const errorHistogram = integrationMeter.createHistogram("integration_secret_sync_errors", {
@@ -439,7 +442,16 @@ export const secretQueueFactory = ({
secretImportDAL,
secretImports,
hasSecretAccess: () => true,
- viewSecretValue: true
+ viewSecretValue: true,
+ projectId: dto.projectId,
+ projectGrantDAL,
+ getProjectDecryptor: async (sourceProjectId: string) => {
+ const { decryptor: sourceDecryptor } = await kmsService.createCipherPairWithDataKey({
+ type: KmsDataKey.SecretManager,
+ projectId: sourceProjectId
+ });
+ return (value) => (value ? sourceDecryptor({ cipherTextBlob: value }).toString() : "");
+ }
});
for (let i = importedSecrets.length - 1; i >= 0; i -= 1) {