quic_dist_auth behaviour (quic v3.1.2)

View Source

Optional authentication callback invoked between the QUIC handshake and the Erlang distribution handshake.

Configure via the auth_callback option (sys.config or -quic_dist auth_callback Mod:Fun):

   {quic, [{dist, [
     {auth_callback, {my_app_auth, authenticate}},
     {auth_handshake_timeout, 10000}
   ]}]}.

The callback runs on both sides. It can refuse the connection by returning {error, Reason}; the connection is then closed and the dist controller is never started.

A callback that proves which node is on the other end returns {ok, {authenticated_node, Node}}. quic_dist then refuses the connection unless the peer's dist node name is Node: on the server, the name the peer announces in the dist handshake; on the client, the node being dialed. A peer asking the server for a dynamic name is refused too. Any other {ok, Info} admits the peer without that check.

Summary

Functions

The node an auth result binds the connection to, if any.

Read the peer's node name from a dist handshake message the way dist_util does, so a name check sees the name dist_util will use. The name stays a string: dist_util turns it into an atom with list_to_atom/1, so it names node N exactly when it equals atom_to_list(N).

Invoke a configured callback, turning a crash or a bad return into {error, _} so a buggy implementation cannot take down the process running it. Callers must filter out undefined first.

Callbacks

authenticate/3

-callback authenticate(Conn :: pid(), Side :: client | server, Timeout :: timeout()) ->
                          {ok, Info :: term()} | {error, Reason :: term()}.

Functions

authenticated_node(Info)

-spec authenticated_node(Info :: term()) -> node() | undefined.

The node an auth result binds the connection to, if any.

peer_name(Data)

-spec peer_name(Data :: term()) -> {static, string()} | {dynamic, string()} | malformed | not_name.

Read the peer's node name from a dist handshake message the way dist_util does, so a name check sees the name dist_util will use. The name stays a string: dist_util turns it into an atom with list_to_atom/1, so it names node N exactly when it equals atom_to_list(N).

run(Callback, Conn, Side, Timeout)

-spec run(Callback :: quic_dist:auth_callback(),
          Conn :: pid(),
          Side :: client | server,
          Timeout :: timeout()) ->
             {ok, term()} | {error, term()}.

Invoke a configured callback, turning a crash or a bad return into {error, _} so a buggy implementation cannot take down the process running it. Callers must filter out undefined first.