From owner-freebsd-net@freebsd.org Sat Jun 25 23:17:55 2016 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7AA57B815BA for ; Sat, 25 Jun 2016 23:17:55 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-oi0-x22a.google.com (mail-oi0-x22a.google.com [IPv6:2607:f8b0:4003:c06::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 41A422032 for ; Sat, 25 Jun 2016 23:17:55 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-oi0-x22a.google.com with SMTP id s66so159253717oif.1 for ; Sat, 25 Jun 2016 16:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=xRl4DRzKysmE3z1rItH/zcNEMIkygZ8oNgXo4JBDdaA=; b=vtEwtOW1mkNtu9s1CRTlSUMAeO2p4PQNT6iRfQaNvgfSlmDDr1MxxppIZ0i/0/T2Nl N1AO5e952vZiJMqFnhx3TsnkS3QScAbM8RmlUzEmfTQKl+aYxopg7l/eWJDcLvBJJEvG XbSHpphueITK8a2nc7kxzSsUX7fH4F9sTUoasJW4+tEajyXbFS2H1ve6W4KTGYqsuxX4 dgoNGgLFvmMLxd3vHKJvadbL7ZVx9zGFbn8KB99jiKWCfsLWgqIkYeYf5YiZoa5y5S+D 8WvlhkagZL/nusJH3F3E2FrC5tzlLU9z92HuXmVlU/xpBPZwl9GVRGtHOYLnKqftHr3K fPiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=xRl4DRzKysmE3z1rItH/zcNEMIkygZ8oNgXo4JBDdaA=; b=HDQuBzXZrEE2tsuP510QubU8XvKy1nHaVorn8DTFQBrXS6GSPweJNOsiLb3R2QMkRa BNtkP+Jmp7CyYUbtigfnR4btIVto8Uh9+DzQWdHdnCtzsYEywQwvCmmMvW33XJiVahI9 xFa/09USXAAbhvs/LEjthudncEi6gisGLqdoZQN6dxmipfYEvxVvJJ0TMiLN340To5WH ICV8+v/syI/Q9Kzkj1lLnIIts0Ywvaf+5IysmPJhWp84/vE7VM30cg3qSqzBBvriSuPS 4lpTDKhZTPP9C/GQTBN+O1Q6nC6kFicMQa/dE66uV3FVFswQWkTyKvD6zIhVU6CtCsp4 QsRg== X-Gm-Message-State: ALyK8tKQ666gQutkWfh5n6PwHkFWatYGaLp4vNWtRJ42o6SxeYPttI5QX4g3GUgij5RfL8WrPB8vLOR3ByKQCg== X-Received: by 10.202.224.136 with SMTP id x130mr7332384oig.105.1466896674312; Sat, 25 Jun 2016 16:17:54 -0700 (PDT) MIME-Version: 1.0 Sender: asomers@gmail.com Received: by 10.202.168.149 with HTTP; Sat, 25 Jun 2016 16:17:53 -0700 (PDT) In-Reply-To: <20160625220137.1ed8de16@copperhead.int.arc7.info> References: <20160625220137.1ed8de16@copperhead.int.arc7.info> From: Alan Somers Date: Sat, 25 Jun 2016 17:17:53 -0600 X-Google-Sender-Auth: odxHu3bxjx0UoOmfCv427q9WCFA Message-ID: Subject: Re: Filtering outbound traffic for private address jails? To: org.freebsd.security@io7m.com Cc: FreeBSD Net Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Jun 2016 23:17:55 -0000 On Sat, Jun 25, 2016 at 4:01 PM, wrote: > Hello. > > I have been searching for the best part of a day for a solution to this > problem and quite frankly cannot believe that I've spent this long on > something that appears to be so simple and that used to be fairly easy > to achieve. Many years ago, I solved this problem on FreeBSD 6, but the > way I did it there seems to no longer work on modern releases. > > The problem is this: I have a single public IP address. I want to run > multiple jails. > > Back in the days of FreeBSD 6.*, the accepted way to do this seemed to > be to create a new loopback device: > > # ifconfig lo1 create > > ... and then add a lot of private 127.0.0.* addresses, one per jail. > > Then, the real network adapter and the new loopback device were both > added to a bridge (if_bridge). Unfortunately, I can't remember the exact > details, but I believe that NAT was then enabled on the real interface. > In order to filter traffic to, from, and between jails, pf rules were > written that filtered the bridge device. > > This meant that jails could correctly send outbound traffic and > receive responses (via pf states), could correctly receive specific > inbound traffic (via rdr rules), and traffic in both directions could be > filtered based on packets entering and leaving the bridge. > > However (see my other mailing list post), it seems that now with > FreeBSD 10, you just can't add loopback devices to bridges. I can find > no evidence of anyone online doing this, or even using the old bridge > method that I just described! I can find one post in russian that seems > to have the same error that I encounter, but nobody has any idea why > it's happening. > > I can find dozens of blog posts describing how to set up jails on > private IP addresses. They all follow the same pattern: > > 1. Create a loopback device. > 2. Create a 127.0.0.* address on the loopback device. > 3. Create a jail using the address you just added. > 4. Set up pf and enable NAT between the real network adapter and > the new loopback device. > > Unfortunately, at this point, you completely lose the ability to filter > outbound jail traffic; All packets sent from a jail will obviously have > their source address changed to that of the host and therefore it's not > possible to distinguish between outbound host traffic and outbound jail > traffic in filter rules. > > As far as I can tell, people are just not filtering outbound traffic, > which seems insane! > > Is it really impossible to do this with FreeBSD 10? > > M I'm filtering outbound traffic, but I'm not using NAT on the jail host. Instead, I have a dedicated router doing NAT, and my jail host has multiple IP addresses. At first I tried using traditional shared-address jails, but the firewall rules quickly got very complicated, especially for dealing with IPv6 and other non-IPv4 traffic. So I switched to using vimage jails. I use iocage to setup my jails, and pf to filter them. A simplified version of my pf.conf follows: www_services = "{ http, https, 8080 }" host_iface = "em0" dmz_iface = "em1" www_jail_iface = "vnet0:1" www_ip = "192.168.0.40" set state-policy if-bound scrub in block in all block out all pass in on $host_iface pass out on $host_iface set skip on lo0 # Allow all traffic to the DMZ. Filtering happens on individual vnet # interfaces pass in on $dmz_iface pass out on $dmz_iface # Put the www jail in a DMZ. Don't allow outgoing traffic from it except for # the webserver pass out on $www_jail_iface proto tcp to $www_ip port $www_services keep state # Uncomment next line to allow outbound traffice from www jail # pass in on $www_jail_iface -Alan