RBAC via casbin
This commit is contained in:
24
config/casbin/model.conf
Normal file
24
config/casbin/model.conf
Normal file
@@ -0,0 +1,24 @@
|
||||
# Casbin access model for the storefront.
|
||||
#
|
||||
# Request is (subject, object, action) = (role, request-path, HTTP-method);
|
||||
# axum-casbin supplies path + method automatically and the subject comes from
|
||||
# our JWT-derived CasbinVals (see src/shared/rbac.rs).
|
||||
#
|
||||
# Deny-override: every request is allowed unless a matching policy line marks it
|
||||
# `deny`. That keeps the public storefront fully open and lets the policy file
|
||||
# carve out the protected `/admin/*` subtree for non-admins only.
|
||||
|
||||
[request_definition]
|
||||
r = sub, obj, act
|
||||
|
||||
[policy_definition]
|
||||
p = sub, obj, act, eft
|
||||
|
||||
[role_definition]
|
||||
g = _, _
|
||||
|
||||
[policy_effect]
|
||||
e = !some(where (p.eft == deny))
|
||||
|
||||
[matchers]
|
||||
m = (r.sub == p.sub || g(r.sub, p.sub)) && keyMatch(r.obj, p.obj) && regexMatch(r.act, p.act)
|
||||
25
config/casbin/policy.csv
Normal file
25
config/casbin/policy.csv
Normal file
@@ -0,0 +1,25 @@
|
||||
# Authorization policy. Format: p, subject(role), object(path-pattern), action(method-regex), effect
|
||||
#
|
||||
# DECISION: this app intentionally runs with a SINGLE hardcoded admin (the user
|
||||
# whose email matches ADMIN_EMAIL in .env, via guard::is_admin / admin_seeder).
|
||||
# Everyone else is `customer` (logged in) or `anonymous` (not). There is no
|
||||
# stored `role` column yet. This is a deliberate choice for current scale, not a
|
||||
# limitation of the wiring — see src/shared/rbac.rs for the upgrade path.
|
||||
#
|
||||
# Deny everyone except admins under the admin subtree. `keyMatch` treats the
|
||||
# trailing `*` as "anything after /admin/", so /admin/dashboard, /admin/orders/5
|
||||
# etc. are all covered; the bare /admin entry point stays open so it can redirect
|
||||
# to /login. Admins match no deny rule and so are allowed through.
|
||||
#
|
||||
# To grow this: give users a real role, emit it as the subject in
|
||||
# src/shared/rbac.rs, then add `p` lines (allow/deny) and `g, <user>, <role>`
|
||||
# mappings here.
|
||||
p, customer, /admin/*, .*, deny
|
||||
p, anonymous, /admin/*, .*, deny
|
||||
# Admin-only endpoints that live outside the /admin/* subtree: the admin JSON
|
||||
# API and the image upload. Public image serving (/images/{filename}) is GET and
|
||||
# not matched here, so it stays open.
|
||||
p, customer, /api/admin/*, .*, deny
|
||||
p, anonymous, /api/admin/*, .*, deny
|
||||
p, customer, /images/upload, .*, deny
|
||||
p, anonymous, /images/upload, .*, deny
|
||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
Reference in New Issue
Block a user