I have used this documentation to setup continuous deployment on Azure functions with git-hub. Now I have successfully setup git-hub repository in Azure function for continuous deployment.
I am able to see APP settings in local.settings.json file. But I want to know how to configure Connection strings (SQL Connection strings) in continuous deployment.
You want to keep your sensitive data out of your source code repository. That being said, app.settings.json of any kind is not an option.
You have several options there. Two mostly used are either Azure Vault or Azure AppSettings where you can set key/value pairs which are then available to your app either through settings (merged with other settings) or through environment variables.
I use second approach with env variables access to AppSettings.
This link might help:
https://www.hanselman.com/blog/BestPracticesForPrivateConfigDataAndConnectionStringsInConfigurationInASPNETAndAzure.aspx
The documentation that you've referred to is sort of a "quick and easy" continuous deployment option for Functions that gets you up and running quickly. It's not ideal for a production environment though, as you've discovered there is no way to parameterize your app settings. In order to build a proper build/release pipeline you'll need to move away from the direct Git integration and use something like VSTS which you can configure properly against multiple environments including the ability to set AppSettings and ConnectionStrings properly. Based on the approach you've taken currently, your only option is to go into the Azure Portal and manually configure AppSetting and ConnectionStrings in your function app directly.
This blog post covers a lot on the topic and shows one approach for accomplishing what you're after:
https://blogs.msdn.microsoft.com/visualstudioalmrangers/2017/10/04/azure-function-ci-cd-devops-pipeline/?utm_source=vs_developer_news&utm_medium=referral
Configuring a complete CI/CD pipeline is a bit involved (as you'll be able to see from the link) so there's no easy answer that can fit right into a StackOverflow post. I highly recommend that you read through that and do some more research on Google around the VSTS and Functions integrations.
Related
We have 4 Azure environments for the stages of our development process; Dev, QA, UAT, Production. As you would expect, settings and options need to differ between environments, e.g., "apiurl": "http://dev-api.ourdomain.com" in dev needs to become "apiurl": "https://uat-api.ourdomain.com" for UAT.
At the moment we manually set these in the App Service Configuration page in the Azure Portal. There are problems with this method we are trying to overcome:
It cannot be timed to happen with releases, it has to be manually done
It's prone to human error
Previous values are lost
We cannot easily compare values between environments
We cannot easily see which settings are no longer used
We would like to setup an appsettings.json with environment transforms for the differences. This addresses the last 3 issues as it will be stored in our code source control (if not secret), but this is useless if we cannot deploy that same file to set the Azure configuration. Pipeline steps might solve issues 1 and 2, but reintroduces issues 3 and 5.
Surely there is a simple way to do this that I am missing?
I'd recommend creating the appsettings.json file in your source code, and use a pipeline to deploy the app service with it included; those settings will take effect. The pipeline can either adjust the file contents immediately before deployment, or upload the file as-is but also deploy app settings to override the file's contents.
This fits your requirements because:
using a pipeline for automation gives you timing control (req 1) and reduces the risk of human error (req 2)
keeping some of the settings in source control gives you a (partial) history of previous values (req 3)
some of the settings may be the same across all environments; those can be left untouched in the appsettings.json, but those which differ can be overridden by the pipeline and adjusted correctly
you could override settings by using a script task such as Powershell or a FileTransform task to actually change the appsettings.json
or, you could override settings by automated configuration of the azure app service configuration, using the Azure CLI or an ARM Template for example.
For comparison of settings across the different environments (req 5), I'd recommend:
organising your pipeline variables into different groups by environment, so the pipeline code makes it clear what the differences will be when deployed
using azure cli or powershell commands to interrogate the actual deployed app services.
I am trying to make my deployments more safe by having credentials information in a separate file and not pushing it to GitHub. The problem is that I have synced the repo with Azure enabling continuous development.
Because the config file is ignored, when the Azure App seeks for the code from GitHub, it cannot find the config file and therefore not being able to read the information.
How can I overcome this? Thanks.
I'll recommend you to look into Azure DevOps. (Free for up to 5 users)
It will give you the opportunity to manage your deployments using pipelines. You don't need to host your code in the Azure DevOps Git. You are free to keep using GitHub for source control.
I'm not a big fan of the built-in "Deployment Center" inside the Azure Services like an "App Service". You will be very limited in customization compared to a Pipeline.
For keeping secrets secure in deployment. You can make use of Key Vault References.
https://learn.microsoft.com/en-us/azure/app-service/app-service-key-vault-references
I'm working on an asp.net core project and I'm trying to figure out how to keep my source and my pipelines 100% secret free.
I've got a VM running the azure agent and an azure dev ops pipelines for build and release.
If i delete the site on the VM, the release pipeline will auto-magically recreate it for me and deploy the latest build.
Super cool.
Now I read up on best practices for configuring a .Net core app and I found this article: https://www.humankode.com/asp-net-core/asp-net-core-configuration-best-practices-for-keeping-secrets-out-of-source-control
So its a bad idea to keep secrets in code, that makes perfect sense.
But if i apply the same security principals to Yaml, then surely I shouldn't place secrets in my pipelines either.
But I need the pipelines to be able to just recreate the site from scratch and it should just work. Somehow the site needs to know where its default sql connection is, or it needs to have a key to the azure app config service. I shouldn't have to log onto the VM and create an appsettings.json manually after every release!
So whatever the site needs to operate needs to be included in the pipeline, therefore some artifact, or included in the code.
I've googled for days, but I can't seem to find any info on how to fully automate this.
I've considered creating a custom configuration provider that reads from the actual VM registry, but that feels wrong too.
I basically need a config option that is NOT hosted in the site itself. So i set it up once on the VM and never again.
The approach that Lex Li lists in the comments is the Microsoft recommended way of securing "secrets" in pipelines.
Ben Smith's answer in my opinion is just as good, maybe slightly less secure.
I use this approach in our organization. All of our release pipelines do the final configuration transformation with the appropriate settings based on the environment they are being deployed to.
i.e db connections are transformed at the dev, test and UAT and production deployment stages.
I keep the relevant secrets in the pipeline variables as protected secrets. I do this for 2 reasons:
Only a select number of trusted personnel have access to the release pipeline definitions.
Even if someone does have access to those definitions - you cannot see a secured variable. Even you you "undo the padlock" on the variable tab - you cannot see what the setting is.
Our actual secrets are then stored in our enterprise secret vault.
Using the Azure Key Vault is definitely a good approach. However we already have a centralized place to keep our stuff; I don't want it in 3 spots.
I would be remiss to not include Variable Groups as part of the pipeline process. Same concept as the build / release variables - the difference is you can now share them in one spot.
These are all opinions of course. This is just one way of doing this; which I feel is a pretty good balance of security and flexibility.
In addition to the suggestions in your questions comments, you can also store secrets in the pipeline "Variables" section.
In here you can add variables and then mark them as secret by selecting "Keep this value secret". Once you've saved a secret its value is then obfuscated i.e. you can make use of it but you can no long see its original value within Azure Devops (which admittedly can be rather frustrating if you want to revisit the variable to check it!).
You can then reference the secret variable in your pipeline YAML using the syntax:
$(variable-name)
So this approach keeps secrets safe within Azure Devops until they need to be resolved by the pipeline YAML script.
I have Azure functions with configs (database connection strings, active directory, etc) set up for dev and live environments, right now I have everything in a class and I comment in/out the bits I'm using or not using.
Is there a way to upload a json file with the azure functions that will guide its config?
You mention "upload a json file" so I'm assuming that you're referring to some sort of release management activity. My suggestion is to simply use the built in AppSettings. Your use case is essentially what they are built for. Generally speaking if you store your settings within the appsettings of a function app and you have separate environments for your functions (dev & live) then you don't need to manage a separate json configuration file. The environment owns the configuration and your code will get the settings from the current environment.
If you have a more complex deployment and configuration management scenario I would consider using a release management tool such as VSTS to manage those configuration settings as part of the release pipeline so each environment has the correct settings at deployment time. Most CI\CD tools have functionality to update json configuration and\or update Azure App configuration directly.
Yes. You need to add connection strings as Application Settings. Azure Functions Core Tools uses local.settings.json file to read your connection strings when running locally and these settings are not pushed to Azure when published.
I am trying to setup essentially a Development, Staging and Production cloud service. So far I have setup 2 cloud services:
MyApp - which is what I am hoping to have be the staging and production since they have the same connection string and should be identical and the ability to quickly swap VIP is a nice feature.
MyAppDev - I want this to point to our development database.
I also want to do the continuous build integration from tfspreview to azure. This is working great except for making the connection string unique.
So far I have setup the cloud services and have it doing continuous builds. I have also set my connection string in web.config and web.production.config. In addition I have setup publishing profiles (.azurePubxml) files and set them to be the Alternative Publish Profile in the build definition process section. These publish profiles specify which config to use (or at least that is what I thought). It seems to pick up the settings for the publish profile because I have RDP enabled and such with different passwords.
So how can I make the build controller use the "Production" & "Debug" build configurations to pickup the web.config transformations?
Hope that makes sense.
EDIT:
I only have Solution to build as seen below:
When defining your build definition, in the "Process" section under item 1. "Items to Build" you are given the opportunity of defining which configuration to Build. In here, type the name of the configuration that matches your .config definition to build that version.
EDIT: This is a little late, but this is how I got the alternate configuration to build along with the correct connection strings. I set the MSBuild Argument for configuration manually and my build correctly changed the connection strings on deployment to Azure.
Just set your downloaded Azure publishing profile in section 6. "Web Deploy Publishing Profile". It's not necessary to use different web.config files Connection String will be rewritten on publish build runtime.