From nobody Sun Feb 8 21:33:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1579882161; cv=none; d=zohomail.com; s=zohoarc; b=eEFYtjMtbcNovrCHZns5BUeh05f5AwEohOQ6YBcLgvy2AO+iV2QpGw2s2EZ6caVwY5Se1Im7plZLaZWmPgbRy2rAsLVsnjp2n6QdAqCD+98y5/+x1nX3ItKsX6d++bSTNuUwqEsjUEkMzVQGic2tSt32t/uNQzBg2SVnx7v2CX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579882161; 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=1cirRJjppfiAolYQvNUZ5bi8Rm1N0s3DLjsneNn8F3E=; b=f2OAoI4+lWITLi/HsbG5/DRjMPfIcJqknS5zWoz+dVhcgLdMf7T+UJAhoZ3S2ArEM1KlfQClYhWcq2J7uG+lxoMoXq11wG8EYhOquxpIf0M5HVFXbuT5LMFWbf2DSz8wFM4z7vTIAh+b8c+A0b9nsvKsVR7OxHH+W5ulAnahkYM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1579882161796417.64647966674306; Fri, 24 Jan 2020 08:09:21 -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-177-HImGPv-zOzaKrZJPSbXNLA-1; Fri, 24 Jan 2020 11:09:18 -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 7F79718C35C3; Fri, 24 Jan 2020 16:09:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 592EE10016EB; Fri, 24 Jan 2020 16:09:12 +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 107001803C33; Fri, 24 Jan 2020 16:09:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00OG9AJq011986 for ; Fri, 24 Jan 2020 11:09:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 106B25C298; Fri, 24 Jan 2020 16:09:10 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C8745C241 for ; Fri, 24 Jan 2020 16:09:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579882160; 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=1cirRJjppfiAolYQvNUZ5bi8Rm1N0s3DLjsneNn8F3E=; b=UUK8u9zQDsRdT7b5Mf4pfRwPeVl3ko/YZEsWdSZHwlNP+4aPuzbsx3j3YnY+j2IEQOIwGM JMBhgiyjuSVoVCP8tQ1ejQCUvN6127XKdw9AJfBy1cSoEaw110Itu6VF/J1iSRmVRn1nyY 8b/09DjuJg09mDIseAivahnp6Zjz6Qk= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 8/9] tools: virsh: Add --interactive flag for secret-set-value command Date: Fri, 24 Jan 2020 17:08:40 +0100 Message-Id: <1053df3df381a846de1525dfb80f144ad5ccffce.1579881978.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: HImGPv-zOzaKrZJPSbXNLA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Simplify human usage of secret-set-value by adding --interactive which will read the value of the secret from the terminal. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/manpages/virsh.rst | 7 +++++-- tools/virsh-secret.c | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index dbeac9232f..8841ae1b31 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -6563,14 +6563,17 @@ secret-set-value .. code-block:: - secret-set-value secret (--file filename [--plain] | base64) + secret-set-value secret (--file filename [--plain] | --interactive | ba= se64) Set the value associated with *secret* (specified by its UUID) to the value Base64-encoded value *base64* or Base-64-encoded contents of file named *filename*. Using the *--plain* flag is together with *--file* allows to u= se the file contents directly as the secret value. -Note that *--file* and *base64* options are mutually exclusive. +If *--interactive* flag is used the secret value is read as a password fro= m the +terminal. + +Note that *--file*, *--interactive* and *base64* options are mutually excl= usive. Passing secrets via the *base64* option on command line is INSECURE and deprecated. Use the *--file* option instead. diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 87f3cfff16..00a434e997 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -186,6 +186,10 @@ static const vshCmdOptDef opts_secret_set_value[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("read the secret from file without converting from base6= 4") }, + {.name =3D "interactive", + .type =3D VSH_OT_BOOL, + .help =3D N_("read the secret from the terminal") + }, {.name =3D "base64", .type =3D VSH_OT_STRING, .help =3D N_("base64-encoded secret value") @@ -204,10 +208,14 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) unsigned char *value; size_t value_size; bool plain =3D vshCommandOptBool(cmd, "plain"); + bool interactive =3D vshCommandOptBool(cmd, "interactive"); int res; VSH_EXCLUSIVE_OPTIONS("file", "base64"); VSH_EXCLUSIVE_OPTIONS("plain", "base64"); + VSH_EXCLUSIVE_OPTIONS("interactive", "base64"); + VSH_EXCLUSIVE_OPTIONS("interactive", "plain"); + VSH_EXCLUSIVE_OPTIONS("interactive", "file"); if (!(secret =3D virshCommandOptSecret(ctl, cmd, NULL))) return false; @@ -218,7 +226,7 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &filename) < 0) return false; - if (!base64 && !filename) { + if (!base64 && !filename && !interactive) { vshError(ctl, _("Input secret value is missing")); return false; } @@ -238,6 +246,18 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) base64 =3D file_buf; } + if (interactive) { + vshPrint(ctl, "%s", _("Enter new value for secret:")); + fflush(stdout); + + if (!(file_buf =3D getpass(""))) { + vshError(ctl, "%s", _("Failed to read secret")); + return false; + } + file_len =3D strlen(file_buf); + plain =3D true; + } + if (plain) { value =3D g_steal_pointer(&file_buf); value_size =3D file_len; --=20 2.24.1