Files
spring-cloud-static/spring-cloud-vault/2.0.0.RC2/spring-cloud-vault.xml
2018-05-25 15:17:08 +00:00

1443 lines
71 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="UTF-8"?>
<?asciidoc-toc?>
<?asciidoc-numbered?>
<book xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<info>
<title>Spring Cloud Vault</title>
<date>2018-05-25</date>
</info>
<preface>
<title></title>
<simpara>&#169; 2016-2018 The original authors.</simpara>
<note>
<simpara><emphasis>Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.</emphasis></simpara>
</note>
<simpara>Spring Cloud Vault Config provides client-side support for externalized configuration in a distributed system. With <link xl:href="https://www.vaultproject.io">HashiCorp&#8217;s Vault</link> you have a central place to manage external secret properties for applications across all environments. Vault can manage static and dynamic secrets such as username/password for remote applications/resources and provide credentials for external services such as MySQL, PostgreSQL, Apache Cassandra, MongoDB, Consul, AWS and more.</simpara>
</preface>
<chapter xml:id="_quick_start">
<title>Quick Start</title>
<simpara><emphasis role="strong">Prerequisites</emphasis></simpara>
<simpara>To get started with Vault and this guide you need a
*NIX-like operating systems that provides:</simpara>
<itemizedlist>
<listitem>
<simpara><literal>wget</literal>, <literal>openssl</literal> and <literal>unzip</literal></simpara>
</listitem>
<listitem>
<simpara>at least Java 7 and a properly configured <literal>JAVA_HOME</literal> environment variable</simpara>
</listitem>
</itemizedlist>
<simpara><emphasis role="strong">Install Vault</emphasis></simpara>
<programlisting language="bash" linenumbering="unnumbered">$ src/test/bash/install_vault.sh</programlisting>
<simpara><emphasis role="strong">Create SSL certificates for Vault</emphasis></simpara>
<programlisting language="bash" linenumbering="unnumbered">$ src/test/bash/create_certificates.sh</programlisting>
<note>
<simpara><literal>create_certificates.sh</literal> creates certificates in <literal>work/ca</literal> and a JKS truststore <literal>work/keystore.jks</literal>. If you want to run Spring Cloud Vault using this quickstart guide you need to configure the truststore the <literal>spring.cloud.vault.ssl.trust-store</literal> property to <literal>file:work/keystore.jks</literal>.</simpara>
</note>
<simpara xml:id="quickstart.vault.start"><emphasis role="strong">Start Vault server</emphasis></simpara>
<programlisting language="bash" linenumbering="unnumbered">$ src/test/bash/local_run_vault.sh</programlisting>
<simpara>Vault is started listening on <literal>0.0.0.0:8200</literal> using the <literal>inmem</literal> storage and
<literal>https</literal>.
Vault is sealed and not initialized when starting up.</simpara>
<note>
<simpara>If you want to run tests, leave Vault uninitialized. The tests will
initialize Vault and create a root token <literal>00000000-0000-0000-0000-000000000000</literal>.</simpara>
</note>
<simpara>If you want to use Vault for your application or give it a try then you need to initialize it first.</simpara>
<programlisting language="bash" linenumbering="unnumbered">$ export VAULT_ADDR="https://localhost:8200"
$ export VAULT_SKIP_VERIFY=true # Don't do this for production
$ vault init</programlisting>
<simpara>You should see something like:</simpara>
<programlisting language="bash" linenumbering="unnumbered">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.</programlisting>
<simpara>Vault will initialize and return a set of unsealing keys and the root token.
Pick 3 keys and unseal Vault. Store the Vault token in the <literal>VAULT_TOKEN</literal>
environment variable.</simpara>
<programlisting language="bash" linenumbering="unnumbered">$ 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"</programlisting>
<simpara>Spring Cloud Vault accesses different resources. By default, the secret
backend is enabled which accesses secret config settings via JSON endpoints.</simpara>
<simpara>The HTTP service has resources in the form:</simpara>
<screen>/secret/{application}/{profile}
/secret/{application}
/secret/{defaultContext}/{profile}
/secret/{defaultContext}</screen>
<simpara>where the "application" is injected as the <literal>spring.application.name</literal> in the
<literal>SpringApplication</literal> (i.e. what is normally "application" in a regular
Spring Boot app), "profile" is an active profile (or comma-separated
list of properties). Properties retrieved from Vault will be used "as-is"
without further prefixing of the property names.</simpara>
</chapter>
<chapter xml:id="_client_side_usage">
<title>Client Side Usage</title>
<simpara>To use these features in an application, just build it as a Spring
Boot application that depends on <literal>spring-cloud-vault-config</literal> (e.g. see
the test cases). Example Maven configuration:</simpara>
<example>
<title>pom.xml</title>
<programlisting language="xml" linenumbering="unnumbered">&lt;parent&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
&lt;version&gt;1.5.4.RELEASE&lt;/version&gt;
&lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-starter-vault-config&lt;/artifactId&gt;
&lt;version&gt;2.0.0.RC2&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;!-- repositories also needed for snapshots and milestones --&gt;</programlisting>
</example>
<simpara>Then you can create a standard Spring Boot application, like this simple HTTP server:</simpara>
<informalexample>
<programlisting language="java" linenumbering="unnumbered">@SpringBootApplication
@RestController
public class Application {
@RequestMapping("/")
public String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}</programlisting>
</informalexample>
<simpara>When it runs it will pick up the external configuration from the
default local Vault server on port <literal>8200</literal> if it is running. To modify
the startup behavior you can change the location of the Vault server
using <literal>bootstrap.properties</literal> (like <literal>application.properties</literal> but for
the bootstrap phase of an application context), e.g.</simpara>
<example>
<title>bootstrap.yml</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
host: localhost
port: 8200
scheme: https
uri: https://localhost:8200
connection-timeout: 5000
read-timeout: 15000
config:
order: -10</programlisting>
</example>
<itemizedlist>
<listitem>
<simpara><literal>host</literal> sets the hostname of the Vault host. The host name will be used
for SSL certificate validation</simpara>
</listitem>
<listitem>
<simpara><literal>port</literal> sets the Vault port</simpara>
</listitem>
<listitem>
<simpara><literal>scheme</literal> setting the scheme to <literal>http</literal> will use plain HTTP.
Supported schemes are <literal>http</literal> and <literal>https</literal>.</simpara>
</listitem>
<listitem>
<simpara><literal>uri</literal> configure the Vault endpoint with an URI. Takes precedence over host/port/scheme configuration</simpara>
</listitem>
<listitem>
<simpara><literal>connection-timeout</literal> sets the connection timeout in milliseconds</simpara>
</listitem>
<listitem>
<simpara><literal>read-timeout</literal> sets the read timeout in milliseconds</simpara>
</listitem>
<listitem>
<simpara><literal>config.order</literal> sets the order for the property source</simpara>
</listitem>
</itemizedlist>
<simpara>Enabling further integrations requires additional dependencies and
configuration. Depending on how you have set up Vault you might need
additional configuration like
<link xl:href="http://cloud.spring.io/spring-cloud-vault/spring-cloud-vault.html#vault.config.ssl">SSL</link> and
<link xl:href="http://cloud.spring.io/spring-cloud-vault/spring-cloud-vault.html#vault.config.authentication">authentication</link>.</simpara>
<simpara>If the application imports the <literal>spring-boot-starter-actuator</literal> project, the
status of the vault server will be available via the <literal>/health</literal> endpoint.</simpara>
<simpara>The vault health indicator can be enabled or disabled through the
property <literal>health.vault.enabled</literal> (default <literal>true</literal>).</simpara>
<section xml:id="_authentication">
<title>Authentication</title>
<simpara>Vault requires an <link xl:href="https://www.vaultproject.io/docs/concepts/auth.html">authentication mechanism</link> to <link xl:href="https://www.vaultproject.io/docs/concepts/tokens.html">authorize client requests</link>.</simpara>
<simpara>Spring Cloud Vault supports multiple <link xl:href="http://cloud.spring.io/spring-cloud-vault/spring-cloud-vault.html#vault.config.authentication">authentication mechanisms</link> to authenticate applications with Vault.</simpara>
<simpara>For a quickstart, use the root token printed by the <link linkend="quickstart.vault.start">Vault initialization</link>.</simpara>
<example>
<title>bootstrap.yml</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
token: 19aefa97-cccc-bbbb-aaaa-225940e63d76</programlisting>
</example>
<warning>
<simpara>Consider carefully your security requirements. Static token authentication is fine if you want quickly get started with Vault, but a static token is not protected any further. Any disclosure to unintended parties allows Vault use with the associated token roles.</simpara>
</warning>
</section>
</chapter>
<chapter xml:id="vault.config.authentication">
<title>Authentication methods</title>
<simpara>Different organizations have different requirements for security
and authentication. Vault reflects that need by shipping multiple authentication
methods. Spring Cloud Vault supports token and AppId authentication.</simpara>
<section xml:id="vault.config.authentication.token">
<title>Token authentication</title>
<simpara>Tokens are the core method for authentication within Vault.
Token authentication requires a static token to be provided using the
<link xl:href="https://github.com/spring-cloud/spring-cloud-commons/blob/master/docs/src/main/asciidoc/spring-cloud-commons.adoc#the-bootstrap-application-context">Bootstrap Application Context</link>.</simpara>
<note>
<simpara>Token authentication is the default authentication method.
If a token is disclosed an unintended party gains access to Vault and
can access secrets for the intended client.</simpara>
</note>
<example>
<title>bootstrap.yml</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: TOKEN
token: 00000000-0000-0000-0000-000000000000</programlisting>
</example>
<itemizedlist>
<listitem>
<simpara><literal>authentication</literal> setting this value to <literal>TOKEN</literal> selects the Token
authentication method</simpara>
</listitem>
<listitem>
<simpara><literal>token</literal> sets the static token to use</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/concepts/tokens.html">Vault Documentation: Tokens</link></simpara>
</section>
<section xml:id="vault.config.authentication.appid">
<title>AppId authentication</title>
<simpara>Vault supports <link xl:href="https://www.vaultproject.io/docs/auth/app-id.html">AppId</link>
authentication that consists of two hard to guess tokens. The AppId
defaults to <literal>spring.application.name</literal> that is statically configured.
The second token is the UserId which is a part determined by the application,
usually related to the runtime environment. IP address, Mac address or a
Docker container name are good examples. Spring Cloud Vault Config supports
IP address, Mac address and static UserId&#8217;s (e.g. supplied via System properties).
The IP and Mac address are represented as Hex-encoded SHA256 hash.</simpara>
<simpara>IP address-based UserId&#8217;s use the local host&#8217;s IP address.</simpara>
<example>
<title>bootstrap.yml using SHA256 IP-Address UserId&#8217;s</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: APPID
app-id:
user-id: IP_ADDRESS</programlisting>
</example>
<itemizedlist>
<listitem>
<simpara><literal>authentication</literal> setting this value to <literal>APPID</literal> selects the AppId
authentication method</simpara>
</listitem>
<listitem>
<simpara><literal>app-id-path</literal> sets the path of the AppId mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>user-id</literal> sets the UserId method. Possible values are <literal>IP_ADDRESS</literal>,
<literal>MAC_ADDRESS</literal> or a class name implementing a custom <literal>AppIdUserIdMechanism</literal></simpara>
</listitem>
</itemizedlist>
<simpara>The corresponding command to generate the IP address UserId from a command line is:</simpara>
<screen>$ echo -n 192.168.99.1 | sha256sum</screen>
<note>
<simpara>Including the line break of <literal>echo</literal> leads to a different hash value
so make sure to include the <literal>-n</literal> flag.</simpara>
</note>
<simpara>Mac address-based UserId&#8217;s obtain their network device from the
localhost-bound device. The configuration also allows specifying
a <literal>network-interface</literal> hint to pick the right device. The value of
<literal>network-interface</literal> is optional and can be either an interface
name or interface index (0-based).</simpara>
<example>
<title>bootstrap.yml using SHA256 Mac-Address UserId&#8217;s</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: APPID
app-id:
user-id: MAC_ADDRESS
network-interface: eth0</programlisting>
</example>
<itemizedlist>
<listitem>
<simpara><literal>network-interface</literal> sets network interface to obtain the physical address</simpara>
</listitem>
</itemizedlist>
<simpara>The corresponding command to generate the IP address UserId from a command line is:</simpara>
<screen>$ echo -n 0AFEDE1234AC | sha256sum</screen>
<note>
<simpara>The Mac address is specified uppercase and without colons.
Including the line break of <literal>echo</literal> leads to a different hash value
so make sure to include the <literal>-n</literal> flag.</simpara>
</note>
<section xml:id="_custom_userid">
<title>Custom UserId</title>
<simpara>The UserId generation is an open mechanism. You can set
<literal>spring.cloud.vault.app-id.user-id</literal> to any string and the configured
value will be used as static UserId.</simpara>
<simpara>A more advanced approach lets you set <literal>spring.cloud.vault.app-id.user-id</literal> to a
classname. This class must be on your classpath and must implement
the <literal>org.springframework.cloud.vault.AppIdUserIdMechanism</literal> interface
and the <literal>createUserId</literal> method. Spring Cloud Vault will obtain the UserId
by calling <literal>createUserId</literal> each time it authenticates using AppId to
obtain a token.</simpara>
<example>
<title>bootstrap.yml</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: APPID
app-id:
user-id: com.examlple.MyUserIdMechanism</programlisting>
</example>
<example>
<title>MyUserIdMechanism.java</title>
<programlisting language="yaml" linenumbering="unnumbered">public class MyUserIdMechanism implements AppIdUserIdMechanism {
@Override
public String createUserId() {
String userId = ...
return userId;
}
}</programlisting>
</example>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/auth/app-id.html">Vault Documentation: Using the App ID auth backend</link></simpara>
</section>
</section>
<section xml:id="_approle_authentication">
<title>AppRole authentication</title>
<simpara><link xl:href="https://www.vaultproject.io/docs/auth/app-id.html">AppRole</link> is intended for machine
authentication, like the deprecated (since Vault 0.6.1) <xref linkend="vault.config.authentication.appid"/>.
AppRole authentication consists of two hard to guess (secret) tokens: RoleId and SecretId.</simpara>
<simpara>Spring Vault supports various AppRole scenarios (push/pull mode and wrapped).</simpara>
<simpara>RoleId and optionally SecretId must be provided by configuration,
Spring Vault will not look up these or create a custom SecretId.</simpara>
<example>
<title>bootstrap.yml with AppRole authentication properties</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: APPROLE
app-role:
role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52</programlisting>
</example>
<simpara>The following scenarios are supported along the required configuration details:</simpara>
<table frame="all" rowsep="1" colsep="1">
<title>Configuration</title>
<tgroup cols="5">
<colspec colname="col_1" colwidth="20*"/>
<colspec colname="col_2" colwidth="20*"/>
<colspec colname="col_3" colwidth="20*"/>
<colspec colname="col_4" colwidth="20*"/>
<colspec colname="col_5" colwidth="20*"/>
<tbody>
<row>
<entry align="left" valign="top"><simpara><emphasis role="strong">Method</emphasis></simpara></entry>
<entry align="left" valign="top"><simpara><emphasis role="strong">RoleId</emphasis></simpara></entry>
<entry align="left" valign="top"><simpara><emphasis role="strong">SecretId</emphasis></simpara></entry>
<entry align="left" valign="top"><simpara><emphasis role="strong">RoleName</emphasis></simpara></entry>
<entry align="left" valign="top"><simpara><emphasis role="strong">Token</emphasis></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Provided RoleId/SecretId</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Provided RoleId without SecretId</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Provided RoleId, Pull SecretId</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Pull RoleId, provided SecretId</simpara></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Full Pull Mode</simpara></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Wrapped</simpara></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Wrapped RoleId, provided SecretId</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Provided RoleId, wrapped SecretId</simpara></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
</row>
</tbody>
</tgroup>
</table>
<table frame="all" rowsep="1" colsep="1">
<title>Pull/Push/Wrapped Matrix</title>
<tgroup cols="3">
<colspec colname="col_1" colwidth="33.3333*"/>
<colspec colname="col_2" colwidth="33.3333*"/>
<colspec colname="col_3" colwidth="33.3334*"/>
<tbody>
<row>
<entry align="left" valign="top"><simpara><emphasis role="strong">RoleId</emphasis></simpara></entry>
<entry align="left" valign="top"><simpara><emphasis role="strong">SecretId</emphasis></simpara></entry>
<entry align="left" valign="top"><simpara><emphasis role="strong">Supported</emphasis></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Pull</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Wrapped</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara>Absent</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Pull</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Pull</simpara></entry>
<entry align="left" valign="top"><simpara>Pull</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Pull</simpara></entry>
<entry align="left" valign="top"><simpara>Wrapped</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Pull</simpara></entry>
<entry align="left" valign="top"><simpara>Absent</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Wrapped</simpara></entry>
<entry align="left" valign="top"><simpara>Provided</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Wrapped</simpara></entry>
<entry align="left" valign="top"><simpara>Pull</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Wrapped</simpara></entry>
<entry align="left" valign="top"><simpara>Wrapped</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>Wrapped</simpara></entry>
<entry align="left" valign="top"><simpara>Absent</simpara></entry>
<entry align="left" valign="top"><simpara></simpara></entry>
</row>
</tbody>
</tgroup>
</table>
<note>
<simpara>You can use still all combinations of push/pull/wrapped modes by providing a configured <literal>AppRoleAuthentication</literal> bean within the boostrap context. Spring Cloud Vault cannot derive all possible AppRole combinations from the configuration properties.</simpara>
</note>
<example>
<title>bootstrap.yml with all AppRole authentication properties</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: APPROLE
app-role:
role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52
secret-id: 1696536f-1976-73b1-b241-0b4213908d39
role: my-role
app-role-path: approle</programlisting>
</example>
<itemizedlist>
<listitem>
<simpara><literal>role-id</literal> sets the RoleId.</simpara>
</listitem>
<listitem>
<simpara><literal>secret-id</literal> sets the SecretId. SecretId can be omitted if AppRole is configured without requiring SecretId (See <literal>bind_secret_id</literal>).</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal>: sets the AppRole name for pull mode.</simpara>
</listitem>
<listitem>
<simpara><literal>app-role-path</literal> sets the path of the approle authentication mount to use.</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/auth/approle.html">Vault Documentation: Using the AppRole auth backend</link></simpara>
</section>
<section xml:id="vault.config.authentication.awsec2">
<title>AWS-EC2 authentication</title>
<simpara>The <link xl:href="https://www.vaultproject.io/docs/auth/aws-ec2.html">aws-ec2</link>
auth backend provides a secure introduction mechanism
for AWS EC2 instances, allowing automated retrieval of a Vault
token. Unlike most Vault authentication backends, this backend
does not require first-deploying, or provisioning security-sensitive
credentials (tokens, username/password, client certificates, etc.).
Instead, it treats AWS as a Trusted Third Party and uses the
cryptographically signed dynamic metadata information that uniquely
represents each EC2 instance.</simpara>
<example>
<title>bootstrap.yml using AWS-EC2 Authentication</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: AWS_EC2</programlisting>
</example>
<simpara>AWS-EC2 authentication enables nonce by default to follow
the Trust On First Use (TOFU) principle. Any unintended party that
gains access to the PKCS#7 identity metadata can authenticate
against Vault.</simpara>
<simpara>During the first login, Spring Cloud Vault generates a nonce
that is stored in the auth backend aside the instance Id.
Re-authentication requires the same nonce to be sent. Any other
party does not have the nonce and can raise an alert in Vault for
further investigation.</simpara>
<simpara>The nonce is kept in memory and is lost during application restart.
You can configure a static nonce with <literal>spring.cloud.vault.aws-ec2.nonce</literal>.</simpara>
<simpara>AWS-EC2 authentication roles are optional and default to the AMI.
You can configure the authentication role by setting the
<literal>spring.cloud.vault.aws-ec2.role</literal> property.</simpara>
<example>
<title>bootstrap.yml with configured role</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: AWS_EC2
aws-ec2:
role: application-server</programlisting>
</example>
<example>
<title>bootstrap.yml with all AWS EC2 authentication properties</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: AWS_EC2
aws-ec2:
role: application-server
aws-ec2-path: aws-ec2
identity-document: http://...
nonce: my-static-nonce</programlisting>
</example>
<itemizedlist>
<listitem>
<simpara><literal>authentication</literal> setting this value to <literal>AWS_EC2</literal> selects the AWS EC2
authentication method</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal> sets the name of the role against which the login is being attempted.</simpara>
</listitem>
<listitem>
<simpara><literal>aws-ec2-path</literal> sets the path of the AWS EC2 mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>identity-document</literal> sets URL of the PKCS#7 AWS EC2 identity document</simpara>
</listitem>
<listitem>
<simpara><literal>nonce</literal> used for AWS-EC2 authentication. An empty nonce defaults to nonce generation</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/auth/aws.html">Vault Documentation: Using the aws auth backend</link></simpara>
</section>
<section xml:id="vault.config.authentication.awsiam">
<title>AWS-IAM authentication</title>
<simpara>The <link xl:href="https://www.vaultproject.io/docs/auth/aws-ec2.html">aws</link> backend provides a secure
authentication mechanism for AWS IAM roles, allowing the automatic authentication with
vault based on the current IAM role of the running application.
Unlike most Vault authentication backends, this backend
does not require first-deploying, or provisioning security-sensitive
credentials (tokens, username/password, client certificates, etc.).
Instead, it treats AWS as a Trusted Third Party and uses the
4 pieces of information signed by the caller with their IAM credentials
to verify that the caller is indeed using that IAM role.</simpara>
<simpara>The current IAM role the application is running in is automatically calculated.
If you are running your application on AWS ECS then the application
will use the IAM role assigned to the ECS task of the running container.
If you are running your application naked on top of an EC2 instance then
the IAM role used will be the one assigned to the EC2 instance.</simpara>
<simpara>When using the AWS-IAM authentication you must create a role in Vault
and assign it to your IAM role. An empty <literal>role</literal> defaults to
the friendly name the current IAM role.</simpara>
<example>
<title>bootstrap.yml with required AWS-IAM Authentication properties</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: AWS_IAM</programlisting>
</example>
<example>
<title>bootstrap.yml with all AWS-IAM Authentication properties</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: AWS_IAM
aws-iam:
role: my-dev-role
aws-path: aws
server-id: some.server.name</programlisting>
</example>
<itemizedlist>
<listitem>
<simpara><literal>role</literal> sets the name of the role against which the login is being attempted. This should be bound to your IAM role. If one is not supplied then the friendly name of the current IAM user will be used as the vault role.</simpara>
</listitem>
<listitem>
<simpara><literal>aws-path</literal> sets the path of the AWS mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>server-id</literal> sets the value to use for the <literal>X-Vault-AWS-IAM-Server-ID</literal> header preventing certain types of replay attacks.</simpara>
</listitem>
</itemizedlist>
<simpara>AWS-IAM requires the AWS Java SDK dependency (<literal>com.amazonaws:aws-java-sdk-core</literal>)
as the authentication implementation uses AWS SDK types for credentials and request signing.</simpara>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/auth/aws.html">Vault Documentation: Using the aws auth backend</link></simpara>
</section>
<section xml:id="vault.config.authentication.clientcert">
<title>TLS certificate authentication</title>
<simpara>The <literal>cert</literal> auth backend allows authentication using SSL/TLS client
certificates that are either signed by a CA or self-signed.</simpara>
<simpara>To enable <literal>cert</literal> authentication you need to:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>Use SSL, see <xref linkend="vault.config.ssl"/></simpara>
</listitem>
<listitem>
<simpara>Configure a Java <literal>Keystore</literal> that contains the client
certificate and the private key</simpara>
</listitem>
<listitem>
<simpara>Set the <literal>spring.cloud.vault.authentication</literal> to <literal>CERT</literal></simpara>
</listitem>
</orderedlist>
<example>
<title>bootstrap.yml</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: CERT
ssl:
key-store: classpath:keystore.jks
key-store-password: changeit
cert-auth-path: cert</programlisting>
</example>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/auth/cert.html">Vault Documentation: Using the Cert auth backend</link></simpara>
</section>
<section xml:id="vault.config.authentication.cubbyhole">
<title>Cubbyhole authentication</title>
<simpara>Cubbyhole authentication uses Vault primitives to provide a secured authentication
workflow. Cubbyhole authentication uses tokens as primary login method.
An ephemeral token is used to obtain a second, login VaultToken from Vault&#8217;s
Cubbyhole secret backend. The login token is usually longer-lived and used to
interact with Vault. The login token will be retrieved from a wrapped
response stored at <literal>/cubbyhole/response</literal>.</simpara>
<simpara><emphasis role="strong">Creating a wrapped token</emphasis></simpara>
<note>
<simpara>Response Wrapping for token creation requires Vault 0.6.0 or higher.</simpara>
</note>
<example>
<title>Creating and storing tokens</title>
<programlisting language="shell" linenumbering="unnumbered">$ vault token-create -wrap-ttl="10m"
Key Value
--- -----
wrapping_token: 397ccb93-ff6c-b17b-9389-380b01ca2645
wrapping_token_ttl: 0h10m0s
wrapping_token_creation_time: 2016-09-18 20:29:48.652957077 +0200 CEST
wrapped_accessor: 46b6aebb-187f-932a-26d7-4f3d86a68319</programlisting>
</example>
<example>
<title>bootstrap.yml</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: CUBBYHOLE
token: 397ccb93-ff6c-b17b-9389-380b01ca2645</programlisting>
</example>
<simpara>See also:</simpara>
<itemizedlist>
<listitem>
<simpara><link xl:href="https://www.vaultproject.io/docs/concepts/tokens.html">Vault Documentation: Tokens</link></simpara>
</listitem>
<listitem>
<simpara><link xl:href="https://www.vaultproject.io/docs/secrets/cubbyhole/index.html">Vault Documentation: Cubbyhole Secret Backend</link></simpara>
</listitem>
<listitem>
<simpara><link xl:href="https://www.vaultproject.io/docs/concepts/response-wrapping.html">Vault Documentation: Response Wrapping</link></simpara>
</listitem>
</itemizedlist>
</section>
<section xml:id="vault.config.authentication.kubernetes">
<title>Kubernetes authentication</title>
<simpara>Kubernetes authentication mechanism (since Vault 0.8.3) allows to authenticate with Vault using a Kubernetes Service Account Token.
The authentication is role based and the role is bound to a service account name and a namespace.</simpara>
<simpara>A file containing a JWT token for a pods service account is automatically mounted at <literal>/var/run/secrets/kubernetes.io/serviceaccount/token</literal>.</simpara>
<example>
<title>bootstrap.yml with all Kubernetes authentication properties</title>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
authentication: KUBERNETES
kubernetes:
role: my-dev-role
service-account-token-file: /var/run/secrets/kubernetes.io/serviceaccount/token</programlisting>
</example>
<itemizedlist>
<listitem>
<simpara><literal>role</literal> sets the Role.</simpara>
</listitem>
<listitem>
<simpara><literal>service-account-token-file</literal> sets the location of the file containing the Kubernetes Service Account Token. Defaults to <literal>/var/run/secrets/kubernetes.io/serviceaccount/token</literal>.</simpara>
</listitem>
</itemizedlist>
<simpara>See also:</simpara>
<itemizedlist>
<listitem>
<simpara><link xl:href="https://www.vaultproject.io/docs/auth/kubernetes.html">Vault Documentation: Kubernetes</link></simpara>
</listitem>
<listitem>
<simpara><link xl:href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/">Kubernetes Documentation: Configure Service Accounts for Pods</link></simpara>
</listitem>
</itemizedlist>
</section>
</chapter>
<chapter xml:id="vault.config.backends">
<title>Secret Backends</title>
<section xml:id="vault.config.backends.generic">
<title>Generic Backend</title>
<simpara>Spring Cloud Vault supports at the basic level the generic secret
backend. The generic secret backend allows storage of arbitrary
values as key-value store. A single context can store one or many
key-value tuples. Contexts can be organized hierarchically.
Spring Cloud Vault allows using the Application name
and a default context name (<literal>application</literal>) in combination with active
profiles.</simpara>
<screen>/secret/{application}/{profile}
/secret/{application}
/secret/{default-context}/{profile}
/secret/{default-context}</screen>
<simpara>The application name is determined by the properties:</simpara>
<itemizedlist>
<listitem>
<simpara><literal>spring.cloud.vault.generic.application-name</literal></simpara>
</listitem>
<listitem>
<simpara><literal>spring.cloud.vault.application-name</literal></simpara>
</listitem>
<listitem>
<simpara><literal>spring.application.name</literal></simpara>
</listitem>
</itemizedlist>
<simpara>Secrets can be obtained from other contexts within the generic backend by adding their
paths to the application name, separated by commas. For example, given the application
name <literal>usefulapp,mysql1,projectx/aws</literal>, each of these folders will be used:</simpara>
<itemizedlist>
<listitem>
<simpara><literal>/secret/usefulapp</literal></simpara>
</listitem>
<listitem>
<simpara><literal>/secret/mysql1</literal></simpara>
</listitem>
<listitem>
<simpara><literal>/secret/projectx/aws</literal></simpara>
</listitem>
</itemizedlist>
<simpara>Spring Cloud Vault adds all active profiles to the list of possible context paths.
No active profiles will skip accessing contexts with a profile name.</simpara>
<simpara>Properties are exposed like they are stored (i.e. without additional prefixes).</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
generic:
enabled: true
backend: secret
profile-separator: '/'
default-context: application
application-name: my-app</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>false</literal> disables the secret backend
config usage</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the secret mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>default-context</literal> sets the context name used by all applications</simpara>
</listitem>
<listitem>
<simpara><literal>application-name</literal> overrides the application name for use in the generic backend</simpara>
</listitem>
<listitem>
<simpara><literal>profile-separator</literal> separates the profile name from the context in
property sources with profiles</simpara>
</listitem>
</itemizedlist>
<note>
<simpara>The key-value secret backend can be operated in versioned (v2) and non-versioned (v1) modes. Depending on the mode of operation, a different API is required to access secrets. Make sure to enable <literal>generic</literal> secret backend usage for non-versioned key-value backends and <literal>kv</literal> secret backend usage for versioned key-value backends.</simpara>
</note>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/kv/kv-v1.html">Vault Documentation: Using the KV Secrets Engine - Version 1 (generic secret backend)</link></simpara>
</section>
<section xml:id="vault.config.backends.kv.versioned">
<title>Versioned Key-Value Backend</title>
<simpara>Spring Cloud Vault supports the versioned Key-Value secret
backend. The key-value backend allows storage of arbitrary
values as key-value store. A single context can store one or many
key-value tuples. Contexts can be organized hierarchically.
Spring Cloud Vault allows using the Application name
and a default context name (<literal>application</literal>) in combination with active
profiles.</simpara>
<screen>/secret/{application}/{profile}
/secret/{application}
/secret/{default-context}/{profile}
/secret/{default-context}</screen>
<simpara>The application name is determined by the properties:</simpara>
<itemizedlist>
<listitem>
<simpara><literal>spring.cloud.vault.kv.application-name</literal></simpara>
</listitem>
<listitem>
<simpara><literal>spring.cloud.vault.application-name</literal></simpara>
</listitem>
<listitem>
<simpara><literal>spring.application.name</literal></simpara>
</listitem>
</itemizedlist>
<simpara>Secrets can be obtained from other contexts within the key-value backend by adding their
paths to the application name, separated by commas. For example, given the application
name <literal>usefulapp,mysql1,projectx/aws</literal>, each of these folders will be used:</simpara>
<itemizedlist>
<listitem>
<simpara><literal>/secret/usefulapp</literal></simpara>
</listitem>
<listitem>
<simpara><literal>/secret/mysql1</literal></simpara>
</listitem>
<listitem>
<simpara><literal>/secret/projectx/aws</literal></simpara>
</listitem>
</itemizedlist>
<simpara>Spring Cloud Vault adds all active profiles to the list of possible context paths.
No active profiles will skip accessing contexts with a profile name.</simpara>
<simpara>Properties are exposed like they are stored (i.e. without additional prefixes).</simpara>
<note>
<simpara>Spring Cloud Vault adds the <literal>data/</literal> context between the mount path and the actual context path.</simpara>
</note>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
kv:
enabled: true
backend: secret
profile-separator: '/'
default-context: application
application-name: my-app</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>false</literal> disables the secret backend
config usage</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the secret mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>default-context</literal> sets the context name used by all applications</simpara>
</listitem>
<listitem>
<simpara><literal>application-name</literal> overrides the application name for use in the generic backend</simpara>
</listitem>
<listitem>
<simpara><literal>profile-separator</literal> separates the profile name from the context in
property sources with profiles</simpara>
</listitem>
</itemizedlist>
<note>
<simpara>The key-value secret backend can be operated in versioned (v2) and non-versioned (v1) modes. Depending on the mode of operation, a different API is required to access secrets. Make sure to enable <literal>generic</literal> secret backend usage for non-versioned key-value backends and <literal>kv</literal> secret backend usage for versioned key-value backends.</simpara>
</note>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/kv/kv-v2.html">Vault Documentation: Using the KV Secrets Engine - Version 2 (versioned key-value backend)</link></simpara>
</section>
<section xml:id="vault.config.backends.consul">
<title>Consul</title>
<simpara>Spring Cloud Vault can obtain credentials for HashiCorp Consul.
The Consul integration requires the <literal>spring-cloud-vault-config-consul</literal>
dependency.</simpara>
<example>
<title>pom.xml</title>
<programlisting language="xml" linenumbering="unnumbered">&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-vault-config-consul&lt;/artifactId&gt;
&lt;version&gt;2.0.0.RC2&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;</programlisting>
</example>
<simpara>The integration can be enabled by setting
<literal>spring.cloud.vault.consul.enabled=true</literal> (default <literal>false</literal>) and
providing the role name with <literal>spring.cloud.vault.consul.role=…</literal>.</simpara>
<simpara>The obtained token is stored in <literal>spring.cloud.consul.token</literal>
so using Spring Cloud Consul can pick up the generated
credentials without further configuration. You can configure
the property name by setting <literal>spring.cloud.vault.consul.token-property</literal>.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
consul:
enabled: true
role: readonly
backend: consul
token-property: spring.cloud.consul.token</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>true</literal> enables the Consul backend config usage</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal> sets the role name of the Consul role definition</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the Consul mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>token-property</literal> sets the property name in which the Consul ACL token is stored</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/consul/index.html">Vault Documentation: Setting up Consul with Vault</link></simpara>
</section>
<section xml:id="vault.config.backends.rabbitmq">
<title>RabbitMQ</title>
<simpara>Spring Cloud Vault can obtain credentials for RabbitMQ.</simpara>
<simpara>The RabbitMQ integration requires the <literal>spring-cloud-vault-config-rabbitmq</literal>
dependency.</simpara>
<example>
<title>pom.xml</title>
<programlisting language="xml" linenumbering="unnumbered">&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-vault-config-rabbitmq&lt;/artifactId&gt;
&lt;version&gt;2.0.0.RC2&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;</programlisting>
</example>
<simpara>The integration can be enabled by setting
<literal>spring.cloud.vault.rabbitmq.enabled=true</literal> (default <literal>false</literal>)
and providing the role name with <literal>spring.cloud.vault.rabbitmq.role=…</literal>.</simpara>
<simpara>Username and password are stored in <literal>spring.rabbitmq.username</literal>
and <literal>spring.rabbitmq.password</literal> so using Spring Boot will pick up the generated
credentials without further configuration. You can configure the property names
by setting <literal>spring.cloud.vault.rabbitmq.username-property</literal> and
<literal>spring.cloud.vault.rabbitmq.password-property</literal>.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
rabbitmq:
enabled: true
role: readonly
backend: rabbitmq
username-property: spring.rabbitmq.username
password-property: spring.rabbitmq.password</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>true</literal> enables the RabbitMQ backend config usage</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal> sets the role name of the RabbitMQ role definition</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the RabbitMQ mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>username-property</literal> sets the property name in which the RabbitMQ username is stored</simpara>
</listitem>
<listitem>
<simpara><literal>password-property</literal> sets the property name in which the RabbitMQ password is stored</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/rabbitmq/index.html">Vault Documentation: Setting up RabbitMQ with Vault</link></simpara>
</section>
<section xml:id="vault.config.backends.aws">
<title>AWS</title>
<simpara>Spring Cloud Vault can obtain credentials for AWS.</simpara>
<simpara>The AWS integration requires the <literal>spring-cloud-vault-config-aws</literal>
dependency.</simpara>
<example>
<title>pom.xml</title>
<programlisting language="xml" linenumbering="unnumbered">&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-vault-config-aws&lt;/artifactId&gt;
&lt;version&gt;2.0.0.RC2&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;</programlisting>
</example>
<simpara>The integration can be enabled by setting
<literal>spring.cloud.vault.aws=true</literal> (default <literal>false</literal>)
and providing the role name with <literal>spring.cloud.vault.aws.role=…</literal>.</simpara>
<simpara>The access key and secret key are stored in <literal>cloud.aws.credentials.accessKey</literal>
and <literal>cloud.aws.credentials.secretKey</literal> so using Spring Cloud AWS will pick up the generated
credentials without further configuration. You can configure the property names
by setting <literal>spring.cloud.vault.aws.access-key-property</literal> and
<literal>spring.cloud.vault.aws.secret-key-property</literal>.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
aws:
enabled: true
role: readonly
backend: aws
access-key-property: cloud.aws.credentials.accessKey
secret-key-property: cloud.aws.credentials.secretKey</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>true</literal> enables the AWS backend config usage</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal> sets the role name of the AWS role definition</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the AWS mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>access-key-property</literal> sets the property name in which the AWS access key is stored</simpara>
</listitem>
<listitem>
<simpara><literal>secret-key-property</literal> sets the property name in which the AWS secret key is stored</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/aws/index.html">Vault Documentation: Setting up AWS with Vault</link></simpara>
</section>
</chapter>
<chapter xml:id="vault.config.backends.database-backends">
<title>Database backends</title>
<simpara>Vault supports several database secret backends to generate database
credentials dynamically based on configured roles. This means
services that need to access a database no longer need to configure
credentials: they can request them from Vault, and use Vault&#8217;s leasing
mechanism to more easily roll keys.</simpara>
<simpara>Spring Cloud Vault integrates with these backends:</simpara>
<itemizedlist>
<listitem>
<simpara><xref linkend="vault.config.backends.database"/></simpara>
</listitem>
<listitem>
<simpara><xref linkend="vault.config.backends.cassandra"/></simpara>
</listitem>
<listitem>
<simpara><xref linkend="vault.config.backends.mongodb"/></simpara>
</listitem>
<listitem>
<simpara><xref linkend="vault.config.backends.mysql"/></simpara>
</listitem>
<listitem>
<simpara><xref linkend="vault.config.backends.postgresql"/></simpara>
</listitem>
</itemizedlist>
<simpara>Using a database secret backend requires to enable the
backend in the configuration and the <literal>spring-cloud-vault-config-databases</literal>
dependency.</simpara>
<simpara>Vault ships since 0.7.1 with a dedicated <literal>database</literal> secret backend that allows
database integration via plugins. You can use that specific backend by using the
generic database backend. Make sure to specify the appropriate
backend path, e.g. <literal>spring.cloud.vault.mysql.role.backend=database</literal>.</simpara>
<example>
<title>pom.xml</title>
<programlisting language="xml" linenumbering="unnumbered">&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-vault-config-databases&lt;/artifactId&gt;
&lt;version&gt;2.0.0.RC2&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;</programlisting>
</example>
<note>
<simpara>Enabling multiple JDBC-compliant databases will generate credentials
and store them by default in the same property keys hence property names for
JDBC secrets need to be configured separately.</simpara>
</note>
<section xml:id="vault.config.backends.database">
<title>Database</title>
<simpara>Spring Cloud Vault can obtain credentials for any database listed at
<link xl:href="https://www.vaultproject.io/api/secret/databases/index.html">https://www.vaultproject.io/api/secret/databases/index.html</link>.
The integration can be enabled by setting
<literal>spring.cloud.vault.database.enabled=true</literal> (default <literal>false</literal>) and
providing the role name with <literal>spring.cloud.vault.database.role=…</literal>.</simpara>
<simpara>While the database backend is a generic one, <literal>spring.cloud.vault.database</literal>
specifically targets JDBC databases. Username and password are
stored in <literal>spring.datasource.username</literal> and <literal>spring.datasource.password</literal>
so using Spring Boot will pick up the generated credentials
for your <literal>DataSource</literal> without further configuration.
You can configure the property names by setting
<literal>spring.cloud.vault.database.username-property</literal> and
<literal>spring.cloud.vault.database.password-property</literal>.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
database:
enabled: true
role: readonly
backend: database
username-property: spring.datasource.username
password-property: spring.datasource.username</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>true</literal> enables the Database backend config usage</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal> sets the role name of the Database role definition</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the Database mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>username-property</literal> sets the property name in which the Database username is stored</simpara>
</listitem>
<listitem>
<simpara><literal>password-property</literal> sets the property name in which the Database password is stored</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/databases/index.html">Vault Documentation: Database Secrets backend</link></simpara>
</section>
<section xml:id="vault.config.backends.cassandra">
<title>Apache Cassandra</title>
<note>
<simpara>The <literal>cassandra</literal> backend has been deprecated in Vault 0.7.1 and
it is recommended to use the <literal>database</literal> backend and mount it as <literal>cassandra</literal>.</simpara>
</note>
<simpara>Spring Cloud Vault can obtain credentials for Apache Cassandra.
The integration can be enabled by setting
<literal>spring.cloud.vault.cassandra.enabled=true</literal> (default <literal>false</literal>) and
providing the role name with <literal>spring.cloud.vault.cassandra.role=…</literal>.</simpara>
<simpara>Username and password are stored in <literal>spring.data.cassandra.username</literal>
and <literal>spring.data.cassandra.password</literal> so using Spring Boot will pick
up the generated credentials without further configuration.
You can configure the property names by setting
<literal>spring.cloud.vault.cassandra.username-property</literal> and
<literal>spring.cloud.vault.cassandra.password-property</literal>.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
cassandra:
enabled: true
role: readonly
backend: cassandra
username-property: spring.data.cassandra.username
password-property: spring.data.cassandra.username</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>true</literal> enables the Cassandra backend config usage</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal> sets the role name of the Cassandra role definition</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the Cassandra mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>username-property</literal> sets the property name in which the Cassandra username is stored</simpara>
</listitem>
<listitem>
<simpara><literal>password-property</literal> sets the property name in which the Cassandra password is stored</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/cassandra/index.html">Vault Documentation: Setting up Apache Cassandra with Vault</link></simpara>
</section>
<section xml:id="vault.config.backends.mongodb">
<title>MongoDB</title>
<note>
<simpara>The <literal>mongodb</literal> backend has been deprecated in Vault 0.7.1 and
it is recommended to use the <literal>database</literal> backend and mount it as <literal>mongodb</literal>.</simpara>
</note>
<simpara>Spring Cloud Vault can obtain credentials for MongoDB.
The integration can be enabled by setting
<literal>spring.cloud.vault.mongodb.enabled=true</literal> (default <literal>false</literal>) and
providing the role name with <literal>spring.cloud.vault.mongodb.role=…</literal>.</simpara>
<simpara>Username and password are stored in <literal>spring.data.mongodb.username</literal>
and <literal>spring.data.mongodb.password</literal> so using Spring Boot will
pick up the generated credentials without further configuration.
You can configure the property names by setting
<literal>spring.cloud.vault.mongodb.username-property</literal> and
<literal>spring.cloud.vault.mongodb.password-property</literal>.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
mongodb:
enabled: true
role: readonly
backend: mongodb
username-property: spring.data.mongodb.username
password-property: spring.data.mongodb.password</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>true</literal> enables the MongodB backend config usage</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal> sets the role name of the MongoDB role definition</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the MongoDB mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>username-property</literal> sets the property name in which the MongoDB username is stored</simpara>
</listitem>
<listitem>
<simpara><literal>password-property</literal> sets the property name in which the MongoDB password is stored</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/mongodb/index.html">Vault Documentation: Setting up MongoDB with Vault</link></simpara>
</section>
<section xml:id="vault.config.backends.mysql">
<title>MySQL</title>
<note>
<simpara>The <literal>mysql</literal> backend has been deprecated in Vault 0.7.1 and
it is recommended to use the <literal>database</literal> backend and mount it as <literal>mysql</literal>.
Configuration for <literal>spring.cloud.vault.mysql</literal> will be removed in a future version.</simpara>
</note>
<simpara>Spring Cloud Vault can obtain credentials for MySQL.
The integration can be enabled by setting
<literal>spring.cloud.vault.mysql.enabled=true</literal> (default <literal>false</literal>) and
providing the role name with <literal>spring.cloud.vault.mysql.role=…</literal>.</simpara>
<simpara>Username and password are stored in <literal>spring.datasource.username</literal>
and <literal>spring.datasource.password</literal> so using Spring Boot will
pick up the generated credentials without further configuration.
You can configure the property names by setting
<literal>spring.cloud.vault.mysql.username-property</literal> and
<literal>spring.cloud.vault.mysql.password-property</literal>.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
mysql:
enabled: true
role: readonly
backend: mysql
username-property: spring.datasource.username
password-property: spring.datasource.username</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>true</literal> enables the MySQL backend config usage</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal> sets the role name of the MySQL role definition</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the MySQL mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>username-property</literal> sets the property name in which the MySQL username is stored</simpara>
</listitem>
<listitem>
<simpara><literal>password-property</literal> sets the property name in which the MySQL password is stored</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/mysql/index.html">Vault Documentation: Setting up MySQL with Vault</link></simpara>
</section>
<section xml:id="vault.config.backends.postgresql">
<title>PostgreSQL</title>
<note>
<simpara>The <literal>postgresql</literal> backend has been deprecated in Vault 0.7.1 and
it is recommended to use the <literal>database</literal> backend and mount it as <literal>postgresql</literal>.
Configuration for <literal>spring.cloud.vault.postgresql</literal> will be removed in a future version.</simpara>
</note>
<simpara>Spring Cloud Vault can obtain credentials for PostgreSQL.
The integration can be enabled by setting
<literal>spring.cloud.vault.postgresql.enabled=true</literal> (default <literal>false</literal>) and
providing the role name with <literal>spring.cloud.vault.postgresql.role=…</literal>.</simpara>
<simpara>Username and password are stored in <literal>spring.datasource.username</literal>
and <literal>spring.datasource.password</literal> so using Spring Boot will
pick up the generated credentials without further configuration.
You can configure the property names by setting
<literal>spring.cloud.vault.postgresql.username-property</literal> and
<literal>spring.cloud.vault.postgresql.password-property</literal>.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
postgresql:
enabled: true
role: readonly
backend: postgresql
username-property: spring.datasource.username
password-property: spring.datasource.username</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>enabled</literal> setting this value to <literal>true</literal> enables the PostgreSQL backend config usage</simpara>
</listitem>
<listitem>
<simpara><literal>role</literal> sets the role name of the PostgreSQL role definition</simpara>
</listitem>
<listitem>
<simpara><literal>backend</literal> sets the path of the PostgreSQL mount to use</simpara>
</listitem>
<listitem>
<simpara><literal>username-property</literal> sets the property name in which the PostgreSQL username is stored</simpara>
</listitem>
<listitem>
<simpara><literal>password-property</literal> sets the property name in which the PostgreSQL password is stored</simpara>
</listitem>
</itemizedlist>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/secrets/postgresql/index.html">Vault Documentation: Setting up PostgreSQL with Vault</link></simpara>
</section>
</chapter>
<chapter xml:id="vault.config.backends.configurer">
<title>Configure <literal>PropertySourceLocator</literal> behavior</title>
<simpara>Spring Cloud Vault uses property-based configuration to create <literal>PropertySource</literal>s
for generic and discovered secret backends.</simpara>
<simpara>Discovered backends provide <literal>VaultSecretBackendDescriptor</literal> beans to describe the configuration
state to use secret backend as <literal>PropertySource</literal>. A <literal>SecretBackendMetadataFactory</literal> is required
to create a <literal>SecretBackendMetadata</literal> object which contains path, name and property transformation
configuration.</simpara>
<simpara><literal>SecretBackendMetadata</literal> is used to back a particular <literal>PropertySource</literal>.</simpara>
<simpara>You can register an arbitrary number of beans implementing <literal>VaultConfigurer</literal> for customization.
Default generic and discovered backend registration is disabled if Spring Cloud Vault discovers
at least one <literal>VaultConfigurer</literal> bean. You can however enable default registration with
<literal>SecretBackendConfigurer.registerDefaultGenericSecretBackends()</literal> and <literal>SecretBackendConfigurer.registerDefaultDiscoveredSecretBackends()</literal>.</simpara>
<informalexample>
<programlisting language="java" linenumbering="unnumbered">public class CustomizationBean implements VaultConfigurer {
@Override
public void addSecretBackends(SecretBackendConfigurer configurer) {
configurer.add("secret/my-application");
configurer.registerDefaultGenericSecretBackends(false);
configurer.registerDefaultDiscoveredSecretBackends(true);
}
}</programlisting>
</informalexample>
<note>
<simpara>All customization is required to happen in the bootstrap context. Add your configuration
classes to <literal>META-INF/spring.factories</literal> at <literal>org.springframework.cloud.bootstrap.BootstrapConfiguration</literal>
in your application.</simpara>
</note>
</chapter>
<chapter xml:id="_service_registry_configuration">
<title>Service Registry Configuration</title>
<simpara>You can use a <literal>DiscoveryClient</literal> (such as from Spring Cloud Consul) to locate
a Vault server by setting spring.cloud.vault.discovery.enabled=true (default <literal>false</literal>).
The net result of that is that your apps need a bootstrap.yml (or an environment variable)
with the appropriate discovery configuration.
The benefit is that the Vault can change its co-ordinates, as long as the discovery service
is a fixed point. The default service id is <literal>vault</literal> but you can change that on the client with
<literal>spring.cloud.vault.discovery.serviceId</literal>.</simpara>
<simpara>The discovery client implementations all support some kind of metadata map
(e.g. for Eureka we have eureka.instance.metadataMap). Some additional properties of the service
may need to be configured in its service registration metadata so that clients can connect
correctly. Service registries that do not provide details about transport layer security
need to provide a <literal>scheme</literal> metadata entry to be set either to <literal>https</literal> or <literal>http</literal>.
If no scheme is configured and the service is not exposed as secure service, then
configuration defaults to <literal>spring.cloud.vault.scheme</literal> which is <literal>https</literal> when it&#8217;s not set.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault.discovery:
enabled: true
service-id: my-vault-service</programlisting>
</informalexample>
</chapter>
<chapter xml:id="vault.config.fail-fast">
<title>Vault Client Fail Fast</title>
<simpara>In some cases, it may be desirable to fail startup of a service if
it cannot connect to the Vault Server. If this is the desired
behavior, set the bootstrap configuration property
<literal>spring.cloud.vault.fail-fast=true</literal> and the client will halt with
an Exception.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
fail-fast: true</programlisting>
</informalexample>
</chapter>
<chapter xml:id="vault.config.ssl">
<title>Vault Client SSL configuration</title>
<simpara>SSL can be configured declaratively by setting various properties.
You can set either <literal>javax.net.ssl.trustStore</literal> to configure
JVM-wide SSL settings or <literal>spring.cloud.vault.ssl.trust-store</literal>
to set SSL settings only for Spring Cloud Vault Config.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
ssl:
trust-store: classpath:keystore.jks
trust-store-password: changeit</programlisting>
</informalexample>
<itemizedlist>
<listitem>
<simpara><literal>trust-store</literal> sets the resource for the trust-store. SSL-secured Vault
communication will validate the Vault SSL certificate with the specified
trust-store.</simpara>
</listitem>
<listitem>
<simpara><literal>trust-store-password</literal> sets the trust-store password</simpara>
</listitem>
</itemizedlist>
<simpara>Please note that configuring <literal>spring.cloud.vault.ssl.*</literal> can be only
applied when either Apache Http Components or the OkHttp client
is on your class-path.</simpara>
</chapter>
<chapter xml:id="vault-lease-renewal">
<title>Lease lifecycle management (renewal and revocation)</title>
<simpara>With every secret, Vault creates a lease:
metadata containing information such as a time duration,
renewability, and more.</simpara>
<simpara>Vault promises that the data will be valid for the given duration,
or Time To Live (TTL). Once the lease is expired, Vault can
revoke the data, and the consumer of the secret can no longer
be certain that it is valid.</simpara>
<simpara>Spring Cloud Vault maintains a lease lifecycle beyond
the creation of login tokens and secrets. That said,
login tokens and secrets associated with a lease
are scheduled for renewal just before the lease expires
until terminal expiry.
Application shutdown revokes obtained login tokens and renewable
leases.</simpara>
<simpara>Secret service and database backends (such as MongoDB or MySQL)
usually generate a renewable lease so generated credentials will
be disabled on application shutdown.</simpara>
<note>
<simpara>Static tokens are not renewed or revoked.</simpara>
</note>
<simpara>Lease renewal and revocation is enabled by default and can
be disabled by setting <literal>spring.cloud.vault.config.lifecycle.enabled</literal>
to <literal>false</literal>. This is not recommended as leases can expire and
Spring Cloud Vault cannot longer access Vault or services
using generated credentials and valid credentials remain active
after application shutdown.</simpara>
<informalexample>
<programlisting language="yaml" linenumbering="unnumbered">spring.cloud.vault:
config.lifecycle.enabled: true</programlisting>
</informalexample>
<simpara>See also: <link xl:href="https://www.vaultproject.io/docs/concepts/lease.html">Vault Documentation: Lease, Renew, and Revoke</link></simpara>
</chapter>
</book>