Can you delete Microsoft.Web/certificates? - azure

I'm creating LetsEncrypt SSL certificates for each of our Web App Services, then binding it to the Web App and subsequently trying to delete the previous one from our Azure resources. I notice Remove-AzureRmWebAppSSLBinding has a -DeleteCertificate flag after unbinding an SSL certificate, but I'd prefer not to unbind/delete until a new certificate has been obtained an bound.
Is there any other way that I can remove the certificates from Azure?

I found that I can delete any resource by ID using Remove-AzureRmResource.
Remove-AzureRmResource -ResourceId $resourceId -Force
This solves my problem for now!

Related

Unable to update SSL cert while using multiple basic listener using WAFV2 Azure App Gateway

I am having trouble uploading a new SSL pfx certificate onto my WAF V2 application gateway. I currently have 3 basic wildcard listeners setup (*.contoso.com *.fabrikam.com and *.adatum.com for example) and I would like to update the certificate associated with *.contoso.com.
The problem with using the UI is that if I attempt to update and save the certificate on the listener I get an error message indicating "This Basic HTTP listener cannot use the same frontend port as an existing listener". I understand this is likely because using multiple basic listeners is still in preview and can only be setup via powershell or ARM templates. I originally setup the gateway via ARM templates.
I instead attempted to update the listener's certificate using powershell. I first uploaded the pfx cert to a key vault. I then created a user managed identity with azure role assignments for both the app gateway and the key vault. After, I ran the following powershell commands from inside the portal's CLI but got the resulting error message.
PS > Select-AzureRmSubscription -Scope CurrentUser -SubscriptionName "Pay-As-You-Go"
PS > $appgw = Get-AzApplicationGateway -ResourceGroupName "myresourcegroup" -Name "myappgateway"
PS > $secret = Get-AzKeyVaultSecret -VaultName "mykeyvault" -Name "contoso-cert"
PS > $secretId = $secret.Id
PS > set-AzApplicationGatewaySSLCertificate -Name "contoso-cert" -ApplicationGateway $appgw -KeyVaultSecretId $secretId
PS > Set-AzApplicationGateway -ApplicationGateway $appgw
Set-AzApplicationGateway: Application Gateway 'myappgateway' requires a 'UserAssigned' Identity with 'get' access policy to the referenced KeyVault. Please provide so by using top level 'Identity' property.
Why am I unable to update the certificate on the basic listener using powershell? Is there any alternative option I can try in order to set the certificate? Please help
Pretty sure I came across this same issue when looking at the Wildcard Listeners Preview in App Gateway.
I don't have a test environment configured in such a way that I can try this for you at the moment, but I believe the solution was to create a Multisite HTTPS listener (instead of basic) with an arbitrary FQDN, and using the same SSL cert as the one you want to update. Then use that listener to update the SSL cert (you could probably even update the cert at the same time as you create the listener).
Let us know how you get on!

PowerShell : binding existing certificate in resource group

Im trying to bind an exisiting certificate in the resource group in a custom domain.
New-AzWebAppSSLBinding -ResourceGroupName $webappname -WebAppName $webappname -Thumbprint "$newthumbprint" -Name "$customdomain"
When I Debug this the custom domain isn't found, But when I check the domain in microsoft azure under tls/ssl bindings, the domain is there with his old thumbprint.
When im using the original domain of the webapp (.azurewebsites.net) then it would say that there is a conflict because in the new certificate is that domain not registered and thats good because I dont want that.
Anyone know how I can change the thumbprint of customdomains in powershell instead of waste my time in microsoft azure application and doing it more then 100 times manually...
For the error, "custom domain isn't found" or "Hostname 'www.exmaple.com' does not exist", here are possible reasons:
You could check the certificate's subject name must match the domains used to access the Web App.
You should find the existing certificate under TLS/SSL settings---Private Key Certificates. When you run the PowerShell commands, ensure that you type the correct Hostname and matched Thumbprint.
The command is working well on my side.
In addition, If you update an SSL certificate from a local machine to the Azure web app, you can use this command.
New-AzWebAppSSLBinding -ResourceGroupName $webapprg -WebAppName $webappname -CertificateFilePath $PathToPfxFile -CertificatePassword $PlainTextPwd -Name $customdomain

Bulk/mass change SSL certificates on Azure app services (web apps)

I've a wildcard SSL that has expired, and I have the new cert (different authority) uploaded to Azure already..
..but I'd like to know if there's a way to bulk change all the sites using the old cert, over to the new cert. On normal IIS when you make a change for any one of your sites on the old cert, to the new cert, it asks you if you want to update other bindings that are using the old cert so that they also use the new cert. I've around 30 sites I need to move to the new cert and it's going to be quite a drag one by one
Is there an equivalent functionality on Azure? Powershell is acceptable if the portal.azure.com won't do it..
I've been using Azure CLI in Powershell for this. First build a CSV file or array with the values. It will need to contain:
- Web App Name
$Thumbprint
Then iterate through
$Thumbprint = "12bnhgikjbkj13kjbblahblah"
$WebApps = #("WebApp1","WebApp2","WebApp3") #OR
Foreach ($WebApp in $WebApps) {
az webapp config ssl bind --certificate-thumbprint $Thumbprint --ssl-type SNI --resource-group ResourceGroupName --name "$WebApp"
}
You can also do it with New-AzureRmWebAppSSLBinding from here. Also a guide here on how to do it.
I used the following code in Azure Cloud Shell to enumerate how many apps were using the old thumbprint and updated them to the new one. I found this easier than writing down each of the app service names.
You'll need to make sure you import your new certificate first.
az account set --subscription "My Application"
$webapp_ids=(az webapp list --query "[?hostNameSslStates.[thumbprint=='OLD_THUMBPRINT']].id" --output tsv)
az webapp config ssl bind --certificate-thumbprint "NEW_THUMBPRINT" --ssl-type SNI --ids $webapp_ids

Azure SSL certificate tag

I have uploaded an SSl certificate on the azure portal for my web app.
Is there a way to add key-value tag for the cert? From the documentation, I see tags only for resource-group etc but not for a particular cert.
If you are able to see the certificate in your resource group, just add tag as usual.
On my side, the certificate is hidden because it's managed by Azure. I can show it by clicking the checkbox on top of your resource group.
If after you click the certificate and there is no Tags bar on its panel, you can choose to use cloud shell to add tag. You can find the cloud shell on top right of your portal.
The first time you run it, you may need to create storage for the shell, just follow the steps azure provides. Then we can add tags. Use powershell script as an example, just two commands to achieve your goal.
$r = Get-AzureRmResource -ResourceName certificatename -ResourceGroupName resourcegroupname
Set-AzureRmResource -Tag #{ TagName="TagValue"} -ResourceId $r.ResourceId -Force
Things work on my side. Any further question, just ask.
Looking at the REST API documentation for Create or Update Certificate, looks like it is possible to assign tags to SSL Certificates. I believe this functionality is not exposed on the Portal. I looked up Azure Powershell Cmdlets as well and couldn't find anything there (it is entirely possible that I may have missed out something).
If you need to assign tags to SSL Certificate, you can always use REST API and invoke that API using either writing code or using a tool like Postman. Other thing you should look at is Azure SDK. In all likelihood, you will find some functionality there which will let you assign tags to a SSL certificate.

Add a certificate to an Azure WebApp and reference it in code

I have an web application on IIS. The asp.net application call external resources and need to send a certificate for authorization. I cannot use the certificate store on Azure in a Web App. How can I store a certificate in Azure and reference it when I make a external call?
In order to use certificated you first have to upload the certifcate to your webapp. You can do this to go to the setting of your webapp and goto custom domain and SSL. Here you can upload your certificate.
In order to be usable in your application Azure cannot use the certificate store but loads the certificates into memory. You can do this by adding WEBSITE_LOAD_CERTIFICATES with value * or you can do it via PowerShell via:
$appSettings = "WEBSITE_LOAD_CERTIFICATES" = "*"}
$w = Set-AzureWebsite $siteName -AppSettings $appSettings
More info can be found at https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/

Resources