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 D440073705 for ; Fri, 18 Jun 2021 10:56:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BD05925097 for ; Fri, 18 Jun 2021 10:56:24 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B828D2508C for ; Fri, 18 Jun 2021 10:56:23 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 75AC744211 for ; Fri, 18 Jun 2021 10:56:23 +0200 (CEST) Date: Fri, 18 Jun 2021 10:56:16 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20210617083918.42253-1-l.stechauner@proxmox.com> In-Reply-To: <20210617083918.42253-1-l.stechauner@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1624006483.mzzgfvmkne.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.762 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, pve6to7.pm] Subject: [pve-devel] applied: [PATCH v3 manager] pve6to7: add check for pool permissions X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jun 2021 08:56:54 -0000 with a small follow-up: [PATCH] pve6to7: improve user.cfg parser make it a bit more like the actual one - remove whitespace padding, use same regex/split calls. Signed-off-by: Fabian Gr=C3=83=C2=BCnbichler --- PVE/CLI/pve6to7.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/PVE/CLI/pve6to7.pm b/PVE/CLI/pve6to7.pm index 4fe606f3..412fb30f 100644 --- a/PVE/CLI/pve6to7.pm +++ b/PVE/CLI/pve6to7.pm @@ -609,9 +609,20 @@ sub check_custom_pool_roles { my $raw =3D read_file('/etc/pve/user.cfg'); =20 my $roles =3D {}; - while ($raw =3D~ /^\s*role:(.*?):(.*?):(.*?)\s*$/gm) { - my ($role, $privlist) =3D ($1, $2); + while ($raw =3D~ /^\s*(.+?)\s*$/gm) { + my $line =3D $1; + my @data; =20 + foreach my $d (split (/:/, $line)) { + $d =3D~ s/^\s+//; + $d =3D~ s/\s+$//; + push @data, $d + } + + my $et =3D shift @data; + next if $et ne 'role'; + + my ($role, $privlist) =3D @data; if (!PVE::AccessControl::verify_rolename($role, 1)) { warn "user config - ignore role '$role' - invalid characters in role = name\n"; next; --=20 2.20.1 On June 17, 2021 10:39 am, Lorenz Stechauner wrote: > the two checks make sure that: > * no user defined role 'PVEPoolUser' exists > * the user gets a hint for roles only containing Pool.Allocate and > not Pool.Audit >=20 > a very simple parser for user.cfg was implemented to be able to > parse the (in pve 6 invalid) Pool.Audit permission >=20 > Signed-off-by: Lorenz Stechauner > --- > PVE/CLI/pve6to7.pm | 48 +++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 47 insertions(+), 1 deletion(-) >=20 > diff --git a/PVE/CLI/pve6to7.pm b/PVE/CLI/pve6to7.pm > index 90f92a55..4fe606f3 100644 > --- a/PVE/CLI/pve6to7.pm > +++ b/PVE/CLI/pve6to7.pm > @@ -9,6 +9,7 @@ use PVE::API2::LXC; > use PVE::API2::Qemu; > use PVE::API2::Certificates; > =20 > +use PVE::AccessControl; > use PVE::Ceph::Tools; > use PVE::Cluster; > use PVE::Corosync; > @@ -16,10 +17,11 @@ use PVE::INotify; > use PVE::JSONSchema; > use PVE::RPCEnvironment; > use PVE::Storage; > -use PVE::Tools qw(run_command); > +use PVE::Tools qw(run_command split_list); > use PVE::QemuServer; > use PVE::VZDump::Common; > =20 > +use File::Slurp; > use Term::ANSIColor; > =20 > use PVE::CLIHandler; > @@ -601,6 +603,49 @@ sub check_cifs_credential_location { > log_pass("no CIFS credentials at outdated location found.") if !$fou= nd; > } > =20 > +sub check_custom_pool_roles { > + log_info("Checking custom roles for pool permissions.."); > + > + my $raw =3D read_file('/etc/pve/user.cfg'); > + > + my $roles =3D {}; > + while ($raw =3D~ /^\s*role:(.*?):(.*?):(.*?)\s*$/gm) { > + my ($role, $privlist) =3D ($1, $2); > + > + if (!PVE::AccessControl::verify_rolename($role, 1)) { > + warn "user config - ignore role '$role' - invalid characters in rol= e name\n"; > + next; > + } > + > + $roles->{$role} =3D {} if !$roles->{$role}; > + foreach my $priv (split_list($privlist)) { > + $roles->{$role}->{$priv} =3D 1; > + } > + } > + > + foreach my $role (sort keys %{$roles}) { > + if (PVE::AccessControl::role_is_special($role)) { > + next; > + } > + > + if ($role eq "PVEPoolUser") { > + # the user created a custom role named PVEPoolUser > + log_fail("Custom role '$role' has a restricted name - a built-in ro= le 'PVEPoolUser' will be available with the upgrade"); > + } else { > + log_pass("Custom role '$role' has no restricted name"); > + } > + > + my $perms =3D $roles->{$role}; > + if ($perms->{'Pool.Allocate'} && $perms->{'Pool.Audit'}) { > + log_pass("Custom role '$role' contains updated pool permissions"); > + } elsif ($perms->{'Pool.Allocate'}) { > + log_warn("Custom role '$role' contains permission 'Pool.Allocate' -= to ensure same behavior add 'Pool.Audit' to this role"); > + } else { > + log_pass("Custom role '$role' contains no permissions that need to = be updated"); > + } > + } > +} > + > sub check_misc { > print_header("MISCELLANEOUS CHECKS"); > my $ssh_config =3D eval { PVE::Tools::file_get_contents('/root/.ssh/= config') }; > @@ -693,6 +738,7 @@ sub check_misc { > =20 > check_backup_retention_settings(); > check_cifs_credential_location(); > + check_custom_pool_roles(); > } > =20 > __PACKAGE__->register_method ({ > --=20 > 2.30.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20