Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't escape \n in secret dump #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vukor
Copy link

@vukor vukor commented Oct 4, 2022

Special symbols like \n are double escaped and secret value with newlines is not identical after restoration.

How to reproduce:

  1. create secret
vault write /secret/ssh-key key='-----BEGIN OPENSSH PRIVATE KEY-----
secret
-----END OPENSSH PRIVATE KEY-----
'
  1. get secret
$ vault kv get -format=json  /secret/ssh-key
{
  "renewable": false,
  "data": {
    "key": "-----BEGIN OPENSSH PRIVATE KEY-----\nsecret\n-----END OPENSSH PRIVATE KEY-----\n"
  },
  "warnings": null
}
  1. dump secret by vault-backup
$ TOP_VAULT_PREFIX=/secret/ssh-key/ python vault-dump.py                                                                                                                                                                               
#
# vault-dump.py backup
# dump made by vukor
# TOP_VAULT_PREFIX env variable: /secret/ssh-key/
# STDIN encoding: utf-8
# STDOUT encoding: utf-8
#
# WARNING: not guaranteed to be consistent!
#
vault write /secret/ssh-key key='-----BEGIN OPENSSH PRIVATE KEY-----\nsecret\n-----END OPENSSH PRIVATE KEY-----\n'
  1. restore secret
$ vault write /secret/ssh-key key='-----BEGIN OPENSSH PRIVATE KEY-----\nsecret\n-----END OPENSSH PRIVATE KEY-----\n'
Success! Data written to: secret/ssh-key
  1. get secret
$ vault kv get -format=json  /secret/ssh-key
{
  "renewable": false,
  "data": {
    "key": "-----BEGIN OPENSSH PRIVATE KEY-----\\nsecret\\n-----END OPENSSH PRIVATE KEY-----\\n"
  },
  "warnings": null
}

As you see it prints \\n. So in my use case, I've got the file with an incorrect SSH private key format.

@vukor vukor closed this Oct 4, 2022
@vukor vukor reopened this Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant