Rules
Rules can deny or allow access to tables or rewrite the SQL statement by adding a where clause. Rules are not attached to tables but applied to the incoming SQL statement before it actually runs in the database engine.
Incoming statements are matched against the rules in a prioritized order, and if there is a match, the rule will be applied.
A rule is applied to a statement if one or more matches are positive:
usernamematches the name of the user.servicematches the kind of service used. Alwayssql.requestmatches the type of statement. Can be eitherselect,insert,updateordelete.schemamatches the schema of the tables in the statement.tablematches the tables in the statement.iprangematches the IP address the statement comes from (CIDR block).
Default for all is *, which means that it will match all.
A rule has three outcomes:
- It will
allowaccess - It will
denyaccess - It will
limitaccess
A limit rule should always have a filter, which is a where clause.
Rules with lower priority are matched first.
SQL statements with multiple tables (like JOIN, UNION, WITH or sub-queries) can match multiple rules. For a such statement to run all matched rules must either allow or limit.
When using rules, it is a good idea to add a "stop block" rule, so unmatched statements don't go through. A "stop block" rule should have the highest
priorityof all rules:
{
"priority": 1000,
"access": "deny"
}
This stops any statement, which are not allowed or limited in prior matches rules.
Create a new rule
- HTTP
- CLI
POST https://api.centia.io/api/v4/rules HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"priority": 1,
"username": "joe",
"request": "delete",
"schema": "my_schema",
"table": "my_table"
"access": "limit",
"filter": "user='joe'",
}
POST https://api.centia.io/api/v4/rules HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"rules": [
{
"priority": 1,
"username": "joe",
"request": "delete",
"schema": "my_schema",
"table": "my_table"
"access": "limit",
"filter": "user='joe'"
},
{
"priority": 1,
"username": "peter",
"request": "delete",
"schema": "my_schema",
"table": "my_table"
"access": "limit",
"filter": "user='peter'"
}
]
}
centia rule add
Get rules
- HTTP
- CLI
GET https://api.centia.io/api/v4/rules/1,2 HTTP/1.1
Accept: application/json
Authorization: Bearer abc123
GET https://api.centia.io/api/v4/rules HTTP/1.1
Accept: application/json
Authorization: Bearer abc123
centia rule get
Update a rule
- HTTP
- CLI
PATCH https://api.centia.io/api/v4/rules/1,2 HTTP/1.1
Content-Type: application/json
Authorization: Bearer abc123
{
"priority": 2
}
centia rule update 1
Delete a rule
- HTTP
- CLI
DELETE https://api.centia.io/api/v4/rules/1,2 HTTP/1.1
Authorization: Bearer abc123
centia rule drop 1