Fix WireGuard nat rules
This commit is contained in:
		
					parent
					
						
							
								e0d1e17bbb
							
						
					
				
			
			
				commit
				
					
						3723b4edf2
					
				
			
		
					 11 changed files with 269 additions and 61 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
{ ... }:
 | 
			
		||||
{ pkgs, ... }:
 | 
			
		||||
{
 | 
			
		||||
  boot.loader.grub = {
 | 
			
		||||
    enable = true;
 | 
			
		||||
| 
						 | 
				
			
			@ -14,6 +14,43 @@
 | 
			
		|||
      enable = true;
 | 
			
		||||
      allowedUDPPorts = [ 51820 ];
 | 
			
		||||
    };
 | 
			
		||||
    # mail-2 VPN
 | 
			
		||||
    wireguard = {
 | 
			
		||||
      enable = true;
 | 
			
		||||
      interfaces.wg0 = {
 | 
			
		||||
        listenPort = 51820;
 | 
			
		||||
        ips = [
 | 
			
		||||
          "172.16.50.1/24"
 | 
			
		||||
        ];
 | 
			
		||||
        peers = [
 | 
			
		||||
          {
 | 
			
		||||
            name = "mail-2";
 | 
			
		||||
            publicKey = "OIBOJlFzzM3P/u1ftVW2HWt8kA6NveB4PaBOIXhCYhM=";
 | 
			
		||||
            presharedKeyFile = "/secrets/wireguard-lifeline-mail-2-lifeline-psk.secret";
 | 
			
		||||
            allowedIPs = [ "172.16.50.2/32" ];
 | 
			
		||||
          }
 | 
			
		||||
        ];
 | 
			
		||||
        postSetup = ''
 | 
			
		||||
          ${pkgs.iptables}/bin/iptables -A FORWARD -i wg0 -j ACCEPT
 | 
			
		||||
          ${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 172.16.50.0/24 -o ens6 -j MASQUERADE
 | 
			
		||||
        '';
 | 
			
		||||
        postShutdown = ''
 | 
			
		||||
          ${pkgs.iptables}/bin/iptables -D FORWARD -i wg0 -j ACCEPT
 | 
			
		||||
          ${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s 172.16.50.0/24 -o ens6 -j MASQUERADE
 | 
			
		||||
        '';
 | 
			
		||||
        privateKeyFile = "/secrets/wireguard-lifeline-wg0-privatekey.secret";
 | 
			
		||||
      };
 | 
			
		||||
    };
 | 
			
		||||
    nat = {
 | 
			
		||||
      enable = true;
 | 
			
		||||
      internalInterfaces = [ "wg0" ];
 | 
			
		||||
      externalInterface = "ens6";
 | 
			
		||||
      forwardPorts = [{
 | 
			
		||||
          destination = "172.16.50.2:25";
 | 
			
		||||
          proto = "tcp";
 | 
			
		||||
          sourcePort = 25;
 | 
			
		||||
      }];
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  services.prometheus.exporters.node.enable = false;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,15 +1,15 @@
 | 
			
		|||
{ ... }:
 | 
			
		||||
{
 | 
			
		||||
  deployment.keys."wireguard-lifeline-mail-1-lifeline-psk.secret" = {
 | 
			
		||||
    keyCommand = [ "env" "GNUPGHOME=/home/yuri/.passinfra_gnupg" "PASSWORD_STORE_DIR=/home/yuri/pass/infra" "pass" "wireguard/lifeline-mail-1/psk" ];
 | 
			
		||||
  deployment.keys."wireguard-lifeline-wg0-privatekey.secret" = {
 | 
			
		||||
    keyCommand = [ "env" "GNUPGHOME=/home/yuri/.passinfra_gnupg" "PASSWORD_STORE_DIR=/home/yuri/pass/infra" "pass" "wireguard/lifeline-wg0-privatekey" ];
 | 
			
		||||
    destDir = "/secrets";
 | 
			
		||||
    user = "root";
 | 
			
		||||
    group = "root";
 | 
			
		||||
    permissions = "0640";
 | 
			
		||||
    uploadAt = "pre-activation";
 | 
			
		||||
  };
 | 
			
		||||
  deployment.keys."wireguard-lifeline-mail-1-lifeline-privatekey.secret" = {
 | 
			
		||||
    keyCommand = [ "env" "GNUPGHOME=/home/yuri/.passinfra_gnupg" "PASSWORD_STORE_DIR=/home/yuri/pass/infra" "pass" "wireguard/lifeline-mail-1/lifeline-privatekey" ];
 | 
			
		||||
  deployment.keys."wireguard-lifeline-mail-2-lifeline-psk.secret" = {
 | 
			
		||||
    keyCommand = [ "env" "GNUPGHOME=/home/yuri/.passinfra_gnupg" "PASSWORD_STORE_DIR=/home/yuri/pass/infra" "pass" "wireguard/lifeline-mail-2/psk" ];
 | 
			
		||||
    destDir = "/secrets";
 | 
			
		||||
    user = "root";
 | 
			
		||||
    group = "root";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue