안전한 노드 통신(TLS)
TLS/SSL을 사용하여 Erlang 노드가 안전하게 통신하도록 구성하고 네트워크를 통해 전송되는 데이터를 암호화합니다.
안전한 노드 통신(TLS)은(는) CoddyKit의 무료 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Secure Erlang Nodes?
When Erlang nodes communicate, especially across a network or in a production environment, their interactions need to be secure. This prevents eavesdropping, tampering, and unauthorized access.
By default, Erlang's distribution protocol doesn't encrypt communication. This lesson will show you how to add a layer of security using TLS/SSL.
TLS: The Security Handshake
TLS (Transport Layer Security) and its predecessor SSL (Secure Sockets Layer) are cryptographic protocols designed to provide communication security over a computer network.
They achieve this by:
- Encryption: Scrambling data so only the intended recipient can read it.
- Authentication: Verifying the identity of the communicating parties.
- Data Integrity: Ensuring data hasn't been altered in transit.
Erlang's Distribution Protocol
Erlang nodes communicate using a built-in distribution protocol. Typically, you start nodes like this:
erl -sname node1
This creates a connection that's fast and efficient, but it does not inherently use encryption. For secure communication, we need to instruct Erlang to use TLS for its distribution.
Certificates & Keys for Trust
TLS relies on a system of digital certificates and private keys to establish trust and secure connections. Think of them as digital IDs.
- Private Key: A secret key used to encrypt/decrypt data and sign certificates. Keep it absolutely secure!
- Certificate (Public Key): Contains a public key and information about the entity (node). It's shared and used to verify identity.
- CA Certificate: A certificate from a Certificate Authority (CA) that signs other certificates, establishing a chain of trust.
Creating Test Certificates
For local testing, we can generate self-signed certificates using tools like openssl. In a production environment, you'd use certificates from a trusted CA.
Here's how to create a CA, a server certificate, and a client certificate:
# CA key and cert
openssl genrsa -out ca_key.pem 2048
openssl req -new -x509 -days 365 -key ca_key.pem -out ca.pem -subj "/CN=MyTestCA"
# Server key and cert
openssl genrsa -out server_key.pem 2048
openssl req -new -key server_key.pem -out server.csr -subj "/CN=server.test"
openssl x509 -req -days 365 -in server.csr -CA ca.pem -CAkey ca_key.pem -CAcreateserial -out server.pem
# Client key and cert
openssl genrsa -out client_key.pem 2048
openssl req -new -key client_key.pem -out client.csr -subj "/CN=client.test"
openssl x509 -req -days 365 -in client.csr -CA ca.pem -CAkey ca_key.pem -CAcreateserial -out client.pem
Configuring TLS on Node A (Server)
To enable TLS, we need to configure the Erlang kernel application. We set proto_dist to inet_tls and provide SSL options.
Node A (the 'server' in this context, listening for connections) needs its certificate, private key, and the CA certificate to verify clients.
erl -sname nodeA -kernel proto_dist inet_tls -kernel dist_listen_min 9000 -kernel dist_listen_max 9000 -kernel ssl_dist_opt '[{server,{certfile,"server.pem"},{keyfile,"server_key.pem"},{cacertfile,"ca.pem"}}, {client,{cacertfile,"ca.pem"}}]'
Note the dist_listen_min/max to fix the port for easier firewall setup.
Configuring TLS on Node B (Client)
Node B (the 'client', initiating a connection) also needs similar configuration. It provides its own certificate and key, and the CA certificate to verify the server.
erl -sname nodeB -kernel proto_dist inet_tls -kernel dist_listen_min 9001 -kernel dist_listen_max 9001 -kernel ssl_dist_opt '[{client,{certfile,"client.pem"},{keyfile,"client_key.pem"},{cacertfile,"ca.pem"}}]'
Both nodes must trust the CA that signed the other's certificate. This is why they both reference ca.pem.
First Secure Connection!
Let's put it all together! First, compile this simple module on both nodes. Then, start two Erlang nodes with the necessary TLS options (using your generated certificate files). Finally, try calling my_module:hello/0 remotely to see a secure interaction.
1. Compile the module:erlc my_module.erl
2. Start Node A (replace hostname with your machine's hostname):erl -sname nodeA@hostname -kernel proto_dist inet_tls -kernel dist_listen_min 9000 -kernel dist_listen_max 9000 -kernel ssl_dist_opt '[{server,{certfile,"server.pem"},{keyfile,"server_key.pem"},{cacertfile,"ca.pem"}}, {client,{cacertfile,"ca.pem"}}]'
3. Start Node B (in a new terminal):erl -sname nodeB@hostname -kernel proto_dist inet_tls -kernel dist_listen_min 9001 -kernel dist_listen_max 9001 -kernel ssl_dist_opt '[{client,{certfile,"client.pem"},{keyfile,"client_key.pem"},{cacertfile,"ca.pem"}}]'
4. On Node B, connect and call:net_adm:ping('nodeA@hostname').
rpc:call('nodeA@hostname', my_module, hello, []).
-module(my_module).
-export([hello/0]).
hello() ->
io:format("~p: Hello from secured node!~n", [node()]),
"Hello from secured node!".Confirming TLS Status
After connecting the nodes, you can verify that the connection is indeed using TLS. The ssl application provides functions to inspect active connections.
From either connected node, you can get information about the SSL connection. For example, on nodeA, after nodeB has connected:
{ok, Socket} = gen_tcp:connect("localhost", 9001, [binary, {active, false}, {packet, 4}, {reuseaddr, true}]).
{ok, SslSocket} = ssl:handshake(Socket, [{mode, client}]).
ssl:connection_info(SslSocket).
You should see details about the TLS version, cipher suite, and certificates in use.
Secure Connection Check
You've learned the fundamental steps to secure Erlang node communication with TLS. Let's test your understanding.
Secure Nodes: What We Learned
Congratulations! You've taken your first steps into securing distributed Erlang applications.
We covered:
- The importance of TLS for secure node communication.
- The core components: certificates, private keys, and Certificate Authorities.
- How to generate self-signed certificates for testing.
- Configuring Erlang nodes to use TLS with
proto_distandssl_dist_opt. - Running a basic secure distributed application.
Securing your Erlang systems is vital. Next, we'll explore how to handle authentication and authorization within your applications.
자주 묻는 질문
“안전한 노드 통신(TLS)” 강의는 무료인가요?
네 — “안전한 노드 통신(TLS)” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
“안전한 노드 통신(TLS)”에서 뭘 배우나요?
TLS/SSL을 사용하여 Erlang 노드가 안전하게 통신하도록 구성하고 네트워크를 통해 전송되는 데이터를 암호화합니다. 브라우저에서 직접 실행하는 실습 코드로 Erlang OTP: Distributed & Fault-Tolerant Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Erlang OTP: Distributed & Fault-Tolerant Systems Programming을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Erlang OTP: Distributed & Fault-Tolerant Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“안전한 노드 통신(TLS)” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 안전한 노드 통신(TLS)
- 인증 및 권한 부여
- 민감한 데이터 보호
- 분산 쿠키와 노드 접근 보안 강화