public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH access-control 2/4] check enforced realm tfa type in new auth
Date: Wed, 10 Nov 2021 13:49:01 +0100	[thread overview]
Message-ID: <20211110124904.164053-3-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20211110124904.164053-1-w.bumiller@proxmox.com>

this way we could also add webauthn as a required tfa type
to the realm configs later on

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
 src/PVE/AccessControl.pm | 48 +++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/src/PVE/AccessControl.pm b/src/PVE/AccessControl.pm
index 49cef94..c043404 100644
--- a/src/PVE/AccessControl.pm
+++ b/src/PVE/AccessControl.pm
@@ -749,29 +749,41 @@ sub authenticate_2nd_new : prototype($$$$) {
 	}
 
 	my $realm_type = $realm_tfa && $realm_tfa->{type};
-	if (defined($realm_type) && $realm_type eq 'yubico') {
-	    # Yubico auth will not be supported in rust for now...
-	    if (!defined($tfa_challenge)) {
-		my $challenge = { yubico => JSON::true };
-		# Even with yubico auth we do allow recovery keys to be used:
-		if (my $recovery = $tfa_cfg->recovery_state($username)) {
-		    $challenge->{recovery} = $recovery;
+	$realm_type = 'totp' if $realm_type eq 'oath'; # we used to call it that
+	# verify realm type unless using recovery keys:
+	if (defined($realm_type)) {
+	    if ($realm_type eq 'yubico') {
+		# Yubico auth will not be supported in rust for now...
+		if (!defined($tfa_challenge)) {
+		    my $challenge = { yubico => JSON::true };
+		    # Even with yubico auth we do allow recovery keys to be used:
+		    if (my $recovery = $tfa_cfg->recovery_state($username)) {
+			$challenge->{recovery} = $recovery;
+		    }
+		    return to_json($challenge);
 		}
-		return to_json($challenge);
-	    }
 
-	    if ($otp =~ /^yubico:(.*)$/) {
-		$otp = $1;
-		# Defer to after unlocking the TFA config:
-		return sub {
-		    authenticate_yubico_new($tfa_cfg, $username, $realm_tfa, $tfa_challenge, $otp);
-		};
+		if ($otp =~ /^yubico:(.*)$/) {
+		    $otp = $1;
+		    # Defer to after unlocking the TFA config:
+		    return sub {
+			authenticate_yubico_new(
+			    $tfa_cfg, $username, $realm_tfa, $tfa_challenge, $otp,
+			);
+		    };
+		}
 	    }
 
-	    # Beside the realm configured auth we only allow recovery keys:
-	    if ($otp !~ /^recovery:/) {
-		die "realm requires yubico authentication\n";
+	    my $response_type;
+	    if (defined($otp)) {
+		if ($otp !~ /^([^:]+):/) {
+		    die "bad otp response\n";
+		}
+		$response_type = $1;
 	    }
+
+	    die "realm requires $realm_type authentication\n"
+		if $response_type && $response_type ne 'recovery' && $response_type ne $realm_type;
 	}
 
 	configure_u2f_and_wa($tfa_cfg);
-- 
2.30.2





  parent reply	other threads:[~2021-11-10 12:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 12:48 [pve-devel] [PATCH access-control + manager] tfa followup Wolfgang Bumiller
2021-11-10 12:49 ` [pve-devel] [PATCH access-control 1/4] assert tfa/user config lock order Wolfgang Bumiller
2021-11-10 12:49 ` Wolfgang Bumiller [this message]
2021-11-10 12:49 ` [pve-devel] [PATCH access-control 3/4] d/control: add liburi-perl dependency Wolfgang Bumiller
2021-11-10 12:49 ` [pve-devel] [PATCH access-control 4/4] merge old user.cfg keys to tfa config when adding entries Wolfgang Bumiller
2021-11-10 12:49 ` [pve-devel] [PATCH manager] depend on and use libjs-qrcodejs Wolfgang Bumiller
2021-11-11  7:38   ` [pve-devel] applied: " Thomas Lamprecht
2021-11-11 16:06 ` [pve-devel] applied-series: [PATCH access-control + manager] tfa followup Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211110124904.164053-3-w.bumiller@proxmox.com \
    --to=w.bumiller@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal