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

Application Gateway support for Keyvault SSL certificate #3935

Closed
msghaleb opened this issue Jul 26, 2019 · 15 comments · Fixed by #4366
Closed

Application Gateway support for Keyvault SSL certificate #3935

msghaleb opened this issue Jul 26, 2019 · 15 comments · Fixed by #4366

Comments

@msghaleb
Copy link

msghaleb commented Jul 26, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Looking to implement keyvault certificates on HTTPS listener for application gateway. Here are the powershell docs I found on the subject: https://docs.microsoft.com/bs-latn-ba/azure/application-gateway/configure-keyvault-ps

we'd need to update the ssl_certificate section to allow the "ID" of the vault certificate also.

New or Affected Resource(s)

resource "azurerm_application_gateway" "AppGateway"

Potential Terraform Configuration

resource "azurerm_application_gateway" "AppGateway" {
  name                = var.name
  resource_group_name = data.azurerm_resource_group.ResourceGroup.name
  location            = data.azurerm_resource_group.ResourceGroup.location

  ssl_certificate {
    name     = var.ssl_certificate_name
    data     = var.ssl_certificate_file
    password = var.ssl_certificate_password
  }
}

References

related but not a replica:
#3640

@Sudharma
Copy link

Sudharma commented Jul 26, 2019

I need exactly the same feature. Powershell has this script below. We need the same implementation extended for tf

$sslCert01 = New-AzApplicationGatewaySslCertificate -Name "SSLCert1" -KeyVaultSecretId $secretId

@egorchabala
Copy link

egorchabala commented Aug 23, 2019

We use the following as an undocumented workaround:

  1. Upload SSL certificate to Azure Vault as a secret
az keyvault secret set --name "certificate" --vault-name "vault_name" --file "certificate.pfx" --encoding base64
  1. Read the secret using Terraform data resource
data "azurerm_key_vault_secret" "certificate" {
    name         = "certificate"
    key_vault_id = var.key_vault_id
}

resource "azurerm_application_gateway" "example" {
...
    ssl_certificate {
        name     = certificate
        data       = data.azurerm_key_vault_secret.certificate.value
        password = var.password
    }
...
}
  1. Profit

@nexxai
Copy link
Contributor

nexxai commented Sep 4, 2019

Azure/azure-cli#10119 has just been merged. Can someone with a little more skill than I (@jeffreyCline @mbfrahry @tombuildsstuff etc) look at how difficult it would be to add it as a resource?

@AlexMabry
Copy link
Contributor

I need this too.

I will try to make the necessary updates, although I will need help contributing for the first time.

@AlexMabry
Copy link
Contributor

h/t to @katbyte for stubbing out most of the key_vault_secret_id already

@Ruankr
Copy link

Ruankr commented Jan 28, 2020

We use the following as an undocumented workaround:

  1. Upload SSL certificate to Azure Vault as a secret
az keyvault secret set --name "certificate" --vault-name "vault_name" --file "certificate.pfx" --encoding base64
  1. Read the secret using Terraform data resource
data "azurerm_key_vault_secret" "certificate" {
    name         = "certificate"
    key_vault_id = var.key_vault_id
}

resource "azurerm_application_gateway" "example" {
...
    ssl_certificate {
        name     = certificate
        data       = data.azurerm_key_vault_secret.certificate.value
        password = var.password
    }
...
}
  1. Profit

Although this works it does not automatically poll for certificate renewals when done this way. Looking at ARM the difference below is observed:

Above method:

            "sslCertificates": [
                {
                    "name": "CertifcateName",
                    "properties": {}
                }

Proper Keyvault integration:

	"sslCertificates": [
                {
                    "name": "CertificateName",
                    "properties": {
                        "keyVaultSecretId": "https://vaultname.vault.azure.net/secrets/certificatename/certficatethumbprint"
                    }
                }
            ],

So it seems we need a change to allow the correct parameter to be used, ie. properties block with keyVaultSecretId as a property.

Noticed it's been requested already and seems on the 2.0.0 roadmap: #4366

@JohnDelisle
Copy link
Contributor

I'm very interested in this functionality too. Proper KV integration is important for centralized certificate lifecycle management.

If you need a tester, let me know.

@JohnDelisle
Copy link
Contributor

@egorchabala Did you happen to find a way to retrieve the public key required for App Gateway's authentication_certificate? For App Gateway v2, we also need to add the root certificate's public key. If you happen to have a working approach for this I'd love to see it!

@egorchabala
Copy link

@JohnDelisle what's the need of adding root certificate's public key? For backend SSL encryption? If yes, this is naively supported in Terrafrom resource

@JohnDelisle
Copy link
Contributor

@egorchabala yes, that's correct, if I understand the requirement correctly this is needed for root CA and the certificate on the backend pool too. I've since discovered that because my backend pool certs are issued by a well-known CA that I did not need to include either for App Gw to work.. it was happy without this.

If I wasn't using a well-known CA, I imagine I could have put the root CA (and intermediary signing certs') public keys into a Key Vault secret and retrieve that as data. However, in addition to the public key for CA and intermediary certs, I believe in some cases you need to provide the public key of the cert used on their backend pool too. In my case, the backend pool cert is the same as my front-end. What I was wondering with my question above was if there's an easy way (in TF) to derive the public key from the private key that's stored in the KV, rather than needing to maintain both the complete cert and the public key of that cert in KV as two items.

I see there are some TF certificate manipulation functions, but I'm not clear as to which if any would work for this situation and produce a public key compatible with App Gw's expectations.

@egorchabala
Copy link

@JohnDelisle Unfortunately, I'm not aware about this. In general, you either have two different certificates (trusted SSL cert for external publishing and self-signed SSL cert for backend pool) or have no need to specify certificate at all (in case backend SSL use trusted SSL cert)

@katbyte katbyte added this to the v2.2.0 milestone Mar 17, 2020
katbyte pushed a commit that referenced this issue Mar 18, 2020
This is my first time contributing, so I may have missed something.

Implements key vault certificates on HTTPS listener for application gateway. See Issue #3935

According to this Microsoft issue (MicrosoftDocs/azure-docs#34382), the key vault must be set for safe delete mode to work, so I also included that in this PR.
@ghost
Copy link

ghost commented Mar 19, 2020

This has been released in version 2.2.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.2.0"
}
# ... other configuration ...

@zerowebcorp
Copy link

How can we use this version? I tried to change the version in the provider to " version = "~> 2.2.0"" but it didn't work.

@nycjay01
Copy link

We use the following as an undocumented workaround:

  1. Upload SSL certificate to Azure Vault as a secret
az keyvault secret set --name "certificate" --vault-name "vault_name" --file "certificate.pfx" --encoding base64
  1. Read the secret using Terraform data resource
data "azurerm_key_vault_secret" "certificate" {
    name         = "certificate"
    key_vault_id = var.key_vault_id
}

resource "azurerm_application_gateway" "example" {
...
    ssl_certificate {
        name     = certificate
        data       = data.azurerm_key_vault_secret.certificate.value
        password = var.password
    }
...
}
  1. Profit

Hi there,

I tried this out and I am able to upload the cert as above. But I keep getting the error message below. Any pointers would be greatly appreciated.

Message="Password` specified for certificate /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/shared-rg/providers/Microsoft.Network/applicationGateways/aks01-appgw/sslCertificates/coreapicert is incorrect." Details=[]

Facts:
Cert is a 3rd part generated cert
I am on TF Enterprise
I have the password from the 3rd Party
Key Vault is in a separate resource group
I have full admin on subscription

@ghost
Copy link

ghost commented Apr 18, 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 Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
10 participants