Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to secure and encrypt setting.xml paswords file in maven?

Tags:

security

maven

How to secure server/proxy settings in settings.xml in maven?

I assume this is mostly about login and passwords stored there and I assume that those can't be placed placed there explicitly, should they be stored in env variables/etc?

how should example of a secure settings.xml look?

like image 962
kol23 Avatar asked Oct 10 '17 07:10

kol23


People also ask

How does maven encryption work?

The server password is decrypted using the master password as the encryption key; the master password is decrypted using "settings. security" as the encryption key.

Where are maven credentials stored?

When you run a Maven build that needs to interact with the repository manager, Maven will retrieve the Master password from the ~/. m2/settings-security. xml file and use this master password to decrypt the password stored in your ~/. m2/settings.

How can I get Maven master password?

How to create a master password. Use the following command line: mvn --encrypt-master-password <password>


2 Answers

You have 2 options:

1)If you need only use in settings.xml:

Execute:

mvn --encrypt-password <password>

You will get the encrypted password like this:

{COQLCE6DU6GtcS5P=}

You can use this password in you settings.xml:

<settings>
 ...
    <servers>
    ...
        <server>
          <id>my.server</id>
          <username>foo</username>
          <password>{COQLCE6DU6GtcS5P=}</password>
        </server>
    ...
    </servers>
...
</settings>

2)If you need to use in multiple uses:

Execute:

mvn --encrypt-master-password <password>

Yo will get the encrypted password like this:

{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}

Store this password in the ${user.home}/.m2/settings-security.xml it should look like:

<settingsSecurity>
      <master>{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}</master>
</settingsSecurity>
like image 145
Javier C. Avatar answered Sep 18 '22 09:09

Javier C.


If a settings.xml is shared (maybe it's a 'team' file, maybe it sits on a shared build/CI box) then sensitivie details within it - specifically passwords - can (should :) be encrypted.

  1. Create a master password:

    mvn --encrypt-master-password <password>
    
  2. Add the master password to settings-security.xml

  3. Encrypt your password

    mvn --encrypt-password <password>
    
  4. Add the encrypted value to your settings.xml

More details in the docs.

like image 43
glytching Avatar answered Sep 20 '22 09:09

glytching