Search code examples
javadeploymentbuildbuild-processdev-to-production

Building Production Release - DB Connection Credentials


We have a build that can package war files for specific environments where all our property files are embedded in the archive (war file).

We are now about to build for production. My concern is the codebase will need to expose the production database password and although unlikely there is a risk where the production build profile could be run with a negative effect.

Options I thought of to negate this risk is to not store the production details in SVN and:

  1. Have the administrators override system properties which are used to connect to the DB, or

  2. Have the container manage the DB connection instead of c3p0, this way they can manage this configuration themselves.

Do you have any advice?


Solution

  • You should definitely not be putting the production DB username and password into your source control system. Your app should be getting its DB connection (eg a DataSource) using JNDI which is controlled/restricted by the admins on the production environment.

    For example, if your app is deployed to Tomcat, you have the following in tomcat/conf/context.xml

     <Resource name="jdbc/myDB"
                  auth="Container"
                  type="javax.sql.DataSource"
                  maxActive="20"
                  maxIdle="10"
                  maxWait="3000"
                  username="myusername"
                  password="mypassword"
                  driverClassName="com.mysql.jdbc.Driver"
                  url="jdbc:mysql://myhost:3306/myschema"
                  defaultAutoCommit="false"/>
    

    ..and the connection is obtained from java:/comp/env/jdbc/myDB without your app ever having to provide a username or password. The tomcat installation is protected on the prod servers by the admins, so it is unavailable to anyone without admin access on your prod server.