Advanced database password encryption

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community


To add extra security to your Bamboo instance, you can encrypt the database password that is stored in the configuration file used by Bamboo to access your database. In this advanced method, you can use the Cipher algorithm that allows you to choose the algorithm used to encrypt your password. It provides more security as you don't have to store the encrypted password anywhere in the configuration file, which makes it difficult to find and decrypt. 

This solution is an obfuscation, which doesn’t assure real security. Bamboo still needs to use the plain text password to connect to your database, so the configuration will contain all the information needed to decrypt the password. An attacker could act like Bamboo to obtain the password. We recommend that you secure the server where Bamboo and the database reside.

Before you begin

Prepare a JSON object which contains all arguments required to encrypt your password using the following information:

FieldDescription
plainTextPasswordPassword in plain text.
algorithmYou can choose one of the following algorithms:
  • AES/CBC/PKCS5Padding

  • DES/CBC/PKCS5Padding

  • DESede/CBC/PKCS5Padding

algorithmKeyThe algorithm key must correspond with the algorithm chosen above:
  • AES

  • DES

  • DESede

See a sample JSON object...

{"plainTextPassword":"yourPassword","algorithm":"AES/CBC/PKCS5PADDING","algorithmKey":"AES"}

To encrypt your database password:

Step 1: Encrypt the password:

  1. Go to <Bamboo-installation-directory>/tools/atlassian-password.
  2. Run the following command to encrypt your password. You can also use optional parameters described below.

    java -cp "./*" com.atlassian.db.config.password.tools.CipherTool -c com.atlassian.db.config.password.ciphers.algorithm.AlgorithmCipher
    See optional arguments...
    • -- silent -s: limits logging to minimum

    • -- help -h: prints a help message with all parameters

    • -- mode -m: defines what to do with the password, either encrypt or decrypt. If omitted, 'encrypt' will be used.

    • -- password -p: JSON object with required arguments. If omitted, you'll be asked to enter it. We recommend that you omit this parameter so your password is not stored in the history.

  3. When prompted, provide the required arguments in a JSON object. 

Step 2: Secure the generated files:

  1. Secure the generated files:

    Move the files generated by the tool to a secure place, and change them to read-only. Bamboo needs to be able to access and read those files to decrypt your password and connect to the database.

    The following files have been generated:

    • javax.crypto.SealedObject_[timestamp] - file with the encrypted password.
    • javax.crypto.spec.SecretKeySpec_[timestamp]- key used to encrypt your password. You will need this file to decrypt your password.
    • java.security.AlgorithmParameters_[timestamp]- Algorithm parameters used to encrypt your password. You will need this file only if you wanted to recreate an encrypted password

Step 3: (optionalStore file paths as environment variables:

You can store paths to the generated files as environment variables. If the paths aren't present in the bamboo.cfg.xml file, Bamboo will automatically look for them in the specific environment variables. In this way, file paths will not be stored in the bamboo.cfg.xml file, making it difficult to locate the files used for encryption.

  1. Store the two of the generated files as environment variables:

    com_atlassian_db_config_password_ciphers_algorithm_javax_crypto_spec_SecretKeySpec
    com_atlassian_db_config_password_ciphers_algorithm_javax_crypto_SealedObject
    Example...
    export com_atlassian_db_config_password_ciphers_algorithm_javax_crypto_spec_SecretKeySpec=/home/bamboo/javax.crypto.spec.SecretKeySpec_123456789
    export com_atlassian_db_config_password_ciphers_algorithm_javax_crypto_SealedObject=/home/bamboo/javax.crypto.SealedObject_123456789
  2. Edit the output from Step 1 and remove paths to the files. The final output should look similar to the following JSON object:

    <property name="jdbc.password.decrypter.classname">com.atlassian.db.config.password.ciphers.algorithm.AlgorithmCipher</property>
    <property name="hibernate.connection.password">{}</property>


Step 4: Adding the encrypted password to bamboo.cfg.xml:

  1. Go to Bamboo home directory and back up the bamboo.cfg.xml file. Move the backup to a safe place outside of your Bamboo server.

  2. In the bamboo.cfg.xml file, replace the content of the <property name="hibernate.connection.password"> tag with the output JSON object. Depending on whether you used environment variables or not, adjust the JSON object to one of the following examples:
    • If you stored file paths as environment variables, remove the paths from the output. It should look like the following example:

      <property name="jdbc.password.decrypter.classname">com.atlassian.db.config.password.ciphers.algorithm.AlgorithmCipher</property>
      <property name="hibernate.connection.password">{}</property>
    • If you didn't use environment variables and want to stick to file paths in the bamboo.cfg.xml file, make sure you updated them after moving the files to a secure place. The output should look like the following example:

      <property name="jdbc.password.decrypter.classname">com.atlassian.db.config.password.ciphers.algorithm.AlgorithmCipher</property>
      <property name="hibernate.connection.password">{"sealedObjectFilePath":"javax.crypto.SealedObject_1621327067811","keyFilePath":"javax.crypto.spec.SecretKeySpec_1621327067777"}</property>
    • You need to additionally escape the file paths and change double quotes (") surrounding the path to single quotes (') to avoid JSON parsing errors. The paths should look like the following example:

      <property name="jdbc.password.decrypter.classname">com.atlassian.db.config.password.ciphers.algorithm.AlgorithmCipher</property>
      <property name="hibernate.connection.password">{"sealedObjectFilePath":'C:\\bamboo\\javax.crypto.SealedObject_123456789',"keyFilePath":"'C:\\bamboo\\javax.crypto.spec.SecretKeySpec_123456789'"}</property>
  3. Restart Bamboo.

To decrypt your database password:

  1. Run the encryption command with the -m decrypt parameter:

    java -cp "./*" com.atlassian.db.config.password.tools.CipherTool -c com.atlassian.db.config.password.ciphers.algorithm.AlgorithmCipher -m decrypt
  2. When asked for the JSON object, provide the one from your bamboo.cfg.xml file.

    Sample JSON object when using file paths...
    {"sealedObjectFilePath":"/home/bamboo/javax.crypto.SealedObject_123456789","keyFilePath":"/home/bamboo/javax.crypto.spec.SecretKeySpec_123456789"}

Recreating an encrypted password

When you lose the encrypted password and encrypt the plain text password once again, the new encrypted password will look differently. This is not an issue, as it will still represent the same plain text password. However, in some cases, you might want to keep the consistency, for example by having the same encrypted password for all Bamboo Data Center nodes.

To encrypt the password in the exact same way as you did before, you will need the key used to encrypt the original password and the algorithm parameters. Both of these were generated by the encryption tool and saved in the following files:

  • Key: javax.crypto.spec.SecretKeySpec_[timestamp]

  • Algorithm parameters: java.security.AlgorithmParameters_[timestamp]

Once you've located these files, you can point the encryption tool to their location by using two extra fields in the JSON object. Below you can find the description of these fields and a sample JSON object.

Field Description
keyFilePathPath to a file that contains the key used to encrypt your original password, e.g. javax.crypto.spec.SecretKeySpec_[timestamp].

If you stored the file path as environment variable, you can omit this parameter.

algorithmParametersFilePathPath to a file that contains the algorithm parameters used to encrypt your original password, e.g. java.security.AlgorithmParameters_[timestamp].

Example of a JSON object with all fields:

{"plainTextPassword":"yourPassword", "algorithm":"AES/CBC/PKCS5PADDING", "algorithmKey":"AES", "algorithmParametersFilePath":"java.security.AlgorithmParameters_123456789", "keyFilePath":"javax.crypto.spec.SecretKeySpec_123456789"}

To encrypt the password, follow the steps in Step 1, and use the JSON object with they key and algorithm parameters.




Last modified on Aug 10, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.