-
Notifications
You must be signed in to change notification settings - Fork 808
Ensure saved shared server passwords are re-encrypted on password change.#9258 #9475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–25 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
web/pgadmin/browser/server_groups/servers/utils.py (1)
475-499: Consider extracting shared re-encryption logic to reduce duplication.The password and tunnel password re-encryption logic (lines 480-495) is nearly identical to the Server handling code (lines 455-470). Consider extracting this into a helper function to improve maintainability.
🔎 Suggested refactoring approach:
Create a helper function to handle the tunnel password re-encryption:
def _reencrpyt_tunnel_password(server, manager, old_key, new_key): """Re-encrypt tunnel password for a server or shared server.""" if server.tunnel_password is not None: tunnel_password = decrypt(server.tunnel_password, old_key) if isinstance(tunnel_password, bytes): tunnel_password = tunnel_password.decode() tunnel_password = encrypt(tunnel_password, new_key) setattr(server, 'tunnel_password', tunnel_password) manager.tunnel_password = tunnel_password elif manager.tunnel_password is not None: tunnel_password = decrypt(manager.tunnel_password, old_key) if isinstance(tunnel_password, bytes): tunnel_password = tunnel_password.decode() tunnel_password = encrypt(tunnel_password, new_key) manager.tunnel_password = tunnel_passwordThen use it for both Server and SharedServer:
for server in Server.query.filter_by(user_id=user_id).all(): manager = driver.connection_manager(server.id) _password_check(server, manager, old_key, new_key) - - if server.tunnel_password is not None: - tunnel_password = decrypt(server.tunnel_password, old_key) - if isinstance(tunnel_password, bytes): - tunnel_password = tunnel_password.decode() - - tunnel_password = encrypt(tunnel_password, new_key) - setattr(server, 'tunnel_password', tunnel_password) - manager.tunnel_password = tunnel_password - elif manager.tunnel_password is not None: - tunnel_password = decrypt(manager.tunnel_password, old_key) - - if isinstance(tunnel_password, bytes): - tunnel_password = tunnel_password.decode() - - tunnel_password = encrypt(tunnel_password, new_key) - manager.tunnel_password = tunnel_password + _reencrpyt_tunnel_password(server, manager, old_key, new_key) db.session.commit() manager.update_session() # Ensure saved shared server passwords are re-encrypted. for server in SharedServer.query.filter_by(user_id=user_id).all(): manager = driver.connection_manager(server.id) _password_check(server, manager, old_key, new_key) - - if server.tunnel_password is not None: - tunnel_password = decrypt(server.tunnel_password, old_key) - if isinstance(tunnel_password, bytes): - tunnel_password = tunnel_password.decode() - - tunnel_password = encrypt(tunnel_password, new_key) - setattr(server, 'tunnel_password', tunnel_password) - manager.tunnel_password = tunnel_password - elif manager.tunnel_password is not None: - tunnel_password = decrypt(manager.tunnel_password, old_key) - - if isinstance(tunnel_password, bytes): - tunnel_password = tunnel_password.decode() - - tunnel_password = encrypt(tunnel_password, new_key) - manager.tunnel_password = tunnel_password + _reencrpyt_tunnel_password(server, manager, old_key, new_key) db.session.commit() manager.update_session()
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
web/pgadmin/browser/server_groups/servers/utils.py(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
web/pgadmin/browser/server_groups/servers/utils.py (2)
web/pgadmin/model/__init__.py (2)
Server(188-275)SharedServer(425-500)web/pgadmin/utils/crypto.py (2)
decrypt(47-61)encrypt(25-44)
🪛 Ruff (0.14.8)
web/pgadmin/browser/server_groups/servers/utils.py
486-486: Do not call setattr with a constant attribute value. It is not any safer than normal property access.
Replace setattr with assignment
(B010)
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: run-feature-tests-pg (16)
- GitHub Check: run-feature-tests-pg (17)
- GitHub Check: run-feature-tests-pg (14)
- GitHub Check: run-feature-tests-pg (13)
- GitHub Check: run-feature-tests-pg (18)
- GitHub Check: run-feature-tests-pg (15)
🔇 Additional comments (1)
web/pgadmin/browser/server_groups/servers/utils.py (1)
22-22: LGTM!The import of
SharedServeris necessary and correct for the new functionality.
| manager = driver.connection_manager(server.id) | ||
| _password_check(server, manager, old_key, new_key) | ||
|
|
||
| if server.tunnel_password is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same logic is used for the server. Please make one common function for servers as well as Shared servers.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.