WSO2 Carbon is shipped with a Secure Vault implementation, which is a modified version of synapse Secure Vault. This allows you to store encrypted passwords that are mapped to aliases. That is, you can use the aliases instead of the actual passwords in your configuration files for better security. For example, some configurations require the admin username and password. If the admin user password is "admin", you could use the alias
UserManager.AdminUser.Password in your configuration file. You would then map that alias to the actual password "admin". At runtime, the product will look up this alias in the secure vault and then decrypt and use its password.
See the following topics:
Elements of the Secure Vault implementation
Some of the important elements in the secure vault implementation, which are used in Carbon products for encrypting plain text passwords are as follows:
- Secret Repository: This is used to store the secret values (encrypted values). The
cipher-text.propertiesfile, located in the
/conf/securityfolder is the default file based secret repository used by the Secret Manager in your Carbon product. Note that, currently, Secure Vault only implements file based secret repositories. The Secret Repository stores aliases vs. their actual secrets in encrypted format (encrypted via a key in keystore). Any secret repositories can be written by implementing the
SecretRepositoryProviderclasses. See the topic on customizing the Secure Vault configuration.
- Secret Manager: The Secret Manager initializes the Secret Repository and the keystore configured for the Carbon server. The secrets stored in the Secret Repository are accessed using the aliases indicated in the
cipher-text.propertiesfile. The keystore is required to create the decryption crypto, which can be used to resolve encrypted secret values. The keystore and Secret Repository are configurable through the
secret-conf.propertiesfile, which is created in the
/conf/securityfolder when you execute the Cipher Tool.
- Secret Callback: This provides the actual password for a given alias. There is a SecretManagerSecretCallbackHandler, which is combined with Secret Manager to resolve the secret. Any callback can be written by implementing the SecretCallbackHandler class. See the topic on customizing the Secure Vault configuration.
- Secret Resolver: Any configuration builder that uses secret information within its own configuration file needs to initialize the Secret Resolver when building its own configuration. The Secret Resolver keeps a list of secured elements that need to be defined in the configuration file with secret aliases. Secret Resolver initializes the Secret Callback handler class, which is defined in the configuration file.
Customizing the Secure Vault configuration
You can implement your own Secure Vault configurations by changing the default Secret Repository and the Secret Callback Handler. See the following for topics for instructions:
Creating a Secret Callback Handler
Let's see how we can write a new Secret Callback Handler class to secure the user management and registry database connection password. In this sample, you do not need to configure a Secret Repository or keystore (cipher-text.properties) as you are not going to store the secret or encrypted values.
Write a Secret Callback class. You need to implement the SecretCallbackHandler interface or extend the AbstractSecretCallbackHandler abstract class. For example,
We can set multiple password-based as follows:
- Create a JAR or an OSGI bundle and copy the JAR file to the
/repository/component/lib/directory or the OSGI bundle to the
master-datasources.xmlfile with an alias name and your Secret Callback handler class name. For example,
Replace the values of two the properties
/conf/security/secret-conf.propertiesfile with your Secret Callback handler class name.
- Restart the server.
Creating a custom Secret Repository
To create a custom secret repository, you need to implement the
Create your custom secret repository by implementing the
Then you need to implement the
org.wso2.securevault.secret.SecretRepositoryProviderclass as shown below. This class returns an instance of the custom
SecretRepositorythat you implemented above.
Create a JAR or an OSGI bundle.
Then, copy the JAR file to the
<EI_HOME>//lib/directory or the OSGI bundle to the
secretRepositories.file.providerentry in the
secret-conf.propertiesfile (stored in the
/conf/security/directory) with your secret repository class name.