Spring Cloud Config Server 返回额外的反斜杠

发布于 2025-01-15 04:24:49 字数 312 浏览 3 评论 0原文

我正在 Vault 中编写一个类似于 secret1=test1\ntest2 的机密,并使用 @Value("${secret1}") 在 Spring Boot 应用程序配置中使用它。但是,通过 Spring Cloud Config Server 从 Vault 成功检索后,secret1 值将转换为 test1**\\n**test1。因此添加了一个额外的反斜杠。这是我需要在应用程序中进行的一个非常小的更改,以删除多余的反斜杠,但我想以正确的方式解决这个问题。如何防止这种额外的反斜杠添加发生?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找一个思念的角度 2025-01-22 04:24:49

Vault 本身不会干扰 \n。在命令行尝试此操作:

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

在线路上,它将作为以下 JSON 发送:

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

获取秘密会带来相同的值:

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

您的 \n 可能会被解释为以 JSON 格式转换并发送到避难所。也许将秘密放入 Vault 的任何内容都不会使用与您的代码相同的库/技术?

确保在将 \n 保存到保险柜时对其进行转义。得到它将使 \n 毫发无伤地回来。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文