Spring boot读书笔记一如何在Vault中创立secret

方法一(通过curl命令进行设置):
curl -H "X-Vault-Token: 你的token" -H "Content-Type: application/json" -X POST -d "{"data":{"keystore":"p@ssw0rd"}}" http://localhost:8200/v1/secret/data/你的应用名称

方法二(通过Vault-Dashbord手动进行设置):
先查看secret是否存在:

  1. Open Vault Dashboard
    Navigate to: http://127.0.0.1:8200
  2. Login with Token
    Click "Token" method
    Enter your token: 你的token
    Click "Sign In"
  3. Navigate to Secrets Engine
    Click on "secret/" (KV v2 secrets engine)
    This is where your application secrets are stored
  4. Find the coursetracker Secret
    Look for a secret named 你的应用名称
    Click on it to view the contents
  5. View the Keystore Password
    Inside the coursetracker secret, you should see:
    Key: keystore, Value: p@ssw0rd

若secret不存在, 手动设置:
In the secret/ engine, click "Create secret"
Set Path: coursetracker
Add Key-Value pair:
Key: keystore,Value: p@ssw0rd
Click "Save"
Verify in Your Application:
Your application.properties references this secret with:

spring.config.import=vault://secret/你的应用名称
server.ssl.key-store-password=${keystore}

properties
The ${keystore} placeholder will be replaced with the value from Vault (p@ssw0rd).

Note: The secret path in Vault is secret/coursetracker and your application will automatically fetch the keystore key from this secret during startup.

posted @ 2026-02-01 23:37  kkbln  阅读(2)  评论(0)    收藏  举报