Commit graph

39 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
6622df9d38
allow to configure nfqueue bypass flag
Nfqueue bypass option skips the enqueue of packets to userspace
if no application is listening to the queue.
https://wiki.nftables.org/wiki-nftables/index.php/Queueing_to_userspace

If this flag is not specified, and for example the daemon dies
unexpectedly, all the outbound traffic will be blocked.

Up until now we've been using this flag by default not to block network
traffic if the daemon dies or is killed for some reason. But some users
want to use precisely this behaviour (#884, #1183, #1201).

Now you can configure it, to block connections if the daemon
unexpectedly dies.

The option is on by default in the configuration (QueueBypass: true).
If this item is not present in the daemon config file, then it'll be
false.
2024-10-19 10:51:40 +02:00
Gustavo Iñiguez Goia
efc05663eb
fw: allow to configure interception queue number
- Added new configuration field to allow configure fw interception
   number queue (default to 0):
   "FwOptions": {
      "QueueNum": 0
   }
   (we still need to reconfigure nfqueue queues in order for this to
take effect).
 - If the fw configuration path is not supplied, default to
   /etc/opensnitchd/system-fw.json
2024-05-14 23:41:25 +02:00
Gustavo Iñiguez Goia
bb95a77c58
sys-fw: load default config path if non supplied
By default load the system fw config file from
/etc/opensnitchd/system-fw.json.

There're these options to specify the file to load:

 - via cli option with -fw-config-file
 - writing it in the default-config.json file:
   "FwOptions": { "ConfigPath": "..." }

If both options are empty, then the default one is used.

FIXME:
 When the cli option is used to load the fw configuration, and the main
preferences are saved, the fw is reloaded but the path to the fw config
is lost.
2024-01-08 00:34:28 +01:00
Gustavo Iñiguez Goia
54ac5a3549
fw: allow to configure config file/ check interval
- Allow to configure system firewall configuration file path:
   * via cli (-fw-config-file).
   * via global configuration file.
 - Allow to configure fw rules check interval.

The system fw config file contains regular iptables/nftables rules.
Previously it was hardcoded to /etc/opensnitchd/system-fw.json

The interval to check if the interception rules were added was also
hardcoded to 10 seconds. Now it's possible to configure it.
A value of "0s" disables the interval, while "" defaults to 10 seconds.
2023-12-20 21:32:45 +01:00
Gustavo Iñiguez Goia
8740755f64
sys fw: report errors to the GUI after reloading
- Send errors to the server (GUI) if there's any error when reloading
   the system fw rules (far from being perfect/optimal, needs a
   rewrite).
 - Don't load the configuration after saving it, let the watcher reload
   it on write change to avoid double reload/duplicated errors.
2023-07-15 20:32:42 +02:00
Gustavo Iñiguez Goia
b7c6c8b8db
fw: minor changes for better code reading 2023-01-30 13:43:44 +01:00
Gustavo Iñiguez Goia
05e63e97a7
sys fw: improved chains creation
This is part of latest commit ced9a24933

 - When reusing a chain, configure the new policy.
 - Don't backup existing rules when reloading the configuration.
2022-12-23 00:50:22 +01:00
Gustavo Iñiguez Goia
c81dc22c02
sys fw: allow to change fw type from the GUI
- Configuration of system firewall rules from the GUI is not supported for
 iptables. Up until now only a warning was displayed, encouring to change
 fw type manually.

 Now if configured fw type is iptables (default-config.json, Firewall:),
 and the user opens the fw dialog, we'll ask the user to change it from
 the GUI.

- Add fw rules before connecting to the GUI. Otherwise we send to the
  GUI an invalid fw state.
2022-12-16 17:03:36 +01:00
Gustavo Iñiguez Goia
2e2f1768f2
improved errors printing 2022-12-11 11:41:47 +01:00
Gustavo Iñiguez Goia
09e9a8ac79
fw: report initialization errors
Allow send fw initialization errors to the server (UI).
2022-10-13 00:08:52 +02:00
Gustavo Iñiguez Goia
d9e0c59158
Allow to configure firewall rules from the GUI (#660)
* Allow to configure firewall rules from the GUI (WIP)

New features:
- Configure and list system firewall rules from the GUI (nftables).
- Configure chains' policies.
- Add simple rules to allow incoming ports.
- Add simple rules to exclude apps (ports) from being intercepted.

This feature is only available for nftables. iptables is still supported,
you can add rules to the configuration file and they'll be loaded, but
you can't configure them from the GUI.

More information: #592
2022-05-03 22:05:12 +02:00
Gustavo Iñiguez Goia
ba7c4e1878 allow to configure what firewall to use
Before this change, we tried to determine what firewall to use based on
the version of iptables (if -V legacy -> nftables, otherwise iptables).

This caused problems (#455), and as there's no support yet for nftables
system firewall rules, it can't be configured to workaround these
errors.

Now the default firewall to use will be iptables.
If it's not available (installed), can't be used or the configuration
option is empty/missing, we'll use nftables.
2021-08-09 00:32:27 +02:00
Gustavo Iñiguez Goia
da23c827f7 added nftables support
Added basic nftables support, which adds the needed rules to intercept
outgoing network traffic and DNS responses. System rules will be added
soon.

What netfilter subsystem to use is determined based on the following:
- nftables: if the _iptables_ binary is not present in the system, or
  if the iptables version (iptables -V) is
  "iptables vX.Y.Z (nf_tables)".
- iptables: in the rest of the cases.
2021-06-07 01:32:05 +02:00
themighty1
616681e44d flush conntrack at start 2021-02-28 15:21:07 +03:00
Gustavo Iñiguez Goia
0b978c0c1f
Merge pull request #361 from themighty1/master
clean up the obsolete "drop marked"
2021-02-28 10:01:18 +01:00
themighty1
b5bf4edec7 clean up the obsolete "drop marked" 2021-02-28 11:30:26 +03:00
themighty1
41172b65e5 minor fixes to prevent go vet from complaining 2021-02-13 19:18:38 +03:00
Gustavo Iñiguez Goia
f2c4b37d6e deleted output rule to drop marked packets
We had an OUTPUT rule to drop marked packets. Packets are marked with a
mark when a user defined rule denies a connection.

The thing is that we only intercept NEW connections, and when we deny a
connnection using NF_DROP, the packets doesn't flow to the next iptables
rule or chain. So it'd be rare to see a packet on the OUTPUT chain marked
with the DropMark.

Besides, nfq_set_verdict2() doesn't seem to place the mark on the
packets (libnetfilter-queue 1.0.5).

This OUTPUT rule had 0 hits on different systems and users.
2021-01-10 23:20:50 +01:00
Gustavo Iñiguez Goia
1384db6a1b fw: clean system rules before insert new ones
If the daemon exits unexpectedly, fw rules are not deleted.
So on every start/reload, clean any possible rule before adding new
ones.
2020-12-22 22:06:37 +01:00
Gustavo Iñiguez Goia
db31e5b71a fw: fixed 100% CPU spike, fixed cleaning rules
- Fixed 100% CPU spike when pausing interception from the GUI
gustavo-iniguez-goya/opensnitch/issues/104
- Fixed monitoring fw rules after re-enabling interception.
- Fixed cleaning up interception and system rules.
2020-12-12 18:16:59 +01:00
Gustavo Iñiguez Goia
e13015ce67 updated import paths 2020-12-09 18:18:42 +01:00
Gustavo Iñiguez Goia
df952d974e fixed errors when IPv6 is not enabled in the system
If IPv6 was not enabled we failed to add IPv6 rules.

closes #96
2020-11-26 16:25:48 +01:00
Gustavo Iñiguez Goia
a3a7becbc8 fixed exception if system-fw.json doesn't exist
closes #88
2020-11-15 00:53:13 +01:00
Gustavo Iñiguez Goia
831ab347e3 Merge branch 'priority-rules' into main
Added option to let the users define iptables rules.

The system rules are added in the file /etc/opensnitchd/system-fw.json
with this format:
```
{
    "SystemRules": [
        {
            "Rule": {
                "Description": "Allow pptp VPN",
                "Table": "mangle",
                "Chain": "OUTPUT",
                "Parameters": "-p gre",
                "Target": "ACCEPT",
                "TargetParameters": ""
            }
        }
    ]
}
```
On the mangle table, OUTPUT chain, these rules are added before
the NFQUEUE interception rule, so any rule you add there bypasses the
interception. Useful to allow traffic you don't want to intercept.

This feature solves in some way the issue some users have connecting to
VPNs when the Default Action configured in the daemon is Deny.

For example:
- OpenVPN when keepalive is configured and ICMP is used.
- PPTP because the GRE routing protocol is blocked.
- probably others like IPSEC.

(regarding WireGuard, as far as I can tell it works just fine, see #61).

closes #47
2020-11-13 00:14:39 +01:00
Gustavo Iñiguez Goia
df9e781051 Do not panic if we can't insert fw rules
Some systems has the IPV6 protocol disabled, so we failed starting up
with the error "Address family not supported by protocol" (#52).

Now we don't exist even if we can't insert the needed rules, we'll just
log the error.
2020-07-30 01:10:53 +02:00
Gustavo Iñiguez Goia
08245a075e intercept RELATED packets
We must intercept RELATED packets, not only for intercept protocols like
ftp-data, but also to handle connection errors (ICMP errors), like the
ones originated when dis/connecting from a wifi network.
2020-07-25 21:48:16 +02:00
Gustavo Iñiguez Goia
214e1b3c49 added priority rules to bypass/extend interception
In some scenarios (#47) may be useful to have a set of rules handled from
OpenSnitch, although you can accomplish it with other software (ufw,...).

This rules will sit just above default intercetion, so if you want to
allow or deny something, just place it here.

These priority rules are defined in /etc/opensnitchd/fw.json, with the
following format (example):

{
    "PriorityRules": {
        "out": {
            "allow": [
            ],
            "deny": [
                "-m conntrack --ctstate INVALID",
                "-p tcp ! --syn -m conntrack --ctstate NEW"
            ]
        }
    }
}

The structure must exist even if you haven't defined any rule, for
example:
{
    "PriorityRules": {
        "out": {
            "allow": [
            ],
            "deny": [
            ]
        }
    }
}
2020-07-25 21:23:53 +02:00
Gustavo Iñiguez Goia
034a95918e removed useless firewall log 2020-06-12 01:21:36 +02:00
Gustavo Iñiguez Goia
6ee80b1640 Allow to change settings from the UI
(1/2)
We start receiving notifications from the UI, which allow us to change
configurations and perform actions on the daemon.

The concept of Node has also been introduced, which identifies every
daemon (client) connected to the UI (server).

These options has been added:
- Enable/Disable firewall interception (for all nodes)
- Change daemons (clients) configuration. globally or per node.
- Change prompt dialog options.

We have fixed some bugs along the way:
- Close audit client connection gracefully.
- Exclude our own connections from being intercepted.
- Better handling of client connection status with the UI.

We probably has also introduced some other bugs (not listed here).
2020-04-19 20:13:31 +02:00
Gustavo Iñiguez Goia
6e3336258c firewall/rules.go formatted and documented. 2020-03-06 21:28:22 +01:00
Gustavo Iñiguez Goia
de956b1bf4 Fixed DNS responses firewall rule not deleted on exit
Sometimes the INPUT rule for to queue DNS responses was not deleted.
The code has also been reorganized.

And a minor tweak to make an if{} more idiomatic.
2020-02-25 01:30:24 +01:00
Gustavo Iñiguez Goia
2c7472f06d firewall: check rules every 5s
Every 5s check if our rules are loaded, and if they aren't, add them
again.
2020-02-22 00:27:35 +01:00
Gustavo Iñiguez Goia
a7e9b5072f project import paths changed 2019-10-20 21:51:35 +02:00
Northern-Lights
ba00f91bde
Fix QueueDNSResponses to include ip6tables 2019-01-26 20:56:12 -08:00
Armen Boursalian
cc3786b919 Fix ignored err check in RunRule 2018-12-30 19:07:05 -08:00
Jerzy Kozera
22c4aca5d0 IPv6 support 2018-11-21 22:57:43 +01:00
Armen Boursalian
bb2ca3887c Put DNS rule higher up in chain 2018-08-23 22:44:48 -07:00
evilsocket
01e5134139
misc: small fix or general refactoring i did not bother commenting 2018-04-10 13:11:39 +02:00
evilsocket
534ec8cd73
misc: small fix or general refactoring i did not bother commenting 2018-04-02 05:25:32 +02:00