From nobody Mon Feb 9 01:47:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1578670979; cv=none; d=zohomail.com; s=zohoarc; b=kXGtO68NgVHvg9UWlXkuR8InjuLu/f2Fwey/xzhToWkGJxExfEwPX3Ye2SwQVzPHVIOmMqJhd7UE4RvpML+sa7+BGoU7XJGMPiuaNo+oyqc7tr1xtLgM/bp0S9FZE4x+dibl2cNjh34UOEvkKnnf4Q/x3IT/VWqEMxFbeqP3dp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670979; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2oGNkYhqp5RC5hUkE5qDNUUpnY0SV04CHUIONXqBM4k=; b=E0U+8dIHUfGTwuUIIzh1Wk+MF3OT76wa3epY9CXPJ5VccFsNASRqCbeWL2x3pqJbRJ9Wkjqx+PDMaLcCFcXnnLBwSrjpxTb/4Z2v6aFzSCv6W3dKE5eVzK5anQfoN+AeMXQ+ruZvNuTqRLUb2dvtfvC6b1Id4W1XR5XLlRG+JCw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 15786709793471002.5295500459966; Fri, 10 Jan 2020 07:42:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-mkBrVHQrMuKd8ATYA_wlLw-1; Fri, 10 Jan 2020 10:42:54 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D9EF800D4C; Fri, 10 Jan 2020 15:42:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6766F10016E8; Fri, 10 Jan 2020 15:42:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2A6F081C76; Fri, 10 Jan 2020 15:42:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00AFgmHN022572 for ; Fri, 10 Jan 2020 10:42:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id B0037271BE; Fri, 10 Jan 2020 15:42:48 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 393F619C6A for ; Fri, 10 Jan 2020 15:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670978; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=2oGNkYhqp5RC5hUkE5qDNUUpnY0SV04CHUIONXqBM4k=; b=X81DALyPlBeDbQItRW6AKTCNRHZQ33jkn5iqDL6xD8Xd/Dj7rSNuPVi1h8+8Ra17BFhClD GRr4R3nR45WWpyscw24RRkNUg4hjv/VC5ftIJWw3BdVZLrYukn+7/h+AqJbUlEGC8J4Y1U 0rshYWjB6o9LIoKtSYuX0M+gP3LNHDE= From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 16:42:41 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] virsh: secret: Add 'secret-passwd' command X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: mkBrVHQrMuKd8ATYA_wlLw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add a command which allows to read a secret value from terminal. 'secret-passwd' is chosen as a name as the password has limitations as passwords do have (printable, terminated by newline which is not contained in the value). This makes it way more user-friendly to use the secret driver with virsh when setting a value. Signed-off-by: Peter Krempa --- docs/manpages/virsh.rst | 15 +++++++++ tools/virsh-secret.c | 70 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 6446a903ca..03364684b5 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -6564,6 +6564,21 @@ Set the value associated with *secret* (specified by= its UUID) to the value Base64-encoded value *base64*. +secret-passwd +---------------- + +**Syntax:** + +.. code-block:: + + secret-passwd secret + +Set the value associated with *secret* (specified by its UUID) to a string +read from stdin. Note that input is terminated by a newline and the secret +can't contain non-printable characters. Use *secret-set-value* for generic +secrets. Note that this requires a terminal associated with virsh to read +the password. + secret-get-value ---------------- diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 66369a25dc..9f64be6b14 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -219,6 +219,70 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) return ret; } + +/* + * "secret-passwd" command + */ +static const vshCmdInfo info_secret_passwd[] =3D { + {.name =3D "help", + .data =3D N_("set a secret value from stdin") + }, + {.name =3D "desc", + .data =3D N_("Set a secret value from stdin") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_secret_passwd[] =3D { + {.name =3D "secret", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("secret UUID"), + .completer =3D virshSecretUUIDCompleter, + }, + {.name =3D NULL} +}; + +static bool +cmdSecretPasswd(vshControl *ctl, + const vshCmd *cmd) +{ + virSecretPtr secret; + g_autofree char *value =3D NULL; + int res; + bool ret =3D false; + + if (!ctl->istty) { + vshError(ctl, "%s", _("secret-passwd requires a terminal")); + return false; + } + + if (!(secret =3D virshCommandOptSecret(ctl, cmd, NULL))) + return false; + + vshPrint(ctl, "%s", _("Enter new value for secret:")); + fflush(stdout); + + if (!(value =3D getpass(""))) { + vshError(ctl, "%s", _("Failed to read secret")); + goto cleanup; + } + + res =3D virSecretSetValue(secret, (unsigned char *) value, strlen(valu= e), 0); + + if (res !=3D 0) { + vshError(ctl, "%s", _("Failed to set secret value")); + goto cleanup; + } + vshPrintExtra(ctl, "%s", _("Secret value set\n")); + ret =3D true; + + cleanup: + virSecretFree(secret); + return ret; +} + + /* * "secret-get-value" command */ @@ -805,6 +869,12 @@ const vshCmdDef secretCmds[] =3D { .info =3D info_secret_set_value, .flags =3D 0 }, + {.name =3D "secret-passwd", + .handler =3D cmdSecretPasswd, + .opts =3D opts_secret_passwd, + .info =3D info_secret_passwd, + .flags =3D 0 + }, {.name =3D "secret-undefine", .handler =3D cmdSecretUndefine, .opts =3D opts_secret_undefine, --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list