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

Add encryption at host flag to the arm template #311

Merged
merged 1 commit into from
Jul 6, 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
3 changes: 3 additions & 0 deletions builder/azure/arm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@ type Config struct {
LicenseType string `mapstructure:"license_type" required:"false"`
// Specifies if Secure Boot and Trusted Launch is enabled for the Virtual Machine.
SecureBootEnabled bool `mapstructure:"secure_boot_enabled" required:"false"`
// Specifies if Encryption at host is enabled for the Virtual Machine.
Copy link
Contributor

@JenGoldstrich JenGoldstrich Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Specifies if Encryption at host is enabled for the Virtual Machine.
// Specifies if Encryption at host is enabled for the Virtual Machine.
// Requires enabling encryption at host in the Subscription read more [here](https://learn.microsoft.com/en-us/azure/virtual-machines/disks-enable-host-based-encryption-portal?tabs=azure-powershell)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamilpi do you mind taking in this change as well? Afterwards you need to run make generate to generate the docs site from the config, let me know if you have any trouble with this as I can just commit the change to your fork

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// Requires enabling encryption at host in the Subscription read more [here](https://learn.microsoft.com/en-us/azure/virtual-machines/disks-enable-host-based-encryption-portal?tabs=azure-powershell)
EncryptionAtHost bool `mapstructure:"encryption_at_host" required:"false"`

// Specifies if vTPM (virtual Trusted Platform Module) and Trusted Launch is enabled for the Virtual Machine.
VTpmEnabled bool `mapstructure:"vtpm_enabled" required:"false"`
Expand Down
2 changes: 2 additions & 0 deletions builder/azure/arm/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions builder/azure/arm/template_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func GetVirtualMachineDeployment(config *Config) (*resources.Deployment, error)
}
}

if config.SecureBootEnabled || config.VTpmEnabled {
err = builder.SetSecurityProfile(config.SecureBootEnabled, config.VTpmEnabled)
if config.SecureBootEnabled || config.VTpmEnabled || config.EncryptionAtHost {
err = builder.SetSecurityProfile(config.SecureBootEnabled, config.VTpmEnabled, config.EncryptionAtHost)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
}
},
"securityProfile": {
"encryptionAtHost": false,
"securityType": "TrustedLaunch",
"uefiSettings": {
"secureBootEnabled": true,
Expand Down
12 changes: 6 additions & 6 deletions builder/azure/chroot/shared_image_gallery_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func TestSharedImageGalleryDestination_Validate(t *testing.T) {
ImageName: "ImageName",
ImageVersion: "0.1.2",
TargetRegions: []TargetRegion{
TargetRegion{
{
Name: "region1",
ReplicaCount: 5,
StorageAccountType: "Standard_ZRS",
},
TargetRegion{
{
Name: "region2",
ReplicaCount: 3,
StorageAccountType: "Standard_LRS",
Expand All @@ -78,12 +78,12 @@ func TestSharedImageGalleryDestination_Validate(t *testing.T) {
ImageName: "ImageName",
ImageVersion: "0.1.2",
TargetRegions: []TargetRegion{
TargetRegion{
{
Name: "region1",
ReplicaCount: 5,
StorageAccountType: "Standard_ZRS",
},
TargetRegion{
{
Name: "region2",
ReplicaCount: 3,
StorageAccountType: "Standard_LRS",
Expand All @@ -104,12 +104,12 @@ func TestSharedImageGalleryDestination_Validate(t *testing.T) {
ImageName: "ImageName",
ImageVersion: "0.1.2alpha",
TargetRegions: []TargetRegion{
TargetRegion{
{
Name: "region1",
ReplicaCount: 5,
StorageAccountType: "Standard_ZRS",
},
TargetRegion{
{
Name: "region2",
ReplicaCount: 3,
StorageAccountType: "Standard_LRS",
Expand Down
13 changes: 8 additions & 5 deletions builder/azure/common/template/template_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,21 @@ func (s *TemplateBuilder) SetLicenseType(licenseType string) error {
return nil
}

func (s *TemplateBuilder) SetSecurityProfile(secureBootEnabled bool, vtpmEnabled bool) error {
func (s *TemplateBuilder) SetSecurityProfile(secureBootEnabled bool, vtpmEnabled bool, encryptionAtHost bool) error {
s.setVariable("apiVersion", "2020-12-01") // Required for Trusted Launch
resource, err := s.getResourceByType(resourceVirtualMachine)
if err != nil {
return err
}

resource.Properties.SecurityProfile = &compute.SecurityProfile{}
resource.Properties.SecurityProfile.UefiSettings = &compute.UefiSettings{}
resource.Properties.SecurityProfile.SecurityType = compute.SecurityTypesTrustedLaunch
resource.Properties.SecurityProfile.UefiSettings.SecureBootEnabled = to.BoolPtr(secureBootEnabled)
resource.Properties.SecurityProfile.UefiSettings.VTpmEnabled = to.BoolPtr(vtpmEnabled)
if secureBootEnabled || vtpmEnabled {
resource.Properties.SecurityProfile.UefiSettings = &compute.UefiSettings{}
resource.Properties.SecurityProfile.SecurityType = compute.SecurityTypesTrustedLaunch
resource.Properties.SecurityProfile.UefiSettings.SecureBootEnabled = to.BoolPtr(secureBootEnabled)
resource.Properties.SecurityProfile.UefiSettings.VTpmEnabled = to.BoolPtr(vtpmEnabled)
}
resource.Properties.SecurityProfile.EncryptionAtHost = to.BoolPtr(encryptionAtHost)
JenGoldstrich marked this conversation as resolved.
Show resolved Hide resolved

return nil
}
Expand Down
3 changes: 3 additions & 0 deletions docs-partials/builder/azure/arm/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@

- `secure_boot_enabled` (bool) - Specifies if Secure Boot and Trusted Launch is enabled for the Virtual Machine.

- `encryption_at_host` (bool) - Specifies if Encryption at host is enabled for the Virtual Machine.
Requires enabling encryption at host in the Subscription read more [here](https://learn.microsoft.com/en-us/azure/virtual-machines/disks-enable-host-based-encryption-portal?tabs=azure-powershell)

- `vtpm_enabled` (bool) - Specifies if vTPM (virtual Trusted Platform Module) and Trusted Launch is enabled for the Virtual Machine.

- `async_resourcegroup_delete` (bool) - If you want packer to delete the
Expand Down