From patchwork Sun Apr 1 09:13:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Hesse X-Patchwork-Id: 284 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net (Dovecot) with LMTP id y2pPFLIzwVqWWQAAIUCqbw for ; Sun, 01 Apr 2018 15:32:02 -0400 Received: from proxy12.mail.iad3b.rsapps.net ([172.31.255.6]) by director10.mail.ord1d.rsapps.net (Dovecot) with LMTP id CzAFDrIzwVoyUQAApN4f7A ; Sun, 01 Apr 2018 15:32:02 -0400 Received: from smtp20.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy12.mail.iad3b.rsapps.net with LMTP id AISiC7IzwVpjFgAAEsW3lA ; Sun, 01 Apr 2018 15:32:02 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp20.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=eworm.de; dmarc=none (p=nil; dis=none) header.from=eworm.de X-Suspicious-Flag: YES X-Classification-ID: 596a95b2-35e3-11e8-af99-525400497f28-1-1 Received: from [216.105.38.7] ([216.105.38.7:19890] helo=lists.sourceforge.net) by smtp20.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 17/27-21306-1B331CA5; Sun, 01 Apr 2018 15:32:01 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1f2ih4-0005OK-2x; Sun, 01 Apr 2018 19:31:10 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1f2igz-0005O4-RJ for openvpn-devel@lists.sourceforge.net; Sun, 01 Apr 2018 19:31:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=WOTQjlse488oI/uIi7yxFRDTsLM5bP8FxpEtLnMSy8g=; b=bYkUariK9/9Lx5td5ta1fZoQz1 5lL1MoXoqaU87t8ujLUzm4bc5Fx4Ph/VoMVWmf0qen8KWijwYNtu8gz+YQu93ayytQZNvxw3LuHUp dSS+jwxE/zMvQnciOvl/snjswXMimMJHbDzk6M20k0CqtB7ZveGzC5H0M2uXlEgaFccQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=WOTQjlse488oI/uIi7yxFRDTsLM5bP8FxpEtLnMSy8g=; b=hAW9hP6+XEvgBdt29DkHecVTFS GtdfK4EzXc3Ate/H8GYxPvVpOyV/x2gmx4I3psBBQ4Ym5K/PbrxqfOroNrYyAz48/qVik9953m6pR YyBWZ/OjEnrHFLaNd4Gs5WU5XSOnwDsWy1YrvSo3TEVdUieLvCIk7jYbz06RVahKR/6Y=; Received: from mx.mylinuxtime.de ([148.251.109.235]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1f2igx-0059X3-SY for openvpn-devel@lists.sourceforge.net; Sun, 01 Apr 2018 19:31:05 +0000 Received: from leda.eworm.de (unknown [10.10.4.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx.mylinuxtime.de (Postfix) with ESMTPSA id 4A522266FE; Sun, 1 Apr 2018 21:14:02 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.10.3 mx.mylinuxtime.de 4A522266FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eworm.de; s=mail; t=1522610042; bh=rceahONkzF8bG/waJ1kqHFQoK/+eyG7kul83BxtQXZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rDuiLZXyKn/pg+SehTT+ge5bviTC5uYZikDYAhC5afawOwxSZEjx7Q+fypAaCACjI T+vwvsdZ2jeiZWoqQWvm9c8xjaphDYOHk90Rs2TecbWec5mrpQU2Peok/qLNEbeB/w LqqR2ng7iBnciA9XFkEIM0YEjqVj0r5ysgUEJbdA= Received: by leda.eworm.de (Postfix, from userid 1000) id E43B9102880; Sun, 1 Apr 2018 21:13:55 +0200 (CEST) From: Christian Hesse To: OpenVPN Development Date: Sun, 1 Apr 2018 21:13:08 +0200 Message-Id: <20180401191309.32211-3-list@eworm.de> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180401191309.32211-1-list@eworm.de> References: <20180401191309.32211-1-list@eworm.de> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1f2igx-0059X3-SY Subject: [Openvpn-devel] [RFC 2/3] systemd: do not downgrade UID/GID X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christian Hesse MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Christian Hesse Now that systemd starts the process with dedicated user we do no longer want to downgrade privileges. Also remove CAP_SETGID and CAP_SETUID from granted privileges. Signed-off-by: Christian Hesse --- distro/systemd/openvpn-client@.service.in | 2 +- distro/systemd/openvpn-server@.service.in | 2 +- src/openvpn/init.c | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot diff --git a/distro/systemd/openvpn-client@.service.in b/distro/systemd/openvpn-client@.service.in index a103d751..ee7957a6 100644 --- a/distro/systemd/openvpn-client@.service.in +++ b/distro/systemd/openvpn-client@.service.in @@ -13,7 +13,7 @@ User=openvpn Group=openvpn WorkingDirectory=/etc/openvpn/client ExecStart=@sbindir@/openvpn --suppress-timestamps --nobind --config %i.conf -AmbientCapabilities=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE +AmbientCapabilities=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SYS_CHROOT CAP_DAC_OVERRIDE LimitNPROC=10 DeviceAllow=/dev/null rw DeviceAllow=/dev/net/tun rw diff --git a/distro/systemd/openvpn-server@.service.in b/distro/systemd/openvpn-server@.service.in index 7275e86a..03d28a2e 100644 --- a/distro/systemd/openvpn-server@.service.in +++ b/distro/systemd/openvpn-server@.service.in @@ -13,7 +13,7 @@ User=openvpn Group=openvpn WorkingDirectory=/etc/openvpn/server ExecStart=@sbindir@/openvpn --status %t/openvpn-server/status-%i.log --status-version 2 --suppress-timestamps --config %i.conf -AmbientCapabilities=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE +AmbientCapabilities=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SYS_CHROOT CAP_DAC_OVERRIDE LimitNPROC=10 DeviceAllow=/dev/null rw DeviceAllow=/dev/net/tun rw diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 36c1a4c4..0fc60d62 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -1151,6 +1151,14 @@ do_uid_gid_chroot(struct context *c, bool no_delay) /* set user and/or group if we want to setuid/setgid */ if (c0->uid_gid_specified) { +#ifdef ENABLE_SYSTEMD + if (sd_notify(0, "READY=0") > 0 && getuid() != 0) + { + msg(M_INFO, "NOTE: Running from systemd with non-root uid, skipping downgrade"); + return; + } +#endif + if (no_delay) { platform_group_set(&c0->platform_state_group);