@@ -413,6 +413,110 @@ def test_static_host_map(self):
413413 assert "172.25.0.1" in config ["static_host_map" ]
414414 assert config ["static_host_map" ]["172.25.0.1" ] == ["1.2.3.4:4242" ]
415415
416+ def test_lighthouse_serve_dns (self ):
417+ """Lighthouse with serve_dns emits serve_dns and dns block inside lighthouse config."""
418+ nebula_mod .__pillar__ ["nebula" ]["hosts" ]["testhost" ]["is_lighthouse" ] = True
419+ nebula_mod .__pillar__ ["nebula" ]["hosts" ]["testhost" ]["serve_dns" ] = True
420+ nebula_mod .__pillar__ ["nebula" ]["hosts" ]["testhost" ]["dns" ] = {
421+ "host" : "172.25.0.2" ,
422+ "port" : 5353 ,
423+ }
424+ with patch .object (
425+ nebula_mod ,
426+ "detect_paths" ,
427+ return_value = {
428+ "ca_file" : "/etc/nebula/ca.crt" ,
429+ "cert_file" : "/etc/nebula/testhost.crt" ,
430+ "key_file" : "/etc/nebula/testhost.key" ,
431+ "config_dir" : "/etc/nebula" ,
432+ },
433+ ):
434+ config = nebula_mod .build_config ()
435+
436+ assert config ["lighthouse" ]["serve_dns" ] is True
437+ assert config ["lighthouse" ]["dns" ]["host" ] == "172.25.0.2"
438+ assert config ["lighthouse" ]["dns" ]["port" ] == 5353
439+
440+ def test_serve_dns_omitted_on_non_lighthouse (self ):
441+ """serve_dns is not emitted for regular nodes even if set in pillar."""
442+ nebula_mod .__pillar__ ["nebula" ]["hosts" ]["testhost" ]["serve_dns" ] = True
443+ with patch .object (
444+ nebula_mod ,
445+ "detect_paths" ,
446+ return_value = {
447+ "ca_file" : "/etc/nebula/ca.crt" ,
448+ "cert_file" : "/etc/nebula/testhost.crt" ,
449+ "key_file" : "/etc/nebula/testhost.key" ,
450+ "config_dir" : "/etc/nebula" ,
451+ },
452+ ):
453+ config = nebula_mod .build_config ()
454+
455+ assert "serve_dns" not in config ["lighthouse" ]
456+ assert "dns" not in config ["lighthouse" ]
457+
458+ def test_sshd_enabled (self ):
459+ """sshd block is built correctly from pillar."""
460+ nebula_mod .__pillar__ ["nebula" ]["hosts" ]["testhost" ]["sshd" ] = {
461+ "enabled" : True ,
462+ "listen" : "127.0.0.1:20022" ,
463+ "host_key" : "/etc/nebula/testhost_host" ,
464+ "authorized_users" : [{"user" : "alice" , "keys" : ["ssh-ed25519 AAAA..." ]}],
465+ }
466+ with patch .object (
467+ nebula_mod ,
468+ "detect_paths" ,
469+ return_value = {
470+ "ca_file" : "/etc/nebula/ca.crt" ,
471+ "cert_file" : "/etc/nebula/testhost.crt" ,
472+ "key_file" : "/etc/nebula/testhost.key" ,
473+ "config_dir" : "/etc/nebula" ,
474+ },
475+ ):
476+ config = nebula_mod .build_config ()
477+
478+ assert "sshd" in config
479+ assert config ["sshd" ]["enabled" ] is True
480+ assert config ["sshd" ]["listen" ] == "127.0.0.1:20022"
481+ assert config ["sshd" ]["host_key" ] == "/etc/nebula/testhost_host"
482+ assert config ["sshd" ]["authorized_users" ][0 ]["user" ] == "alice"
483+
484+ def test_sshd_default_host_key (self ):
485+ """sshd host_key defaults to config_dir/ssh_host_ed25519_key."""
486+ nebula_mod .__pillar__ ["nebula" ]["hosts" ]["testhost" ]["sshd" ] = {
487+ "enabled" : True ,
488+ "listen" : "127.0.0.1:22" ,
489+ }
490+ with patch .object (
491+ nebula_mod ,
492+ "detect_paths" ,
493+ return_value = {
494+ "ca_file" : "/etc/nebula/ca.crt" ,
495+ "cert_file" : "/etc/nebula/testhost.crt" ,
496+ "key_file" : "/etc/nebula/testhost.key" ,
497+ "config_dir" : "/etc/nebula" ,
498+ },
499+ ):
500+ config = nebula_mod .build_config ()
501+
502+ assert config ["sshd" ]["host_key" ] == "/etc/nebula/ssh_host_ed25519_key"
503+
504+ def test_sshd_absent_when_not_configured (self ):
505+ """sshd key is not emitted when not in pillar."""
506+ with patch .object (
507+ nebula_mod ,
508+ "detect_paths" ,
509+ return_value = {
510+ "ca_file" : "/etc/nebula/ca.crt" ,
511+ "cert_file" : "/etc/nebula/testhost.crt" ,
512+ "key_file" : "/etc/nebula/testhost.key" ,
513+ "config_dir" : "/etc/nebula" ,
514+ },
515+ ):
516+ config = nebula_mod .build_config ()
517+
518+ assert "sshd" not in config
519+
416520
417521# ---------------------------------------------------------------------------
418522# backup_config / rollback_config
0 commit comments