diff --git a/antrun/build-main.xml b/antrun/build-main.xml new file mode 100644 index 00000000..cbb9cb27 --- /dev/null +++ b/antrun/build-main.xml @@ -0,0 +1,18 @@ + + + + :nofooter: +:linkcss: +:stylesdir: css +:stylesheet: manual-singlepage.css + += {docs-main} + +{spring-cloud-version} + +== Pick The Documentation Option + +- link:single/{docs-main}.html[Single HTML] +- link:multi/multi_{docs-main}.html[Multi HTML] + + \ No newline at end of file diff --git a/css/highlight.css b/css/highlight.css new file mode 100644 index 00000000..ffefef72 --- /dev/null +++ b/css/highlight.css @@ -0,0 +1,35 @@ +/* + code highlight CSS resemblign the Eclipse IDE default color schema + @author Costin Leau +*/ + +.hl-keyword { + color: #7F0055; + font-weight: bold; +} + +.hl-comment { + color: #3F5F5F; + font-style: italic; +} + +.hl-multiline-comment { + color: #3F5FBF; + font-style: italic; +} + +.hl-tag { + color: #3F7F7F; +} + +.hl-attribute { + color: #7F007F; +} + +.hl-value { + color: #2A00FF; +} + +.hl-string { + color: #2A00FF; +} \ No newline at end of file diff --git a/css/manual-multipage.css b/css/manual-multipage.css new file mode 100644 index 00000000..0c484531 --- /dev/null +++ b/css/manual-multipage.css @@ -0,0 +1,9 @@ +@IMPORT url("manual.css"); + +body.firstpage { + background: url("../images/background.png") no-repeat center top; +} + +div.part h1 { + border-top: none; +} diff --git a/css/manual-singlepage.css b/css/manual-singlepage.css new file mode 100644 index 00000000..4a7fd140 --- /dev/null +++ b/css/manual-singlepage.css @@ -0,0 +1,6 @@ +@IMPORT url("manual.css"); + +body { + background: url("../images/background.png") no-repeat center top; +} + diff --git a/css/manual.css b/css/manual.css new file mode 100644 index 00000000..0ecbe2e8 --- /dev/null +++ b/css/manual.css @@ -0,0 +1,344 @@ +@IMPORT url("highlight.css"); + +html { + padding: 0pt; + margin: 0pt; +} + +body { + color: #333333; + margin: 15px 30px; + font-family: Helvetica, Arial, Freesans, Clean, Sans-serif; + line-height: 1.6; + -webkit-font-smoothing: antialiased; +} + +code { + font-size: 16px; + font-family: Consolas, "Liberation Mono", Courier, monospace; +} + +:not(a)>code { + color: #6D180B; +} + +:not(pre)>code { + background-color: #F2F2F2; + border: 1px solid #CCCCCC; + border-radius: 4px; + padding: 1px 3px 0; + text-shadow: none; + white-space: nowrap; +} + +body>*:first-child { + margin-top: 0 !important; +} + +div { + margin: 0pt; +} + +hr { + border: 1px solid #CCCCCC; + background: #CCCCCC; +} + +h1,h2,h3,h4,h5,h6 { + color: #000000; + cursor: text; + font-weight: bold; + margin: 30px 0 10px; + padding: 0; +} + +h1,h2,h3 { + margin: 40px 0 10px; +} + +h1 { + margin: 70px 0 30px; + padding-top: 20px; +} + +div.part h1 { + border-top: 1px dotted #CCCCCC; +} + +h1,h1 code { + font-size: 32px; +} + +h2,h2 code { + font-size: 24px; +} + +h3,h3 code { + font-size: 20px; +} + +h4,h1 code,h5,h5 code,h6,h6 code { + font-size: 18px; +} + +div.book,div.chapter,div.appendix,div.part,div.preface { + min-width: 300px; + max-width: 1200px; + margin: 0 auto; +} + +p.releaseinfo { + font-weight: bold; + margin-bottom: 40px; + margin-top: 40px; +} + +div.authorgroup { + line-height: 1; +} + +p.copyright { + line-height: 1; + margin-bottom: -5px; +} + +.legalnotice p { + font-style: italic; + font-size: 14px; + line-height: 1; +} + +div.titlepage+p,div.titlepage+p { + margin-top: 0; +} + +pre { + line-height: 1.0; + color: black; +} + +a { + color: #4183C4; + text-decoration: none; +} + +p { + margin: 15px 0; + text-align: left; +} + +ul,ol { + padding-left: 30px; +} + +li p { + margin: 0; +} + +div.table { + margin: 1em; + padding: 0.5em; + text-align: center; +} + +div.table table,div.informaltable table { + display: table; + width: 100%; +} + +div.table td { + padding-left: 7px; + padding-right: 7px; +} + +.sidebar { + line-height: 1.4; + padding: 0 20px; + background-color: #F8F8F8; + border: 1px solid #CCCCCC; + border-radius: 3px 3px 3px 3px; +} + +.sidebar p.title { + color: #6D180B; +} + +pre.programlisting,pre.screen { + font-size: 15px; + padding: 6px 10px; + background-color: #F8F8F8; + border: 1px solid #CCCCCC; + border-radius: 3px 3px 3px 3px; + clear: both; + overflow: auto; + line-height: 1.4; + font-family: Consolas, "Liberation Mono", Courier, monospace; +} + +table { + border-collapse: collapse; + border-spacing: 0; + border: 1px solid #DDDDDD !important; + border-radius: 4px !important; + border-collapse: separate !important; + line-height: 1.6; +} + +table thead { + background: #F5F5F5; +} + +table tr { + border: none; + border-bottom: none; +} + +table th { + font-weight: bold; +} + +table th,table td { + border: none !important; + padding: 6px 13px; +} + +table tr:nth-child(2n) { + background-color: #F8F8F8; +} + +td p { + margin: 0 0 15px 0; +} + +div.table-contents td p { + margin: 0; +} + +div.important *,div.note *,div.tip *,div.warning *,div.navheader *,div.navfooter *,div.calloutlist * + { + border: none !important; + background: none !important; + margin: 0; +} + +div.important p,div.note p,div.tip p,div.warning p { + color: #6F6F6F; + line-height: 1.6; +} + +div.important code,div.note code,div.tip code,div.warning code { + background-color: #F2F2F2 !important; + border: 1px solid #CCCCCC !important; + border-radius: 4px !important; + padding: 1px 3px 0 !important; + text-shadow: none !important; + white-space: nowrap !important; +} + +.note th,.tip th,.warning th { + display: none; +} + +.note tr:first-child td,.tip tr:first-child td,.warning tr:first-child td + { + border-right: 1px solid #CCCCCC !important; + padding-top: 10px; +} + +div.calloutlist p,div.calloutlist td { + padding: 0; + margin: 0; +} + +div.calloutlist>table>tbody>tr>td:first-child { + padding-left: 10px; + width: 30px !important; +} + +div.important,div.note,div.tip,div.warning { + margin-left: 0px !important; + margin-right: 20px !important; + margin-top: 20px; + margin-bottom: 20px; + padding-top: 10px; + padding-bottom: 10px; +} + +div.toc { + line-height: 1.2; +} + +dl,dt { + margin-top: 1px; + margin-bottom: 0; +} + +div.toc>dl>dt { + font-size: 32px; + font-weight: bold; + margin: 30px 0 10px 0; + display: block; +} + +div.toc>dl>dd>dl>dt { + font-size: 24px; + font-weight: bold; + margin: 20px 0 10px 0; + display: block; +} + +div.toc>dl>dd>dl>dd>dl>dt { + font-weight: bold; + font-size: 20px; + margin: 10px 0 0 0; +} + +tbody.footnotes * { + border: none !important; +} + +div.footnote p { + margin: 0; + line-height: 1; +} + +div.footnote p sup { + margin-right: 6px; + vertical-align: middle; +} + +div.navheader { + border-bottom: 1px solid #CCCCCC; +} + +div.navfooter { + border-top: 1px solid #CCCCCC; +} + +.title { + margin-left: -1em; + padding-left: 1em; +} + +.title>a { + position: absolute; + visibility: hidden; + display: block; + font-size: 0.85em; + margin-top: 0.05em; + margin-left: -1em; + vertical-align: text-top; + color: black; +} + +.title>a:before { + content: "\00A7"; +} + +.title:hover>a,.title>a:hover,.title:hover>a:hover { + visibility: visible; +} + +.title:focus>a,.title>a:focus,.title:focus>a:focus { + outline: 0; +} diff --git a/images/background.png b/images/background.png new file mode 100644 index 00000000..15dca6fb Binary files /dev/null and b/images/background.png differ diff --git a/images/caution.png b/images/caution.png new file mode 100644 index 00000000..8a5e4fca Binary files /dev/null and b/images/caution.png differ diff --git a/images/important.png b/images/important.png new file mode 100644 index 00000000..ec54df65 Binary files /dev/null and b/images/important.png differ diff --git a/images/logo.png b/images/logo.png new file mode 100644 index 00000000..ade2ce6e Binary files /dev/null and b/images/logo.png differ diff --git a/images/note.png b/images/note.png new file mode 100644 index 00000000..88d997b1 Binary files /dev/null and b/images/note.png differ diff --git a/images/sts_exception.png b/images/sts_exception.png new file mode 100644 index 00000000..8607c38a Binary files /dev/null and b/images/sts_exception.png differ diff --git a/images/tip.png b/images/tip.png new file mode 100644 index 00000000..6530abb4 Binary files /dev/null and b/images/tip.png differ diff --git a/images/warning.png b/images/warning.png new file mode 100644 index 00000000..0d5b5244 Binary files /dev/null and b/images/warning.png differ diff --git a/images/web-selected.png b/images/web-selected.png new file mode 100644 index 00000000..aa6b2da6 Binary files /dev/null and b/images/web-selected.png differ diff --git a/multi/css/highlight.css b/multi/css/highlight.css new file mode 100644 index 00000000..ffefef72 --- /dev/null +++ b/multi/css/highlight.css @@ -0,0 +1,35 @@ +/* + code highlight CSS resemblign the Eclipse IDE default color schema + @author Costin Leau +*/ + +.hl-keyword { + color: #7F0055; + font-weight: bold; +} + +.hl-comment { + color: #3F5F5F; + font-style: italic; +} + +.hl-multiline-comment { + color: #3F5FBF; + font-style: italic; +} + +.hl-tag { + color: #3F7F7F; +} + +.hl-attribute { + color: #7F007F; +} + +.hl-value { + color: #2A00FF; +} + +.hl-string { + color: #2A00FF; +} \ No newline at end of file diff --git a/multi/css/manual-multipage.css b/multi/css/manual-multipage.css new file mode 100644 index 00000000..0c484531 --- /dev/null +++ b/multi/css/manual-multipage.css @@ -0,0 +1,9 @@ +@IMPORT url("manual.css"); + +body.firstpage { + background: url("../images/background.png") no-repeat center top; +} + +div.part h1 { + border-top: none; +} diff --git a/multi/css/manual-singlepage.css b/multi/css/manual-singlepage.css new file mode 100644 index 00000000..4a7fd140 --- /dev/null +++ b/multi/css/manual-singlepage.css @@ -0,0 +1,6 @@ +@IMPORT url("manual.css"); + +body { + background: url("../images/background.png") no-repeat center top; +} + diff --git a/multi/css/manual.css b/multi/css/manual.css new file mode 100644 index 00000000..0ecbe2e8 --- /dev/null +++ b/multi/css/manual.css @@ -0,0 +1,344 @@ +@IMPORT url("highlight.css"); + +html { + padding: 0pt; + margin: 0pt; +} + +body { + color: #333333; + margin: 15px 30px; + font-family: Helvetica, Arial, Freesans, Clean, Sans-serif; + line-height: 1.6; + -webkit-font-smoothing: antialiased; +} + +code { + font-size: 16px; + font-family: Consolas, "Liberation Mono", Courier, monospace; +} + +:not(a)>code { + color: #6D180B; +} + +:not(pre)>code { + background-color: #F2F2F2; + border: 1px solid #CCCCCC; + border-radius: 4px; + padding: 1px 3px 0; + text-shadow: none; + white-space: nowrap; +} + +body>*:first-child { + margin-top: 0 !important; +} + +div { + margin: 0pt; +} + +hr { + border: 1px solid #CCCCCC; + background: #CCCCCC; +} + +h1,h2,h3,h4,h5,h6 { + color: #000000; + cursor: text; + font-weight: bold; + margin: 30px 0 10px; + padding: 0; +} + +h1,h2,h3 { + margin: 40px 0 10px; +} + +h1 { + margin: 70px 0 30px; + padding-top: 20px; +} + +div.part h1 { + border-top: 1px dotted #CCCCCC; +} + +h1,h1 code { + font-size: 32px; +} + +h2,h2 code { + font-size: 24px; +} + +h3,h3 code { + font-size: 20px; +} + +h4,h1 code,h5,h5 code,h6,h6 code { + font-size: 18px; +} + +div.book,div.chapter,div.appendix,div.part,div.preface { + min-width: 300px; + max-width: 1200px; + margin: 0 auto; +} + +p.releaseinfo { + font-weight: bold; + margin-bottom: 40px; + margin-top: 40px; +} + +div.authorgroup { + line-height: 1; +} + +p.copyright { + line-height: 1; + margin-bottom: -5px; +} + +.legalnotice p { + font-style: italic; + font-size: 14px; + line-height: 1; +} + +div.titlepage+p,div.titlepage+p { + margin-top: 0; +} + +pre { + line-height: 1.0; + color: black; +} + +a { + color: #4183C4; + text-decoration: none; +} + +p { + margin: 15px 0; + text-align: left; +} + +ul,ol { + padding-left: 30px; +} + +li p { + margin: 0; +} + +div.table { + margin: 1em; + padding: 0.5em; + text-align: center; +} + +div.table table,div.informaltable table { + display: table; + width: 100%; +} + +div.table td { + padding-left: 7px; + padding-right: 7px; +} + +.sidebar { + line-height: 1.4; + padding: 0 20px; + background-color: #F8F8F8; + border: 1px solid #CCCCCC; + border-radius: 3px 3px 3px 3px; +} + +.sidebar p.title { + color: #6D180B; +} + +pre.programlisting,pre.screen { + font-size: 15px; + padding: 6px 10px; + background-color: #F8F8F8; + border: 1px solid #CCCCCC; + border-radius: 3px 3px 3px 3px; + clear: both; + overflow: auto; + line-height: 1.4; + font-family: Consolas, "Liberation Mono", Courier, monospace; +} + +table { + border-collapse: collapse; + border-spacing: 0; + border: 1px solid #DDDDDD !important; + border-radius: 4px !important; + border-collapse: separate !important; + line-height: 1.6; +} + +table thead { + background: #F5F5F5; +} + +table tr { + border: none; + border-bottom: none; +} + +table th { + font-weight: bold; +} + +table th,table td { + border: none !important; + padding: 6px 13px; +} + +table tr:nth-child(2n) { + background-color: #F8F8F8; +} + +td p { + margin: 0 0 15px 0; +} + +div.table-contents td p { + margin: 0; +} + +div.important *,div.note *,div.tip *,div.warning *,div.navheader *,div.navfooter *,div.calloutlist * + { + border: none !important; + background: none !important; + margin: 0; +} + +div.important p,div.note p,div.tip p,div.warning p { + color: #6F6F6F; + line-height: 1.6; +} + +div.important code,div.note code,div.tip code,div.warning code { + background-color: #F2F2F2 !important; + border: 1px solid #CCCCCC !important; + border-radius: 4px !important; + padding: 1px 3px 0 !important; + text-shadow: none !important; + white-space: nowrap !important; +} + +.note th,.tip th,.warning th { + display: none; +} + +.note tr:first-child td,.tip tr:first-child td,.warning tr:first-child td + { + border-right: 1px solid #CCCCCC !important; + padding-top: 10px; +} + +div.calloutlist p,div.calloutlist td { + padding: 0; + margin: 0; +} + +div.calloutlist>table>tbody>tr>td:first-child { + padding-left: 10px; + width: 30px !important; +} + +div.important,div.note,div.tip,div.warning { + margin-left: 0px !important; + margin-right: 20px !important; + margin-top: 20px; + margin-bottom: 20px; + padding-top: 10px; + padding-bottom: 10px; +} + +div.toc { + line-height: 1.2; +} + +dl,dt { + margin-top: 1px; + margin-bottom: 0; +} + +div.toc>dl>dt { + font-size: 32px; + font-weight: bold; + margin: 30px 0 10px 0; + display: block; +} + +div.toc>dl>dd>dl>dt { + font-size: 24px; + font-weight: bold; + margin: 20px 0 10px 0; + display: block; +} + +div.toc>dl>dd>dl>dd>dl>dt { + font-weight: bold; + font-size: 20px; + margin: 10px 0 0 0; +} + +tbody.footnotes * { + border: none !important; +} + +div.footnote p { + margin: 0; + line-height: 1; +} + +div.footnote p sup { + margin-right: 6px; + vertical-align: middle; +} + +div.navheader { + border-bottom: 1px solid #CCCCCC; +} + +div.navfooter { + border-top: 1px solid #CCCCCC; +} + +.title { + margin-left: -1em; + padding-left: 1em; +} + +.title>a { + position: absolute; + visibility: hidden; + display: block; + font-size: 0.85em; + margin-top: 0.05em; + margin-left: -1em; + vertical-align: text-top; + color: black; +} + +.title>a:before { + content: "\00A7"; +} + +.title:hover>a,.title>a:hover,.title:hover>a:hover { + visibility: visible; +} + +.title:focus>a,.title>a:focus,.title:focus>a:focus { + outline: 0; +} diff --git a/multi/images/background.png b/multi/images/background.png new file mode 100644 index 00000000..15dca6fb Binary files /dev/null and b/multi/images/background.png differ diff --git a/multi/images/caution.png b/multi/images/caution.png new file mode 100644 index 00000000..8a5e4fca Binary files /dev/null and b/multi/images/caution.png differ diff --git a/multi/images/important.png b/multi/images/important.png new file mode 100644 index 00000000..ec54df65 Binary files /dev/null and b/multi/images/important.png differ diff --git a/multi/images/logo.png b/multi/images/logo.png new file mode 100644 index 00000000..ade2ce6e Binary files /dev/null and b/multi/images/logo.png differ diff --git a/multi/images/note.png b/multi/images/note.png new file mode 100644 index 00000000..88d997b1 Binary files /dev/null and b/multi/images/note.png differ diff --git a/multi/images/sts_exception.png b/multi/images/sts_exception.png new file mode 100644 index 00000000..8607c38a Binary files /dev/null and b/multi/images/sts_exception.png differ diff --git a/multi/images/tip.png b/multi/images/tip.png new file mode 100644 index 00000000..6530abb4 Binary files /dev/null and b/multi/images/tip.png differ diff --git a/multi/images/warning.png b/multi/images/warning.png new file mode 100644 index 00000000..0d5b5244 Binary files /dev/null and b/multi/images/warning.png differ diff --git a/multi/images/web-selected.png b/multi/images/web-selected.png new file mode 100644 index 00000000..aa6b2da6 Binary files /dev/null and b/multi/images/web-selected.png differ diff --git a/multi/multi__client_side_usage.html b/multi/multi__client_side_usage.html new file mode 100644 index 00000000..52f292b8 --- /dev/null +++ b/multi/multi__client_side_usage.html @@ -0,0 +1,67 @@ + + + 2. Client Side Usage

2. Client Side Usage

To use these features in an application, just build it as a Spring +Boot application that depends on spring-cloud-vault-config (e.g. see +the test cases). Example Maven configuration:

Example 2.1. pom.xml

<parent>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-parent</artifactId>
+    <version>1.5.4.RELEASE</version>
+    <relativePath /> <!-- lookup parent from repository -->
+</parent>
+
+<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-starter-vault-config</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-test</artifactId>
+        <scope>test</scope>
+    </dependency>
+</dependencies>
+
+<build>
+    <plugins>
+        <plugin>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-maven-plugin</artifactId>
+        </plugin>
+    </plugins>
+</build>
+
+<!-- repositories also needed for snapshots and milestones -->

Then you can create a standard Spring Boot application, like this simple HTTP server:

@SpringBootApplication
+@RestController
+public class Application {
+
+    @RequestMapping("/")
+    public String home() {
+        return "Hello World!";
+    }
+
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+}

When it runs it will pick up the external configuration from the +default local Vault server on port 8200 if it is running. To modify +the startup behavior you can change the location of the Vault server +using bootstrap.properties (like application.properties but for +the bootstrap phase of an application context), e.g.

Example 2.2. bootstrap.yml

spring.cloud.vault:
+    host: localhost
+    port: 8200
+    scheme: https
+    uri: https://localhost:8200
+    connection-timeout: 5000
+    read-timeout: 15000
+    config:
+        order: -10

Enabling further integrations requires additional dependencies and +configuration. Depending on how you have set up Vault you might need +additional configuration like +SSL and +authentication.

If the application imports the spring-boot-starter-actuator project, the +status of the vault server will be available via the /health endpoint.

The vault health indicator can be enabled or disabled through the +property health.vault.enabled (default true).

2.1 Authentication

Vault requires an authentication mechanism to authorize client requests.

Spring Cloud Vault supports multiple authentication mechanisms to authenticate applications with Vault.

For a quickstart, use the root token printed by the Vault initialization.

Example 2.3. bootstrap.yml

spring.cloud.vault:
+    token: 19aefa97-cccc-bbbb-aaaa-225940e63d76

[Warning]Warning

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.

\ No newline at end of file diff --git a/multi/multi__quick_start.html b/multi/multi__quick_start.html new file mode 100644 index 00000000..bac5384d --- /dev/null +++ b/multi/multi__quick_start.html @@ -0,0 +1,37 @@ + + + 1. Quick Start

1. Quick Start

Prerequisites

To get started with Vault and this guide you need a +*NIX-like operating systems that provides:

Install Vault

$ src/test/bash/install_vault.sh

Create SSL certificates for Vault

$ src/test/bash/create_certificates.sh
[Note]Note

create_certificates.sh creates certificates in work/ca and a JKS truststore work/keystore.jks. If you want to run Spring Cloud Vault using this quickstart guide you need to configure the truststore the spring.cloud.vault.ssl.trust-store property to file:work/keystore.jks.

Start Vault server

$ src/test/bash/local_run_vault.sh

Vault is started listening on 0.0.0.0:8200 using the inmem storage and +https. +Vault is sealed and not initialized when starting up.

[Note]Note

If you want to run tests, leave Vault uninitialized. The tests will +initialize Vault and create a root token 00000000-0000-0000-0000-000000000000.

If you want to use Vault for your application or give it a try then you need to initialize it first.

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

You should see something like:

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 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 VAULT_TOKEN + environment variable.

$ 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 accesses different resources. By default, the secret +backend is enabled which accesses secret config settings via JSON endpoints.

The HTTP service has resources in the form:

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

where the "application" is injected as the spring.application.name in the +SpringApplication (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.

\ No newline at end of file diff --git a/multi/multi__service_registry_configuration.html b/multi/multi__service_registry_configuration.html new file mode 100644 index 00000000..0631a3f7 --- /dev/null +++ b/multi/multi__service_registry_configuration.html @@ -0,0 +1,17 @@ + + + 7. Service Registry Configuration

7. Service Registry Configuration

You can use a DiscoveryClient (such as from Spring Cloud Consul) to locate +a Vault server by setting spring.cloud.vault.discovery.enabled=true (default false). +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 vault but you can change that on the client with +spring.cloud.vault.discovery.serviceId.

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 scheme metadata entry to be set either to https or http. +If no scheme is configured and the service is not exposed as secure service, then +configuration defaults to spring.cloud.vault.scheme which is https when it’s not set.

spring.cloud.vault.discovery:
+    enabled: true
+    service-id: my-vault-service
\ No newline at end of file diff --git a/multi/multi_pr01.html b/multi/multi_pr01.html new file mode 100644 index 00000000..7fad193c --- /dev/null +++ b/multi/multi_pr01.html @@ -0,0 +1,3 @@ + + +

© 2016-2017 The original authors.

[Note]Note

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.

Spring Cloud Vault Config provides client-side support for externalized configuration in a distributed system. With HashiCorp’s Vault 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.

\ No newline at end of file diff --git a/multi/multi_spring-cloud-vault.html b/multi/multi_spring-cloud-vault.html new file mode 100644 index 00000000..a6a2b6ad --- /dev/null +++ b/multi/multi_spring-cloud-vault.html @@ -0,0 +1,3 @@ + + + Spring Cloud Vault

Spring Cloud Vault


Table of Contents

1. Quick Start
2. Client Side Usage
2.1. Authentication
3. Authentication methods
3.1. Token authentication
3.2. AppId authentication
3.2.1. Custom UserId
3.3. AppRole authentication
3.4. AWS-EC2 authentication
3.5. TLS certificate authentication
3.6. Cubbyhole authentication
4. Secret Backends
4.1. Generic Backend
4.2. Consul
4.3. RabbitMQ
4.4. AWS
5. Database backends
5.1. Apache Cassandra
5.2. MongoDB
5.3. MySQL
5.4. PostgreSQL
6. Configure PropertySourceLocator behavior
7. Service Registry Configuration
8. Vault Client Fail Fast
9. Vault Client SSL configuration
10. Lease lifecycle management (renewal and revocation)
\ No newline at end of file diff --git a/multi/multi_vault-lease-renewal.html b/multi/multi_vault-lease-renewal.html new file mode 100644 index 00000000..e5fcbbb8 --- /dev/null +++ b/multi/multi_vault-lease-renewal.html @@ -0,0 +1,22 @@ + + + 10. Lease lifecycle management (renewal and revocation)

10. Lease lifecycle management (renewal and revocation)

With every secret, Vault creates a lease: +metadata containing information such as a time duration, +renewability, and more.

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.

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.

Secret service and database backends (such as MongoDB or MySQL) +usually generate a renewable lease so generated credentials will +be disabled on application shutdown.

[Note]Note

Static tokens are not renewed or revoked.

Lease renewal and revocation is enabled by default and can +be disabled by setting spring.cloud.vault.config.lifecycle.enabled +to false. 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.

spring.cloud.vault:
+    config.lifecycle.enabled: true

See also: Vault Documentation: Lease, Renew, and Revoke

\ No newline at end of file diff --git a/multi/multi_vault.config.authentication.html b/multi/multi_vault.config.authentication.html new file mode 100644 index 00000000..eb38c56a --- /dev/null +++ b/multi/multi_vault.config.authentication.html @@ -0,0 +1,113 @@ + + + 3. Authentication methods

3. Authentication methods

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.

3.1 Token authentication

Tokens are the core method for authentication within Vault. +Token authentication requires a static token to be provided using the +Bootstrap Application Context.

[Note]Note

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.

Example 3.1. bootstrap.yml

spring.cloud.vault:
+    authentication: TOKEN
+    token: 00000000-0000-0000-0000-000000000000

  • authentication setting this value to TOKEN selects the Token +authentication method
  • token sets the static token to use

See also: Vault Documentation: Tokens

3.2 AppId authentication

Vault supports AppId +authentication that consists of two hard to guess tokens. The AppId +defaults to spring.application.name 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’s (e.g. supplied via System properties). +The IP and Mac address are represented as Hex-encoded SHA256 hash.

IP address-based UserId’s use the local host’s IP address.

Example 3.2. bootstrap.yml using SHA256 IP-Address UserId’s

spring.cloud.vault:
+    authentication: APPID
+    app-id:
+        user-id: IP_ADDRESS

  • authentication setting this value to APPID selects the AppId +authentication method
  • app-id-path sets the path of the AppId mount to use
  • user-id sets the UserId method. Possible values are IP_ADDRESS, +MAC_ADDRESS or a class name implementing a custom AppIdUserIdMechanism

The corresponding command to generate the IP address UserId from a command line is:

$ echo -n 192.168.99.1 | sha256sum
[Note]Note

Including the line break of echo leads to a different hash value +so make sure to include the -n flag.

Mac address-based UserId’s obtain their network device from the +localhost-bound device. The configuration also allows specifying +a network-interface hint to pick the right device. The value of +network-interface is optional and can be either an interface +name or interface index (0-based).

Example 3.3. bootstrap.yml using SHA256 Mac-Address UserId’s

spring.cloud.vault:
+    authentication: APPID
+    app-id:
+        user-id: MAC_ADDRESS
+        network-interface: eth0

  • network-interface sets network interface to obtain the physical address

The corresponding command to generate the IP address UserId from a command line is:

$ echo -n 0AFEDE1234AC | sha256sum
[Note]Note

The Mac address is specified uppercase and without colons. +Including the line break of echo leads to a different hash value +so make sure to include the -n flag.

3.2.1 Custom UserId

The UserId generation is an open mechanism. You can set +spring.cloud.vault.app-id.user-id to any string and the configured +value will be used as static UserId.

A more advanced approach lets you set spring.cloud.vault.app-id.user-id to a +classname. This class must be on your classpath and must implement +the org.springframework.cloud.vault.AppIdUserIdMechanism interface +and the createUserId method. Spring Cloud Vault will obtain the UserId +by calling createUserId each time it authenticates using AppId to +obtain a token.

Example 3.4. bootstrap.yml

spring.cloud.vault:
+    authentication: APPID
+    app-id:
+        user-id: com.examlple.MyUserIdMechanism

Example 3.5. MyUserIdMechanism.java

public class MyUserIdMechanism implements AppIdUserIdMechanism {
+
+  @Override
+  public String createUserId() {
+    String userId = ...
+    return userId;
+  }
+}

See also: Vault Documentation: Using the App ID auth backend

3.3 AppRole authentication

AppRole is intended for machine +authentication, like the deprecated (since Vault 0.6.1) Section 3.2, “AppId authentication”. +AppRole authentication consists of two hard to guess (secret) tokens: RoleId and SecretId.

Spring Vault supports AppRole authentication by providing either RoleId only +or together with a provided SecretId (push or pull mode).

RoleId and optionally SecretId must be provided by configuration, +Spring Vault will not look up these or create a custom SecretId.

Example 3.6. bootstrap.yml with AppRole authentication properties

spring.cloud.vault:
+    authentication: APPROLE
+    app-role:
+        role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52

  • role-id sets the RoleId.

Example 3.7. bootstrap.yml with all AppRole authentication properties

spring.cloud.vault:
+    authentication: APPROLE
+    app-role:
+        role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52
+        secret-id: 1696536f-1976-73b1-b241-0b4213908d39
+        app-auth-path: approle

  • role-id sets the RoleId.
  • secret-id sets the SecretId. SecretId can be omitted if AppRole is configured without requiring SecretId (See bind_secret_id)
  • approle-path sets the path of the approle authentication mount to use

See also: Vault Documentation: Using the AppRole auth backend

3.4 AWS-EC2 authentication

The aws-ec2 +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.

Example 3.8. bootstrap.yml using AWS-EC2 Authentication

spring.cloud.vault:
+    authentication: AWS_EC2

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.

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.

The nonce is kept in memory and is lost during application restart. +You can configure a static nonce with spring.cloud.vault.aws-ec2.nonce.

AWS-EC2 authentication roles are optional and default to the AMI. +You can configure the authentication role by setting the +spring.cloud.vault.aws-ec2.role property.

Example 3.9. bootstrap.yml with configured role

spring.cloud.vault:
+    authentication: AWS_EC2
+    aws-ec2:
+        role: application-server

Example 3.10. bootstrap.yml with all AWS EC2 authentication properties

spring.cloud.vault:
+    authentication: AWS_EC2
+    aws-ec2:
+        role: application-server
+        aws-ec2-path: aws-ec2
+        identity-document: http://...
+        nonce: my-static-nonce

  • authentication setting this value to AWS_EC2 selects the AWS EC2 +authentication method
  • role sets the role name of the AWS EC2 role definition
  • aws-ec2-path sets the path of the AWS EC2 mount to use
  • identity-document sets URL of the PKCS#7 AWS EC2 identity document
  • nonce used for AWS-EC2 authentication. An empty nonce defaults to nonce generation

See also: Vault Documentation: Using the aws-ec2 auth backend

3.5 TLS certificate authentication

The cert auth backend allows authentication using SSL/TLS client +certificates that are either signed by a CA or self-signed.

To enable cert authentication you need to:

  1. Use SSL, see Chapter 9, Vault Client SSL configuration
  2. Configure a Java Keystore that contains the client +certificate and the private key
  3. Set the spring.cloud.vault.authentication to CERT

Example 3.11. bootstrap.yml

spring.cloud.vault:
+    authentication: CERT
+    ssl:
+        key-store: classpath:keystore.jks
+        key-store-password: changeit
+        cert-auth-path: cert

See also: Vault Documentation: Using the Cert auth backend

3.6 Cubbyhole authentication

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’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 /cubbyhole/response.

Creating a wrapped token

[Note]Note

Response Wrapping for token creation requires Vault 0.6.0 or higher.

Example 3.12. Crating and storing tokens

$ 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

Example 3.13. bootstrap.yml

spring.cloud.vault:
+    authentication: CUBBYHOLE
+    token: 397ccb93-ff6c-b17b-9389-380b01ca2645

See also:

\ No newline at end of file diff --git a/multi/multi_vault.config.backends.configurer.html b/multi/multi_vault.config.backends.configurer.html new file mode 100644 index 00000000..feecb534 --- /dev/null +++ b/multi/multi_vault.config.backends.configurer.html @@ -0,0 +1,22 @@ + + + 6. Configure PropertySourceLocator behavior

6. Configure PropertySourceLocator behavior

Spring Cloud Vault uses property-based configuration to create PropertySources +for generic and discovered secret backends.

Discovered backends provide VaultSecretBackendDescriptor beans to describe the configuration +state to use secret backend as PropertySource. A SecretBackendMetadataFactory is required +to create a SecretBackendMetadata object which contains path, name and property transformation +configuration.

SecretBackendMetadata is used to back a particular PropertySource.

You can register an arbitrary number of beans implementing VaultConfigurer for customization. +Default generic and discovered backend registration is disabled if Spring Cloud Vault discovers +at least one VaultConfigurer bean. You can however enable default registration with +SecretBackendConfigurer.registerDefaultGenericSecretBackends() and SecretBackendConfigurer.registerDefaultDiscoveredSecretBackends().

public class CustomizationBean implements VaultConfigurer {
+
+    @Override
+    public void addSecretBackends(SecretBackendConfigurer configurer) {
+
+        configurer.add("secret/my-application");
+
+        configurer.registerDefaultGenericSecretBackends(false);
+        configurer.registerDefaultDiscoveredSecretBackends(true);
+    }
+}
[Note]Note

All customization is required to happen in the bootstrap context. Add your configuration +classes to META-INF/spring.factories at org.springframework.cloud.bootstrap.BootstrapConfiguration +in your application.

\ No newline at end of file diff --git a/multi/multi_vault.config.backends.database-backends.html b/multi/multi_vault.config.backends.database-backends.html new file mode 100644 index 00000000..fd58ccd7 --- /dev/null +++ b/multi/multi_vault.config.backends.database-backends.html @@ -0,0 +1,73 @@ + + + 5. Database backends

5. Database backends

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’s leasing +mechanism to more easily roll keys.

Spring Cloud Vault integrates with these backends:

Using a database secret backend requires to enable the +backend in the configuration and the spring-cloud-vault-config-databases +dependency.

Example 5.1. pom.xml

<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-vault-config-databases</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+</dependencies>

[Note]Note

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.

5.1 Apache Cassandra

Spring Cloud Vault can obtain credentials for Apache Cassandra. +The integration can be enabled by setting +spring.cloud.vault.cassandra.enabled=true (default false) and +providing the role name with spring.cloud.vault.cassandra.role=….

Username and password are stored in spring.data.cassandra.username +and spring.data.cassandra.password so using Spring Boot will pick +up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.cassandra.username-property and +spring.cloud.vault.cassandra.password-property.

spring.cloud.vault:
+    cassandra:
+        enabled: true
+        role: readonly
+        backend: cassandra
+        username-property: spring.data.cassandra.username
+        password-property: spring.data.cassandra.username
  • enabled setting this value to true enables the Cassandra backend config usage
  • role sets the role name of the Cassandra role definition
  • backend sets the path of the Cassandra mount to use
  • username-property sets the property name in which the Cassandra username is stored
  • password-property sets the property name in which the Cassandra password is stored

See also: Vault Documentation: Setting up Apache Cassandra with Vault

5.2 MongoDB

Spring Cloud Vault can obtain credentials for MongoDB. +The integration can be enabled by setting +spring.cloud.vault.mongodb.enabled=true (default false) and +providing the role name with spring.cloud.vault.mongodb.role=….

Username and password are stored in spring.data.mongodb.username +and spring.data.mongodb.password so using Spring Boot will +pick up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.mongodb.username-property and +spring.cloud.vault.mongodb.password-property.

spring.cloud.vault:
+    mongodb:
+        enabled: true
+        role: readonly
+        backend: mongodb
+        username-property: spring.data.mongodb.username
+        password-property: spring.data.mongodb.password
  • enabled setting this value to true enables the MongodB backend config usage
  • role sets the role name of the MongoDB role definition
  • backend sets the path of the MongoDB mount to use
  • username-property sets the property name in which the MongoDB username is stored
  • password-property sets the property name in which the MongoDB password is stored

See also: Vault Documentation: Setting up MongoDB with Vault

5.3 MySQL

Spring Cloud Vault can obtain credentials for MySQL. +The integration can be enabled by setting +spring.cloud.vault.mysql.enabled=true (default false) and +providing the role name with spring.cloud.vault.mysql.role=….

Username and password are stored in spring.datasource.username +and spring.datasource.password so using Spring Boot will +pick up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.mysql.username-property and +spring.cloud.vault.mysql.password-property.

spring.cloud.vault:
+    mysql:
+        enabled: true
+        role: readonly
+        backend: mysql
+        username-property: spring.datasource.username
+        password-property: spring.datasource.username
  • enabled setting this value to true enables the MySQL backend config usage
  • role sets the role name of the MySQL role definition
  • backend sets the path of the MySQL mount to use
  • username-property sets the property name in which the MySQL username is stored
  • password-property sets the property name in which the MySQL password is stored

See also: Vault Documentation: Setting up MySQL with Vault

5.4 PostgreSQL

Spring Cloud Vault can obtain credentials for PostgreSQL. +The integration can be enabled by setting +spring.cloud.vault.postgresql.enabled=true (default false) and +providing the role name with spring.cloud.vault.postgresql.role=….

Username and password are stored in spring.datasource.username +and spring.datasource.password so using Spring Boot will +pick up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.postgresql.username-property and +spring.cloud.vault.postgresql.password-property.

spring.cloud.vault:
+    postgresql:
+        enabled: true
+        role: readonly
+        backend: postgresql
+        username-property: spring.datasource.username
+        password-property: spring.datasource.username
  • enabled setting this value to true enables the PostgreSQL backend config usage
  • role sets the role name of the PostgreSQL role definition
  • backend sets the path of the PostgreSQL mount to use
  • username-property sets the property name in which the PostgreSQL username is stored
  • password-property sets the property name in which the PostgreSQL password is stored

See also: Vault Documentation: Setting up PostgreSQL with Vault

\ No newline at end of file diff --git a/multi/multi_vault.config.backends.html b/multi/multi_vault.config.backends.html new file mode 100644 index 00000000..854148f6 --- /dev/null +++ b/multi/multi_vault.config.backends.html @@ -0,0 +1,79 @@ + + + 4. Secret Backends

4. Secret Backends

4.1 Generic Backend

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 (application) in combination with active +profiles.

/secret/{application}/{profile}
+/secret/{application}
+/secret/{default-context}/{profile}
+/secret/{default-context}

The application name is determined by the properties:

  • spring.cloud.vault.generic.application-name
  • spring.cloud.vault.application-name
  • spring.application.name

Secrets can be obtained from other folders within the generic backend by adding their +paths to the application name, separated by commas. For example, given the application +name usefulapp,mysql1,projectx/aws, each of these folders will be used:

  • /secret/usefulapp
  • /secret/mysql1
  • /secret/projectx/aws

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.

Properties are exposed like they are stored (i.e. without additional prefixes).

spring.cloud.vault:
+    generic:
+        enabled: true
+        backend: secret
+        profile-separator: '/'
+        default-context: application
+        application-name: my-app
  • enabled setting this value to false disables the secret backend +config usage
  • backend sets the path of the secret mount to use
  • default-context sets the context name used by all applications
  • application-name overrides the application name for use in the generic backend
  • profile-separator separates the profile name from the context in +property sources with profiles

See also: Vault Documentation: Using the generic secret backend

4.2 Consul

Spring Cloud Vault can obtain credentials for HashiCorp Consul. +The Consul integration requires the spring-cloud-vault-config-consul +dependency.

Example 4.1. pom.xml

<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-vault-config-consul</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+</dependencies>

The integration can be enabled by setting +spring.cloud.vault.consul.enabled=true (default false) and +providing the role name with spring.cloud.vault.consul.role=….

The obtained token is stored in spring.cloud.consul.token +so using Spring Cloud Consul can pick up the generated +credentials without further configuration. You can configure +the property name by setting spring.cloud.vault.consul.token-property.

spring.cloud.vault:
+    consul:
+        enabled: true
+        role: readonly
+        backend: consul
+        token-property: spring.cloud.consul.token
  • enabled setting this value to true enables the Consul backend config usage
  • role sets the role name of the Consul role definition
  • backend sets the path of the Consul mount to use
  • token-property sets the property name in which the Consul ACL token is stored

See also: Vault Documentation: Setting up Consul with Vault

4.3 RabbitMQ

Spring Cloud Vault can obtain credentials for RabbitMQ.

The RabbitMQ integration requires the spring-cloud-vault-config-rabbitmq +dependency.

Example 4.2. pom.xml

<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-vault-config-rabbitmq</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+</dependencies>

The integration can be enabled by setting +spring.cloud.vault.rabbitmq.enabled=true (default false) +and providing the role name with spring.cloud.vault.rabbitmq.role=….

Username and password are stored in spring.rabbitmq.username +and spring.rabbitmq.password so using Spring Boot will pick up the generated +credentials without further configuration. You can configure the property names +by setting spring.cloud.vault.rabbitmq.username-property and +spring.cloud.vault.rabbitmq.password-property.

spring.cloud.vault:
+    rabbitmq:
+        enabled: true
+        role: readonly
+        backend: rabbitmq
+        username-property: spring.rabbitmq.username
+        password-property: spring.rabbitmq.password
  • enabled setting this value to true enables the RabbitMQ backend config usage
  • role sets the role name of the RabbitMQ role definition
  • backend sets the path of the RabbitMQ mount to use
  • username-property sets the property name in which the RabbitMQ username is stored
  • password-property sets the property name in which the RabbitMQ password is stored

See also: Vault Documentation: Setting up RabbitMQ with Vault

4.4 AWS

Spring Cloud Vault can obtain credentials for AWS.

The AWS integration requires the spring-cloud-vault-config-aws +dependency.

Example 4.3. pom.xml

<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-vault-config-aws</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+</dependencies>

The integration can be enabled by setting +spring.cloud.vault.aws=true (default false) +and providing the role name with spring.cloud.vault.aws.role=….

The access key and secret key are stored in cloud.aws.credentials.accessKey +and cloud.aws.credentials.secretKey so using Spring Cloud AWS will pick up the generated +credentials without further configuration. You can configure the property names +by setting spring.cloud.vault.aws.access-key-property and +spring.cloud.vault.aws.secret-key-property.

spring.cloud.vault:
+    aws:
+        enabled: true
+        role: readonly
+        backend: aws
+        access-key-property: cloud.aws.credentials.accessKey
+        secret-key-property: cloud.aws.credentials.secretKey
  • enabled setting this value to true enables the AWS backend config usage
  • role sets the role name of the AWS role definition
  • backend sets the path of the AWS mount to use
  • access-key-property sets the property name in which the AWS access key is stored
  • secret-key-property sets the property name in which the AWS secret key is stored

See also: Vault Documentation: Setting up AWS with Vault

\ No newline at end of file diff --git a/multi/multi_vault.config.fail-fast.html b/multi/multi_vault.config.fail-fast.html new file mode 100644 index 00000000..690bfc29 --- /dev/null +++ b/multi/multi_vault.config.fail-fast.html @@ -0,0 +1,8 @@ + + + 8. Vault Client Fail Fast

8. Vault Client Fail Fast

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 +spring.cloud.vault.fail-fast=true and the client will halt with +an Exception.

spring.cloud.vault:
+    fail-fast: true
\ No newline at end of file diff --git a/multi/multi_vault.config.ssl.html b/multi/multi_vault.config.ssl.html new file mode 100644 index 00000000..cd4e69ed --- /dev/null +++ b/multi/multi_vault.config.ssl.html @@ -0,0 +1,13 @@ + + + 9. Vault Client SSL configuration

9. Vault Client SSL configuration

SSL can be configured declaratively by setting various properties. +You can set either javax.net.ssl.trustStore to configure +JVM-wide SSL settings or spring.cloud.vault.ssl.trust-store +to set SSL settings only for Spring Cloud Vault Config.

spring.cloud.vault:
+    ssl:
+        trust-store: classpath:keystore.jks
+        trust-store-password: changeit

Please note that configuring spring.cloud.vault.ssl.* can be only +applied when either Apache Http Components or the OkHttp client +is on your class-path.

\ No newline at end of file diff --git a/single/css/highlight.css b/single/css/highlight.css new file mode 100644 index 00000000..ffefef72 --- /dev/null +++ b/single/css/highlight.css @@ -0,0 +1,35 @@ +/* + code highlight CSS resemblign the Eclipse IDE default color schema + @author Costin Leau +*/ + +.hl-keyword { + color: #7F0055; + font-weight: bold; +} + +.hl-comment { + color: #3F5F5F; + font-style: italic; +} + +.hl-multiline-comment { + color: #3F5FBF; + font-style: italic; +} + +.hl-tag { + color: #3F7F7F; +} + +.hl-attribute { + color: #7F007F; +} + +.hl-value { + color: #2A00FF; +} + +.hl-string { + color: #2A00FF; +} \ No newline at end of file diff --git a/single/css/manual-multipage.css b/single/css/manual-multipage.css new file mode 100644 index 00000000..0c484531 --- /dev/null +++ b/single/css/manual-multipage.css @@ -0,0 +1,9 @@ +@IMPORT url("manual.css"); + +body.firstpage { + background: url("../images/background.png") no-repeat center top; +} + +div.part h1 { + border-top: none; +} diff --git a/single/css/manual-singlepage.css b/single/css/manual-singlepage.css new file mode 100644 index 00000000..4a7fd140 --- /dev/null +++ b/single/css/manual-singlepage.css @@ -0,0 +1,6 @@ +@IMPORT url("manual.css"); + +body { + background: url("../images/background.png") no-repeat center top; +} + diff --git a/single/css/manual.css b/single/css/manual.css new file mode 100644 index 00000000..0ecbe2e8 --- /dev/null +++ b/single/css/manual.css @@ -0,0 +1,344 @@ +@IMPORT url("highlight.css"); + +html { + padding: 0pt; + margin: 0pt; +} + +body { + color: #333333; + margin: 15px 30px; + font-family: Helvetica, Arial, Freesans, Clean, Sans-serif; + line-height: 1.6; + -webkit-font-smoothing: antialiased; +} + +code { + font-size: 16px; + font-family: Consolas, "Liberation Mono", Courier, monospace; +} + +:not(a)>code { + color: #6D180B; +} + +:not(pre)>code { + background-color: #F2F2F2; + border: 1px solid #CCCCCC; + border-radius: 4px; + padding: 1px 3px 0; + text-shadow: none; + white-space: nowrap; +} + +body>*:first-child { + margin-top: 0 !important; +} + +div { + margin: 0pt; +} + +hr { + border: 1px solid #CCCCCC; + background: #CCCCCC; +} + +h1,h2,h3,h4,h5,h6 { + color: #000000; + cursor: text; + font-weight: bold; + margin: 30px 0 10px; + padding: 0; +} + +h1,h2,h3 { + margin: 40px 0 10px; +} + +h1 { + margin: 70px 0 30px; + padding-top: 20px; +} + +div.part h1 { + border-top: 1px dotted #CCCCCC; +} + +h1,h1 code { + font-size: 32px; +} + +h2,h2 code { + font-size: 24px; +} + +h3,h3 code { + font-size: 20px; +} + +h4,h1 code,h5,h5 code,h6,h6 code { + font-size: 18px; +} + +div.book,div.chapter,div.appendix,div.part,div.preface { + min-width: 300px; + max-width: 1200px; + margin: 0 auto; +} + +p.releaseinfo { + font-weight: bold; + margin-bottom: 40px; + margin-top: 40px; +} + +div.authorgroup { + line-height: 1; +} + +p.copyright { + line-height: 1; + margin-bottom: -5px; +} + +.legalnotice p { + font-style: italic; + font-size: 14px; + line-height: 1; +} + +div.titlepage+p,div.titlepage+p { + margin-top: 0; +} + +pre { + line-height: 1.0; + color: black; +} + +a { + color: #4183C4; + text-decoration: none; +} + +p { + margin: 15px 0; + text-align: left; +} + +ul,ol { + padding-left: 30px; +} + +li p { + margin: 0; +} + +div.table { + margin: 1em; + padding: 0.5em; + text-align: center; +} + +div.table table,div.informaltable table { + display: table; + width: 100%; +} + +div.table td { + padding-left: 7px; + padding-right: 7px; +} + +.sidebar { + line-height: 1.4; + padding: 0 20px; + background-color: #F8F8F8; + border: 1px solid #CCCCCC; + border-radius: 3px 3px 3px 3px; +} + +.sidebar p.title { + color: #6D180B; +} + +pre.programlisting,pre.screen { + font-size: 15px; + padding: 6px 10px; + background-color: #F8F8F8; + border: 1px solid #CCCCCC; + border-radius: 3px 3px 3px 3px; + clear: both; + overflow: auto; + line-height: 1.4; + font-family: Consolas, "Liberation Mono", Courier, monospace; +} + +table { + border-collapse: collapse; + border-spacing: 0; + border: 1px solid #DDDDDD !important; + border-radius: 4px !important; + border-collapse: separate !important; + line-height: 1.6; +} + +table thead { + background: #F5F5F5; +} + +table tr { + border: none; + border-bottom: none; +} + +table th { + font-weight: bold; +} + +table th,table td { + border: none !important; + padding: 6px 13px; +} + +table tr:nth-child(2n) { + background-color: #F8F8F8; +} + +td p { + margin: 0 0 15px 0; +} + +div.table-contents td p { + margin: 0; +} + +div.important *,div.note *,div.tip *,div.warning *,div.navheader *,div.navfooter *,div.calloutlist * + { + border: none !important; + background: none !important; + margin: 0; +} + +div.important p,div.note p,div.tip p,div.warning p { + color: #6F6F6F; + line-height: 1.6; +} + +div.important code,div.note code,div.tip code,div.warning code { + background-color: #F2F2F2 !important; + border: 1px solid #CCCCCC !important; + border-radius: 4px !important; + padding: 1px 3px 0 !important; + text-shadow: none !important; + white-space: nowrap !important; +} + +.note th,.tip th,.warning th { + display: none; +} + +.note tr:first-child td,.tip tr:first-child td,.warning tr:first-child td + { + border-right: 1px solid #CCCCCC !important; + padding-top: 10px; +} + +div.calloutlist p,div.calloutlist td { + padding: 0; + margin: 0; +} + +div.calloutlist>table>tbody>tr>td:first-child { + padding-left: 10px; + width: 30px !important; +} + +div.important,div.note,div.tip,div.warning { + margin-left: 0px !important; + margin-right: 20px !important; + margin-top: 20px; + margin-bottom: 20px; + padding-top: 10px; + padding-bottom: 10px; +} + +div.toc { + line-height: 1.2; +} + +dl,dt { + margin-top: 1px; + margin-bottom: 0; +} + +div.toc>dl>dt { + font-size: 32px; + font-weight: bold; + margin: 30px 0 10px 0; + display: block; +} + +div.toc>dl>dd>dl>dt { + font-size: 24px; + font-weight: bold; + margin: 20px 0 10px 0; + display: block; +} + +div.toc>dl>dd>dl>dd>dl>dt { + font-weight: bold; + font-size: 20px; + margin: 10px 0 0 0; +} + +tbody.footnotes * { + border: none !important; +} + +div.footnote p { + margin: 0; + line-height: 1; +} + +div.footnote p sup { + margin-right: 6px; + vertical-align: middle; +} + +div.navheader { + border-bottom: 1px solid #CCCCCC; +} + +div.navfooter { + border-top: 1px solid #CCCCCC; +} + +.title { + margin-left: -1em; + padding-left: 1em; +} + +.title>a { + position: absolute; + visibility: hidden; + display: block; + font-size: 0.85em; + margin-top: 0.05em; + margin-left: -1em; + vertical-align: text-top; + color: black; +} + +.title>a:before { + content: "\00A7"; +} + +.title:hover>a,.title>a:hover,.title:hover>a:hover { + visibility: visible; +} + +.title:focus>a,.title>a:focus,.title:focus>a:focus { + outline: 0; +} diff --git a/single/images/background.png b/single/images/background.png new file mode 100644 index 00000000..15dca6fb Binary files /dev/null and b/single/images/background.png differ diff --git a/single/images/caution.png b/single/images/caution.png new file mode 100644 index 00000000..8a5e4fca Binary files /dev/null and b/single/images/caution.png differ diff --git a/single/images/important.png b/single/images/important.png new file mode 100644 index 00000000..ec54df65 Binary files /dev/null and b/single/images/important.png differ diff --git a/single/images/logo.png b/single/images/logo.png new file mode 100644 index 00000000..ade2ce6e Binary files /dev/null and b/single/images/logo.png differ diff --git a/single/images/note.png b/single/images/note.png new file mode 100644 index 00000000..88d997b1 Binary files /dev/null and b/single/images/note.png differ diff --git a/single/images/sts_exception.png b/single/images/sts_exception.png new file mode 100644 index 00000000..8607c38a Binary files /dev/null and b/single/images/sts_exception.png differ diff --git a/single/images/tip.png b/single/images/tip.png new file mode 100644 index 00000000..6530abb4 Binary files /dev/null and b/single/images/tip.png differ diff --git a/single/images/warning.png b/single/images/warning.png new file mode 100644 index 00000000..0d5b5244 Binary files /dev/null and b/single/images/warning.png differ diff --git a/single/images/web-selected.png b/single/images/web-selected.png new file mode 100644 index 00000000..aa6b2da6 Binary files /dev/null and b/single/images/web-selected.png differ diff --git a/single/spring-cloud-vault.html b/single/spring-cloud-vault.html new file mode 100644 index 00000000..3d3745f5 --- /dev/null +++ b/single/spring-cloud-vault.html @@ -0,0 +1,424 @@ + + + Spring Cloud Vault

Spring Cloud Vault


Table of Contents

1. Quick Start
2. Client Side Usage
2.1. Authentication
3. Authentication methods
3.1. Token authentication
3.2. AppId authentication
3.2.1. Custom UserId
3.3. AppRole authentication
3.4. AWS-EC2 authentication
3.5. TLS certificate authentication
3.6. Cubbyhole authentication
4. Secret Backends
4.1. Generic Backend
4.2. Consul
4.3. RabbitMQ
4.4. AWS
5. Database backends
5.1. Apache Cassandra
5.2. MongoDB
5.3. MySQL
5.4. PostgreSQL
6. Configure PropertySourceLocator behavior
7. Service Registry Configuration
8. Vault Client Fail Fast
9. Vault Client SSL configuration
10. Lease lifecycle management (renewal and revocation)

© 2016-2017 The original authors.

[Note]Note

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.

Spring Cloud Vault Config provides client-side support for externalized configuration in a distributed system. With HashiCorp’s Vault 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.

1. Quick Start

Prerequisites

To get started with Vault and this guide you need a +*NIX-like operating systems that provides:

  • wget, openssl and unzip
  • at least Java 7 and a properly configured JAVA_HOME environment variable

Install Vault

$ src/test/bash/install_vault.sh

Create SSL certificates for Vault

$ src/test/bash/create_certificates.sh
[Note]Note

create_certificates.sh creates certificates in work/ca and a JKS truststore work/keystore.jks. If you want to run Spring Cloud Vault using this quickstart guide you need to configure the truststore the spring.cloud.vault.ssl.trust-store property to file:work/keystore.jks.

Start Vault server

$ src/test/bash/local_run_vault.sh

Vault is started listening on 0.0.0.0:8200 using the inmem storage and +https. +Vault is sealed and not initialized when starting up.

[Note]Note

If you want to run tests, leave Vault uninitialized. The tests will +initialize Vault and create a root token 00000000-0000-0000-0000-000000000000.

If you want to use Vault for your application or give it a try then you need to initialize it first.

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

You should see something like:

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 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 VAULT_TOKEN + environment variable.

$ 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 accesses different resources. By default, the secret +backend is enabled which accesses secret config settings via JSON endpoints.

The HTTP service has resources in the form:

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

where the "application" is injected as the spring.application.name in the +SpringApplication (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.

2. Client Side Usage

To use these features in an application, just build it as a Spring +Boot application that depends on spring-cloud-vault-config (e.g. see +the test cases). Example Maven configuration:

Example 2.1. pom.xml

<parent>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-parent</artifactId>
+    <version>1.5.4.RELEASE</version>
+    <relativePath /> <!-- lookup parent from repository -->
+</parent>
+
+<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-starter-vault-config</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-test</artifactId>
+        <scope>test</scope>
+    </dependency>
+</dependencies>
+
+<build>
+    <plugins>
+        <plugin>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-maven-plugin</artifactId>
+        </plugin>
+    </plugins>
+</build>
+
+<!-- repositories also needed for snapshots and milestones -->

Then you can create a standard Spring Boot application, like this simple HTTP server:

@SpringBootApplication
+@RestController
+public class Application {
+
+    @RequestMapping("/")
+    public String home() {
+        return "Hello World!";
+    }
+
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+}

When it runs it will pick up the external configuration from the +default local Vault server on port 8200 if it is running. To modify +the startup behavior you can change the location of the Vault server +using bootstrap.properties (like application.properties but for +the bootstrap phase of an application context), e.g.

Example 2.2. bootstrap.yml

spring.cloud.vault:
+    host: localhost
+    port: 8200
+    scheme: https
+    uri: https://localhost:8200
+    connection-timeout: 5000
+    read-timeout: 15000
+    config:
+        order: -10

  • host sets the hostname of the Vault host. The host name will be used +for SSL certificate validation
  • port sets the Vault port
  • scheme setting the scheme to http will use plain HTTP. +Supported schemes are http and https.
  • uri configure the Vault endpoint with an URI. Takes precedence over host/port/scheme configuration
  • connection-timeout sets the connection timeout in milliseconds
  • read-timeout sets the read timeout in milliseconds
  • config.order sets the order for the property source

Enabling further integrations requires additional dependencies and +configuration. Depending on how you have set up Vault you might need +additional configuration like +SSL and +authentication.

If the application imports the spring-boot-starter-actuator project, the +status of the vault server will be available via the /health endpoint.

The vault health indicator can be enabled or disabled through the +property health.vault.enabled (default true).

2.1 Authentication

Vault requires an authentication mechanism to authorize client requests.

Spring Cloud Vault supports multiple authentication mechanisms to authenticate applications with Vault.

For a quickstart, use the root token printed by the Vault initialization.

Example 2.3. bootstrap.yml

spring.cloud.vault:
+    token: 19aefa97-cccc-bbbb-aaaa-225940e63d76

[Warning]Warning

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.

3. Authentication methods

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.

3.1 Token authentication

Tokens are the core method for authentication within Vault. +Token authentication requires a static token to be provided using the +Bootstrap Application Context.

[Note]Note

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.

Example 3.1. bootstrap.yml

spring.cloud.vault:
+    authentication: TOKEN
+    token: 00000000-0000-0000-0000-000000000000

  • authentication setting this value to TOKEN selects the Token +authentication method
  • token sets the static token to use

See also: Vault Documentation: Tokens

3.2 AppId authentication

Vault supports AppId +authentication that consists of two hard to guess tokens. The AppId +defaults to spring.application.name 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’s (e.g. supplied via System properties). +The IP and Mac address are represented as Hex-encoded SHA256 hash.

IP address-based UserId’s use the local host’s IP address.

Example 3.2. bootstrap.yml using SHA256 IP-Address UserId’s

spring.cloud.vault:
+    authentication: APPID
+    app-id:
+        user-id: IP_ADDRESS

  • authentication setting this value to APPID selects the AppId +authentication method
  • app-id-path sets the path of the AppId mount to use
  • user-id sets the UserId method. Possible values are IP_ADDRESS, +MAC_ADDRESS or a class name implementing a custom AppIdUserIdMechanism

The corresponding command to generate the IP address UserId from a command line is:

$ echo -n 192.168.99.1 | sha256sum
[Note]Note

Including the line break of echo leads to a different hash value +so make sure to include the -n flag.

Mac address-based UserId’s obtain their network device from the +localhost-bound device. The configuration also allows specifying +a network-interface hint to pick the right device. The value of +network-interface is optional and can be either an interface +name or interface index (0-based).

Example 3.3. bootstrap.yml using SHA256 Mac-Address UserId’s

spring.cloud.vault:
+    authentication: APPID
+    app-id:
+        user-id: MAC_ADDRESS
+        network-interface: eth0

  • network-interface sets network interface to obtain the physical address

The corresponding command to generate the IP address UserId from a command line is:

$ echo -n 0AFEDE1234AC | sha256sum
[Note]Note

The Mac address is specified uppercase and without colons. +Including the line break of echo leads to a different hash value +so make sure to include the -n flag.

3.2.1 Custom UserId

The UserId generation is an open mechanism. You can set +spring.cloud.vault.app-id.user-id to any string and the configured +value will be used as static UserId.

A more advanced approach lets you set spring.cloud.vault.app-id.user-id to a +classname. This class must be on your classpath and must implement +the org.springframework.cloud.vault.AppIdUserIdMechanism interface +and the createUserId method. Spring Cloud Vault will obtain the UserId +by calling createUserId each time it authenticates using AppId to +obtain a token.

Example 3.4. bootstrap.yml

spring.cloud.vault:
+    authentication: APPID
+    app-id:
+        user-id: com.examlple.MyUserIdMechanism

Example 3.5. MyUserIdMechanism.java

public class MyUserIdMechanism implements AppIdUserIdMechanism {
+
+  @Override
+  public String createUserId() {
+    String userId = ...
+    return userId;
+  }
+}

See also: Vault Documentation: Using the App ID auth backend

3.3 AppRole authentication

AppRole is intended for machine +authentication, like the deprecated (since Vault 0.6.1) Section 3.2, “AppId authentication”. +AppRole authentication consists of two hard to guess (secret) tokens: RoleId and SecretId.

Spring Vault supports AppRole authentication by providing either RoleId only +or together with a provided SecretId (push or pull mode).

RoleId and optionally SecretId must be provided by configuration, +Spring Vault will not look up these or create a custom SecretId.

Example 3.6. bootstrap.yml with AppRole authentication properties

spring.cloud.vault:
+    authentication: APPROLE
+    app-role:
+        role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52

  • role-id sets the RoleId.

Example 3.7. bootstrap.yml with all AppRole authentication properties

spring.cloud.vault:
+    authentication: APPROLE
+    app-role:
+        role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52
+        secret-id: 1696536f-1976-73b1-b241-0b4213908d39
+        app-auth-path: approle

  • role-id sets the RoleId.
  • secret-id sets the SecretId. SecretId can be omitted if AppRole is configured without requiring SecretId (See bind_secret_id)
  • approle-path sets the path of the approle authentication mount to use

See also: Vault Documentation: Using the AppRole auth backend

3.4 AWS-EC2 authentication

The aws-ec2 +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.

Example 3.8. bootstrap.yml using AWS-EC2 Authentication

spring.cloud.vault:
+    authentication: AWS_EC2

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.

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.

The nonce is kept in memory and is lost during application restart. +You can configure a static nonce with spring.cloud.vault.aws-ec2.nonce.

AWS-EC2 authentication roles are optional and default to the AMI. +You can configure the authentication role by setting the +spring.cloud.vault.aws-ec2.role property.

Example 3.9. bootstrap.yml with configured role

spring.cloud.vault:
+    authentication: AWS_EC2
+    aws-ec2:
+        role: application-server

Example 3.10. bootstrap.yml with all AWS EC2 authentication properties

spring.cloud.vault:
+    authentication: AWS_EC2
+    aws-ec2:
+        role: application-server
+        aws-ec2-path: aws-ec2
+        identity-document: http://...
+        nonce: my-static-nonce

  • authentication setting this value to AWS_EC2 selects the AWS EC2 +authentication method
  • role sets the role name of the AWS EC2 role definition
  • aws-ec2-path sets the path of the AWS EC2 mount to use
  • identity-document sets URL of the PKCS#7 AWS EC2 identity document
  • nonce used for AWS-EC2 authentication. An empty nonce defaults to nonce generation

See also: Vault Documentation: Using the aws-ec2 auth backend

3.5 TLS certificate authentication

The cert auth backend allows authentication using SSL/TLS client +certificates that are either signed by a CA or self-signed.

To enable cert authentication you need to:

  1. Use SSL, see Chapter 9, Vault Client SSL configuration
  2. Configure a Java Keystore that contains the client +certificate and the private key
  3. Set the spring.cloud.vault.authentication to CERT

Example 3.11. bootstrap.yml

spring.cloud.vault:
+    authentication: CERT
+    ssl:
+        key-store: classpath:keystore.jks
+        key-store-password: changeit
+        cert-auth-path: cert

See also: Vault Documentation: Using the Cert auth backend

3.6 Cubbyhole authentication

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’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 /cubbyhole/response.

Creating a wrapped token

[Note]Note

Response Wrapping for token creation requires Vault 0.6.0 or higher.

Example 3.12. Crating and storing tokens

$ 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

Example 3.13. bootstrap.yml

spring.cloud.vault:
+    authentication: CUBBYHOLE
+    token: 397ccb93-ff6c-b17b-9389-380b01ca2645

See also:

4. Secret Backends

4.1 Generic Backend

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 (application) in combination with active +profiles.

/secret/{application}/{profile}
+/secret/{application}
+/secret/{default-context}/{profile}
+/secret/{default-context}

The application name is determined by the properties:

  • spring.cloud.vault.generic.application-name
  • spring.cloud.vault.application-name
  • spring.application.name

Secrets can be obtained from other folders within the generic backend by adding their +paths to the application name, separated by commas. For example, given the application +name usefulapp,mysql1,projectx/aws, each of these folders will be used:

  • /secret/usefulapp
  • /secret/mysql1
  • /secret/projectx/aws

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.

Properties are exposed like they are stored (i.e. without additional prefixes).

spring.cloud.vault:
+    generic:
+        enabled: true
+        backend: secret
+        profile-separator: '/'
+        default-context: application
+        application-name: my-app
  • enabled setting this value to false disables the secret backend +config usage
  • backend sets the path of the secret mount to use
  • default-context sets the context name used by all applications
  • application-name overrides the application name for use in the generic backend
  • profile-separator separates the profile name from the context in +property sources with profiles

See also: Vault Documentation: Using the generic secret backend

4.2 Consul

Spring Cloud Vault can obtain credentials for HashiCorp Consul. +The Consul integration requires the spring-cloud-vault-config-consul +dependency.

Example 4.1. pom.xml

<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-vault-config-consul</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+</dependencies>

The integration can be enabled by setting +spring.cloud.vault.consul.enabled=true (default false) and +providing the role name with spring.cloud.vault.consul.role=….

The obtained token is stored in spring.cloud.consul.token +so using Spring Cloud Consul can pick up the generated +credentials without further configuration. You can configure +the property name by setting spring.cloud.vault.consul.token-property.

spring.cloud.vault:
+    consul:
+        enabled: true
+        role: readonly
+        backend: consul
+        token-property: spring.cloud.consul.token
  • enabled setting this value to true enables the Consul backend config usage
  • role sets the role name of the Consul role definition
  • backend sets the path of the Consul mount to use
  • token-property sets the property name in which the Consul ACL token is stored

See also: Vault Documentation: Setting up Consul with Vault

4.3 RabbitMQ

Spring Cloud Vault can obtain credentials for RabbitMQ.

The RabbitMQ integration requires the spring-cloud-vault-config-rabbitmq +dependency.

Example 4.2. pom.xml

<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-vault-config-rabbitmq</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+</dependencies>

The integration can be enabled by setting +spring.cloud.vault.rabbitmq.enabled=true (default false) +and providing the role name with spring.cloud.vault.rabbitmq.role=….

Username and password are stored in spring.rabbitmq.username +and spring.rabbitmq.password so using Spring Boot will pick up the generated +credentials without further configuration. You can configure the property names +by setting spring.cloud.vault.rabbitmq.username-property and +spring.cloud.vault.rabbitmq.password-property.

spring.cloud.vault:
+    rabbitmq:
+        enabled: true
+        role: readonly
+        backend: rabbitmq
+        username-property: spring.rabbitmq.username
+        password-property: spring.rabbitmq.password
  • enabled setting this value to true enables the RabbitMQ backend config usage
  • role sets the role name of the RabbitMQ role definition
  • backend sets the path of the RabbitMQ mount to use
  • username-property sets the property name in which the RabbitMQ username is stored
  • password-property sets the property name in which the RabbitMQ password is stored

See also: Vault Documentation: Setting up RabbitMQ with Vault

4.4 AWS

Spring Cloud Vault can obtain credentials for AWS.

The AWS integration requires the spring-cloud-vault-config-aws +dependency.

Example 4.3. pom.xml

<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-vault-config-aws</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+</dependencies>

The integration can be enabled by setting +spring.cloud.vault.aws=true (default false) +and providing the role name with spring.cloud.vault.aws.role=….

The access key and secret key are stored in cloud.aws.credentials.accessKey +and cloud.aws.credentials.secretKey so using Spring Cloud AWS will pick up the generated +credentials without further configuration. You can configure the property names +by setting spring.cloud.vault.aws.access-key-property and +spring.cloud.vault.aws.secret-key-property.

spring.cloud.vault:
+    aws:
+        enabled: true
+        role: readonly
+        backend: aws
+        access-key-property: cloud.aws.credentials.accessKey
+        secret-key-property: cloud.aws.credentials.secretKey
  • enabled setting this value to true enables the AWS backend config usage
  • role sets the role name of the AWS role definition
  • backend sets the path of the AWS mount to use
  • access-key-property sets the property name in which the AWS access key is stored
  • secret-key-property sets the property name in which the AWS secret key is stored

See also: Vault Documentation: Setting up AWS with Vault

5. Database backends

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’s leasing +mechanism to more easily roll keys.

Spring Cloud Vault integrates with these backends:

Using a database secret backend requires to enable the +backend in the configuration and the spring-cloud-vault-config-databases +dependency.

Example 5.1. pom.xml

<dependencies>
+    <dependency>
+        <groupId>org.springframework.cloud</groupId>
+        <artifactId>spring-cloud-vault-config-databases</artifactId>
+        <version>1.1.0.BUILD-SNAPSHOT</version>
+    </dependency>
+</dependencies>

[Note]Note

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.

5.1 Apache Cassandra

Spring Cloud Vault can obtain credentials for Apache Cassandra. +The integration can be enabled by setting +spring.cloud.vault.cassandra.enabled=true (default false) and +providing the role name with spring.cloud.vault.cassandra.role=….

Username and password are stored in spring.data.cassandra.username +and spring.data.cassandra.password so using Spring Boot will pick +up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.cassandra.username-property and +spring.cloud.vault.cassandra.password-property.

spring.cloud.vault:
+    cassandra:
+        enabled: true
+        role: readonly
+        backend: cassandra
+        username-property: spring.data.cassandra.username
+        password-property: spring.data.cassandra.username
  • enabled setting this value to true enables the Cassandra backend config usage
  • role sets the role name of the Cassandra role definition
  • backend sets the path of the Cassandra mount to use
  • username-property sets the property name in which the Cassandra username is stored
  • password-property sets the property name in which the Cassandra password is stored

See also: Vault Documentation: Setting up Apache Cassandra with Vault

5.2 MongoDB

Spring Cloud Vault can obtain credentials for MongoDB. +The integration can be enabled by setting +spring.cloud.vault.mongodb.enabled=true (default false) and +providing the role name with spring.cloud.vault.mongodb.role=….

Username and password are stored in spring.data.mongodb.username +and spring.data.mongodb.password so using Spring Boot will +pick up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.mongodb.username-property and +spring.cloud.vault.mongodb.password-property.

spring.cloud.vault:
+    mongodb:
+        enabled: true
+        role: readonly
+        backend: mongodb
+        username-property: spring.data.mongodb.username
+        password-property: spring.data.mongodb.password
  • enabled setting this value to true enables the MongodB backend config usage
  • role sets the role name of the MongoDB role definition
  • backend sets the path of the MongoDB mount to use
  • username-property sets the property name in which the MongoDB username is stored
  • password-property sets the property name in which the MongoDB password is stored

See also: Vault Documentation: Setting up MongoDB with Vault

5.3 MySQL

Spring Cloud Vault can obtain credentials for MySQL. +The integration can be enabled by setting +spring.cloud.vault.mysql.enabled=true (default false) and +providing the role name with spring.cloud.vault.mysql.role=….

Username and password are stored in spring.datasource.username +and spring.datasource.password so using Spring Boot will +pick up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.mysql.username-property and +spring.cloud.vault.mysql.password-property.

spring.cloud.vault:
+    mysql:
+        enabled: true
+        role: readonly
+        backend: mysql
+        username-property: spring.datasource.username
+        password-property: spring.datasource.username
  • enabled setting this value to true enables the MySQL backend config usage
  • role sets the role name of the MySQL role definition
  • backend sets the path of the MySQL mount to use
  • username-property sets the property name in which the MySQL username is stored
  • password-property sets the property name in which the MySQL password is stored

See also: Vault Documentation: Setting up MySQL with Vault

5.4 PostgreSQL

Spring Cloud Vault can obtain credentials for PostgreSQL. +The integration can be enabled by setting +spring.cloud.vault.postgresql.enabled=true (default false) and +providing the role name with spring.cloud.vault.postgresql.role=….

Username and password are stored in spring.datasource.username +and spring.datasource.password so using Spring Boot will +pick up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.postgresql.username-property and +spring.cloud.vault.postgresql.password-property.

spring.cloud.vault:
+    postgresql:
+        enabled: true
+        role: readonly
+        backend: postgresql
+        username-property: spring.datasource.username
+        password-property: spring.datasource.username
  • enabled setting this value to true enables the PostgreSQL backend config usage
  • role sets the role name of the PostgreSQL role definition
  • backend sets the path of the PostgreSQL mount to use
  • username-property sets the property name in which the PostgreSQL username is stored
  • password-property sets the property name in which the PostgreSQL password is stored

See also: Vault Documentation: Setting up PostgreSQL with Vault

6. Configure PropertySourceLocator behavior

Spring Cloud Vault uses property-based configuration to create PropertySources +for generic and discovered secret backends.

Discovered backends provide VaultSecretBackendDescriptor beans to describe the configuration +state to use secret backend as PropertySource. A SecretBackendMetadataFactory is required +to create a SecretBackendMetadata object which contains path, name and property transformation +configuration.

SecretBackendMetadata is used to back a particular PropertySource.

You can register an arbitrary number of beans implementing VaultConfigurer for customization. +Default generic and discovered backend registration is disabled if Spring Cloud Vault discovers +at least one VaultConfigurer bean. You can however enable default registration with +SecretBackendConfigurer.registerDefaultGenericSecretBackends() and SecretBackendConfigurer.registerDefaultDiscoveredSecretBackends().

public class CustomizationBean implements VaultConfigurer {
+
+    @Override
+    public void addSecretBackends(SecretBackendConfigurer configurer) {
+
+        configurer.add("secret/my-application");
+
+        configurer.registerDefaultGenericSecretBackends(false);
+        configurer.registerDefaultDiscoveredSecretBackends(true);
+    }
+}
[Note]Note

All customization is required to happen in the bootstrap context. Add your configuration +classes to META-INF/spring.factories at org.springframework.cloud.bootstrap.BootstrapConfiguration +in your application.

7. Service Registry Configuration

You can use a DiscoveryClient (such as from Spring Cloud Consul) to locate +a Vault server by setting spring.cloud.vault.discovery.enabled=true (default false). +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 vault but you can change that on the client with +spring.cloud.vault.discovery.serviceId.

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 scheme metadata entry to be set either to https or http. +If no scheme is configured and the service is not exposed as secure service, then +configuration defaults to spring.cloud.vault.scheme which is https when it’s not set.

spring.cloud.vault.discovery:
+    enabled: true
+    service-id: my-vault-service

8. Vault Client Fail Fast

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 +spring.cloud.vault.fail-fast=true and the client will halt with +an Exception.

spring.cloud.vault:
+    fail-fast: true

9. Vault Client SSL configuration

SSL can be configured declaratively by setting various properties. +You can set either javax.net.ssl.trustStore to configure +JVM-wide SSL settings or spring.cloud.vault.ssl.trust-store +to set SSL settings only for Spring Cloud Vault Config.

spring.cloud.vault:
+    ssl:
+        trust-store: classpath:keystore.jks
+        trust-store-password: changeit
  • trust-store sets the resource for the trust-store. SSL-secured Vault +communication will validate the Vault SSL certificate with the specified +trust-store.
  • trust-store-password sets the trust-store password

Please note that configuring spring.cloud.vault.ssl.* can be only +applied when either Apache Http Components or the OkHttp client +is on your class-path.

10. Lease lifecycle management (renewal and revocation)

With every secret, Vault creates a lease: +metadata containing information such as a time duration, +renewability, and more.

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.

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.

Secret service and database backends (such as MongoDB or MySQL) +usually generate a renewable lease so generated credentials will +be disabled on application shutdown.

[Note]Note

Static tokens are not renewed or revoked.

Lease renewal and revocation is enabled by default and can +be disabled by setting spring.cloud.vault.config.lifecycle.enabled +to false. 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.

spring.cloud.vault:
+    config.lifecycle.enabled: true

See also: Vault Documentation: Lease, Renew, and Revoke

\ No newline at end of file diff --git a/spring-cloud-vault.html b/spring-cloud-vault.html index 154377eb..6bf80ffa 100644 --- a/spring-cloud-vault.html +++ b/spring-cloud-vault.html @@ -4,2129 +4,109 @@ - -Spring Cloud Vault - + +spring-cloud-vault + + + - + +
-

© 2016-2017 The original authors.

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

Spring Cloud Vault Config provides client-side support for externalized configuration in a distributed system. With HashiCorp’s Vault 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.

+

1.1.0.BUILD-SNAPSHOT

-

Quick Start

+

Pick The Documentation Option

-
-

Prerequisites

-
-
-

To get started with Vault and this guide you need a -*NIX-like operating systems that provides:

-
  • -

    wget, openssl and unzip

    +

    Single HTML

  • -

    at least Java 7 and a properly configured JAVA_HOME environment variable

    +

    Multi HTML

-
-

Install Vault

-
-
-
-
$ src/test/bash/install_vault.sh
-
-
-
-

Create SSL certificates for Vault

-
-
-
-
$ src/test/bash/create_certificates.sh
-
-
-
- - - - - -
-
Note
-
-create_certificates.sh creates certificates in work/ca and a JKS truststore work/keystore.jks. If you want to run Spring Cloud Vault using this quickstart guide you need to configure the truststore the spring.cloud.vault.ssl.trust-store property to file:work/keystore.jks. -
-
-
-

Start Vault server

-
-
-
-
$ src/test/bash/local_run_vault.sh
-
-
-
-

Vault is started listening on 0.0.0.0:8200 using the inmem storage and -https. -Vault is sealed and not initialized when starting up.

-
-
- - - - - -
-
Note
-
-If you want to run tests, leave Vault uninitialized. The tests will -initialize Vault and create a root token 00000000-0000-0000-0000-000000000000. -
-
-
-

If you want to use Vault for your application or give it a try then you need to initialize it first.

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

You should see something like:

-
-
-
-
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 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 VAULT_TOKEN - environment variable.

-
-
-
-
$ 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 accesses different resources. By default, the secret -backend is enabled which accesses secret config settings via JSON endpoints.

-
-
-

The HTTP service has resources in the form:

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

where the "application" is injected as the spring.application.name in the -SpringApplication (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.

-
-
-
-
-

Client Side Usage

-
-
-

To use these features in an application, just build it as a Spring -Boot application that depends on spring-cloud-vault-config (e.g. see -the test cases). Example Maven configuration:

-
-
-
Example 1. pom.xml
-
-
-
-
<parent>
-    <groupId>org.springframework.boot</groupId>
-    <artifactId>spring-boot-starter-parent</artifactId>
-    <version>1.5.4.RELEASE</version>
-    <relativePath /> <!-- lookup parent from repository -->
-</parent>
-
-<dependencies>
-    <dependency>
-        <groupId>org.springframework.cloud</groupId>
-        <artifactId>spring-cloud-starter-vault-config</artifactId>
-        <version>1.1.0.BUILD-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-        <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-starter-test</artifactId>
-        <scope>test</scope>
-    </dependency>
-</dependencies>
-
-<build>
-    <plugins>
-        <plugin>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-maven-plugin</artifactId>
-        </plugin>
-    </plugins>
-</build>
-
-<!-- repositories also needed for snapshots and milestones -->
-
-
-
-
-
-

Then you can create a standard Spring Boot application, like this simple HTTP server:

-
-
-
-
-
-
@SpringBootApplication
-@RestController
-public class Application {
-
-    @RequestMapping("/")
-    public String home() {
-        return "Hello World!";
-    }
-
-    public static void main(String[] args) {
-        SpringApplication.run(Application.class, args);
-    }
-}
-
-
-
-
-
-

When it runs it will pick up the external configuration from the -default local Vault server on port 8200 if it is running. To modify -the startup behavior you can change the location of the Vault server -using bootstrap.properties (like application.properties but for -the bootstrap phase of an application context), e.g.

-
-
-
Example 2. bootstrap.yml
-
-
-
-
spring.cloud.vault:
-    host: localhost
-    port: 8200
-    scheme: https
-    uri: https://localhost:8200
-    connection-timeout: 5000
-    read-timeout: 15000
-    config:
-        order: -10
-
-
-
-
-
-
    -
  • -

    host sets the hostname of the Vault host. The host name will be used -for SSL certificate validation

    -
  • -
  • -

    port sets the Vault port

    -
  • -
  • -

    scheme setting the scheme to http will use plain HTTP. -Supported schemes are http and https.

    -
  • -
  • -

    uri configure the Vault endpoint with an URI. Takes precedence over host/port/scheme configuration

    -
  • -
  • -

    connection-timeout sets the connection timeout in milliseconds

    -
  • -
  • -

    read-timeout sets the read timeout in milliseconds

    -
  • -
  • -

    config.order sets the order for the property source

    -
  • -
-
-
-

Enabling further integrations requires additional dependencies and -configuration. Depending on how you have set up Vault you might need -additional configuration like -SSL and -authentication.

-
-
-

If the application imports the spring-boot-starter-actuator project, the -status of the vault server will be available via the /health endpoint.

-
-
-

The vault health indicator can be enabled or disabled through the -property health.vault.enabled (default true).

-
-
-

Authentication

- -
-

Spring Cloud Vault supports multiple authentication mechanisms to authenticate applications with Vault.

-
-
-

For a quickstart, use the root token printed by the Vault initialization.

-
-
-
Example 3. bootstrap.yml
-
-
-
-
spring.cloud.vault:
-    token: 19aefa97-cccc-bbbb-aaaa-225940e63d76
-
-
-
-
-
- - - - - -
-
Warning
-
-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. -
-
-
-
-
-
-

Authentication methods

-
-
-

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.

-
-
-

Token authentication

-
-

Tokens are the core method for authentication within Vault. -Token authentication requires a static token to be provided using the -Bootstrap Application Context.

-
-
- - - - - -
-
Note
-
-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. -
-
-
-
Example 4. bootstrap.yml
-
-
-
-
spring.cloud.vault:
-    authentication: TOKEN
-    token: 00000000-0000-0000-0000-000000000000
-
-
-
-
-
-
    -
  • -

    authentication setting this value to TOKEN selects the Token -authentication method

    -
  • -
  • -

    token sets the static token to use

    -
  • -
-
- -
-
-

AppId authentication

-
-

Vault supports AppId -authentication that consists of two hard to guess tokens. The AppId -defaults to spring.application.name 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’s (e.g. supplied via System properties). -The IP and Mac address are represented as Hex-encoded SHA256 hash.

-
-
-

IP address-based UserId’s use the local host’s IP address.

-
-
-
Example 5. bootstrap.yml using SHA256 IP-Address UserId’s
-
-
-
-
spring.cloud.vault:
-    authentication: APPID
-    app-id:
-        user-id: IP_ADDRESS
-
-
-
-
-
-
    -
  • -

    authentication setting this value to APPID selects the AppId -authentication method

    -
  • -
  • -

    app-id-path sets the path of the AppId mount to use

    -
  • -
  • -

    user-id sets the UserId method. Possible values are IP_ADDRESS, -MAC_ADDRESS or a class name implementing a custom AppIdUserIdMechanism

    -
  • -
-
-
-

The corresponding command to generate the IP address UserId from a command line is:

-
-
-
-
$ echo -n 192.168.99.1 | sha256sum
-
-
-
- - - - - -
-
Note
-
-Including the line break of echo leads to a different hash value -so make sure to include the -n flag. -
-
-
-

Mac address-based UserId’s obtain their network device from the -localhost-bound device. The configuration also allows specifying -a network-interface hint to pick the right device. The value of -network-interface is optional and can be either an interface -name or interface index (0-based).

-
-
-
Example 6. bootstrap.yml using SHA256 Mac-Address UserId’s
-
-
-
-
spring.cloud.vault:
-    authentication: APPID
-    app-id:
-        user-id: MAC_ADDRESS
-        network-interface: eth0
-
-
-
-
-
-
    -
  • -

    network-interface sets network interface to obtain the physical address

    -
  • -
-
-
-

The corresponding command to generate the IP address UserId from a command line is:

-
-
-
-
$ echo -n 0AFEDE1234AC | sha256sum
-
-
-
- - - - - -
-
Note
-
-The Mac address is specified uppercase and without colons. -Including the line break of echo leads to a different hash value -so make sure to include the -n flag. -
-
-
-

Custom UserId

-
-

The UserId generation is an open mechanism. You can set -spring.cloud.vault.app-id.user-id to any string and the configured -value will be used as static UserId.

-
-
-

A more advanced approach lets you set spring.cloud.vault.app-id.user-id to a -classname. This class must be on your classpath and must implement -the org.springframework.cloud.vault.AppIdUserIdMechanism interface -and the createUserId method. Spring Cloud Vault will obtain the UserId -by calling createUserId each time it authenticates using AppId to -obtain a token.

-
-
-
Example 7. bootstrap.yml
-
-
-
-
spring.cloud.vault:
-    authentication: APPID
-    app-id:
-        user-id: com.examlple.MyUserIdMechanism
-
-
-
-
-
-
Example 8. MyUserIdMechanism.java
-
-
-
-
public class MyUserIdMechanism implements AppIdUserIdMechanism {
-
-  @Override
-  public String createUserId() {
-    String userId = ...
-    return userId;
-  }
-}
-
-
-
-
- -
-
-
-

AppRole authentication

-
-

AppRole is intended for machine -authentication, like the deprecated (since Vault 0.6.1) AppId authentication. -AppRole authentication consists of two hard to guess (secret) tokens: RoleId and SecretId.

-
-
-

Spring Vault supports AppRole authentication by providing either RoleId only -or together with a provided SecretId (push or pull mode).

-
-
-

RoleId and optionally SecretId must be provided by configuration, -Spring Vault will not look up these or create a custom SecretId.

-
-
-
Example 9. bootstrap.yml with AppRole authentication properties
-
-
-
-
spring.cloud.vault:
-    authentication: APPROLE
-    app-role:
-        role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52
-
-
-
-
-
-
    -
  • -

    role-id sets the RoleId.

    -
  • -
-
-
-
Example 10. bootstrap.yml with all AppRole authentication properties
-
-
-
-
spring.cloud.vault:
-    authentication: APPROLE
-    app-role:
-        role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52
-        secret-id: 1696536f-1976-73b1-b241-0b4213908d39
-        app-auth-path: approle
-
-
-
-
-
-
    -
  • -

    role-id sets the RoleId.

    -
  • -
  • -

    secret-id sets the SecretId. SecretId can be omitted if AppRole is configured without requiring SecretId (See bind_secret_id)

    -
  • -
  • -

    approle-path sets the path of the approle authentication mount to use

    -
  • -
-
- -
-
-

AWS-EC2 authentication

-
-

The aws-ec2 -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.

-
-
-
Example 11. bootstrap.yml using AWS-EC2 Authentication
-
-
-
-
spring.cloud.vault:
-    authentication: AWS_EC2
-
-
-
-
-
-

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.

-
-
-

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.

-
-
-

The nonce is kept in memory and is lost during application restart. -You can configure a static nonce with spring.cloud.vault.aws-ec2.nonce.

-
-
-

AWS-EC2 authentication roles are optional and default to the AMI. -You can configure the authentication role by setting the -spring.cloud.vault.aws-ec2.role property.

-
-
-
Example 12. bootstrap.yml with configured role
-
-
-
-
spring.cloud.vault:
-    authentication: AWS_EC2
-    aws-ec2:
-        role: application-server
-
-
-
-
-
-
Example 13. bootstrap.yml with all AWS EC2 authentication properties
-
-
-
-
spring.cloud.vault:
-    authentication: AWS_EC2
-    aws-ec2:
-        role: application-server
-        aws-ec2-path: aws-ec2
-        identity-document: http://...
-        nonce: my-static-nonce
-
-
-
-
-
-
    -
  • -

    authentication setting this value to AWS_EC2 selects the AWS EC2 -authentication method

    -
  • -
  • -

    role sets the role name of the AWS EC2 role definition

    -
  • -
  • -

    aws-ec2-path sets the path of the AWS EC2 mount to use

    -
  • -
  • -

    identity-document sets URL of the PKCS#7 AWS EC2 identity document

    -
  • -
  • -

    nonce used for AWS-EC2 authentication. An empty nonce defaults to nonce generation

    -
  • -
-
- -
-
-

TLS certificate authentication

-
-

The cert auth backend allows authentication using SSL/TLS client -certificates that are either signed by a CA or self-signed.

-
-
-

To enable cert authentication you need to:

-
-
-
    -
  1. -

    Use SSL, see Vault Client SSL configuration

    -
  2. -
  3. -

    Configure a Java Keystore that contains the client -certificate and the private key

    -
  4. -
  5. -

    Set the spring.cloud.vault.authentication to CERT

    -
  6. -
-
-
-
Example 14. bootstrap.yml
-
-
-
-
spring.cloud.vault:
-    authentication: CERT
-    ssl:
-        key-store: classpath:keystore.jks
-        key-store-password: changeit
-        cert-auth-path: cert
-
-
-
-
- -
-
-

Cubbyhole authentication

-
-

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’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 /cubbyhole/response.

-
-
-

Creating a wrapped token

-
-
- - - - - -
-
Note
-
-Response Wrapping for token creation requires Vault 0.6.0 or higher. -
-
-
-
Example 15. Crating and storing tokens
-
-
-
-
$ 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
-
-
-
-
-
-
Example 16. bootstrap.yml
-
-
-
-
spring.cloud.vault:
-    authentication: CUBBYHOLE
-    token: 397ccb93-ff6c-b17b-9389-380b01ca2645
-
-
-
-
-
-

See also:

-
- -
-
-
-
-

Secret Backends

-
-
-

Generic Backend

-
-

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 (application) in combination with active -profiles.

-
-
-
-
/secret/{application}/{profile}
-/secret/{application}
-/secret/{default-context}/{profile}
-/secret/{default-context}
-
-
-
-

The application name is determined by the properties:

-
-
-
    -
  • -

    spring.cloud.vault.generic.application-name

    -
  • -
  • -

    spring.cloud.vault.application-name

    -
  • -
  • -

    spring.application.name

    -
  • -
-
-
-

Secrets can be obtained from other folders within the generic backend by adding their -paths to the application name, separated by commas. For example, given the application -name usefulapp,mysql1,projectx/aws, each of these folders will be used:

-
-
-
    -
  • -

    /secret/usefulapp

    -
  • -
  • -

    /secret/mysql1

    -
  • -
  • -

    /secret/projectx/aws

    -
  • -
-
-
-

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.

-
-
-

Properties are exposed like they are stored (i.e. without additional prefixes).

-
-
-
-
-
-
spring.cloud.vault:
-    generic:
-        enabled: true
-        backend: secret
-        profile-separator: '/'
-        default-context: application
-        application-name: my-app
-
-
-
-
-
-
    -
  • -

    enabled setting this value to false disables the secret backend -config usage

    -
  • -
  • -

    backend sets the path of the secret mount to use

    -
  • -
  • -

    default-context sets the context name used by all applications

    -
  • -
  • -

    application-name overrides the application name for use in the generic backend

    -
  • -
  • -

    profile-separator separates the profile name from the context in -property sources with profiles

    -
  • -
-
- -
-
-

Consul

-
-

Spring Cloud Vault can obtain credentials for HashiCorp Consul. -The Consul integration requires the spring-cloud-vault-config-consul -dependency.

-
-
-
Example 17. pom.xml
-
-
-
-
<dependencies>
-    <dependency>
-        <groupId>org.springframework.cloud</groupId>
-        <artifactId>spring-cloud-vault-config-consul</artifactId>
-        <version>1.1.0.BUILD-SNAPSHOT</version>
-    </dependency>
-</dependencies>
-
-
-
-
-
-

The integration can be enabled by setting -spring.cloud.vault.consul.enabled=true (default false) and -providing the role name with spring.cloud.vault.consul.role=….

-
-
-

The obtained token is stored in spring.cloud.consul.token -so using Spring Cloud Consul can pick up the generated -credentials without further configuration. You can configure -the property name by setting spring.cloud.vault.consul.token-property.

-
-
-
-
-
-
spring.cloud.vault:
-    consul:
-        enabled: true
-        role: readonly
-        backend: consul
-        token-property: spring.cloud.consul.token
-
-
-
-
-
-
    -
  • -

    enabled setting this value to true enables the Consul backend config usage

    -
  • -
  • -

    role sets the role name of the Consul role definition

    -
  • -
  • -

    backend sets the path of the Consul mount to use

    -
  • -
  • -

    token-property sets the property name in which the Consul ACL token is stored

    -
  • -
-
- -
-
-

RabbitMQ

-
-

Spring Cloud Vault can obtain credentials for RabbitMQ.

-
-
-

The RabbitMQ integration requires the spring-cloud-vault-config-rabbitmq -dependency.

-
-
-
Example 18. pom.xml
-
-
-
-
<dependencies>
-    <dependency>
-        <groupId>org.springframework.cloud</groupId>
-        <artifactId>spring-cloud-vault-config-rabbitmq</artifactId>
-        <version>1.1.0.BUILD-SNAPSHOT</version>
-    </dependency>
-</dependencies>
-
-
-
-
-
-

The integration can be enabled by setting -spring.cloud.vault.rabbitmq.enabled=true (default false) -and providing the role name with spring.cloud.vault.rabbitmq.role=….

-
-
-

Username and password are stored in spring.rabbitmq.username -and spring.rabbitmq.password so using Spring Boot will pick up the generated -credentials without further configuration. You can configure the property names -by setting spring.cloud.vault.rabbitmq.username-property and -spring.cloud.vault.rabbitmq.password-property.

-
-
-
-
-
-
spring.cloud.vault:
-    rabbitmq:
-        enabled: true
-        role: readonly
-        backend: rabbitmq
-        username-property: spring.rabbitmq.username
-        password-property: spring.rabbitmq.password
-
-
-
-
-
-
    -
  • -

    enabled setting this value to true enables the RabbitMQ backend config usage

    -
  • -
  • -

    role sets the role name of the RabbitMQ role definition

    -
  • -
  • -

    backend sets the path of the RabbitMQ mount to use

    -
  • -
  • -

    username-property sets the property name in which the RabbitMQ username is stored

    -
  • -
  • -

    password-property sets the property name in which the RabbitMQ password is stored

    -
  • -
-
- -
-
-

AWS

-
-

Spring Cloud Vault can obtain credentials for AWS.

-
-
-

The AWS integration requires the spring-cloud-vault-config-aws -dependency.

-
-
-
Example 19. pom.xml
-
-
-
-
<dependencies>
-    <dependency>
-        <groupId>org.springframework.cloud</groupId>
-        <artifactId>spring-cloud-vault-config-aws</artifactId>
-        <version>1.1.0.BUILD-SNAPSHOT</version>
-    </dependency>
-</dependencies>
-
-
-
-
-
-

The integration can be enabled by setting -spring.cloud.vault.aws=true (default false) -and providing the role name with spring.cloud.vault.aws.role=….

-
-
-

The access key and secret key are stored in cloud.aws.credentials.accessKey -and cloud.aws.credentials.secretKey so using Spring Cloud AWS will pick up the generated -credentials without further configuration. You can configure the property names -by setting spring.cloud.vault.aws.access-key-property and -spring.cloud.vault.aws.secret-key-property.

-
-
-
-
-
-
spring.cloud.vault:
-    aws:
-        enabled: true
-        role: readonly
-        backend: aws
-        access-key-property: cloud.aws.credentials.accessKey
-        secret-key-property: cloud.aws.credentials.secretKey
-
-
-
-
-
-
    -
  • -

    enabled setting this value to true enables the AWS backend config usage

    -
  • -
  • -

    role sets the role name of the AWS role definition

    -
  • -
  • -

    backend sets the path of the AWS mount to use

    -
  • -
  • -

    access-key-property sets the property name in which the AWS access key is stored

    -
  • -
  • -

    secret-key-property sets the property name in which the AWS secret key is stored

    -
  • -
-
- -
-
-
-
-

Database backends

-
-
-

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’s leasing -mechanism to more easily roll keys.

-
-
-

Spring Cloud Vault integrates with these backends:

-
-
- -
-
-

Using a database secret backend requires to enable the -backend in the configuration and the spring-cloud-vault-config-databases -dependency.

-
-
-
Example 20. pom.xml
-
-
-
-
<dependencies>
-    <dependency>
-        <groupId>org.springframework.cloud</groupId>
-        <artifactId>spring-cloud-vault-config-databases</artifactId>
-        <version>1.1.0.BUILD-SNAPSHOT</version>
-    </dependency>
-</dependencies>
-
-
-
-
-
- - - - - -
-
Note
-
-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. -
-
-
-

Apache Cassandra

-
-

Spring Cloud Vault can obtain credentials for Apache Cassandra. -The integration can be enabled by setting -spring.cloud.vault.cassandra.enabled=true (default false) and -providing the role name with spring.cloud.vault.cassandra.role=….

-
-
-

Username and password are stored in spring.data.cassandra.username -and spring.data.cassandra.password so using Spring Boot will pick -up the generated credentials without further configuration. -You can configure the property names by setting -spring.cloud.vault.cassandra.username-property and -spring.cloud.vault.cassandra.password-property.

-
-
-
-
-
-
spring.cloud.vault:
-    cassandra:
-        enabled: true
-        role: readonly
-        backend: cassandra
-        username-property: spring.data.cassandra.username
-        password-property: spring.data.cassandra.username
-
-
-
-
-
-
    -
  • -

    enabled setting this value to true enables the Cassandra backend config usage

    -
  • -
  • -

    role sets the role name of the Cassandra role definition

    -
  • -
  • -

    backend sets the path of the Cassandra mount to use

    -
  • -
  • -

    username-property sets the property name in which the Cassandra username is stored

    -
  • -
  • -

    password-property sets the property name in which the Cassandra password is stored

    -
  • -
-
- -
-
-

MongoDB

-
-

Spring Cloud Vault can obtain credentials for MongoDB. -The integration can be enabled by setting -spring.cloud.vault.mongodb.enabled=true (default false) and -providing the role name with spring.cloud.vault.mongodb.role=….

-
-
-

Username and password are stored in spring.data.mongodb.username -and spring.data.mongodb.password so using Spring Boot will -pick up the generated credentials without further configuration. -You can configure the property names by setting -spring.cloud.vault.mongodb.username-property and -spring.cloud.vault.mongodb.password-property.

-
-
-
-
-
-
spring.cloud.vault:
-    mongodb:
-        enabled: true
-        role: readonly
-        backend: mongodb
-        username-property: spring.data.mongodb.username
-        password-property: spring.data.mongodb.password
-
-
-
-
-
-
    -
  • -

    enabled setting this value to true enables the MongodB backend config usage

    -
  • -
  • -

    role sets the role name of the MongoDB role definition

    -
  • -
  • -

    backend sets the path of the MongoDB mount to use

    -
  • -
  • -

    username-property sets the property name in which the MongoDB username is stored

    -
  • -
  • -

    password-property sets the property name in which the MongoDB password is stored

    -
  • -
-
- -
-
-

MySQL

-
-

Spring Cloud Vault can obtain credentials for MySQL. -The integration can be enabled by setting -spring.cloud.vault.mysql.enabled=true (default false) and -providing the role name with spring.cloud.vault.mysql.role=….

-
-
-

Username and password are stored in spring.datasource.username -and spring.datasource.password so using Spring Boot will -pick up the generated credentials without further configuration. -You can configure the property names by setting -spring.cloud.vault.mysql.username-property and -spring.cloud.vault.mysql.password-property.

-
-
-
-
-
-
spring.cloud.vault:
-    mysql:
-        enabled: true
-        role: readonly
-        backend: mysql
-        username-property: spring.datasource.username
-        password-property: spring.datasource.username
-
-
-
-
-
-
    -
  • -

    enabled setting this value to true enables the MySQL backend config usage

    -
  • -
  • -

    role sets the role name of the MySQL role definition

    -
  • -
  • -

    backend sets the path of the MySQL mount to use

    -
  • -
  • -

    username-property sets the property name in which the MySQL username is stored

    -
  • -
  • -

    password-property sets the property name in which the MySQL password is stored

    -
  • -
-
- -
-
-

PostgreSQL

-
-

Spring Cloud Vault can obtain credentials for PostgreSQL. -The integration can be enabled by setting -spring.cloud.vault.postgresql.enabled=true (default false) and -providing the role name with spring.cloud.vault.postgresql.role=….

-
-
-

Username and password are stored in spring.datasource.username -and spring.datasource.password so using Spring Boot will -pick up the generated credentials without further configuration. -You can configure the property names by setting -spring.cloud.vault.postgresql.username-property and -spring.cloud.vault.postgresql.password-property.

-
-
-
-
-
-
spring.cloud.vault:
-    postgresql:
-        enabled: true
-        role: readonly
-        backend: postgresql
-        username-property: spring.datasource.username
-        password-property: spring.datasource.username
-
-
-
-
-
-
    -
  • -

    enabled setting this value to true enables the PostgreSQL backend config usage

    -
  • -
  • -

    role sets the role name of the PostgreSQL role definition

    -
  • -
  • -

    backend sets the path of the PostgreSQL mount to use

    -
  • -
  • -

    username-property sets the property name in which the PostgreSQL username is stored

    -
  • -
  • -

    password-property sets the property name in which the PostgreSQL password is stored

    -
  • -
-
- -
-
-
-
-

Configure PropertySourceLocator behavior

-
-
-

Spring Cloud Vault uses property-based configuration to create PropertySources -for generic and discovered secret backends.

-
-
-

Discovered backends provide VaultSecretBackendDescriptor beans to describe the configuration -state to use secret backend as PropertySource. A SecretBackendMetadataFactory is required -to create a SecretBackendMetadata object which contains path, name and property transformation -configuration.

-
-
-

SecretBackendMetadata is used to back a particular PropertySource.

-
-
-

You can register an arbitrary number of beans implementing VaultConfigurer for customization. -Default generic and discovered backend registration is disabled if Spring Cloud Vault discovers -at least one VaultConfigurer bean. You can however enable default registration with -SecretBackendConfigurer.registerDefaultGenericSecretBackends() and SecretBackendConfigurer.registerDefaultDiscoveredSecretBackends().

-
-
-
-
-
-
public class CustomizationBean implements VaultConfigurer {
-
-    @Override
-    public void addSecretBackends(SecretBackendConfigurer configurer) {
-
-        configurer.add("secret/my-application");
-
-        configurer.registerDefaultGenericSecretBackends(false);
-        configurer.registerDefaultDiscoveredSecretBackends(true);
-    }
-}
-
-
-
-
-
- - - - - -
-
Note
-
-All customization is required to happen in the bootstrap context. Add your configuration -classes to META-INF/spring.factories at org.springframework.cloud.bootstrap.BootstrapConfiguration -in your application. -
-
-
-
-
-

Service Registry Configuration

-
-
-

You can use a DiscoveryClient (such as from Spring Cloud Consul) to locate -a Vault server by setting spring.cloud.vault.discovery.enabled=true (default false). -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 vault but you can change that on the client with -spring.cloud.vault.discovery.serviceId.

-
-
-

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 scheme metadata entry to be set either to https or http. -If no scheme is configured and the service is not exposed as secure service, then -configuration defaults to spring.cloud.vault.scheme which is https when it’s not set.

-
-
-
-
-
-
spring.cloud.vault.discovery:
-    enabled: true
-    service-id: my-vault-service
-
-
-
-
-
-
-
-

Vault Client Fail Fast

-
-
-

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 -spring.cloud.vault.fail-fast=true and the client will halt with -an Exception.

-
-
-
-
-
-
spring.cloud.vault:
-    fail-fast: true
-
-
-
-
-
-
-
-

Vault Client SSL configuration

-
-
-

SSL can be configured declaratively by setting various properties. -You can set either javax.net.ssl.trustStore to configure -JVM-wide SSL settings or spring.cloud.vault.ssl.trust-store -to set SSL settings only for Spring Cloud Vault Config.

-
-
-
-
-
-
spring.cloud.vault:
-    ssl:
-        trust-store: classpath:keystore.jks
-        trust-store-password: changeit
-
-
-
-
-
-
    -
  • -

    trust-store sets the resource for the trust-store. SSL-secured Vault -communication will validate the Vault SSL certificate with the specified -trust-store.

    -
  • -
  • -

    trust-store-password sets the trust-store password

    -
  • -
-
-
-

Please note that configuring spring.cloud.vault.ssl.* can be only -applied when either Apache Http Components or the OkHttp client -is on your class-path.

-
-
-
-
-

Lease lifecycle management (renewal and revocation)

-
-
-

With every secret, Vault creates a lease: -metadata containing information such as a time duration, -renewability, and more.

-
-
-

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.

-
-
-

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.

-
-
-

Secret service and database backends (such as MongoDB or MySQL) -usually generate a renewable lease so generated credentials will -be disabled on application shutdown.

-
-
- - - - - -
-
Note
-
-Static tokens are not renewed or revoked. -
-
-
-

Lease renewal and revocation is enabled by default and can -be disabled by setting spring.cloud.vault.config.lifecycle.enabled -to false. 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.

-
-
-
-
-
-
spring.cloud.vault:
-    config.lifecycle.enabled: true
-
-
-
-
-
diff --git a/spring-cloud-vault.xml b/spring-cloud-vault.xml new file mode 100644 index 00000000..f146a6d8 --- /dev/null +++ b/spring-cloud-vault.xml @@ -0,0 +1,1063 @@ + + + + + +Spring Cloud Vault +2017-08-29 + + + +© 2016-2017 The original authors. + +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. + +Spring Cloud Vault Config provides client-side support for externalized configuration in a distributed system. With HashiCorp’s Vault 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. + + +Quick Start +Prerequisites +To get started with Vault and this guide you need a +*NIX-like operating systems that provides: + + +wget, openssl and unzip + + +at least Java 7 and a properly configured JAVA_HOME environment variable + + +Install Vault +$ src/test/bash/install_vault.sh +Create SSL certificates for Vault +$ src/test/bash/create_certificates.sh + +create_certificates.sh creates certificates in work/ca and a JKS truststore work/keystore.jks. If you want to run Spring Cloud Vault using this quickstart guide you need to configure the truststore the spring.cloud.vault.ssl.trust-store property to file:work/keystore.jks. + +Start Vault server +$ src/test/bash/local_run_vault.sh +Vault is started listening on 0.0.0.0:8200 using the inmem storage and +https. +Vault is sealed and not initialized when starting up. + +If you want to run tests, leave Vault uninitialized. The tests will +initialize Vault and create a root token 00000000-0000-0000-0000-000000000000. + +If you want to use Vault for your application or give it a try then you need to initialize it first. +$ export VAULT_ADDR="https://localhost:8200" +$ export VAULT_SKIP_VERIFY=true # Don't do this for production +$ vault init +You should see something like: +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 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 VAULT_TOKEN + environment variable. +$ 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 accesses different resources. By default, the secret +backend is enabled which accesses secret config settings via JSON endpoints. +The HTTP service has resources in the form: +/secret/{application}/{profile} +/secret/{application} +/secret/{defaultContext}/{profile} +/secret/{defaultContext} +where the "application" is injected as the spring.application.name in the +SpringApplication (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. + + +Client Side Usage +To use these features in an application, just build it as a Spring +Boot application that depends on spring-cloud-vault-config (e.g. see +the test cases). Example Maven configuration: + +pom.xml +<parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>1.5.4.RELEASE</version> + <relativePath /> <!-- lookup parent from repository --> +</parent> + +<dependencies> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-vault-config</artifactId> + <version>1.1.0.BUILD-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> +</dependencies> + +<build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> +</build> + +<!-- repositories also needed for snapshots and milestones --> + +Then you can create a standard Spring Boot application, like this simple HTTP server: + +@SpringBootApplication +@RestController +public class Application { + + @RequestMapping("/") + public String home() { + return "Hello World!"; + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} + +When it runs it will pick up the external configuration from the +default local Vault server on port 8200 if it is running. To modify +the startup behavior you can change the location of the Vault server +using bootstrap.properties (like application.properties but for +the bootstrap phase of an application context), e.g. + +bootstrap.yml +spring.cloud.vault: + host: localhost + port: 8200 + scheme: https + uri: https://localhost:8200 + connection-timeout: 5000 + read-timeout: 15000 + config: + order: -10 + + + +host sets the hostname of the Vault host. The host name will be used +for SSL certificate validation + + +port sets the Vault port + + +scheme setting the scheme to http will use plain HTTP. +Supported schemes are http and https. + + +uri configure the Vault endpoint with an URI. Takes precedence over host/port/scheme configuration + + +connection-timeout sets the connection timeout in milliseconds + + +read-timeout sets the read timeout in milliseconds + + +config.order sets the order for the property source + + +Enabling further integrations requires additional dependencies and +configuration. Depending on how you have set up Vault you might need +additional configuration like +SSL and +authentication. +If the application imports the spring-boot-starter-actuator project, the +status of the vault server will be available via the /health endpoint. +The vault health indicator can be enabled or disabled through the +property health.vault.enabled (default true). +
+Authentication +Vault requires an authentication mechanism to authorize client requests. +Spring Cloud Vault supports multiple authentication mechanisms to authenticate applications with Vault. +For a quickstart, use the root token printed by the Vault initialization. + +bootstrap.yml +spring.cloud.vault: + token: 19aefa97-cccc-bbbb-aaaa-225940e63d76 + + +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. + +
+
+ +Authentication methods +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. +
+Token authentication +Tokens are the core method for authentication within Vault. +Token authentication requires a static token to be provided using the +Bootstrap Application Context. + +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. + + +bootstrap.yml +spring.cloud.vault: + authentication: TOKEN + token: 00000000-0000-0000-0000-000000000000 + + + +authentication setting this value to TOKEN selects the Token +authentication method + + +token sets the static token to use + + +See also: Vault Documentation: Tokens +
+
+AppId authentication +Vault supports AppId +authentication that consists of two hard to guess tokens. The AppId +defaults to spring.application.name 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’s (e.g. supplied via System properties). +The IP and Mac address are represented as Hex-encoded SHA256 hash. +IP address-based UserId’s use the local host’s IP address. + +bootstrap.yml using SHA256 IP-Address UserId’s +spring.cloud.vault: + authentication: APPID + app-id: + user-id: IP_ADDRESS + + + +authentication setting this value to APPID selects the AppId +authentication method + + +app-id-path sets the path of the AppId mount to use + + +user-id sets the UserId method. Possible values are IP_ADDRESS, +MAC_ADDRESS or a class name implementing a custom AppIdUserIdMechanism + + +The corresponding command to generate the IP address UserId from a command line is: +$ echo -n 192.168.99.1 | sha256sum + +Including the line break of echo leads to a different hash value +so make sure to include the -n flag. + +Mac address-based UserId’s obtain their network device from the +localhost-bound device. The configuration also allows specifying +a network-interface hint to pick the right device. The value of +network-interface is optional and can be either an interface +name or interface index (0-based). + +bootstrap.yml using SHA256 Mac-Address UserId’s +spring.cloud.vault: + authentication: APPID + app-id: + user-id: MAC_ADDRESS + network-interface: eth0 + + + +network-interface sets network interface to obtain the physical address + + +The corresponding command to generate the IP address UserId from a command line is: +$ echo -n 0AFEDE1234AC | sha256sum + +The Mac address is specified uppercase and without colons. +Including the line break of echo leads to a different hash value +so make sure to include the -n flag. + +
+Custom UserId +The UserId generation is an open mechanism. You can set +spring.cloud.vault.app-id.user-id to any string and the configured +value will be used as static UserId. +A more advanced approach lets you set spring.cloud.vault.app-id.user-id to a +classname. This class must be on your classpath and must implement +the org.springframework.cloud.vault.AppIdUserIdMechanism interface +and the createUserId method. Spring Cloud Vault will obtain the UserId +by calling createUserId each time it authenticates using AppId to +obtain a token. + +bootstrap.yml +spring.cloud.vault: + authentication: APPID + app-id: + user-id: com.examlple.MyUserIdMechanism + + +MyUserIdMechanism.java +public class MyUserIdMechanism implements AppIdUserIdMechanism { + + @Override + public String createUserId() { + String userId = ... + return userId; + } +} + +See also: Vault Documentation: Using the App ID auth backend +
+
+
+AppRole authentication +AppRole is intended for machine +authentication, like the deprecated (since Vault 0.6.1) . +AppRole authentication consists of two hard to guess (secret) tokens: RoleId and SecretId. +Spring Vault supports AppRole authentication by providing either RoleId only +or together with a provided SecretId (push or pull mode). +RoleId and optionally SecretId must be provided by configuration, +Spring Vault will not look up these or create a custom SecretId. + +bootstrap.yml with AppRole authentication properties +spring.cloud.vault: + authentication: APPROLE + app-role: + role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52 + + + +role-id sets the RoleId. + + + +bootstrap.yml with all AppRole authentication properties +spring.cloud.vault: + authentication: APPROLE + app-role: + role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52 + secret-id: 1696536f-1976-73b1-b241-0b4213908d39 + app-auth-path: approle + + + +role-id sets the RoleId. + + +secret-id sets the SecretId. SecretId can be omitted if AppRole is configured without requiring SecretId (See bind_secret_id) + + +approle-path sets the path of the approle authentication mount to use + + +See also: Vault Documentation: Using the AppRole auth backend +
+
+AWS-EC2 authentication +The aws-ec2 +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. + +bootstrap.yml using AWS-EC2 Authentication +spring.cloud.vault: + authentication: AWS_EC2 + +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. +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. +The nonce is kept in memory and is lost during application restart. +You can configure a static nonce with spring.cloud.vault.aws-ec2.nonce. +AWS-EC2 authentication roles are optional and default to the AMI. +You can configure the authentication role by setting the +spring.cloud.vault.aws-ec2.role property. + +bootstrap.yml with configured role +spring.cloud.vault: + authentication: AWS_EC2 + aws-ec2: + role: application-server + + +bootstrap.yml with all AWS EC2 authentication properties +spring.cloud.vault: + authentication: AWS_EC2 + aws-ec2: + role: application-server + aws-ec2-path: aws-ec2 + identity-document: http://... + nonce: my-static-nonce + + + +authentication setting this value to AWS_EC2 selects the AWS EC2 +authentication method + + +role sets the role name of the AWS EC2 role definition + + +aws-ec2-path sets the path of the AWS EC2 mount to use + + +identity-document sets URL of the PKCS#7 AWS EC2 identity document + + +nonce used for AWS-EC2 authentication. An empty nonce defaults to nonce generation + + +See also: Vault Documentation: Using the aws-ec2 auth backend +
+
+TLS certificate authentication +The cert auth backend allows authentication using SSL/TLS client +certificates that are either signed by a CA or self-signed. +To enable cert authentication you need to: + + +Use SSL, see + + +Configure a Java Keystore that contains the client +certificate and the private key + + +Set the spring.cloud.vault.authentication to CERT + + + +bootstrap.yml +spring.cloud.vault: + authentication: CERT + ssl: + key-store: classpath:keystore.jks + key-store-password: changeit + cert-auth-path: cert + +See also: Vault Documentation: Using the Cert auth backend +
+
+Cubbyhole authentication +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’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 /cubbyhole/response. +Creating a wrapped token + +Response Wrapping for token creation requires Vault 0.6.0 or higher. + + +Crating and storing tokens +$ 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 + + +bootstrap.yml +spring.cloud.vault: + authentication: CUBBYHOLE + token: 397ccb93-ff6c-b17b-9389-380b01ca2645 + +See also: + + +Vault Documentation: Tokens + + +Vault Documentation: Cubbyhole Secret Backend + + +Vault Documentation: Response Wrapping + + +
+
+ +Secret Backends +
+Generic Backend +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 (application) in combination with active +profiles. +/secret/{application}/{profile} +/secret/{application} +/secret/{default-context}/{profile} +/secret/{default-context} +The application name is determined by the properties: + + +spring.cloud.vault.generic.application-name + + +spring.cloud.vault.application-name + + +spring.application.name + + +Secrets can be obtained from other folders within the generic backend by adding their +paths to the application name, separated by commas. For example, given the application +name usefulapp,mysql1,projectx/aws, each of these folders will be used: + + +/secret/usefulapp + + +/secret/mysql1 + + +/secret/projectx/aws + + +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. +Properties are exposed like they are stored (i.e. without additional prefixes). + +spring.cloud.vault: + generic: + enabled: true + backend: secret + profile-separator: '/' + default-context: application + application-name: my-app + + + +enabled setting this value to false disables the secret backend +config usage + + +backend sets the path of the secret mount to use + + +default-context sets the context name used by all applications + + +application-name overrides the application name for use in the generic backend + + +profile-separator separates the profile name from the context in +property sources with profiles + + +See also: Vault Documentation: Using the generic secret backend +
+
+Consul +Spring Cloud Vault can obtain credentials for HashiCorp Consul. +The Consul integration requires the spring-cloud-vault-config-consul +dependency. + +pom.xml +<dependencies> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-vault-config-consul</artifactId> + <version>1.1.0.BUILD-SNAPSHOT</version> + </dependency> +</dependencies> + +The integration can be enabled by setting +spring.cloud.vault.consul.enabled=true (default false) and +providing the role name with spring.cloud.vault.consul.role=…. +The obtained token is stored in spring.cloud.consul.token +so using Spring Cloud Consul can pick up the generated +credentials without further configuration. You can configure +the property name by setting spring.cloud.vault.consul.token-property. + +spring.cloud.vault: + consul: + enabled: true + role: readonly + backend: consul + token-property: spring.cloud.consul.token + + + +enabled setting this value to true enables the Consul backend config usage + + +role sets the role name of the Consul role definition + + +backend sets the path of the Consul mount to use + + +token-property sets the property name in which the Consul ACL token is stored + + +See also: Vault Documentation: Setting up Consul with Vault +
+
+RabbitMQ +Spring Cloud Vault can obtain credentials for RabbitMQ. +The RabbitMQ integration requires the spring-cloud-vault-config-rabbitmq +dependency. + +pom.xml +<dependencies> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-vault-config-rabbitmq</artifactId> + <version>1.1.0.BUILD-SNAPSHOT</version> + </dependency> +</dependencies> + +The integration can be enabled by setting +spring.cloud.vault.rabbitmq.enabled=true (default false) +and providing the role name with spring.cloud.vault.rabbitmq.role=…. +Username and password are stored in spring.rabbitmq.username +and spring.rabbitmq.password so using Spring Boot will pick up the generated +credentials without further configuration. You can configure the property names +by setting spring.cloud.vault.rabbitmq.username-property and +spring.cloud.vault.rabbitmq.password-property. + +spring.cloud.vault: + rabbitmq: + enabled: true + role: readonly + backend: rabbitmq + username-property: spring.rabbitmq.username + password-property: spring.rabbitmq.password + + + +enabled setting this value to true enables the RabbitMQ backend config usage + + +role sets the role name of the RabbitMQ role definition + + +backend sets the path of the RabbitMQ mount to use + + +username-property sets the property name in which the RabbitMQ username is stored + + +password-property sets the property name in which the RabbitMQ password is stored + + +See also: Vault Documentation: Setting up RabbitMQ with Vault +
+
+AWS +Spring Cloud Vault can obtain credentials for AWS. +The AWS integration requires the spring-cloud-vault-config-aws +dependency. + +pom.xml +<dependencies> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-vault-config-aws</artifactId> + <version>1.1.0.BUILD-SNAPSHOT</version> + </dependency> +</dependencies> + +The integration can be enabled by setting +spring.cloud.vault.aws=true (default false) +and providing the role name with spring.cloud.vault.aws.role=…. +The access key and secret key are stored in cloud.aws.credentials.accessKey +and cloud.aws.credentials.secretKey so using Spring Cloud AWS will pick up the generated +credentials without further configuration. You can configure the property names +by setting spring.cloud.vault.aws.access-key-property and +spring.cloud.vault.aws.secret-key-property. + +spring.cloud.vault: + aws: + enabled: true + role: readonly + backend: aws + access-key-property: cloud.aws.credentials.accessKey + secret-key-property: cloud.aws.credentials.secretKey + + + +enabled setting this value to true enables the AWS backend config usage + + +role sets the role name of the AWS role definition + + +backend sets the path of the AWS mount to use + + +access-key-property sets the property name in which the AWS access key is stored + + +secret-key-property sets the property name in which the AWS secret key is stored + + +See also: Vault Documentation: Setting up AWS with Vault +
+
+ +Database backends +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’s leasing +mechanism to more easily roll keys. +Spring Cloud Vault integrates with these backends: + + + + + + + + + + + + + + +Using a database secret backend requires to enable the +backend in the configuration and the spring-cloud-vault-config-databases +dependency. + +pom.xml +<dependencies> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-vault-config-databases</artifactId> + <version>1.1.0.BUILD-SNAPSHOT</version> + </dependency> +</dependencies> + + +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. + +
+Apache Cassandra +Spring Cloud Vault can obtain credentials for Apache Cassandra. +The integration can be enabled by setting +spring.cloud.vault.cassandra.enabled=true (default false) and +providing the role name with spring.cloud.vault.cassandra.role=…. +Username and password are stored in spring.data.cassandra.username +and spring.data.cassandra.password so using Spring Boot will pick +up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.cassandra.username-property and +spring.cloud.vault.cassandra.password-property. + +spring.cloud.vault: + cassandra: + enabled: true + role: readonly + backend: cassandra + username-property: spring.data.cassandra.username + password-property: spring.data.cassandra.username + + + +enabled setting this value to true enables the Cassandra backend config usage + + +role sets the role name of the Cassandra role definition + + +backend sets the path of the Cassandra mount to use + + +username-property sets the property name in which the Cassandra username is stored + + +password-property sets the property name in which the Cassandra password is stored + + +See also: Vault Documentation: Setting up Apache Cassandra with Vault +
+
+MongoDB +Spring Cloud Vault can obtain credentials for MongoDB. +The integration can be enabled by setting +spring.cloud.vault.mongodb.enabled=true (default false) and +providing the role name with spring.cloud.vault.mongodb.role=…. +Username and password are stored in spring.data.mongodb.username +and spring.data.mongodb.password so using Spring Boot will +pick up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.mongodb.username-property and +spring.cloud.vault.mongodb.password-property. + +spring.cloud.vault: + mongodb: + enabled: true + role: readonly + backend: mongodb + username-property: spring.data.mongodb.username + password-property: spring.data.mongodb.password + + + +enabled setting this value to true enables the MongodB backend config usage + + +role sets the role name of the MongoDB role definition + + +backend sets the path of the MongoDB mount to use + + +username-property sets the property name in which the MongoDB username is stored + + +password-property sets the property name in which the MongoDB password is stored + + +See also: Vault Documentation: Setting up MongoDB with Vault +
+
+MySQL +Spring Cloud Vault can obtain credentials for MySQL. +The integration can be enabled by setting +spring.cloud.vault.mysql.enabled=true (default false) and +providing the role name with spring.cloud.vault.mysql.role=…. +Username and password are stored in spring.datasource.username +and spring.datasource.password so using Spring Boot will +pick up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.mysql.username-property and +spring.cloud.vault.mysql.password-property. + +spring.cloud.vault: + mysql: + enabled: true + role: readonly + backend: mysql + username-property: spring.datasource.username + password-property: spring.datasource.username + + + +enabled setting this value to true enables the MySQL backend config usage + + +role sets the role name of the MySQL role definition + + +backend sets the path of the MySQL mount to use + + +username-property sets the property name in which the MySQL username is stored + + +password-property sets the property name in which the MySQL password is stored + + +See also: Vault Documentation: Setting up MySQL with Vault +
+
+PostgreSQL +Spring Cloud Vault can obtain credentials for PostgreSQL. +The integration can be enabled by setting +spring.cloud.vault.postgresql.enabled=true (default false) and +providing the role name with spring.cloud.vault.postgresql.role=…. +Username and password are stored in spring.datasource.username +and spring.datasource.password so using Spring Boot will +pick up the generated credentials without further configuration. +You can configure the property names by setting +spring.cloud.vault.postgresql.username-property and +spring.cloud.vault.postgresql.password-property. + +spring.cloud.vault: + postgresql: + enabled: true + role: readonly + backend: postgresql + username-property: spring.datasource.username + password-property: spring.datasource.username + + + +enabled setting this value to true enables the PostgreSQL backend config usage + + +role sets the role name of the PostgreSQL role definition + + +backend sets the path of the PostgreSQL mount to use + + +username-property sets the property name in which the PostgreSQL username is stored + + +password-property sets the property name in which the PostgreSQL password is stored + + +See also: Vault Documentation: Setting up PostgreSQL with Vault +
+
+ +Configure <literal>PropertySourceLocator</literal> behavior +Spring Cloud Vault uses property-based configuration to create PropertySources +for generic and discovered secret backends. +Discovered backends provide VaultSecretBackendDescriptor beans to describe the configuration +state to use secret backend as PropertySource. A SecretBackendMetadataFactory is required +to create a SecretBackendMetadata object which contains path, name and property transformation +configuration. +SecretBackendMetadata is used to back a particular PropertySource. +You can register an arbitrary number of beans implementing VaultConfigurer for customization. +Default generic and discovered backend registration is disabled if Spring Cloud Vault discovers +at least one VaultConfigurer bean. You can however enable default registration with +SecretBackendConfigurer.registerDefaultGenericSecretBackends() and SecretBackendConfigurer.registerDefaultDiscoveredSecretBackends(). + +public class CustomizationBean implements VaultConfigurer { + + @Override + public void addSecretBackends(SecretBackendConfigurer configurer) { + + configurer.add("secret/my-application"); + + configurer.registerDefaultGenericSecretBackends(false); + configurer.registerDefaultDiscoveredSecretBackends(true); + } +} + + +All customization is required to happen in the bootstrap context. Add your configuration +classes to META-INF/spring.factories at org.springframework.cloud.bootstrap.BootstrapConfiguration +in your application. + + + +Service Registry Configuration +You can use a DiscoveryClient (such as from Spring Cloud Consul) to locate +a Vault server by setting spring.cloud.vault.discovery.enabled=true (default false). +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 vault but you can change that on the client with +spring.cloud.vault.discovery.serviceId. +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 scheme metadata entry to be set either to https or http. +If no scheme is configured and the service is not exposed as secure service, then +configuration defaults to spring.cloud.vault.scheme which is https when it’s not set. + +spring.cloud.vault.discovery: + enabled: true + service-id: my-vault-service + + + +Vault Client Fail Fast +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 +spring.cloud.vault.fail-fast=true and the client will halt with +an Exception. + +spring.cloud.vault: + fail-fast: true + + + +Vault Client SSL configuration +SSL can be configured declaratively by setting various properties. +You can set either javax.net.ssl.trustStore to configure +JVM-wide SSL settings or spring.cloud.vault.ssl.trust-store +to set SSL settings only for Spring Cloud Vault Config. + +spring.cloud.vault: + ssl: + trust-store: classpath:keystore.jks + trust-store-password: changeit + + + +trust-store sets the resource for the trust-store. SSL-secured Vault +communication will validate the Vault SSL certificate with the specified +trust-store. + + +trust-store-password sets the trust-store password + + +Please note that configuring spring.cloud.vault.ssl.* can be only +applied when either Apache Http Components or the OkHttp client +is on your class-path. + + +Lease lifecycle management (renewal and revocation) +With every secret, Vault creates a lease: +metadata containing information such as a time duration, +renewability, and more. +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. +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. +Secret service and database backends (such as MongoDB or MySQL) +usually generate a renewable lease so generated credentials will +be disabled on application shutdown. + +Static tokens are not renewed or revoked. + +Lease renewal and revocation is enabled by default and can +be disabled by setting spring.cloud.vault.config.lifecycle.enabled +to false. 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. + +spring.cloud.vault: + config.lifecycle.enabled: true + +See also: Vault Documentation: Lease, Renew, and Revoke + +
\ No newline at end of file