From owner-freebsd-virtualization@freebsd.org Sun Aug 2 01:36:25 2020 Return-Path: Delivered-To: freebsd-virtualization@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 521B936A46E for ; Sun, 2 Aug 2020 01:36:25 +0000 (UTC) (envelope-from jtubnor@gmail.com) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BK3Wq6xxnz3cx9 for ; Sun, 2 Aug 2020 01:36:23 +0000 (UTC) (envelope-from jtubnor@gmail.com) Received: by mail-wm1-f44.google.com with SMTP id q76so11189817wme.4 for ; Sat, 01 Aug 2020 18:36:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=I2Rv2KfWRz3pa5nFJIKacSje+hOoYAXMd4UEqw1Xhvo=; b=mZaMRJxzxWsvAQ6+nWb0VW/AsS6l8IgS3ykWBjZ02LwZ66h2/hD+UDo7KvnIUxb6oE A09/3MiAsdSCBHCOAq8cAfBhg3c6NwJyY/Ci/FLBhFtmf+LMU91AZBw3aRLQkFNHXir1 bHP1O5h7AfrcGpTOMSlfIgo3Sd/MTuhVVOvmnHT9vz/OLcxh2EXqr5/3BDM7gxjtr7Wf uAKqXIshmPIiIrqspRG3l6T5Iqy72iAflwXBrGFkbKXRGbjA5qHUMN/UvMB9CE9Mlcj7 Mv1MjSwW8PqtIWhY8b9OhMY9LIbDro2YtnMXmjyiCjJd3QfEQ6HDKGhKfLar61iuSwoD at9w== X-Gm-Message-State: AOAM532wqtjxm2NV7f4PuEw7S2Q8Rt0CQ4MHtDHiVtORTqkgxWS9yVHl Cfb1aqtp/vLH+0hGPyUd6ZEbUslW6O+I8Zl5IaKBng== X-Google-Smtp-Source: ABdhPJy5+Q1uIvxTCgjRq9P5ItWRuvCp6HN7vLkNHuP9e1fQcc021qF+QMhy5za80+EzsmwHQt948D8HmgflaBUaG1U= X-Received: by 2002:a05:600c:2904:: with SMTP id i4mr9402216wmd.126.1596332182061; Sat, 01 Aug 2020 18:36:22 -0700 (PDT) MIME-Version: 1.0 References: <20200801145144.7bf342d9@sunflower.int.arc7.info> In-Reply-To: <20200801145144.7bf342d9@sunflower.int.arc7.info> From: Jason Tubnor Date: Sun, 2 Aug 2020 11:36:09 +1000 Message-ID: Subject: Re: Restricting IP ranges for guests over tap devices To: Mark Raynsford Cc: "freebsd-virtualization@freebsd.org" X-Rspamd-Queue-Id: 4BK3Wq6xxnz3cx9 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of jtubnor@gmail.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=jtubnor@gmail.com X-Spamd-Result: default: False [-2.22 / 15.00]; ARC_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; TO_DN_EQ_ADDR_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17:c]; RCVD_TLS_ALL(0.00)[]; TAGGED_RCPT(0.00)[org.freebsd.virtualization]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-virtualization@freebsd.org]; DMARC_NA(0.00)[tubnor.net]; NEURAL_HAM_LONG(-0.97)[-0.972]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-0.52)[-0.523]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[209.85.128.44:from]; NEURAL_HAM_MEDIUM(-0.73)[-0.726]; FORGED_SENDER(0.30)[jason@tubnor.net,jtubnor@gmail.com]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.128.44:from]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_COUNT_TWO(0.00)[2]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; FROM_NEQ_ENVFROM(0.00)[jason@tubnor.net,jtubnor@gmail.com] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.33 X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Aug 2020 01:36:25 -0000 On Sun, 2 Aug 2020 at 00:51, Mark Raynsford via freebsd-virtualization < freebsd-virtualization@freebsd.org> wrote: > Hello! > > Let's say I have a machine running a few dozen bhyve guests. Each bhyve > guest gets its own tap device, and all of the tap devices are connected > to a bridge. > > Everything works fine. I can write pf rules that control access between > each guest, and between each guest and the world. I can't directly > observe the IP addresses that the guests have assigned to the tap > devices I gave them, but if I know the addresses beforehand, I can for > example write pf rules that say things like: > > block log all > pass in on tap23 proto tcp \ > from any to $guest_23_ip port ssh modulate state > > That then means that even if the guest is compromised and tries to bind > a server to another address, the pf rules won't allow anyone else to > actually connect to it. > > The good thing about this is also the bad thing about this; I have to > write specific rules that say "only allow access to this specific IP > via this specific tap device". Over dozens of guests, that can multiply > to hundreds of laboriously maintained rules. > > Is there some more general way I can supply a mapping between tap > devices and allowed addresses? Remember that pf can't see the guest > addresses on the host sides of the tap devices, so I can't use the > (device) syntax to expand to "the address of a NIC called 'device'". > > > Treat the tap interface as a bridge and only define the destination port. That way you are able to protect the guest from the host without knowing the guest IP address. I'd do it a bit differently though. I'd treat the bridge that everything is tapped into as being a hostile environment. As such, each guest would protect itself as if you had a VPN on the public internet, using the guests built-in firewall. Another way is isolating each guest or bunch of guests on private VLANs and then protect these subnets on the host. Cheers, Jason.