From nobody Mon Feb 2 09:26:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1767982456; cv=none; d=zohomail.com; s=zohoarc; b=FvFHEp17zzfda8m8D4AE7Rg7ykIf7FI8z9JnAHSRk/UOW41Ce5EYSDTrlYTqez0VoZldDMgDs/f0CM9+qtpuZHvT1fkp5XvVetaCoaYuL2baUoPEfjA7/ky9eDWgZFA7gmqo6XYGKlaYzmSXQnBj7lO3khNrySAQ/6VAps03vnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767982456; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=a8l6ZUHUmYX97jfGG1Xms5qz8+jqpEGDJsvCji3ZL5c=; b=cVbmuNnrJr3YARLHCXQ8xBOk/vukHlPJ+Z7ecDBXv9MAo6gWW5e+e9J1BH5SiCwqh90AvqAjF3kj4174y8dGnmACGWG1m8q/mUc1Wy33v6471OewE0r0+/ABGjbu89urSPbEdFrG1iM2sqsfqPeIcoXvpGFx/vjXUUv1cuWhEus= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1767982456705727.0115658276866; Fri, 9 Jan 2026 10:14:16 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id AF61743E53; Fri, 9 Jan 2026 13:14:15 -0500 (EST) Received: from [172.19.199.83] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 6F3CE43EDA; Fri, 9 Jan 2026 13:10:17 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id A1DCE43E0C; Fri, 9 Jan 2026 13:09:51 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 9A19443E00 for ; Fri, 9 Jan 2026 13:09:49 -0500 (EST) Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-423-eKP4heIhNRCdyMAxh-pHVw-1; Fri, 09 Jan 2026 13:09:46 -0500 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2a351686c17so53929985ad.0 for ; Fri, 09 Jan 2026 10:09:46 -0800 (PST) Received: from armenon-kvm.armenon-thinkpadp16vgen1.bengluru.csb ([49.36.108.228]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3cc8803sm111020495ad.71.2026.01.09.10.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jan 2026 10:09:44 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767982189; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a8l6ZUHUmYX97jfGG1Xms5qz8+jqpEGDJsvCji3ZL5c=; b=CqZ9/DH65M7D0yEKBlo9yDUZhMUKmy/vpkc7Vr/lbseoI9j0MlHV3wpVx/798X9OeH/gJr UR0N4yRJZNUZo+AciuC5o+SitVUFQbARldXx11kVPYxP32zEA3AO8zoUy+vhQIr+gXArk8 mpNL5XgoBCBgQF+aWDgbRjOdghw2H3o= X-MC-Unique: eKP4heIhNRCdyMAxh-pHVw-1 X-Mimecast-MFC-AGG-ID: eKP4heIhNRCdyMAxh-pHVw_1767982186 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767982185; x=1768586985; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=a8l6ZUHUmYX97jfGG1Xms5qz8+jqpEGDJsvCji3ZL5c=; b=EXmXGcmen09b43JtVkB7OTa04QxQw4w9xecM8FvkBu4ZEH4/KOkiQRljNOe4XcRt2w kZs97j1EmbDiNAMJFkcNGlvRynVmbB9GUVZtpbUJlnTVFCaAE8QFq/StG5dvmyVGDwQY 9EFPseG+2YUyE8Clyl0yzlRzNok2rWM+97PubB3zI+WdhXleYYqiG3VxxDS8zDrISEYl k1mzxEciuap3n3c2YaINf1/CB9TjaKpWL2Q16yv+8NxNreS5G5kJe6UzULrB22H4nwEW nxf75D3FrCEdSCCGY3cO1IcWBqmgcviYlgkufTdfOlom4MNezQwoCCmHPxugRH4xZJVe +moQ== X-Gm-Message-State: AOJu0YxoV30XIBZAWkGmxozEj9ioVn/Ho3TYZfiipA8RKTmtYbfSIo4N 1YqRBVWpL7jVnq20UbB2ORAo4L+0kgEq5WP1yin4OwMT6ooSmy02SKqALQO2pE/xzUnwOH6zT/m txqWkortTe2Dwltew30K2GHOfnbn8qXbMzw+bmkQbtVmm4buS68f9xCo0dD8WxwAsDVlU9DpV74 8++bLYxxOq+R4Rk2BERyq2rycuC8d7cWlulnbvbQcvSQ== X-Gm-Gg: AY/fxX4w8QUgIzT8Iy8FTOmYckOeyIcEDS2Qwsrzg5fvrQxrCxcIIlB2Dm28ViofOAB lqhAbduqtB+5aSWzUOpPczySjfMyWQA8+/x501lu1wGWDsJx9nDofV1Ly3hQiytFA7ZczOLBGEF CAFgPj+FAalxXd0GS2Txc8AT8pTkETsF0gRaTUYUO638J9VS6fTD8+svwIS/E3rC/+jAKVQZ08j WV5qTsbPU91hNQ10nr6tMOAtMPFO7g9bRyrJw6jQBKBXS05PFmhOfEfPs4ZxNXeiokaBepmeqSc qZ1qKHLb6xPQO2g80TgDIJ1aDXTHHdYHIiP88G+dUcJ1Fyh3qDK4g/cax06sB616jf/N6SF/PjO Pvbgr73ZgaN0tpy6tfqF0ZskLFfv+Gi9sTndhqwy9nV9zDix5gti9eN/rvQ== X-Received: by 2002:a17:903:1247:b0:2a0:b7d3:eec5 with SMTP id d9443c01a7336-2a3ee4e85bdmr101559465ad.33.1767982185250; Fri, 09 Jan 2026 10:09:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmUoVRiBBTNNvq6OIir0aO48HxdaFo4SDWTDcWfqEArydSj+92oP5V3iBlLpsoGzWKk4vgAQ== X-Received: by 2002:a17:903:1247:b0:2a0:b7d3:eec5 with SMTP id d9443c01a7336-2a3ee4e85bdmr101559285ad.33.1767982184639; Fri, 09 Jan 2026 10:09:44 -0800 (PST) To: devel@lists.libvirt.org Subject: [PATCH v4 2/6] secret: Set up default encryption secret key for the virtsecretd service Date: Fri, 9 Jan 2026 23:39:32 +0530 Message-ID: <20260109180936.127454-3-armenon@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20260109180936.127454-1-armenon@redhat.com> References: <20260109180936.127454-1-armenon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hJuipw0542M2N0ulYBOKSeX-VdCCG_67SufnQnbzDKM_1767982186 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HAVBP6H7HKO7NICYDPB6R6GHLS4ER5BC X-Message-ID-Hash: HAVBP6H7HKO7NICYDPB6R6GHLS4ER5BC X-MailFrom: armenon@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Arun Menon X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Arun Menon via Devel Reply-To: Arun Menon X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1767982463147158500 Content-Type: text/plain; charset="utf-8"; x-default="true" This commit sets the foundation for encrypting the libvirt secrets by provi= ding a secure way to pass a secret encryption key to the virtsecretd service. A random secret key is generated using the new virt-secret-init-encryption service. This key can be consumed by the virtsecretd service. By using the "Before=3D" directive in the new virt-secret-init-encryption service and using "Requires=3D" directive in the virtsecretd service, we make sure that the daemon is run only after we have an encrypted secret key file generated and placed in /var/lib/libvirt/secrets. The virtsecretd service can then read the key from CREDENTIALS_DIRECTORY. [= 1] This setup therefore provides a default key out-of-the-box for initial use. A subsequent commit will introduce the logic for virtsecretd to access and use this key via the $CREDENTIALS_DIRECTORY environment varia= ble. [2] [1] https://www.freedesktop.org/software/systemd/man/latest/systemd-creds.h= tml [2] https://systemd.io/CREDENTIALS/ Signed-off-by: Arun Menon --- libvirt.spec.in | 5 +++++ src/meson.build | 1 + src/remote/libvirtd.service.in | 4 ++++ src/secret/meson.build | 13 +++++++++++++ src/secret/virt-secret-init-encryption.service.in | 8 ++++++++ src/secret/virtsecretd.service.extra.in | 8 ++++++++ 6 files changed, 39 insertions(+) create mode 100644 src/secret/virt-secret-init-encryption.service.in diff --git a/libvirt.spec.in b/libvirt.spec.in index ccfe75135b..6a497bfecd 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1890,13 +1890,16 @@ exit 0 %pre daemon-driver-secret %libvirt_sysconfig_pre virtsecretd %libvirt_systemd_unix_pre virtsecretd +%libvirt_systemd_oneshot_pre virt-secret-init-encryption =20 %posttrans daemon-driver-secret %libvirt_sysconfig_posttrans virtsecretd %libvirt_systemd_unix_posttrans virtsecretd +%libvirt_systemd_unix_posttrans virt-secret-init-encryption =20 %preun daemon-driver-secret %libvirt_systemd_unix_preun virtsecretd +%libvirt_systemd_unix_preun virt-secret-init-encryption =20 %pre daemon-driver-storage-core %libvirt_sysconfig_pre virtstoraged @@ -2248,11 +2251,13 @@ exit 0 %{_datadir}/augeas/lenses/virtsecretd.aug %{_datadir}/augeas/lenses/tests/test_virtsecretd.aug %{_unitdir}/virtsecretd.service +%{_unitdir}/virt-secret-init-encryption.service %{_unitdir}/virtsecretd.socket %{_unitdir}/virtsecretd-ro.socket %{_unitdir}/virtsecretd-admin.socket %attr(0755, root, root) %{_sbindir}/virtsecretd %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/secrets/ +%dir %attr(0700, root, root) %{_localstatedir}/lib/libvirt/secrets/ %ghost %dir %attr(0700, root, root) %{_rundir}/libvirt/secrets/ %{_libdir}/libvirt/connection-driver/libvirt_driver_secret.so %{_mandir}/man8/virtsecretd.8* diff --git a/src/meson.build b/src/meson.build index 47c978cc1f..f18f562fd9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -837,6 +837,7 @@ if conf.has('WITH_LIBVIRTD') 'sbindir': sbindir, 'sysconfdir': sysconfdir, 'initconfdir': initconfdir, + 'localstatedir': localstatedir, 'name': unit['name'], 'service': unit['service'], 'SERVICE': unit['service'].to_upper(), diff --git a/src/remote/libvirtd.service.in b/src/remote/libvirtd.service.in index b0a062e885..7965010a0a 100644 --- a/src/remote/libvirtd.service.in +++ b/src/remote/libvirtd.service.in @@ -12,6 +12,8 @@ After=3Dlibvirtd.socket After=3Dlibvirtd-ro.socket After=3Dlibvirtd-admin.socket Requires=3Dvirtlogd.socket +Requires=3Dvirt-secret-init-encryption.service +After=3Dvirt-secret-init-encryption.service Wants=3Dvirtlockd.socket After=3Dvirtlogd.socket After=3Dvirtlockd.socket @@ -29,6 +31,8 @@ Conflicts=3Dxendomains.service Type=3Dnotify-reload Environment=3DLIBVIRTD_ARGS=3D"--timeout 120" EnvironmentFile=3D-@initconfdir@/libvirtd +Environment=3DSECRETS_ENCRYPTION_KEY=3D%d/secrets-encryption-key +LoadCredentialEncrypted=3Dsecrets-encryption-key:@localstatedir@/lib/libvi= rt/secrets/secrets-encryption-key ExecStart=3D@sbindir@/libvirtd $LIBVIRTD_ARGS ExecReload=3D/bin/kill -HUP $MAINPID KillMode=3Dprocess diff --git a/src/secret/meson.build b/src/secret/meson.build index 3b859ea7b4..b69abe32ab 100644 --- a/src/secret/meson.build +++ b/src/secret/meson.build @@ -31,6 +31,18 @@ if conf.has('WITH_SECRETS') 'name': 'virtsecretd', } =20 + virt_secret_init_encryption_conf =3D configuration_data() + + virt_secret_init_encryption_conf.set('localstatedir', localstatedir) + + configure_file( + input: 'virt-secret-init-encryption.service.in', + output: '@0@.service'.format('virt-secret-init-encryption'), + configuration: virt_secret_init_encryption_conf, + install: true, + install_dir: unitdir, + ) + virt_daemon_units +=3D { 'service': 'virtsecretd', 'name': 'secret', @@ -50,5 +62,6 @@ if conf.has('WITH_SECRETS') virt_install_dirs +=3D [ confdir / 'secrets', runstatedir / 'libvirt' / 'secrets', + localstatedir / 'lib' / 'libvirt' / 'secrets', ] endif diff --git a/src/secret/virt-secret-init-encryption.service.in b/src/secret= /virt-secret-init-encryption.service.in new file mode 100644 index 0000000000..44940bd72b --- /dev/null +++ b/src/secret/virt-secret-init-encryption.service.in @@ -0,0 +1,8 @@ +[Unit] +Before=3Dvirtsecretd.service +Before=3Dlibvirtd.service +ConditionPathExists=3D!@localstatedir@/lib/libvirt/secrets/secrets-encrypt= ion-key + +[Service] +Type=3Doneshot +ExecStart=3D/usr/bin/sh -c 'umask 0066 && (dd if=3D/dev/urandom status=3Dn= one bs=3D32 count=3D1 | systemd-creds encrypt --name=3Dsecrets-encryption-k= ey - @localstatedir@/lib/libvirt/secrets/secrets-encryption-key)' diff --git a/src/secret/virtsecretd.service.extra.in b/src/secret/virtsecre= td.service.extra.in index 1fc8c672f7..116458b22a 100644 --- a/src/secret/virtsecretd.service.extra.in +++ b/src/secret/virtsecretd.service.extra.in @@ -1,2 +1,10 @@ # The contents of this unit will be merged into a base template. # Additional units might be merged as well. See meson.build for details. +# +[Unit] +Requires=3Dvirt-secret-init-encryption.service +After=3Dvirt-secret-init-encryption.service + +[Service] +LoadCredentialEncrypted=3Dsecrets-encryption-key:@localstatedir@/lib/libvi= rt/secrets/secrets-encryption-key +Environment=3DSECRETS_ENCRYPTION_KEY=3D%d/secrets-encryption-key --=20 2.51.1