Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: pr feedback
IgorHorta80d968818d0b
diff --git a/backend/src/ee/services/permission/project-permission.ts b/backend/src/ee/services/permission/project-permission.tsindex cabeebd6d1..5769644558 100644--- a/backend/src/ee/services/permission/project-permission.ts+++ b/backend/src/ee/services/permission/project-permission.ts@@ -329,8 +329,8 @@ export type SecretFolderSubjectFields = {};export type SecretSyncSubjectFields = {- environment: string;- secretPath: string;+ environment?: string;+ secretPath?: string;connectionId?: string;};@@ -354,8 +354,8 @@ export type SecretImportSubjectFields = {};export type SecretRotationsSubjectFields = {- environment: string;- secretPath: string;+ environment?: string;+ secretPath?: string;connectionId?: string;};diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.tsindex 66cfad75a0..174b610100 100644--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts@@ -239,6 +239,26 @@ export const secretRotationV2ServiceFactory = ({}};+ const getSecretRotationSubject = (+ rotation: {+ environment?: { slug: string };+ folder?: { path: string };+ connection?: { id: string };+ },+ overrides?: { environment?: string; secretPath?: string; connectionId?: string }+ ) => {+ const connectionId = overrides?.connectionId ?? rotation.connection?.id;+ const envSlug = overrides?.environment ?? rotation.environment?.slug;+ const secretPath = overrides?.secretPath ?? rotation.folder?.path;+ const hasAny = connectionId || envSlug || secretPath;+ if (!hasAny) return ProjectPermissionSub.SecretRotation;+ return subject(ProjectPermissionSub.SecretRotation, {+ ...(envSlug && { environment: envSlug }),+ ...(secretPath && { secretPath }),+ ...(connectionId && { connectionId })+ });+ };+const listSecretRotationsByProjectId = async ({ projectId, type }: TListSecretRotationsV2ByProjectId,actor: OrgServiceActor@@ -272,14 +292,7 @@ export const secretRotationV2ServiceFactory = ({return Promise.all(secretRotations.filter((rotation) =>- permission.can(- ProjectPermissionSecretRotationActions.Read,- subject(ProjectPermissionSub.SecretRotation, {- environment: rotation.environment.slug,- secretPath: rotation.folder.path,- connectionId: rotation.connection.id- })- )+ permission.can(ProjectPermissionSecretRotationActions.Read, getSecretRotationSubject(rotation))).map((rotation) => expandSecretRotation(rotation, kmsService)));@@ -313,11 +326,7 @@ export const secretRotationV2ServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretRotationActions.Read,- subject(ProjectPermissionSub.SecretRotation, {- environment: environment.slug,- secretPath: folder.path,- connectionId: connection.id- })+ getSecretRotationSubject(secretRotation));if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])@@ -360,11 +369,7 @@ export const secretRotationV2ServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretRotationActions.ReadGeneratedCredentials,- subject(ProjectPermissionSub.SecretRotation, {- environment: environment.slug,- secretPath: folder.path,- connectionId: connection.id- })+ getSecretRotationSubject(secretRotation));if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])@@ -426,11 +431,7 @@ export const secretRotationV2ServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretRotationActions.Read,- subject(ProjectPermissionSub.SecretRotation, {- environment,- secretPath,- connectionId: connection.id- })+ getSecretRotationSubject(secretRotation));if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])@@ -479,10 +480,10 @@ export const secretRotationV2ServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretRotationActions.Create,- subject(ProjectPermissionSub.SecretRotation, {- environment,- secretPath,- ...(payload.connectionId && { connectionId: payload.connectionId })+ getSecretRotationSubject({+ environment: { slug: environment },+ folder: { path: secretPath },+ connection: payload.connectionId ? { id: payload.connectionId } : undefined}));@@ -682,11 +683,7 @@ export const secretRotationV2ServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretRotationActions.Edit,- subject(ProjectPermissionSub.SecretRotation, {- environment: environment.slug,- secretPath: folder.path,- connectionId: connection.id- })+ getSecretRotationSubject(secretRotation));if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])@@ -833,11 +830,7 @@ export const secretRotationV2ServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretRotationActions.Delete,- subject(ProjectPermissionSub.SecretRotation, {- environment: environment.slug,- secretPath: folder.path,- connectionId: connection.id- })+ getSecretRotationSubject(secretRotation));if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])@@ -1168,11 +1161,7 @@ export const secretRotationV2ServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretRotationActions.RotateSecrets,- subject(ProjectPermissionSub.SecretRotation, {- environment: environment.slug,- secretPath: folder.path,- connectionId: connection.id- })+ getSecretRotationSubject(secretRotation));if (connection.app !== SECRET_ROTATION_CONNECTION_MAP[type])@@ -1244,14 +1233,7 @@ export const secretRotationV2ServiceFactory = ({const rotationsForCount = secretRotations as TSecretRotationV2PermissionContext[];const count = rotationsForCount.filter((rotation) =>- permission.can(- ProjectPermissionSecretRotationActions.Read,- subject(ProjectPermissionSub.SecretRotation, {- environment: rotation.environment.slug,- secretPath: rotation.folder.path,- connectionId: rotation.connection.id- })- )+ permission.can(ProjectPermissionSecretRotationActions.Read, getSecretRotationSubject(rotation))).length;return count;@@ -1317,14 +1299,7 @@ export const secretRotationV2ServiceFactory = ({// Filter by per-rotation permission so connectionId (and other) restrictions are enforced.const secretRotations = secretRotationsRaw.filter((rotation: TSecretRotationV2PermissionContext) =>- permission.can(- ProjectPermissionSecretRotationActions.Read,- subject(ProjectPermissionSub.SecretRotation, {- environment: rotation.environment.slug,- secretPath: rotation.folder.path,- connectionId: rotation.connection.id- })- )+ permission.can(ProjectPermissionSecretRotationActions.Read, getSecretRotationSubject(rotation)));const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({@@ -1441,14 +1416,7 @@ export const secretRotationV2ServiceFactory = ({// Filter by per-rotation permission so connectionId (and other) restrictions are enforced.return secretRotations.filter((rotation) =>- permission.can(- ProjectPermissionSecretRotationActions.Read,- subject(ProjectPermissionSub.SecretRotation, {- environment: rotation.environment.slug,- secretPath: rotation.folder.path,- connectionId: rotation.connection.id- })- )+ permission.can(ProjectPermissionSecretRotationActions.Read, getSecretRotationSubject(rotation))) as TSecretRotationV2[];};@@ -1496,11 +1464,7 @@ export const secretRotationV2ServiceFactory = ({ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretRotationActions.RotateSecrets,- subject(ProjectPermissionSub.SecretRotation, {- environment: environment.slug,- secretPath: folder.path,- connectionId: connection.id- })+ getSecretRotationSubject(secretRotation));const localAccountParams = parameters as TLocalAccountRotation["parameters"];diff --git a/backend/src/services/secret-sync/secret-sync-service.ts b/backend/src/services/secret-sync/secret-sync-service.tsindex e4d2cd2c7d..bcaa888da0 100644--- a/backend/src/services/secret-sync/secret-sync-service.ts+++ b/backend/src/services/secret-sync/secret-sync-service.ts@@ -7,8 +7,7 @@ import { TPermissionServiceFactory } from "@app/ee/services/permission/permissioimport {ProjectPermissionSecretActions,ProjectPermissionSecretSyncActions,- ProjectPermissionSub,- type SecretSyncSubjectFields+ ProjectPermissionSub} from "@app/ee/services/permission/project-permission";import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";import { DatabaseErrorCode } from "@app/lib/error-codes";@@ -80,6 +79,30 @@ export const secretSyncServiceFactory = ({keyStore,licenseService}: TSecretSyncServiceFactoryDep) => {+ const getConnectionId = (sync: { connectionId?: string; connection?: { id: string } }) =>+ sync.connectionId ?? sync.connection?.id;++ const getSecretSyncSubject = (+ sync: {+ environment?: { slug: string } | null;+ folder?: { path: string } | null;+ connectionId?: string;+ connection?: { id: string };+ },+ overrides?: { connectionId?: string }+ ) => {+ const connectionId = overrides?.connectionId ?? getConnectionId(sync);+ const envSlug = sync.environment?.slug;+ const secretPath = sync.folder?.path;+ const hasAny = connectionId || envSlug || secretPath;+ if (!hasAny) return ProjectPermissionSub.SecretSyncs;+ return subject(ProjectPermissionSub.SecretSyncs, {+ ...(envSlug && { environment: envSlug }),+ ...(secretPath && { secretPath }),+ ...(connectionId && { connectionId })+ });+ };+const listSecretSyncsByProjectId = async ({ projectId, destination }: TListSecretSyncsByProjectId,actor: OrgServiceActor@@ -103,20 +126,8 @@ export const secretSyncServiceFactory = ({projectId});- const getConnectionId = (sync: { connectionId?: string; connection?: { id: string } }) =>- sync.connectionId ?? sync.connection?.id;-return secretSyncs.filter((secretSync) =>- permission.can(- ProjectPermissionSecretSyncActions.Read,- secretSync.environment && secretSync.folder- ? subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- ...(getConnectionId(secretSync) && { connectionId: getConnectionId(secretSync) })- })- : ProjectPermissionSub.SecretSyncs- )+ permission.can(ProjectPermissionSecretSyncActions.Read, getSecretSyncSubject(secretSync))) as TSecretSync[];};@@ -156,21 +167,9 @@ export const secretSyncServiceFactory = ({}});- // Filter by per-sync permission so connectionId (and other) restrictions are enforced.- const getConnectionId = (sync: { connectionId?: string; connection?: { id: string } }) =>- sync.connectionId ?? sync.connection?.id;- return secretSyncs.filter((sync) => {- const subjectFields: Record<string, string> = {- ...(sync.environment && { environment: sync.environment.slug }),- ...(sync.folder && { secretPath: sync.folder.path }),- ...(getConnectionId(sync) && { connectionId: getConnectionId(sync) })- };- const sub =- Object.keys(subjectFields).length > 0- ? subject(ProjectPermissionSub.SecretSyncs, subjectFields as SecretSyncSubjectFields)- : ProjectPermissionSub.SecretSyncs;- return permission.can(ProjectPermissionSecretSyncActions.Read, sub);- }) as TSecretSync[];+ return secretSyncs.filter((sync) =>+ permission.can(ProjectPermissionSecretSyncActions.Read, getSecretSyncSubject(sync))+ ) as TSecretSync[];};const findSecretSyncById = async ({ destination, syncId }: TFindSecretSyncByIdDTO, actor: OrgServiceActor) => {@@ -190,17 +189,9 @@ export const secretSyncServiceFactory = ({projectId: secretSync.projectId});- const connectionId = secretSync.connectionId ?? secretSync.connection?.id;-ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretSyncActions.Read,- secretSync.environment && secretSync.folder- ? subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- ...(connectionId && { connectionId })- })- : ProjectPermissionSub.SecretSyncs+ getSecretSyncSubject(secretSync));if (secretSync.connection.app !== SECRET_SYNC_CONNECTION_MAP[destination])@@ -235,17 +226,9 @@ export const secretSyncServiceFactory = ({projectId: secretSync.projectId});- const connectionId = secretSync.connectionId ?? secretSync.connection?.id;-ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretSyncActions.Read,- secretSync.environment && secretSync.folder- ? subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- ...(connectionId && { connectionId })- })- : ProjectPermissionSub.SecretSyncs+ getSecretSyncSubject(secretSync));if (secretSync.connection.app !== SECRET_SYNC_CONNECTION_MAP[destination])@@ -445,23 +428,10 @@ export const secretSyncServiceFactory = ({const connectionId = secretSync.connectionId ?? secretSync.connection?.id;- // we always check the permission against the existing environment / secret path- // if no secret path / environment is present on the secret sync, we need to check without conditions- if (secretSync.environment?.slug && secretSync.folder?.path) {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.Edit,- subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- ...(connectionId && { connectionId })- })- );- } else {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.Edit,- ProjectPermissionSub.SecretSyncs- );- }+ ForbiddenError.from(permission).throwUnlessCan(+ ProjectPermissionSecretSyncActions.Edit,+ getSecretSyncSubject(secretSync)+ );// if the user is updating the secret path or environment, we need to check the permission against the new valuesif (secretPath || environment) {@@ -526,16 +496,10 @@ export const secretSyncServiceFactory = ({// If changing connectionId, verify user has Edit permission for syncs with the NEW connectionIdif (params.connectionId !== connectionId) {- if (secretSync.environment?.slug && secretSync.folder?.path) {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.Edit,- subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- connectionId: params.connectionId- })- );- }+ ForbiddenError.from(permission).throwUnlessCan(+ ProjectPermissionSecretSyncActions.Edit,+ getSecretSyncSubject(secretSync, { connectionId: params.connectionId })+ );}}@@ -608,23 +572,10 @@ export const secretSyncServiceFactory = ({projectId: secretSync.projectId});- const connectionId = secretSync.connectionId ?? secretSync.connection?.id;-- if (secretSync.environment?.slug && secretSync.folder?.path) {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.Delete,- subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- ...(connectionId && { connectionId })- })- );- } else {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.Delete,- ProjectPermissionSub.SecretSyncs- );- }+ ForbiddenError.from(permission).throwUnlessCan(+ ProjectPermissionSecretSyncActions.Delete,+ getSecretSyncSubject(secretSync)+ );if (secretSync.connection.app !== SECRET_SYNC_CONNECTION_MAP[destination])throw new BadRequestError({@@ -634,13 +585,7 @@ export const secretSyncServiceFactory = ({if (removeSecrets) {ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretSyncActions.RemoveSecrets,- secretSync.environment?.slug && secretSync.folder?.path- ? subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- ...(connectionId && { connectionId })- })- : ProjectPermissionSub.SecretSyncs+ getSecretSyncSubject(secretSync));if (!secretSync.folderId)@@ -694,23 +639,10 @@ export const secretSyncServiceFactory = ({projectId: secretSync.projectId});- const connectionId = secretSync.connectionId ?? secretSync.connection?.id;-- if (secretSync.environment?.slug && secretSync.folder?.path) {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.SyncSecrets,- subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- ...(connectionId && { connectionId })- })- );- } else {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.SyncSecrets,- ProjectPermissionSub.SecretSyncs- );- }+ ForbiddenError.from(permission).throwUnlessCan(+ ProjectPermissionSecretSyncActions.SyncSecrets,+ getSecretSyncSubject(secretSync)+ );if (secretSync.connection.app !== SECRET_SYNC_CONNECTION_MAP[destination])throw new BadRequestError({@@ -769,23 +701,10 @@ export const secretSyncServiceFactory = ({projectId: secretSync.projectId});- const connectionId = secretSync.connectionId ?? secretSync.connection?.id;-- if (secretSync.environment?.slug && secretSync.folder?.path) {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.ImportSecrets,- subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- ...(connectionId && { connectionId })- })- );- } else {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.ImportSecrets,- ProjectPermissionSub.SecretSyncs- );- }+ ForbiddenError.from(permission).throwUnlessCan(+ ProjectPermissionSecretSyncActions.ImportSecrets,+ getSecretSyncSubject(secretSync)+ );if (secretSync.connection.app !== SECRET_SYNC_CONNECTION_MAP[destination])throw new BadRequestError({@@ -838,23 +757,10 @@ export const secretSyncServiceFactory = ({projectId: secretSync.projectId});- const connectionId = secretSync.connectionId ?? secretSync.connection?.id;-- if (secretSync.environment?.slug && secretSync.folder?.path) {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.RemoveSecrets,- subject(ProjectPermissionSub.SecretSyncs, {- environment: secretSync.environment.slug,- secretPath: secretSync.folder.path,- ...(connectionId && { connectionId })- })- );- } else {- ForbiddenError.from(permission).throwUnlessCan(- ProjectPermissionSecretSyncActions.RemoveSecrets,- ProjectPermissionSub.SecretSyncs- );- }+ ForbiddenError.from(permission).throwUnlessCan(+ ProjectPermissionSecretSyncActions.RemoveSecrets,+ getSecretSyncSubject(secretSync)+ );if (secretSync.connection.app !== SECRET_SYNC_CONNECTION_MAP[destination])throw new BadRequestError({