feat(permissions): cache invalidation для permission layer (#205)#217
Merged
Conversation
…205) 9 mutation points (admin + workspace) now broadcast invalidate: - toggleSystemFeature, setUserRole, create/deleteUserPermission - toggleWorkspaceFeature, add/removeWorkspaceMemberPermission - updateMemberRole, addMember/inviteByEmail, removeMember - updateRolePreset cascades to all preset holders (batched-100 + setImmediate) New shared/utils/permissions-invalidate.ts: - broadcastInvalidate{User,Workspace,System}: local + Redis publish - subscriber with INSTANCE_ID skip-own (no pub/sub loop) - 500ms debounce on system invalidates (forge-DoS guard, security review H-2) - redactUrl() strips passwords from Redis error messages - race-safe init with in-flight promise singleton - test-only helpers throw in production server.ts: subscriber init on listen, closeRedisClient + closeInvalidateSubscriber on SIGTERM/SIGINT, logger.info instead of console.log. redis.ts: getRedisSubClient (separate sub connection), closeRedisClient, on('error') logs error code only (no URL leak), orphan-promise suppression. permissions-cache.ts: NUL-byte sentinel for global scope keys (avoids "null" string collision); __getCacheSize/__hasCacheEntry test helpers. Drive-by: removed leftover debug console.error from #193 in rate-limit middleware and error-handler. Tests: - backend/src/__tests__/cache-invalidation.test.ts (12 integration) - backend/src/__tests__/permissions-invalidate.test.ts (16 unit) - Total: 429/429 backend tests passing Closes #205. L-4 deferred follow-up (NODE_ENV=e2e bypass) filed as #216.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #205. Tracker: #191. Depends on #192, #193 (both merged).
Что делает
Подключает существующие
invalidateUser/Workspace/Systemк 9 мутационным точкам permissions API + Redis pub/sub для распространения invalidation между backend-инстансами.Без этого PR: смена роли / permission override / feature toggle становится видимой через 5 минут (TTL).
Точки инжекции (9)
Multi-instance pub/sub
Канал
permissions:invalidate. Каждое сообщение содержитinstanceId— подписчик skip'ает свои сообщения (no loop).Безопасность:
type:system— защита от forge-DoS если злоумышленник пишет в RedisredactUrl()чистит пароли из node-redis error messages перед логами__getCacheSize,__hasCacheEntry,__handleMessageForTests,__getInstanceIdForTests) throw в productionGraceful degradation: Redis недоступен → publish no-op (local invalidate всё равно работает; multi-instance восстановится через TTL).
Drive-by
Убраны 3 console.error дебаг-лога из #193 в
rate-limit.ts(__reset, fallback) иerror-handler.ts([errorHandler 429]).Review
Test plan
backend/src/__tests__/cache-invalidation.test.ts— 12 integration тестовbackend/src/__tests__/permissions-invalidate.test.ts— 16 unit тестовnpm run typecheck✓npm run lint✓ (только pre-existing warnings)Follow-ups
deleteWorkspaceinvalidate (I-1 из security review)