Erlang如何限制节点对集群的访问之net_kernel:allow
2013-05-11 20:02
357 查看
本文转载自yufeng.info
默认情况下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,其他拒
我们来试验下:
view source
print?
在其他终端运行:
view source
print?
同时我们会在foo的终端上看到:
view source
print?
看代码:
view source
print?
可以知道如果Allowed空的话,代表不做任何限制,否则net_kernel:allow限制主动和被动连接的节点。
祝玩得开心!
默认情况下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,其他拒
我们来试验下:
view source
print?
$ 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> |
view source
print?
$ 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 |
view source
print?
=ERROR REPORT==== 24-Oct-2011::01:08:20 === |
** Connection attempt from disallowed node 'z@127.0.0.1' ** |
(foo@127.0.0.1)2> |
view source
print?
... |
%% 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 . |
... |
祝玩得开心!
相关文章推荐
- [Erlang 0098] net_kernel与节点互连,断开,监控
- 如何使用erlang 的shell 访问远程节点
- asp.net TreeView安装、使用(如何将TreeView打包发布)(带CheckBox选择框的TreeView的初始化,TreeView客户端操作:选择父节点后自动选择所有子节点,子节点选择后自动选择父节点)(TreeView节点精确定位)
- VB.net使用httpWebRequest访问带cookie的网站时如何传递cookie值
- asp.net网站如何保存历史访问记录
- Android 在 SElinux下 如何获得对一个内核节点的访问权限
- 如何限制windows用户访问磁盘
- [翻译]ASP.NET MVC 3 开发的20个秘诀(一)[20 Recipes for Programming MVC 3]:通过密码验证限制访问视图
- 如何从外部访问Kubernetes集群中的应用?
- [Erlang]Erlang与Java如何进行节点通信
- 如何限制访问一些网站
- 如何在Rancher 2.0 TP2 Kubernetes集群中添加自定义节点
- 限制用户访问某个目录,应该如何做?
- asp.net signalR 专题—— 第三篇 如何从外部线程访问 PersistentConnection
- 如何在AJAX应用中访问ADO.NET Data Service
- Redis集群节点变化如何处理?
- android在hal下 如何获得对一个内核节点的访问权限
- 如何将传递节点设置为通过使用 Visual C#.NET 内联 XSLT 脚本函数
- 再谈“ASP.NET网站限制恶意访问”
- [VB.NET]OLEDB.NET 如何访问Oracle8i