Erlang如何限制节点对集群的访问之net_kernel:allow
浏览:3592次 出处信息
默认情况下Erlang的集群访问是全授权的,只要cookie认证过了后,新加入的节点可以访问集群里面的任何机器,这给运维带来很大风险。目前erlang有二种方法可以限制 1. IP网段限制,参看这里 2. 节点名称限制。这个是通过net_kernel:allow来实现的,参看:
allow/1
Limits access to the specified set of nodes. Any access attempts made from (or to) nodes not in Nodes will be rejected.
Returns error if any element in Nodes is not an atom.
我们假设集群有节点x,y,z, foo:
1. 有个节点叫foo, 它只允许来自x,y节点的请求,其他的节点访问被拒;
2. z只能访问x,其他拒
我们来试验下:
$ erl -name foo@127.0.0.1 Erlang R14B04 (erts-5.8.5) 1 [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) (foo@127.0.0.1)1> net_kernel:allow([\'x@127.0.0.1\', \'y@127.0.0.1\']). ok (foo@127.0.0.1)2>
在其他终端运行:
$ erl -name x@127.0.0.1 Erlang R14B04 (erts-5.8.5) 1 [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) (x@127.0.0.1)1> net_adm:ping(\'foo@127.0.0.1\'). pong (x@127.0.0.1)2> $ erl -name y@127.0.0.1 Erlang R14B04 (erts-5.8.5) 1 [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) (y@127.0.0.1)1> net_adm:ping(\'foo@127.0.0.1\'). pong (y@127.0.0.1)2> $ erl -name z@127.0.0.1 Erlang R14B04 (erts-5.8.5) 1 [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false] Eshell V5.8.5 (abort with ^G) (z@127.0.0.1)1> net_adm:ping(\'foo@127.0.0.1\'). pang (z@127.0.0.1)2> net_adm:ping(\'y@127.0.0.1\'). pong (z@127.0.0.1)3> net_kernel:disconnect(\'y@127.0.0.1\'). true (z@127.0.0.1)4> net_kernel:allow([\'x@127.0.0.1\']). ok (z@127.0.0.1)5> net_adm:ping(\'y@127.0.0.1\'). =ERROR REPORT==== 24-Oct-2011::01:23:34 === ** Connection attempt with disallowed node \'y@127.0.0.1\' ** pang
同时我们会在foo的终端上看到:
=ERROR REPORT==== 24-Oct-2011::01:08:20 === ** Connection attempt from disallowed node \'z@127.0.0.1\' ** (foo@127.0.0.1)2>
看代码:
...
%% dist_util.erl
%%
%% check if connecting node is allowed to connect
%% with allow-node-scheme
%%
is_allowed(#hs_data{other_node = Node,
allowed = Allowed} = HSData) ->
case lists:member(Node, Allowed) of
false when Allowed =/= [] ->
send_status(HSData, not_allowed),
error_msg("** Connection attempt from "
"disallowed node ~w ** ~n", [Node]),
?shutdown(Node);
_ -> true
end.
...
可以知道如果Allowed空的话,代表不做任何限制,否则net_kernel:allow限制主动和被动连接的节点。
建议继续学习:
- whatsapp深度使用Erlang有感 (阅读:5285)
- Erlang match_spec引擎介绍和应用 (阅读:5201)
- php-erlang (阅读:4885)
- 分析MySQL的授权许可 (阅读:4209)
- gen_tcp调用进程收到{empty_out_q, Port}消息奇怪行为分析 (阅读:3943)
- “好奇号”火星车和它搭载的软件(来自Erlang程序员的观点) (阅读:3961)
- hibernate使用注意事项 (阅读:3843)
- Erlang linkin driver用port_control方式时的一些经验分享 (阅读:3529)
- 【社会化设计】自我(self)部分――授权 (阅读:3310)
- ERLANG OTP源码分析 – gen_server (阅读:3261)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
扫一扫订阅我的微信号:IT技术博客大学习
<< 前一篇:多些时间能少写些代码
后一篇:rebar和common_test使用实践和疑惑澄清 >>
文章信息
- 作者:Yu Feng 来源: Erlang非业余研究
- 标签: Erlang net_kernel 授权
- 发布时间:2011-10-25 13:41:20
建议继续学习
近3天十大热文
-
[930] WordPress插件开发 -- 在插件使用 -
[130] 解决 nginx 反向代理网页首尾出现神秘字 -
[51] 如何保证一个程序在单台服务器上只有唯一实例( -
[51] 海量小文件存储 -
[50] 整理了一份招PHP高级工程师的面试题 -
[49] CloudSMS:免费匿名的云短信 -
[48] 全站换域名时利用nginx和javascri -
[48] 用 Jquery 模拟 select -
[47] Innodb分表太多或者表分区太多,会导致内 -
[46] ps 命令常见用法
