From nobody Thu Apr 18 01:22:08 2024 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 Reviewed-by: Daniel Henrique Barboza --- 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 From nobody Thu Apr 18 01:22:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1578670988; cv=none; d=zohomail.com; s=zohoarc; b=iG+9R4XhvVRw8lx52Av6dOB3SbXUGssZaOwdRqmPY5G1kYzE622z6deDxrudo6xfp9Gs5BcdRpvGqOa9FV7v4Q9U917rUWZDTsmOJCGtlVzQnhSIHFRnHYd/cgYQ+RxNVbjfoLNIuIGDdAB+vRbYGw1ai5eOfkZln4lZ4K6IMN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670988; 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=SMNYzjxF0E+PjsoOYeEV/71bv9DLEKVRxpUaxadlkhQ=; b=K1jjHEzvqIPgICi6ZsiuQt6Z+MxJAGasuLhWuZ1kc5/8fApgVyDwl6JiEDPQrXms1YQd7gv71j3hI5j1bbqIGMJgJpPe29p6z61J5GVplQPdGuBndkoEJtHLw7ZHNujk7oiQS0z4CThPi8qhGOdCFvKfIAyrx8dfpERjDteNgpk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1578670988645271.4616737339053; Fri, 10 Jan 2020 07:43:08 -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-170-Xm11dey0NduqvvZ0qOavIw-1; Fri, 10 Jan 2020 10:43:05 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB9ED800D5E; Fri, 10 Jan 2020 15:42:53 +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 98A4886CD0; Fri, 10 Jan 2020 15:42:53 +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 4F2E081C7C; Fri, 10 Jan 2020 15:42:53 +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 00AFgnJJ022580 for ; Fri, 10 Jan 2020 10:42:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 808C6271BE; Fri, 10 Jan 2020 15:42:49 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09C1B19C6A 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=1578670987; 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=SMNYzjxF0E+PjsoOYeEV/71bv9DLEKVRxpUaxadlkhQ=; b=ECyM2a7xq8ytdZ3vqQ2nyq0pcyFxScXEGxnuXOo9ji8xIh4tSVqisAaMtgY4oBVbAWnWVZ gtGsw42G9VkJ8xYjdlhCTrgNZGthY0gUjm2eGqOr29x++y5v7JhDEQCnpxsuBnbjHPveSO zBzxQKG8+GfMcEplzKt6MV60V6aDtBo= From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 16:42:42 +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 2/4] virsh: secret: Allow getting secret's value without base64 encoding 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.79 on 10.5.11.13 X-MC-Unique: Xm11dey0NduqvvZ0qOavIw-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" Users might want to get the raw value instead of dealing with base64 encoding. This might be useful for redirection to file and also for simple human-readable secrets. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/manpages/virsh.rst | 6 +++++- tools/virsh-secret.c | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 03364684b5..fcc8ef6758 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -6586,11 +6586,15 @@ secret-get-value .. code-block:: - secret-get-value secret + secret-get-value [--plain] secret Output the value associated with *secret* (specified by its UUID) to stdou= t, encoded using Base64. +If the *--plain* flag is used the value is not base64 encoded, but rather +printed raw. Note that unless virsh is started in quiet mode (*virsh -q*) = it +prints a newline at the end of the command. This newline is not part of the +secret. secret-undefine --------------- diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 9f64be6b14..6d95ed9d5d 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -303,6 +303,10 @@ static const vshCmdOptDef opts_secret_get_value[] =3D { .help =3D N_("secret UUID"), .completer =3D virshSecretUUIDCompleter, }, + {.name =3D "plain", + .type =3D VSH_OT_BOOL, + .help =3D N_("get value without converting to base64") + }, {.name =3D NULL} }; @@ -313,6 +317,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd) VIR_AUTODISPOSE_STR base64 =3D NULL; unsigned char *value; size_t value_size; + bool plain =3D vshCommandOptBool(cmd, "plain"); bool ret =3D false; secret =3D virshCommandOptSecret(ctl, cmd, NULL); @@ -323,9 +328,16 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd) if (value =3D=3D NULL) goto cleanup; - base64 =3D g_base64_encode(value, value_size); + if (plain) { + if (fwrite(value, 1, value_size, stdout) !=3D value_size) { + vshError(ctl, "failed to write secret"); + goto cleanup; + } + } else { + base64 =3D g_base64_encode(value, value_size); - vshPrint(ctl, "%s", base64); + vshPrint(ctl, "%s", base64); + } ret =3D true; cleanup: --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 01:22:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1578670989; cv=none; d=zohomail.com; s=zohoarc; b=cbQM2fqQ2m0qPg9gGETDjGi4U3J+qQJyq/Tyg09psWi+dOHrqPA2U5fSYNZkCStCsluPQU7Zqgh4aTeTXidnR3464wjbRoEdf8lt2MmKIlDa1xUrSKFj4Blv8CaKnEZqBwn9cZ6d512IfSJ399uhH4+Nnyqiz0kXRS8rkaiVQUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670989; 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=DIfXnnGQ1YZGuai/xarfVQUdfiqjS2MgcR5LpGQBVIg=; b=HNIJFhoBnlWlt5P1f6xEGyusEItvDqmNAKF8xaIHaAkHCNNga1Xiz52VSN3500lwVYzDR3GuETQZNDBCIxyeRPyzKFPxjinA7fIyh0a+lsG/HNlCZXh/zCtYsxlnCK9MoDIsjxaWR53rpIqSmdsYMytTM1+MSPsHYm6JxMihxeE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1578670989143724.4979594670956; Fri, 10 Jan 2020 07:43:09 -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-194-ON-oZKHkN8Cgg2llmjo1kA-1; Fri, 10 Jan 2020 10:43:05 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 733721005514; Fri, 10 Jan 2020 15:42:53 +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 475FA272C4; Fri, 10 Jan 2020 15:42:53 +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 EB4C218034ED; Fri, 10 Jan 2020 15:42:52 +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 00AFgo7D022596 for ; Fri, 10 Jan 2020 10:42:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 519F919C6A; Fri, 10 Jan 2020 15:42:50 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF418272A7 for ; Fri, 10 Jan 2020 15:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670988; 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=DIfXnnGQ1YZGuai/xarfVQUdfiqjS2MgcR5LpGQBVIg=; b=QUjEKgJiFXV5WOvzlFnhFzs7vVQWsPRausCa1qB7oC9Pgyb+ERlcwSIGTqzeQscAScNyhn +2+wF3Cf2Te6DYaqQBIizTS9ZH5/rQ9jw9Te7b0iRnP15+UC6LCH17+HRy4HG2aSozs43x Krq8cRtk6l2SvNOb3UdV3svH18suLK4= From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 16:42:43 +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 3/4] virsh: secret: Allow setting secrets from file 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.23 X-MC-Unique: ON-oZKHkN8Cgg2llmjo1kA-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" The necessity to specify the secret value as command argument is insecure. Allow reading the secret from a file. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- docs/manpages/virsh.rst | 5 +++-- tools/virsh-secret.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index fcc8ef6758..992b1daf90 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -6558,10 +6558,11 @@ secret-set-value .. code-block:: - secret-set-value secret base64 + secret-set-value secret (--file filename | base64) Set the value associated with *secret* (specified by its UUID) to the value -Base64-encoded value *base64*. +Base64-encoded value *base64* or from file named *filename*. Note that *--= file* +and *base64* options are mutually exclusive. secret-passwd diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 6d95ed9d5d..dd6bf75705 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -177,9 +177,13 @@ static const vshCmdOptDef opts_secret_set_value[] =3D { .help =3D N_("secret UUID"), .completer =3D virshSecretUUIDCompleter, }, + {.name =3D "file", + .type =3D VSH_OT_STRING, + .flags =3D VSH_OFLAG_REQ_OPT, + .help =3D N_("read secret from file"), + }, {.name =3D "base64", - .type =3D VSH_OT_DATA, - .flags =3D VSH_OFLAG_REQ, + .type =3D VSH_OT_STRING, .help =3D N_("base64-encoded secret value") }, {.name =3D NULL} @@ -191,17 +195,37 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd) virSecretPtr secret; size_t value_size; const char *base64 =3D NULL; + const char *filename =3D NULL; unsigned char *value; int res; bool ret =3D false; + VSH_EXCLUSIVE_OPTIONS("file", "base64"); + if (!(secret =3D virshCommandOptSecret(ctl, cmd, NULL))) return false; if (vshCommandOptStringReq(ctl, cmd, "base64", &base64) < 0) goto cleanup; - value =3D g_base64_decode(base64, &value_size); + if (vshCommandOptStringReq(ctl, cmd, "file", &filename) < 0) + goto cleanup; + + if (!base64 && !filename) { + vshError(ctl, _("Input secret value is missing")); + goto cleanup; + } + + if (filename) { + ssize_t read_len; + if ((read_len =3D virFileReadAll(filename, 1024, (char **) &value)= ) < 0) { + vshSaveLibvirtError(); + goto cleanup; + } + value_size =3D read_len; + } else { + value =3D g_base64_decode(base64, &value_size); + } res =3D virSecretSetValue(secret, value, value_size, 0); memset(value, 0, value_size); --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 01:22:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.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 205.139.110.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=1578670991; cv=none; d=zohomail.com; s=zohoarc; b=KrgqcXd3xO3l55r1QFNi/FzOCx3OvEpR3ZK2M6ezHp5ZUQj65wm3i1wuk/i8q74wV0mCjs1g53mTjgjhNWT4K4W2J/kU5jX1xd0TIa+LJMW7N2edHSSiGrkoHrDqbdWKRpl9NqUbQOfyIL8lzgZZjBURGlnF1IZ8ZKaa8KXQedY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670991; 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=49uvL3BGtUY75bSJEYpSUHN33kD7ViGj/kqrxWATYJw=; b=V7+qbmSd0J+72QFEpoFxtl4uWPjy1SZIbU6Hk6GshFMcEE3xDQnfRUxNRkztgvlXfzv5qSKZZtyLAghH6adR0ZSADAtraT4C3J669nQh6LgcbVNUKSCYALCNU2fHxhBn+lAbIAJsgqvmUgWK6gb7MrXSp0pnRYRi3Rilo6gM4f0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.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 [205.139.110.120]) by mx.zohomail.com with SMTPS id 1578670991813682.84404580066; Fri, 10 Jan 2020 07:43:11 -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-218-EJV58w2hPcq-dAF27-kBrQ-1; Fri, 10 Jan 2020 10:43:08 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 126EE593A8; Fri, 10 Jan 2020 15:42:57 +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 DF1B35C296; Fri, 10 Jan 2020 15:42:56 +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 9D34A81C8B; Fri, 10 Jan 2020 15:42:56 +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 00AFgpma022603 for ; Fri, 10 Jan 2020 10:42:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 234C7271BE; Fri, 10 Jan 2020 15:42:51 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id A066C19C6A for ; Fri, 10 Jan 2020 15:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670990; 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=49uvL3BGtUY75bSJEYpSUHN33kD7ViGj/kqrxWATYJw=; b=Tw7biVeSQl/rIn+t/tf0WOIAkovLKESA/ggeOLeWMxZ9b8erkwgrBQyGqbLX7mlHVmjyGe SOHWhLR09ShLCovPiG1CquJw98a8Y9l0AtQ0qStlaxy7NrhvuGdcHerjOBCG3VTyXZhL/3 AXfWZ+0s2GpuW0lKN7a7LFld6QnsnC4= From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 16:42:44 +0100 Message-Id: <39fea525d036e219cab39be089744c9a82938870.1578670887.git.pkrempa@redhat.com> 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 4/4] docs: secret: Unify and sanitize examples on how to set secret value 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.79 on 10.5.11.16 X-MC-Unique: EJV58w2hPcq-dAF27-kBrQ-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" Discourage passing secrets as commandline arguments. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- docs/formatsecret.html.in | 86 +++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/docs/formatsecret.html.in b/docs/formatsecret.html.in index 8f5383cf64..61a8396682 100644 --- a/docs/formatsecret.html.in +++ b/docs/formatsecret.html.in @@ -76,13 +76,13 @@
 # virsh secret-define volume-secret.xml
 Secret 0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f created
-#
-# MYSECRET=3D`printf %s "open sesame" | base64`
-# virsh secret-set-value 0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f $MYSECRET
-Secret value set
-#
     
+

+ See virsh secret-set-value on how + to set the value of the secret. +

+

The volume type secret can be supplied either in volume XML during creation of a storage volu= me @@ -103,12 +103,11 @@ Secret value set # virsh secret-define luks-secret.xml Secret f52a81b2-424e-490c-823d-6bd4235bc57 created -# -# MYSECRET=3D`printf %s "letmein" | base64` -# virsh secret-set-value f52a81b2-424e-490c-823d-6bd4235bc57 $MYSECRET -Secret value set -# +

+ See virsh secret-set-value on how + to set the value of the secret. +

The volume type secret can be supplied in domain XML for a luks stor= age @@ -156,13 +155,11 @@ Secret 1b40a534-8301-45d5-b1aa-11894ebb1735 created UUID Usage ----------------------------------------------------------- 1b40a534-8301-45d5-b1aa-11894ebb1735 cephx ceph_example -# -# CEPHPHRASE=3D`printf %s "pass phrase" | base64` -# virsh secret-set-value 1b40a534-8301-45d5-b1aa-11894ebb1735 $CEPHPHRASE -Secret value set - -# +

+ See virsh secret-set-value on how + to set the value of the secret. +

The ceph secret can then be used by UUID or by the @@ -229,7 +226,9 @@ incominguser myname mysecret

Next, use virsh secret-define iscsi-secret.xml to define - the secret and virsh secret-set-value using the generat= ed + the secret and + virsh secret-set-value + using the generated UUID value and a base64 generated secret value in order to define the chosen secret pass phrase. The pass phrase must match the password used in the iSCSI authentication configuration file. @@ -243,12 +242,13 @@ Secret c4dbe20b-b1a3-4ac1-b6e6-2ac97852ebb6 created ----------------------------------------------------------- c4dbe20b-b1a3-4ac1-b6e6-2ac97852ebb6 iscsi libvirtiscsi -# MYSECRET=3D`printf %s "mysecret" | base64` -# virsh secret-set-value c4dbe20b-b1a3-4ac1-b6e6-2ac97852ebb6 $MYSECRET -Secret value set -# +

+ See virsh secret-set-value on how + to set the value of the secret. +

+

The iSCSI secret can then be used by UUID or by the usage name via the <auth> element in a domain's @@ -313,19 +313,13 @@ Secret 718c71bd-67b5-4a2b-87ec-a24e8ca200dc created Once the secret is defined, a secret value will need to be set. The secret would be the passphrase used to access the TLS credentials. The following is a simple example of using - virsh secret-set-value to set the secret value. The + virsh secret-set-value = to set + the secret value. The virSecretSetValue API may also be used to set a more secure secret without using printable/readable characters.

-
-# MYSECRET=3D`printf %s "letmein" | base64`
-# virsh secret-set-value 718c71bd-67b5-4a2b-87ec-a24e8ca200dc $MYSECRET
-Secret value set
-
-    
-

Usage type "vtpm"

@@ -370,17 +364,47 @@ Secret 6dd3e4a5-1d76-44ce-961f-f119f5aad935 created Once the secret is defined, a secret value will need to be set. The secret would be the passphrase used to decrypt the vTPM state. The following is a simple example of using - virsh secret-set-value to set the secret value. The + virsh secret-set-value + to set the secret value. The virSecretSetValue API may also be used to set a more secure secret without using printable/readable characters.

+

Setting secret values in virsh

+ +

+ To set the value of the secret you can use the following virsh comma= nds. + If the secret is a password-like string (printable characters, no ne= wline) + you can use: +

+
+# virsh secret-passwd 6dd3e4a5-1d76-44ce-961f-f119f5aad935
+Enter new value for secret:
+Secret value set
+    
+ +

+ Another secure option is to read the secret from a file. This way the + secret can contain any bytes (even NUL and non-printable characters)= . The + length of the secret is the length of the input file. +

+ +
+# virsh secret-set-value 6dd3e4a5-1d76-44ce-961f-f119f5aad935 --file secre=
tinfile
+Secret value set
+    
+ +

+ The secret can also be set via an argument, but note that other users + may see it in the process listing output. The secret must be base64 + encoded. +

+
 # MYSECRET=3D`printf %s "open sesame" | base64`
 # virsh secret-set-value 6dd3e4a5-1d76-44ce-961f-f119f5aad935 $MYSECRET
 Secret value set
-
     
--=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list