I am trying to eliminate using connection strings in my azure infra that is created using terraform. I am planning to assign specific rbac roles to resources like web app, function app etc to make them connect to Keyvault, storage account, cosmos db etc. How to do the same for Application insights? if i grant Application Insights Component Contributor to the managed identity of the app service, how do i point it to which application insights it should connect to? is using APPINSIGHTS_INSTRUMENTATIONKEY
or connection string mandatory here? or can i pass this somewhere azurerm_application_insights.example.app_id
?
Thanks in advance.
2
Answers
You can get the System Managed Identity a few different ways. For your use case, when the Web App is deployed, the principal ID will be returned as output.
If this isn’t suitable, you can get it with PowerShell or Azure CLI.
CLI:
However. To send logs and telemetry data to App Insights, the instrumentation key must be provided in the connection string. The best workaround for this would be to use Azure KeyVault.
Bearing in mind that this adds a bit of complexity and more security considerations to the solution, and the fact that the instrumentation key isn’t as sensitive as – for example – a database connection string, you may want to reevaluate whether this is really necessary. If you do want to go down this route, read on.
GET
permission on secrets[email protected](SecretUri=https://MyKeyVault.vault.azure.net/secrets/InstrumentationKey/...
When the App Service runtime sees this in the config, it automatically fetches the secret from KeyVault using the identity of the app.
The right way of securely ingesting data into Application Insights consists of a few steps:
Monitoring Metrics Publisher
role to target Application Insights resource