-
Notifications
You must be signed in to change notification settings - Fork 1k
Implement Hostgroup-Based Backend Credentials #5227
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: v3.0
Are you sure you want to change the base?
Conversation
Allows separate credentials for frontend (client->ProxySQL) and backend (ProxySQL->MySQL) connections, mapped by hostgroup. Core changes: - Added lookup_backend_for_hostgroup() to MySQL/PgSQL Authentication - Modified MySQL/PgSQL_Session to use hostgroup-specific credentials - Added SQLite triggers to enforce one backend user per hostgroup
- Implement lookup_backend_for_hostgroup() in PgSQL_Authentication - Update PgSQL_Session to use hostgroup-specific credentials - Add PostgreSQL test containers and init scripts - Extend test suite with 5 PostgreSQL tests (Tests 9-13)
- MySQL: Add missing free(username) in free_account_details() - MySQL: Remove duplicate free(password) dead code - PgSQL: Use free_account_details() instead of manual cleanup
Summary of ChangesHello @maurice2k, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to ProxySQL by enabling hostgroup-based backend credentials for both MySQL and PostgreSQL. This feature allows for a more flexible and secure authentication model where client-facing and database-facing credentials can be distinct and managed per hostgroup. It transforms ProxySQL into a more powerful authentication proxy, providing granular control over how connections are established to backend servers. The changes maintain backward compatibility and are thoroughly validated with a new, extensive test suite. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Can one of the admins verify this patch? |
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.
Code Review
This pull request introduces a significant and valuable feature: hostgroup-based backend credentials for both MySQL and PostgreSQL. The implementation is comprehensive, touching authentication, session management, and database schema with new triggers. The inclusion of a thorough Docker-based test suite is commendable and greatly increases confidence in the changes. My review of the C++ code confirms that the core logic is sound, and the memory leak fix in free_account_details() is a good catch. My main feedback centers on improving maintainability by reducing code duplication. Specifically, the logic for creating database triggers in Admin_Bootstrap.cpp and the logic for applying backend credentials in MySQL_Session.cpp and PgSQL_Session.cpp are repeated in several places. I've suggested refactoring these into helper functions. Overall, this is a solid contribution.
- MySQL_Session: Extract duplicated credential lookup into helper method - PgSQL_Session: Same refactoring for PostgreSQL - Reduces code duplication across 5 call sites in MySQL and 2 in PgSQL - Addresses review feedback from Gemini Code Assist
|
Hey there! I changed most of what Gemini Code Assist said (all valid points) but SonarQube is complaining about malloc/free that is used all over the codebase and also was already in place where I made changes. Happy to get this merged! |
|
|
Is there something I can do? |


Fixes #3446
Summary
This PR implements the ability to use separate credentials for frontend (client → ProxySQL) and backend (ProxySQL → MySQL/PostgreSQL) connections, mapped by hostgroup. This allows ProxySQL to act as an authentication middleware where clients authenticate with one set of credentials, while ProxySQL uses different credentials to connect to backend servers.
Changes
Core Implementation:
lookup_backend_for_hostgroup()method toMySQL_AuthenticationandPgSQL_AuthenticationclassesMySQL_SessionandPgSQL_Sessionto use hostgroup-specific backend credentials when availablebackend=1user perdefault_hostgroupfree_account_details()(missingusernamefree, duplicatepasswordfree)How It Works:
frontend=1, backend=0- used for client authenticationfrontend=0, backend=1- used for backend connections, mapped bydefault_hostgroupfrontend=1, backend=1- classic ProxySQL behavior (same credentials for both)Example Configuration:
When
app_userconnects and queries are routed to hostgroup 10, ProxySQL automatically usesbackend_usercredentials for the backend connection.Testing
Includes a Docker-based test suite (
test/backend-credentials/) with:Run tests:
cd test/backend-credentials ./run-tests.shBackward Compatibility
Fully backward compatible. Existing configurations with
frontend=1, backend=1continue to work unchanged.