Skip to content

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

feat(secret-sync): warn before moving or copying secrets into a synced path

Calvindc4150d8b967
diff --git a/backend/e2e-test/routes/v1/dashboard-move-warnings.spec.ts b/backend/e2e-test/routes/v1/dashboard-move-warnings.spec.ts
new file mode 100644
index 0000000000..24838fc70d
--- /dev/null
+++ b/backend/e2e-test/routes/v1/dashboard-move-warnings.spec.ts
@@ -0,0 +1,240 @@
+import { randomUUID } from "node:crypto";
+
+import { createAwsAppConnection } from "e2e-test/testUtils/app-connections";
+import { createIsolatedOrgAndProject } from "e2e-test/testUtils/fixtures";
+import { createFolder } from "e2e-test/testUtils/folders";
+import { createSecretSync } from "e2e-test/testUtils/secret-syncs";
+import jwt from "jsonwebtoken";
+
+import { AccessScope, OrgMembershipRole, OrgMembershipStatus, ProjectMembershipRole, TableName } from "@app/db/schemas";
+import { getConfig, initEnvConfig } from "@app/lib/config/env";
+import { initLogger, logger } from "@app/lib/logger";
+import { alphaNumericNanoId } from "@app/lib/nanoid";
+import { AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";
+
+const ENV = "dev";
+const REGION = "us-east-1";
+
+type TMoveWarningSecretSync = {
+ id: string | null;
+ name: string | null;
+ destination: string | null;
+ secretPath: string | null;
+ includeAllSubFolders: boolean | null;
+ isAutoSyncEnabled: boolean | null;
+};
+
+describe("Move warnings", async () => {
+ vi.setConfig({ testTimeout: 30_000, hookTimeout: 30_000 });
+
+ let orgId: string;
+ let projectId: string;
+ let adminToken: string;
+ let cleanupOrg: () => Promise<void>;
+ let noAccessUserId: string;
+ let noAccessToken: string;
+
+ const getMoveWarnings = async (
+ query: {
+ sourceEnvironment?: string;
+ sourceSecretPath: string;
+ destinationEnvironment?: string;
+ destinationSecretPath: string;
+ },
+ authToken = adminToken
+ ) => {
+ const res = await testServer.inject({
+ method: "GET",
+ url: "/api/v1/dashboard/move-warnings",
+ headers: { authorization: `Bearer ${authToken}` },
+ query: {
+ projectId,
+ sourceEnvironment: query.sourceEnvironment ?? ENV,
+ destinationEnvironment: query.destinationEnvironment ?? ENV,
+ sourceSecretPath: query.sourceSecretPath,
+ destinationSecretPath: query.destinationSecretPath
+ }
+ });
+
+ return res;
+ };
+
+ const syncNames = async (query: Parameters<typeof getMoveWarnings>[0]) => {
+ const res = await getMoveWarnings(query);
+ expect(res.statusCode).toBe(200);
+ return (res.json().secretSyncs as TMoveWarningSecretSync[]).map((sync) => sync.name);
+ };
+
+ beforeAll(async () => {
+ initLogger();
+ await initEnvConfig(testHsmService, testKmsRootConfigDAL, testSuperAdminDAL, logger);
+
+ ({
+ orgId,
+ projectId,
+ authToken: adminToken,
+ cleanup: cleanupOrg
+ } = await createIsolatedOrgAndProject("move-warnings"));
+
+ const connectionId = await createAwsAppConnection({
+ name: `move-warnings-${randomUUID().slice(0, 8)}`,
+ authToken: adminToken
+ });
+
+ for (const folder of [
+ { secretPath: "/", name: "apps" },
+ { secretPath: "/apps", name: "payments" },
+ { secretPath: "/", name: "flat" },
+ { secretPath: "/", name: "unsynced" }
+ ]) {
+ // eslint-disable-next-line no-await-in-loop
+ await createFolder({ authToken: adminToken, workspaceId: projectId, environmentSlug: ENV, ...folder });
+ }
+
+ for (const sync of [
+ { name: "apps-recursive", secretPath: "/apps", includeAllSubFolders: true },
+ { name: "flat-only", secretPath: "/flat", includeAllSubFolders: false }
+ ]) {
+ // eslint-disable-next-line no-await-in-loop
+ await createSecretSync({
+ ...sync,
+ projectId,
+ connectionId,
+ environmentSlug: ENV,
+ region: REGION,
+ destinationPath: `/${sync.name}/`,
+ authToken: adminToken
+ });
+ }
+
+ const username = `move-warnings-${alphaNumericNanoId(8)}@example.com`.toLowerCase();
+ const [user] = await testDb(TableName.Users)
+ .insert({ username, email: username, isGhost: false, isAccepted: true, authMethods: [AuthMethod.EMAIL] })
+ .returning("*");
+ noAccessUserId = user.id;
+
+ const [orgMembership] = await testDb(TableName.Membership)
+ .insert({
+ scope: AccessScope.Organization,
+ scopeOrgId: orgId,
+ actorUserId: noAccessUserId,
+ status: OrgMembershipStatus.Accepted,
+ isActive: true
+ })
+ .returning("*");
+ await testDb(TableName.MembershipRole).insert({ membershipId: orgMembership.id, role: OrgMembershipRole.Member });
+
+ const [projectMembership] = await testDb(TableName.Membership)
+ .insert({
+ scope: AccessScope.Project,
+ scopeOrgId: orgId,
+ scopeProjectId: projectId,
+ actorUserId: noAccessUserId
+ })
+ .returning("*");
+ await testDb(TableName.MembershipRole).insert({
+ membershipId: projectMembership.id,
+ role: ProjectMembershipRole.NoAccess
+ });
+
+ const sessionId = randomUUID();
+ await testDb(TableName.AuthTokenSession).insert({
+ id: sessionId,
+ userId: noAccessUserId,
+ ip: "127.0.0.1",
+ userAgent: "e2e-move-warnings",
+ accessVersion: 1,
+ refreshVersion: 1,
+ lastUsed: new Date()
+ } as never);
+
+ noAccessToken = jwt.sign(
+ {
+ authTokenType: AuthTokenType.ACCESS_TOKEN,
+ userId: noAccessUserId,
+ tokenVersionId: sessionId,
+ authMethod: AuthMethod.EMAIL,
+ organizationId: orgId,
+ accessVersion: 1
+ },
+ getConfig().AUTH_SECRET,
+ { expiresIn: 3600 }
+ );
+ });
+
+ afterAll(async () => {
+ await cleanupOrg();
+ await testDb(TableName.AuthTokenSession).where({ userId: noAccessUserId }).del();
+ await testDb(TableName.Users).where({ id: noAccessUserId }).del();
+ });
+
+ test("lists a recursive sync above the destination", async () => {
+ expect(await syncNames({ sourceSecretPath: "/", destinationSecretPath: "/apps/payments" })).toEqual([
+ "apps-recursive"
+ ]);
+ });
+
+ test("returns the sync's details", async () => {
+ const res = await getMoveWarnings({ sourceSecretPath: "/", destinationSecretPath: "/apps" });
+
+ expect(res.json().secretSyncs).toEqual([
+ expect.objectContaining({
+ name: "apps-recursive",
+ destination: "aws-parameter-store",
+ secretPath: "/apps",
+ includeAllSubFolders: true,
+ isAutoSyncEnabled: false
+ })
+ ]);
+ });
+
+ test("leaves out a sync that already covers the source", async () => {
+ expect(await syncNames({ sourceSecretPath: "/apps", destinationSecretPath: "/apps/payments" })).toEqual([]);
+ });
+
+ test("lists a non-recursive sync on the destination itself", async () => {
+ expect(await syncNames({ sourceSecretPath: "/", destinationSecretPath: "/flat" })).toEqual(["flat-only"]);
+ });
+
+ test("does not list a non-recursive sync for a folder moved beneath it", async () => {
+ // A folder lands at the destination plus its own name, which the non-recursive sync never reads.
+ expect(await syncNames({ sourceSecretPath: "/unsynced", destinationSecretPath: "/flat/unsynced" })).toEqual([]);
+ });
+
+ test("lists a recursive sync for a folder moved beneath it", async () => {
+ expect(await syncNames({ sourceSecretPath: "/unsynced", destinationSecretPath: "/apps/unsynced" })).toEqual([
+ "apps-recursive"
+ ]);
+ });
+
+ test("returns nothing for an unsynced destination", async () => {
+ expect(await syncNames({ sourceSecretPath: "/apps", destinationSecretPath: "/unsynced" })).toEqual([]);
+ });
+
+ test("withholds the details of a sync the actor cannot read", async () => {
+ const res = await getMoveWarnings({ sourceSecretPath: "/", destinationSecretPath: "/apps" }, noAccessToken);
+
+ expect(res.statusCode).toBe(200);
+ expect(res.json().secretSyncs).toEqual([
+ {
+ id: null,
+ name: null,
+ destination: null,
+ secretPath: null,
+ includeAllSubFolders: null,
+ isAutoSyncEnabled: null
+ }
+ ]);
+ });
+
+ test("names an environment that does not exist", async () => {
+ const res = await getMoveWarnings({
+ sourceSecretPath: "/",
+ destinationEnvironment: "missing-env",
+ destinationSecretPath: "/"
+ });
+
+ expect(res.statusCode).toBe(404);
+ expect(res.json().message).toContain('"missing-env"');
+ });
+});
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 032de566fe..a3a2f2b4ac 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -1506,6 +1506,23 @@ export const SECRET_IMPORTS = {
} as const;
export const DASHBOARD = {
+ MOVE_WARNINGS: {
+ projectId: "The ID of the project containing the items being moved or copied.",
+ sourceEnvironment: "The slug of the environment the items are moved or copied from.",
+ sourceSecretPath:
+ "The path the items live at now. For secrets, the folder holding them. For a folder, the folder's own path.",
+ destinationEnvironment: "The slug of the environment the items are moved or copied to.",
+ destinationSecretPath:
+ "The path the items will live at. For secrets, the destination folder. For a folder, the destination folder followed by the moved folder's name.",
+ secretSyncs:
+ "The secret syncs that cover the destination path but not the source path, so would start sending the items to their destination. Details of a sync you cannot read are null.",
+ syncId: "The ID of the secret sync.",
+ syncName: "The name of the secret sync.",
+ syncDestination: "The external service the secret sync sends secrets to.",
+ syncSecretPath: "The folder the secret sync reads secrets from.",
+ includeAllSubFolders: "Whether the secret sync also reads the folders beneath its path.",
+ isAutoSyncEnabled: "Whether the secret sync runs automatically when secrets change."
+ },
SECRET_METADATA_LIST: {
projectId: "The ID of the project containing the secrets.",
environment: "The slug of the environment containing the secrets.",
diff --git a/backend/src/server/routes/v1/dashboard-router.ts b/backend/src/server/routes/v1/dashboard-router.ts
index badc66e507..87409831d8 100644
--- a/backend/src/server/routes/v1/dashboard-router.ts
+++ b/backend/src/server/routes/v1/dashboard-router.ts
@@ -35,6 +35,7 @@ import {
SecretImportReferencesBehavior,
SecretsOrderBy
} from "@app/services/secret/secret-types";
+import { SecretSync } from "@app/services/secret-sync/secret-sync-enums";
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
import { SecretMetadataQuerySchema, SecretMetadataResponseSchema } from "./dashboard-secret-metadata-schemas";
@@ -2170,6 +2171,71 @@ export const registerDashboardRouter = async (server: FastifyZodProvider) => {
}
});
+ server.route({
+ method: "GET",
+ url: "/move-warnings",
+ config: {
+ rateLimit: readLimit
+ },
+ schema: {
+ operationId: "listMoveWarnings",
+ description:
+ "List what a user should know before moving or copying items from one path to another, such as secret syncs that would start sending them to an external service",
+ security: [
+ {
+ bearerAuth: []
+ }
+ ],
+ querystring: z.object({
+ projectId: z.string().trim().min(1).max(64).describe(DASHBOARD.MOVE_WARNINGS.projectId),
+ sourceEnvironment: z.string().trim().min(1).max(64).describe(DASHBOARD.MOVE_WARNINGS.sourceEnvironment),
+ sourceSecretPath: z
+ .string()
+ .trim()
+ .max(1000)
+ .default("/")
+ .transform(prefixWithSlash)
+ .transform(removeTrailingSlash)
+ .describe(DASHBOARD.MOVE_WARNINGS.sourceSecretPath),
+ destinationEnvironment: z
+ .string()
+ .trim()
+ .min(1)
+ .max(64)
+ .describe(DASHBOARD.MOVE_WARNINGS.destinationEnvironment),
+ destinationSecretPath: z
+ .string()
+ .trim()
+ .max(1000)
+ .default("/")
+ .transform(prefixWithSlash)
+ .transform(removeTrailingSlash)
+ .describe(DASHBOARD.MOVE_WARNINGS.destinationSecretPath)
+ }),
+ response: {
+ 200: z.object({
+ secretSyncs: z
+ .object({
+ id: z.string().nullable().describe(DASHBOARD.MOVE_WARNINGS.syncId),
+ name: z.string().nullable().describe(DASHBOARD.MOVE_WARNINGS.syncName),
+ destination: z.nativeEnum(SecretSync).nullable().describe(DASHBOARD.MOVE_WARNINGS.syncDestination),
+ secretPath: z.string().nullable().describe(DASHBOARD.MOVE_WARNINGS.syncSecretPath),
+ includeAllSubFolders: z.boolean().nullable().describe(DASHBOARD.MOVE_WARNINGS.includeAllSubFolders),
+ isAutoSyncEnabled: z.boolean().nullable().describe(DASHBOARD.MOVE_WARNINGS.isAutoSyncEnabled)
+ })
+ .array()
+ .describe(DASHBOARD.MOVE_WARNINGS.secretSyncs)
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.OAUTH]),
+ handler: async (req) => {
+ const secretSyncs = await server.services.secretSync.listSecretSyncsNewlyCoveringPath(req.query, req.permission);
+
+ return { secretSyncs };
+ }
+ });
+
server.route({
method: "GET",
url: "/folder/move-check/:folderId",
diff --git a/backend/src/services/secret-sync/secret-sync-queue.ts b/backend/src/services/secret-sync/secret-sync-queue.ts
index ec657b9f06..f79a415646 100644
--- a/backend/src/services/secret-sync/secret-sync-queue.ts
+++ b/backend/src/services/secret-sync/secret-sync-queue.ts
@@ -44,7 +44,7 @@ import {
import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
import { enterpriseSyncCheck, parseSyncErrorMessage, SecretSyncFns } from "@app/services/secret-sync/secret-sync-fns";
import { SECRET_SYNC_DAILY_RETRY_DESTINATIONS, SECRET_SYNC_NAME_MAP } from "@app/services/secret-sync/secret-sync-maps";
-import { buildSyncPayload, getAncestorPaths } from "@app/services/secret-sync/secret-sync-recursive-fns";
+import { buildSyncPayload, findSecretSyncsCoveringPath } from "@app/services/secret-sync/secret-sync-recursive-fns";
import {
SecretSyncAction,
SecretSyncStatus,
@@ -1052,27 +1052,12 @@ export const secretSyncQueueFactory = ({
const environment = await projectEnvDAL.findOne({ projectId, slug: environmentSlug });
if (!environment) return;
- const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, secretPath);
-
- const ancestorFolders = (
- await folderDAL.findByManySecretPath(
- getAncestorPaths(secretPath).map((path) => ({ envId: environment.id, secretPath: path }))
+ const secretSyncs = (
+ await findSecretSyncsCoveringPath(
+ { projectId, environment: { id: environment.id, slug: environmentSlug }, secretPath },
+ { folderDAL, secretSyncDAL }
)
- ).filter((entry): entry is NonNullable<typeof entry> => Boolean(entry));
-
- const candidateSyncs = await secretSyncDAL.find({
- $in: { folderId: [...ancestorFolders.map((entry) => entry.id), ...(folder ? [folder.id] : [])] },
- isAutoSyncEnabled: true
- });
-
- // A sync on the path itself always matches, whether or not it includes subfolders. A sync on an
- // ancestor folder only matches when it includes them, so a sync rooted above this path that does
- // not is never triggered by a change it was never configured to cover.
- const secretSyncs = candidateSyncs.filter(
- (sync) =>
- (folder && sync.folderId === folder.id) ||
- Boolean((sync.syncOptions as TSecretSync["syncOptions"])?.includeAllSubFolders)
- );
+ ).filter((sync) => sync.isAutoSyncEnabled);
await secretSyncDAL.update(
{
diff --git a/backend/src/services/secret-sync/secret-sync-recursive-fns.test.ts b/backend/src/services/secret-sync/secret-sync-recursive-fns.test.ts
index 6ef305a268..08feb3c158 100644
--- a/backend/src/services/secret-sync/secret-sync-recursive-fns.test.ts
+++ b/backend/src/services/secret-sync/secret-sync-recursive-fns.test.ts
@@ -1,5 +1,6 @@
import {
buildSyncPayload,
+ findSecretSyncsCoveringPath,
getAncestorPaths,
getSyncedFolders,
mergeImportedSecrets
@@ -98,6 +99,81 @@ describe("getAncestorPaths", () => {
});
});
+describe("findSecretSyncsCoveringPath", () => {
+ const folderIdByPath: Record<string, string> = {
+ "/": "root",
+ "/apps": "apps",
+ "/apps/payments": "payments"
+ };
+
+ const syncs = [
+ { id: "root-flat", folderId: "root", syncOptions: { includeAllSubFolders: false } },
+ { id: "apps-recursive", folderId: "apps", syncOptions: { includeAllSubFolders: true } },
+ { id: "payments-flat", folderId: "payments", syncOptions: {} }
+ ];
+
+ const toFolder = (path: string) => (folderIdByPath[path] ? { id: folderIdByPath[path], path } : undefined);
+
+ const coveringDeps = {
+ folderDAL: {
+ findBySecretPath: async (_projectId: string, _environment: string, path: string) => toFolder(path),
+ findByManySecretPath: async (queries: { secretPath: string }[]) =>
+ queries.map(({ secretPath }) => toFolder(secretPath))
+ },
+ secretSyncDAL: {
+ find: vi.fn(async ({ $in }: { $in: { folderId: string[] } }) =>
+ syncs.filter((sync) => $in.folderId.includes(sync.folderId))
+ )
+ }
+ } as unknown as Parameters<typeof findSecretSyncsCoveringPath>[1];
+
+ const coveringIds = async (secretPath: string) =>
+ (
+ await findSecretSyncsCoveringPath(
+ { projectId: "proj-1", environment: { id: "env-1", slug: "dev" }, secretPath },
+ coveringDeps
+ )
+ )
+ .map((sync) => sync.id)
+ .sort();
+
+ test("matches a sync on the path itself whether or not it includes subfolders", async () => {
+ expect(await coveringIds("/apps/payments")).toEqual(["apps-recursive", "payments-flat"]);
+ });
+
+ test("matches a sync on an ancestor only when it includes subfolders", async () => {
+ expect(await coveringIds("/apps")).toEqual(["apps-recursive"]);
+ });
+
+ test("matches ancestors of a path that does not exist yet", async () => {
+ // A folder being moved lands at a path that has no folder until the move runs.
+ expect(await coveringIds("/apps/payments/new")).toEqual(["apps-recursive"]);
+ });
+
+ test("matches the root sync for the root path", async () => {
+ expect(await coveringIds("/")).toEqual(["root-flat"]);
+ });
+
+ test("returns nothing without querying syncs when no folder on the path exists", async () => {
+ const find = vi.mocked(coveringDeps.secretSyncDAL.find);
+ find.mockClear();
+
+ const result = await findSecretSyncsCoveringPath(
+ { projectId: "proj-1", environment: { id: "env-2", slug: "prod" }, secretPath: "/missing" },
+ {
+ ...coveringDeps,
+ folderDAL: {
+ findBySecretPath: async () => undefined,
+ findByManySecretPath: async (queries: unknown[]) => queries.map(() => undefined)
+ } as unknown as Parameters<typeof findSecretSyncsCoveringPath>[1]["folderDAL"]
+ }
+ );
+
+ expect(result).toEqual([]);
+ expect(find).not.toHaveBeenCalled();
+ });
+});
+
describe("mergeImportedSecrets", () => {
const imported = (key: string, secretValue: string) => ({ key, secretValue }) as never;
diff --git a/backend/src/services/secret-sync/secret-sync-recursive-fns.ts b/backend/src/services/secret-sync/secret-sync-recursive-fns.ts
index 7fe27f10e7..66cd6adc68 100644
--- a/backend/src/services/secret-sync/secret-sync-recursive-fns.ts
+++ b/backend/src/services/secret-sync/secret-sync-recursive-fns.ts
@@ -6,6 +6,7 @@ import { TProjectFolderGrantDALFactory } from "@app/services/project-folder-gran
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
import { TSecretImportDALFactory } from "@app/services/secret-import/secret-import-dal";
import { fnSecretsV2FromImports } from "@app/services/secret-import/secret-import-fns";
+import { TSecretSyncDALFactory } from "@app/services/secret-sync/secret-sync-dal";
import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
import {
createSecretSyncPayload,
@@ -34,6 +35,43 @@ export const getAncestorPaths = (path: string): string[] => {
return segments.map((_, index) => (index === 0 ? "/" : `/${segments.slice(0, index).join("/")}`));
};
+// A sync on the path itself always covers it, whether or not it includes subfolders. A sync on an
+// ancestor folder only covers it when it includes them. The path need not exist yet: a folder being
+// moved has no folder at its landing path, and only the recursive syncs above it can cover it there.
+export const findSecretSyncsCoveringPath = async (
+ {
+ projectId,
+ environment,
+ secretPath
+ }: { projectId: string; environment: { id: string; slug: string }; secretPath: string },
+ {
+ folderDAL,
+ secretSyncDAL
+ }: {
+ folderDAL: Pick<TSecretFolderDALFactory, "findBySecretPath" | "findByManySecretPath">;
+ secretSyncDAL: Pick<TSecretSyncDALFactory, "find">;
+ }
+) => {
+ const folder = await folderDAL.findBySecretPath(projectId, environment.slug, secretPath);
+
+ const ancestorFolders = (
+ await folderDAL.findByManySecretPath(
+ getAncestorPaths(secretPath).map((path) => ({ envId: environment.id, secretPath: path }))
+ )
+ ).filter((entry): entry is NonNullable<typeof entry> => Boolean(entry));
+
+ const folderIds = [...ancestorFolders.map((entry) => entry.id), ...(folder ? [folder.id] : [])];
+ if (!folderIds.length) return [];
+
+ const candidateSyncs = await secretSyncDAL.find({ $in: { folderId: folderIds } });
+
+ return candidateSyncs.filter(
+ (sync) =>
+ (folder && sync.folderId === folder.id) ||
+ Boolean((sync.syncOptions as TSecretSync["syncOptions"])?.includeAllSubFolders)
+ );
+};
+
export const getSyncedFolders = async ({
folderDAL,
projectEnvDAL,
diff --git a/backend/src/services/secret-sync/secret-sync-service.ts b/backend/src/services/secret-sync/secret-sync-service.ts
index 95f8ae126e..f5a0cbd1c3 100644
--- a/backend/src/services/secret-sync/secret-sync-service.ts
+++ b/backend/src/services/secret-sync/secret-sync-service.ts
@@ -34,7 +34,11 @@ import {
preSaveTransformDestinationConfig,
preSaveTransformSyncOptions
} from "@app/services/secret-sync/secret-sync-fns";
-import { buildSyncPayload, getSyncedFolders } from "@app/services/secret-sync/secret-sync-recursive-fns";
+import {
+ buildSyncPayload,
+ findSecretSyncsCoveringPath,
+ getSyncedFolders
+} from "@app/services/secret-sync/secret-sync-recursive-fns";
import {
SecretSyncStatus,
TCheckDuplicateDestinationDTO,
@@ -45,6 +49,7 @@ import {
TFindSecretSyncByNameDTO,
TListSecretSyncsByFolderId,
TListSecretSyncsByProjectId,
+ TListSecretSyncsNewlyCoveringPathDTO,
TSecretSync,
TTriggerSecretSyncImportSecretsByIdDTO,
TTriggerSecretSyncRemoveSecretsByIdDTO,
@@ -431,6 +436,77 @@ export const secretSyncServiceFactory = ({
) as TSecretSync[];
};
+ // The syncs that would start sending an item to their destination if it were moved or copied from the
+ // source path to the destination path. A sync that already covers the source is left out, since the
+ // item already reaches it. Any project member gets the list, so the warning still reaches an actor
+ // who cannot read the syncs themselves; only the details of those syncs are withheld.
+ const listSecretSyncsNewlyCoveringPath = async (
+ {
+ projectId,
+ sourceEnvironment,
+ sourceSecretPath,
+ destinationEnvironment,
+ destinationSecretPath
+ }: TListSecretSyncsNewlyCoveringPathDTO,
+ actor: OrgServiceActor
+ ) => {
+ const { permission } = await permissionService.getProjectPermission({
+ actor: actor.type,
+ actorId: actor.id,
+ actorAuthMethod: actor.authMethod,
+ actorOrgId: actor.orgId,
+ actionProjectType: ActionProjectType.SecretManager,
+ projectId
+ });
+
+ const [sourceEnv, destinationEnv] = await Promise.all([
+ projectEnvDAL.findOne({ projectId, slug: sourceEnvironment }),
+ projectEnvDAL.findOne({ projectId, slug: destinationEnvironment })
+ ]);
+
+ if (!sourceEnv) throw new NotFoundError({ message: `Could not find environment with slug "${sourceEnvironment}"` });
+ if (!destinationEnv)
+ throw new NotFoundError({ message: `Could not find environment with slug "${destinationEnvironment}"` });
+
+ const [sourceSyncs, destinationSyncs] = await Promise.all([
+ findSecretSyncsCoveringPath(
+ { projectId, environment: sourceEnv, secretPath: sourceSecretPath },
+ { folderDAL, secretSyncDAL }
+ ),
+ findSecretSyncsCoveringPath(
+ { projectId, environment: destinationEnv, secretPath: destinationSecretPath },
+ { folderDAL, secretSyncDAL }
+ )
+ ]);
+
+ const sourceSyncIds = new Set(sourceSyncs.map((sync) => sync.id));
+
+ return destinationSyncs
+ .filter((sync) => !sourceSyncIds.has(sync.id))
+ .sort((a, b) => a.name.localeCompare(b.name))
+ .map((sync) => {
+ if (permission.cannot(ProjectPermissionSecretSyncActions.Read, getSecretSyncSubject(sync))) {
+ return {
+ id: null,
+ name: null,
+ destination: null,
+ secretPath: null,
+ includeAllSubFolders: null,
+ isAutoSyncEnabled: null
+ };
+ }
+
+ return {
+ id: sync.id,
+ name: sync.name,
+ destination: sync.destination as SecretSync,
+ secretPath: sync.folder?.path ?? null,
+ includeAllSubFolders: Boolean((sync.syncOptions as TSecretSync["syncOptions"])?.includeAllSubFolders),
+ isAutoSyncEnabled: sync.isAutoSyncEnabled
+ };
+ });
+ };
+
const findSecretSyncById = async ({ destination, syncId }: TFindSecretSyncByIdDTO, actor: OrgServiceActor) => {
const secretSync = await secretSyncDAL.findById(syncId);
@@ -1237,6 +1313,7 @@ export const secretSyncServiceFactory = ({
triggerSecretSyncImportSecretsById,
triggerSecretSyncRemoveSecretsById,
checkDuplicateDestination,
- findRecursiveConflicts
+ findRecursiveConflicts,
+ listSecretSyncsNewlyCoveringPath
};
};
diff --git a/backend/src/services/secret-sync/secret-sync-types.ts b/backend/src/services/secret-sync/secret-sync-types.ts
index a878de7147..e071337508 100644
--- a/backend/src/services/secret-sync/secret-sync-types.ts
+++ b/backend/src/services/secret-sync/secret-sync-types.ts
@@ -506,6 +506,14 @@ export type TFindRecursiveSyncConflictsDTO = {
keySchema?: string;
};
+export type TListSecretSyncsNewlyCoveringPathDTO = {
+ projectId: string;
+ sourceEnvironment: string;
+ sourceSecretPath: string;
+ destinationEnvironment: string;
+ destinationSecretPath: string;
+};
+
export enum SecretSyncStatus {
Pending = "pending",
Running = "running",
diff --git a/frontend/src/components/secret-syncs/SecretSyncMoveWarning.tsx b/frontend/src/components/secret-syncs/SecretSyncMoveWarning.tsx
new file mode 100644
index 0000000000..a99559afaf
--- /dev/null
+++ b/frontend/src/components/secret-syncs/SecretSyncMoveWarning.tsx
@@ -0,0 +1,124 @@
+import { useState } from "react";
+import { Link } from "@tanstack/react-router";
+import { ExternalLinkIcon, TriangleAlertIcon } from "lucide-react";
+
+import { Alert, AlertDescription, AlertTitle, Checkbox, Label } from "@app/components/v3";
+import { ROUTE_PATHS } from "@app/const/routes";
+import { useOrganization } from "@app/context";
+import { SECRET_SYNC_MAP } from "@app/helpers/secretSyncs";
+import { useGetMoveWarnings } from "@app/hooks/api/dashboard/queries";
+import { TMoveWarningsCheck } from "@app/hooks/api/dashboard/types";
+
+// the acknowledgement is tied to the checks it was given for, so changing the destination clears it
+// and a user never carries a yes over to a path they have not seen the warning for.
+export const useSecretSyncMoveWarning = (checks: TMoveWarningsCheck[]) => {
+ const warnings = useGetMoveWarnings(checks);
+ const checksKey = JSON.stringify(checks);
+ const [acknowledgedChecksKey, setAcknowledgedChecksKey] = useState<string | null>(null);
+
+ const isAcknowledged = acknowledgedChecksKey === checksKey;
+ const needsAcknowledgement =
+ warnings.hasError || warnings.hasHiddenSecretSyncs || warnings.secretSyncs.length > 0;
+
+ return {
+ ...warnings,
+ needsAcknowledgement,
+ isAcknowledged,
+ setIsAcknowledged: (value: boolean) => setAcknowledgedChecksKey(value ? checksKey : null),
+ isBlockingSubmit: warnings.isChecking || (needsAcknowledgement && !isAcknowledged)
+ };
+};
+
+type Props = {
+ warning: ReturnType<typeof useSecretSyncMoveWarning>;
+ projectId: string;
+ noun: string;
+ verb: "moved" | "copied";
+};
+
+const getTitle = ({
+ subject,
+ visibleCount,
+ hasHidden,
+ hasError
+}: {
+ subject: string;
+ visibleCount: number;
+ hasHidden: boolean;
+ hasError: boolean;
+}) => {
+ if (hasError) return "Could not check the destination for secret syncs";
+ if (hasHidden) return `${subject} here will be synced to external destinations`;
+ return `${subject} here will be synced to ${visibleCount} external destination${visibleCount === 1 ? "" : "s"}`;
+};
+
+export const SecretSyncMoveWarning = ({ warning, projectId, noun, verb }: Props) => {
+ const { currentOrg } = useOrganization();
+ const { needsAcknowledgement, isChecking, hasError, hasHiddenSecretSyncs, secretSyncs } = warning;
+
+ if (isChecking || !needsAcknowledgement) return null;
+
+ return (
+ <Alert variant="warning">
+ <TriangleAlertIcon />
+ <AlertTitle>
+ {getTitle({
+ subject: `${noun.charAt(0).toUpperCase()}${noun.slice(1)} ${verb}`,
+ visibleCount: secretSyncs.length,
+ hasHidden: hasHiddenSecretSyncs,
+ hasError
+ })}
+ </AlertTitle>
+ <AlertDescription>
+ {hasError && <p>Secret syncs may send these {noun} to external destinations.</p>}
+ {secretSyncs.length > 0 && (
+ <ul className="list-disc pl-4">
+ {secretSyncs.map((sync) => (
+ <li key={sync.id}>
+ <span className="font-medium text-foreground">{sync.name}</span>
+ {` (${SECRET_SYNC_MAP[sync.destination].name}) syncs `}
+ <code>{sync.secretPath ?? "/"}</code>
+ {sync.includeAllSubFolders ? " and all its subfolders." : "."}
+ {!sync.isAutoSyncEnabled &&
+ " Auto-sync is off, so it sends them on its next manual sync."}{" "}
+ <Link
+ to={ROUTE_PATHS.SecretManager.SecretSyncDetailsByIDPage.path}
+ params={{
+ orgId: currentOrg.id,
+ projectId,
+ destination: sync.destination,
+ syncId: sync.id
+ }}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="inline-flex items-center gap-1 underline underline-offset-2"
+ >
+ View Sync
+ <ExternalLinkIcon className="size-3" />
+ </Link>
+ </li>
+ ))}
+ </ul>
+ )}
+ {hasHiddenSecretSyncs && (
+ <p>
+ {secretSyncs.length
+ ? "Other secret syncs you don't have access to also cover the destination."
+ : "Secret syncs you don't have access to cover the destination."}
+ </p>
+ )}
+ <div className="mt-2 flex items-center gap-2">
+ <Checkbox
+ id="secret-sync-move-warning-acknowledgement"
+ variant="warning"
+ isChecked={warning.isAcknowledged}
+ onCheckedChange={(checked) => warning.setIsAcknowledged(checked === true)}
+ />
+ <Label htmlFor="secret-sync-move-warning-acknowledgement">
+ I understand these {noun} {hasError ? "may" : "will"} be synced to external destinations
+ </Label>
+ </div>
+ </AlertDescription>
+ </Alert>
+ );
+};
diff --git a/frontend/src/hooks/api/dashboard/queries.tsx b/frontend/src/hooks/api/dashboard/queries.tsx
index 4b896c03da..08e1f23029 100644
--- a/frontend/src/hooks/api/dashboard/queries.tsx
+++ b/frontend/src/hooks/api/dashboard/queries.tsx
@@ -23,6 +23,9 @@ import {
TGetDashboardProjectSecretsQuickSearchDTO,
TGetSecretMetadataDTO,
TGetSecretValueDTO,
+ TMoveWarningsCheck,
+ TMoveWarningSecretSync,
+ TMoveWarningsResponse,
TSearchSecretsByMetadataDTO,
TSearchSecretsByMetadataResponse,
TSecretMetadataPage
@@ -114,7 +117,9 @@ export const dashboardKeys = {
folderId,
destinationEnvironment,
destinationPath
- ] as const
+ ] as const,
+ getMoveWarnings: (check: TMoveWarningsCheck) =>
+ [...dashboardKeys.all(), "move-warnings", check] as const
};
export const fetchSecretMetadata = async (params: TGetSecretMetadataDTO, signal?: AbortSignal) => {
@@ -773,3 +778,51 @@ export const useGetFoldersMoveDestinationEligibility = (checks: TFolderMoveDesti
return { isChecking, isDestinationBlocked, blockedDestinations, hasError };
}
});
+
+export type TVisibleMoveWarningSecretSync = TMoveWarningSecretSync & {
+ id: string;
+ name: string;
+ destination: NonNullable<TMoveWarningSecretSync["destination"]>;
+};
+
+// fans out one check per (source, destination) pair, since a copy or multi-environment move writes to
+// several destinations. syncs the actor cannot read come back without an id, so they cannot be deduped
+// across checks and are only reported as present.
+export const useGetMoveWarnings = (checks: TMoveWarningsCheck[]) =>
+ useQueries({
+ queries: checks.map((check) => ({
+ queryKey: dashboardKeys.getMoveWarnings(check),
+ queryFn: async () => {
+ const { data } = await apiRequest.get<TMoveWarningsResponse>(
+ "/api/v1/dashboard/move-warnings",
+ { params: check }
+ );
+ return data;
+ },
+ enabled: Boolean(check.projectId && check.sourceEnvironment && check.destinationEnvironment)
+ })),
+ combine: (results) => {
+ const seen = new Set<string>();
+ const secretSyncs: TVisibleMoveWarningSecretSync[] = [];
+ let hasHiddenSecretSyncs = false;
+
+ results.forEach(({ data }) => {
+ data?.secretSyncs.forEach((sync) => {
+ if (!sync.id || !sync.name || !sync.destination) {
+ hasHiddenSecretSyncs = true;
+ return;
+ }
+ if (seen.has(sync.id)) return;
+ seen.add(sync.id);
+ secretSyncs.push(sync as TVisibleMoveWarningSecretSync);
+ });
+ });
+
+ return {
+ isChecking: results.some((result) => result.isLoading),
+ hasError: results.some((result) => result.isError),
+ secretSyncs,
+ hasHiddenSecretSyncs
+ };
+ }
+ });
diff --git a/frontend/src/hooks/api/dashboard/types.ts b/frontend/src/hooks/api/dashboard/types.ts
index 90b7dd64f2..9c15380e09 100644
--- a/frontend/src/hooks/api/dashboard/types.ts
+++ b/frontend/src/hooks/api/dashboard/types.ts
@@ -7,6 +7,7 @@ import { TSecretFolder } from "@app/hooks/api/secretFolders/types";
import { TSecretImport } from "@app/hooks/api/secretImports/types";
import { TSecretRotationV2 } from "@app/hooks/api/secretRotationsV2";
import { SecretV3Raw, SecretV3RawSanitized } from "@app/hooks/api/secrets/types";
+import { SecretSync } from "@app/hooks/api/secretSyncs/enums";
export type DashboardProjectSecretsOverviewResponse = {
folders?: (TSecretFolder & { environment: string })[];
@@ -285,6 +286,29 @@ export type FolderMoveEligibilityResponse = {
hasRbacPolicies?: boolean;
};
+// for a folder, the paths are the folder's own path and the path it will have once moved
+export type TMoveWarningsCheck = {
+ projectId: string;
+ sourceEnvironment: string;
+ sourceSecretPath: string;
+ destinationEnvironment: string;
+ destinationSecretPath: string;
+};
+
+// every field is null when the actor cannot read the sync
+export type TMoveWarningSecretSync = {
+ id: string | null;
+ name: string | null;
+ destination: SecretSync | null;
+ secretPath: string | null;
+ includeAllSubFolders: boolean | null;
+ isAutoSyncEnabled: boolean | null;
+};
+
+export type TMoveWarningsResponse = {
+ secretSyncs: TMoveWarningSecretSync[];
+};
+
export type TFolderMoveDestinationCheck = {
folderId: string;
folderName: string;
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx
index d52c4d4bdc..92a8b2784f 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/CopySecretsSheet/CopySecretsSheet.tsx
@@ -8,6 +8,10 @@ import {
} from "lucide-react";
import { createNotification } from "@app/components/notifications";
+import {
+ SecretSyncMoveWarning,
+ useSecretSyncMoveWarning
+} from "@app/components/secret-syncs/SecretSyncMoveWarning";
import {
Alert,
AlertDescription,
@@ -193,6 +197,20 @@ const CopySecretsSession = ({
destinationRootPath: normalizedDestinationPath,
includeValues
});
+ const secretSyncWarning = useSecretSyncMoveWarning(
+ sourceEnvironmentSlug &&
+ destinationEnvironmentSlug &&
+ isSourcePathSettled &&
+ isDestinationPathSettled
+ ? requestGroups.map((group) => ({
+ projectId,
+ sourceEnvironment: sourceEnvironmentSlug,
+ sourceSecretPath: group.sourcePath,
+ destinationEnvironment: destinationEnvironmentSlug,
+ destinationSecretPath: group.destinationPath
+ }))
+ : []
+ );
const destinationFolderPaths = getCopyDestinationFolderPaths({
folderPaths: selectedFolderPaths,
sourceRootPath: normalizedSourcePath,
@@ -326,6 +344,8 @@ const CopySecretsSession = ({
if (destinationErrorKind === "forbidden") return "Destination access is required";
if (isDestinationLoading) return "Loading destination secrets";
if (!selectedItemCount) return "Select at least one secret or folder";
+ if (secretSyncWarning.isChecking) return "Checking the destination for secret syncs";
+ if (secretSyncWarning.isBlockingSubmit) return "Confirm the secret sync warning to copy";
if (
destinationFolderSteps.some(
({ parentPath }) => !canCreateFoldersAt(destinationEnvironmentSlug, parentPath)
@@ -742,6 +762,13 @@ const CopySecretsSession = ({
<span className="font-mono text-foreground">{normalizedDestinationPath}</span>,
including empty folders. Managed secrets, dynamic secrets, and imports are excluded.
</p>
+
+ <SecretSyncMoveWarning
+ warning={secretSyncWarning}
+ projectId={projectId}
+ noun={selectedFolderPaths.length ? "items" : "secrets"}
+ verb="copied"
+ />
</div>
<SheetFooter className="flex-wrap items-center border-t">
diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx
index 95f86477b4..bc91d1a6ba 100644
--- a/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx
+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SelectionPanel/components/MoveSecretsDialog/MoveSecretsDialog.tsx
@@ -17,6 +17,10 @@ import { twMerge } from "tailwind-merge";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
+import {
+ SecretSyncMoveWarning,
+ useSecretSyncMoveWarning
+} from "@app/components/secret-syncs/SecretSyncMoveWarning";
import {
Alert,
AlertDescription,
@@ -62,7 +66,8 @@ import {
} from "@app/hooks/api/dashboard/queries";
import {
FolderMoveBlockingType,
- TFolderMoveDestinationCheck
+ TFolderMoveDestinationCheck,
+ TMoveWarningsCheck
} from "@app/hooks/api/dashboard/types";
import { ProjectEnv } from "@app/hooks/api/projects/types";
import {
@@ -540,6 +545,45 @@ const buildDestinationTargets = ({
return { checks: isSelfMove ? [] : checks, isSelfMove };
};
+// a secret lands in the destination folder itself, a folder at the destination folder plus its own name.
+// each secret environment and each moved folder gets its own check, since a sync covers one path in one
+// environment.
+const buildMoveWarningChecks = ({
+ projectId,
+ sourceSecretPath,
+ destinationPath,
+ secretEnvironments,
+ movedFolders
+}: {
+ projectId: string;
+ sourceSecretPath: string;
+ destinationPath?: string;
+ secretEnvironments: { sourceEnv: string; destinationEnvironment: string }[];
+ movedFolders: MovedFolder[];
+}): TMoveWarningsCheck[] => {
+ if (!destinationPath) return [];
+
+ const destination = removeTrailingSlash(destinationPath);
+ const base = removeTrailingSlash(sourceSecretPath);
+
+ return [
+ ...secretEnvironments.map(({ sourceEnv, destinationEnvironment }) => ({
+ projectId,
+ sourceEnvironment: sourceEnv,
+ sourceSecretPath: base,
+ destinationEnvironment,
+ destinationSecretPath: destination
+ })),
+ ...movedFolders.map(({ folderName, sourceEnv, destinationEnvironment }) => ({
+ projectId,
+ sourceEnvironment: sourceEnv,
+ sourceSecretPath: joinSecretPath(base, folderName),
+ destinationEnvironment,
+ destinationSecretPath: joinSecretPath(destination, folderName)
+ }))
+ ];
+};
+
// memoizes the destination checks for the moved folders and runs the destination approval-policy eligibility
// query, returning what the move form needs to gate submit. shared by the single- and multi-environment content
// so the wiring lives in one place.
@@ -878,6 +922,35 @@ const SingleEnvContent = ({
destinationPath: destinationSelected ? selectedPath?.secretPath : undefined
});
+ const hasSecretsToMove =
+ Object.values(secrets).some((secretRecord) => Boolean(secretRecord[sourceEnv.slug])) ||
+ Object.values(rotations).some((rotationRecord) => Boolean(rotationRecord[sourceEnv.slug]));
+
+ const moveWarningChecks = useMemo(
+ () =>
+ buildMoveWarningChecks({
+ projectId,
+ sourceSecretPath,
+ destinationPath: destinationSelected && !isSelfMove ? selectedPath?.secretPath : undefined,
+ secretEnvironments: hasSecretsToMove
+ ? [{ sourceEnv: sourceEnv.slug, destinationEnvironment: selectedEnvironment }]
+ : [],
+ movedFolders
+ }),
+ [
+ projectId,
+ sourceSecretPath,
+ destinationSelected,
+ isSelfMove,
+ selectedPath?.secretPath,
+ hasSecretsToMove,
+ sourceEnv.slug,
+ selectedEnvironment,
+ movedFolders
+ ]
+ );
+ const secretSyncWarning = useSecretSyncMoveWarning(moveWarningChecks);
+
const handleFormSubmit = async (data: TSingleEnvFormSchema) => {
if (!selectedPath) {
createNotification({
@@ -1106,6 +1179,12 @@ const SingleEnvContent = ({
environments={environments}
/>
<FolderRbacPoliciesWarning folderNames={foldersWithRbacPolicies} />
+ <SecretSyncMoveWarning
+ warning={secretSyncWarning}
+ projectId={projectId}
+ noun={moveCopy.noun}
+ verb="moved"
+ />
<DialogFooter className="items-center">
{showOverwriteOption && (
<Controller
@@ -1135,7 +1214,8 @@ const SingleEnvContent = ({
isCreatingFolder ||
isSelfMove ||
isCheckingDestination ||
- isDestinationBlocked
+ isDestinationBlocked ||
+ secretSyncWarning.isBlockingSubmit
}
isPending={isSubmitting}
>
@@ -1261,6 +1341,38 @@ const MultiEnvContent = ({
destinationPath: destinationSelected ? selectedPath?.secretPath : undefined
});
+ const moveWarningChecks = useMemo(
+ () =>
+ buildMoveWarningChecks({
+ projectId,
+ sourceSecretPath,
+ destinationPath: destinationSelected && !isSelfMove ? selectedPath?.secretPath : undefined,
+ secretEnvironments: environments
+ .filter(
+ ({ slug }) =>
+ (Object.values(secrets).some((secretRecord) => Boolean(secretRecord[slug])) &&
+ !moveEligibility[slug].cannotMoveSecrets) ||
+ (Object.values(rotations).some((rotationRecord) => Boolean(rotationRecord[slug])) &&
+ !moveEligibility[slug].cannotMoveRotations)
+ )
+ .map(({ slug }) => ({ sourceEnv: slug, destinationEnvironment: slug })),
+ movedFolders
+ }),
+ [
+ projectId,
+ sourceSecretPath,
+ destinationSelected,
+ isSelfMove,
+ selectedPath?.secretPath,
+ environments,
+ secrets,
+ rotations,
+ moveEligibility,
+ movedFolders
+ ]
+ );
+ const secretSyncWarning = useSecretSyncMoveWarning(moveWarningChecks);
+
const environmentsToBeSkipped = useMemo(() => {
if (!destinationSelected) return [];
@@ -1575,6 +1687,12 @@ const MultiEnvContent = ({
environments={environments}
/>
<FolderRbacPoliciesWarning folderNames={foldersWithRbacPolicies} />
+ <SecretSyncMoveWarning
+ warning={secretSyncWarning}
+ projectId={projectId}
+ noun={moveCopy.noun}
+ verb="moved"
+ />
<DialogFooter className="items-center">
{showOverwriteOption && (
<Controller
@@ -1604,7 +1722,8 @@ const MultiEnvContent = ({
isCreatingFolder ||
isSelfMove ||
isCheckingDestination ||
- isDestinationBlocked
+ isDestinationBlocked ||
+ secretSyncWarning.isBlockingSubmit
}
isPending={isSubmitting}
>