Casbin

Casbin

  • 文档
  • API
  • 编辑器
  • JetBrains 插件
  • Dashboard
  • 论坛
  • OA
  • 趋势
  • 云服务
  • 帮助
  • 博客
  • Languages icon中文
    • English
    • 한국어
    • 参与翻译
  • GitHub

›Model

基础知识

  • 概述
  • 开始使用
  • 工作原理
  • 教程

Model

  • 支持的Models
  • Model语法
  • 函数
  • 基于角色的访问控制
  • 域内RBAC
  • ABAC

存储

  • Model存储
  • Policy存储
  • 政策子集加载

扩充功能

  • 适配器
  • 观察者
  • 调度器
  • 角色管理器
  • 中间件

API

  • 管理 API
  • RBAC API

高级用法。

  • 多线程
  • 基准测试

管理

  • 管理员门户
  • Casbin 服务
  • 日志 & 错误处理
  • 在线编辑器
  • Frontend Usage

更多

  • 本项目使用者
  • 隐私政策
  • 服务条款
Translate

ABAC

什么是ABAC模式?

ABAC是 基于属性的访问控制,可以使用主体、客体或动作的属性,而不是字符串本身来控制访问。 您之前可能就已经听过 XACML ,是一个复杂的 ABAC 访问控制语言。 与XACML相比,Casbin的ABAC非常简单: 在ABAC中,可以使用struct(或基于编程语言的类实例) 而不是字符串来表示模型元素。

例如,ABAC的官方实例如下:

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = r.sub == r.obj.Owner

我们在 matcher 中使用 r.obj.Owner 代替 r.obj。 在 Enforce() 函数中传递的 r.obj 函数是结构或类实例,而不是字符串。 Casbin将使用映像来检索 obj结构或类中的成员变量。

这里是 r.obj construction 或 class 的定义:

type testResource struct {
    Name  string
    Owner string
}

如何使用ABAC?

简单地说,要使用ABAC,您需要做两件事:

  1. 在模型匹配器中指定属性。
  2. 将元素的结构或类实例作为Casbin的Enforce() 的参数传入。
warning

目前,仅有形如r.sub, r.obj, r.act 等请求元素支持ABAC。 您不能在policy元素上使用它,比如p.sub,因为在Casbin的policy中没有定义结构或者类。

您可以在匹配器中使用多个ABAC属性,例如:m = r.sub.Domain == r.obj.Domain。
:::

适配复杂且大量的ABAC规则

上述ABAC实施实例的核心非常简单。 但授权系统通常需要非常复杂和大量的ABAC规则。 To fit this necessity the above implementation will increase the verbosity of the model to a large extent. So, it’s wise to add the rules in the policy instead of in the model. This is done by introducing a eval() functional construct. Below is the example instance to manage such ABAC models.

This is the definition of the CONF file used for defining the ABAC model.

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub_rule, obj, act

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = eval(p.sub_rule) && r.obj == p.obj && r.act == p.act

Here, p.sub_rule is of type struct or class(user-defined type) which consists of necessary attributes to be used in the policy.

This is the policy that is used against the model for Enforcement. Now, you can use the object instance which is passed to eval() as a parameter to define certain ABAC constraints.

p, r.sub.Age > 18, /data1, read
p, r.sub.Age < 60, /data2, write
← 域内RBACModel存储 →
  • 什么是ABAC模式?
  • 如何使用ABAC?
  • 适配复杂且大量的ABAC规则
Casbin
Docs
Getting StartedManagement APIRBAC APIMiddlewares
Community
Who's using Casbin?ForumStack OverflowProject Chat
Casbin          jCasbin
Node-Casbin   PHP-CasbinPyCasbin          Casbin.NETCasbin-CPP        Casbin-RS
Follow @CasbinNews
Copyright © 2021 Casbin contributors.