英文:
App Settings - Azure App Service (Multiple environments)
问题
I am trying to set up connectivity from azure app service to azure sql db using managed identity (System assigned)
Here is the set up: Two azure app services one for app and one for api in one service plan. I have a SQL server in Azure with two azure sql db. The app services have their system assigned managed identity turned on. I have app settings for multiple environments in both the project (app and api).
appsettings.json appsetings.Development.json appsettings.Acceptance.json appsettings.Production.json
When I explored Kudu after deploying my app to app service from yaml pipeline I see all the app settings files are available.
The configuration -> application setting in Azure app service just has the app insight instrumentation key which I add (IaC) in template while provisioning app service in Azure. In this situation:
If all the app settings file are pushed (as seen in Kudu), which app setting will be read? appsettings.json or any other environment specific? As I understand it should be appsettings.json. Will the best way to handle the app settings for different environments would be to only have appsettings.json and appsettings.development.json in solution/repo and while provisioning azure app service (IaC template), parameter files for different environments can have the required settings (stored as secrets in key vault and read)? Or any other way is better, easy, and secure? I am not sure how can I make use of secrets manager for multiple environments.
英文:
I am trying to set up connectivity from azure app service to azure sql db using managed identity (System assigned)
Here is the set up: Two azure app services one for app and one for api in one service plan. I have a SQL server in Azure with two azure sql db. The app services have their system assigned managed identity turned on. I have app settings for multiple environments in both the project (app and api).
appsettings.json
appsetings.Development.json
appsettings.Acceptance.json
appsettings.Production.json
When I explored Kudu after deploying my app to app service from yaml pipeline I see all the app settings files are available.
The configuration ->application setting in Azure app service just has the app insight instrumentation key which I add (IaC) in template while provisioning app service in Azure. In this situation:
If all the app settings file are pushed (as seen in Kudu), which app setting will be read? appsettings.json or any other environment specific? As I understand it should be appsettings.json. Will the best way to handle the app settings for different environments would be to only have appsettings.json and appsettings.development.json in solution/repo and while provisioning azure app service (IaC template), parameter files for different environments can have the required settings (stored as secrets in key vault and read)? Or any other way is better, easy, and secure? I am not sure how can I make use of secrets manager for multiple environment.
答案1
得分: 1
如我所提到的,应用程序设置的读取将基于环境。
- 如果我们希望Azure应用程序选择特定的配置文件,那么我们需要使用特定值(
Development
/Production
/Acceptance
)设置键ASPNETCORE_ENVIRONMENT
。
>当我在将我的应用程序从YAML管道部署到应用服务后,在Kudu中探索时,我看到所有的应用程序设置文件都可用。
是的,当我们发布应用程序
时,所有可用的配置文件都会部署到Azure应用服务
中。
你也可以在我的应用程序中看到同样的情况。
KUDU控制台:
-
正如你所说,你是从
yaml
管道部署你的应用服务,那么你在yaml
文件中指定的配置将会被使用。 -
即使你在KUDU控制台中看到所有文件,实际上只有在
yaml
文件中指定的配置将会被应用程序使用。 -
据我所知,仅在
yaml
文件中转换的应用程序设置才会被读取。 -
你可以在
Pipeline
的Azure应用服务部署
任务中找到这个选项。
- 你可以在
Azure应用服务
的配置
中看到yaml
的配置=>应用程序设置
。
更多关于XML转换的信息,请参考MSDoc。
>csharp >处理不同环境的应用程序设置的最佳方法是只在解决方案/仓库中保留appsettings.json和appsettings.development.json,然后在配置Azure应用程序服务(IaC模板)时,不同环境的参数文件可以包含所需的设置(存储为密钥保管库中的秘密并进行读取)? >
要使用Azure密钥保管库
来存储密钥,我们在Azure管道任务中有一个选项。
感谢@rahulpnath清晰解释了不同环境中配置文件的工作原理
。
英文:
As I have mentioned, reading of App settings will be based on the Environment.
- If we want the Azure App to pick any particular configuration file, then we need to set the key
ASPNETCORE_ENVIRONMENT
with the specific value (Development
/Production
/Acceptance
).
>When I explored Kudu after deploying my app to app service from yaml pipeline I see all the app settings files are available.
Yes, when we publish the Application
, all the available configuration files are deployed to Azure App Service
.
You can see the same for my application too.
KUDU Console:
-
As you said you are deploying your app service from
yaml
pipeline, then the configurations which you have specified in theyaml
file only will be used. -
Even though you see all the files in the KUDU Console, the configurations which are only specified in the
yaml
file be used in the App. -
AFAIK, the application setting which are only transformed in the
yaml
file are only read. -
You can find the option in
Azure App Service deploy
Task in thePipeline
.
- You can see the configurations of
yaml
in theAzure App Service
=>Configuration
=>Application settings
.
Refer MSDoc for more information on XML Transformations.
>csharp
>Will the best way to handle the app settings for different environments would be to only have appsettings.json and appsettings.development.json in solution/repo and while provisioning azure app service (IaC template), parameter files for different environments can have the required settings (stored as secrets in key vault and read)?
>
To Use Azure Key Vault
for storing secrets we have an option in Aure Pipeline Task.
Thanks @rahulpnath for the clear explanation on how configuration file works in different environment
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论