93. 快速入门

****的先决条件

要开始使用 Vault 和本指南,您需要一个* NIX-like 操作系统,它提供:

  • wgetopensslunzip

  • 至少 Java 7 和正确配置的JAVA_HOME环境变量

安装 Vault

$ src/test/bash/install_vault.sh

为 Vault创建 SSL 证书

$ src/test/bash/create_certificates.sh

create_certificates.shwork/ca和 JKS 信任库work/keystore.jks中创建证书。如果您想使用此快速入门指南 run Spring Cloud Vault,则需要将spring.cloud.vault.ssl.trust-store property 配置为file:work/keystore.jks


启动 Vault 服务器

$ src/test/bash/local_run_vault.sh

Vault 使用inmem存储和https开始侦听0.0.0.0:8200。 Vault 已密封,启动时未初始化。

如果您想要 run 测试,请保留 Vault 未初始化。测试将初始化 Vault 并创建根令牌00000000-0000-0000-0000-000000000000

如果您想将 Vault 用于 application 或试一试,那么您需要先将其初始化。

$ 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 将初始化和 return 一组解封密钥和根令牌。选择 3 个键并开启 Vault。 在VAULT_TOKEN环境变量中存储 Vault 标记。

$ 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 访问不同的资源。默认情况下,启用 secret 后端,通过 JSON endpoints 访问 secret 配置设置。

HTTP 服务具有以下形式的资源:

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

其中“application”作为SpringApplication注入SpringApplication(i.e.常规 Spring Boot 应用程序中通常为“application”),“ profile”是 active profile(或 properties 的 comma-separated 列表)。从 Vault 检索的 Properties 将使用“as-is”,而不会为 property 名称添加前缀。