### Generate README.adoc from docs
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Regenerate README.adoc from the docs directory. Requires Ruby and the asciidoctor gem installed via gem install asciidoctor.
```bash
$ ../mvnw clean install -Pdocs
```
--------------------------------
### Install Vault with wget and unzip
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Downloads and extracts the Vault binary for the specified version and platform. Requires wget and unzip.
```bash
$ wget https://releases.hashicorp.com/vault/${vault_version}/vault_${vault_version}_${platform}.zip
$ unzip vault_${vault_version}_${platform}.zip
```
--------------------------------
### Run Vault setup scripts
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Run these scripts before building the project to set up SSL certificates and a running Vault instance on localhost:8200. Leave Vault uninitialized; tests will initialize and unseal it and create a root token 00000000-0000-0000-0000-000000000000.
```bash
$ ./src/test/bash/install_vault.sh
$ ./src/test/bash/create_certificates.sh
$ ./src/test/bash/local_run_vault.sh
```
--------------------------------
### Vault initialization output
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Example output from 'vault operator init' showing unseal keys and the initial root token.
```bash
Key 1: 7149c6a2e16b8833f6eb1e76df03e47f6113a3288b3093faf5033d44f0e70fe701
Key 2: 901c534c7988c18c20435a85213c683bdcf0efcd82e38e2893779f152978c18c02
Key 3: 03ff3948575b1165a20c20ee7c3e6edf04f4cdbe0e82dbff5be49c63f98bc03a03
Key 4: 216ae5cc3ddaf93ceb8e1d15bb9fc3176653f5b738f5f3d1ee00cd7dccbe926e04
Key 5: b2898fc8130929d569c1677ee69dc5f3be57d7c4b494a6062693ce0b1c4d93d805
Initial Root Token: 19aefa97-cccc-bbbb-aaaa-225940e63d76
```
--------------------------------
### Maven Configuration for spring-cloud-starter-vault-config
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Example pom.xml with parent, dependencies, and build plugins for using Spring Cloud Vault Config. Requires repositories for snapshots and milestones.
```xml
org.springframework.boot
spring-boot-starter-parent
${springBootVersion}
org.springframework.cloud
spring-cloud-starter-vault-config
{project-version}
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
```
--------------------------------
### Generate docs site with Antora
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Generate the documentation site using the docs profile and Antora. This processes includes from docs/src/main/asciidoc/README.adoc and copies the result to the project root.
```bash
./mvnw -pl docs -P docs antora:antora
```
--------------------------------
### Start Vault server
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Starts the Vault server using the specified configuration file. The server listens on 0.0.0.0:8200 with HTTPS and in-memory storage.
```bash
$ vault server -config=vault.conf
```
--------------------------------
### Spring Cloud Build checkstyle module file tree
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Shows the file layout of the spring-cloud-build-tools module, including checkstyle configuration files. The tree uses callouts to identify default rules, file header setup, and default suppression rules.
```text
└── src
├── checkstyle
│ └── checkstyle-suppressions.xml <3>
└── main
└── resources
├── checkstyle-header.txt <2>
└── checkstyle.xml <1>
```
--------------------------------
### Checkstyle Suppressions File Example
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Defines a checkstyle-suppressions.xml file to suppress specific rules, such as HideUtilityClassConstructor and LineLengthCheck, for particular files. Place it under ${project.root}/src/checkstyle/.
```xml
```
--------------------------------
### Configure Vault token and import in application.yml
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Set the Vault token and use Spring Boot's Config Data API by setting spring.config.import to vault://. Static token authentication is suitable for quickstarts but not recommended for production due to security risks.
```yaml
spring.cloud.vault:
token: 19aefa97-cccc-bbbb-aaaa-225940e63d76
spring.config.import: vault://
```
--------------------------------
### Spring Cloud Build Tools Directory Structure
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Shows the layout of the spring-cloud-build-tools directory, including checkstyle configuration and Intellij project files.
```text
└── src
├── checkstyle
│ └── checkstyle-suppressions.xml <3>
└── main
└── resources
├── checkstyle-header.txt <2>
├── checkstyle.xml <1>
└── intellij
├── Intellij_Project_Defaults.xml <4>
└── Intellij_Spring_Boot_Java_Conventions.xml <5>
```
--------------------------------
### Download EditorConfig and Spring Format Files
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Downloads the .editorconfig and creates an empty .springformat file to apply default formatting rules. Run these commands from the project root.
```bash
$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/.editorconfig -o .editorconfig
$ touch .springformat
```
--------------------------------
### Initialize Vault
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Sets Vault address and skips TLS verification (not for production), then initializes Vault. Output includes unseal keys and initial root token.
```bash
$ export VAULT_ADDR="https://localhost:8200"
$ export VAULT_SKIP_VERIFY=true # Don't do this for production
$ vault operator init
```
--------------------------------
### Create Vault token for tests
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/quickstart.adoc
Creates a root token with a fixed ID for running Spring Cloud Vault tests after manual initialization.
```shell
$ vault token create -id="00000000-0000-0000-0000-000000000000" -policy="root"
```
--------------------------------
### Build with Maven wrapper
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Basic compile and test using the Maven wrapper. Requires JDK 17. You can also use a local Maven (>=3.3.3) with the mvn command and possibly add -P spring for pre-release artifacts.
```bash
$ ./mvnw install
```
--------------------------------
### Vault Configuration in application.yml
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
YAML configuration for connecting to a Vault server, including host, port, scheme, URI, timeouts, and spring.config.import to mount Vault as PropertySource.
```yaml
spring.cloud.vault:
host: localhost
port: 8200
scheme: https
uri: https://localhost:8200
connection-timeout: 5000
read-timeout: 15000
spring.config.import: vault://
```
--------------------------------
### Configure ignoredClassPatterns and ignoredResourcePatterns for duplicate-finder
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Shows how to add ignoredClassPatterns and ignoredResourcePatterns in the plugin configuration section. Use this to exclude specific classes or resources from duplicate checks.
```xml
org.basepom.maven
duplicate-finder-maven-plugin
org.joda.time.base.BaseDateTime
.*module-info
changelog.txt
```
--------------------------------
### Vault server configuration file
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Configures Vault with in-memory storage, a TCP listener on port 8200 with TLS certificates, and disables mlock. Save as vault.conf.
```hcl
backend "inmem" {
}
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "work/ca/certs/localhost.cert.pem"
tls_key_file = "work/ca/private/localhost.decrypted.key.pem"
}
disable_mlock = true
```
--------------------------------
### Unseal Vault and Create Token
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Commands to unseal Vault after initialization using three unsealing keys, export the root token to VAULT_TOKEN, and create a root token with a specific ID for Spring Cloud Vault tests.
```bash
$ vault operator unseal (Key 1)
$ vault operator unseal (Key 2)
$ vault operator 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"
```
--------------------------------
### Customizing ClientHttpRequestFactory
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/config-data.adoc
Shows how to customize the infrastructure used by Spring Cloud Vault by registering a custom `ClientHttpRequestFactory` via the `Bootstrapper` API. This example creates an `HttpClientBuilder` with default SSL configuration.
```java
ClientOptions options = new ClientOptions();
SslConfiguration sslConfiguration = SslConfiguration.unconfigured();
HttpClientBuilder builder = HttpComponents.getHttpClientBuilder(options, sslConfiguration);
```
--------------------------------
### Generate Eclipse project metadata with Maven wrapper
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Use this command to generate Eclipse project metadata when not using m2eclipse. Run it from the project root; the generated projects can be imported via 'import existing projects' in Eclipse.
```shell
$ ./mvnw eclipse:eclipse
```
--------------------------------
### Spring Boot Application with Vault
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Standard Spring Boot application that picks up external configuration from the default local Vault server on port 8200 when running.
```java
@SpringBootApplication
@RestController
public class Application {
@RequestMapping("/")
public String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```
--------------------------------
### Add duplicate-finder-maven-plugin to pom.xml
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Required to enable the duplicate-finder-maven-plugin in the build section of the project's pom.xml. The plugin is enabled by default and runs in the verify phase, but only takes effect when added to the build.
```xml
org.basepom.maven
duplicate-finder-maven-plugin
```
--------------------------------
### Maven POM Configuration for Checkstyle and Spring Java Format
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
Adds Maven properties and plugins to fail the build on Checkstyle errors/violations, include test sources in analysis, and apply Spring Java Format. The checkstyle plugin is added to both build and reporting phases.
```xml
true <1>
true
<2>
true
<3>
<4>
io.spring.javaformat
spring-javaformat-maven-plugin
<5>
org.apache.maven.plugins
maven-checkstyle-plugin
<5>
org.apache.maven.plugins
maven-checkstyle-plugin
```
--------------------------------
### Vault Secret Backend Resources
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/README.adoc
HTTP resource paths for accessing secret config settings via JSON endpoints. The application name is injected as spring.application.name, and profile is an active profile or comma-separated list.
```text
/secret/{application}/{profile}
/secret/{application}
/secret/{defaultContext}/{profile}
/secret/{defaultContext}
```
--------------------------------
### Unseal Vault and set token
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/quickstart.adoc
Unseals Vault using three of the generated keys and stores the root token in the VAULT_TOKEN environment variable. Replace (Key 1), (Key 2), (Key 3), and (Root token) with actual values.
```bash
$ vault operator unseal (Key 1)
$ vault operator unseal (Key 2)
$ vault operator unseal (Key 3)
$ export VAULT_TOKEN=(Root token)
```
--------------------------------
### Custom VaultConfigurer implementation
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Shows the start of a custom `VaultConfigurer` implementation to customize which secret backends are exposed as `PropertySource`. Providing a `VaultConfigurer` disables default key-value and discovered backend registration unless explicitly re-enabled via `SecretBackendConfigurer` methods.
```java
public class MyConfigurer implements VaultConfigurer {
```
--------------------------------
### TLS Certificate Authentication Configuration
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Enables cert authentication using SSL/TLS client certificates. Requires SSL configuration, a Java Keystore containing the client certificate and private key, and setting spring.cloud.vault.authentication to CERT. The example shows key-store, key-store-password, key-store-type, cert-auth-path, and role properties.
```yaml
spring.cloud.vault:
authentication: CERT
ssl:
key-store: classpath:keystore.jks
key-store-password: changeit
key-store-type: JKS
cert-auth-path: cert
role: my-dev-role
```
--------------------------------
### Enable Vault client fail-fast with spring.cloud.vault.fail-fast
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/advanced-topics.adoc
Set spring.cloud.vault.fail-fast=true to halt service startup with an Exception if the Vault server cannot be connected.
```yaml
spring.cloud.vault:
fail-fast: true
```
--------------------------------
### Configure Vault client SSL with spring.cloud.vault.ssl
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/advanced-topics.adoc
Configures SSL settings for Spring Cloud Vault Config only. Requires Apache Http Components or OkHttp client on the class-path. trust-store sets the resource for the trust-store; trust-store-password sets the password; trust-store-type sets the type (supports all KeyStore types including PEM); enabled-protocols and enabled-cipher-suites are available since 3.0.2.
```yaml
spring.cloud.vault:
ssl:
trust-store: classpath:keystore.jks
trust-store-password: changeit
trust-store-type: JKS
enabled-protocols: TLSv1.2,TLSv1.3
enabled-cipher-suites: TLS_AES_128_GCM_SHA256
```
--------------------------------
### Configure Vault config lease lifecycle (spring.cloud.vault.config.lifecycle)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/advanced-topics.adoc
YAML configuration for managing Vault config leases. `enabled` controls lease renewal and rotation (default true), `min-renewal` prevents too-frequent renewals, `expiry-threshold` sets when to renew before expiry, and `lease-endpoints` selects Legacy (pre-0.8) or SysLeases endpoints. `lease-strategy` (DropOnError, RetainOnError, RetainOnIoError) controls error handling on renewal.
```yaml
spring.cloud.vault:
config.lifecycle:
enabled: true
min-renewal: 10s
expiry-threshold: 1m
lease-endpoints: Legacy
```
--------------------------------
### Vault Config Import with Prefixes
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/config-data.adoc
Uses the `prefix` query parameter to avoid property name shadowing when the same secret names exist in different context paths. Prefixes are added as-is to all property names, so include a trailing dot for separation.
```yaml
spring.config.import: vault://my/path?prefix=foo., vault://my/other/path?prefix=bar.
secret: ${foo.secret}
other.secret: ${bar.secret}
```
--------------------------------
### Customize ClientFactoryWrapper with HttpComponentsClientHttpRequestFactory
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/config-data.adoc
Registers a custom ClientFactoryWrapper in the bootstrap registry to configure the HTTP client used by Vault. The supplier builds an HttpComponentsClientHttpRequestFactory from a builder and wraps it.
```java
InstanceSupplier supplier = context ->
new ClientFactoryWrapper(new HttpComponentsClientHttpRequestFactory(builder.build()));
SpringApplication application = new SpringApplication(MyApplication.class);
application.addBootstrapRegistryInitializer(registry -> registry.register(ClientFactoryWrapper.class, supplier));
```
--------------------------------
### Cubbyhole Authentication - Create Wrapped Token
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Creates a wrapped token using the Vault CLI with a 10-minute TTL. The output shows the wrapping token and related metadata. Requires Vault 0.6.0 or higher for response wrapping.
```shell
$ 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
```
--------------------------------
### PCF authentication with all properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configures Spring Cloud Vault to authenticate using Pivotal CloudFoundry's pcf auth backend with all available properties. instance-certificate and instance-key default to the CF_INSTANCE_CERT and CF_INSTANCE_KEY environment variables respectively. Requires BouncyCastle (bcpkix-jdk15on) on the classpath for RSA PSS signing.
```yaml
spring.cloud.vault:
authentication: PCF
pcf:
role: my-dev-role
pcf-path: path
instance-certificate: /etc/cf-instance-credentials/instance.crt
instance-key: /etc/cf-instance-credentials/instance.key
```
--------------------------------
### Configure Vault session token lifecycle (spring.cloud.vault.session.lifecycle)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/advanced-topics.adoc
YAML configuration for session token lifecycle management. `enabled` controls renewal (default true), `refresh-before-expiry` determines when to renew (default 5s), and `expiry-threshold` sets the minimum TTL to consider a token valid (default 7s). The threshold should be greater than `refresh-before-expiry` to prevent token expiry.
```yaml
spring.cloud.vault:
session.lifecycle:
enabled: true
refresh-before-expiry: 10s
expiry-threshold: 20s
```
--------------------------------
### Bootstrap Registry Initializer with Custom Configurer
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Registers a custom configurer as a bootstrap registry initializer for a SpringApplication.
```java
SpringApplication application = new SpringApplication(MyApplication.class);
application.addBootstrapRegistryInitializer(VaultBootstrapper.fromConfigurer(new MyConfigurer()));
```
--------------------------------
### Key-Value Backend Path Patterns
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Shows the path patterns used by Spring Cloud Vault to access secrets in the key-value backend. The application name and active profiles determine the context paths.
```text
/secret/{application}/{profile}
/secret/{application}
/secret/{default-context}/{profile}
/secret/{default-context}
```
--------------------------------
### Configure Vault discovery via spring.cloud.vault.discovery
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/advanced-topics.adoc
Enables service discovery to locate a Vault server. Set spring.cloud.vault.discovery.enabled=true (default false) and optionally change the service id with spring.cloud.vault.discovery.serviceId. The default service id is 'vault'.
```yaml
spring.cloud.vault.discovery:
enabled: true
service-id: my-vault-service
```
--------------------------------
### Customize RestTemplateBuilder with default header
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/config-data.adoc
Registers a custom RestTemplateBuilder in the bootstrap registry to customize the RestTemplate used by Vault. The builder uses the ClientFactoryWrapper from the context and adds a default header for the Vault namespace.
```java
InstanceSupplier supplier = context -> {
return RestTemplateBuilder
.builder()
.requestFactory(context.get(ClientFactoryWrapper.class).getClientHttpRequestFactory())
.defaultHeader("X-Vault-Namespace", "my-namespace");
};
SpringApplication application = new SpringApplication(MyApplication.class);
application.addBootstrapRegistryInitializer(registry -> registry.register(RestTemplateBuilder.class, supplier));
```
--------------------------------
### Configure multiple database backends (YAML)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Configures multiple database secret backends under `spring.cloud.vault.databases.*`. Each entry requires unique `username-property` and `password-property` to avoid property shadowing.
```yaml
spring.cloud.vault:
databases:
primary:
enabled: true
role: readwrite
backend: database
username-property: spring.primary-datasource.username
password-property: spring.primary-datasource.password
other-database:
enabled: true
role: readonly
backend: database
username-property: spring.secondary-datasource.username
password-property: spring.secondary-datasource.password
```
--------------------------------
### Key-Value Backend Configuration (YAML)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Configuration properties for the key-value backend. Set `enabled` to false to disable, `backend` sets the mount path, `default-context` sets the default context name, `application-name` overrides the application name, `profiles` overrides active profiles, and `profile-separator` separates profile from context.
```yaml
spring.cloud.vault:
kv:
enabled: true
backend: secret
profile-separator: '/'
default-context: application
application-name: my-app
profiles: local, cloud
```
--------------------------------
### Cubbyhole Authentication Configuration
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configures Cubbyhole authentication by setting spring.cloud.vault.authentication to CUBBYHOLE and providing the wrapping token obtained from the token-create command. The login token is retrieved from a wrapped response stored at /cubbyhole/response.
```yaml
spring.cloud.vault:
authentication: CUBBYHOLE
token: 397ccb93-ff6c-b17b-9389-380b01ca2645
```
--------------------------------
### Enable database backend (YAML)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Enables the generic database backend for JDBC databases. Set `spring.cloud.vault.database.enabled=true` and provide the role name. Username and password are stored in `spring.datasource.username` and `spring.datasource.password` by default.
```yaml
spring.cloud.vault:
database:
enabled: true
role: readonly
backend: database
username-property: spring.datasource.username
password-property: spring.datasource.password
```
--------------------------------
### Generate IP Address UserId with sha256sum
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Command to generate the IP address UserId from a command line. The -n flag is required because including the line break of echo leads to a different hash value.
```bash
$ echo -n 192.168.99.1 | sha256sum
```
--------------------------------
### Spring Config Import with Vault Locations
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/config-data.adoc
Configures Spring Boot to import Vault property sources from multiple locations, including the default and contextual paths. The `spring.config.import` property accepts a comma-separated list of Vault locations.
```yaml
spring.config.import: vault://first/context/path, vault://other/path, vault://
```
--------------------------------
### Azure MSI Authentication - All Properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configures Azure MSI authentication with all optional properties: azure-path for the Azure mount path, metadata-service for the instance metadata service URI, and identity-token-service for the identity token service URI. The Vault server Resource Id defaults to https://vault.hashicorp.com; change it by setting identity-token-service.
```yaml
spring.cloud.vault:
authentication: AZURE_MSI
azure-msi:
role: my-dev-role
azure-path: azure
metadata-service: http://169.254.169.254/metadata/instance…
identity-token-service: http://169.254.169.254/metadata/identity…
```
--------------------------------
### AWS-EC2 authentication with all properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configure AWS-EC2 authentication with all available properties: role, aws-ec2-path, identity-document, and nonce. The nonce is used for TOFU; an empty nonce defaults to nonce generation.
```yaml
spring.cloud.vault:
authentication: AWS_EC2
aws-ec2:
role: application-server
aws-ec2-path: aws-ec2
identity-document: http://...
nonce: my-static-nonce
```
--------------------------------
### Generate Mac Address UserId with sha256sum
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Command to generate the Mac address UserId from a command line. The Mac address is specified uppercase and without colons; the -n flag is required because including the line break of echo leads to a different hash value.
```bash
$ echo -n 0AFEDE1234AC | sha256sum
```
--------------------------------
### Add spring-cloud-vault-config-databases dependency (pom.xml)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Required dependency for using database secret backends with Spring Cloud Vault. Add this to your Maven pom.xml.
```xml
org.springframework.cloud
spring-cloud-vault-config-databases
{project-version}
```
--------------------------------
### RabbitMQ Dependency (pom.xml)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Maven dependency required for the RabbitMQ integration. Add this to your project's pom.xml to enable Spring Cloud Vault to obtain RabbitMQ credentials.
```xml
org.springframework.cloud
spring-cloud-vault-config-rabbitmq
{project-version}
```
--------------------------------
### Consul Backend Configuration (YAML)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Configuration for the Consul backend. Set `enabled` to true, provide the role name, set the backend path, and optionally configure the token property name. The obtained token is stored in `spring.cloud.consul.token` by default.
```yaml
spring.cloud.vault:
consul:
enabled: true
role: readonly
backend: consul
token-property: spring.cloud.consul.token
```
--------------------------------
### Configure Vault Enterprise namespace with spring.cloud.vault.namespace
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/advanced-topics.adoc
Sets the namespace header X-Vault-Namespace on every outgoing HTTP request when using the Vault RestTemplate or WebClient. Not supported by Vault Community edition and has no effect on Vault operations.
```yaml
spring.cloud.vault:
namespace: my-namespace
```
--------------------------------
### Enable Cassandra backend with spring.cloud.vault.cassandra
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Configure Spring Cloud Vault to obtain Cassandra credentials. Set enabled to true and provide the role name. Username and password are stored in spring.data.cassandra.username and spring.data.cassandra.password by default.
```yaml
spring.cloud.vault:
cassandra:
enabled: true
role: readonly
backend: cassandra
username-property: spring.data.cassandra.username
password-property: spring.data.cassandra.password
```
--------------------------------
### Configure AppId Authentication with MAC_ADDRESS UserId in application.yml
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Selects APPID authentication and sets the UserId mechanism to MAC_ADDRESS, with an optional network-interface hint (interface name or 0-based index) to pick the device. The Mac address is specified uppercase and without colons.
```yaml
spring.cloud.vault:
authentication: APPID
app-id:
user-id: MAC_ADDRESS
network-interface: eth0
```
--------------------------------
### RabbitMQ Backend Configuration (YAML)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Enables the RabbitMQ backend by setting spring.cloud.vault.rabbitmq.enabled=true and providing the role name. Username and password are stored in spring.rabbitmq.username and spring.rabbitmq.password by default, configurable via username-property and password-property.
```yaml
spring.cloud.vault:
rabbitmq:
enabled: true
role: readonly
backend: rabbitmq
username-property: spring.rabbitmq.username
password-property: spring.rabbitmq.password
```
--------------------------------
### AWS-IAM authentication with all properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configure AWS-IAM authentication with all available properties: region, role, aws-path, server-name, and endpoint-uri. The role defaults to the friendly name of the current IAM role if not supplied.
```yaml
spring.cloud.vault:
authentication: AWS_IAM
aws-iam:
region: aws-global
role: my-dev-role
aws-path: aws
server-name: some.server.name
endpoint-uri: https://sts.eu-central-1.amazonaws.com
```
--------------------------------
### Configure Token Authentication in application.yml
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Sets the authentication method to TOKEN and provides a static token. If the token is missing or empty, Spring Cloud Vault attempts to retrieve it from ~/.vault-token. Token authentication is the default method; a disclosed token grants unintended access to Vault.
```yaml
spring.cloud.vault:
authentication: TOKEN
token: 00000000-0000-0000-0000-000000000000
```
--------------------------------
### Configure AppRole authentication with all properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Sets spring.cloud.vault.authentication to APPROLE and provides role-id, secret-id, role, and app-role-path. role sets the AppRole name for pull mode; app-role-path sets the authentication mount path.
```yaml
spring.cloud.vault:
authentication: APPROLE
app-role:
role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52
secret-id: 1696536f-1976-73b1-b241-0b4213908d39
role: my-role
app-role-path: approle
```
--------------------------------
### Enable Couchbase backend with spring.cloud.vault.couchbase
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Configure Spring Cloud Vault to obtain Couchbase credentials. Set enabled to true and provide the role name. Username and password are stored in spring.couchbase.username and spring.couchbase.password by default.
```yaml
spring.cloud.vault:
couchbase:
enabled: true
role: readonly
backend: database
username-property: spring.couchbase.username
password-property: spring.couchbase.password
```
--------------------------------
### Custom Secret Backend Configurer
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Implements addSecretBackends to add a custom secret backend and configure default backend registration.
```java
@Override
public void addSecretBackends(SecretBackendConfigurer configurer) {
configurer.add("secret/my-application");
configurer.registerDefaultKeyValueSecretBackends(false);
configurer.registerDefaultDiscoveredSecretBackends(true);
}
}
```
--------------------------------
### GCP-IAM Authentication All Properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Full GCP_IAM configuration with credentials location or encoded-key, gcp-path, jwt-validity (default 15 minutes), project-id, role, and service-account-id overrides. Note: GcpIamAuthentication does not support reactive usage.
```yaml
spring.cloud.vault:
authentication: GCP_IAM
gcp-iam:
credentials:
location: classpath:credentials.json
encoded-key: e+KApn0=
gcp-path: gcp
jwt-validity: 15m
project-id: my-project-id
role: my-dev-role
service-account-id: my-service@projectid.iam.gserviceaccount.com
```
--------------------------------
### GCP-IAM Authentication Required Properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Minimal configuration for GCP_IAM authentication, setting only the role. Requires the Google Cloud Java SDK dependencies for credentials and JWT signing.
```yaml
spring.cloud.vault:
authentication: GCP_IAM
gcp-iam:
role: my-dev-role
```
--------------------------------
### Consul Dependency (pom.xml)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Maven dependency required for the Consul integration. Add this to your project's pom.xml to enable Spring Cloud Vault to obtain Consul credentials.
```xml
org.springframework.cloud
spring-cloud-vault-config-consul
{project-version}
```
--------------------------------
### PostgreSQL backend configuration
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Enables the PostgreSQL backend in Spring Cloud Vault. Set `enabled` to true, provide the role name, backend path, and optionally override the default username and password property names. Note: the `postgresql` backend is deprecated in Vault 0.7.1; use the `database` backend mounted as `postgresql` instead.
```yaml
spring.cloud.vault:
postgresql:
enabled: true
role: readonly
backend: postgresql
username-property: spring.datasource.username
password-property: spring.datasource.password
```
--------------------------------
### MySQL backend configuration
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Enables the MySQL backend in Spring Cloud Vault. Set `enabled` to true, provide the role name, backend path, and optionally override the default username and password property names. Note: the `mysql` backend is deprecated in Vault 0.7.1; use the `database` backend mounted as `mysql` instead.
```yaml
spring.cloud.vault:
mysql:
enabled: true
role: readonly
backend: mysql
username-property: spring.datasource.username
password-property: spring.datasource.password
```
--------------------------------
### GCP-GCE Authentication Configuration
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configures GCP-GCE authentication by setting spring.cloud.vault.authentication to GCP_GCE and providing the role property. Uses GCP IAM and GCE credentials without requiring security-sensitive credentials.
```yaml
spring.cloud.vault:
authentication: GCP_GCE
gcp-gce:
role: my-dev-role
```
--------------------------------
### Enable Elasticsearch backend with spring.cloud.vault.elasticsearch
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Configure Spring Cloud Vault to obtain Elasticsearch credentials. Set enabled to true and provide the role name. Username and password are stored in spring.elasticsearch.rest.username and spring.elasticsearch.rest.password by default.
```yaml
spring.cloud.vault:
elasticsearch:
enabled: true
role: readonly
backend: mongodb
username-property: spring.elasticsearch.rest.username
password-property: spring.elasticsearch.rest.password
```
--------------------------------
### Configure AppId Authentication with IP_ADDRESS UserId in application.yml
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Selects APPID authentication and sets the UserId mechanism to IP_ADDRESS, which uses the local host's IP address as a Hex-encoded SHA256 hash. The app-id-path can be set to change the AppId mount path.
```yaml
spring.cloud.vault:
authentication: APPID
app-id:
user-id: IP_ADDRESS
```
--------------------------------
### AWS-IAM authentication with required properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configure AWS-IAM authentication with the minimum required property. The IAM role is automatically calculated from the environment. Requires the AWS Java SDK v2 dependency (`software.amazon.awssdk:auth`).
```yaml
spring.cloud.vault:
authentication: AWS_IAM
```
--------------------------------
### MongoDB backend configuration
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Enables the MongoDB backend in Spring Cloud Vault. Set `enabled` to true, provide the role name, backend path, and optionally override the default username and password property names.
```yaml
spring.cloud.vault:
mongodb:
enabled: true
role: readonly
backend: mongodb
username-property: spring.data.mongodb.username
password-property: spring.data.mongodb.password
```
--------------------------------
### PCF authentication with required properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configures Spring Cloud Vault to authenticate using Pivotal CloudFoundry's pcf auth backend with only the required role property. This backend uses PCF as a Trusted Third Party and does not require provisioning security-sensitive credentials.
```yaml
spring.cloud.vault:
authentication: PCF
pcf:
role: my-dev-role
```
--------------------------------
### Configure AppRole authentication with role-id
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Sets spring.cloud.vault.authentication to APPROLE and provides a role-id. SecretId is optional and can be omitted if AppRole is configured without requiring it.
```yaml
spring.cloud.vault:
authentication: APPROLE
app-role:
role-id: bde2076b-cccb-3cf0-d57e-bca7b1e83a52
```
--------------------------------
### GitHub Authentication Properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configures GitHub authentication with a personal access token. Optionally allows fallback to GitHub CLI token retrieval via spring.cloud.vault.github.allow-cli-token=true, disabled by default.
```yaml
spring.cloud.vault:
authentication: GITHUB
github:
token: gho_…
```
--------------------------------
### AWS Backend Dependency (pom.xml)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Adds the spring-cloud-vault-config-aws dependency required for the AWS integration.
```xml
org.springframework.cloud
spring-cloud-vault-config-aws
{project-version}
```
--------------------------------
### AWS-EC2 authentication with configured role
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configure AWS-EC2 authentication with a specific role. The role is optional and defaults to the AMI. Set the role via the `spring.cloud.vault.aws-ec2.role` property.
```yaml
spring.cloud.vault:
authentication: AWS_EC2
aws-ec2:
role: application-server
```
--------------------------------
### Configure AppId authentication with custom UserId mechanism
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Sets spring.cloud.vault.authentication to APPID and specifies a custom class for user-id. The class must implement org.springframework.cloud.vault.AppIdUserIdMechanism and its createUserId method is called each time authentication occurs.
```yaml
spring.cloud.vault:
authentication: APPID
app-id:
user-id: com.examlple.MyUserIdMechanism
```
```java
public class MyUserIdMechanism implements AppIdUserIdMechanism {
@Override
public String createUserId() {
String userId = ...
return userId;
}
}
```
--------------------------------
### Kubernetes authentication properties in application.yml
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configures Spring Cloud Vault to authenticate with Vault using a Kubernetes Service Account Token. The role must be bound to a service account name and namespace. The service-account-token-file defaults to /var/run/secrets/kubernetes.io/serviceaccount/token.
```yaml
spring.cloud.vault:
authentication: KUBERNETES
kubernetes:
role: my-dev-role
kubernetes-path: kubernetes
service-account-token-file: /var/run/secrets/kubernetes.io/serviceaccount/token
```
--------------------------------
### Configure AWS-EC2 authentication
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Sets spring.cloud.vault.authentication to AWS_EC2 to use the AWS-EC2 auth backend for secure introduction of EC2 instances.
```yaml
spring.cloud.vault:
authentication: AWS_EC2
```
--------------------------------
### AWS Backend Configuration for assumed_role (STS) (YAML)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Enables the AWS backend with the assumed_role credential type for STS. Includes session token property, TTL, and role ARN configuration.
```yaml
spring.cloud.vault:
aws:
enabled: true
role: sts-vault-role
backend: aws
credential-type: assumed_role
access-key-property: cloud.aws.credentials.accessKey
secret-key-property: cloud.aws.credentials.secretKey
session-token-key-property: cloud.aws.credentials.sessionToken
ttl: 3600s
role-arn: arn:aws:iam::${AWS_ACCOUNT}:role/sts-app-role
```
--------------------------------
### GCP-GCE Authentication Properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configures Spring Cloud Vault to use GCP_GCE authentication with optional role, gcp-path, and service-account overrides. The service-account defaults to the 'default' service account.
```yaml
spring.cloud.vault:
authentication: GCP_GCE
gcp-gce:
gcp-path: gcp
role: my-dev-role
service-account: my-service@projectid.iam.gserviceaccount.com
```
--------------------------------
### AWS Backend Configuration for iam_user (YAML)
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/secret-backends.adoc
Enables the AWS backend with the default iam_user credential type. Access key and secret key are stored in cloud.aws.credentials.accessKey and cloud.aws.credentials.secretKey by default.
```yaml
spring.cloud.vault:
aws:
enabled: true
role: readonly
backend: aws
access-key-property: cloud.aws.credentials.accessKey
secret-key-property: cloud.aws.credentials.secretKey
```
--------------------------------
### Azure MSI Authentication - Required Properties
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Configures Spring Cloud Vault to use Azure MSI authentication with the required role property. Set spring.cloud.vault.authentication to AZURE_MSI and provide the role name for the login attempt.
```yaml
spring.cloud.vault:
authentication: AZURE_MSI
azure-msi:
role: my-dev-role
```
--------------------------------
### Disable Authentication for Vault Agent in application.yml
Source: https://github.com/spring-cloud/spring-cloud-vault/blob/main/docs/modules/ROOT/pages/authentication.adoc
Sets authentication to NONE to disable Spring Vault's ClientAuthentication and SessionManager, allowing reuse of cached session credentials from Vault Agent running on localhost without the X-Vault-Token header.
```yaml
spring.cloud.vault:
authentication: NONE
```