Vault的transit secrets engine是用來做資料加解密的功能, Vault本身不儲存加解密前後的資料,可以把它視為一個加解密的服務。
$ vault secrets enable -path=abc-transit transit
Success! Enabled the transit secrets engine at: abc-transit/
$ vault write -f abc-transit/keys/passwd
Success! Data written to: abc-transit/keys/passwd
再加密之前要把資料轉成base64,才能進行加密,加密後會看到有一個key_version
,沒錯當你換key的時候,這個"vault:v1"的前綴會讓vault知道要用v1的key來解密。
$ vault write abc-transit/encrypt/passwd plaintext=$(base64 <<< "This isn't password.")
Key Value
--- -----
ciphertext vault:v1:5hSALtNUt7KbhxX0kgpDEoFbCkxdIgdrBXGtqCPP17yxQ6aXlptWJiiskZji+MRAdQ==
key_version 1
$ vault write abc-transit/decrypt/passwd ciphertext=vault:v1:5hSALtNUt7KbhxX0kgpDEoFbCkxdIgdrBXGtqCPP17yxQ6aXlptWJiiskZji+MRAdQ==
Key Value
--- -----
plaintext VGhpcyBpc24ndCBwYXNzd29yZC4K
別忘了要再base64解密回來
$ base64 --decode <<< "VGhpcyBpc24ndCBwYXNzd29yZC4K"
This isn't password.
以上是加解密的示範,如果要程式化,可以使用Vault HTTP API.