限制Corda网络中节点的流量访问
Restricting flow access of nodes in Corda network
除了权限管理,我的 Corda 应用程序运行良好。目前每个节点都可以启动 ever flow,但这应该是不可能的。我试图限制build.gradle
文件中某些节点的权限。这里以一个节点为例:
node {
name "O=PartyA,L=Paris,C=FR"
p2pPort 10008
rpcSettings {
address("localhost:10009")
adminAddress("localhost:10049")
}
rpcUsers = [[ user: "user2", password: "test", permissions: ["StartFlow.FlowInitiatorOne", "StartFlow.FlowInitiatorTwo"]]]
}
我使用 deployNodes
命令部署我的网络。我的流程是用 Java 写的。无论权限如何,PartyA
都可以启动所有流程。 PartyA
的日志文件显示,在向节点添加权限之前,所有流都已注册。
[INFO ] 2019-12-13T09:35:25,796Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorOne to initiate com.template.flows.FlowResponderOne (version 1)
[INFO ] 2019-12-13T09:35:25,797Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorTwo to initiate com.template.flows.FlowResponderTwo (version 1)
[INFO ] 2019-12-13T09:35:25,798Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorThree to initiate com.template.flows.FlowResponderThree (version 1)
[INFO ] 2019-12-13T09:35:25,800Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorFour to initiate com.template.flows.FlowResponderFour (version 1)
[INFO ] 2019-12-13T09:35:25,793Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorFive to initiate com.template.flows.FlowResponderFive (version 1)
在流程注册下方,日志文件显示了具有正确权限的用户
[INFO ] 2019-12-13T09:35:55,434Z [main] security.RPCSecurityManagerImpl.buildImpl - Constructing realm from list of users in config [User(user2, permissions=[StartFlow.FlowInitiatorOne, StartFlow.FlowInitiatorTwo])]
如果我在终端输入flow list
,PartyA
会告诉我它可以启动所有五个流程。我该如何解决这个问题?
您的设置是正确的,您在日志中看到的内容也很有意义。
1. 当节点启动时,它会扫描 cordapps
文件夹并注册它看到的所有流。
2. 由于您直接连接到节点(不是通过 ssh
或使用 standalone
shell)并且您的节点处于 dev
模式;然后 Corda 以用户 shell
和密码 shell
的身份将您连接到节点,您可以 运行 所有流。
3. 要测试您的 RPC 用户,您必须编写一个使用 test
用户连接到您的节点的客户端;该客户端将仅限于调用您指定的 2 个流程。
了解访问节点的不同类型:https://docs.corda.net/shell.html
您可以在 R3 的 cordapp-example(在 Kotlin 中)中看到一个示例客户端:
1. 在控制器 class 中,您使用 proxy
调用流:https://github.com/corda/samples/blob/release-V4/cordapp-example/clients/src/main/kotlin/com/example/server/MainController.k
2. 注意Gradle 到运行 的任务,web 服务器如何使用定义的RPC 用户:https://github.com/corda/samples/blob/69ff8d4a668c520b6695be67864f4f96ab7ec809/cordapp-example/clients/build.gradle#L64
3. Java 模板还带有预定义的 clients
模块:https://github.com/corda/cordapp-template-java/tree/release-V4/clients/src/main/java/com/template/webserver
除了权限管理,我的 Corda 应用程序运行良好。目前每个节点都可以启动 ever flow,但这应该是不可能的。我试图限制build.gradle
文件中某些节点的权限。这里以一个节点为例:
node {
name "O=PartyA,L=Paris,C=FR"
p2pPort 10008
rpcSettings {
address("localhost:10009")
adminAddress("localhost:10049")
}
rpcUsers = [[ user: "user2", password: "test", permissions: ["StartFlow.FlowInitiatorOne", "StartFlow.FlowInitiatorTwo"]]]
}
我使用 deployNodes
命令部署我的网络。我的流程是用 Java 写的。无论权限如何,PartyA
都可以启动所有流程。 PartyA
的日志文件显示,在向节点添加权限之前,所有流都已注册。
[INFO ] 2019-12-13T09:35:25,796Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorOne to initiate com.template.flows.FlowResponderOne (version 1)
[INFO ] 2019-12-13T09:35:25,797Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorTwo to initiate com.template.flows.FlowResponderTwo (version 1)
[INFO ] 2019-12-13T09:35:25,798Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorThree to initiate com.template.flows.FlowResponderThree (version 1)
[INFO ] 2019-12-13T09:35:25,800Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorFour to initiate com.template.flows.FlowResponderFour (version 1)
[INFO ] 2019-12-13T09:35:25,793Z [main] internal.NodeFlowManager.registerInitiatedFlow - Registered com.template.flows.FlowInitiatorFive to initiate com.template.flows.FlowResponderFive (version 1)
在流程注册下方,日志文件显示了具有正确权限的用户
[INFO ] 2019-12-13T09:35:55,434Z [main] security.RPCSecurityManagerImpl.buildImpl - Constructing realm from list of users in config [User(user2, permissions=[StartFlow.FlowInitiatorOne, StartFlow.FlowInitiatorTwo])]
如果我在终端输入flow list
,PartyA
会告诉我它可以启动所有五个流程。我该如何解决这个问题?
您的设置是正确的,您在日志中看到的内容也很有意义。
1. 当节点启动时,它会扫描 cordapps
文件夹并注册它看到的所有流。
2. 由于您直接连接到节点(不是通过 ssh
或使用 standalone
shell)并且您的节点处于 dev
模式;然后 Corda 以用户 shell
和密码 shell
的身份将您连接到节点,您可以 运行 所有流。
3. 要测试您的 RPC 用户,您必须编写一个使用 test
用户连接到您的节点的客户端;该客户端将仅限于调用您指定的 2 个流程。
了解访问节点的不同类型:https://docs.corda.net/shell.html
您可以在 R3 的 cordapp-example(在 Kotlin 中)中看到一个示例客户端:
1. 在控制器 class 中,您使用 proxy
调用流:https://github.com/corda/samples/blob/release-V4/cordapp-example/clients/src/main/kotlin/com/example/server/MainController.k
2. 注意Gradle 到运行 的任务,web 服务器如何使用定义的RPC 用户:https://github.com/corda/samples/blob/69ff8d4a668c520b6695be67864f4f96ab7ec809/cordapp-example/clients/build.gradle#L64
3. Java 模板还带有预定义的 clients
模块:https://github.com/corda/cordapp-template-java/tree/release-V4/clients/src/main/java/com/template/webserver