Skip to content

az keyvault secret set with --value fails when the secret starts with a dash #16044

Description

@christianfosli

Describe the bug

Running az keyvault secret set, passing the secret with --value fails when the secret starts with a dash (-).
It gives the error ArgumentUsageError: argument --value: expected one argument

Running with the --debug option shows that the secret value is interpreted as another argument. For example, passing --value '-secretvalue' shows a few interesting pointers:

Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7fe759214620>]
az_command_data_logger : command args: keyvault secret set -n {} --value -s{} --vault-name {} --debug
# <a few lines omitted>
Event: CommandInvoker.OnPreParseArgs []
"-s" is an invalid parameter for command "keyvault secret set".
# < a few lines omitted>
cli.azure.cli.core.azclierror : ArgumentParseError: argument --value: expected one argument
ArgumentParseError: argument --value: expected one argument

To Reproduce

Given that I have a keyvault named "mykeyvault":

az keyvault secret set -n mysecret --value '-secret' --vault-name mykeyvault

Expected behavior

A secret will be set/created with the value "-secret"

Environment summary

azure-cli 2.14.2 run with docker run -it mcr.microsoft.com/azure-cli

Additional context

I experimented with wrapping the secret in single and double quotes, but that makes no difference.
I also tried to escape the - with a \, but that causes the backslash to be a part of the secret itself, so it doesn't work.

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions