Display connection specific cookies in Erlang

2019-02-24 14:57发布

When setting a cookie on a node with erlang:set_cookie/2 it is possible to set different cookies for different nodes. Is there any way to display, which cookie is set for which node?

Calling erlang:get_cookie/1 does not display this information, only the "default" cookie is displayed.

Example:

Start NodeA with cookie foo and a NodeB with cookie bar. At NodeA now set the cookie to use when communicating with NodeB to bar by calling erlang:set_cookie(NodeB, bar). Pinging now works fine, no "Connection attempt from disallowed node..." errors. Calling erlang:get_cookie() on NodeA however still shows the "default" cookie foo. How can find which cookie is set for NodeB?

标签: erlang
2条回答
混吃等死
2楼-- · 2019-02-24 15:21

It doesn't seem to be documented, but auth:get_cookie/1 does what you want. For your case, you can call auth:get_cookie(NodeB) on NodeA.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-02-24 15:37

You have to run the get_cookie/0 function on NodeB to get the name for that node. Simple solution is to do (on NodeA):

rpc:call(NodeB, erlang, get_cookie, []).

after you have connected the nodes.

Doing the erlang:set_cookie(NodeB, bar) call on NodeA just makes it possible for NodeA/NodeB to connect to each other, they still have their original cookies.

But to be able to connect to the other node you must already know the cookie for that node :)

查看更多
登录 后发表回答