hyperswitch icon indicating copy to clipboard operation
hyperswitch copied to clipboard

fix(users): use global Redis prefix for all user-related cache operations

Open tsdk02 opened this issue 7 months ago • 1 comments

Type of Change

  • [x] Bugfix
  • [ ] New feature
  • [ ] Enhancement
  • [ ] Refactoring
  • [ ] Dependency updates
  • [ ] Documentation
  • [ ] CI/CD

Description

This PR updates all user-related Redis operations to consistently use the global Redis key prefix (global:) instead of environment-specific prefixes like public: (V1) or public_v2: (V2).

Previously, different deployments used different prefixes, which caused inconsistencies especially during login, logout, switch, and caching flows.

Changes Introduced:

  • Updated Redis connection fetchers for all user modules (lineage context, SSO, blacklist, etc.) to use a global Redis connection.

Affected functions:

utils/user.rs

  • set_sso_id_in_redis
  • get_sso_id_from_redis

utils/user/two_factor_auth.rs

  • check_totp_in_redis
  • check_recovery_code_in_redis
  • insert_totp_in_redis
  • insert_totp_secret_in_redis
  • get_totp_secret_from_redis
  • delete_totp_secret_from_redis
  • insert_recovery_code_in_redis
  • delete_totp_from_redis
  • delete_recovery_code_from_redis
  • insert_totp_attempts_in_redis
  • get_totp_attempts_from_redis
  • insert_recovery_code_attempts_in_redis
  • get_recovery_code_attempts_from_redis
  • delete_totp_attempts_from_redis
  • delete_recovery_code_attempts_from_redis

services/authorization.rs

  • get_role_info_from_cache
  • set_role_info_in_cache

services/openidconnect.rs

  • get_authorization_url
  • get_nonce_from_redis

services/user.rs

  • insert_user_in_blacklist
  • insert_role_in_blacklist
  • invalidate_role_cache
  • check_user_in_blacklist
  • check_role_in_blacklist
  • insert_email_token_in_blacklist
  • check_email_token_in_blacklist

Additional Changes

  • [ ] This PR modifies the API contract
  • [ ] This PR modifies the database schema
  • [ ] This PR modifies application configuration/environment variables

Motivation and Context

  • It helps in storing the redis keys which are common to both v1 and v2 deployments under a common prefix, so it can be used irrespective of the version of the deployment.

How did you test it?

Used the dashboard and then signed out. Screenshot 2025-04-29 at 3 52 37 PM As it is evident in the screenshot, blacklist functions, and lineage context now use global: prefix while setting the key in redis.

We need to check the redis-cli and verify that the user-related keys have the global prefix, instead of deployment specific keys like public and public_v2.

Checklist

  • [x] I formatted the code cargo +nightly fmt --all
  • [x] I addressed lints thrown by cargo clippy
  • [x] I reviewed the submitted code
  • [ ] I added unit tests for my changes where possible

tsdk02 avatar Apr 29 '25 10:04 tsdk02