Authorization in Authz
Purpose
This article explains how authorization is managed by the platform’s Authz component and how access rules are defined.
Overview
Authentication and authorization are separate concerns.
- Authentication answers: who is the user?
- Authorization answers: what is the user allowed to access?
In this platform, authorization is handled by Authz, which uses a simple rule model based on:
- HTTP methods
- regex path matching
- allowed roles
- an allow or deny effect
The rules management interface is at the /authz/subpath. Once the json is saved the rules are defined in JSON, saved, and then applied immediately.
Rule model
Authz evaluates incoming requests against a set of rules. Each rule can define:
- a rule name
- an effect, such as
allow - one or more HTTP methods
- a
path_regexused to match resources - one or more roles that are allowed to access those resources
A default_effect is also defined for requests that do not match an allow rule.
Example configuration
{
"rules": [
{
"name": "admin-all",
"effect": "allow",
"methods": [
"*"
],
"path_regex": "^/.*$",
"roles": [
"admin",
"default-roles-giotto"
]
},
{
"name": "user-api-only",
"effect": "allow",
"methods": [
"GET",
"POST",
"PUT",
"PATCH",
"DELETE"
],
"path_regex": "^/api/.*$",
"roles": [
"user",
"admin",
"default-roles-giotto"
]
}
],
"default_effect": "deny"
}How to read this example
Rule 1: admin-all
This rule allows users with role admin or default-roles-giotto to access any path, with any method.
The regex:
^/.*$
matches all paths beginning with /, so this is effectively a global allow rule for administrators.
Rule 2: user-api-only
This rule allows users with role user, admin, or default-roles-giotto to access only paths under:
^/api/.*$
and only for the listed HTTP methods. This means general users are limited to API paths, while admins are still covered there as well.
Default effect
The configuration ends with:
"default_effect": "deny"
This is an important security principle. If a request does not match one of the allow rules, it is denied by default.
How authorization decisions work
At a high level, the flow is:
- the user authenticates through Keycloak
- the request carries identity and role information
- Authz matches the request against its rules
- if a rule allows the request, access is granted
- otherwise, the
default_effectis applied
This makes the model easy to reason about and easy to audit.
Why regex-based paths are useful
Using regex for paths makes the authorization layer flexible. Instead of listing every possible resource one by one, administrators can define families of paths with a single pattern.
This is especially useful when APIs have consistent URL structures.
How to apply changes
The operational model is intentionally simple:
- edit the JSON rules
- save the configuration
- the rules take effect
That makes Authz easy to update without introducing a more complex policy language.
Best practices
Keep default_effect as deny
A deny-by-default model is the safest baseline and reduces the chance of accidental overexposure.
Use narrow regular expressions when possible
It is better to match the intended resource set precisely than to use very broad patterns unless broad access is truly required.
Keep role names aligned with Keycloak
Because Authz decisions depend on roles, role naming should stay consistent with what is defined in Keycloak.
Document each rule
Clear rule names such as admin-all and user-api-only make the policy easier to understand and maintain.
Comments
0 comments
Article is closed for comments.