Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/samba-wsdd: openFirewall option does not allow multicast traffic #309910

Open
xieve opened this issue May 7, 2024 · 4 comments
Open

nixos/samba-wsdd: openFirewall option does not allow multicast traffic #309910

xieve opened this issue May 7, 2024 · 4 comments

Comments

@xieve
Copy link

xieve commented May 7, 2024

Describe the bug

Machines (called "servers" from hereon) running the samba-wsdd modules with openFirewall set to true will announce themselves on the network when wsdd starts up, but will not receive multicasts from scanning Windows machines (called "clients" from hereon). This results in servers only showing up in the Windows Explorer network section when wsdd is (re-)started while the Explorer is open, but not when you open or refresh the Explorer while wsdd is running.

Steps To Reproduce

Steps to reproduce the behavior:
1.

services.samba-wsdd = {
  enable = true;
  openFirewall = true;
};
  1. Rebuild
  2. Server will show up on client
  3. Hit F5 in the Explorer
  4. Server will disappear in Explorer
  5. systemctl stop firewall.service
  6. Hit F5 in Explorer
  7. Server will appear in Explorer

Expected behavior

services.samba-wsdd.openFirewall should configure the firewall in a way that does not block any traffic sent or received by the service. I have found this configuration, which works for me*:
*Edit: Because it crashes firewall.service, oops.

networking.firewall.extraCommands = ''
  iptables -s 224.0.0.0/24 -j nixos-fw-accept
'';

I don't know whether this is fine security-wise. IPv6 should probably also be configured similarly.

Notify maintainers

@Izorkin

Metadata

$ nix run nixpkgs#nix-info -- -m 
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.79, NixOS, 24.05 (Uakari), 24.05.20240229.1536926`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/store/lwyjz70qh12nq6cb7fixl85vryzxqm3c-source`

Add a 👍 reaction to issues you find important.

@Izorkin
Copy link
Contributor

Izorkin commented May 7, 2024

Working this variant?:

networking.firewall.extraCommands = ''
  iptables -s 239.255.255.250 -j nixos-fw-accept
'';

Information from https://github.com/christgau/wsdd#firewall-setup

@Izorkin
Copy link
Contributor

Izorkin commented May 7, 2024

On my home server I use this variant:

      iptables -t filter -N SAMBA-WSDD
      iptables -t filter -A SAMBA-WSDD -p udp -m state --state NEW -m udp --dport 3702 -s 192.168.0.0/24 -j ACCEPT
      iptables -t filter -A SAMBA-WSDD -p udp -m state --state NEW -m udp --sport 3702 -s 192.168.0.0/24 -j ACCEPT
      iptables -t filter -A SAMBA-WSDD -p tcp -m state --state NEW -m tcp --dport 5357 -s 192.168.0.0/24 -j ACCEPT
      iptables -t filter -A SAMBA-WSDD -p tcp -m state --state NEW -m tcp --sport 5357 -s 192.168.0.0/24 -j ACCEPT
      iptables -t filter -A SAMBA-WSDD -p igmp -m state --state NEW -m pkttype --pkt-type multicast -d 239.255.255.250 -j ACCEPT
      iptables -t filter -A SAMBA-WSDD -j RETURN

@xieve
Copy link
Author

xieve commented May 7, 2024

Working this variant?:

networking.firewall.extraCommands = ''
  iptables -s 239.255.255.250 -j nixos-fw-accept
'';

Information from https://github.com/christgau/wsdd#firewall-setup

Oh, I just realized my iptables commands are complete bogus. The reason this works anyway is that firewall.service will fail silently and just not start lol. Here's a config that actually works:

networking.firewall.extraCommands = ''
  iptables -A nixos-fw -p udp -m conntrack --ctstate NEW -m pkttype --pkt-type multicast -d 239.255.255.250 -j nixos-fw-accept
  ip6tables -A nixos-fw -p udp -m conntrack --ctstate NEW -m pkttype --pkt-type multicast -d ff02::c -j nixos-fw-accept
'';

I'm still improving on this at the moment. IPv4 is not really working.

@xieve
Copy link
Author

xieve commented May 8, 2024

networking.firewall.extraCommands = ''
  iptables -A nixos-fw -p udp -m pkttype --pkt-type multicast -m udp --dport 3702 -d 239.255.255.250/32 -j nixos-fw-accept
  ip6tables -A nixos-fw -p udp -m pkttype --pkt-type multicast -m udp --dport 3702 -d ff02::c/128 -j nixos-fw-accept
'';

I think this should be sufficiently precise. I have confirmed that it works via IPv6 and IPv4. Afaik this will not work with nftables, sadly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants