在 Hyperledger Fabric CA 中为 LDAP 用户设置管理员角色
Set admin role for an LDAP user in Hyperledger Fabric CA
我有一个使用 V1.4 的 Hyperledger Fabric 区块链,我通过 LDAP 连接到我组织的 Active Directory,我希望能够从我的 AD 更改我的用户的角色。
基本上我需要两个角色:用户和管理员,用户可以 运行 合同,管理员可以安装和升级合同。
所以我想做的是在 fabric-ca-server-config.yaml 上的 ldap 配置中添加一个转换器和一个将我的“memberOf”AD 属性 更改为hf.Registrar.Roles 像这样:
ldap:
url: ldap://CN=USER,DC=ORG1,DC=com:password@ldapserver:389/DC=ORG1,DC=com
userfilter: (userPrincipalName=%s)
attribute:
names: ['userPrincipalName','memberOf']
converters:
- name: hf.Revoker
value: attr("userPrincipalName") =~ "revoker*"
- name: hf.Registrar.Roles
value: map(attr("memberOf"),"roles")
maps:
roles:
- name: CN=BC-CLIENT,DC=ORG1,DC=com
value: client
- name: CN=BC-USER,DC=ORG1,DC=com
value: user
- name: CN=BC-ADMIN,DC=ORG1,DC=com
value: admin
- name: CN=BC-PEER,DC=ORG1,DC=com
value: peer
- name: CN=BC-ORDERER,DC=ORG1,DC=com
value: orderer
到目前为止一切顺利,我可以像这样使用 nodejs 注册用户:
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
const enrollment = await ca.enroll({
enrollmentID: adminId,
enrollmentSecret: adminSecret,
});
const identity = X509WalletMixin.createIdentity('Org1MSP', enrollment.certificate, enrollment.key.toBytes());
await wallet.import(adminId, identity);
有了这个用户,我可以查询和调用合同,但是当我尝试安装合同时,出现以下错误:
install proposal was bad Error: access denied for [install]: Failed verifying that proposal's creator satisfies local MSP principal during channelless check policy with policy [Admins]: [The identity is not an admin under this MSP [Org1MSP]: The identity does not contain OU [ADMIN], MSP: [Org1MSP]],Error: access denied for [install]: Failed verifying that proposal's creator satisfies local MSP principal during channelless check policy with policy [Admins]: [The identity is not an admin under this MSP [Org1MSP]: The identity does not contain OU [ADMIN], MSP: [Org1MSP]]
我可以看到映射在 CA 日志中运行良好,但后来我猜 hf.Registrar.Roles 它不是我需要的 属性。
我怎样才能做到这一点?
谢谢
更新:
我像这样向转换器添加了一个 OU 属性:
ldap:
attribute:
converters:
- name: OU
value: map(attr("memberOf"),"roles")
我可以看到转换是在 CA 中完成的。
Evaluating expression for attribute 'OU' from LDAP user 'user@company.com'
Values for LDAP attribute 'memberOf' are '[CN=BC-CLIENT,DC=ORG1,DC=com CN=BC-USER,DC=ORG1,DC=com CN=BC-ADMIN,DC=ORG1,DC=com]'
Evaluated expression for attribute 'OU'; parms: map[CN=USER,DC=ORG1,DC=com affiliation:[]]; result: client,admin,user
但我仍然遇到同样的错误,所以我不能将 ldap 属性映射到证书吗?
还有我的 NodeOU
NodeOUs:
Enable: true
ClientOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: client
PeerOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: peer
AdminOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: admin
OrdererOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: orderer
谢谢
摘要
感谢 Yacov 的帮助,我发现从 LDAP 创建的证书总是获取客户端 OU,并且您无法更改它,但它也具有来自 LDAP 的用户的 OU,因此您可以更改 NodeOU 值并将它们映射到您组织的 OU,对我来说这行不通,因为我只能更改我的用户的 memberOf 而不是 OU。
谢谢!
证书需要有定义管理员的 OU。查看您的 MSP 文件夹中的 config.yaml(在同级 - MSPCONFIGPATH 中)并查看定义管理员的 OU。
你也可以试试把你用的证书放在对端MSP的admincerts
文件夹下,应该也是admin。
我有一个使用 V1.4 的 Hyperledger Fabric 区块链,我通过 LDAP 连接到我组织的 Active Directory,我希望能够从我的 AD 更改我的用户的角色。
基本上我需要两个角色:用户和管理员,用户可以 运行 合同,管理员可以安装和升级合同。
所以我想做的是在 fabric-ca-server-config.yaml 上的 ldap 配置中添加一个转换器和一个将我的“memberOf”AD 属性 更改为hf.Registrar.Roles 像这样:
ldap:
url: ldap://CN=USER,DC=ORG1,DC=com:password@ldapserver:389/DC=ORG1,DC=com
userfilter: (userPrincipalName=%s)
attribute:
names: ['userPrincipalName','memberOf']
converters:
- name: hf.Revoker
value: attr("userPrincipalName") =~ "revoker*"
- name: hf.Registrar.Roles
value: map(attr("memberOf"),"roles")
maps:
roles:
- name: CN=BC-CLIENT,DC=ORG1,DC=com
value: client
- name: CN=BC-USER,DC=ORG1,DC=com
value: user
- name: CN=BC-ADMIN,DC=ORG1,DC=com
value: admin
- name: CN=BC-PEER,DC=ORG1,DC=com
value: peer
- name: CN=BC-ORDERER,DC=ORG1,DC=com
value: orderer
到目前为止一切顺利,我可以像这样使用 nodejs 注册用户:
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName);
const enrollment = await ca.enroll({
enrollmentID: adminId,
enrollmentSecret: adminSecret,
});
const identity = X509WalletMixin.createIdentity('Org1MSP', enrollment.certificate, enrollment.key.toBytes());
await wallet.import(adminId, identity);
有了这个用户,我可以查询和调用合同,但是当我尝试安装合同时,出现以下错误:
install proposal was bad Error: access denied for [install]: Failed verifying that proposal's creator satisfies local MSP principal during channelless check policy with policy [Admins]: [The identity is not an admin under this MSP [Org1MSP]: The identity does not contain OU [ADMIN], MSP: [Org1MSP]],Error: access denied for [install]: Failed verifying that proposal's creator satisfies local MSP principal during channelless check policy with policy [Admins]: [The identity is not an admin under this MSP [Org1MSP]: The identity does not contain OU [ADMIN], MSP: [Org1MSP]]
我可以看到映射在 CA 日志中运行良好,但后来我猜 hf.Registrar.Roles 它不是我需要的 属性。
我怎样才能做到这一点?
谢谢
更新:
我像这样向转换器添加了一个 OU 属性:
ldap:
attribute:
converters:
- name: OU
value: map(attr("memberOf"),"roles")
我可以看到转换是在 CA 中完成的。
Evaluating expression for attribute 'OU' from LDAP user 'user@company.com'
Values for LDAP attribute 'memberOf' are '[CN=BC-CLIENT,DC=ORG1,DC=com CN=BC-USER,DC=ORG1,DC=com CN=BC-ADMIN,DC=ORG1,DC=com]'
Evaluated expression for attribute 'OU'; parms: map[CN=USER,DC=ORG1,DC=com affiliation:[]]; result: client,admin,user
但我仍然遇到同样的错误,所以我不能将 ldap 属性映射到证书吗?
还有我的 NodeOU
NodeOUs:
Enable: true
ClientOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: client
PeerOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: peer
AdminOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: admin
OrdererOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: orderer
谢谢
摘要
感谢 Yacov 的帮助,我发现从 LDAP 创建的证书总是获取客户端 OU,并且您无法更改它,但它也具有来自 LDAP 的用户的 OU,因此您可以更改 NodeOU 值并将它们映射到您组织的 OU,对我来说这行不通,因为我只能更改我的用户的 memberOf 而不是 OU。
谢谢!
证书需要有定义管理员的 OU。查看您的 MSP 文件夹中的 config.yaml(在同级 - MSPCONFIGPATH 中)并查看定义管理员的 OU。
你也可以试试把你用的证书放在对端MSP的admincerts
文件夹下,应该也是admin。