Add documentation that explains what is going on with the new daemon.

This commit is contained in:
Manuel Amador (Rudd-O) 2018-11-21 03:09:55 +00:00
parent e25b341d7c
commit 590ce707ad
5 changed files with 64 additions and 23 deletions

4
.gitignore vendored
View File

@ -1,4 +1,8 @@
rpm/
pkgs/
*.pyc *.pyc
*.pyo
*~ *~
*.tar.gz *.tar.gz
*.rpm *.rpm
.*.swp

3
Makefile.builder Normal file
View File

@ -0,0 +1,3 @@
ifeq ($(PACKAGE_SET),dom0)
RPM_SPEC_FILES=qubes-network-server.spec
endif

View File

@ -1,3 +1,5 @@
%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
%define debug_package %{nil} %define debug_package %{nil}
%define mybuildnumber %{?build_number}%{?!build_number:1} %define mybuildnumber %{?build_number}%{?!build_number:1}
@ -37,8 +39,8 @@ make install DESTDIR=$RPM_BUILD_ROOT BINDIR=%{_bindir} LIBDIR=%{_libdir}
%files %files
%attr(0755, root, root) %{_bindir}/qvm-static-ip %attr(0755, root, root) %{_bindir}/qvm-static-ip
%attr(0644, root, root) %{_libdir}/python2.7/site-packages/qubes/modules/*.py* %attr(0644, root, root) %{python_sitearch}/qubes/modules/*.py*
%attr(0644, root, root) %{_libdir}/python2.7/site-packages/qubes/modules/qubes-appvm-firewall %attr(0644, root, root) %{python_sitearch}/qubes/modules/qubes-appvm-firewall
%doc README.md TODO %doc README.md TODO
%changelog %changelog

View File

@ -96,35 +96,45 @@ class QubesProxyVm(OriginalQubesProxyVm):
rules_action = accept_action rules_action = accept_action
for rule in conf["rules"]: for rule in conf["rules"]:
if getattr(vm, "static_ip", None) and rule["address"].startswith("from-"): is_inbound = rule["address"].startswith("from-") and getattr(vm, "static_ip", None)
ruletext = "-s {0} -d {1}".format(rule["address"][len("from-"):], ip) if is_inbound:
if rule["netmask"] != 32: src_addr = rule["address"][len("from-"):]
ruletext += "/{0}".format(rule["netmask"]) src_mask = rule["netmask"]
dst_addr = ip
dst_mask = 32
else:
src_addr = ip
src_mask = 32
dst_addr = rule["address"]
dst_mask = rule["netmask"]
if rule["proto"] is not None and rule["proto"] != "any": args = []
ruletext += " -p {0}".format(rule["proto"])
if rule["portBegin"] is not None and rule["portBegin"] > 0:
ruletext += " --dport {0}".format(rule["portBegin"])
if rule["portEnd"] is not None and rule["portEnd"] > rule["portBegin"]:
ruletext += ":{0}".format(rule["portEnd"])
ruletext += " -j {0}\n".format(rules_action) def constrain(sd, addr, mask):
iptables += "-A PR-QBS-FORWARD " + ruletext if mask != 0:
vm_iptables += "-A FORTRESS-INPUT " + ruletext if mask == 32:
continue args.append("{0} {1}".format(sd, addr))
else:
args.append("{0} {1}/{2}".format(sd, addr, mask))
iptables += "-A PR-QBS-FORWARD -s {0} -d {1}".format(ip, rule["address"]) constrain("-s", src_addr, src_mask)
if rule["netmask"] != 32: constrain("-d", dst_addr, dst_mask)
iptables += "/{0}".format(rule["netmask"])
if rule["proto"] is not None and rule["proto"] != "any": if rule["proto"] is not None and rule["proto"] != "any":
iptables += " -p {0}".format(rule["proto"]) args.append("-p {0}".format(rule["proto"]))
if rule["portBegin"] is not None and rule["portBegin"] > 0: if rule["portBegin"] is not None and rule["portBegin"] > 0:
iptables += " --dport {0}".format(rule["portBegin"])
if rule["portEnd"] is not None and rule["portEnd"] > rule["portBegin"]: if rule["portEnd"] is not None and rule["portEnd"] > rule["portBegin"]:
iptables += ":{0}".format(rule["portEnd"]) portrange = "{0}:{1}".format(rule["portBegin"], rule["portEnd"])
else:
portrange = rule["portBegin"]
args.append("--dport {0}".format(portrange))
iptables += " -j {0}\n".format(rules_action) args.append("-j {0}".format(rules_action))
ruletext = ' '.join(args)
iptables += "-A PR-QBS-FORWARD {0}\n".format(ruletext)
if is_inbound:
vm_iptables += "-A FORTRESS-INPUT {0}\n".format(ruletext)
if conf["allowDns"] and self.netvm is not None: if conf["allowDns"] and self.netvm is not None:
# PREROUTING does DNAT to NetVM DNSes, so we need self.netvm. # PREROUTING does DNAT to NetVM DNSes, so we need self.netvm.

View File

@ -1,5 +1,27 @@
#!/usr/bin/env python #!/usr/bin/env python
'''
This code is intended to replace the very fragile firewall generation code
that currently runs on dom0, by a lightweight daemon that applies the rules
on the AppVM (with static IP), responding to rule changes made by the
administrator on-the-fly.
This daemon is injected into the VM as soon as qrexec capability becomes
available on the recently-started VM. The daemon:
1. Reads the QubesDB key /qubes-fortress-iptables-rules.
2. Atomically applies the rules therein saved therein.
The rules in /qubes-fortress-iptables-rules are generated by the dom0 code
in 007FortressQubesProxyVM, which in turn are based on the firewall rules
that the administrator has configured. These rules are generated and applied
at the same time as the rules generated and applied on the ProxyVM attached to
the AppVM, ensuring that the rules in the VM are kept in sync with the rules
in the ProxyVM at all times.
FIXME: The previous paragraph is still a work in progress.
'''
import collections import collections
import logging import logging
import os import os