From nobody Fri Mar 29 06:31:15 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 --- 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