打开链接即可点亮社区Star,照亮技术的前进之路。
Github 地址:https://github.com/secretflow/trustflow/
TrustFlow提供了一套简洁易懂的语法帮助用户对数据使用行为的授权进行描述。接下来我们会详细描述这套语法,并结合示例进行讲解。
授权策略概览
constraint:约束表达式,描述了具体的数据使用行为约束。rule: 指具体的策略规则,rule本质上由一条或者多条约束表达式组成。policy:指作用于具体数据的授权策略,policy由一条或者多条rule组成。

constraint
constraint本质上是描述"访问控制"这件事,比如允许对数据进行什么样的计算。
可限制的元信息
constraint支持对以下元信息进行限制。具体语法上,每一条constraint的元素都是以r.作为开头。(TrustFlow采用了casbin作为底层的访问控制实现)
platform
在global_constraints下设置。
限制代码运行的TEE平台。目前可选sim/sgx/tdx/csv。
yaml
r.env.tee.platform=="tee platform type"
mr_enclave
在global_constraints下设置。
限制代码的MRENCLAVE,关于MRENCLAVE的说明参见 Enclave 。
yaml
r.env.tee.sgx.mr_encalve=="mrenclave of the enclave"
mr_signer
在global_constraints下设置。
限制代码的MRSIGNER,关于MRSIGNER的说明参见 Enclave 。
yaml
r.env.tee.sgx.mr_signer=="mrsigner of the enclave"
(暂不可用) execution_time
在global_constraints下设置。
限制执行时间。
yaml
r.execution_time<="2023-10-01 23:59:59"
(暂不可用) op参数
在op_constraints下设置。
限制可信app的参数。具体参数名可以在可信APP中找到对应的app查询。
例如限制回归类型为逻辑回归:
yaml
r.op.params.reg_type=="logistic"
元素之间支持的操作符
用户可以根据需要对元信息进行操作,TrustFlow支持的操符作如下。

rule
成员说明
rule包含以下信息。
rule_id
每一条rule都会有一个ID用于标识它。
grantee_party_ids
列表形式,由被授权方的机构ID组成。
op_constraints
op_constraints表示作用于特定算法的约束,由一条或者多条op_constraint组成。op_constraint表示针对具体算子的约束,包含算子名称和一条或者多条constraint。
如果没有填写op_constraints,则表示不允许进行任何计算。
global_constraints
作用于全局的约束,由一条或者多条constraint组成。
(可选)columns
对于结构化数据,可以限定数据的哪些列可以被使用。
使用示例
下列rule描述了以下限制
- 被授权方为bob和carol
- 允许使用数据列f1、f2和f3
- 允许xgb_train组件使用数据
- 允许lr_train组件进行逻辑回归时使用数据
- 限制组件运行平台为sgx
- 限制代码的mr_enclave为MRENCLAVE
json
{
"rule_id":"test_rule_id",
"grantee_party_ids":[
"bob",
"carol"
],
"columns":[
"f1",
"f2",
"f3"
],
"op_constraints":[
{
"op_name": "xgb_train",
"constraints":[]
},
{
"op_name": "lr_train",
"constraints":[
"r.op.params.reg_type==\"logistic\""
]
}
],
"global_constraints":[
"r.env.tee.platform==\"sgx\"",
"r.env.tee.sgx.mr_enclave==\"MRENCLAVE\""
]
}
policy
policy描述了完整的授权策略。
成员说明
data_uuid
策略所作用于的数据id。
rules
由一条或者多条rule组成的列表。
示例
我们继续以上面rule的使用示例为例,一个完整的policy如下。
json
{
"data_uuid":"data id",
"rules":[
{
"rule_id":"test_rule_id",
"grantee_party_ids":[
"bob",
"carol"
],
"columns":[
"f1",
"f2",
"f3"
],
"op_constraints":[
{
"op_name": "xgb_train",
"constraints":[]
},
{
"op_name": "lr_train",
"constraints":[
"r.op.params.reg_type==\"logistic\""
]
}
],
"global_constraints":[
"r.env.tee.platform==\"sgx\"",
"r.env.tee.sgx.mr_enclave==\"MRENCLAVE\""
]
}
]
}