Skip to content

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

feat(keystore): add SecretPermissionFingerprint prefix and implement caching for permission fingerprint retrieval

Victor Hugo dos Santos1a50cce9a8ed
diff --git a/backend/src/keystore/keystore.ts b/backend/src/keystore/keystore.ts
index 1898f52685..969450e6d0 100644
--- a/backend/src/keystore/keystore.ts
+++ b/backend/src/keystore/keystore.ts
@@ -124,6 +124,8 @@ export const KeyStorePrefixes = {
TelemetryGroupIdentify: (orgId: string) => `telemetry-group-identify:${orgId}` as const,
TelemetryIdentify: (distinctId: string) => `telemetry-identify:${distinctId}` as const,
SecretEtag: (projectId: string, dayStamp: string) => `secret-etag:${projectId}:${dayStamp}` as const,
+ SecretPermissionFingerprint: (projectId: string, actorType: string, actorId: string) =>
+ `secret-perm-fingerprint:${projectId}:${actorType}:${actorId}` as const,
PamAwsIamAccessKeyId: (sessionId: string) => `pam-aws-iam-access-key-id:${sessionId}` as const,
PamDefaultProject: (orgId: string) => `pam-default-project:${orgId}` as const,
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 d8d7beeea7..c0065f9e2b 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
@@ -30,6 +30,7 @@ import { TSecretApprovalRequestSecretDALFactory } from "@app/ee/services/secret-
import { scanSecretPolicyViolations } from "@app/ee/services/secret-scanning-v2/secret-scanning-v2-fns";
import { TSecretSnapshotServiceFactory } from "@app/ee/services/secret-snapshot/secret-snapshot-service";
import { KeyStorePrefixes, KeyStoreTtls, TKeyStoreFactory } from "@app/keystore/keystore";
+import { withCache } from "@app/lib/cache/with-cache";
import { generateCacheKeyFromBuffer, generateCacheKeyFromData } from "@app/lib/crypto/cache";
import { utcDayStamp } from "@app/lib/dates";
import { DatabaseErrorCode } from "@app/lib/error-codes";
@@ -1264,11 +1265,19 @@ export const secretV2BridgeServiceFactory = ({
let permissionFingerprint = "";
if (actor === ActorType.USER || actor === ActorType.IDENTITY) {
- permissionFingerprint = await permissionDAL.getPermissionFingerprint({
- projectId,
- orgId: actorOrgId,
- actorId,
- actorType: actor
+ // Cache the fingerprint for the marker window so repeated polls
+ // skip the per-request DB query. Same 10s TTL as getProjectPermission's marker, so no new staleness.
+ permissionFingerprint = await withCache({
+ keyStore,
+ key: KeyStorePrefixes.SecretPermissionFingerprint(projectId, actor, actorId),
+ ttlSeconds: KeyStoreTtls.ProjectPermissionMarkerTtlSeconds,
+ fetcher: () =>
+ permissionDAL.getPermissionFingerprint({
+ projectId,
+ orgId: actorOrgId,
+ actorId,
+ actorType: actor
+ })
});
}