Parameter 'secret_name' must conform to the following pattern: '^[0-9a-zA-Z-]+$'

Vinod Malli 20 Reputation points
2023-03-24T13:30:13.4933333+00:00

Hello,

I am getting the below error when I tried to run a simple for loop (bash script) to upload key/value pairs into azure keyvault. Can someone help me to resolve the error?

Error:

Parameter 'secret_name' must conform to the following pattern: '^[0-9a-zA-Z-]+$'

key/value file:

cat 1.txt

"d4c45726-f2db-48d0-8363-b7806895ba9f" "99ahijkbdjnmscjruivAKJBHIKDJNEJK"

"6568f27c-da2c-418c-a3bc-75086d37228b" "199abdjnmscscjruiabcdKDJNEJK"

"549a6c49-3969-40d5-8a85-18b285fc474e" "DRh4JHQZ/BwoadIPHD1asasAA4qabcd0qKrmI5sTYu8="

"8dff7280-d079-4d97-81d1-6ad88e149dc0" "Znl8ZfAAArFabcdycM0XYgaJOh39yQRtYj7+t6X8="

"5b849093-a159-4801-9b73-1e645c31ccaf" "0zaJLL/Qqzabcdhy9sRM6brW8DM5hz2wQbqxDsa/xfRVRQQ="

Bash Script: (Failing)

cat 1.txt | while read line
do 
	echo "$line"
	key=`echo $line | cut -d " " -f 1`
	value=`echo $line | cut -d " " -f 2`
	echo $key
	echo $value

	az keyvault secret set --vault-name "test-kv-csv" --name $key --value $value
done

If I use same key value pairs manually (one by one) with az keyvault command (on Linux terminal or az cli) then it works.

Manually: (Worked)
az keyvault secret set --vault-name "test-kv-csv" --name "549a6c49-3969-40d5-8a85-18b285fc474e" --value "DRh4JHQZ/BwoadIPHD1asasAA4qabcd0qKrmI5sTYu8="

az keyvault secret set --vault-name "test-kv-csv" --name "d4c45726-f2db-48d0-8363-b7806895ba9f" --value "99ahijkbdjnmscjruivAKJBHIKDJNEJK"

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,451 questions
{count} votes

Accepted answer
  1. JamesTran-MSFT 36,911 Reputation points Microsoft Employee Moderator
    2023-03-24T20:09:20.1966667+00:00

    @Vinod Malli

    Thank you for your post!

    Error Message:

    Parameter 'secret_name' must conform to the following pattern: '^[0-9a-zA-Z-]+$'

    I understand that you're trying to upload Key-Value pairs into the Azure Key Vault but you're running into the above error message. When manually uploading these Key-Value pairs one-by-one everything works as expected when using the az keyvault secret set command, but the issue comes when you try to run your Bash Script.

    I was able to reproduce your issue within my environment and it looks like the Secret Name is being created with the quotes ("d4c45726...."). However, after removing the quotes within the TXT, I was able to create all of the Key Value pairs you referenced except for 5b849093...

    User's image

    I hope this helps!

    If you have any other questions, please let me know. Thank you for your time and patience throughout this issue.


    If the information helped address your question, please Accept the answer. This will help us and also improve searchability for others in the community who might be researching similar information.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.