Spring Cloud Vault快速入門

2024-01-03 17:35 更新

先決條件

要開始使用Vault和本指南,您需要一個類似* NIX的操作系統(tǒng),該操作系統(tǒng)提供:

  • wget,opensslunzip
  • 至少Java 7和正確配置的JAVA_HOME環(huán)境變量

安裝Vault

$ src/test/bash/install_vault.sh

為Vault創(chuàng)建SSL證書

$ src/test/bash/create_certificates.sh

create_certificates.shwork/ca和JKS信任庫work/keystore.jks中創(chuàng)建證書。如果要使用此快速入門指南運行Spring Cloud Vault,則需要將信任庫的spring.cloud.vault.ssl.trust-store屬性配置為file:work/keystore.jks。

啟動Vault服務(wù)器

$ src/test/bash/local_run_vault.sh

Vault開始使用inmem存儲和https0.0.0.0:8200上偵聽。Vault被密封并且在啟動時未初始化。

 如果要運行測試,請保留Vault未初始化。測試將初始化Vault并創(chuàng)建根令牌00000000-0000-0000-0000-000000000000

如果要對應(yīng)用程序使用Vault或嘗試使用它,則需要首先對其進行初始化。

$ export VAULT_ADDR="https://localhost:8200"
$ export VAULT_SKIP_VERIFY=true # Don't do this for production
$ vault init

您應(yīng)該看到類似以下內(nèi)容:

Key 1: 7149c6a2e16b8833f6eb1e76df03e47f6113a3288b3093faf5033d44f0e70fe701
Key 2: 901c534c7988c18c20435a85213c683bdcf0efcd82e38e2893779f152978c18c02
Key 3: 03ff3948575b1165a20c20ee7c3e6edf04f4cdbe0e82dbff5be49c63f98bc03a03
Key 4: 216ae5cc3ddaf93ceb8e1d15bb9fc3176653f5b738f5f3d1ee00cd7dccbe926e04
Key 5: b2898fc8130929d569c1677ee69dc5f3be57d7c4b494a6062693ce0b1c4d93d805
Initial Root Token: 19aefa97-cccc-bbbb-aaaa-225940e63d76

Vault initialized with 5 keys and a key threshold of 3. Please
securely distribute the above keys. When the Vault is re-sealed,
restarted, or stopped, you must provide at least 3 of these keys
to unseal it again.

Vault does not store the master key. Without at least 3 keys,
your Vault will remain permanently sealed.

Vault將初始化并返回一組啟封密鑰和根令牌。選擇3個鍵并解開Vault。將Vault令牌存儲在VAULT_TOKEN環(huán)境變量中。

$ vault unseal (Key 1)
$ vault unseal (Key 2)
$ vault unseal (Key 3)
$ export VAULT_TOKEN=(Root token)
# Required to run Spring Cloud Vault tests after manual initialization
$ vault token-create -id="00000000-0000-0000-0000-000000000000" -policy="root"

Spring Cloud Vault訪問不同的資源。默認(rèn)情況下,啟用秘密后端,該后端通過JSON端點訪問秘密配置設(shè)置。

HTTP服務(wù)具有以下形式的資源:

/secret/{application}/{profile}
/secret/{application}
/secret/{defaultContext}/{profile}
/secret/{defaultContext}

如果將“應(yīng)用程序”作為spring.application.name插入SpringApplication中(即常規(guī)Spring Boot應(yīng)用程序中通常是“應(yīng)用程序”),則“配置文件”是有效的配置文件(或逗號分隔的列表)屬性)。從Vault中檢索到的Properties將按原樣使用,而無需進一步添加屬性名稱的前綴。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號