jhaals / ansible-vault

ansible lookup plugin for secrets stored in Vault(by HashiCorp)
BSD 3-Clause "New" or "Revised" License
347 stars 65 forks source link

Error when ~/.vault-token has a newline #32

Closed xiongchiamiov closed 7 years ago

xiongchiamiov commented 7 years ago

vault auth puts a token in ~/.vault-token, with no newline. However, if you change the token manually, it's easy to add a newline at the end (echo does this by default, as do most text editors).

The vault cli handles this gracefully, but ansible-vault sends the entire contents of the file along, including the newline, producing errors like this one:

fatal: [localhost]: FAILED! => {
    "failed": true, 
    "msg": "An unhandled exception occurred while running the lookup plugin 'vault'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Unable to read secret/hello from vault: Invalid header value '<my token here>\\n'"
}

It would be great if ansible-vault just did a strip() on the data it reads in.