From nobody Wed Feb 11 01:26:10 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; 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=1770711499; cv=none; d=zohomail.com; s=zohoarc; b=HBH2DZfqAjyZuwVCFXuIVasVMkWPFiTOKBmYFhMRseQ9St4lCgpPzMuM5eAFv8dgHNnSndXqihlomTdtCzmzlKNoBoXVZWGwzQHFacLaUKDCA2UlabkNVnjPoUnB5Owj+dlE0XnXB2CkXnJyV5UG4Y4h4zQIFhp3QtHZKszXaDw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770711499; 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=7wyuNw9mDtcomhtr5XeLuiKU4nTl8PPFENM2pQCqjMw=; b=SqvTaPmhi1asSm0SLo+ssdyycYNGyTXdmHbkCRILZdDdElbpR2i0pBHEdZETdCSBkRv/9pSgspWY8uThCbF6tQu6YhvtjF6G9JxGBF0Y8PQ07xe9bRVTYma0LpafgUTxhQ42w1nsMCaxUhjKvnvbuU6ncD8ctuynD/Y4KvBtaN8= 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 1770711499457863.9764066283983; Tue, 10 Feb 2026 00:18:19 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 8805E44054; Tue, 10 Feb 2026 03:18:19 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 5367B4410B; Tue, 10 Feb 2026 03:16:40 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id A58B43F36D; Tue, 10 Feb 2026 03:00:28 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 80EE93F322 for ; Tue, 10 Feb 2026 03:00:24 -0500 (EST) Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-204-oRwAx90ePsuSx_h6gEri7A-1; Tue, 10 Feb 2026 03:00:22 -0500 Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2aad5fc5b2fso6973845ad.1 for ; Tue, 10 Feb 2026 00:00:22 -0800 (PST) Received: from armenon-kvm.armenon-thinkpadp16vgen1.bengluru.csb ([49.36.106.198]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aadc397d8dsm98273835ad.1.2026.02.10.00.00.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Feb 2026 00:00:19 -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=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, 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=1770710424; 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=7wyuNw9mDtcomhtr5XeLuiKU4nTl8PPFENM2pQCqjMw=; b=TAfNlRgXdyPw3tkjLXRqqM0pg/IrQa4dzaqSwsHqNhZfOQ/vBj6Q5jlOBNF5HNAWpVCtDI jhywNgDuHHn3yF2+aWIJThK5k6glxhHIw3fUdTCgYLPtdpN8r+hL6q5PKd8gGGynCoolr5 P3DACQW94Ym5IF0KjEi7LwwTaY4LIAM= X-MC-Unique: oRwAx90ePsuSx_h6gEri7A-1 X-Mimecast-MFC-AGG-ID: oRwAx90ePsuSx_h6gEri7A_1770710421 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770710421; x=1771315221; 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=7wyuNw9mDtcomhtr5XeLuiKU4nTl8PPFENM2pQCqjMw=; b=Y/mYLqGz0yBocXNOKCkXL44Y6K5RJLZWE40q87kLcRvgBaAIGXfwLLeNeQzmvKSpqR vGx2UNWrPgliwi5g9Q1Q+ZTzH8fuaWsSU9endWTFMKhHGJKOQt/d/mY9bMqcGg2ae/sT Ruidh8mvhlIqr+qaSiAM3Ji6BM+Um3j3LYeryN9RvMwf1fp8Uww4/BwLmOqLYZ/2v56q grAaKXCiu4VqZmPszOTPHIa0QXGIL9vXpYAo16XNtUB7BYGhuf0QUQJG3zqjQ7zBNHN8 3LilVqXPLO8Mcq221QtlOfg6jOiZyjyyyQ4YhBpSoZWjpSDDDWHCeISjzdvumhA+TvAY SFSg== X-Gm-Message-State: AOJu0Yz8vOfBUlyckBwhd+poHYT3zB128ZFG0RHqYVGPd0hzbsg7gDjq KJYB3yE3/eQ1O+JDq2ZZpBowLAc2tNL7PKxOCk8HHV4IMeRSK6ZpED3FB/2S/qHdAiymfUT8eBk C4zAd4duynKBWR0ulySuU7Bh4DYBgcG0iTHRLr0VFpVr/9Nfg+WpIQaBGP5fuwVfkRTqa5ToqxK Lqacs7raQwt4MXvfW3nMXiI4oRRu79dy+UNptVGfuOuQ== X-Gm-Gg: AZuq6aKHGSwceRNh/RIuYrVc9C8iYow3OJ9voZ0YAZv+3cZHuwwnE5zmQJ1hC01VD17 hcBkuH9pXZ/RjhoWh3bnMz0NSryYaxOXkjgsfzGOHaoQhtnZwWuq61hR+l6ThQJ1QWuFE4ke5sW MQLjr6VhuJ4QIoUe291lz3G87MWkDrqM2iWoCtzfDYieP2EstWSf7N2Yw9aBlZ+AbHmW7aqT/rG pwQlECloAw0jl13ItjhUG4C3ivSrtLw+aCN6ay1/1fmEP+kg6E2AjaYHMqlq3BqQ89PH7871LPp ux5+tTlSufLpb9miCTRBaFf6Ud+X65JYSfsj4uAa74ooHFpDE46Rd8uIBiP80omECWwXJMrfVIr 5zkxkZwNyH/ndQOot3kHr8Wc+oG1mEXEqpVyOsAoGki3A2KJhdJFP/wPZ0Y87sTzkhhikmw== X-Received: by 2002:a17:902:ce08:b0:2a9:622e:fd3f with SMTP id d9443c01a7336-2a9622f3041mr122671685ad.36.1770710420638; Tue, 10 Feb 2026 00:00:20 -0800 (PST) X-Received: by 2002:a17:902:ce08:b0:2a9:622e:fd3f with SMTP id d9443c01a7336-2a9622f3041mr122670955ad.36.1770710419779; Tue, 10 Feb 2026 00:00:19 -0800 (PST) To: devel@lists.libvirt.org Subject: [PATCH v5 2/6] secret: Set up default encryption secret key for the virtsecretd service Date: Tue, 10 Feb 2026 13:30:08 +0530 Message-ID: <20260210080012.17753-3-armenon@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20260210080012.17753-1-armenon@redhat.com> References: <20260210080012.17753-1-armenon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: NDzUuLDttJSd6DZQOkBYv2K2uaeqHAYdwAEDl3fSLjE_1770710421 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3ESEFPSYFMYNUVAMEIHRIZKXYQPEOGA6 X-Message-ID-Hash: 3ESEFPSYFMYNUVAMEIHRIZKXYQPEOGA6 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: 1770711533881158500 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 Reviewed-by: Peter Krempa --- 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 22c9975d9f..34a47d689c 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1891,13 +1891,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 @@ -2249,11 +2252,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 16875622f4..cab52ce7a3 100644 --- a/src/meson.build +++ b/src/meson.build @@ -833,6 +833,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..8fd54002a0 --- /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 0077 && (dd if=3D/dev/random status=3Dno= ne bs=3D32 count=3D1 | systemd-creds encrypt --name=3Dsecrets-encryption-ke= y - @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