Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bug: metadata functionality has broken kv_secret_v2 resource #1719

Closed
lrstanley opened this issue Jan 9, 2023 · 0 comments · Fixed by #1722
Closed

bug: metadata functionality has broken kv_secret_v2 resource #1719

lrstanley opened this issue Jan 9, 2023 · 0 comments · Fixed by #1722
Assignees
Milestone

Comments

@lrstanley
Copy link

lrstanley commented Jan 9, 2023

Noticing an issue with the kv_secret_v2 resource where API calls to Vault are being mangled due to the recently added metadata functionality.

Versions

  • Terraform: 1.3.1
  • Provider: v3.12.0

Affected Resource(s)

  • kv_secret_v2

Terraform Configuration Files

resource "vault_kv_secret_v2" "workspace_id" {
  for_each = local.workspace_ids
  provider = vault.infra-prod
  mount    = "cloud-metadata"
  name     = "aws/account/${each.key}/bootstrap-workspace-id"

  data_json = jsonencode({
    value       = each.value
    description = "TRUNCATED"
    }
  )
}

Debug Output

I don't have the debug output handy, but this should be sufficient as well as the below explanation:

Error: Error making API request. URL: GET https://vault.truncated.com/v1/cloud-metametadata/data/aws/account/TRUNCATED/bootstrap-workspace-id Code: 403. Errors: * 1 error occurred: * permission denied
with vault_kv_secret_v2.workspace_id["TRUNCATED"]
on vault.tf line 1, in resource "vault_kv_secret_v2" "workspace_id":
resource "vault_kv_secret_v2" "workspace_id" {

Expected Behavior

Resource to write/update the values correctly. This used to work, and the only change is the provider version.

Actual Behavior

It looks as though the API url that is getting generated has been mangled and is not correctly using the values that we have input.

Steps to Reproduce

Use a secret engine or secret path that includes the word data.

Important Factoids

It looks as though this bug was introduced in PR #1687 (see this line), where the provider attempts to generate the metadata URL by simply doing a string replacement of the data-path that was generated for reads. The problem with this is that the path can contain "data" (or "/data", "data/", whichever it's matching), and this is what looks to mangle the generated URL.

The above logic should be changed to explicitly generate the metadata URL rather than relying on the previously generated one (for data).

References

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

Successfully merging a pull request may close this issue.

2 participants