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

shared_image_version - support for new block uefi_settings #28076

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yeoldegrove
Copy link

@yeoldegrove yeoldegrove commented Nov 20, 2024

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

  • Bump galleryimageversions API to support security profile and uefi settings.

  • For resource shared_image_version

    • support new block uefi_settings
      • This new settings configure secure boot certificates and is needed if you want to boot a secure bootable image with custom keys.
    • add documentation for uefi_settings
  • Not adding a matching block to the data source as the Azure API does not return any security profiles.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevent documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #28064

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

@yeoldegrove
Copy link
Author

When can I expect that somebody has a look at this?

Copy link

This PR is being labeled as "stale" because it has not been updated for 30 or more days.

If this PR is still valid, please remove the "stale" label. If this PR is blocked, please add it to the "Blocked" milestone.

If you need some help completing this PR, please leave a comment letting us know. Thank you!

@github-actions github-actions bot added the stale label Jan 20, 2025
@yeoldegrove
Copy link
Author

It would be great if somebody would take a look at this.

@github-actions github-actions bot removed the stale label Feb 4, 2025
@codgician
Copy link

Kindly adding some active maintainers for comments: @katbyte @jackofallops @stephybun

@yeoldegrove
Copy link
Author

@codgician @katbyte @jackofallops @stephybun Can anybody please start reviewing this?

Copy link
Contributor

@ms-zhenhua ms-zhenhua left a comment

Choose a reason for hiding this comment

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

Hi @yeoldegrove,

Thanks for this PR - I've taken a look through and left some comments inline. If we can fix those up, this should be good to go 👍

@yeoldegrove yeoldegrove force-pushed the shared_image_version_uefi_settings branch from 58ad4cf to 57ef77c Compare February 24, 2025 11:46
@yeoldegrove
Copy link
Author

@ms-zhenhua Thanks for the review! I just fixed all the issues you pointed out and force pushed to this PR.

Copy link
Contributor

@ms-zhenhua ms-zhenhua left a comment

Choose a reason for hiding this comment

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

Hi @yeoldegrove,

Thanks for your updates - I've taken another look through and left some comments inline. Please help confirm.

@yeoldegrove yeoldegrove force-pushed the shared_image_version_uefi_settings branch from 57ef77c to d74f0fc Compare February 26, 2025 12:45
@yeoldegrove
Copy link
Author

@ms-zhenhua another round of improvements ;)

Copy link
Contributor

@ms-zhenhua ms-zhenhua left a comment

Choose a reason for hiding this comment

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

Hi @yeoldegrove,

Thanks for your updates - I've taken another look through and left some comments inline. Please help confirm.

data := input[0].(map[string]interface{})
return &galleryimageversions.UefiKey{
Type: pointer.To(galleryimageversions.UefiKeyType(data["type"].(string))),
Value: &[]string{data["certificate_base64"].(string)},
Copy link
Contributor

Choose a reason for hiding this comment

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

since certificate_base64 is a string list, why convert it to a string ?

Copy link
Author

Choose a reason for hiding this comment

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

Removed both Single functions. Those were artifacts I missed in the refactoring.


result := make(map[string]interface{})
if input.Value != nil && len(*input.Value) > 0 {
result["certificate_base64"] = (*input.Value)[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

certificate_base64 is a string list, why assign the first element only?

Copy link
Author

Choose a reason for hiding this comment

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

Removed both Single functions. Those were artifacts I missed in the refactoring.

return results
}

func flattenUefiKey(input *galleryimageversions.UefiKey) []interface{} {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference between flattenSingleUefiKey and flattenUefiKey ?

Copy link
Author

Choose a reason for hiding this comment

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

Removed both Single functions. Those were artifacts I missed in the refactoring.

Comment on lines +300 to +303
check.That(data.ResourceName).Key("uefi_settings.0.signature_template_names.#").HasValue("1"),
check.That(data.ResourceName).Key("uefi_settings.0.signature_template_names.0").HasValue("MicrosoftUefiCertificateAuthorityTemplate"),
check.That(data.ResourceName).Key("uefi_settings.0.additional_signatures.0.db.0.type").HasValue(keyType),
check.That(data.ResourceName).Key("uefi_settings.0.additional_signatures.0.db.0.certificate_base64.0").HasValue(certData),
Copy link
Contributor

Choose a reason for hiding this comment

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

why these checks still exist?

Copy link
Author

Choose a reason for hiding this comment

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

Forgot to add this to the commit 🤦

Comment on lines +485 to +493
if securityProfile := props.SecurityProfile; securityProfile != nil {
if uefiSettings := securityProfile.UefiSettings; uefiSettings != nil {
d.Set("uefi_settings", flattenUefiSettings(uefiSettings))
} else {
d.Set("uefi_settings", nil)
}
} else {
d.Set("uefi_settings", nil)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if securityProfile := props.SecurityProfile; securityProfile != nil {
if uefiSettings := securityProfile.UefiSettings; uefiSettings != nil {
d.Set("uefi_settings", flattenUefiSettings(uefiSettings))
} else {
d.Set("uefi_settings", nil)
}
} else {
d.Set("uefi_settings", nil)
}
if securityProfile := props.SecurityProfile; securityProfile != nil {
d.Set("uefi_settings", flattenUefiSettings(securityProfile.UefiSettings;))
}

Copy link
Author

Choose a reason for hiding this comment

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

👍 I guess I thought to complicated here.

})
}

func TestAccSharedImageVersion_uefiSettingsUpdateKeyType(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please consider combing TestAccSharedImageVersion_uefiSettings and TestAccSharedImageVersion_uefiSettingsUpdateKeyType into one testcase as their first steps are the same.

Copy link
Author

Choose a reason for hiding this comment

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

I can remove one of those and only use the combined one, correct.

additional_signatures {
db {
type = "%s"
certificate_base64 = "%s"
Copy link
Contributor

Choose a reason for hiding this comment

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

since certificate_base64 is a string list in the schema, why it is a string here? Could you provide your local test result?

Copy link
Author

Choose a reason for hiding this comment

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

Actually my testing setup/cycle was provisioning resources with my built provider by hand.

I now checked out https://github.com/hashicorp/terraform-provider-azurerm/blob/main/DEVELOPER.md#developing-the-provider and managed to run make acctests SERVICE='compute' TESTARGS='-run=TestAccSharedImageVersion_uefiSettings' TESTTIMEOUT='60m'

I must say... having to create ARM_CLIENT_ID was a bit complicated as the subscription I have did not initially allow this.

But now I managed to fix most of the test cases. But now I have to figure out to boot a secure bootable VM in this test setup. This will most likely take a few hours.

@ms-zhenhua Do you think it is advisable to really boot a secure_boot_enabled and vtpm_enabled enabled VM (with real keys) inside the test suite?

signature_template_names = [%s]

additional_signatures {
db {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you also test dbx, kek and pk ?

Copy link
Author

Choose a reason for hiding this comment

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

sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for uefi_settings in azurerm_shared_image_version
3 participants