feat: added per service enable options for fail2ban configs
This commit is contained in:
		
							parent
							
								
									ecec04a9ce
								
							
						
					
					
						commit
						a8af8930fa
					
				
					 4 changed files with 59 additions and 31 deletions
				
			
		|  | @ -3,36 +3,46 @@ | |||
|   pkgs, | ||||
|   config, | ||||
|   ... | ||||
| }: | ||||
| lib.mkIf (config.services.fail2ban.enable && config.services.home-assistant.enable) { | ||||
|   environment.etc = { | ||||
|     "fail2ban/filter.d/hass.local".text = ( | ||||
|       pkgs.lib.mkDefault (pkgs.lib.mkAfter '' | ||||
|         [INCLUDES] | ||||
|         before = common.conf | ||||
| 
 | ||||
|         [Definition] | ||||
|         failregex = ^%(__prefix_line)s.*Login attempt or request with invalid authentication from <HOST>.*$ | ||||
| 
 | ||||
|         ignoreregex = | ||||
| 
 | ||||
|         [Init] | ||||
|         datepattern = ^%%Y-%%m-%%d %%H:%%M:%%S | ||||
|       '') | ||||
|     ); | ||||
| }: { | ||||
|   options.services.home-assistant = { | ||||
|     fail2ban = { | ||||
|       enable = lib.mkOption { | ||||
|         type = lib.types.bool; | ||||
|         default = config.services.fail2ban.enable && config.services.home-assistant.enable; | ||||
|       }; | ||||
|     }; | ||||
|   }; | ||||
| 
 | ||||
|   services.fail2ban = { | ||||
|     jails = { | ||||
|       home-assistant-iptables.settings = { | ||||
|         enabled = true; | ||||
|         filter = "hass"; | ||||
|         action = ''iptables-multiport[name=HTTP, port="http,https"]''; | ||||
|         logpath = "${config.services.home-assistant.configDir}/*.log"; | ||||
|         backend = "auto"; | ||||
|         findtime = 600; | ||||
|         bantime = 600; | ||||
|         maxretry = 5; | ||||
|   config = lib.mkIf config.services.home-assistant.fail2ban.enable { | ||||
|     environment.etc = { | ||||
|       "fail2ban/filter.d/hass.local".text = ( | ||||
|         pkgs.lib.mkDefault (pkgs.lib.mkAfter '' | ||||
|           [INCLUDES] | ||||
|           before = common.conf | ||||
| 
 | ||||
|           [Definition] | ||||
|           failregex = ^%(__prefix_line)s.*Login attempt or request with invalid authentication from <HOST>.*$ | ||||
| 
 | ||||
|           ignoreregex = | ||||
| 
 | ||||
|           [Init] | ||||
|           datepattern = ^%%Y-%%m-%%d %%H:%%M:%%S | ||||
|         '') | ||||
|       ); | ||||
|     }; | ||||
| 
 | ||||
|     services.fail2ban = { | ||||
|       jails = { | ||||
|         home-assistant-iptables.settings = { | ||||
|           enabled = true; | ||||
|           filter = "hass"; | ||||
|           action = ''iptables-multiport[name=HTTP, port="http,https"]''; | ||||
|           logpath = "${config.services.home-assistant.configDir}/*.log"; | ||||
|           backend = "auto"; | ||||
|           findtime = 600; | ||||
|           bantime = 600; | ||||
|           maxretry = 5; | ||||
|         }; | ||||
|       }; | ||||
|     }; | ||||
|   }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue