Cluster.Strategy.AuthenticatedGossip (libcluster v3.6.1)

Copy Markdown View Source

This clustering strategy gossips node names over multicast UDP, like Cluster.Strategy.Gossip, but every heartbeat is encrypted and authenticated. Use it when hosts you do not control can reach the gossip port.

A heartbeat is only acted on if it was sealed by a node holding the same key, carries a timestamp close to the local clock, and is newer than the last heartbeat accepted from that node. Anything else is dropped before it is parsed: it creates no atoms, starts no connection attempts and leaves no state behind.

Key

The key is derived from the secret option. Without a secret, it is derived from the node's Erlang cookie, so nodes that are able to connect to each other can also discover each other with no further configuration. The cookie is read again at every heartbeat, so a changed cookie takes effect within a few seconds. A node that has neither a secret nor a cookie (distribution is not started) neither announces itself nor accepts heartbeats.

Configure a secret if you use per-node cookies, or if the cookie is weak: a recorded heartbeat lets someone test guesses for the key material offline, as a recorded distribution handshake does for the cookie.

Clocks

Heartbeats carry the sender's system time. A heartbeat is ignored if that time differs from the receiver's clock by more than max_clock_skew milliseconds (30,000 by default), which is what stops recorded heartbeats from being replayed later. Nodes therefore need roughly synchronized clocks. When an authentic heartbeat is ignored for this reason a warning is logged, at most once a minute.

What this does not protect against

Anyone holding the secret or cookie is trusted to announce any node name. Someone able to saturate the network or the socket's receive buffer can delay discovery for as long as they keep it up; excess datagrams are dropped by the operating system rather than queued in the VM.

This strategy does not interoperate with Cluster.Strategy.Gossip. Both may use the same port and multicast address; each ignores the other's packets.

Configuration

config :libcluster,
  topologies: [
    gossip_example: [
      strategy: Elixir.Cluster.Strategy.AuthenticatedGossip,
      config: [
        port: 45892,
        if_addr: "0.0.0.0",
        multicast_if: "192.168.1.1",
        multicast_addr: "233.252.1.32",
        multicast_ttl: 1,
        secret: "somepassword",
        max_clock_skew: 30_000]]]

port, if_addr, multicast_if, multicast_addr, multicast_ttl and broadcast_only behave as they do for Cluster.Strategy.Gossip, including port sharing between nodes on one host and the {:udp_open_failed, reason, [port: port, if_addr: address]} stop reason.

Wire format

"LCAG" | version (1) | nonce (12 bytes) | ciphertext | tag (16 bytes)

The ciphertext is AES-256-GCM over a 64-bit millisecond timestamp followed by the node name in UTF-8, with the first five bytes as associated data. The key is HKDF-SHA-256 of the secret or cookie.

Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for Cluster.Strategy.start_link/1.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(args)

Callback implementation for Cluster.Strategy.start_link/1.