Advertise with Googlier.com  Steve Spencer's Blog - Azure Blogging on Azure Stuff http://blogs.recneps.net/ http://www.rssboard.org/rss-specification BlogEngine.NET 2.9.1.0 en-US http://blogs.recneps.net/opml.axd http://www.dotnetblogengine.net/syndication.axd Steve Spencer Steve Spencer's Blog 0.000000 0.000000 Adding Security Policies To Azure API Management <p>The Azure API Management service allows you to publish your APIs both internally and externally and to control who and what can access them. Out of the box you will get a standard API key for each of you users who sign up to the API, but this is often not enough meet the security requirements for you or your partners. API Management allows you to add a more fine grained security model you each of your APIs and this can be done using the policy feature. Policies are used for more than just security and there are numerous policies that allow you to change the behaviour of your API through configuration. Documentation for the types of policies can be found <a href="https://docs.microsoft.com/en-gb/azure/api-management/api-management-policies">here</a>. Sample policy examples can be found <a href="https://docs.microsoft.com/en-gb/azure/api-management/policy-samples">here</a>.</p> <p>Two policies that I am going to discuss here will allow you to restrict access to your API through IP Whitelisting and through validating JWT claims. I will also discuss how you can put different controls onto your API for different partners.</p> <p>Policies can be set at different levels and the documentation will highlight the areas where they are applicable. For security policies I am going to talk about protecting at the API level and at the product level. Adding a policy at the API level will be applicable to all subscribers to the API whereas adding the policy at the product level will be applicable to all subscribers to the product. A product can contain multiple APIs and and API can be in multiple products. So we can add in protection at either level depending upon what your exact requirements are. The policies are the same but their impact will depend upon where they are applied.</p> <p>&nbsp;</p> <p>Lets start with API level policies. To add or edit policies then you need to navigate to your API in the <a href="https://portal.azure.com/">Azure Management portal</a>. Then click on the API option, then click on the API you wish to protect</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_65.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_65.png" width="996" height="442"></a></p> <p>The easiest way to add a policy is to click the Add Policy link in the inbound section. </p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_66.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_66.png" width="557" height="625"></a></p> <p>Click Filter IP Addresses and Add IP Filter</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_67.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_67.png" width="561" height="410"></a></p> <p>This form allows you to add ranges or single IP addresses to both allow or deny.When you have finished click Save.</p> <p>You will now see the policy in the policy editor view. If you are happier to add this in manually or want to copy this and version control the config then you can access this via the Code Editor menu on the Inbound processing policies box</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_68.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_68.png" width="568" height="347"></a></p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_69.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_69.png" width="523" height="494"></a></p> <p>Appling this policy on the API means that only IP addresses within this range can access this specific API and can be useful to ensure that this specific API is blocked from being accessed regardless of the product has been subscribed to. Its also useful if you want to block access from specific IP addresses. However, you may have different partners who have different security arrangements or that you want to give different permissions to . To allow for this you will need to add the policy at the product level.</p> <p>To edit the policy at the product level, click Products, pick the product you want to secure.</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_70.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_70.png" width="946" height="315"></a></p> <p>In this example I have a new More Secure API that I’ve created and there’s an access control section which allows you to pick the users who have access to this API</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_71.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_71.png" width="948" height="268"></a></p> <p>So I’ve immediately blocked access to this API to guest users and we can add user authentication to&nbsp; the API if we want, such as OAuth 2.0 and OpenID connect. </p> <p>However, this post is talking about adding security policies and if we want to allow only specific IP addresses to access this API we can edit the policy at the Product level. To access the policy definition click Policies</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_72.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_72.png" width="950" height="469"></a></p> <p>You’ll notice that this is just the editor view and the easiest way is to add the policy at the API level using the wizard and copy the config to here. Products are a mechanism to allow you to group and protect APIs which means that from a management point of view you could create a product for each of your partners making it easier to maintain the security details for each and make it easier to disable access and remove only the security policies that apply to the specific partner. Managing this at the API level means that you will end up with a large number of security policies relating to a large number of partners making it difficult to manage. Security polices at the Product level are more important when you want to do some specific protection like checking claims in a signed JWT. The Product level policy allows you to have different signing keys for each product meaning that you can have different signing keys for each of your partners (assuming one product per partner).</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_73.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_73.png" width="954" height="340"></a></p> <p>This policy requires a JWT signed with the key eW91ci0yNTYtYml0LXNlY3JldA== and that also has the claim admin=true. If there is an error then 401 is returned with the message “You have failed the security checks please contact your administrator”</p> <p>To summarise, we can add policies at both API and product level. Product level polices allow us to create a new product for each of our partners and then add specific security policies to the product tailored to our specific partners needs. The product level policy makes it easier to manage the security policies at a partner level but we can allso add global security policies at the API level such as blocking access from certain IP address ranges. Policies can do a lot more than security so check out the links at the start of the post for further information</p> http://blogs.recneps.net/post/Adding-Security-Policies-To-Azure-API-Management http://blogs.recneps.net/post/Adding-Security-Policies-To-Azure-API-Management#comment http://blogs.recneps.net/post.aspx?id=b8cbe8f2-276a-44e3-a511-957bde1565e7 Thu, 28 Feb 2019 09:25:42 +0000 Security Microsoft Azure Azure APIM steve http://blogs.recneps.net/pingback.axd http://blogs.recneps.net/post.aspx?id=b8cbe8f2-276a-44e3-a511-957bde1565e7 25 http://blogs.recneps.net/trackback.axd?id=b8cbe8f2-276a-44e3-a511-957bde1565e7 http://blogs.recneps.net/post/Adding-Security-Policies-To-Azure-API-Management#comment http://blogs.recneps.net/syndication.axd?post=b8cbe8f2-276a-44e3-a511-957bde1565e7 Adding existing logs to Log Analytics <p>I created a <a href="https://www.youtube.com/watch?v=I7eN-VuRD2o">video</a> to walk you through how to add existing logs to Log Analytics. There have been some changes to the way you do this.</p> <p>The location of the settings to configure this has now move to Log Analytics in the Azure Portal. Previously, this was in the Operations Management Suite (OMS).</p> <p>Logon to your Azure Portal (<a href="https://portal.azure.com">https://portal.azure.com</a>) and click through to your log analytics workspace.&nbsp; Then click on Advanced Settings</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_63.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_63.png" width="245" height="368"></a></p> <p>The Advanced Settings page will allow you to configure your data sources and where your logs will be pulled from. The rest of the <a href="https://www.youtube.com/watch?v=I7eN-VuRD2o">video</a> is the same.</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_64.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_64.png" width="635" height="304"></a></p> http://blogs.recneps.net/post/Adding-existing-logs-to-Log-Analytics http://blogs.recneps.net/post/Adding-existing-logs-to-Log-Analytics#comment http://blogs.recneps.net/post.aspx?id=be430a58-d897-49ed-a562-3833b2edad39 Sat, 24 Nov 2018 06:23:00 +0000 Azure Logging steve http://blogs.recneps.net/pingback.axd http://blogs.recneps.net/post.aspx?id=be430a58-d897-49ed-a562-3833b2edad39 15 http://blogs.recneps.net/trackback.axd?id=be430a58-d897-49ed-a562-3833b2edad39 http://blogs.recneps.net/post/Adding-existing-logs-to-Log-Analytics#comment http://blogs.recneps.net/syndication.axd?post=be430a58-d897-49ed-a562-3833b2edad39 Using Azure Logic Apps to Import CSV to SQL Server <p>When Logic Apps first came out I wrote a <a href="http://blogs.recneps.net/post/Processing-a-flat-file-with-Azure-Logic-Apps">blog post</a> explaining how to convert a CSV file into XML.A lot of this is still relevant, especially the integration account and the schemas and maps that are in my <a href="https://github.com/sdspencer-mvp/AzureStuff">github repo</a>. This post will show how Logic Apps are now even simpler to use with flat file decoding and also show how to insert the CSV data into a SQL server. The SQL part of the blog was adapted from this post: <a title="https://pellitterisbiztalkblog.wordpress.com/2016/11/14/upload-flat-file-on-azure-sql-database-using-azure-logic-app/" href="https://pellitterisbiztalkblog.wordpress.com/2016/11/14/upload-flat-file-on-azure-sql-database-using-azure-logic-app/">https://pellitterisbiztalkblog.wordpress.com/2016/11/14/upload-flat-file-on-azure-sql-database-using-azure-logic-app/</a></p> <p>Logic Apps has evolved since I last wrote about this topic and you now no longer need to create a function to transform our csv to xml.</p> <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001_9.png"><img title="clip_image001" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image001" src="http://blogs.recneps.org/image.axd?picture=clip_image001_thumb_8.png" width="841" height="374"></a></p> <p>The Transform XML connector is used now with the same maps we used in the previous post</p> <p>In order to add the individual rows to the database there are a number of things you need to do. We will use an XML schema mapping in a stored procedure to extract the data from the transformed xml.</p> <p>In your SQL database you will need to add a stored procedure, table and an XML schema, The SQL Scripts to create the table, stored procedure and xml schema have been added to the <a href="https://github.com/sdspencer-mvp/AzureStuff">github repo</a>. The stored procedure takes the xml file that has been transformed and uses the xml schema to extract the firstname, middlename and surname from the xml and then store the data in the employees table. In the logic app you need to add a SQL server connector and configure the connection to your Azure SQL database and also add in the stored procedure with the parameter as the output from the Transform XML.</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_60.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_60.png" width="553" height="496"></a></p> <p>The only other thing I needed to do to get this working was to remove the first row of the csv file as it contained the header fields and I didn’t want that inserted into the database. </p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_61.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_61.png" width="532" height="543"></a></p> <p>The “length” expression is:&nbsp; <strong><em>length(variables('csvdata'))</em></strong></p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_62.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_62.png" width="531" height="492"></a></p> <p>The “indexOf” expression is: <strong><em>indexOf(variables('csvdata'),'\r\n')</em></strong></p> <p>However if you add this in the editor the back slash will be delimited and you will end up with <a href="file://\\r\\n">\\r\\n</a> which will not work. To fix this you will need to click the View Code button, search for the \r\n and remove the extra back&nbsp; slash </p> <p>The “substring” expression is: <strong><em>substring(variables('csvdata'),add(variables('firstnewlineposition'),2),sub(variables('csvlength'),add(variables('firstnewlineposition'),2)))</em></strong></p> <p>The trigger for my Logic App was when a new file was added to OneDrive, so click the run button and then drop a file into the configured OneDrive location and the csv entries should be added to your database.</p> http://blogs.recneps.net/post/Using-Azure-Logic-Apps-to-Import-CSV-to-SQL-Server http://blogs.recneps.net/post/Using-Azure-Logic-Apps-to-Import-CSV-to-SQL-Server#comment http://blogs.recneps.net/post.aspx?id=a1f91e15-9932-4209-9f3c-9faf84a888ac Sun, 05 Aug 2018 17:49:20 +0000 Logic Apps Azure Microsoft Azure SQL Azure steve http://blogs.recneps.net/pingback.axd http://blogs.recneps.net/post.aspx?id=a1f91e15-9932-4209-9f3c-9faf84a888ac 631 http://blogs.recneps.net/trackback.axd?id=a1f91e15-9932-4209-9f3c-9faf84a888ac http://blogs.recneps.net/post/Using-Azure-Logic-Apps-to-Import-CSV-to-SQL-Server#comment http://blogs.recneps.net/syndication.axd?post=a1f91e15-9932-4209-9f3c-9faf84a888ac Cloud Load Testing Behind a Firewall with Visual Studio Team Services <p>Recently I’ve been looking at how we can load test one of our services so that we are able to understand the load our partners can put onto our systems before we start to have any issues. We used the Cloud-based Load Testing (CLT) service of Visual Studio Team Services (VSTS). I created a short <a href="https://youtu.be/c7GFwF1cy0o">video</a> showing you how to easily setup a url based load test. The next stage of our load testing was to load test the service that our partners provide, Their service required IP whitelisting to connect which meant the CLT service would not be able to connect. Luckily for us the CLT service allows you to deploy agents into your own infrastructure&nbsp; to carry out the load testing and they are controlled by the same CLT service that we used to load test our own service. This blog post will show you how to install the agent and configure the load test for this scenario.</p> <p>The load test agent is installed using a PowerShell script which can be obtained from <a href="https://docs.microsoft.com/en-us/vsts/load-test/clt-behind-firewall?view=vsts#manage-self-provisioned-agents">here</a>. Open the PowerShell as administrator and don’t forget to unblock the script</p> <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001_7.png"><img title="clip_image001" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001" src="http://blogs.recneps.org/image.axd?picture=clip_image001_thumb_7.png" width="513" height="451"></a></p> <p>To enable you to run the script and to configure the agents to talk to the CLT service, you will need to create a PAT token in VSTS.</p> <p>Login and click on your user icon, then select Security</p> <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001%5B5%5D.png"><img title="clip_image001[5]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001[5]" src="http://blogs.recneps.org/image.axd?picture=clip_image001%5B5%5D_thumb.png" width="222" height="244"></a></p> <p>Select Personal Access Tokens, then Add</p> <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001%5B7%5D.png"><img title="clip_image001[7]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001[7]" src="http://blogs.recneps.org/image.axd?picture=clip_image001%5B7%5D_thumb.png" width="466" height="170"></a></p> <p>Fill in the form and click Create Token at the bottom of the page</p> <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001%5B9%5D.png"><img title="clip_image001[9]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001[9]" src="http://blogs.recneps.org/image.axd?picture=clip_image001%5B9%5D_thumb.png" width="244" height="140"></a></p> <p>This creates your token and this is the only time you will be able to access the token</p> <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001%5B11%5D.png"><img title="clip_image001[11]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001[11]" src="http://blogs.recneps.org/image.axd?picture=clip_image001%5B11%5D_thumb.png" width="640" height="56"></a></p> <p>You need to make sure that you copy it now as it you will not be able to access it after you have left the page,</p> <p>Gong back to PowerShell, run the following command</p> <p>.\ManageVSTSCloudLoadAgent.ps1 -TeamServicesAccountName StevesVSTS -PATToken 37abawavsmsgj6hpakltwhdjt4jrqsmup2jx62hlcxbju2l2tbja -ConfigureAgent -AgentGroupName StevesInternalTest <p>This will take a few minutes to run. If you didn’t run PowerShell as an Administrator you might see errors. When it has run the VSTSLoadAgentService should be installed and running <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001%5B13%5D.png"><img title="clip_image001[13]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001[13]" src="http://blogs.recneps.org/image.axd?picture=clip_image001%5B13%5D_thumb.png" width="533" height="61"></a> <p>Now need to configure a load test. Following on from my <a href="https://youtu.be/c7GFwF1cy0o">video</a>, you can create a url test <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001%5B17%5D.png"><img title="clip_image001[17]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001[17]" src="http://blogs.recneps.org/image.axd?picture=clip_image001%5B17%5D_thumb.png" width="434" height="262"></a> <p>I ran a test web app in Visual Studio using localhost as the address <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001%5B19%5D.png"><img title="clip_image001[19]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001[19]" src="http://blogs.recneps.org/image.axd?picture=clip_image001%5B19%5D_thumb.png" width="436" height="182"></a> <p>When the test has been created select the Settings tab, click “Use self-provisioned agents” and select your agent from the list and add the number of agents you want to use. You could install the agents on a number of machines in your environment using the same script, then you will be able to add more than 1 agent if required. As I only installed the one agent I can only select 1. You can see how many agents the CTL service can see <p><a href="http://blogs.recneps.org/image.axd?picture=image_59.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_59.png" width="468" height="157"></a> <p>If there are less than you think you will need to check to make sure the service was installed without error and that it is running&nbsp; <p>Save the load test and run it. <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001%5B23%5D.png"><img title="clip_image001[23]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001[23]" src="http://blogs.recneps.org/image.axd?picture=clip_image001%5B23%5D_thumb.png" width="596" height="251"></a> <p>Whilst the test was running the performance meters in Visual Studio showed that the web page was being loaded. <p>When the test is complete you should see that it has not cost you any VUM (Virtual User Minutes) as the load tests are running on your own agents <p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001%5B21%5D.png"><img title="clip_image001[21]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001[21]" src="http://blogs.recneps.org/image.axd?picture=clip_image001%5B21%5D_thumb.png" width="590" height="321"></a> <p>The Cloud Load Test service allows you to load test both publicly accessible and private websites and services. As long as the servers running the load test agents have outbound access to the internet for HTTPS then we are able to load test private sites and services and the load test does not cost anything apart from the cost of the infrastructure that the agents are running on locally. http://blogs.recneps.net/post/Cloud-Load-Testing-Behind-a-Firewall-with-Visual-Studio-Team-Services http://blogs.recneps.net/post/Cloud-Load-Testing-Behind-a-Firewall-with-Visual-Studio-Team-Services#comment http://blogs.recneps.net/post.aspx?id=6b7c6fec-708a-4fa6-b49d-3e2d712325d9 Sat, 19 May 2018 06:47:44 +0000 Visual Studio Team Services Visual Studio Microsoft Azure Azure Testing steve http://blogs.recneps.net/pingback.axd http://blogs.recneps.net/post.aspx?id=6b7c6fec-708a-4fa6-b49d-3e2d712325d9 37 http://blogs.recneps.net/trackback.axd?id=6b7c6fec-708a-4fa6-b49d-3e2d712325d9 http://blogs.recneps.net/post/Cloud-Load-Testing-Behind-a-Firewall-with-Visual-Studio-Team-Services#comment http://blogs.recneps.net/syndication.axd?post=6b7c6fec-708a-4fa6-b49d-3e2d712325d9 Azure Key Vault Logging and Events with Log Analytics <p>Following on from my previous blog post (<a href="http://blogs.recneps.net/post/Setting-up-Azure-Key-Vault-with-Audit-logging">http://blogs.recneps.net/post/Setting-up-Azure-Key-Vault-with-Audit-logging</a>) which explains how to set up Azure key vault with logging enabled, this post explains how to access the details of these logs and also to create an alert so you can see if someone is accessing the key vault from an unknown ip address (for example) <p>Open the <a href="https://portal.azure.com">Azure portal</a> and navigate to the Resource Groups section and pick the resource group that we configured last time which contains the key vault and log analytics resources <p><a href="http://blogs.recneps.org/image.axd?picture=image_43.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_43.png" width="738" height="151"></a> <p>Click your log analytics item, to open Log Analytics. <p>You can then select Log Search <p><a href="http://blogs.recneps.org/image.axd?picture=image_44.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_44.png" width="734" height="168"></a> <p>This screen allows you to create your own query or select from existing ones. <p><a href="http://blogs.recneps.org/image.axd?picture=image_45.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_45.png" width="585" height="328"></a> <p>Selecting “All Collected Logs” will show you the logs for the last day. I’ve highlighted the areas where you can change the time period, see the query and also click on Advanced Analytics to give a richer environment for analysing your logs. <p><a href="http://blogs.recneps.org/image.axd?picture=image_46.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_46.png" width="597" height="333"></a> <p>If you want to query just for the Key Vault Audit logs then you can use the following query: <p>search * | where Category=="AuditEvent" <p><a href="http://blogs.recneps.org/image.axd?picture=image_47.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_47.png" width="348" height="379"></a> <p>This will default to a list view, but clicking the Table button will format the data in an easier to read table. <p><a href="http://blogs.recneps.org/image.axd?picture=image_48.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_48.png" width="602" height="251"></a> <p>You can sort and filter on the column headers. This can also be achieved using the order by clause as follows: <p>search * |where Category=="AuditEvent"&nbsp; | order by TimeGenerated desc <p>A blog post discussing the query language can be found <a href="https://azure.microsoft.com/en-gb/blog/azure-log-analytics-meet-our-new-query-language-2/">here</a> <p>We are interested in all calls where someone has tried to access a Secret from the key vault. For that we are looking for an AuditEvent with an OperationName of SecretGet. If we also want to restrict the columns we retrieve then you can use “project” e.g. <p>search * | where Category=="AuditEvent"&nbsp; and OperationName == "SecretGet"<br>| order by TimeGenerated desc<br>| project TimeGenerated, OperationName, CallerIPAddress, ResultSignature, requestUri_s </p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_49.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_49.png" width="608" height="162"></a></p> <p>Now we are familiar with writing queries we can look at alerting. I’d like to set up an alert when the key vault is access from an IP Address other than the one where my application is running. This can be done as follows:</p> <p>search * | where Category=="AuditEvent" and CallerIPAddress != "51.140.184.51" </p> <p>This ip address is actually the Azure Portal and is shown when you view the resource group that contains the key vault.I’m using this ip address so that I will actually get an alert (at the wrong time) when my application runs </p> <p>Click New Alert Rule</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_50.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_50.png" width="607" height="235"></a></p> <p>The following screen should appear</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_51.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_51.png" width="603" height="500"></a></p> <p>The Alert Target should be the Log Analytics we’ve been using and the Target Criteria (when clicked) should show the query we’ve just written</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_52.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_52.png" width="298" height="633"></a></p> <p>We need to configure the rule for when this alert should be triggered. I’m interested when at least 1 attempt has been made in the last 5 minutes to access the Key Vault from an unknown location, so I set the threshold to be zero and click Done. We’ve now configured the logic to determine when the event is fired. Now we need to say what we want to happen when it fires.Firstly we need to give the alert a name and description</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_53.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_53.png" width="496" height="254"></a></p> <p>Now we need to configure how we are alerted. For this you need to create an action group. An action group allows you to define a collection of activities that will happen when the alert is fired. Click New Action Group</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_54.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_54.png" width="641" height="335"></a></p> <p>Action Types can be any of the following:</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_55.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_55.png" width="244" height="154"></a></p> <p>An action group can have multiple actions and you can select both email and SMS in a single action.Once you have created your Action Group you need to select in then click “Create alert rule”</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_56.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_56.png" width="529" height="269"></a></p> <p>Your alert is now set up and running. You can view/edit alerts by selecting Monitor in the Azure Portal</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_57.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_57.png" width="210" height="244"></a></p> <p>then click Alerts (preview), you will be able to see the alerts that have fired.</p> <p><a href="http://blogs.recneps.org/image.axd?picture=image_58.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.recneps.org/image.axd?picture=image_thumb_58.png" width="545" height="214"></a></p> <p>Click Manage Rules to edit the alert.</p> <p>When the alert is fired I will get an email containing the details of the alert. </p> <p>Log analytics is a powerful tool and whilst this series of posts has been related to auditing of Key Vault we can use log analytics for a wide variety of log sources such as Application Insights. We can also use the same mechanism for alerting to these other log sources,</p> <p>The <a href="https://www.youtube.com/watch?v=I7eN-VuRD2o&amp;t=10s">next post is a video</a> that shows you how to connect existing log files to log analytics</p> http://blogs.recneps.net/post/Azure-Key-Vault-Logging-and-Events-with-Log-Analytics http://blogs.recneps.net/post/Azure-Key-Vault-Logging-and-Events-with-Log-Analytics#comment http://blogs.recneps.net/post.aspx?id=f7ef288d-4e33-48a2-a7f3-6b95cfc11820 Thu, 22 Feb 2018 19:59:03 +0000 Azure Logging Security steve http://blogs.recneps.net/pingback.axd http://blogs.recneps.net/post.aspx?id=f7ef288d-4e33-48a2-a7f3-6b95cfc11820 600 http://blogs.recneps.net/trackback.axd?id=f7ef288d-4e33-48a2-a7f3-6b95cfc11820 http://blogs.recneps.net/post/Azure-Key-Vault-Logging-and-Events-with-Log-Analytics#comment http://blogs.recneps.net/syndication.axd?post=f7ef288d-4e33-48a2-a7f3-6b95cfc11820 Setting up Azure Key Vault with Audit logging <p>Azure Key Vault is a good way to share secrets with your partners in a way that allows you to have control over the access to each of the assets in Azure. We also need to know who is accessing the resources and from where so that we can monitor for suspicious activity. This post will talk through setting up the key vault and then configuring logging to keep track of the audit information for your certificates, keys and secrets. For each application that you want to access your resources you will need to create some credentials that the application can use.</p> <p>To allow an application to access key vault an App Registration needs to be added to Azure Active Directory (AAD). This effectively sets up a username and password that the application can use for credentials. </p><p>Open the azure portal (<a href="http://portal.azure.com">http://portal.azure.com</a>) and navigate to Active Directory. </p><p>Click "App registrations" </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image002_2.jpg"><img title="clip_image002" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image002" src="http://blogs.recneps.org/image.axd?picture=clip_image002_thumb_2.jpg" width="538" height="289"></a> </p><p>Then "New application registration" </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image001_6.png"><img title="clip_image001" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; margin: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image001" src="http://blogs.recneps.org/image.axd?picture=clip_image001_thumb_6.png" width="232" height="244"></a> </p><p>Name needs to be unique within your AD, select Web API/API and enter sign-on url. If you not building a website then enter anything in here. It might be useful to use a url related to your existing domain with application name appended. It doesn’t need to be a valid url. The click “Create” </p><p>Once created copy the Application ID as this is equivalent to a username to be used when calling the Key Vault in code. You now need to create the password. </p><p>Click Settings then Keys </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image002_4.png"><img title="clip_image002" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; margin: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image002" src="http://blogs.recneps.org/image.axd?picture=clip_image002_thumb_4.png" width="244" height="181"></a> </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image004_2.jpg"><img title="clip_image004" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image004" src="http://blogs.recneps.org/image.axd?picture=clip_image004_thumb_2.jpg" width="586" height="259"></a> </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image006.jpg"><img title="clip_image006" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image006" src="http://blogs.recneps.org/image.axd?picture=clip_image006_thumb.jpg" width="588" height="276"></a> </p><p>Enter a name in the description field and select a duration, then click Save. The new key value will be displayed. You will need to copy this as it will not be visible again once you leave this page. This will be used as the password. </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image002%5B5%5D.jpg"><img title="clip_image002[5]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image002[5]" src="http://blogs.recneps.org/image.axd?picture=clip_image002%5B5%5D_thumb.jpg" width="592" height="227"></a> </p><p>Now create the Key Vault. To do that it is a good idea to put it in a specific resource group, especially if you are creating a set of resources that the key vault is going to access or if you are going to setup third party access. Once the Resource Group has been created, select it and add a Key Vault. When the Create Key Vault panel appears, click Access Policies, click "Add new" </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image004%5B5%5D.jpg"><img title="clip_image004[5]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image004[5]" src="http://blogs.recneps.org/image.axd?picture=clip_image004%5B5%5D_thumb.jpg" width="593" height="369"></a> </p><p>Pick the application you just created in AAD and select Get in Secret permissions, Save then go back to the main Key Vault pane and click Create </p><p>You have just given the application we created earlier access to just retrieving secrets. As you can see from the access policy you can give the application permissions to access a combination of Keys, Secrets and Certificates with the minimum access of Get. The Key Vault security is at the vault level and you cannot protect individual secrets at the user level. By granting only Get access on the Secret the application will not be able to list the Secrets available and will only be able to retrieve secrets it knows the names of. </p><p>Now the Key vault is set up and can be accessed, we want to know who is accessing the vault and from where. Out of the box this is not enabled and requires additional configuration and resources to allow us to be able to retrieve this audit information. This is achieved by enabling diagnostic logs in the Key Vault. </p><p>Before you can enable this you need to create a new storage account in this resource group to store the logs, then add Application Insights to the resource group </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image002%5B7%5D.jpg"><img title="clip_image002[7]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image002[7]" src="http://blogs.recneps.org/image.axd?picture=clip_image002%5B7%5D_thumb.jpg" width="591" height="161"></a> </p><p>Once these have been provisioned, navigate to the Key Vault you just created &amp; click Diagnostic logs </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image004%5B7%5D.jpg"><img title="clip_image004[7]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image004[7]" src="http://blogs.recneps.org/image.axd?picture=clip_image004%5B7%5D_thumb.jpg" width="595" height="309"></a> </p><p>Click "Turn on diagnostics" </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image006%5B6%5D.jpg"><img title="clip_image006[6]" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image006[6]" src="http://blogs.recneps.org/image.axd?picture=clip_image006%5B6%5D_thumb.jpg" width="596" height="525"></a> </p><p>Select “Archive to Storage Account” and Pick the storage account you’ve just created </p><p>Select “Send to Log Analytics” and Create a new OMS workspace in your resource group </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image008.jpg"><img title="clip_image008" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image008" src="http://blogs.recneps.org/image.axd?picture=clip_image008_thumb.jpg" width="602" height="308"></a> </p><p>Once created select this for Log Analytics </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image009.png"><img title="clip_image009" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image009" src="http://blogs.recneps.org/image.axd?picture=clip_image009_thumb.png" width="312" height="421"></a> </p><p>select the AuditEvent log and click Save.&nbsp; </p><p>Now any changes to the Key Vault plus any access from your application will be logged and visible via log analytics. There’s a 10 – 15 minute delay between accessing the Key Vault and the log appearing. </p><p>To Add a Secret to the vault, Navigate to the vault, click Secrets then Add </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image010_1.png"><img title="clip_image010" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image010" src="http://blogs.recneps.org/image.axd?picture=clip_image010_thumb_1.png" width="532" height="413"></a> </p><p>Select Manual from the Upload options, enter a name and the secret </p><p><a href="http://blogs.recneps.org/image.axd?picture=clip_image011.png"><img title="clip_image011" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="clip_image011" src="http://blogs.recneps.org/image.axd?picture=clip_image011_thumb.png" width="531" height="549"></a> </p><p>Remember the name you gave the Secret as you will need this in your code when accessing the key vault. This secret will now have a unique identifier that you will use. The one I’ve just created is: </p><p><a href="https://recneps-vault.vault.azure.net/secrets/recnepssvsb-key">https://recneps-vault.vault.azure.net/secrets/recnepssvsb-key</a> </p><p>You should see in the logs this secret being created and also when it gets accessed. </p><p>Accessing the KeyVault in C# can be seen here: <a href="https://docs.microsoft.com/en-us/azure/key-vault/key-vault-use-from-web-application">https://docs.microsoft.com/en-us/azure/key-vault/key-vault-use-from-web-application</a> </p><p>The application in the example uses settings as defined below: </p><p>ClientID is the Application ID we created in the application registration in AD </p><p>ClientSecret is the key you created (that you had to save as it wasn’t visible again) as part of creating the application registration in AD. </p><p>Each Key, Secret and Certificate has a unique url which is used as the SecretURI e.g. <a href="https://recneps-vault.vault.azure.net/secrets/recnepssvsb-key">https://recneps-vault.vault.azure.net/secrets/recnepssvsb-key</a> </p><p>You now have your key vault set up with audit logging and are able to access it. <a href="http://blogs.recneps.org/post/Azure-Key-Vault-Logging-and-Events-with-Log-Analytics" style="">My next blog post</a> will talk you through how to access the logs and also how to set up alerting</p> http://blogs.recneps.net/post/Setting-up-Azure-Key-Vault-with-Audit-logging http://blogs.recneps.net/post/Setting-up-Azure-Key-Vault-with-Audit-logging#comment http://blogs.recneps.net/post.aspx?id=89bc396d-aa9f-4376-9827-fca918429f5b Tue, 06 Feb 2018 20:09:00 +0000 Azure Logging Security steve http://blogs.recneps.net/pingback.axd http://blogs.recneps.net/post.aspx?id=89bc396d-aa9f-4376-9827-fca918429f5b 234 http://blogs.recneps.net/trackback.axd?id=89bc396d-aa9f-4376-9827-fca918429f5b http://blogs.recneps.net/post/Setting-up-Azure-Key-Vault-with-Audit-logging#comment http://blogs.recneps.net/syndication.axd?post=89bc396d-aa9f-4376-9827-fca918429f5b