2023-08-08 20:00:52 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
name = "opensnitch";
|
|
|
|
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ onny ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
server =
|
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
|
|
services.caddy = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."localhost".extraConfig = ''
|
|
|
|
respond "Hello, world!"
|
|
|
|
'';
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2023-08-08 20:00:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
clientBlocked =
|
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
services.opensnitch = {
|
|
|
|
enable = true;
|
|
|
|
settings.DefaultAction = "deny";
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2023-08-08 20:00:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
clientAllowed =
|
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
services.opensnitch = {
|
|
|
|
enable = true;
|
|
|
|
settings.DefaultAction = "deny";
|
|
|
|
rules = {
|
2023-12-24 13:04:26 +00:00
|
|
|
curl = {
|
2023-08-08 20:00:52 +00:00
|
|
|
name = "curl";
|
|
|
|
enabled = true;
|
|
|
|
action = "allow";
|
|
|
|
duration = "always";
|
|
|
|
operator = {
|
|
|
|
type = "simple";
|
|
|
|
sensitive = false;
|
|
|
|
operand = "process.path";
|
|
|
|
data = "${pkgs.curl}/bin/curl";
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2023-08-08 20:00:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
start_all()
|
|
|
|
server.wait_for_unit("caddy.service")
|
|
|
|
server.wait_for_open_port(80)
|
|
|
|
|
|
|
|
clientBlocked.wait_for_unit("opensnitchd.service")
|
|
|
|
clientBlocked.fail("curl http://server")
|
|
|
|
|
|
|
|
clientAllowed.wait_for_unit("opensnitchd.service")
|
|
|
|
clientAllowed.succeed("curl http://server")
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|