Chapter 49. Hashicorp Vault Since Camel 3.18 Only producer is supported The hashicorp-vault component that integrates Hashicorp Vault . 49.1. Dependencies When using hashicorp-vault Red Hat build of Camel Spring Boot, add the following Maven dependency to your pom.xml to have support for auto configuration: <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-hashicorp-vault-starter</artifactId> </dependency> 49.2. Configuring Options Camel components are configured on two levels: Component level Endpoint level 49.2.1. Component Level Options The component level is the highest level. The configurations you define at this level are inherited by all the endpoints. For example, a component can have security settings, credentials for authentication, urls for network connection, and so on. Since components typically have pre-configured defaults for the most common cases, you may need to only configure a few component options, or maybe none at all. You can configure components with Component DSL in a configuration file ( application.properties or yaml ), directly with Java code. 49.2.2. Endpoint Level Options At the Endpoint level you have many options, which you can use to configure what you want the endpoint to do. The options are categorized according to whether the endpoint is used as a consumer ( from ) or as a producer ( to ) or used for both. You can configure endpoints directly in the endpoint URI as path and query parameters. You can also use Endpoint DSL and DataFormat DSL as type safe ways of configuring endpoints and data formats in Java. When configuring options, use Property Placeholders for urls, port numbers, sensitive information, and other settings. Property placeholders provide a few benefits: They help prevent using hardcoded urls, port numbers, sensitive information, and other settings. They allow externalizing the configuration from the code. They help the code to become more flexible and reusable. 49.3. Component Options The Hashicorp Vault component supports 2 options, which are listed below. Name Description Default Type lazyStartProducer (producer) Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. false boolean autowiredEnabled (advanced) Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. true boolean 49.4. Endpoint Options The Hashicorp Vault endpoint is configured using URI syntax: With the following path and query parameters: 49.4.1. Path Parameters (1 parameters) Name Description Default Type secretsEngine (producer) Vault Name to be used. String 49.4.2. Query Parameters (8 parameters) Name Description Default Type host (producer) Hashicorp Vault instance host to be used. String operation (producer) Operation to be performed. Enum values: createSecret getSecret deleteSecret listSecrets HashicorpVaultOperation port (producer) Hashicorp Vault instance port to be used. 8200 String scheme (producer) Hashicorp Vault instance scheme to be used. https String secretPath (producer) Hashicorp Vault instance secret Path to be used. String vaultTemplate (producer) Autowired Instance of Vault template. VaultTemplate lazyStartProducer (producer (advanced)) Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. false boolean token (security) Token to be used. String 49.5. Message Headers The Hashicorp Vault component supports 3 message header(s), which is/are listed below: Name Description Default Type CamelHashicorpVaultProducerOperation (producer) Constant: OPERATION Overrides the desired operation to be used in the producer. String CamelHashicorpVaultSecretPath (producer) Constant: SECRET_PATH Set the desired secret path as header. String CamelHashicorpVaultSecretVersion (producer) Constant: SECRET_VERSION Set the desired secret version as header. String 49.6. Examples 49.6.1. Using Hashicorp Vault Property Function To use this function, you'll need to provide credentials for Hashicorp vault as environment variables: export USDCAMEL_VAULT_HASHICORP_TOKEN=token export USDCAMEL_VAULT_HASHICORP_HOST=host export USDCAMEL_VAULT_HASHICORP_PORT=port export USDCAMEL_VAULT_HASHICORP_SCHEME=http/https You can also configure the credentials in the application.properties file such as: camel.vault.hashicorp.token = token camel.vault.hashicorp.host = host camel.vault.hashicorp.port = port camel.vault.hashicorp.scheme = scheme Note camel.vault.hashicorp configuration only applies to the Hashicorp Vault properties function (E.g when resolving properties). When using the operation option to create, get, list secrets etc., you should provide the host , port , scheme (if required) & token options. At this point, you'll be able to reference a property in the following way: <camelContext> <route> <from uri="direct:start"/> <to uri="{{hashicorp:secret:route}}"/> </route> </camelContext> Where route is the name of the secret stored in the Hashicorp Vault instance, in the 'secret' engine. You must specify a default value in case the secret is not present on Hashicorp Vault instance: <camelContext> <route> <from uri="direct:start"/> <to uri="{{hashicorp:secret:route:default}}"/> </route> </camelContext> In this case, if the secret doesn't exist in the 'secret' engine, the property will fall back to "default" as value. Also, you are able to get a particular field of the secret, if you have, for example, a secret named database of this form: { "username": "admin", "password": "password123", "engine": "postgres", "host": "127.0.0.1", "port": "3128", "dbname": "db" } You can have a single secret value in your route, in the 'secret' engine, for example: <camelContext> <route> <from uri="direct:start"/> <log message="Username is {{hashicorp:secret:database/username}}"/> </route> </camelContext> Or re-use the property as part of an endpoint. Specify a default value in case the particular field of secret is not present on Hashicorp Vault instance, in the 'secret' engine: <camelContext> <route> <from uri="direct:start"/> <log message="Username is {{hashicorp:secret:database/username:admin}}"/> </route> </camelContext> In this case, if the secret doesn't exist or the secret exists (in the 'secret' engine) but the username field is not part of the secret, the property will fall back to "admin" as value. There is also the syntax to get a particular version of the secret for both the approach, with field/default value specified or only with secret: <camelContext> <route> <from uri="direct:start"/> <to uri="{{hashicorp:secret:route@2}}"/> </route> </camelContext> This approach returns the RAW route secret with version '2', in the 'secret' engine. <camelContext> <route> <from uri="direct:start"/> <to uri="{{hashicorp:route:default@2}}"/> </route> </camelContext> This approach will return the route secret value with version '2' or default value in case the secret doesn't exist or the version doesn't exist (in the 'secret' engine). <camelContext> <route> <from uri="direct:start"/> <log message="Username is {{hashicorp:secret:database/username:admin@2}}"/> </route> </camelContext> This approach will return the username field of the database secret with version '2' or admin in case the secret doesn't exist or the version doesn't exist (in the 'secret' engine). The only requirement is adding the camel-hashicorp-vault jar to your Camel application. 49.7. Spring Boot Auto-Configuration When using hashicorp-vault with Spring Boot make sure to use the following Maven dependency to have support for auto configuration: The component supports 3 options, which are listed below. Name Description Default Type camel.component.hashicorp-vault.autowired-enabled Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. true Boolean camel.component.hashicorp-vault.enabled Whether to enable auto configuration of the hashicorp-vault component. This is enabled by default. Boolean camel.component.hashicorp-vault.lazy-start-producer Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. false Boolean

Commands:
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-hashicorp-vault-starter</artifactId> </dependency>
hashicorp-vault:secretsEngine
export USDCAMEL_VAULT_HASHICORP_TOKEN=token export USDCAMEL_VAULT_HASHICORP_HOST=host export USDCAMEL_VAULT_HASHICORP_PORT=port export USDCAMEL_VAULT_HASHICORP_SCHEME=http/https
camel.vault.hashicorp.token = token camel.vault.hashicorp.host = host camel.vault.hashicorp.port = port camel.vault.hashicorp.scheme = scheme
<camelContext> <route> <from uri="direct:start"/> <to uri="{{hashicorp:secret:route}}"/> </route> </camelContext>
<camelContext> <route> <from uri="direct:start"/> <to uri="{{hashicorp:secret:route:default}}"/> </route> </camelContext>
username: admin
password: password123
engine: postgres
host: 127.0.0.1
port: 3128
dbname: db
<camelContext> <route> <from uri="direct:start"/> <log message="Username is {{hashicorp:secret:database/username}}"/> </route> </camelContext>
<camelContext> <route> <from uri="direct:start"/> <log message="Username is {{hashicorp:secret:database/username:admin}}"/> </route> </camelContext>
<camelContext> <route> <from uri="direct:start"/> <to uri="{{hashicorp:secret:route@2}}"/> </route> </camelContext>
<camelContext> <route> <from uri="direct:start"/> <to uri="{{hashicorp:route:default@2}}"/> </route> </camelContext>
<camelContext> <route> <from uri="direct:start"/> <log message="Username is {{hashicorp:secret:database/username:admin@2}}"/> </route> </camelContext>