hashicorp-vault

Hashicorp vault - export key from one vault, import into another vault


I'd like to export a key from one vault, and import it into another vault.

It feels there should be an easy way to do this from the command line, but I don't see an abstract simple way to do it, to fully export, then import a key.

Is there anyway to do this? I would prefer command line solutions, using the vault script.


Solution

  • The only way to do that is by chaining two vault commands, which is effectively reading the value out of the first vault and then writing it to the second one. For example:

    export VAULT_TOKEN=valid-token-for1
    export VAULT_ADDR=https://vault1
    JSON_DATA=$(vault kv get -format json -field data secret/foo)
    
    export VAULT_TOKEN=valid-token-for2
    export VAULT_ADDR=https://vault2
    echo $JSON_DATA | vault kv put secret/foo -