all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Mark Atwood <mark@wolfssl.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH access-control v2 1/1] tickets: sign with the hash from the datacenter configuration
Date: Fri, 13 Nov 2026 03:06:52 +0000	[thread overview]
Message-ID: <20261113030652.3550-2-mark@wolfssl.com> (raw)
In-Reply-To: <20261113030652.3550-1-mark@wolfssl.com>

Read the new 'ticket-signature-hash' option of datacenter.cfg and pass
it to PVE::Ticket::assemble_rsa_ticket() for all tickets that are
signed here: login and TFA tickets, as well as the short-lived VNC and
tunnel tickets. Without the option, tickets are signed with SHA-1 as
before.

This lets setups where SHA-1 signatures are not acceptable, like
running in FIPS mode, create tickets. It depends on the option in
pve-cluster and on the changes to PVE::Ticket in pve-common, which
should be applied first. With older versions of those, the option is
not set and the parameter is ignored, so tickets are still signed with
SHA-1.

Tickets that nodes verify are accepted with either hash, as long as
those nodes have the PVE::Ticket changes. Tunnel tickets are verified
on the target node, so the option must only be set to 'sha256' once all
nodes of the cluster have them. The datacenter configuration is the
same on all nodes, so the same hash is used on all of them.

The tests check the hash of the signature for each kind of ticket and
that tickets of both hashes verify with either setting.

Signed-off-by: Mark Atwood <mark@wolfssl.com>
---
 src/PVE/AccessControl.pm               |  23 +++++-
 src/test/Makefile                      |   1 +
 src/test/ticket-signature-hash-test.pl | 100 +++++++++++++++++++++++++
 3 files changed, 122 insertions(+), 2 deletions(-)
 create mode 100644 src/test/ticket-signature-hash-test.pl

diff --git a/src/PVE/AccessControl.pm b/src/PVE/AccessControl.pm
index a4e1c36..fceea56 100644
--- a/src/PVE/AccessControl.pm
+++ b/src/PVE/AccessControl.pm
@@ -377,12 +377,25 @@ my $get_ticket_age_range = sub {
     return ($min, $max);
 };
 
+# The hash algorithm for the signature of newly created tickets, as configured cluster-wide.
+my sub get_ticket_signature_hash {
+    my $dc_conf = cfs_read_file('datacenter.cfg');
+
+    return $dc_conf->{'ticket-signature-hash'} // 'sha1';
+}
+
 sub assemble_ticket : prototype($;$) {
     my ($data, $aad) = @_;
 
     my $rsa_priv = get_privkey();
 
-    return PVE::Ticket::assemble_rsa_ticket($rsa_priv, 'PVE', $data, $aad);
+    return PVE::Ticket::assemble_rsa_ticket(
+        $rsa_priv,
+        'PVE',
+        $data,
+        $aad,
+        get_ticket_signature_hash(),
+    );
 }
 
 # Returns the username, "age" and tfa info.
@@ -516,7 +529,13 @@ my $assemble_short_lived_ticket = sub {
     my $secret_data = "$username:$path";
     $secret_data .= ":$additional_secret" if defined($additional_secret);
 
-    return PVE::Ticket::assemble_rsa_ticket($rsa_priv, $prefix, undef, $secret_data);
+    return PVE::Ticket::assemble_rsa_ticket(
+        $rsa_priv,
+        $prefix,
+        undef,
+        $secret_data,
+        get_ticket_signature_hash(),
+    );
 };
 
 my $verify_short_lived_ticket = sub {
diff --git a/src/test/Makefile b/src/test/Makefile
index 8f3ba47..ac8c6cc 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -22,4 +22,5 @@ check:
 	perl -I.. api-tests.pl
 	perl -I.. sdn_acl_pruning_test.pl
 	perl -I.. sdn_acl_migration_test.pl
+	perl -I.. ticket-signature-hash-test.pl
 
diff --git a/src/test/ticket-signature-hash-test.pl b/src/test/ticket-signature-hash-test.pl
new file mode 100644
index 0000000..2e4d05b
--- /dev/null
+++ b/src/test/ticket-signature-hash-test.pl
@@ -0,0 +1,100 @@
+#!/usr/bin/perl
+
+use v5.36;
+
+use lib qw(..);
+
+use Crypt::OpenSSL::RSA;
+use MIME::Base64;
+use Test::MockModule;
+use Test::More;
+
+use PVE::AccessControl;
+
+# Tickets are signed with the hash from the 'ticket-signature-hash' datacenter option, which
+# defaults to SHA-1. Whether a signature is SHA-1 or SHA-256 is checked by verifying it with a
+# public key where only that hash is accepted.
+
+my $rsa_priv = Crypt::OpenSSL::RSA->generate_key(2048);
+my $pub_pem = $rsa_priv->get_public_key_string();
+
+my $datacenter_conf = {};
+
+my $access_control_module = Test::MockModule->new('PVE::AccessControl');
+$access_control_module->mock(
+    get_privkey => sub { return $rsa_priv },
+    get_pubkey => sub { return (Crypt::OpenSSL::RSA->new_public_key($pub_pem), time()) },
+    cfs_read_file => sub($file) {
+        die "unexpected cfs_read_file('$file') call\n" if $file ne 'datacenter.cfg';
+        return $datacenter_conf;
+    },
+);
+
+my sub signed_with($ticket, $hash, $secret_data) {
+    my $pub = Crypt::OpenSSL::RSA->new_public_key($pub_pem);
+    $hash eq 'sha256' ? $pub->use_sha256_hash() : $pub->use_sha1_hash();
+    my ($plain, $sig) = $ticket =~ m/^(.+)::([^:]+)$/ or die "unexpected ticket '$ticket'\n";
+    my $full = defined($secret_data) ? "$plain:$secret_data" : $plain;
+    return $pub->verify($full, decode_base64($sig)) ? 1 : 0;
+}
+
+# name, assemble function and the secret data that is signed along but not part of the ticket
+my @tickets = (
+    ['login ticket', sub { PVE::AccessControl::assemble_ticket('root@pam') }, undef],
+    [
+        'TFA ticket',
+        sub { PVE::AccessControl::assemble_ticket('root@pam', 'tfa-aad') },
+        'tfa-aad',
+    ],
+    [
+        'VNC ticket',
+        sub { PVE::AccessControl::assemble_vnc_ticket('root@pam', '/vms/100', 5900) },
+        'root@pam:/vms/100:5900',
+    ],
+    [
+        'tunnel ticket',
+        sub { PVE::AccessControl::assemble_tunnel_ticket('root@pam', '/vms/100') },
+        'root@pam:/vms/100',
+    ],
+);
+
+my @options = (
+    ['unset', {}, 'sha1'],
+    ['sha1', { 'ticket-signature-hash' => 'sha1' }, 'sha1'],
+    ['sha256', { 'ticket-signature-hash' => 'sha256' }, 'sha256'],
+);
+
+for my $option (@options) {
+    my ($name, $conf, $expected) = @$option;
+    my $other = $expected eq 'sha1' ? 'sha256' : 'sha1';
+    $datacenter_conf = $conf;
+
+    for my $ticket_type (@tickets) {
+        my ($type, $assemble, $secret) = @$ticket_type;
+        my $ticket = $assemble->();
+        is(
+            signed_with($ticket, $expected, $secret),
+            1,
+            "$type is signed with $expected if option is $name",
+        );
+        is(
+            signed_with($ticket, $other, $secret),
+            0,
+            "$type is not signed with $other if option is $name",
+        );
+    }
+}
+
+# tickets of either hash have to be accepted, independent of the option
+for my $option (@options) {
+    my ($name, $conf) = @$option;
+    $datacenter_conf = $conf;
+    my $ticket = PVE::AccessControl::assemble_ticket('root@pam');
+    for my $verify_conf (@options) {
+        $datacenter_conf = $verify_conf->[1];
+        my ($user) = PVE::AccessControl::verify_ticket($ticket, 1);
+        is($user, 'root@pam', "ticket created with option $name is valid with $verify_conf->[0]");
+    }
+}
+
+done_testing();



  reply	other threads:[~2026-11-13  3:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  3:06 [PATCH access-control v2 0/1] tickets: sign with the hash from datacenter.cfg Mark Atwood
2026-11-13  3:06 ` Mark Atwood [this message]
2026-11-17 16:05   ` [PATCH access-control v2 1/1] tickets: sign with the hash from the datacenter configuration Shannon Sterz

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=20261113030652.3550-2-mark@wolfssl.com \
    --to=mark@wolfssl.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal