Add sql_guard: regex-based SQL firewall with blacklist/whitelist modes#1285
Open
ilya-maltsev wants to merge 8 commits into
Open
Add sql_guard: regex-based SQL firewall with blacklist/whitelist modes#1285ilya-maltsev wants to merge 8 commits into
ilya-maltsev wants to merge 8 commits into
Conversation
Collaborator
|
why not this format? |
Contributor
Author
ok, no problem |
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.
Summary
sql_guard- a lightweight SQL firewall at the connection pooler layer that filters queries using POSIX extended regular expressions before they reach the PostgreSQL backend.sql_guard "blacklist") - blocks queries matching dangerous patterns (SQL injection prevention: DROP TABLE, UNION SELECT, COPY PROGRAM, pg_sleep, etc.)sql_guard "whitelist") - allows only queries matching the regex through; blocks everything else (strict access control for untrusted users, contractors, reporting tools)sql_guard_cache yes) - optional direct-mapped murmur hash cache (4096 entries) that skips regex on repeated queries (~3.2x speedup)Use cases
Config validation
Invalid combinations are rejected at startup (odyssey --test):
sql_guard "blacklist" without sql_guard_regex -> error
sql_guard_regex without sql_guard -> error
sql_guard_cache yes without sql_guard -> error
Functional tests:
test/functional/tests/sql_guard/ - 34 test queries (blocked + allowed + case-insensitive)
test/functional/tests/config-validation/configs/sql_guard/ - 6 configs (3 valid, 3 invalid)
Performance
Performance tests:
For run benchmark use command:
make benchmark-sql-guard
Results are saved to test/benchmark-sql-guard/results.txt.
CI performance tests (pass/fail validation):
make ci-perf-test
Example benchmark results:
Cache hit rate: 100% after initial pass (20 unique queries, 4096 slots). Cache never fills up, new entries overwrite old ones, worst case is one extra regex call.
Config example