From nobody Wed Dec 17 05:49:24 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=1765868361; cv=none; d=zohomail.com; s=zohoarc; b=Q6azywXt3IYGBkw1FQPgu1tU/MDdw7tjJRyVWJd2w0sUqh3C1LZ9DAC72eBQbq4BZDtIdQaMNNa2VjJGto9Uz4FEEDqDFxsHbsG0Tj9dogfNO8LXlv7hTjWzMSOJjPNvtBPPF2eewSf7u3sIZEL/H6gQww/jpn4Jjpj0T4Wzz/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765868361; 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=6wMB7fHwMebc0947hXnEnLmrAgDyxCDfzWteh8m2S4w=; b=bGwH8kWbUgyzWP7eVoL17r3B+Ny5yFiAo+CrM2fFi2l1FR6cVtUeZ4epUbj/Xr/0e1sQ0ujqTucfgVOPT3VMzRX+88fP+K66jUOvQbfWOOBo/dcew6olioDQj16u/ikLG4v+3R91QCW6+fg9AN5fZye+YtXk02x2Soe0WmNvofQ= 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 1765868361477181.68899324370352; Mon, 15 Dec 2025 22:59:21 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id A8D0841B53; Tue, 16 Dec 2025 01:59:20 -0500 (EST) Received: from [172.19.199.80] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 8188E41AAA; Tue, 16 Dec 2025 01:58:22 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id CDA2C41A36; Tue, 16 Dec 2025 01:52:28 -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 7A7DE41A19 for ; Tue, 16 Dec 2025 01:52:24 -0500 (EST) Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-399-SsJxdyusPMORXCr1POjyBQ-1; Tue, 16 Dec 2025 01:52:22 -0500 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-7b9090d9f2eso7747815b3a.0 for ; Mon, 15 Dec 2025 22:52:21 -0800 (PST) Received: from armenon-kvm.armenon-thinkpadp16vgen1.bengluru.csb ([49.36.108.104]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7f4c22851besm14513304b3a.11.2025.12.15.22.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Dec 2025 22:52: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=1765867944; 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=6wMB7fHwMebc0947hXnEnLmrAgDyxCDfzWteh8m2S4w=; b=hG3kvvvgPLbqnmvKEqEzxd/jOYTBWU2haynHK2o8fShmgS8uDNPnH0j8CL8x+8LjzB29rm b8OqwsLsnpsorO6O0qD4gx5axnXcXbl+zqWOOc2S1yrAIWoPoAOideKE5L4+QmAXCH0KJL 1dkytFY5R67S+GbIdyZuuhz6EBR13jE= X-MC-Unique: SsJxdyusPMORXCr1POjyBQ-1 X-Mimecast-MFC-AGG-ID: SsJxdyusPMORXCr1POjyBQ_1765867941 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765867941; x=1766472741; 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=6wMB7fHwMebc0947hXnEnLmrAgDyxCDfzWteh8m2S4w=; b=UusrgeTENbybfC/vD58hJHUPgAULv8zg9K2iYQS8ci73TI5Rz+CKWIljpHQFEQSLfb dKD/0DGUd9ogRQAXT/xB6dXh4osZcFpaXP4UpoyBgNZuBIUZnuVcgH2p6aD4T4gPuWyR +dZIqHu251h5iJMxiNBsxYpBe+CnJ2jipsg0yQ4sUMtKmh36/mZExDuYXWDcLPIahkcW HLULZZyhs2ctt6+/bizx2uzw10Vgmg0/aYJSr84xQcIIEwDqX1+PdVkNCIHS+xpmNq88 C+qq9cO8mGIU+ZhRzW1gbKaj2ccTABxOXa7zWD75q2e4l57rJK4CybDL2hjHqFIzGKE/ putQ== X-Gm-Message-State: AOJu0YzpAkBjbjHsrd9CX7SmsgCR6z6oa8Ca9u62axC2ku70CkucGP54 4/Szv3AEGBUc1qeUreA6e4pEPLHkeDntKne+DmDTQ9gkg7XU667Kral4VONIWFd13cS59sxTOdr JaRT99odF0YqMYuRDX96bNdHKFJpCkU7kB2c98V6b3MrLEBYxpqZAc2LLIsHXtMQPgLX6ACY8zn PG1tw/N25gc0mNs5GgOMiR52tabn+R2utldH+doNEzTQ== X-Gm-Gg: AY/fxX7Y8Q2d48rKp4vywfh9deDfz8QZo/m90a6W+p/eNnP1tM0gooPHtRMVFfVvWBG BMnz3qXvNLqHck+qlu8M8m3lR6g1sfuvkLC5nR0wziNC0DDWgyMikqibChXSGrrUHbaS2OhuXz+ UyCqvynJwkl3lfQ/wIMK72JixbFY9ZbI/mf1e6UECZWJwXdBSOGqZUAu3yALGGfXJ95akDhYdRn awVxDciqBTgSDKA94h+KkwFFwBVV/NWK6WWucsc6Qh6EFPh14f+qXyT5kByb+oP/OvDUzvuocJc 9gTnBiHRERRpzbgSw2GOnbOCdPRdANTTsMNRAdYVi9+DH1pgNnw88dtVoDAo8J0eWzvjzeGi+5N LfptaVdTPJSWIdObF5ngsExc1XICs8X+IxWj7ydcsnkXiwS02rJyNJowSfw== X-Received: by 2002:a05:6a00:430a:b0:7e8:4398:b36b with SMTP id d2e1a72fcca58-7f669c8517bmr11867105b3a.62.1765867940785; Mon, 15 Dec 2025 22:52:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IG908RJO5JxU8xGqW3SdcdZlxOzba855gb43FGzPnM0z57ewDFwZ8H2J5oUZcITG0hq+wyxsA== X-Received: by 2002:a05:6a00:430a:b0:7e8:4398:b36b with SMTP id d2e1a72fcca58-7f669c8517bmr11867074b3a.62.1765867940146; Mon, 15 Dec 2025 22:52:20 -0800 (PST) To: devel@lists.libvirt.org Subject: [PATCH v2 2/5] secret: Set up default encryption secret key for the virtsecretd service Date: Tue, 16 Dec 2025 12:22:07 +0530 Message-ID: <20251216065210.9297-3-armenon@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251216065210.9297-1-armenon@redhat.com> References: <20251216065210.9297-1-armenon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: I6eNAtcefoJePQWoRobqPCZfYNJvaP4WfuWjvuA3K08_1765867941 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: PMYJYGLW24JTVRSZ57AO75VSJQA2T4RR X-Message-ID-Hash: PMYJYGLW24JTVRSZ57AO75VSJQA2T4RR 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: 1765868372543158500 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 | 4 ++++ src/meson.build | 1 + src/remote/libvirtd.service.in | 4 ++++ src/secret/meson.build | 12 ++++++++++++ src/secret/virt-secret-init-encryption.service.in | 8 ++++++++ src/secret/virtsecretd.service.extra.in | 8 ++++++++ 6 files changed, 37 insertions(+) create mode 100644 src/secret/virt-secret-init-encryption.service.in diff --git a/libvirt.spec.in b/libvirt.spec.in index ccfe75135b..8505a220c7 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,6 +2251,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/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..6d47569a4a 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', 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