Jump to content

Custom solution to Omit Azure SQL Auditing Data


Recommended Posts

Guest sakshigupta
Posted

I have come up with the requirement from customer to omit the bind values captured as part of Azure SQL Auditing – Batch completed event.

 

 

 

When we talk about bind values, I am referring to the parameters passed as part of prepared statement from application. By default, SQL Batch completed event captures complete statements executed by an application below is an example:

 

mediumvv2px400.png.ce9cfd2e7444d76a6ba7db2032327709.png

 

 

 

So, the custom solution here includes the below services:

 

 

 

  • Azure SQL Database
  • Event Hub - 1st Destination to send the raw event.
  • Blob Storage - Final Destination to send filtered Data.
  • Stream Analytics Jobs – Used to filter the data.

 

 

 

  • As a first steps, Azure SQL Database is provisioned and enabled SQL Auditing. Target selected to send auditing data as Event Hub. As you may be aware, default auditing would capture Successful/Failed logins/Batch Completed Event.

 

 

 

  • mediumvv2px400.png.3178798e666ee23d6223aaa015baa1c2.png

     

     

 

 

 

  • Event Hub as 1st Target to send auditing event.
    • Event hub would store batch completed event(PreparedStatement) sent by an application in the below format. So, the aim here is to exclude the values passed as parameter. This could be a requirement from security/compliance perspective where companies would like to capture audit event but doesn’t want to store values passed as a parameter and omit those values.
    • mediumvv2px400.png.4986117816b7ef933e9aacb4eadc66d3.png
       
       

    [*]Once this is done, I have provisioned stream analytics and configured source and target.

 

mediumvv2px400.png.3878f3a2cf964ea4d64da588cbb444e2.png

 

 

 

mediumvv2px400.png.894839622d4e8cfe0c01d8c46ece3464.png

 

 

 

  • As you can see the above screenshot, source and destination is configured and using the query to filter the data. I have sample application running and executing prepared statement as sp_executesql so I have setup the filter in my query accordingly. I have executed application several times to ensure some data is captured in event hub and can later be used as source by streamAnalytics jobs to read the data.

 

Below screenshot indicates, I have couple of requests coming in event hub.

 

 

 

 

 

mediumvv2px400.png.6013c297c408d85579eab5c45be830fb.png

 

 

 

 

 

  • Once I validated, I would like use SA job to read and send the data. Below is the same query I am using read the data sending to blob storage. You can further filter the data based on the classification defined on specific columns if needed. Using two columns here as Statement – Capturing as-is data and StatementnoBind as filtered data to omit bind values.

 

 

 

SELECT

 

RecordsArray.ArrayValue.time,

 

RecordsArray.ArrayValue.resourceId,

 

RecordsArray.ArrayValue.category,

 

RecordsArray.ArrayValue.properties.action_name,

 

RecordsArray.ArrayValue.properties.event_time,

 

RecordsArray.ArrayValue.properties.data_sensitivity_information,

 

RecordsArray.ArrayValue.properties.statement,

 

case when left(RecordsArray.ArrayValue.properties.statement,18) = 'exec sp_executesql'

 

-- and REGEXMATCH(RecordsArray.ArrayValue.properties.data_sensitivity_information, 'information_type="Health"') = 0

 

then

 

substring(RecordsArray.ArrayValue.properties.statement,0,PATINDEX('%,N''%', RecordsArray.ArrayValue.properties.statement))

 

else

 

RecordsArray.ArrayValue.properties.statement

 

end as statementnobind

 

INTO

 

[blobstoragedest]

 

FROM

 

[eventhubsrc]

 

CROSS APPLY GetArrayElements(records) AS RecordsArray where RecordsArray.ArrayValue.properties.action_name in ( 'BATCH COMPLETED', 'RPC COMPLETED')

 

 

 

mediumvv2px400.png.0ab61eeca3f2799f82bdd3559a85c8ed.png

 

 

 

 

 

As you can see the below screenshot, statement no bind columns are not capturing any values passed as a parameters. This validation is done from UI as of now and can see the results are expected.

 

 

 

 

 

 

 

mediumvv2px400.png.a1de14077acd4f8fb2d2c917ecd2ec86.png

 

 

 

 

 

  • Now, will start SA job and see if data is stored inside blobstorage. As you can my job is running and can see the usage and event counts are increasing.
    • mediumvv2px400.png.eab5f45c5c858ed4773ade7354dd3f11.png
       
       
       

    • mediumvv2px400.png.d7367bffcd6b6bf0ed6e238ce921694c.png
       
       

 

 

 

  • As a next step, I could file is present inside blobstorage and captured data is showing as expected StatementNOBIND – no parameters values are captured.
    • mediumvv2px400.png.2bf7569050f3b54b80036d37fd20f60a.png
       
       

 

mediumvv2px400.png.50c198d1f107c98b23e06e4681ef74bc.png

 

 

 

 

 

Thats all. :)

 

 

 

Enjoy Learning!!

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...