2

I have a YAML file that i want to push it to Vault.

# values.yaml
db:
  username: msql
  pass:  p$$ass

However, vault accepts only key/value pair namely secret engine v2.

 vault kv secret/projects/craft/app-a mykey=value

If I can convert the YAML file into a properties file, i will get the key/value pair automatically. then, I can push its key/value pair .

I can see that the question Convert YAML file to Application.properties will answer my question.

However, the answers suggested some tools, however,it does not support yaml list format.

Also, the question was closed and no more accept answers !!

I've tried other ways , but nothing seems to work.

How can I convert the YAML file to a full key path/value pairs.. which is at the end a properties file.

Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254

2 Answers2

4

Because the original question Convert YAML file to Application.properties has been closed, I will answer here.

Indeed, yq CLI must be enough here :


yq r values.yaml --printMode pv "**" | sed 's/: /=/' > values.properties

explanation:

  • yq r : read yaml file
  • --printMode pv : pv means Path-Value
  • ** : means all key paths.
  • sed 's/: /=/' : if you run it without sed, the delimiter between path and value is : , while we need it to be =. So we need to replace : by = in each line (only the first occurrence)
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
2

Although not exactly what you asked for, you can save the text as base64 and then decode it when you retrieve it, for example

vault kv put secret/foo data=$(base64 < values.yaml )

and then when you retrieve it, base64 decode it, for example

vault kv get -field data secret/foo | base64 -d
user2599522
  • 3,005
  • 2
  • 23
  • 40