Spring Cloud Vault快速入门
先决条件
要开始使用Vault和本指南,您需要一个类似* NIX的操作系统,该操作系统提供:
wget,openssl和unzip- 至少Java 7和正确配置的
JAVA_HOME环境变量
安装Vault
$ src/test/bash/install_vault.sh为Vault创建SSL证书
$ src/test/bash/create_certificates.sh
create_certificates.sh在work/ca和JKS信任库work/keystore.jks中创建证书。如果要使用此快速入门指南运行Spring Cloud Vault,则需要将信任库的spring.cloud.vault.ssl.trust-store属性配置为file:work/keystore.jks。
$ src/test/bash/local_run_vault.shVault开始使用inmem存储和https在0.0.0.0:8200上侦听。Vault被密封并且在启动时未初始化。
如果要运行测试,请保留Vault未初始化。测试将初始化Vault并创建根令牌
00000000-0000-0000-0000-000000000000。
如果要对应用程序使用Vault或尝试使用它,则需要首先对其进行初始化。
$ export VAULT_ADDR="https://localhost:8200" $ export VAULT_SKIP_VERIFY=true # Don't do this for production $ vault init
您应该看到类似以下内容:
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环境变量中。
$ 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访问不同的资源。默认情况下,启用秘密后端,该后端通过JSON端点访问秘密配置设置。
HTTP服务具有以下形式的资源:
/secret/{application}/{profile}
/secret/{application}
/secret/{defaultContext}/{profile}
/secret/{defaultContext}如果将“应用程序”作为spring.application.name插入SpringApplication中(即常规Spring Boot应用程序中通常是“应用程序”),则“配置文件”是有效的配置文件(或逗号分隔的列表)属性)。从Vault中检索到的Properties将按原样使用,而无需进一步添加属性名称的前缀。