From owner-svn-ports-all@freebsd.org Tue Apr 24 01:06:48 2018 Return-Path: Delivered-To: svn-ports-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ADE39FB0321; Tue, 24 Apr 2018 01:06:48 +0000 (UTC) (envelope-from dbaio@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 58FE57C373; Tue, 24 Apr 2018 01:06:48 +0000 (UTC) (envelope-from dbaio@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 538F14140; Tue, 24 Apr 2018 01:06:48 +0000 (UTC) (envelope-from dbaio@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3O16mZE046760; Tue, 24 Apr 2018 01:06:48 GMT (envelope-from dbaio@FreeBSD.org) Received: (from dbaio@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3O16mTN046757; Tue, 24 Apr 2018 01:06:48 GMT (envelope-from dbaio@FreeBSD.org) Message-Id: <201804240106.w3O16mTN046757@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dbaio set sender to dbaio@FreeBSD.org using -f From: "Danilo G. Baio" Date: Tue, 24 Apr 2018 01:06:48 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r468172 - in head/dns/dnscrypt-proxy2: . files X-SVN-Group: ports-head X-SVN-Commit-Author: dbaio X-SVN-Commit-Paths: in head/dns/dnscrypt-proxy2: . files X-SVN-Commit-Revision: 468172 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Apr 2018 01:06:48 -0000 Author: dbaio Date: Tue Apr 24 01:06:47 2018 New Revision: 468172 URL: https://svnweb.freebsd.org/changeset/ports/468172 Log: dns/dnscrypt-proxy2: Add mac_portacl option in rc script Version 2 of dnscrypt-proxy is written in Go and therefore isn't capable of dropping privileges after binding to a low port on FreeBSD. By default, this port's daemon will listen on port 5353 (TCP/UDP). With this option it's possible to bind it and listen on port 53 (TCP/UDP) with mac_portacl(4) kernel module (network port access control policy). For this add dnscrypt_proxy_mac_portacl_enable=YES in your rc.conf. The dnscrypt-proxy startup script will load mac_portacl and add a rule where %%USER%% user will be able to bind on port 53 (TCP/UDP). This port can be changed by dnscrypt_proxy_mac_portacl_port variable in your rc.conf. You also need to change dnscrypt-proxy config file to use port 53. Suggested by: feld Approved by: egypcio@googlemail.com (maintainer) Differential Revision: https://reviews.freebsd.org/D15151 Modified: head/dns/dnscrypt-proxy2/Makefile head/dns/dnscrypt-proxy2/files/dnscrypt-proxy.in head/dns/dnscrypt-proxy2/files/pkg-message.in Modified: head/dns/dnscrypt-proxy2/Makefile ============================================================================== --- head/dns/dnscrypt-proxy2/Makefile Tue Apr 24 01:01:37 2018 (r468171) +++ head/dns/dnscrypt-proxy2/Makefile Tue Apr 24 01:06:47 2018 (r468172) @@ -2,6 +2,7 @@ PORTNAME= dnscrypt-proxy PORTVERSION= 2.0.10 +PORTREVISION= 1 CATEGORIES= dns security ipv6 PKGNAMESUFFIX= 2 Modified: head/dns/dnscrypt-proxy2/files/dnscrypt-proxy.in ============================================================================== --- head/dns/dnscrypt-proxy2/files/dnscrypt-proxy.in Tue Apr 24 01:01:37 2018 (r468171) +++ head/dns/dnscrypt-proxy2/files/dnscrypt-proxy.in Tue Apr 24 01:06:47 2018 (r468172) @@ -19,6 +19,14 @@ # # dnscrypt_proxy_uid (str) User to run dnscrypt_proxy as # Default: %%USER%% +# +# dnscrypt_proxy_mac_portacl_enable (bool) +# Load mac_portacl module (network port access control policy) +# Default: NO +# +# dnscrypt_proxy_mac_portacl_port (int) +# Port used in the mac_portacl rule +# Default: 53 . /etc/rc.subr @@ -33,10 +41,65 @@ load_rc_config $name : ${dnscrypt_proxy_conf:="%%ETCDIR%%/dnscrypt-proxy.toml"} : ${dnscrypt_proxy_suexec:="NO"} : ${dnscrypt_proxy_uid:="%%USER%%"} +: ${dnscrypt_proxy_mac_portacl_enable:="NO"} +: ${dnscrypt_proxy_mac_portacl_port:="53"} checkyesno dnscrypt_proxy_suexec && dnscrypt_proxy_uid="root" command="/usr/sbin/daemon" command_args="-p ${pidfile} -u ${dnscrypt_proxy_uid} -f ${procname} -config ${dnscrypt_proxy_conf}" +start_precmd="dnscrypt_proxy_precmd" + +dnscrypt_proxy_precmd() { + local reservedlow reservedhigh rules_current rules_dnscrypt rport ruid + + if checkyesno dnscrypt_proxy_mac_portacl_enable ; then + + # Check and load mac_portacl module + if ! kldstat -m mac_portacl >/dev/null 2>&1 ; then + if ! kldload mac_portacl ; then + warn "Could not load mac_portacl module." + return 1 + fi + fi + + # Check and add mac_portacl rules + ruid=$(id -u $dnscrypt_proxy_uid) + rport=$dnscrypt_proxy_mac_portacl_port #smaller variable + rules_current=$(sysctl -n security.mac.portacl.rules) + rules_dnscrypt="uid:${ruid}:tcp:${rport},uid:${ruid}:udp:${rport}" + if [ ! $rules_current = "" ]; then + if ! echo $rules_current | grep "$rules_dnscrypt" >/dev/null 2>&1 ; then + rules_current="${rules_current},${rules_dnscrypt}" + if ! sysctl security.mac.portacl.rules="$rules_current" >/dev/null 2>&1 ; then + warn "Could not insert mac_portacl rules." + return 1 + fi + fi + elif ! sysctl security.mac.portacl.rules=$rules_dnscrypt >/dev/null 2>&1 ; then + warn "Could not insert mac_portacl rules." + return 1 + fi + + # Check and disable net.inet.ip.portrange.* control + reservedlow=$(sysctl -n net.inet.ip.portrange.reservedlow) + reservedhigh=$(sysctl -n net.inet.ip.portrange.reservedhigh) + if [ ! $reservedlow -eq 0 ]; then + if ! sysctl net.inet.ip.portrange.reservedlow=0 >/dev/null 2>&1 ; then + warn "Could not change net.inet.ip.portrange.reservedlow." + return 1 + fi + fi + if [ ! $reservedhigh -eq 0 ]; then + if ! sysctl net.inet.ip.portrange.reservedhigh=0 >/dev/null 2>&1 ; then + warn "Could not change net.inet.ip.portrange.reservedhigh." + return 1 + fi + fi + + fi # dnscrypt_proxy_mac_portacl_enable + + return 0 +} run_rc_command "$1" Modified: head/dns/dnscrypt-proxy2/files/pkg-message.in ============================================================================== --- head/dns/dnscrypt-proxy2/files/pkg-message.in Tue Apr 24 01:01:37 2018 (r468171) +++ head/dns/dnscrypt-proxy2/files/pkg-message.in Tue Apr 24 01:06:47 2018 (r468172) @@ -3,8 +3,15 @@ Version 2 of dnscrypt-proxy is written in Go and there of dropping privileges after binding to a low port on FreeBSD. By default, this port's daemon will listen on port 5353 (TCP/UDP) as the -%%USER%% user. It's still possible to bind it and listen on port -53 (TCP/UDP), but it's not recommended. +%%USER%% user. + +It's possible to bind it and listen on port 53 (TCP/UDP) with mac_portacl(4) +kernel module (network port access control policy). For this add +dnscrypt_proxy_mac_portacl_enable=YES in your rc.conf. The dnscrypt-proxy +startup script will load mac_portacl and add a rule where %%USER%% user will +be able to bind on port 53 (TCP/UDP). This port can be changed by +dnscrypt_proxy_mac_portacl_port variable in your rc.conf. You also need to +change dnscrypt-proxy config file to use port 53. Below are a few examples on how to redirect local connections from port 5353 to 53.