API Functional Monitoring - Mask authentication headers such as ClientId and ClientSecret for Endpoints using Secrets Manager
The steps below are derived with a more detailed information based on the MuleSoft documentation for Using Secrets to Mask Sensitive Information in Monitors. It is recommended to read through this documentation before following the detailed illustration below.
The process consists of the below 4 steps.
The following illustration uses masking ClientId and ClientSecret fields.
Step 1: Creating Shared Secrets
Step 2: Create a Monitor and Modify it
import * from bat::BDD import * from bat::Assertions var cliId = secret('clientId-alias') default 'Client Not Found' var cliSecret = secret('clientSecret-alias') default 'Secret Not Found' --- suite("HTTP Monitor") in [ it should "Assert endpoint: http://status-coder.ir-e1.cloudhub.io/status?code=200&reason=Ok" in [ GET `http://status-coder.ir-e1.cloudhub.io/status?code=200&reason=Ok` with { "headers": { "client_id": cliId, "client_secret": cliSecret } } assert [ $.response.status mustEqual 200 ] ] ]
The values highlighted in orange are aliases for the secretes stored in Secrets Manager.
Step 3: Granting Permissions and Creating Aliases
This step requires installation of BAT CLI command-line tool. Refer to the docuemntation for Installing BAT. Additionally, refer to the API Functional Monitoring with the Blackbox Automated Testing (BAT) CLI documentation for understanding all the relevant BAT CLI commands.
Using API Functional Monitoring UI setup only requires executing bat login and bat grant commands as explained below.
bat login --client-id=<client_id> --client-secret=<client_secret>
bat grant -g=NewSecretGroup -s=clientId-alias:clientId-service0001,clientSecret-alias:clientSecret-service0001
Grants successfully generated.
Now, the Monitor has access to the shared secrets through the aliases defined.
Step 4: Upload Monitor
Alternative method to upload using BAT CLI tool: (This method can be ignored if following the UI approach)
bat location ls
This will return a list of the locations available for Monitor running.
IMPORTANT: The Monitor can only run in a Private Location and these locations consume vCores from your pool.
bat schedule create --target=<id>
BAT Version: 1.0.175
# File: main.dwl
*** Setting script timeout (3599997 ms) ***
HTTP Monitor
Assert endpoint: http://<app-name>.cloudhub.io/status?code=200&reason=Ok
✓ GET http://<app-name>.cloudhub.io/status?code=200&reason=Ok (874.49ms)
✓ 200 must equal 200
# Reporter: bat/Reporters/JSON.dwl >> /var/folders/5s/vcnnv4g14c3gg6sn4vzzb04h0000gp/T/bat_report_20210118174115.json
# Reporter: bat/Reporters/HTML.dwl >> /var/folders/5s/vcnnv4g14c3gg6sn4vzzb04h0000gp/T/bat_report_20210118174115.html
#Creating artifact...
+ exchange.json
+ main.dwl
+ bat.yaml
+ .idea/.gitignore
+ .idea/workspace.xml
+ .idea/modules.xml
+ .idea/http-monitor_1.0.11.iml
+ .idea/misc.xml
# Creating artifact...OK
# Uploading <id>:http-monitor:1.0.11
# Version 1.0.12 published
scheduleId: a17ffa68-3adf-4284-9ea1-7266e38ea626
If you get an error saying the Monitor could not be uploaded, you will need to change the version in the exchange.json file.
After this, you will see the Monitor in your Functional Monitoring UI
Hit the play button and run it in the Private Location. Then in the History section, you will see the details of the call where the headers are masked
While in the logs of the application we can see the information reaching in the correct format
001115801

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.