@@ -175,6 +175,16 @@ impl ClusterSettings {
175175 detail : "cluster.replication_factor must be at least 1" . into ( ) ,
176176 } ) ;
177177 }
178+ if self . insecure_transport && !nodedb_cluster:: insecure_transport_bind_allowed ( self . listen )
179+ {
180+ return Err ( crate :: Error :: Config {
181+ detail : format ! (
182+ "cluster.insecure_transport requires cluster.listen to use a loopback or \
183+ private address; {} is unspecified or publicly routable",
184+ self . listen
185+ ) ,
186+ } ) ;
187+ }
178188 if self . force_bootstrap && !self . seed_nodes . contains ( & self . listen ) {
179189 return Err ( crate :: Error :: Config {
180190 detail : "cluster.force_bootstrap requires cluster.listen to be present in \
@@ -185,3 +195,40 @@ impl ClusterSettings {
185195 Ok ( ( ) )
186196 }
187197}
198+
199+ #[ cfg( test) ]
200+ mod tests {
201+ use super :: * ;
202+
203+ fn insecure_settings ( listen : & str ) -> ClusterSettings {
204+ let listen = listen. parse ( ) . unwrap ( ) ;
205+ ClusterSettings {
206+ node_id : 1 ,
207+ listen,
208+ seed_nodes : vec ! [ listen] ,
209+ num_groups : 1 ,
210+ replication_factor : 1 ,
211+ force_bootstrap : false ,
212+ tls : None ,
213+ max_active_sessions : 0 ,
214+ login_attempts_per_ip_per_min : 30 ,
215+ login_attempts_per_user_per_min : 10 ,
216+ insecure_transport : true ,
217+ log_compaction_threshold : None ,
218+ }
219+ }
220+
221+ #[ test]
222+ fn insecure_transport_rejects_public_and_unspecified_binds ( ) {
223+ for listen in [ "0.0.0.0:9400" , "8.8.8.8:9400" , "[::]:9400" ] {
224+ assert ! ( insecure_settings( listen) . validate( ) . is_err( ) , "{listen}" ) ;
225+ }
226+ }
227+
228+ #[ test]
229+ fn insecure_transport_allows_private_binds ( ) {
230+ for listen in [ "127.0.0.1:9400" , "10.0.0.1:9400" , "[fd00::1]:9400" ] {
231+ assert ! ( insecure_settings( listen) . validate( ) . is_ok( ) , "{listen}" ) ;
232+ }
233+ }
234+ }
0 commit comments