pub struct SqlGuardConfig {
pub dialect: SqlDialect,
pub operation_allowlist: Vec<SqlOperation>,
pub table_allowlist: Vec<String>,
pub column_allowlist: Option<HashMap<String, Vec<String>>>,
pub denylisted_predicates: Vec<String>,
pub require_where_for_mutations: bool,
pub allow_all: bool,
}Expand description
Guard configuration for SqlQueryGuard.
The guard is fail-closed: when every list is empty and allow_all is
false, the guard denies every SQL query.
Fields§
§dialect: SqlDialectSQL dialect used by the parser. Defaults to SqlDialect::Generic.
operation_allowlist: Vec<SqlOperation>Operations that are permitted. A query whose parsed
SqlOperation is not in this list is denied.
table_allowlist: Vec<String>Tables that may be referenced in FROM, JOIN, INSERT INTO,
UPDATE, and DELETE FROM. Comparisons are case-insensitive.
column_allowlist: Option<HashMap<String, Vec<String>>>Optional per-table projected-column allowlist. When set, every
column projected in a SELECT on the table must appear here. A
table that does not appear as a key is treated as having no column
restriction. SELECT * is denied whenever the referenced table has
a column allowlist entry.
denylisted_predicates: Vec<String>Regex patterns matched against the canonicalized WHERE clause text of each query. A match denies the query.
require_where_for_mutations: boolDeny mutations (UPDATE, DELETE) that lack a WHERE clause.
Defaults to true (roadmap 7.1 acceptance criterion).
allow_all: boolEscape hatch: allow every query that parses successfully.
This overrides the fail-closed default. The guard logs a warning
on construction when allow_all is true so operators can find the
escape hatch in observability. Malformed SQL is still denied: the
parse error wins over allow_all.
Implementations§
Source§impl SqlGuardConfig
impl SqlGuardConfig
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true when every allowlist is empty. The guard treats this
as “no config” and denies every query unless allow_all is set.
Sourcepub fn table_allowed(&self, name: &str) -> bool
pub fn table_allowed(&self, name: &str) -> bool
Case-insensitive lookup of a table in the allowlist.
Sourcepub fn column_allowed(&self, table: &str, column: &str) -> Option<bool>
pub fn column_allowed(&self, table: &str, column: &str) -> Option<bool>
Case-insensitive lookup of a column on the given table. Returns
None when no column allowlist is configured, Some(true) when the
column is allowed, and Some(false) when it is denied.
Sourcepub fn table_has_column_allowlist(&self, table: &str) -> bool
pub fn table_has_column_allowlist(&self, table: &str) -> bool
Returns true when the table has an explicit column allowlist entry.
Used to decide whether SELECT * should be denied.
Trait Implementations§
Source§impl Clone for SqlGuardConfig
impl Clone for SqlGuardConfig
Source§fn clone(&self) -> SqlGuardConfig
fn clone(&self) -> SqlGuardConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more