Azure Key Vault offers secure storage for sensitive information like passwords, secrets etc. If you host your PHPRunner or ASPRunner.NET application on Azure, it will makes sense to store your connection strings in Key Vault. In this article we’ll show you how this can be done.
Creating Key Vault in Azure
1. Create an application in Azure. Write down tenantId, clientId and clientSecret values.
2. Logon to Azure and create a subscription. You need to specify subscription name and select a billing account.
More info:
https://learn.microsoft.com/ru-ru/azure/cost-management-billing/manage/create-subscription
3. Go back to portal home and proceed to Key Vaults. Click ‘Create’. Select a subscription, select a Resource group ( or create a new one ). Enter Key Vault name.
4. Now it is the time to assign access permissions. Under the Key Vault you just created proceed to ‘Access control (IAM)’. Add -> Add Role assigment, select ‘Key Vault Certificates Officer’ using search option, click ‘Next’. Select ‘User, group, or service principal’
Click ‘Select members’ search for your application name and select it. . в поисковой строке справа найти свое приложение (не пользолвателя). Next, Review + assign.
Permissions may take a bit of time to be applied but in our situation it worked right away.
5. Create a secret. The secret is the actual object that stores the sensitive information, database password in our case. Select your Key Vault and under Objects -> Secrets -> Generate/Import enter the name of the secret ( “pass” in our case ) and its value.
Now we are ready to use this in our code.
Using Key Vault in PHPRunner
1. Under Style Editor -> Custom Files add a new file named keyvault.php. Paste the code below and use your own values of tenantId, clientId and clientSecret.
2. An example of using Key Vault in your application. We will create a new Server Database Connection and will retrieve database password from Key Vault. In this example we use MySQL database.
Using Key Vault in ASPRunner.NET
1. Under Style Editor -> Custom Files add a new file named keyvault.cs. Paste the code below and use your own values of tenantId, clientId and clientSecret.
2. In BeforeConnect event use the following code: