2015-12-30 11:07:16 -05:00
|
|
|
(* Copyright (C) 2015, Thomas Leonard <thomas.leonard@unikernel.com>
|
|
|
|
See the README file for details. *)
|
|
|
|
|
2019-04-17 06:03:17 -04:00
|
|
|
(** Put your firewall rules in this file. *)
|
2015-12-30 11:07:16 -05:00
|
|
|
|
2019-04-17 06:03:17 -04:00
|
|
|
open Packet (* Allow us to use definitions in packet.ml *)
|
2015-12-30 11:07:16 -05:00
|
|
|
|
2019-04-11 07:25:19 -04:00
|
|
|
(* List your AppVM IP addresses here if you want to match on them in the rules below.
|
|
|
|
Any client not listed here will appear as [`Client `Unknown]. *)
|
|
|
|
let clients = [
|
|
|
|
(*
|
|
|
|
"10.137.0.12", `Dev;
|
|
|
|
"10.137.0.14", `Untrusted;
|
|
|
|
*)
|
|
|
|
]
|
|
|
|
|
|
|
|
(* List your external (non-AppVM) IP addresses here if you want to match on them in the rules below.
|
|
|
|
Any external machine not listed here will appear as [`External `Unknown]. *)
|
|
|
|
let externals = [
|
|
|
|
(*
|
|
|
|
"8.8.8.8", `GoogleDNS;
|
|
|
|
*)
|
|
|
|
]
|
|
|
|
|
2019-04-17 06:03:17 -04:00
|
|
|
(* OCaml normally warns if you don't match all fields, but that's OK here. *)
|
|
|
|
[@@@ocaml.warning "-9"]
|
|
|
|
|
|
|
|
(** This function decides what to do with a packet from a client VM.
|
|
|
|
|
|
|
|
It takes as input an argument [info] (of type [Packet.info]) describing the
|
|
|
|
packet, and returns an action (of type [Packet.action]) to perform.
|
|
|
|
|
|
|
|
See packet.ml for the definitions of [info] and [action].
|
|
|
|
|
2015-12-30 11:07:16 -05:00
|
|
|
Note: If the packet matched an existing NAT rule then this isn't called. *)
|
2019-04-17 06:03:17 -04:00
|
|
|
let from_client (info : ([`Client of _], _) Packet.info) : Packet.action =
|
2019-04-17 05:26:32 -04:00
|
|
|
match info with
|
2019-04-17 06:03:17 -04:00
|
|
|
(* Examples (add your own rules here):
|
|
|
|
|
|
|
|
1. Allows Dev to send SSH packets to Untrusted.
|
|
|
|
Note: responses are not covered by this!
|
2019-05-03 06:12:58 -04:00
|
|
|
2. Allows Untrusted to reply to Dev.
|
2019-04-17 06:03:17 -04:00
|
|
|
3. Blocks an external site.
|
|
|
|
|
|
|
|
In all cases, make sure you've added the VM name to [clients] or [externals] above, or it won't
|
|
|
|
match anything! *)
|
2019-04-11 07:25:19 -04:00
|
|
|
(*
|
|
|
|
| { src = `Client `Dev; dst = `Client `Untrusted; proto = `TCP { dport = 22 } } -> `Accept
|
2019-05-03 06:12:58 -04:00
|
|
|
| { src = `Client `Untrusted; dst = `Client `Dev; proto = `TCP _; packet }
|
2019-04-11 07:25:19 -04:00
|
|
|
when not (is_tcp_start packet) -> `Accept
|
|
|
|
| { dst = `External `GoogleDNS } -> `Drop "block Google DNS"
|
|
|
|
*)
|
2016-01-01 06:32:57 -05:00
|
|
|
| { dst = (`External _ | `NetVM) } -> `NAT
|
2019-05-16 14:18:31 -04:00
|
|
|
| { dst = `Firewall; proto = `UDP { dport = 53 } } -> `NAT_to (`NetVM, 53)
|
|
|
|
| { dst = `Firewall } -> `Drop "packet addressed to firewall itself"
|
2019-04-11 07:25:19 -04:00
|
|
|
| { dst = `Client _ } -> `Drop "prevent communication between client VMs by default"
|
2015-12-30 11:07:16 -05:00
|
|
|
|
|
|
|
(** Decide what to do with a packet received from the outside world.
|
|
|
|
Note: If the packet matched an existing NAT rule then this isn't called. *)
|
2019-04-17 06:03:17 -04:00
|
|
|
let from_netvm (info : ([`NetVM | `External of _], _) Packet.info) : Packet.action =
|
2019-04-17 05:26:32 -04:00
|
|
|
match info with
|
2015-12-30 11:07:16 -05:00
|
|
|
| _ -> `Drop "drop by default"
|