Sunday, February 11, 2018

Onboarding Azure SQL Analytics

One of the solutions I am working on for a client makes heavy use of the Azure SQL platform.  As such, getting diagnostics and metrics data from all those databases can be quite a challenge.  Luckily for us, OMS has an Azure SQL Analytics solution which is currently in preview.  You can read more about the solution here.

The goal of this post is to talk a little bit about how to onboard databases into the solution.  The easiest way, and least scalable, is to use the portal.  Adding on Azure resources in general is a simple as navigating to the Log Analytics Tab, and selecting Azure Resources.




Once you are in that window, you can use the filtering tools up top to grab the view you are looking for.  Clicking on an Azure SQL database will open up the following:



It is important to note that sometimes these options do change.  For example, when the solution was first released, audit was not an option you could select.  I do like how you are able to select the categories you would like to monitor, allowing you to control cost inside of Log Analytics.

Another option for onboarding systems is to use the Enable-AzureRMDiagnostics.ps1 script, released by Microsoft.  This script is not specific to Azure SQL, rather, works on all Azure resources that have this capability built-in.

Instructions for installation and use can be found here.

While the script has a bunch of interactive elements to determine key settings (such as the workspace id), cracking it open simply reveals that it uses the Set-AzureRmDiagnosticSetting cmdlet to enable the appropriate settings.

The script essentially does the following:

- Logs into Azure
- Determines the subscription to use
- Determines the workspace to use
- Analyzes the subscription/resource group for resources that can have metrics/logs enabled
- Uses the Get-AzureRmDiagnosticSetting cmdlet to determine what log/metric settings can be set on a given resource type
- Prompts the user for which categories to enable
- Enables it on the target

The solution is actually pretty slick, and since everything is done via inspection, the script will never age.  Have a look at the parameters list to see automation options.

It is important to note that different resource types have different options enabled.  In the case of SQL, you'll want to enable appropriate settings for:
- Azure SQL Server
- Azure SQL Server Elastic Pools
- Azure SQL Database

In our case, we found it extremely important to compare the results between what the pool was registering, and what an individual database was registering.

In any event, this covers some of the options for onboarding databases to Azure SQL Analytics.  It is a must do as part of your Azure SQL deployment.
 










Wednesday, February 7, 2018

Missing computers in Azure Update/Inventory/Change Management

Recently, I enabled a couple of preview services for a client.  These services centered around using the OMS/Automation system to surface data around update/inventory/change management.  You can read more about these preview services:

https://azure.microsoft.com/en-ca/updates/update-management-inventory-and-change-tracking-are-available-in-azure-automation/

To be honest, these are pretty powerful features that help make VMs act more "as a service" by bringing in cross VM views.  In any event, for my client, only one of our VMs actually showed up in the list.  Funny enough, it was the one non-domain joined machine.

After a call into Azure support, this turns out to be a known issue.  Essentially, there are a couple of saved searches in Log Analytics that are used to determine the computer group to report on.  When you enable the service, VMs show up with only their VM name, which does not work properly when machines are domain joined.

If you navigate to your log analytics workspace, under saved searches, you will see two searches named "MicrosoftDefaultComputerGroup".




What you will want to do is right click on the search and click edit.  You can then edit the query being used.  Essentially, there is a where statement, and you need to change all the computer names to the FQDN of that computer.

ie:  prodvm01 ==> prodvm01.contoso.com

After saving that query (and waiting a bit), you should see all your domain joined machines come up in the list.  This is a known issue and Microsoft is working on a fix.  Obviously, as you add machines, you will have to re-edit the appropriate query.

Hope that helps!

Tuesday, February 6, 2018

Looking at the Azure JIT VM Access Activity Log

Azure Just-in-time VM Access is a pretty cool feature, and in a previous post I discussed initial steps for onboarding the service.  In this post, I'd like to examine the auditing features of the service.

Currently, there is an activity log that you can review.  The activity log is nothing special, it is just the Azure activity log with the operation name of Microsoft.Security/locations/jitNetworkAccessPolicies/initiate/action.

You can view this pretty easily from the ASC itself by right clicking on the server in scope and requesting the activity log.  You can also see all the requests across all resources by using the AzureActivity solution in OMS, or by using the activity log tab in the Azure portal.

Upon request, I can see that 4 events are created in the Activity log.





Now, I'm assuming the order presented is probably incorrect, and this is due to the time resolution of the activity log.  This follows logically, since I don't think a write to the NSG could occur before I made the request :)

In any event, lets take a look at them in order:

The first event (starting from the bottom.... shoutout to my man Drake!) is the write to the network security group.  Key points here are the following:

- The resource under scope is actually the NSG that protects the target VM (this makes sense)
- The event is initiated from the Windows Azure Security Resource Provider.  This will probably lead to interesting RBAC control issues for this service ( think about NSGs used for IR and other types of activities)
-  Deep in the request body, you can see where the port is being opened for the requested IP.  The description around the rule itself is generic  "ASC JIT Network Access rule for policy 'default' of VM 'xxxx'.\"
- The rule name that is created has some identifiers on it, and looks like SecurityCenter-JITRule_-1xxx9_5xxxx2

The next event up is an initiate event on the VM itself.  Interesting.  Key points:

- Operation name
    "operationName": { 
    "value": "Microsoft.Security/locations/jitNetworkAccessPolicies/initiate/action",

    "localizedValue": "Microsoft.Security/locations/jitNetworkAccessPolicies/initiate/action"},

- There is a properties section that seems to contain all the information for the policy being applied.



Moving on up the stack, there is now a request which seems to contain very similar information to the previous request, but this one is targeted at the locations/westus/jitNetworkAccessPolicies/default resources (this must be the initial request to the ASC subsystem).

The one above that (the first one in the list) is a pretty blank request to the same resources.

Conclusion

In conclusion, there seems to be a few events that are generated as it relates to an access request.  This makes sense, and it follows that the user request is first handled by the security subsystem, then forwarded to the VM (this is probably how write permissions are checked) and lastly sent to edit/modify the NSG.

One thing that I found interesting while doing is that there doesn't seem to be an easy/logical way to track the NSG rule name created to a particular request.  I tried searching the activity log for the various components of the NSG rule name, and only found the write NSG activity log.  Of course the write NSG does not link itself to the request, so you start to lose the trail.  Will be interesting to investigate this further (which is code word for I probably did something wrong).