From patchwork Thu Jun 30 10:15:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Roevens X-Patchwork-Id: 5714 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4LYZ4b6YNRz40V9 for ; Thu, 30 Jun 2022 10:16:47 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4LYZ4X2SY9z1gg; Thu, 30 Jun 2022 10:16:44 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4LYZ4X1mKMz2yWQ; Thu, 30 Jun 2022 10:16:44 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4LYZ4W5BNrz2yWP for ; Thu, 30 Jun 2022 10:16:43 +0000 (UTC) Received: from knopi.disroot.org (knopi.disroot.org [178.21.23.139]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4LYZ4W1fybz1gR for ; Thu, 30 Jun 2022 10:16:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 091444597A for ; Thu, 30 Jun 2022 12:16:43 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5C1cEfb23SEZ for ; Thu, 30 Jun 2022 12:16:41 +0200 (CEST) Received: from chojin.sicho.home (amaterasu.sicho.home [192.168.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (no client certificate requested) (Authenticated sender) by hachiman (MailScanner Milter) with SMTP id 6F7004B9EE; Thu, 30 Jun 2022 12:16:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1656584195; bh=ZPEzL6fP+y6r1+PaK75uWwtAr0PDgg2hmrlsSsLcW2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aidjg84Ugo3a+olGW1FfCvAVXVNi91FQLLcjLKC8ZnTSyz1Ax9VEFpGJTF6AZXJQL CBt+m99imKaRhwxmAPAj9dzX9UcXbJ0WqfRZMnHCMueQypnsn4mriWGmgePgjxRIT1 sknPMl+pJvwKrz3z/wFogP19NZGkvsg3S3EYuwewpAj32NQkDfsCDAEpVV6mnfhbOg F9yf8fI0hbfE2/C/R7pOBCYC6fDTB4gnxqHE3v3netjlOX+iVo6VS+K16uYB12B9lF jl4vNiyAGU+0srOUuMi2OORlxUFUGW8RF9cqIsg5HTlTnlf9sy/xKb9lFFI+DVLuuT DQ7ktG/2flUHg== From: Robin Roevens To: development@lists.ipfire.org Subject: [PATCH v5 4/6] zabbix_agentd: Sudoers file reorganization Date: Thu, 30 Jun 2022 12:15:53 +0200 Message-Id: <20220630101555.13438-5-robin.roevens@disroot.org> In-Reply-To: <20220630101555.13438-1-robin.roevens@disroot.org> References: <20220630101555.13438-1-robin.roevens@disroot.org> Mime-Version: 1.0 X-sicho-MailScanner-ID: 6F7004B9EE.A8A80 X-sicho-MailScanner: Found to be clean X-sicho-MailScanner-From: robin.roevens@disroot.org X-sicho-MailScanner-Watermark: 1657188971.77068@MiP/wbEW1njHDyUbnk53Ig ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1656584203; a=rsa-sha256; cv=none; b=blkIB7gOmVNQ+yFWBgXAhVPUScLHoVEvNOqCviI3vx7MKw3X/i5LWt1A3vuVskMVe+q6C1 uFt3ZDnicdvKBmSLF3wJDEFmKVwMl97kBdCE+wYbkLHPm99pvftP4iJmG0atYLLyXqTBqH 8qlziyYezR6khIqKJvYyFXp0UmyiTAQDfMzOGVLeUEOS3+CcLk/7WXnzG0+2+wvZZ4rOt/ iOtphLA5gJI+YpVQmEDiOzbHmvdJIhsK3W21ircDDuHIHRbB/Ky/ChHAzRYS1SpNve6PoL t17mJli4wYR4l+hCCxSuXQhYpe4AMYegkX1G5GsPbbsjvdxs8iHM/jPJjdwUzw== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=aidjg84U; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org; dmarc=pass (policy=quarantine) header.from=disroot.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1656584203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EVAFmx4v40C2pGpQve1yqD9/Fe86Mfj9du9GoaAthK0=; b=uVCGAF+pBZu6YfnCwynkhSBHjhU9Dst3fslraTcUPlNL7Z7Hc80ZI11JU3lSiy3qCrfXqq 61RIuHoXKbFvNPfdQ8S2BerCG1wmETalWHztEmNXUIOVtf982/407dneruJ6fdbUOmaiM8 m3tBRNfZsKGwh3CzJABds/RocP8T5Ei7HiWFgtwlNYPgzDjwhQJja6Vm32hDcQEqF/uWly YYIbyxOWqHH8KBlprPHDDZW6x4asQHcEFnDL5lZ18cccWgnWufC/wr5y8/Am/458+OM5Jo EImaD4TY1r3f4gYyGdeFspbUUWblEbILm8y8QnNe1w5Ujc6PQ+7Fd+9TrClLtg== X-Spamd-Result: default: False [-7.80 / 11.00]; REPLY(-4.00)[]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM(-1.00)[-1.000]; SPF_REPUTATION_HAM(-0.78)[-0.78380193243943]; R_MISSING_CHARSET(0.50)[]; MV_CASE(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[disroot.org,quarantine]; R_SPF_ALLOW(-0.20)[+a:c]; R_DKIM_ALLOW(-0.20)[disroot.org:s=mail]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; IP_REPUTATION_HAM(-0.01)[asn: 50673(0.00), country: NL(-0.01), ip: 178.21.23.139(0.00)]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[development@lists.ipfire.org]; ARC_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; RCVD_COUNT_THREE(0.00)[4]; ASN(0.00)[asn:50673, ipnet:178.21.23.0/24, country:NL]; DKIM_TRACE(0.00)[disroot.org:+]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_SOME(0.00)[] Authentication-Results: mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=aidjg84U; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org; dmarc=pass (policy=quarantine) header.from=disroot.org X-Rspamd-Queue-Id: 4LYZ4W1fybz1gR X-Rspamd-Server: mail01.haj.ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" - Remove sudoers file 'zabbix' in favour of new IPFire managed 'zabbix_agentd' and user managed 'zabbix_agentd_user' which is included in the backup - Provide migration of old sudoers file 'zabbix' or 'zabbix.user' to new zabbix_agentd_user sudoers file if it was modified by user. Signed-off-by: Robin Roevens --- config/backup/includes/zabbix_agentd | 4 ++-- config/rootfiles/packages/zabbix_agentd | 3 ++- config/zabbix_agentd/sudoers | 14 ++++---------- config/zabbix_agentd/sudoers_user | 16 ++++++++++++++++ lfs/zabbix_agentd | 4 +++- src/paks/zabbix_agentd/update.sh | 22 ++++++++++++++++++---- 6 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 config/zabbix_agentd/sudoers_user diff --git a/config/backup/includes/zabbix_agentd b/config/backup/includes/zabbix_agentd index 4be365297..834766992 100644 --- a/config/backup/includes/zabbix_agentd +++ b/config/backup/includes/zabbix_agentd @@ -1,5 +1,5 @@ -/etc/sudoers.d/zabbix +/etc/sudoers.d/zabbix_agentd_user /etc/zabbix_agentd/zabbix_agentd.conf /etc/zabbix_agentd/scripts/ /etc/zabbix_agentd/zabbix_agentd.d/ -/usr/lib/zabbix/ +/usr/lib/zabbix/ \ No newline at end of file diff --git a/config/rootfiles/packages/zabbix_agentd b/config/rootfiles/packages/zabbix_agentd index c6e0c5634..b5325c636 100644 --- a/config/rootfiles/packages/zabbix_agentd +++ b/config/rootfiles/packages/zabbix_agentd @@ -1,6 +1,7 @@ etc/logrotate.d/zabbix_agentd etc/rc.d/init.d/zabbix_agentd -etc/sudoers.d/zabbix +etc/sudoers.d/zabbix_agentd +etc/sudoers.d/zabbix_agentd_user etc/zabbix_agentd etc/zabbix_agentd/scripts etc/zabbix_agentd/zabbix_agentd.conf diff --git a/config/zabbix_agentd/sudoers b/config/zabbix_agentd/sudoers index 1b362a4fd..cb4263ff6 100644 --- a/config/zabbix_agentd/sudoers +++ b/config/zabbix_agentd/sudoers @@ -1,17 +1,11 @@ # Include file for sudoers file # -# This is needed for some userparameters to be able to execute commands that only run as root (using sudo) -# e.g. /usr/bin/openssl or /usr/sbin/smartctl +# This is needed for some IPFire specific userparameters to be able to execute commands that only run as root (using sudo) # -# USE AT YOU'RE OWN RISK. USING THIS WRONG CAN RESULT IN A SECURITY BREACH! +# DO NOT CHANGE THIS FILE. This file is managed by IPFire, will be overwritten on next addon upgrade and is not +# included in the backup. # -# Some hints: -# - It is strongly recommended to edit this file only using the visudo -f command. If you mess up this file, -# you might end up locking yourself out of your system! -# - Append the full path incl. parameters to each command, using "," as separator. -# - Only add commands you really need. Zabbix should not have more rights than it has to. -# -# Append / edit the following list of commands to fit your needs: +# To add more sudo rights to zabbix agent, you should modify the sudoers file zabbix_agentd_user # Defaults:zabbix !requiretty zabbix ALL=(ALL) NOPASSWD: /opt/pakfire/pakfire status diff --git a/config/zabbix_agentd/sudoers_user b/config/zabbix_agentd/sudoers_user new file mode 100644 index 000000000..61cbc417b --- /dev/null +++ b/config/zabbix_agentd/sudoers_user @@ -0,0 +1,16 @@ +# Include file for sudoers file +# +# This is needed for some userparameters to be able to execute commands that only run as root (using sudo) +# e.g. /usr/bin/openssl or /usr/sbin/smartctl +# +# USE AT YOU'RE OWN RISK. USING THIS WRONG CAN RESULT IN A SECURITY BREACH! +# +# Some hints: +# - It is strongly recommended to edit this file only using the visudo -f command. If you mess up this file, +# you might end up locking yourself out of your system! +# - Append the full path incl. parameters to each command, using "," as separator. +# - Only add commands you really need. Zabbix should not have more rights than it has to. +# +# Uncomment the following line and edit the example of commands to fit your needs: + +#zabbix ALL=(ALL) NOPASSWD: , , ... diff --git a/lfs/zabbix_agentd b/lfs/zabbix_agentd index 025a0f0db..f8fbdae5e 100644 --- a/lfs/zabbix_agentd +++ b/lfs/zabbix_agentd @@ -124,7 +124,9 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) # Install sudoers include file install -v -m 640 $(DIR_SRC)/config/zabbix_agentd/sudoers \ - /etc/sudoers.d/zabbix + /etc/sudoers.d/zabbix_agentd + install -v -m 640 $(DIR_SRC)/config/zabbix_agentd/sudoers_user \ + /etc/sudoers.d/zabbix_agentd_user # Install include file for backup install -v -m 644 $(DIR_SRC)/config/backup/includes/zabbix_agentd \ diff --git a/src/paks/zabbix_agentd/update.sh b/src/paks/zabbix_agentd/update.sh index 68bba4f80..a41e72ab4 100644 --- a/src/paks/zabbix_agentd/update.sh +++ b/src/paks/zabbix_agentd/update.sh @@ -22,11 +22,25 @@ ############################################################################ # . /opt/pakfire/lib/functions.sh + +# Check if old sudoers file exists and remove if it was not modified +# or rename to the new zabbix_agentd_user file if it was. +if [ -f /etc/sudoers.d/zabbix.user ]; then + mv -v /etc/sudoers.d/zabbix.user /etc/sudoers.d/zabbix +fi + +if [ -f /etc/sudoers.d/zabbix ]; then + blake2=$(b2sum /etc/sudoers.d/zabbix | cut -f1 -d" ") + # from commits 5737a22 & 06fc617 + if [ "$blake2" == "b0f73b107fd3842efc7ef3e30f6d948235aa07d533715476c2d3f58c08379193fdde9ff69aa6e0f5eb6cf4a98b2ed2a6f003f23078a57aff239b34cc29e62a98" ] || \ + [ "$blake2" == "0628c416a1f217b0962a8ce6d1e339bdb0f0427d86fc06b2e40b63487ffc1a3543562d16f7f954d7fb92cee9764f0261c1663a39dd50bc73fd9b772575c56cfc" ]; then + rm -vf /etc/sudoers.d/zabbix + else + mv -v /etc/sudoers.d/zabbix /etc/sudoers.d/zabbix_agentd_user + fi +fi + extract_backup_includes ./uninstall.sh ./install.sh -# Ensure /etc/sudoers.d/zabbix.user is renamed to /etc/sudoers.d/zabbix -if [ -e /etc/sudoers.d/zabbix.user ]; then - mv -v /etc/sudoers.d/zabbix.user /etc/sudoers.d/zabbix -fi