From nobody Fri Dec 12 14:05:55 2025 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=1764228590; cv=none; d=zohomail.com; s=zohoarc; b=RGa2cC32Anpg8OZnppvvWnQnI74tbnUNzEHDM6J656kxse1XH/TkeTTb6wHedFzOMQg3Qlah/7pSFGvlM4ngO34equr1J0ToWZd1qJ/fgL1fPmIztEmDK0kXmmWXimj24Aoj3UvmlwGy4tobjAkF1fFeyW+XyjEAtb2Xw9f3rRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764228590; 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=qyiQygNl4dbtYf/9vDVmTXZVM5C3pL8uRhDWVvmRuVw=; b=Xq7SG7/hVDBqcrFxGFs+Kwb+NRhSg1j4ktkoRj11XwifPT7RlhsEams02I4WGnRf9Xbhlq5ePall4qyE6Fzjiz8VEx0NRBGsoVGm/LFnlX1EiGzbz2RLeMvxITQ+IACG3pZYGbvRlMCuigr4I3XfuSjf4mXXYeCRbn1lNNJ6VLs= 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 1764228590364359.02891531035914; Wed, 26 Nov 2025 23:29:50 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id BD16F44B87; Thu, 27 Nov 2025 02:29:49 -0500 (EST) Received: from [172.19.199.74] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id B7493419F5; Thu, 27 Nov 2025 02:28:39 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 01AE4442E2; Thu, 27 Nov 2025 02:22:48 -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 C6ED0442E2 for ; Thu, 27 Nov 2025 02:22:46 -0500 (EST) Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-345-Cg3j4kTtN0mizTlslP_kkw-1; Thu, 27 Nov 2025 02:22:44 -0500 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-29845b18d1aso11026625ad.1 for ; Wed, 26 Nov 2025 23:22:44 -0800 (PST) Received: from armenon-kvm.armenon-thinkpadp16vgen1.bengluru.csb ([49.47.195.90]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce478762sm7801695ad.45.2025.11.26.23.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Nov 2025 23:22:42 -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=1764228166; 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=qyiQygNl4dbtYf/9vDVmTXZVM5C3pL8uRhDWVvmRuVw=; b=cE78Yg3YmqcRyZoqWXwxKhiyCYrz+ZclEWCR25ndBi+NNYy1jHhdsuMuBTJrTCYkOZLHIe 7DTmv7vf0B3KqjhIOZPaLxPHY0WcvsWME2tytpuKpKCTBdkAyoo6UToEhuiRIJVXIneoqf TovxYZaJbnc62MsirPpdW+Q32nL2svU= X-MC-Unique: Cg3j4kTtN0mizTlslP_kkw-1 X-Mimecast-MFC-AGG-ID: Cg3j4kTtN0mizTlslP_kkw_1764228164 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764228163; x=1764832963; 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=qyiQygNl4dbtYf/9vDVmTXZVM5C3pL8uRhDWVvmRuVw=; b=hv5D30GmjXMzyL3h5ybXLwuWdWeTRaG/2nVD3x/vi1svf5yapKj+8zyYGzQhZ1MMuz ClCV6auTkvfLP6nSm8ODw0HQS6l0SUCDfLkqzEoySbUNQdH8ZSvUYX7hexsoxUxNbFta tWV0zFK98gjjw7/JMDuFL2LFDWS4j09O9LNlIahayV8sywLHr4b2DedCnt+53JV/yg7K 6i7g1iRGl2qwAQdUdhOJ/njTELeQevT8zfg0cjURos0mcAtVNFytyw2x1P45hQsJARa8 AQ+Rg14DrHYF6ATT6xAwhJ9bZipUhIFsDXWI1nu9cZtffExxD1+fOAXyTmnzLO+2S+HD KfrQ== X-Gm-Message-State: AOJu0YxzaLybsLkm0gLQG36tYhs8Dl4AZ591R363ECxG0IiT3/7tfnKI CBkCQ+iOzgK/tk2DovJ3ApmvYDMeb+pZIjp2fMpfI1S9D6Io9SyN9bUdbBthQ9ngwCIGB2CG62X o1KdeGkdcf1ZYjhgW1W04+kMtmGxny9A0jrKyd6x3ARYYVN8PdmyuJno118mGf09Ub1hddsuhSt EqnbPn9NcuM120VIksL+zoBX463J+ehxf3xcxJPCxjXw== X-Gm-Gg: ASbGncuASei59VQnJNpx0jK/nZzTjI6VpWujK8F2BQC8n29Hv3vkx+b6Dl1AVdeSjVl 9lCzp0b5CJD8f74Pz4iDtJYAxRg+kK7gZgINuWDLkMNXz8a0yBb/vp4fWwBRAMXREkXH8hL+Oj+ lXdb7Ir9VK2zw2+Auj2SZXIZZIa9DSp841QPUHepaEn9lxKLMwSyxZwtNfxfXuuKuQ89hDZtVH0 UTUhADkQhOBNx0jPzB7dkC/xv8vsVCBlqR2vK4qbK4+X3z2iZwXd4TAV7fpKbBMe4/tD5CAZQRC XMvRLMr2U83e6me9aPcKBUlmsPWFd7aEdgd5CATI9dr63QXQPgvO8QdNobEYnmEEjwkrooC4tiM bfR7MVMSxFQhibm9+V00WJlOvAnf3mEreGWPi2dHDh2C4cDcQUACnt0mq X-Received: by 2002:a17:902:c950:b0:295:2645:9f5 with SMTP id d9443c01a7336-29b6c575196mr288828625ad.37.1764228163427; Wed, 26 Nov 2025 23:22:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/RTnwVkH1tjZ1hn9Nhv2DZYdCB9Rwq5dVJqVFrzbjizNnpSSSsD/yYyloJ/HqfJ3ob6cGgw== X-Received: by 2002:a17:902:c950:b0:295:2645:9f5 with SMTP id d9443c01a7336-29b6c575196mr288828325ad.37.1764228162910; Wed, 26 Nov 2025 23:22:42 -0800 (PST) To: devel@lists.libvirt.org Subject: [RFC v3 2/5] secret: Set up default encryption secret key for the virtsecretd service Date: Thu, 27 Nov 2025 12:52:29 +0530 Message-ID: <20251127072232.38426-3-armenon@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251127072232.38426-1-armenon@redhat.com> References: <20251127072232.38426-1-armenon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: kaLtM_AcPYrSIP6Icwv_zujoQmph8p5IrmH0ugIT5wk_1764228164 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 7GZPTL6M3ECOTHV7HXFTQIK3EI2M6DXT X-Message-ID-Hash: 7GZPTL6M3ECOTHV7HXFTQIK3EI2M6DXT 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: 1764228597685019200 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 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 | 4 ++++ src/meson.build | 1 + src/secret/meson.build | 24 ++++++++++++++++++++++++ src/secret/secret-init-encryption.in | 10 ++++++++++ src/secret/virtsecretd.service.extra.in | 8 ++++++++ 5 files changed, 47 insertions(+) create mode 100644 src/secret/secret-init-encryption.in diff --git a/libvirt.spec.in b/libvirt.spec.in index 62af7fb517..dba8a71311 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1880,13 +1880,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 @@ -2238,6 +2241,7 @@ 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 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/secret/meson.build b/src/secret/meson.build index 3b859ea7b4..c02d1064a9 100644 --- a/src/secret/meson.build +++ b/src/secret/meson.build @@ -31,6 +31,30 @@ if conf.has('WITH_SECRETS') 'name': 'virtsecretd', } =20 + secret_init_encryption_unit =3D { + 'service': 'virt-secret-init-encryption', + 'name': 'Libvirt Secret Encryption Init', + 'input': 'secret-init-encryption.in', + } + + unit_conf =3D configuration_data() + unit_conf.set('runstatedir', runstatedir) + unit_conf.set('sbindir', sbindir) + unit_conf.set('localstatedir', localstatedir) + unit_conf.set('sysconfdir', sysconfdir) + unit_conf.set('initconfdir', initconfdir) + unit_conf.set('name', secret_init_encryption_unit['name']) + unit_conf.set('service', secret_init_encryption_unit['service']) + unit_conf.set('SERVICE', secret_init_encryption_unit['service'].to_upper= ()) + + configure_file( + input: secret_init_encryption_unit['input'], + output: '@0@.service'.format(secret_init_encryption_unit['service']), + configuration: unit_conf, + install: true, + install_dir: unitdir, + ) + virt_daemon_units +=3D { 'service': 'virtsecretd', 'name': 'secret', diff --git a/src/secret/secret-init-encryption.in b/src/secret/secret-init-= encryption.in new file mode 100644 index 0000000000..29da6dbcce --- /dev/null +++ b/src/secret/secret-init-encryption.in @@ -0,0 +1,10 @@ +[Unit] +Before=3Dvirtsecretd.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)' + +[Install] +WantedBy=3Dmulti-user.target 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