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

azurerm_key_vault_key - rotation_policy block added #19113

Merged
merged 12 commits into from
Feb 28, 2023

Conversation

aristosvo
Copy link
Collaborator

@aristosvo aristosvo commented Nov 2, 2022

Depends on #18576

Fixes #14471

Issues:

@aristosvo aristosvo force-pushed the keyvault/key_rotation_policy_inline branch 2 times, most recently from f993fe3 to 9127673 Compare November 2, 2022 23:10
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

THanks @aristosvo - couple comments on property names, mainly expire_time seems less then idea for clarity on what it means. WDYT?

internal/services/keyvault/key_vault_key_resource.go Outdated Show resolved Hide resolved
internal/services/keyvault/key_vault_key_resource.go Outdated Show resolved Hide resolved
website/docs/r/key_vault_key.html.markdown Outdated Show resolved Hide resolved
website/docs/r/key_vault_key.html.markdown Outdated Show resolved Hide resolved
website/docs/r/key_vault_key.html.markdown Outdated Show resolved Hide resolved
@aristosvo aristosvo marked this pull request as ready for review November 3, 2022 08:27
@aristosvo
Copy link
Collaborator Author

aristosvo commented Nov 3, 2022

@katbyte It seems the troubles of implementing this as an inline resource are bubbling up:

testcase.go:110: Step 1/1 error: Error running apply: exit status 1
Error: keyvault.BaseClient#GetKeyRotationPolicy: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="Forbidden" Message="The user, group or application 'appid=*******;oid=3aa04c8c-5a75-4e5e-9117-1b7cf6f33e21;numgroups=9;iss=https://sts.windows.net/*******/' does not have keys getrotationpolicy permission on key vault 'acctestkv-vecj9;location=westeurope'. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287" InnerError={"code":"ForbiddenByPolicy"}
with azurerm_key_vault_key.test,

This means we would not have backwards compatibility and we'd need more permissions on key_vault than strictly necessary for a non-keyvaultkeypolicy user.. 😢 Especially in a resource like KV, not something we want.., WDYT?

Edit: Added a workaround for now, ignoring the policy if unauthorised. Maybe something like a features flag would be the best solution:

provider "azurerm" {
  features {
    key_vault {
      ignore_missing_key_vault_key_policy_permissions = true
    }
  }
}

@katbyte
Copy link
Collaborator

katbyte commented Nov 3, 2022

@aristosvo - would those permissions not still be needed by the separate resources?

i imagine you could infer if the user is trying to set them from the existence of the block or not, if not set + read fails ignore, if set + read fails error out, but that does seem less then ideal 😅

@aristosvo
Copy link
Collaborator Author

aristosvo commented Nov 3, 2022

@aristosvo - would those permissions not still be needed by the separate resources?

Yes it would, but then it is not breaking azurerm_key_vault_key for existing user base with limited permissions

i imagine you could infer if the user is trying to set them from the existence of the block or not, if not set + read fails ignore, if set + read fails error out, but that does seem less then ideal 😅

Yeah, doing something like that now, I set it conditionally and ignore read fails. Could finetune that indeed a bit, but it still isn't ideal. Should've stopped thinking earlier and just implemented it separately 😅

Reopened and improved #18603 to have options. Both are working and tested, each with their own compromise I'd say.

@aristosvo aristosvo force-pushed the keyvault/key_rotation_policy_inline branch 2 times, most recently from 01ca72e to b149c02 Compare November 12, 2022 08:02
@katbyte katbyte added the upstream/microsoft Indicates that there's an upstream issue blocking this issue/PR label Nov 14, 2022
@katbyte katbyte added this to the Blocked milestone Nov 14, 2022
@katbyte
Copy link
Collaborator

katbyte commented Nov 15, 2022

this is waiting on #18576 which is waiting on Azure/azure-rest-api-specs#21137

@aristosvo
Copy link
Collaborator Author

Added in SDK v7.4, but this one is not available yet, causing all tests to fail.

@tombuildsstuff
Copy link
Contributor

@aristosvo SDK v7.4 is now available in tombuildsstuff/kermit, which is being updated in #20649 - so once that's in we should be able to rebase this FYI :)

@tombuildsstuff tombuildsstuff removed this from the Blocked milestone Feb 24, 2023
@tombuildsstuff tombuildsstuff removed the upstream/microsoft Indicates that there's an upstream issue blocking this issue/PR label Feb 24, 2023
@aristosvo aristosvo force-pushed the keyvault/key_rotation_policy_inline branch from c661169 to 8c7e679 Compare February 24, 2023 13:31
@aristosvo
Copy link
Collaborator Author

Rebased and replaced with the kermit SDK!!

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Thanks @aristosvo ! LGTM 🌴

@katbyte katbyte merged commit a872bf3 into hashicorp:main Feb 28, 2023
@github-actions github-actions bot added this to the v3.46.0 milestone Feb 28, 2023
katbyte added a commit that referenced this pull request Feb 28, 2023
@MattoHopkins
Copy link

MattoHopkins commented Feb 28, 2023

Out of curiosity, will v3.46.0 come out the 2nd @katbyte? Not normally a github follower, but I noticed the 'due date' was the 2nd and wasn't sure if those were hard or soft dates

Ty ty!

@ziyeqf
Copy link
Contributor

ziyeqf commented Feb 28, 2023

Hey @aristosvo @katbyte , want to confirm the final decision on "ignore read fails", it seems it's always failing but with a more friendly error message when read fails without enough permission now?

https://github.com/hashicorp/terraform-provider-azurerm/blob/main/internal/services/keyvault/key_vault_key_resource.go#L590

@aristosvo
Copy link
Collaborator Author

@ziyeqf Although it has been a while since implementing it, I believe that is indeed the case, discussed that with @katbyte privately.

@github-actions
Copy link

github-actions bot commented Mar 6, 2023

This functionality has been released in v3.46.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@markor002002
Copy link

This functionality has been released but no documentation has bene provided.

@aristosvo
Copy link
Collaborator Author

This functionality has been released but no documentation has bene provided.

website/docs/r/key_vault_key.html.markdown contains updates in this PR on the rotation_policy block, can you explain what you are looking for?

@markor002002
Copy link

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_key my bad sorry all is ok,

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Azure Keyvault key rotation and rotation policy
6 participants