spring-bootspring-cloud-confighashicorp-vaultspring-cloud-config-server

Spring Cloud Config Server returns extra backslash


I'm writing a secret in Vault similar to secret1=test1\ntest2 and use it inside a Spring Boot application configuration using @Value("${secret1}"). However, upon successful retrieval from Vault via Spring Cloud Config Server the secret1 value is turned into test1**\\n**test1. So an extra backslash is added. It is a very small change that I would need to do in the application to remove that extra backslash, but I'd like to solve this the proper way. How can I prevent this extra backslash addition from happening?


Solution

  • Vault itself will not mess with the \n. Try this at the command line:

    vault kv put secret/new-line secret1="test1\ntest2"
    

    On the wire, it will be sent as this JSON:

    {
      "data":{
        "secret": "test1\\ntest2"
      }
    }
    

    And getting the secret back brings the same value:

    vault kv get --field data secret/new-line 
    map[secret:test1\ntest2]
    

    Your \n is probably interpreted as it is transformed in JSON and sent to Vault. Maybe whatever puts the secret in Vault does not use the same library/technology as your code?

    Make sure that you escape the \n when it is saved in Vault. Getting it will bring back the \n unharmed.