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
enhance(permission): implement fingerprint-based caching for project permissions and improve cache management
Victor Hugo dos Santos0fec6d28e276
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.mdindex ccbcc52914..18af7d3104 100644--- a/backend/CLAUDE.md+++ b/backend/CLAUDE.md@@ -124,6 +124,15 @@ Uses CASL (`@casl/ability`) with MongoDB-style rules. Permission logic lives inBuilt-in roles: `Admin`, `Member`, `Viewer`, `NoAccess`. Custom roles use unpacked CASL rules stored in the database. Rules can include conditions with operators `$IN`, `$EQ`, `$NEQ`, `$GLOB` (for pattern matching like `prod-*`). See `PermissionConditionSchema` in `permission-types.ts`.+**Project permission caching** uses a fingerprint-based two-tier cache (`withCacheFingerprint` in `src/lib/cache/with-cache.ts`):+- **Short-lived marker** (10s TTL) in Redis — while present, cached data is served with 0 DB reads.+- **Long-lived data payload** (10m TTL) in Redis — holds the full permission blob plus a fingerprint hash.+- On marker expiry, a lightweight **fingerprint query** (`getPermissionFingerprint` in `permission-dal.ts`) runs (1 DB read). If the fingerprint matches the cached payload, the marker is reset; otherwise, a full data re-fetch occurs.+- The fingerprint covers **both project-scoped and org-scoped** memberships for the actor, so org-level changes (e.g. SSO bypass grant/revoke, org role edits) also trigger cache invalidation.+- `filterTemporary` in `flattenActiveRolesFromMemberships` runs on every request as a real-time safety net — it filters out expired temporary access regardless of cache state, so access revocation for timed roles/privileges is immediate.+- **No explicit cache invalidation calls exist.** The fingerprint self-corrects within the marker TTL (10s eventual consistency for access granting). The old `invalidateProjectPermissionCache` / DAL version counter pattern has been removed.+- Cache helpers (`cacheGet`, `cacheSet`, `applyReviver`) in `src/lib/cache/with-cache.ts` are shared between the simple `withCache` and the fingerprint-based `withCacheFingerprint`.+### Queue System (BullMQ)Queue infrastructure in `src/queue/queue-service.ts`. Defines 30+ named queues via `QueueName` enum (e.g., `SecretRotation`, `AuditLog`, `IntegrationSync`, `SecretReplication`, `SecretSync`, `DynamicSecretRevocation`). Each queue has typed payloads defined in `TQueueJobTypes`.diff --git a/backend/src/ee/services/permission/permission-dal.ts b/backend/src/ee/services/permission/permission-dal.tsindex 73cef556ad..09b0b71e36 100644--- a/backend/src/ee/services/permission/permission-dal.ts+++ b/backend/src/ee/services/permission/permission-dal.ts@@ -852,7 +852,9 @@ export const permissionDALFactory = (db: TDbClient): TPermissionDALFactory => {if (actorType === ActorType.IDENTITY) {qb.on(`${TableName.IdentityMetadata}.identityId`, `${TableName.Membership}.actorIdentityId`);} else {- qb.on(`${TableName.IdentityMetadata}.identityId`, `${TableName.Membership}.actorUserId`);+ void qb+ .on(`${TableName.IdentityMetadata}.userId`, db.raw("?", [actorId]))+ .andOn(`${TableName.Membership}.scopeOrgId`, `${TableName.IdentityMetadata}.orgId`);}}).where(`${TableName.Membership}.scopeOrgId`, orgId)diff --git a/backend/src/ee/services/permission/permission-service.ts b/backend/src/ee/services/permission/permission-service.tsindex 148c1c4b44..073ffd5c6f 100644--- a/backend/src/ee/services/permission/permission-service.ts+++ b/backend/src/ee/services/permission/permission-service.ts@@ -350,10 +350,10 @@ export const permissionServiceFactory = ({let username = "";if (actor === ActorType.USER) {const userDetails = await userDAL.findById(actorId);- username = userDetails?.username;+ username = userDetails?.username ?? "";} else {const identityDetails = await identityDAL.findById(actorId);- username = identityDetails?.name;+ username = identityDetails?.name ?? "";}// SSO bypass check (for USER actors) — pre-compute and cache the boolean