-
Notifications
You must be signed in to change notification settings - Fork 211
Allow database.properties username and password to be overriden via Environment Variables or System Properties #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@talawahdotnet actually, there was an undocumented feature that allows the file I think it solves this issue by large without any environment variables. |
@talawahdotnet , ultimately I think this is not that important because in production you do not really use this file, but rather configure database connection pool using standard container tools, so for instance on our production, the configuration looks like this:
Then, the Java container is used to configure this to point to a DB using a pool. In the end, the passwords end up in container configuration files, but... if a hacker got a hold of your box, a property file with DB access is least of your concerns :) |
I agree that if a hacker compromises the box then it is game over, I am just more interested in keeping all passwords (including the ones for test/qa and dev) outside of source control. The alternate property file location is interesting, but I was hoping for something that worked a little more smoothly with the default mechanisms provided by the Heroku and AWS i.e. env vars and sys properties. I didn't realize I could mix and match url/user/pass and jndi for different environments in the same properties file. I guess I can use that as a workaround since I can use system properties in JNDI definition in Tomcat's context.xml. I guess can settle for dev passwords under source control as long as QA/PROD ones aren't. It still makes me feel a little dirty though lol |
@talawahdotnet I do not see this as a workaround and it does not make me feel dirty :). |
@talawahdotnet, I want to close this as a non-issue. Have you solved your problem? |
Sure, this can be closed. I am able to use system properties to configure JNDI for QA and PROD and I can live with hard coding the username and password in database.properties for the DEV environment. |
Actually I just ran into another related issue, not sure if I need to open a separate ticket or perhaps you can clarify. When org/junit/Test.class is on the classpath, DB.java has a hack in place that forces the environment to be "test" even if another value was specified in the environment variable. I am not sure I understand the original intention, but it seems to have the side-effect of forcing tests run on my development environment and tests run on my QA environment to both use the same set of credentials since Junit is present in both cases. |
@talawahdotnet yes, this is kind of a hack. In development environment you have two databases: test and development, so this is more of a "mode" in dev. env. This is how it picks up correct DB connection parameters. You should not be including JUnit in your build anywhere other than dev. |
What about using a CI server like Jenkins to execute automated unit tests in a QA environment. Seems like a legitimate use case to me. |
@talawahdotnet , this is totally fine, as this is exactly how we run these projects in Jenkins. You do need a test database on Jenkins, correct? |
Yes, I need to connect to a database on Jenkins, but it is a different database from what I use to execute unit tests in development. All I am saying is that I just don't think the hack should override the environment variable. The environment variable should give you full control. Right now the hack forces you to use the same credentials for running tests in development and QA/CI |
@talawahdotnet you might be right. Let me think about for a couple of days. What you are proposing would be correct, but will require explicit configuration for every environment. The current hack is.. a hack, but it is quite convenient because it requires less configuration. |
@talawahdotnet , you are right on both accounts (what was I thinking - lol!). Please, give it a try see if it works for you. I'd like to cut a new release (long over due), so that this change gets into it. |
Great. Haven't tested it yet, but taking a look at the commit it looks like you have a copy/paste typo in Configuration.java. In overrideFromSystemProperties() you call System.getProperty on "activejdbc.user" 2 extra times where you should be referencing "activejdbc.password" and "activejdbc.driver". Funnily enough the documentation has the same error as well. At least it is consistent :) |
…via Environment Variables or. Typos
@talawahdotnet thanks for catching this. However, our Jenkins instance is down, and in the process of rebuilding. At the earliest the new snapshot will be available close to end of this week. If you want to try this sooner, you can pull code and build from sources. |
you cannot underestimate the power of copy/paste! At least you can see the process: code becomes docs :) |
re-opening to add override for jndi as well |
@talawahtech are you using this feature? It is possible that a slight change will be coming soon, it will require a single line of code. |
@ipolevoy, no I am not working with that codebase at all anymore, but thanks for checking. |
It would be great if Active JDBC could allowed the user to override the username and passwords from the database.properties file by specifying them using Environment Variables or System Properties.
This would allow us to exert greater control over this type of sensitive data by not placing them under source control. So similar to the existing ACTIVE_ENV variable it would be nice to support something like ACTIVE_DB_USER and ACTIVE_DB_PASS.
This is particularly useful in cloud environment, for example, Heroku uses environment variables to pass sensitive config data. Kubernetes supports this as well. AWS ElasticBeanstalk on the other hand uses JVM System Properties.
My expectation would be that the values would read from database.properties by default, then check for env vars and override if found, then check for JVM properties and override if found.
The text was updated successfully, but these errors were encountered: