分布式安全与 Cookie
使用魔术 Cookie、节点命名和 TLS 分布式通信,保护分布式 Erlang 节点之间的通信。
分布式安全与 Cookie 是 CoddyKit 上的免费 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Trust in a Cluster
Connected Erlang nodes fully trust each other: any node can run code on any other. That power makes securing distribution essential.
The Magic Cookie
Each node has a secret cookie. Two nodes can only connect if their cookies match. It is the basic authentication mechanism for clustering.
erlang:get_cookie().
% => 'SECRETCOOKIE'Setting the Cookie
You can set the cookie at startup or at runtime. All nodes that should cluster must share the same value.
% at startup:
% erl -setcookie SECRET -name node1@host
erlang:set_cookie(node(), 'SECRET').The .erlang.cookie File
If not set explicitly, the VM reads ~/.erlang.cookie. It must have restrictive permissions or the VM refuses to start.
% chmod 400 ~/.erlang.cookieShort vs Long Names
Nodes use -sname (short hostname) or -name (fully qualified). Both nodes must use the same scheme to connect.
% erl -sname worker
% erl -name worker@10.0.0.5Cookies Are Not Encryption
A matching cookie only authenticates the connection. By default, traffic between nodes is unencrypted. On untrusted networks you need TLS.
TLS Distribution
Erlang can tunnel all inter-node traffic over TLS using the inet_tls_dist module, configured via a proto_dist flag and a certificate file.
% erl -proto_dist inet_tls \
% -ssl_dist_optfile ssl_dist.conf \
% -name node1@hostThe ssl_dist Config
The config file points to your certificate, key, and CA so nodes mutually authenticate and encrypt.
[{server, [{certfile, "node.pem"},
{keyfile, "node.key"},
{cacertfile, "ca.pem"}]},
{client, [{cacertfile, "ca.pem"}]}].Restricting epmd Exposure
The Erlang Port Mapper Daemon (epmd) registers node ports. Never expose epmd or distribution ports to the public internet; firewall them or use a VPN.
Hidden Nodes
A node started with -hidden connects without joining the global mesh, useful for tools that should not be part of the cluster's full-trust topology.
% erl -hidden -name monitor@hostSecurity Checklist
For safe distribution:
- Use a strong, unique cookie
- Protect the cookie file (chmod 400)
- Enable TLS on untrusted networks
- Firewall epmd and distribution ports
Quick Check
Test your distribution security knowledge.
Recap
You learned to secure distributed Erlang.
- Matching cookies authenticate nodes
- Protect the
.erlang.cookiefile - Use TLS distribution for encryption
- Firewall epmd and distribution ports
常见问题解答
「分布式安全与 Cookie」课时是免费的吗?
是的 — 「分布式安全与 Cookie」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 课程的其余内容,请升级到 CoddyKit PRO。 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 课程共包含 4 节课。
「分布式安全与 Cookie」这节课中我会学到什么?
使用魔术 Cookie、节点命名和 TLS 分布式通信,保护分布式 Erlang 节点之间的通信。 你通过在浏览器中直接运行的动手代码来练习 Erlang OTP: Distributed & Fault-Tolerant Systems Programming,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「分布式安全与 Cookie」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 课中编写并运行代码吗?
能。每节 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 节点通信与配置
- 远程过程调用(RPC)
- 全局进程注册
- 分布式安全与 Cookie