Mule 4 Secure Properties

Every development project needs a way to have certain values change when an application is moved from environment to environment. Many teams opt for environment variables on the server. I’m not a fan of these, because they are “hidden”. Only a server admin can see that they exist, and what their values are. MuleSoft, Mule 4 has a method for using Secure Properties in your apps, you may want to consider using these.

The main advantage of Secure Properties is that they are easily maintained in the Runtime Manager. This means that they are easy to administrate by whomever has rights to deploy applications. Hence, the values for each environment can be part of your roll-out documentation. If the property values are sensitive, i.e. passwords, then your documentation can state that the values are to be retrieved by other means, but still show where they should be set.

Alright then, enough with the back story, let’s get started!

First thing we’ll need to do is to setup a YAML file that has the properties we want to use in our app. We can easily add to this list over time as needs arise. For this example, I’m going to call the file secure-config.yaml, but feel free to name it as you see fit.

Let’s get started

  1. Right click on your Mule project
  2. Select “New” -> “File”
  3. Navigate to your project and into the src\main\resources folder
  4. Enter the file name you’d like with a .yaml extension
  5. Click “Finish”
Adding new file in MuleSoft Anypoint Studio

Open your new file and add your new properties, you can select to create them in a hierarchy, or not. As always, I recommend organizing your thoughts, as you don’t know how many properties you may eventually have. It could get difficult to find the one you want in the future if there are dozens.

Sample Secure Properties YAML file

Once this is saved, you need to declare the properties you’re using that you wish to set in the Runtime Manager. In order to do this, you’ll need to edit your mule-artifact.json file in the root of your project. We’ll be adding a new line to declare the properties:

mule-artifact.json file with new line added

Make sure to add a comma before your new line to keep the integrity of the properties in this file. Notice how the property that I had created in the config-secure.yaml file under the “defaultAppSettings” is depicted here with a period. This is the same way you’ll use it in the Runtime Manager and any documentation that you create.

After saving your changes to the mule-artifact.json file, there is one more step. We need to add this new config-secure.yaml file as a known configuration file for your project.

  1. With any of your flow files open from your “src/main/mule” folder, click on the “Global Elements” tab.
  2. Click on “Create”
  3. Now Click on “Global Configurations” -> “Configuration properties”
  4. Click “OK”
  5. In the “File” box, select your new config-secure.yaml file. You can use the ellipses to make sure you have the path correct.
  6. Click “OK”
  7. Save all your changes
Showing the value of the Configuration properties once you’re done

NOTE: Make sure and save all your changes in Anypoint Studio.

Now you can use these properties as you would any other properties in a .yaml file.

Example in a Set Variable showing a secure property as the Value

For this example, I have a simple application that pulls my two config settings and saves them to variables. I then display the variables as JSON.

Using my properties that are fed by my config-secure.yaml file

Deploying an application is beyond the scope of this post, so I’ll assume you know how to do that.

After Deploying Anypoint Manager

After deploying, I run my application and view the following response message in my browser:

Now, back in Anypoint Manager – Runtime Manager, I hover over the name of my application and click on the little leaping arrow:

How to manage your application in Runtime Manager

Select “Manage Application” on the right side pane.

On this screen, look for the properties tab and click it.

Properties tab in Anypoint Manager – Runtime Manager

Here is where we can change the values of the properties we created in the config.secure.yaml file. By also adding them to the mule-artifact.json file, we have exposed them to this tab. So I’ll change the two values for my two sample properties, like so:

There are three things I want to mention about this screen.

  1. Make sure you click the save button after adding each property. If you add several and click save, I’ve had it wipe out all but the one I clicked.
  2. Note the key is exactly the same as the way that I access them from within my Mule application. Make sure and double check the names of your properties.
  3. You MUST click “Redeploy Application” for any of these change to not only take effect, but to be saved at all.

Click on “Redeploy Application”. Once it is started. I’ll refresh the application in my browser and see what we have:

Mule service JSON display after changing values on Properties tab

So now I include the settings for these properties in my deployment document and every time the application is run on a server, it picks up the values that are appropriate for that environment.

Happy Muling, and remember, don’t make an ass of yourself.

Author: Jack Yasgar

Jack Yasgar has been developing software for various industries for two decades. Currently, he utilizes C#, JQuery, JavaScript, SQL Server with stored procedures and/or Entity Framework to produce MVC responsive web sites that converse to a service layer utilizing RESTful API in Web API 2.0 or Microsoft WCF web services. The infrastructure can be internal, shared or reside in Azure. Jack has designed dozens of relational databases that use the proper primary keys and foreign keys to allow for data integrity moving forward. While working in a Scrum/Agile environment, he is a firm believer that quality software comes from quality planning. Without getting caught up in analysis paralysis, it is still possible to achieve a level of design that allows an agile team to move forward quickly while keeping re-work to a minimum. Jack believes, “The key to long term software success is adhering to the SOLID design principles. Software written quickly, using wizards and other methods can impress the business sponsor / product owner for a short period of time. Once the honeymoon is over, the product owner will stay enamored when the team can implement changes quickly and fix bugs in minutes, not hours or days.” Jack has become certified by the Object Management Group as OCUP II (OMG Certified UML Professional) in addition to his certification as a Microsoft Certified Professional. The use of the Unified Modeling Language (UML) provides a visual guide to Use Cases and Activities that can guide the product owner in designing software that meets the end user needs. The software development teams then use the same drawings to create their Unit Tests to make sure that the software meets all those needs. The QA testing team can use the UML drawings as a guide to produce test cases. Once the software is in production, the UML drawings become a reference for business users and support staff to know what decisions are happening behind the scenes to guide their support efforts.

Leave a Reply

Your email address will not be published. Required fields are marked *