From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BE7AD64951 for ; Wed, 30 Dec 2020 17:12:08 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AD0D324065 for ; Wed, 30 Dec 2020 17:11:38 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id DE06024058 for ; Wed, 30 Dec 2020 17:11:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id AF618446F9 for ; Wed, 30 Dec 2020 17:11:36 +0100 (CET) Date: Wed, 30 Dec 2020 17:11:31 +0100 From: Stoiko Ivanov To: Fabian =?UTF-8?B?R3LDvG5iaWNobGVy?= Cc: pmg-devel@lists.proxmox.com Message-ID: <20201230171131.11510bc1@rosa.proxmox.com> In-Reply-To: <1609333346.zxlabc8udx.astroid@nora.none> References: <20201216171813.29694-1-s.ivanov@proxmox.com> <20201216171813.29694-4-s.ivanov@proxmox.com> <1609333346.zxlabc8udx.astroid@nora.none> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.074 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pmg-devel] [PATCH pmg-api 3/4] api: spamassassin: update local channels X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Dec 2020 16:12:08 -0000 On Wed, 30 Dec 2020 14:07:22 +0100 Fabian Gr=C3=BCnbichler wrote: > On December 16, 2020 6:18 pm, Stoiko Ivanov wrote: > > This patch adds a helper to loop over all present Spamassassin > > channels files in /etc/mail/spamassassin/channel.d and: > > * import the included gpg key into sa-update's keyring > > * run sa-update for each channel separately > >=20 > > the verbose argument of the helper is for reusing the code in > > pmg-daily (where we only want to log errors and be less informative) > >=20 > > In order to only hardcode the path of sa-update once the definition > > was moved to PMG::Utils. > >=20 > > The choice of invoking sa-update for each channel separately is based, > > instead of providing multiple '--channel' and '--gpgkey' options to > > a single command was made to prevent downloading signatures, which > > were signed by a key not configured for the channel. > >=20 > > Signed-off-by: Stoiko Ivanov > > --- > > src/PMG/API2/SpamAssassin.pm | 6 +++--- > > src/PMG/Utils.pm | 29 +++++++++++++++++++++++++++++ > > 2 files changed, 32 insertions(+), 3 deletions(-) > >=20 > > diff --git a/src/PMG/API2/SpamAssassin.pm b/src/PMG/API2/SpamAssassin.pm > > index 5f9c3a5..df46c64 100644 > > --- a/src/PMG/API2/SpamAssassin.pm > > +++ b/src/PMG/API2/SpamAssassin.pm > > @@ -11,15 +11,13 @@ use PVE::RESTHandler; > > use PMG::RESTEnvironment; > > use PVE::JSONSchema qw(get_standard_option); > > =20 > > -use PMG::Utils; > > +use PMG::Utils qw($SAUPDATE); > > use PMG::Config; > > =20 > > use Mail::SpamAssassin; > > =20 > > use base qw(PVE::RESTHandler); > > =20 > > -my $SAUPDATE =3D '/usr/bin/sa-update'; > > - > > __PACKAGE__->register_method ({ > > name =3D> 'index', > > path =3D> '', > > @@ -174,6 +172,8 @@ __PACKAGE__->register_method({ > > my $cmd =3D "$SAUPDATE -v"; > > =20 > > PVE::Tools::run_command($cmd, noerr =3D> 1); > > + > > + PMG::Utils::update_local_spamassassin_channels(1); > > }; > > =20 > > return $rpcenv->fork_worker('saupdate', undef, $authuser, $realcmd); > > diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm > > index 3f5b045..de74d4e 100644 > > --- a/src/PMG/Utils.pm > > +++ b/src/PMG/Utils.pm > > @@ -44,6 +44,7 @@ use base 'Exporter'; > > =20 > > our @EXPORT_OK =3D qw( > > postgres_admin_cmd > > +$SAUPDATE > > ); > > =20 > > my $valid_pmg_realms =3D ['pam', 'pmg', 'quarantine']; > > @@ -1442,6 +1443,8 @@ sub domain_regex { > > return $regex; > > } > > =20 > > +our $SAUPDATE =3D '/usr/bin/sa-update'; > > + > > sub local_spamassassin_channels { > > =20 > > my $res =3D []; > > @@ -1470,4 +1473,30 @@ sub local_spamassassin_channels { > > return $res; > > } > > =20 > > +sub update_local_spamassassin_channels { > > + my ($verbose) =3D @_; > > + # import all configured channel's gpg-keys to sa-update's keyring > > + my $importcmd =3D "$SAUPDATE"; > > + $importcmd .=3D '-v' if $verbose; > > + my $localchannels =3D PMG::Utils::local_spamassassin_channels(); > > + for my $channel (@$localchannels) { > > + $importcmd .=3D " --import $channel->{filename}"; > > + } > > + print "Importing gpg files from locally available channel definiti= ons\n" if $verbose; > > + PVE::Tools::run_command($importcmd, noerr =3D> 1); =20 >=20 > why is $importcmd not an array/list? how does the import behave if one=20 > of X channel files is bad/corrupt/malformed/...? wouldn't it make sense=20 > to import + update each channel on their own? Great catch - Thanks! While the man-page of sa-update(1p) explictly states that it is supported to import multiple keys at once with multiple '--import' options - the Getopt::Long usage in sa-update does not - it simply imports the last provided on the command line. if the file is malformed - sa-updates exits with 2 (and gpg's error output) -> will change it to run sa-update --import for each channel separately (and provide the arguments as list). >=20 > is the noerr needed? in this case it's wrong (I copied from the sa-update invocation below, where it's needed) - sa-update exits quite directly after calling `gpg --import` - with gpg's exit status. >=20 > > + my $fresh_updates =3D 0; > > + > > + for my $channel (@$localchannels) { > > + my $cmd =3D "$SAUPDATE -v --channel $channel->{channelurl} --gpgkey $= channel->{keyid}"; > > + print "Updating $channel->{channelurl}\n" if $verbose; > > + my $ret =3D PVE::Tools::run_command($cmd, noerr =3D> 1); =20 >=20 > $cmd should also be a list.. >=20 > > + die "updating $channel->{channelurl} failed - sa-update exited with $= ret\n" if $ret >=3D 2; > > + > > + $fresh_updates =3D 1 if $ret =3D=3D 0; > > + } > > + > > + return $fresh_updates > > +} > > + > > 1; > > --=20 > > 2.20.1 > >=20 > >=20 > >=20 > > _______________________________________________ > > pmg-devel mailing list > > pmg-devel@lists.proxmox.com > > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel > >=20 > >=20 > > =20