Integrate grails with hashicorp vault

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Integrate grails with hashicorp vault



I'm trying to integrate hashicorp vault on a grails app. I wasn't able to find a tutorial or some help on the internet. Even the grails documentation doesn't comment anything on this topic.



Does anyone know how I can accomplish this?



I'm using grails 2.5.6



Edit



By integration I mean to let grails read properties from hashicorp vault instead of the ones that I defined in Config.groovy or DataSource.groovy or another properties in classpath. I defined a custom place holder that is able to reach my hashicorp vault but grails is not recognizing the properties I brought.



MyPlaceholderConfigurer.java


public class MyPlaceholderConfigurer extends GrailsPlaceholderConfigurer
final static Logger logger = Logger.getLogger(MyPlaceholderConfigurer.class);

public MyPlaceholderConfigurer(GrailsApplication application)
super(application);
logger.info("XXXXXXXXX: Started MyPlaceholderConfigurer");


@Override
protected void loadProperties(Properties props) throws IOException
logger.info("XXXXXXXXX: loadProperties()");
super.loadProperties(props);
Map<String, Object> vault = HashicorpVault.getSecrets();
props.putAll(vault);




resources.groovy


propertySourcesPlaceholderConfigurer(MyPlaceholderConfigurer, application)
environment = getUnrefreshedApplicationContext().getEnvironment()



Config.groovy


grails.config.locations = ["classpath:Principal.properties", "classpath:MyDatabase.groovy"]




1 Answer
1



There is no client library for groovy (or grails-plugin).



Since groovy works good with java you can just use the java-client library (https://www.vaultproject.io/api/libraries.html) the one you most likely want is https://github.com/BetterCloud/vault-java-driver since the Spring version of the driver can conflict with grails' Spring version. Also, the non-spring version targets java 7+ so you won't end up solving java 8 new features -problems that are not supported in old groovy versions bundled with grails 2.5.x


java-client


java 8 new features



Modify your BuildConfig.groovy to get the library:


BuildConfig.groovy


dependencies

...

compile 'com.bettercloud:vault-java-driver:3.1.0'

...



And follow the instructions on github page.





Thanks for your answer. I updated my question. Basically I'm able to reach hashicorp vault but I'm not able to let grails use the properties I brought. Do you know how grails can use the properties I brought instead of the one defined on DataSource.groovy, etc. ?
– david
Aug 10 at 15:24





In Config.groovy for example you can just say some.setting = SomeCustomConfigObject.get("myPassword") for example and then create SomeCustomConfigObject with static method get(String key) and make it do whatever you want to return the value for myPassword. This is read when the app starts. Maybe make a wrapper for the vault for this purpose? What you are doing is not wrong, but there is something you are missing to make it work and I can't easily help you with that, sorry.
– Tuomas Valtonen
Aug 10 at 21:33


some.setting = SomeCustomConfigObject.get("myPassword")


SomeCustomConfigObject


get(String key)


myPassword






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS