强化分布式 Cookie 与节点访问控制
使用 Cookie、允许节点列表和网络隔离限制可连接到集群的节点,防止未经授权的访问。
强化分布式 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 节课。
本课时的部分内容尚未翻译,以英文显示。
How Nodes Authenticate
Erlang nodes form a cluster by sharing a secret cookie. Any node that knows the cookie and can reach the port may connect — and once connected, can run arbitrary code. This makes the cookie a critical secret.
The Magic Cookie
By default each node reads its cookie from ~/.erlang.cookie. If two nodes share it, they trust each other completely.
erlang:get_cookie().The Danger of Defaults
A weak or default cookie on a publicly reachable distribution port is a full remote-code-execution hole. Treat the cookie like a root password.
Setting a Strong Cookie
Set a long, random cookie explicitly at startup rather than relying on the file default.
erlang:set_cookie(node(), 'a-very-long-random-secret').Protecting the Cookie File
The cookie file must be readable only by its owner. Erlang refuses to start if permissions are too open.
chmod 400 ~/.erlang.cookieRestricting Node Names
Use net_kernel options and firewall rules so only known hostnames can even attempt a connection. Distribution should never be exposed to the open internet.
Binding the Distribution Port
Pin the distribution to specific ports and bind EPMD to a private interface so the cluster is unreachable from outside the trusted network.
erl -kernel inet_dist_listen_min 9100 inet_dist_listen_max 9105Monitoring Connections
nodes/0 lists currently connected nodes. Periodically auditing this list helps detect an unexpected peer.
nodes().Reacting to New Nodes
Subscribe to node up/down events with net_kernel:monitor_nodes/1 to log or reject connections you did not expect.
net_kernel:monitor_nodes(true).Hidden Nodes
Start tooling or monitoring nodes as hidden with -hidden so they connect without joining the full mesh, reducing the trust surface of your cluster.
erl -hidden -name tool@10.0.0.5 -setcookie SECRETDefense in Depth
Cookies alone are not enough. Combine them with TLS distribution, a private network (VPN/VLAN), firewalled EPMD, and least-privilege node placement.
Quick Check
Test your node security knowledge.
Recap
You learned to harden node access:
- The shared cookie is the cluster password — keep it long, random, secret
- Protect
~/.erlang.cookiewith 400 permissions - Bind distribution and EPMD to private interfaces; firewall them
- Audit connected nodes with
nodes/0and monitor events - Layer cookies with TLS and network isolation
用 AI 导师学习 Erlang — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「强化分布式 Cookie 与节点访问控制」课时是免费的吗?
是的 — 「强化分布式 Cookie 与节点访问控制」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 课程的其余内容,请升级到 CoddyKit PRO。 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 课程共包含 4 节课。
「强化分布式 Cookie 与节点访问控制」这节课中我会学到什么?
使用 Cookie、允许节点列表和网络隔离限制可连接到集群的节点,防止未经授权的访问。 你通过在浏览器中直接运行的动手代码来练习 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 反馈 — 无需本地设置。
此课程中的所有课时
- 安全节点通信(TLS)
- 身份验证与授权
- 保护敏感数据
- 强化分布式 Cookie 与节点访问控制