Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fixing logger prints unmasked sensitive data. #78

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.avioconsulting.mule.deployment.api.models.deployment

import com.avioconsulting.mule.deployment.api.models.CloudhubWorkerSpecRequest
import com.avioconsulting.mule.deployment.internal.models.CloudhubAppProperties
import com.avioconsulting.mule.deployment.secure.PropertiesObfuscator
import com.fasterxml.jackson.databind.ObjectMapper
import groovy.json.JsonOutput
import groovy.transform.ToString
Expand Down Expand Up @@ -157,4 +158,9 @@ class CloudhubDeploymentRequest extends FileBasedAppDeploymentRequest {
String getCloudhubAppInfoAsJson() {
JsonOutput.toJson(cloudhubAppInfo)
}

Map<String,String> getCloudAppInfoAsObfuscatedJson() {
PropertiesObfuscator.obfuscateMap(cloudhubAppInfo,"properties")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CloudHubDeployer extends BaseDeployer implements ICloudHubDeployer {

private def doDeployment(HttpEntityEnclosingRequestBase request,
CloudhubDeploymentRequest deploymentRequest) {
def prettyJson = JsonOutput.prettyPrint(deploymentRequest.cloudhubAppInfoAsJson)
def prettyJson = JsonOutput.prettyPrint(JsonOutput.toJson(deploymentRequest.getCloudAppInfoAsObfuscatedJson()))
if (dryRunMode != DryRunMode.Run) {
logger.println "WOULD deploy using settings but in dry-run mode: ${prettyJson}"
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.avioconsulting.mule.deployment.secure

class PropertiesObfuscator {

private static PROPERTIES_TO_MATCH_EXP = "\\b(^.*key.*\$|^.*secret.*\$|^.*password.*\$|^.*client_id.*|^.*clientId.*|^.*pwd.*\$)\\b"
public static MASKING_STRING = "**************"

private static Map<String,String> obfuscateProperties(Map<String,String> mapToObfuscate){
Map<String,String> obfuscatedMap = new LinkedHashMap<>()
mapToObfuscate.keySet().forEach {key ->
if(key.toLowerCase().matches(PROPERTIES_TO_MATCH_EXP.toLowerCase())){
obfuscatedMap.put(key,MASKING_STRING)
}else{
obfuscatedMap.put(key,mapToObfuscate.get(key))
}
}
obfuscatedMap
}

static Map<String,String> obfuscateMap(Map<String,String> mapToObfuscate, String propertiesEntryKey){
def appInfo = mapToObfuscate
if(appInfo.containsKey(propertiesEntryKey)){
Map<String,String> propsToObfuscate = appInfo[propertiesEntryKey]
appInfo.remove(propertiesEntryKey)
appInfo[propertiesEntryKey] = PropertiesObfuscator.obfuscateProperties(propsToObfuscate)
}
appInfo
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,47 @@ class CloudhubDeploymentRequestTest implements MavenInvoke {
]
]))
}

@Test
void test_obfuscate_properties() {
def request = new CloudhubDeploymentRequest('DEV',
new CloudhubWorkerSpecRequest(),
builtFile,
'theKey',
'theClientId',
'theSecret',
'client')

// act
def appInfo = request.getCloudAppInfoAsObfuscatedJson()

// assert
assertThat appInfo,
is(equalTo([
domain : 'client-mule-deploy-lib-v4-test-app-dev',
muleVersion : [
version: '4.3.0'
],
monitoringAutoRestart : true,
workers : [
type : [
name: 'Micro'
],
amount: 1
],
staticIPsEnabled : false,
loggingCustomLog4JEnabled: false,
objectStoreV1 : false,
persistentQueues : false,
properties : [
env : 'dev',
'crypto.key' : '**************',
'anypoint.platform.client_id' : '**************',
'anypoint.platform.client_secret' : '**************',
'anypoint.platform.config.analytics.agent.enabled': true
]
]))


}
}