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

Change type of encryption_at_host to *bool #338

Merged
merged 6 commits into from
Oct 16, 2023

Conversation

KMConner
Copy link
Contributor

In v1.4.4, encryption_at_host flag was introduced, but we need to enable EncryptionAtHost on Azure subscrioptions in oder to use encryption_at_host feature.

packer build with arm builder always fails on Azure subscription if EncryptionAtHost feature is not enabled.
This error happens even if encryption_at_host is set to false or encryption_at_host is not specified.

The below is the error message.

[{"code":"InvalidParameter","message":"The property 'securityProfile.encryptionAtHost' is not valid because the 'Microsoft.Compute/EncryptionAtHost' feature is not enabled for this subscription.","target":"securityProfile.encryptionAtHost"}]

This is because securityProfile.encryptionAtHost property is always specified in the template deployed while build.
The property should not be specified when EncryptionAtHost feature is not enabled (Error happend even if false is specified).

So, I changed encryption_at_host argument from bool to *bool, so that securityProfile.encryptionAtHost property is not contained in the deployed template when encryption_at_host is not specified.

@hashicorp-cla
Copy link

hashicorp-cla commented Sep 16, 2023

CLA assistant check
All committers have signed the CLA.

@KMConner KMConner marked this pull request as ready for review September 16, 2023 17:34
@KMConner KMConner requested a review from a team as a code owner September 16, 2023 17:34
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

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

Hi @KMConner,

Thanks for submitting this PR, I reviewed the code, and while this works, I wonder if we can only add the attribute to the template if it is set, and not systematically.
This may not cover all cases though, but I'll leave this suggestion here, feel free to respond when you have time.

Other than this concern, the code looks legit, I'll come back to this when there's an update, and if we decide to keep the code as-is, we can merge.

@@ -533,7 +533,7 @@ func (s *TemplateBuilder) SetSecurityProfile(secureBootEnabled bool, vtpmEnabled
resource.Properties.SecurityProfile.UefiSettings.SecureBootEnabled = common.BoolPtr(secureBootEnabled)
resource.Properties.SecurityProfile.UefiSettings.VTpmEnabled = common.BoolPtr(vtpmEnabled)
}
resource.Properties.SecurityProfile.EncryptionAtHost = common.BoolPtr(encryptionAtHost)
resource.Properties.SecurityProfile.EncryptionAtHost = encryptionAtHost
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder, should we only set the parameter if true instead of always setting a value? This would be a different (simpler) implementation than what you propose here, that being said maybe there's a case for setting encryptionAtHost to false manually?
If so the current approach makes sense and we can accept it as-is.

cc @JenGoldstrich since you know Azure much better than I do

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm conflicted tbh, to do what you suggest it would need to be refactored to be something like this

if encryptionAtHost != nil && *encryptionAtHost {
     	resource.Properties.SecurityProfile.EncryptionAtHost = encryptionAtHost
}

While we would avoid setting the the field in the template by changing to this, it requires that extra nil check and a true/false. check, when we never actually send false, only true and nil, since sending false is what causes this issue for Azure Subscriptions without this feature enabled (TBH this feels like an API bug but thats an aside). But I will accept either solution tbh

@JenGoldstrich
Copy link
Contributor

Hey @KMConner thanks for your PR, I merged a PR that modifies the template builder quite a lot, do you mind rebasing on top of those changes, and making sure your changes still resolve your issue? Honestly after bumping the deployment API version we might have resolved this issue so it'd be helpful for you to re-test with the version of the plugin on main (If you'd prefer I can trigger a release next week for you to try before we move forward). If you still experience this issue on the new API I'm happy to merge this change to unblock you from upgrading your Azure plugin

@KMConner KMConner force-pushed the encrypt-at-host-nil branch from d61a569 to 9e58ff8 Compare October 15, 2023 16:07
Copy link
Contributor

@JenGoldstrich JenGoldstrich left a comment

Choose a reason for hiding this comment

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

Thanks for rebasing, @KMConner this LGTM, I manually tested this field and ran acceptance tests, thanks for your contribution!

@JenGoldstrich JenGoldstrich merged commit 81cf188 into hashicorp:main Oct 16, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants