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 stand-alone resource to edit Key Vault access policies #1052

Closed
wants to merge 3 commits into from

Conversation

day-jeff
Copy link
Contributor

@day-jeff day-jeff commented Mar 31, 2018

This new resource allows access policies to be set on existing Key Vaults without creating/destroying the KV instance. This allows new resources (e.g. VMs) to be given access to keys, secrets and certificates stored in KV.

This PR was created in order to allow new VMs (stand-alone or in a scale set) to read/write secrets and certificates from/to an existing Key Vault.

@day-jeff
Copy link
Contributor Author

Ping... Any way to get a review going on this PR?

@monkey-jeff
Copy link

I didn't notice this PR when I opened #1149 this weekend. I didn't see any PRs associated with #754 which is the issue i was looking at.

I just want this feature added, so lets pool resources. I see several issues with this PR and will comment inline pointing them out. To avoid duplicate work lets collaborate here.

Copy link

@monkey-jeff monkey-jeff left a comment

Choose a reason for hiding this comment

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

Just a few issues I currently see with this. Sorry if it seems like I am being harsh, definitely not my intention.

// schema with some tweaks so that unneed properties need not be
// specified in the template.

kvapSchema := resourceArmKeyVault()

Choose a reason for hiding this comment

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

Doing this will make it look just like a Key Vault resource so the examples you have wouldn't follow this pater. This resource would have to look like

resource "azurerm_key_vault" "test" {
  name                = "testvault"
  resource_group_name = "${azurerm_resource_group.test.name}"

  tenant_id = "d6e396d0-5584-41dc-9fc0-268df99bc610"

  access_policy {
    tenant_id = "d6e396d0-5584-41dc-9fc0-268df99bc610"
    object_id = "d746815a-0433-4a21-b95d-fc437d2d475b"

    key_permissions = [
      "get",
    ]

    secret_permissions = [
      "get",
    ]
  }

Which wouldn't really be allowing you to attach it to an existing keyvault.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed that the SDK has the UpdateAccessPolicy function. I therefore intentionally reused the KV resource with the idea of reading all its existing properties and editing only the access policies. Given that UpdateAccessPolicy is there, I will quickly reassess approaches and write back.

Tags: expandTags(tags),
}

_, err = client.CreateOrUpdate(ctx, resGroup, name, parameters)
Copy link

@monkey-jeff monkey-jeff Apr 23, 2018

Choose a reason for hiding this comment

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

There is a call in the sdk to only update the policy

client.UpdateAccessPolicy(ctx, resGroup, name, action, parameters)

*# Remaining scaleset configuration omitted for brevity...*
}

resource "azurerm_key_vault_access_policy" "test" {

Choose a reason for hiding this comment

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

As noted above, the written code would allow for resources that look like this.

Access policies can be imported from any Key Vault using the `resource id`, e.g.

```shell
terraform import azurerm_key_vault.test /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.KeyVault/vaults/vault1

Choose a reason for hiding this comment

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

Probably shouldn't import the entire vault for just the access policies.

}
}

resource access_policy {

Choose a reason for hiding this comment

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

This terraform is malformed and the tests fail due to this, should be

resource "azurerm_key_vault_access_policy" "test"

Or something like that

})
}

func testCheckAzureRMKeyVaultAccessPolicyDestroy(s *terraform.State) error {

Choose a reason for hiding this comment

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

This should be used to ensure that resources setup by your acceptance tests are detroyed.


func TestAccAzureRMKeyVaultAccessPolicy_update(t *testing.T) {
ri := acctest.RandInt()
resourceName := "azurerm_key_vault.test"

Choose a reason for hiding this comment

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

Should reference your tests policy resource

)

func TestAccAzureRMKeyVaultAccessPolicy(t *testing.T) {
resourceName := "azurerm_key_vault.test"

Choose a reason for hiding this comment

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

Should reference your test policy resource

@day-jeff
Copy link
Contributor Author

Jeff, this is simple--your implementation is correct, this one is not. I will close this PR in favor of yours. I missed that the Go SDK has a function to update access policies, so I implemented a workaround. I reviewed and tested your code, and it looks great.

@day-jeff day-jeff closed this Apr 23, 2018
@ghost
Copy link

ghost commented Mar 31, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
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.

3 participants