Skip to content

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

hide everything if cross-project sharing is disabled

Matheus Nogueira733c41ec6698
diff --git a/backend/src/services/secret-import/secret-import-dal.ts b/backend/src/services/secret-import/secret-import-dal.ts
index d785ec3e73..4af44aebc9 100644
--- a/backend/src/services/secret-import/secret-import-dal.ts
+++ b/backend/src/services/secret-import/secret-import-dal.ts
@@ -176,11 +176,11 @@ export const secretImportDALFactory = (db: TDbClient) => {
};
const getProjectImportCount = async (
- { search, ...filter }: Partial<TSecretImports & { projectId: string; search?: string }>,
+ { search, projectId, ...filter }: Partial<TSecretImports & { projectId: string; search?: string }>,
tx?: Knex
) => {
try {
- const docs = await (tx || db.replicaNode())(TableName.SecretImport)
+ const query = (tx || db.replicaNode())(TableName.SecretImport)
.where(filter)
.where("isReplication", false)
.where((bd) => {
@@ -189,9 +189,13 @@ export const secretImportDALFactory = (db: TDbClient) => {
}
})
.join(TableName.Environment, `${TableName.SecretImport}.importEnv`, `${TableName.Environment}.id`)
- .whereNull(`${TableName.Environment}.deleteAfter`)
- .count();
+ .whereNull(`${TableName.Environment}.deleteAfter`);
+
+ if (projectId) {
+ void query.where(`${TableName.Environment}.projectId`, projectId);
+ }
+ const docs = await query.count();
return Number(docs[0]?.count ?? 0);
} catch (error) {
throw new DatabaseError({ error, name: "get secret imports count" });
diff --git a/backend/src/services/secret-import/secret-import-service.ts b/backend/src/services/secret-import/secret-import-service.ts
index 1e33aef2b2..aada4c7b56 100644
--- a/backend/src/services/secret-import/secret-import-service.ts
+++ b/backend/src/services/secret-import/secret-import-service.ts
@@ -88,14 +88,15 @@ export const secretImportServiceFactory = ({
actorOrgId: string
): Promise<(T & { isAccessRevoked: boolean })[]> => {
const crossProject = imports.filter((imp) => imp.importEnv.projectId !== projectId);
+ // TODO: Do we need isAccessRemoved?
if (!crossProject.length) return imports.map((imp) => ({ ...imp, isAccessRevoked: false }));
- // If org-level toggle is disabled, ignore all cross-project imports
+ // If org-level toggle is disabled, strip cross-project imports entirely
if (!(await isCrossProjectEnabled(actorOrgId, orgDAL))) {
- return imports.map((imp) => ({
- ...imp,
- isAccessRevoked: imp.importEnv.projectId !== projectId
- }));
+ return imports
+ .filter((imp) => imp.importEnv.projectId === projectId)
+ // TODO: Do we need isAccessRemoved?
+ .map((imp) => ({ ...imp, isAccessRevoked: false }));
}
const sourceFolders = await folderDAL.findByManySecretPath(
@@ -120,10 +121,9 @@ export const secretImportServiceFactory = ({
.map((imp) => imp.id)
);
- return imports.map((imp) => ({
- ...imp,
- isAccessRevoked: revokedIds.has(imp.id)
- }));
+ return imports
+ .filter((imp) => !revokedIds.has(imp.id))
+ .map((imp) => ({ ...imp, isAccessRevoked: false }));
};
const createImport = async ({
@@ -629,9 +629,9 @@ export const secretImportServiceFactory = ({
message: `Folder with path '${secretPath}' in environment with slug '${environment}' not found`
});
- const count = await secretImportDAL.getProjectImportCount({ folderId: folder.id, search });
-
- return count;
+ const allImports = await secretImportDAL.find({ folderId: folder.id, search });
+ const accessible = await $annotateCrossProjectImports(allImports, projectId, actorOrgId);
+ return accessible.length;
};
const getProjectImportMultiEnvCount = async ({
@@ -679,10 +679,21 @@ export const secretImportServiceFactory = ({
throw new NotFoundError({
message: `Folder with path '${secretPath}' not found on environments with slugs '${environments.join(", ")}'`
});
- return secretImportDAL.getUniqueImportCountByFolderIds(
- folders.map((folder) => folder.id),
- search
+
+ const importArrays = await Promise.all(
+ folders.map(async (folder) => {
+ const imports = await secretImportDAL.find({ folderId: folder.id, search });
+ return $annotateCrossProjectImports(imports, projectId, actorOrgId);
+ })
);
+
+ const seen = new Set<string>();
+ for (const folderImports of importArrays) {
+ for (const imp of folderImports) {
+ seen.add(`${imp.importPath}:${imp.importEnv.id}`);
+ }
+ }
+ return seen.size;
};
const getImports = async ({
diff --git a/frontend/src/pages/project/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx b/frontend/src/pages/project/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
index 3b72eb08e2..ce525facee 100644
--- a/frontend/src/pages/project/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
+++ b/frontend/src/pages/project/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
@@ -1,5 +1,5 @@
import { ProjectOverviewChangeSection } from "@app/components/project/ProjectOverviewChangeSection";
-import { useServerConfig } from "@app/context";
+import { useOrganization, useServerConfig } from "@app/context";
import { AuditLogsRetentionSection } from "../AuditLogsRetentionSection";
import { CrossProjectSharingSection } from "../CrossProjectSharingSection";
@@ -8,11 +8,14 @@ import { DeleteProjectSection } from "../DeleteProjectSection";
export const ProjectGeneralTab = () => {
const { config } = useServerConfig();
+ const { currentOrg } = useOrganization();
return (
<div>
<ProjectOverviewChangeSection showSlugField />
<AuditLogsRetentionSection />
- {config.isCrossProjectSecretSharingEnabled && <CrossProjectSharingSection />}
+ {config.isCrossProjectSecretSharingEnabled && currentOrg.allowCrossProjectSecretSharing && (
+ <CrossProjectSharingSection />
+ )}
<DeleteProjectProtection />
<DeleteProjectSection />
</div>