Skip to content

Commit aa7624a

Browse files
sudo87Locharla, Sandeep
authored andcommitted
Mask vncPasswd being logged in agent.log (apache#12404)
1 parent f0669b2 commit aa7624a

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
163163
final String target = command.getDestinationIp();
164164
xmlDesc = dm.getXMLDesc(xmlFlag);
165165
if (logger.isDebugEnabled()) {
166-
logger.debug(String.format("VM [%s] with XML configuration [%s] will be migrated to host [%s].", vmName, xmlDesc, target));
166+
logger.debug("VM {} with XML configuration {} will be migrated to host {}.", vmName, maskSensitiveInfoInXML(xmlDesc), target);
167167
}
168168

169169
// Limit the VNC password in case the length is greater than 8 characters
@@ -178,7 +178,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
178178
logger.debug(String.format("Editing mount path of ISO from %s to %s", oldIsoVolumePath, newIsoVolumePath));
179179
xmlDesc = replaceDiskSourceFile(xmlDesc, newIsoVolumePath, vmName);
180180
if (logger.isDebugEnabled()) {
181-
logger.debug(String.format("Replaced disk mount point [%s] with [%s] in Instance [%s] XML configuration. New XML configuration is [%s].", oldIsoVolumePath, newIsoVolumePath, vmName, xmlDesc));
181+
logger.debug("Replaced disk mount point {} with {} in Instance {} XML configuration. New XML configuration is {}.", oldIsoVolumePath, newIsoVolumePath, vmName, maskSensitiveInfoInXML(xmlDesc));
182182
}
183183
}
184184

@@ -209,23 +209,23 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
209209

210210
if (migrateStorage) {
211211
if (logger.isDebugEnabled()) {
212-
logger.debug(String.format("Changing VM [%s] volumes during migration to host: [%s].", vmName, target));
212+
logger.debug("Changing VM {} volumes during migration to host: {}.", vmName, target);
213213
}
214214
xmlDesc = replaceStorage(xmlDesc, mapMigrateStorage, migrateStorageManaged);
215215
if (logger.isDebugEnabled()) {
216-
logger.debug(String.format("Changed VM [%s] XML configuration of used storage. New XML configuration is [%s].", vmName, xmlDesc));
216+
logger.debug("Changed VM {} XML configuration of used storage. New XML configuration is {}.", vmName, maskSensitiveInfoInXML(xmlDesc));
217217
}
218218
migrateDiskLabels = getMigrateStorageDeviceLabels(disks, mapMigrateStorage);
219219
}
220220

221221
Map<String, DpdkTO> dpdkPortsMapping = command.getDpdkInterfaceMapping();
222222
if (MapUtils.isNotEmpty(dpdkPortsMapping)) {
223223
if (logger.isTraceEnabled()) {
224-
logger.trace(String.format("Changing VM [%s] DPDK interfaces during migration to host: [%s].", vmName, target));
224+
logger.trace("Changing VM {} DPDK interfaces during migration to host: {}.", vmName, target);
225225
}
226226
xmlDesc = replaceDpdkInterfaces(xmlDesc, dpdkPortsMapping);
227227
if (logger.isDebugEnabled()) {
228-
logger.debug(String.format("Changed VM [%s] XML configuration of DPDK interfaces. New XML configuration is [%s].", vmName, xmlDesc));
228+
logger.debug("Changed VM {} XML configuration of DPDK interfaces. New XML configuration is {}.", vmName, maskSensitiveInfoInXML(xmlDesc));
229229
}
230230
}
231231

@@ -240,7 +240,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
240240
}
241241

242242
//run migration in thread so we can monitor it
243-
logger.info(String.format("Starting live migration of instance [%s] to destination host [%s] having the final XML configuration: [%s].", vmName, dconn.getURI(), xmlDesc));
243+
logger.info("Starting live migration of instance {} to destination host {} having the final XML configuration: {}.", vmName, dconn.getURI(), maskSensitiveInfoInXML(xmlDesc));
244244
final ExecutorService executor = Executors.newFixedThreadPool(1);
245245
boolean migrateNonSharedInc = command.isMigrateNonSharedInc() && !migrateStorageManaged;
246246

@@ -715,9 +715,7 @@ String replaceIpForVNCInDescFileAndNormalizePassword(String xmlDesc, final Strin
715715
graphElem = graphElem.replaceAll("passwd='([^\\s]+)'", "passwd='" + vncPassword + "'");
716716
}
717717
xmlDesc = xmlDesc.replaceAll(GRAPHICS_ELEM_START + CONTENTS_WILDCARD + GRAPHICS_ELEM_END, graphElem);
718-
if (logger.isDebugEnabled()) {
719-
logger.debug(String.format("Replaced the VNC IP address [%s] with [%s] in VM [%s].", originalGraphElem, graphElem, vmName));
720-
}
718+
logger.debug("Replaced the VNC IP address {} with {} in VM {}.", maskSensitiveInfoInXML(originalGraphElem), maskSensitiveInfoInXML(graphElem), vmName);
721719
}
722720
}
723721
return xmlDesc;
@@ -1036,4 +1034,10 @@ private boolean findSourceNode(Document doc, Node diskNode, String vmName, Strin
10361034
}
10371035
return false;
10381036
}
1037+
1038+
public static String maskSensitiveInfoInXML(String xmlDesc) {
1039+
if (xmlDesc == null) return null;
1040+
return xmlDesc.replaceAll("(graphics\\s+[^>]*type=['\"]vnc['\"][^>]*passwd=['\"])([^'\"]*)(['\"])",
1041+
"$1*****$3");
1042+
}
10391043
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public Answer execute(final StartCommand command, final LibvirtComputingResource
8484
}
8585

8686
libvirtComputingResource.createVifs(vmSpec, vm);
87-
88-
logger.debug("starting " + vmName + ": " + vm.toString());
87+
if (logger.isDebugEnabled()) {
88+
logger.debug("Starting {} : {}", vmName, LibvirtMigrateCommandWrapper.maskSensitiveInfoInXML(vm.toString()));
89+
}
8990
String vmInitialSpecification = vm.toString();
9091
String vmFinalSpecification = performXmlTransformHook(vmInitialSpecification, libvirtComputingResource);
9192
libvirtComputingResource.startVM(conn, vmName, vmFinalSpecification);

0 commit comments

Comments
 (0)