Compare commits

...

13 Commits

Author SHA1 Message Date
Egor Savkin ed9b79a2d7 Fix postfix settings so it should load successfully and accept and send messages through tunnel
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-08 16:28:25 +08:00
Egor Savkin 95ee041e13 Fix postfix settings so it should load successfully
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-07 16:43:57 +08:00
Egor Savkin 451328c28b Add virtual ips for the gre tunnel
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin 91260e8ec5 Return swan into the zoo
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin 291d5c1ee3 Use IPv6 for WG transport to decrease latency by 20%
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin 67c1f49478 Ip rules instead of iptables tracking
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin 2949d444bc Apply tested client configuration
Adds an additional route, but doesn't enforce it so other apps will remain the same, but smtp can use tunnel for sending. Also sends replies through the tunnel if connection arrives on the tunnel.
Better have something tested and working before I start doing "perfect".

Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin 7a378cacad Use wireguard instead of strongswan since its in the kernel
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin ec259b1789 WIP: Use gre/ipsec instead of proxy
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin 10bbd4f55d Use proxychains-ng instead of tsocks
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin 355c69f1b0 Use tsocks to wrap socks and add sock transport type
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin 2ea87d3d1b Use wildcard instead of explicit specification
As in example at https://www.postfix.org/transport.5.html

Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
Egor Savkin d1dbdca0cb Use postfix options for routing mails through ssh tunnel
Signed-off-by: Egor Savkin <es@m-labs.hk>
2024-10-04 15:25:52 +08:00
2 changed files with 80 additions and 2 deletions

View File

@ -228,6 +228,29 @@ in
}
];
};
greTunnels.intl0 = {
dev = netifWan;
remote = "5.78.86.156";
local = "94.190.212.123";
ttl = 255;
type = "tun";
};
interfaces.intl0 = {
ipv4.addresses = [
{
address = "10.47.3.1";
prefixLength = 31;
}
];
ipv4.routes = [
{
address = "0.0.0.0";
prefixLength = 0;
via = "10.47.3.0";
options.table = "3";
}
];
};
vlans = {
"${netifAltVlan}" = {
id = 2;
@ -280,6 +303,27 @@ in
after = [ "network-addresses-${netifAlt}.service" ];
requires = [ "network-addresses-${netifAlt}.service" ];
};
services.strongswan-swanctl.swanctl.connections.intl = {
local_addrs = [ "94.190.212.123" ];
remote_addrs = [ "5.78.86.156" ];
local.main = {
auth = "pubkey";
id = "fqdn:m-labs.hk";
pubkeys = [ "/etc/swanctl/pubkey/m-labs.hk" ];
};
remote.main = {
auth = "pubkey";
id = "fqdn:m-labs-intl.com";
pubkeys = [ "/etc/swanctl/pubkey/m-labs-intl.com" ];
};
children.intl0 = {
mode = "transport";
ah_proposals = [ "sha256-curve25519" ];
remote_ts = [ "5.78.86.156[gre]" ];
local_ts = [ "94.190.212.123[gre]" ];
start_action = "start";
};
};
systemd.services.network-custom-route-backup = {
wantedBy = [ "network.target" ];
@ -299,6 +343,15 @@ in
ExecStop = "${pkgs.iproute2}/bin/ip rule del table 1";
};
};
systemd.services.network-custom-route-intl = {
wantedBy = [ "network.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${pkgs.iproute2}/bin/ip rule add from 10.47.3.0/31 table 3";
ExecStop = "${pkgs.iproute2}/bin/ip rule del table 3";
};
};
# https://kb.isc.org/docs/dnssec-key-and-signing-policy
# chown named.named /etc/nixos/named
@ -1207,6 +1260,18 @@ in
};
};
services.postfix.mapFiles.sender_transport = pkgs.writeText "sender_transport" ''
@m-labs-intl.com intltunnel:
* :
'';
systemd.services.postfix-rebuild-sender-relay = {
description = "Postfix Rebuild Sender Dependent Transport Maps";
serviceConfig = {
ExecStart = "${pkgs.postfix}/sbin/postmap /var/lib/postfix/conf/sender_transport";
};
wantedBy = [ "multi-user.target" ];
};
mailserver = {
enable = true;
localDnsResolver = false; # conflicts with dnsmasq
@ -1215,8 +1280,22 @@ in
enablePop3 = true;
enablePop3Ssl = true;
certificateScheme = "acme-nginx";
policydSPFExtraConfig = "skip_addresses = 5.78.86.156,2a01:4ff:1f0:83de::1";
} // (import /etc/nixos/secret/email_settings.nix);
services.postfix = {
config = {
sender_dependent_default_transport_maps = "hash:/var/lib/postfix/conf/sender_transport";
};
masterConfig."intltunnel" = {
type = "unix";
command = "smtp";
args = [
"-o" "smtp_bind_address=10.47.3.1"
"-o" "inet_interfaces=10.47.3.1"
"-o" "inet_protocols=ipv4"
];
};
};
services.roundcube = {
enable = true;
hostName = "mail.m-labs.hk";

View File

@ -23,7 +23,6 @@ ns A 94.190.212.123
ns AAAA 2001:470:18:390::2
mail A 5.78.86.156
mail AAAA 2a01:4ff:1f0:83de::1
mail._domainkey IN TXT "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJVPuhSGXghO7ib8Em/Se3jfCCIJK5g4zn5pGZ3/e0I0f+zGHMuvwpjkAKf6eSmo/AAXEaco28pDi3qE5xfV512AJsORCfPoPFyNhLsj/qtri6hc5KVSWW0Ja3MSFBINDCaX78c7PXPY+3jJJGpwSBDLjdxj9AQwtfiCVlH4qE/QIDAQAB"
_dmarc TXT "v=DMARC1; p=none"