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

CLI auth does not work with Key Vaults secrets #656

Closed
mattops opened this issue Jan 2, 2018 · 15 comments · Fixed by #1544
Closed

CLI auth does not work with Key Vaults secrets #656

mattops opened this issue Jan 2, 2018 · 15 comments · Fixed by #1544
Assignees
Milestone

Comments

@mattops
Copy link

mattops commented Jan 2, 2018

Whilst trying to manage key vault secrets, using CLI auth, getting:

* module.my_mod_instance.azurerm_key_vault_secret.my_secret_name: azurerm_key_vault_secret.my_secret_name: Error making Read request on Azure KeyVault Secret my_secret_name: keyvault.ManagementClient#GetSecret: Failure responding to request: StatusCode=401 -- Original Error: autorest/azure: error response cannot be parsed: "" error: EOF

getting this in the DEBUG logs:

e.g.
TF_LOG=DEBUG terraform apply

2018-01-02T14:11:47.804Z [DEBUG] plugin.terraform-provider-azurerm_v1.0.0_x4: 2018/01/02 14:11:47 [DEBUG] Resource "https://vault.azure.net" isn't a management domain

This is related to this line of code:

https://github.com/terraform-providers/terraform-provider-azurerm/blob/1005762a37e67f93aa340b40d1682f70523da61a/azurerm/helpers/authentication/access_token.go#L37

When managing azure key vaults, Azure needs the correct bearer token for the specific "Azure resource endpoints" - in this case it should be "https://vault.azure.net".

When managing secrets via the az cli - this is done transparently, but is effectively similar to:

az account get-access-token --resource https://vault.azure.net

This token then then permits access.

@mattops
Copy link
Author

mattops commented Jan 17, 2018

@tombuildsstuff any idea when this will get fixed?

@steve-hawkins
Copy link
Contributor

this is not limited to just secrets in a key vault

I am also hitting this same error when managing certificates in a key vault

@kcighon
Copy link

kcighon commented Feb 23, 2018

is there currently a workaround?

@hafizullah
Copy link

just got slapped by this issue :(

@achandmsft achandmsft added this to the 1.4.0 milestone Mar 9, 2018
@anoff
Copy link

anoff commented Apr 5, 2018

Ran into the same issue while debugging locally. My workaround was using a service principal locally instead of az login

provider "azurerm" {
  # following ENV need to exist: ARM_SUBSCRIPTION_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET, ARM_TENANT_ID
}

One other thing I missed is creating an access policy for the SP within the keyvault otherwise it won't be able to manage secrets. Seems to be common KeyVault behavior but I initially thought any IAM contributor can also manage secrets 🙄 If you deploy the keyvault itself via TF make sure the access policy is set automatically.

@hafizullah
Copy link

Thanks @anoff 👍 will give your workaround a try

@tombuildsstuff tombuildsstuff self-assigned this Apr 12, 2018
@tombuildsstuff tombuildsstuff modified the milestones: 1.4.0, Soon Apr 12, 2018
@andrey-moor
Copy link
Contributor

Same issue with the keys, any update on this?

@andrey-moor
Copy link
Contributor

@tombuildsstuff is there any reason to make this check only for management domain?

if !strings.Contains(accessToken.Resource, "management") {
  log.Printf("[DEBUG] Resource %q isn't a management domain", accessToken.Resource)
  continue
}

If that's important does it make sense to create a list of allowed domains for now and the future platform features?

@DonEstefan
Copy link

Please keep in mind that there are multiple vault domains (like *.vault.microsoftazure.de for azure germany).

@tombuildsstuff
Copy link
Contributor

@DonEstefan indeed - rather than hard-coding domain name suffixes we use the values from the Azure Environment (which contains, amongst other things - the API Base URI's & Domain Suffixes).

To give an update here: we're intending on getting to this - but I can't give an timeframe for fixing this at this point.

I took a quick look into this recently and the complexity comes with testing this (since CloudShell, the Azure CLI v1 [Node.JS] and the Azure CLI v2 [Python]) all return the same configuration file with a different schema, such that we need to manually test this in each environment (since the format can [and has in the past] changed). In the interim the workaround is to use a Service Principal, which whilst I realise isn't ideal - does provide a workaround for this issue for the moment.

Regarding prioritising this - if you'd like to see this implemented, we'd really appreciate a 👍 on the first post here - which we use to influence what we're working on (we tend to sort issues by the most 👍 when determining what should be prioritised).

Thanks.

@MarkWme
Copy link

MarkWme commented Jun 20, 2018

I hit this issue today whilst working with data.azurerm_key_vault_secret whilst developing a terraform deployment locally on my Mac (Azure CLI 2.0.37, Terraform 0.11.7, azurerm 1.7.0) I found that using the Cloud Shell it worked fine, so just adding that as another potential workaround for folks hitting this issue.

tombuildsstuff added a commit that referenced this issue Jul 11, 2018
This fix was originally contributed by @sophos-jeff in #1349 but has been split-out

This allows Azure CLI auth to be used to accessing Key Vaults, which fixes #656.
@tombuildsstuff tombuildsstuff modified the milestones: Soon, 1.9.0 Jul 11, 2018
@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Jul 11, 2018

👋 hey all

Just to let you know that @sophos-jeff has contributed a fix for this in #1349 which fixes this issue. So that we can ship this in the next release I've split this out into PR #1544, (I hope you don't mind @sophos-jeff).

Thanks!

@marrik96
Copy link

Just ran into this issue. Looks like a fix was pushed? I'm on terraform v0.11.7 with Azure provider v1.8.0. Not clear if issues is fixed or if I'm doing something wrong. Working with secrets using "azurerm_key_vault_secret"

Thanks.

tombuildsstuff added a commit that referenced this issue Jul 16, 2018
#1544)

This fix was originally contributed by @sophos-jeff in #1349 but has been split-out

This allows Azure CLI auth to be used to accessing Key Vaults, which fixes #656.
@tombuildsstuff
Copy link
Contributor

tombuildsstuff commented Jul 21, 2018

hi @mattops @steve-hawkins @kcighon @hafizullah @anoff @marrik96 @MarkWme @DonEstefan @andrey-moor

Just to let you know that is now available in [v1.10 of the AzureRM Provider(https://github.com/terraform-providers/terraform-provider-azurerm/blob/v1.10.0/CHANGELOG.md#1100-july-21-2018) - which you can update to this version by specifying it in the Provider block, like so:

provider "azurerm" {
  version = "=1.10.0"
}

Thanks again @sophos-jeff :)

Thanks!

@ghost
Copy link

ghost commented Mar 30, 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 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet