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?
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.
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 to create a master password. Use the following command line: mvn --encrypt-master-password <password>
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>
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.
Create a master password:
mvn --encrypt-master-password <password>
Add the master password to settings-security.xml
Encrypt your password
mvn --encrypt-password <password>
Add the encrypted value to your settings.xml
More details in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With