Skip to content

Encrypting Secrets

WSO2 Micro Integrator can use secrets with static origins as well as dynamic origins in configurations. This applies to secrets in server-level configurations as well as configurations within integration solutions (synapse configurations).

It is not recommended to use plain-text values for your sensitive data in your configurations. Therefore, you can encrypt the plain-text secrets using the secure vault implementation that is built in to the Micro Integrator.

The Micro Integrator is shipped with the Cipher Tool, which uses the secure vault implementation and encrypts the secrets you specify. Running the Cipher Tool also ensures that the secrets are enabled in the Micro Integrator environment. You can then refer the encrypted secrets from anywhere in your server configurations or synapse configurations.

Note that you can customize the default secure vault configurations in the product by implementing a new secret repository, call back handler, etc.

Follow the steps given below to encrypt secrets.

Step 1: Defining secrets

Static secrets

Static secrets are sensitive data that are specified directly in configurations. The secret can be a plain-text value or the alias of an encrypted value.

You must first list the plain-text secrets in the deployment.toml file under the secrets header. Note that we have specified an alias for the secret followed by the actual plain-text secret.

[secrets]
server_secret = "[secret_1]"
synapse_secret = "[secret_2]"

Dynamic secrets

Dynamic secrets are specified in configurations as environment variables, system properties, Docker secrets, or Kubernetes secrets. The actual secrets is then encrypted using the WSO2 Micro Integrator CLI and injected to the environment.

  1. First, list the dynamic secrets in the deployment.toml file under the [secrets] section. However, unlike for static secrets, specify the secret value as an environment variable or system property.

    Note

    In this example, dynamic_secret is a placeholder for the secret. You will use this placeholder as the secret's alias when you encrypt the plain-text secret using the CLI (in the next step).

    [secrets]
    server_secret = "$env{dynamic_secret}"
    [secrets]
    server_secret = "$sys{dynamic_secret}"
  2. Now, encrypt a plain-text secret for the dynamic_secret alias by using the Micro Integrator CLI.

    1. Download and set up the CLI tool.
    2. Execute one of the following commands to generate the secret:

      • To generate secrets for a VM deployment, use the following commands:

        # To encrypt secret and get output to console
        mi secret create
        
        # To encrypt secret and get output to file
        mi secret create file
        
        # To bulk encrypt secrets defined in a properties file
        mi secret create -f=</file_path>
      • To generate secrets in a .yaml file for a Kubernetes environment, use the following commands:

        # To encrypt secret and get output as a .yaml file
        mi secret create k8
        
        # To bulk encrypt secrets defined in a properties file and get the output as a .yaml file
        mi secret create k8 -f=</file_path>

Step 2: Running the Cipher Tool

Running the Cipher Tool will first encrypt any static secrets defined in the [secrets] section, and then enable all the secrets (static as well as dynamic) in the environment.

In a VM environment

In a VM environment, you need to manually run the Cipher Tool as follows:

Tip

If you are using Windows, you need to have Ant installed before using the Cipher Tool.

  1. Open a terminal, navigate to the <MI_HOME>/bin/ directory.
  2. Execute the -Dconfigure command with the cipher tool script as shown below.

    ./ciphertool.sh -Dconfigure
    ./ciphertool.bat -Dconfigure

In a Kubernetes environment

In a Kubernetes environment, you don't need to manually run the Cipher tool. Follow the steps given below.

  1. Open your Integration Project in WSO2 Integration Studio, which contains all the integration artifacts and the Kubernetes Exporter.
  2. Open the pom.xml of the Kubernetes Exporter module and select the Enable Cipher Tool check box as show below.

  3. When you build the Docker image from your Kubernetes exporter, the secrets will get encrypted and enabled in the environment.

If you specified any static secrets, go back to the deployment.toml file and see that the secrets are encrypted.

[secrets]
keystore_password = "encrypted_pass_3"
key_password = "encrypted_pass_4"
truststore_password = "encrypted_pass_5"

Step 3: Accessing secrets

In server configurations

You can refer an encrypted secret in your server configurations by using the $secret{alias} function in place of the plain-text secret as shown below. Replace alias with the secret's alias that is defined under the [secrets] section.

Note

You can use encrypted static secrets as well as dynamic secrets.

[keystore.primary]
password = "$secret{server_secret}"
alias = "$secret{server_secret}"
key_password = "$secret{server_secret}"  

[truststore]                  
password = "$secret{server_secret}"

In synapse configurations

You can refer an encrypted secret in your synapse configurations by using the vault lookup function ({wso2:vault-lookup('alias')) in place of the plain-text secret as shown below. Replace alias with the secret's alias that is defined under the [secrets] section.

Note

You can only use encrypted static secrets here.

<log level="custom">
  <property expression="wso2:vault-lookup('synapse_secret')" name="secret"/>
</log>

Step 4: Populating dynamic secrets

If you have defined dynamic secrets in your configurations, you must populate the secret into the relevant environment as required.

In a VM environment

For an instance, in the case of environment variables, you can populate them with the export command as follows:

export env_carbon_sec=<ENCRYPTED_VALUE>

In a Kubernetes environment

If you are in a Kubernetes enviroment, you should have generated a .yaml file with the encrypted secrets using the Micro Integrator CLI. See defining dynamic secrets.

Top