99. Quick Start

Prerequisites

要开始使用 Vault 和本指南,您需要一个类似* NIX 的 os,该 os 提供:

Install Vault

$ src/test/bash/install_vault.sh

为Vault创建 SSL 证书

$ src/test/bash/create_certificates.sh

Note

create_certificates.shwork/ca和 JKS 信任库work/keystore.jks中创建证书。如果要使用此快速Starter指南运行 Spring Cloud Vault,则需要将 truststore 的spring.cloud.vault.ssl.trust-store属性配置为file:work/keystore.jks

启动保管箱服务器

$ src/test/bash/local_run_vault.sh

保管库开始使用inmem存储和https0.0.0.0:8200上侦听。启动时,保管箱已密封且未初始化。

Note

如果要运行测试,请使保管库未初始化。测试将初始化 Vault 并创建根令牌00000000-0000-0000-0000-000000000000

如果要对应用程序使用保管箱或尝试使用保管箱,则需要先对其进行初始化。

$ 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.

保管箱将初始化并返回一组启封密钥和根令牌。选择 3 个钥匙,然后打开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 访问不同的资源。默认情况下,启用 Secret 后端,该后端通过 JSON 端点访问 Secret 配置设置。

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

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

其中“应用程序”在spring.application.name中作为spring.application.name注入(即常规 Spring Boot 应用程序中通常是“应用程序”),而“配置文件”是有效的配置文件(或用逗号分隔的属性列表)。从保管库检索到的属性将按原样使用,而无需进一步加前缀属性名称。

首页