Fabric的权限管理:Attribute-Based Access Control
之前稍微了解过Client Identity Chaincode Library,这几天正好开始实际应用。
虽然了解过,还是发现了不少之前理解的不足,也踩了不少坑。
先列出官方介绍: https://github.com/hyperledger/fabric/blob/release-1.1/core/chaincode/lib/cid/README.md
1,首先要给注册的user添加attrs,但是在ca 数据库中看不到,chaincode 层也查不到
查看CA的log,并没有报错,user也成功enroll,
chaincode层查找fabric 默认的attrs,则可以查到。然后意识到,需要在ca-server-config.yaml中添加需要的attrs。
2,在chaincode中 import http://github.com/hyperledger/fabric/core/chaincode/lib/cid,compile的时候总是说找不到 github.com/hyperledger/fabric/core/chaincode/lib/cid
错误消息说的很明确,但是由于对go语言及扩展知识理解不做,踩了不少坑。
shim包可以引入成功,但是并不知道shim包在哪里,也不知道应该怎么引入新包。于是系统中搜索shim,但是找不到结果。
上网查找,很确认这里是正解:https://stackoverflow.com/questions/49560104/cannot-find-package-cid-in-goroot-or-gopath
但是还是不是很明白,最后参考abac的例子和govendor的文档,才搞定
下面是一些关键代码:
ca-config.yaml
registry:
# Maximum number of times a password/secret can be reused for enrollment
# (default: -1, which means there is no limit)
maxenrollments: -1 # Contains identity information which is used when LDAP is disabled
identities:
- name: admin
pass: adminpw
type: client
affiliation: ""
attrs:
hf.Registrar.Roles: "peer,orderer,client,user"
hf.Registrar.DelegateRoles: "peer,orderer,client,user"
hf.Revoker: true
hf.IntermediateCA: true
hf.GenCRL: true
hf.Registrar.Attributes: "*"
hf.AffiliationMgr: true
permissions: "*"
node js
let secret = await caClient.register({
enrollmentID: username,
affiliation: userOrg.toLowerCase() + '.department1',
attrs:[{name:"hf.Registrar.Attributes",value:"query",ecert:true},
{name:"permissions",value:"query",ecert:true}]
//attrs:reg_attr
}, adminUserObj);
chaincode
// Get the client ID object
id, err := cid.New(stub) fmt.Println("client ID object:")
fmt.Println(id)
if err != nil {
return shim.Error(err.Error())
}
mspid, err := id.GetMSPID() fmt.Println("mspid:")
fmt.Println(mspid)
if err != nil {
return shim.Error(err.Error())
} cert, err := cid.GetX509Certificate(stub)
fmt.Println("cert:")
fmt.Printf("%+v\n", cert)
fmt.Println("cert.Extensions :")
fmt.Printf("%+v\n", cert.Extensions)
fmt.Println("cert.Subject.CommonName:")
fmt.Println(cert.Subject.CommonName) val, ok, err := cid.GetAttributeValue(stub, "hf.Registrar.Attributes")
if err != nil {
return shim.Error(err.Error())
}
if !ok {
return shim.Error("The client identity does not possess the attribute:hf.Registrar.Attributes")
}
fmt.Println("hf.Registrar.Attributes:")
fmt.Println(val) val, ok, err = cid.GetAttributeValue(stub, "permissions")
if err != nil {
return shim.Error(err.Error())
}
if !ok {
return shim.Error("The client identity does not possess the attribute:permissions")
}
fmt.Println("permissions:")
fmt.Println(val)
Fabric的权限管理:Attribute-Based Access Control的更多相关文章
- [认证授权] 6.Permission Based Access Control
在前面5篇博客中介绍了OAuth2和OIDC(OpenId Connect),其作用是授权和认证.那么当我们得到OAuth2的Access Token或者OIDC的Id Token之后,我们的资源服务 ...
- Azure ARM (16) 基于角色的访问控制 (Role Based Access Control, RBAC) - 使用默认的Role
<Windows Azure Platform 系列文章目录> 今天上午刚刚和客户沟通过,趁热打铁写一篇Blog. 熟悉Microsoft Azure平台的读者都知道,在老的Classic ...
- Azure RBAC(Roles Based Access Control)正式上线了
期盼已久的Azure RBAC(Roles Based Access Control)正式上线了. 在非常多情况下.客户须要对各种类型的用户加以区分,以便做出适当的授权决定.基于角色的訪问控制 (RB ...
- Risk Adaptive Information Flow Based Access Control
Systems and methods are provided to manage risk associated with access to information within a given ...
- Custom Roles Based Access Control (RBAC) in ASP.NET MVC Applications - Part 1 (Framework Introduction)
https://www.codeproject.com/Articles/875547/Custom-Roles-Based-Access-Control-RBAC-in-ASP-NET Introd ...
- Linux VFS Extended Attribute And Access Control Table
catalog . 简介 . 扩展属性 . 访问控制表 . 小结 0. 简介 许多文件系统都提供了一些特性,扩展了VFS层提供的标准功能,虚拟文件系统不可能为所有特性都提供具体的数据结构.超出标准的U ...
- 基于角色的权限控制系统(role-based access control)
role-based access control(rbac),指对于不同角色的用户,拥有不同的权限 .用户对应一个角色,一个角色拥有若干权限,形成用户-角色-权限的关系,如下图所示.当一个用户进行访 ...
- 概念 : 用户>角色>权限 的管理(Role-Based Access Control)
RBAC 用户管理规范 概念:每个user有多个accounts,每个account 有一个account binding,有多个roles和多个tasks 举个例子:某个用户现在manager,这是 ...
- Azure ARM (17) 基于角色的访问控制 (Role Based Access Control, RBAC) - 自定义Role
<Windows Azure Platform 系列文章目录> 在上面一篇博客中,笔者介绍了如何在RBAC里面,设置默认的Role. 这里笔者将介绍如何使用自定的Role. 主要内容有: ...
随机推荐
- oracle linux 6.8 安装
' 测试环境vm虚拟机 硬盘大小50G 内存2G CPU 4 选择install or upgrade an existing system 选择skip跳过内存检查 Next 选择语言,Next 选 ...
- LiveBindings如何绑定一个对象(转)
原文 http://www.malcolmgroves.com/blog/?p=1084 一.新建VCL工程加入TAdapterBingSource控件 二.定一个TPerson类 MyPerson ...
- day2模块初识别
sys_mod.py import sys print(sys.argv) #['C:/Users/Administrator/desktop/s17/day2/sys_mod.py'] 打印脚本的绝 ...
- Angular2中使用ngx-translate进行国际化
转自 https://blog.csdn.net/u014291497/article/details/61233033 相较于angularjs中的ng-translate, angular2也有适 ...
- ssl协议相关
<1> SSL版本 测试浏览器支持的SSL版本的网站: https://www.ssllabs.com/ssltest/viewMyClient.html 0xfefd (DTLS ...
- 关于x-shell连接不上本地虚拟机linux
首先把虚拟机网络模式调成nat模式,用于共享主机的ip地址. 然后再虚拟机输入命令ifconfig查看虚拟机的ip 在windows下ping一下虚拟机的ip确保能ping通,同理在虚拟机下ping主 ...
- django之 基于queryset和双下划线的跨表查询
前面篇随笔写的是基于对象的跨表查询:对象.objects.filter(...) 对象.关联对象_set.all(...) -->反向 基于对象的跨表查询例如: book_obj= Book ...
- 【FZSZ2017暑假提高组Day1】华容道游戏
[问题描述] 华容道是一种有趣的滑块游戏,大概是下面这个样子的. 游戏局面由一个2*2的曹操滑块,五个2*1的蜀将滑块(横竖是不定的).四个1*1的小兵滑块以及两个空的位置构成,玩家需要利用空的位子移 ...
- K8s之Etcd
Etcd是一个开源的.高可用的.分布式的键值对数据存储系统,提供共享配置.服务的注册和发现.etcd与zookeeper相比算是轻量级系统,两者的一致性协议也一样,etcd的raft比zookeepe ...
- 安装好ubuntu双系统启动时卡死解决办法
问题描述:在安装完ubuntu双系统后,第一次启动ubuntu系统时,卡死在启动界面(或者黑屏),这大概都是由于显卡驱动的原因,具体不在这里阐述,通过以下方法能成功解决,据我个人经验,这可能是诸多方法 ...