Skip to content

Commit 72b1cca

Browse files
authored
Added support for TrustedLaunch flag for agent deployments (#544)
1 parent 8efd635 commit 72b1cca

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ public int hashCode() {
306306

307307
private boolean installDocker;
308308

309+
private boolean trustedLaunch;
310+
309311
private final String osType;
310312

311313
private transient String agentLaunchMethod;
@@ -632,6 +634,15 @@ public void setSpotInstance(boolean spotInstance) {
632634
this.spotInstance = spotInstance;
633635
}
634636

637+
public boolean isTrustedLaunch() {
638+
return trustedLaunch;
639+
}
640+
641+
@DataBoundSetter
642+
public void setTrustedLaunch(boolean trustedLaunch) {
643+
this.trustedLaunch = trustedLaunch;
644+
}
645+
635646
public boolean isAcceleratedNetworking() {
636647
return acceleratedNetworking;
637648
}

src/main/java/com/microsoft/azure/vmagent/AzureVMManagementServiceDelegate.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ public AzureVMDeploymentInfo createDeployment(
629629
if (template.isSpotInstance()) {
630630
addSpotInstance(tmp);
631631
}
632+
633+
if (template.isTrustedLaunch()) {
634+
addTrustedLaunch(tmp);
635+
}
632636

633637
if (!(Boolean) properties.get("usePrivateIP")) {
634638
addPublicIPResourceNode(tmp, tags);
@@ -739,6 +743,44 @@ private void addSpotInstance(JsonNode template) {
739743
}
740744
}
741745
}
746+
747+
748+
private void addTrustedLaunch(JsonNode template) {
749+
ObjectNode parameterNode = (ObjectNode) template.get("parameters");
750+
ObjectNode securityTypeNode = MAPPER.createObjectNode();
751+
securityTypeNode.put("type", "string");
752+
securityTypeNode.put("defaultValue", "TrustedLaunch");
753+
ArrayNode allowedValuesNode = MAPPER.createArrayNode();
754+
allowedValuesNode.add("Standard");
755+
allowedValuesNode.add("TrustedLaunch");
756+
securityTypeNode.set("allowedValues", allowedValuesNode);
757+
ObjectNode metaDataNode = MAPPER.createObjectNode();
758+
metaDataNode.put("description", "Security Type of the Virtual Machine.");
759+
securityTypeNode.set("metadata", metaDataNode);
760+
parameterNode.set("securityType", securityTypeNode);
761+
762+
ObjectNode variableNode = (ObjectNode) template.get("variables");
763+
ObjectNode profileNode = MAPPER.createObjectNode();
764+
ObjectNode settingsNode = MAPPER.createObjectNode();
765+
settingsNode.put("secureBootEnabled", true);
766+
settingsNode.put("vTpmEnabled", true);
767+
768+
profileNode.set("uefiSettings", settingsNode);
769+
profileNode.put("securityType", "[parameters('securityType')]");
770+
771+
variableNode.set("securityProfileJson", profileNode);
772+
773+
774+
775+
ArrayNode resources = (ArrayNode) template.get("resources");
776+
for (JsonNode resource : resources) {
777+
String type = resource.get("type").asText();
778+
if (type.contains("virtualMachine")) {
779+
ObjectNode properties = (ObjectNode) resource.get("properties");
780+
properties.put("securityProfile", "[if(equals(parameters('securityType'), 'TrustedLaunch'), variables('securityProfileJson'), null())]");
781+
}
782+
}
783+
}
742784

743785
private void addAcceleratedNetworking(JsonNode template) {
744786
ArrayNode resources = (ArrayNode) template.get("resources");

src/main/resources/com/microsoft/azure/vmagent/AzureVMAgentTemplate/config.jelly

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@
130130
<f:entry title="${%Spot instance}" field="spotInstance">
131131
<f:checkbox/>
132132
</f:entry>
133+
134+
<f:entry title="${%Use Trusted Launch}" field="trustedLaunch">
135+
<f:checkbox/>
136+
</f:entry>
137+
133138

134139
<f:entry title="${%Enable_MSI}" field="enableMSI">
135140
<f:checkbox/>

0 commit comments

Comments
 (0)