.. code-block::
- secret-set-value secret (--file filename [--plain] | base64)
+ secret-set-value secret (--file filename [--plain] | --interactive | base64)
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 use
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 from the
+terminal.
+
+Note that *--file*, *--interactive* and *base64* options are mutually exclusive.
Passing secrets via the *base64* option on command line is INSECURE and
deprecated. Use the *--file* option instead.
.type = VSH_OT_BOOL,
.help = N_("read the secret from file without converting from base64")
},
+ {.name = "interactive",
+ .type = VSH_OT_BOOL,
+ .help = N_("read the secret from the terminal")
+ },
{.name = "base64",
.type = VSH_OT_STRING,
.help = N_("base64-encoded secret value")
unsigned char *value;
size_t value_size;
bool plain = vshCommandOptBool(cmd, "plain");
+ bool interactive = 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 = virshCommandOptSecret(ctl, cmd, NULL)))
return false;
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;
}
base64 = file_buf;
}
+ if (interactive) {
+ vshPrint(ctl, "%s", _("Enter new value for secret:"));
+ fflush(stdout);
+
+ if (!(file_buf = getpass(""))) {
+ vshError(ctl, "%s", _("Failed to read secret"));
+ return false;
+ }
+ file_len = strlen(file_buf);
+ plain = true;
+ }
+
if (plain) {
value = g_steal_pointer(&file_buf);
value_size = file_len;