{"id":514,"date":"2011-12-01T21:34:00","date_gmt":"2011-12-01T21:34:00","guid":{"rendered":"\/blogs\/bobb\/post\/Using-filtering-and-server-audit-specs-to-audit-DB-objects-in-SQL-Server-2012.aspx"},"modified":"2011-12-01T21:34:00","modified_gmt":"2011-12-01T21:34:00","slug":"using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/","title":{"rendered":"Using filtering and server audit specs to audit DB objects in SQL Server 2012"},"content":{"rendered":"<p>\nI&#39;ve always been pretty &quot;standard&quot; in my approach to SQL Server&#39;s auditing feature. That is, Server Audit Specifications are for auditing server-level objects and Database Audit Specifications are for auditing database-level objects. There have always been a few &quot;Audit Action Groups&quot; that pertain to database objects that could be specified in Server Audit Specifications. An example of this would be the Audit Action Group SCHEMA_OBJECT_ACCESS_GROUP that will audit a schema-level object use of an object&#39;s permission. Or SCHEMA_OBJECT_CHANGE_GROUP that will audit a CREATE\/ALTER\/DROP against a schema-level object. This has been the case back to SQL Server 2008, when the auditing feature was first introduced.\n<\/p>\n<p>\nThe drawback of using Audit Action Groups like SCHEMA_OBJECT_ACCESS_GROUP in a Server Audit Specification is that they audit access to ANY schema object in ANY database. Server-level actions do not allow for detailed filtering on database-level actions. This is going to generate a LOT of audit records.\n<\/p>\n<p>\nEnter SQL Server 2012. One of the new auditing features allows predicates to be specified on the CREATE SERVER AUDIT level. This allows much more granular auditing using Server Audit Specifications. The way that this works is to use predicates on the SERVER AUDIT object associated with a SERVER AUDIT SPECIFICATION.\n<\/p>\n<p>\nHere&#39;s an example. Here&#39;s a SQL Server 2008 way to audit SELECT on the HumanResources.EmployeePayHistory table in AdventureWorks by dbo:\n<\/p>\n<p>\nUSE master<br \/>\nGO<br \/>\nCREATE SERVER AUDIT TestAudit1 TO file (filepath = &#39;c:\\temp&#39;);\n<\/p>\n<p>\nUSE AdventureWorks<br \/>\nGO<br \/>\nCREATE DATABASE AUDIT SPECIFICATION TestDBSpec1<br \/>\nFOR SERVER AUDIT TestAudit1<br \/>\n&nbsp;&nbsp;&nbsp; ADD (SELECT ON HumanResources.EmployeePayHistory BY dbo) WITH (STATE = ON);<br \/>\nGO\n<\/p>\n<p>\nFire up these objects (run ALTER SERVER AUDIT TestAudit1 WITH (STATE = ON); ) and you&#39;re auditing. But in SQL Server 2012, you can do (approximately) the same thing with this:\n<\/p>\n<p>\nUSE master<br \/>\nGO<br \/>\nCREATE SERVER AUDIT TestAudit2 TO file (filepath = &#39;c:\\temp&#39;)<br \/>\nWHERE database_name =&#39;AdventureWorks&#39; AND schema_name =&#39;HumanResources&#39; <br \/>\n&nbsp; AND object_name =&#39;EmployeePayHistory&#39; AND database_principal_name =&#39;dbo&#39;;\n<\/p>\n<p>\nCREATE SERVER AUDIT SPECIFICATION TestServerSpec2<br \/>\nFOR SERVER AUDIT TestAudit2<br \/>\n&nbsp;&nbsp;&nbsp; &#8212; ADD SELECT ON HumanResources.EmployeePayHistory BY dbo) &#8212; note: you can&#39;t do this in SERVER AUDIT SPEC<br \/>\n&nbsp;&nbsp;&nbsp; ADD (SCHEMA_OBJECT_ACCESS_GROUP)<br \/>\n&nbsp;&nbsp;&nbsp; WITH (STATE = ON);<br \/>\nGO\n<\/p>\n<p>\nNote that they&#39;re not EXACTLY the same. The Database Audit Spec is auditing only SELECT, while the filtered predicate doesn&#39;t filter on action_id (the action_id for SELECT is &#39;SL&#39;). This&nbsp;*may* be a bug, <a href=\"http:\/\/connect.microsoft.com\/SQLServer\/feedback\/details\/710424\/action-id-fails-in-audit-predicate-if-string-specified\">reported on Connect currently<\/a>. Although the action_id is defined as CHAR(4), specifying a string causes an error: &quot;Msg 25713, Level 16, State 23, Line 1 The <strong>value<\/strong> specified for event attribute or predicate source, &quot;action_id&quot;, event, &quot;audit_event&quot;, is invalid.&quot;. Using a number for action_id works (and using action_id is <strong>supposed<\/strong> to work according to BOL) but there are no specifications of numeric action_ids. Even in sys.dm_audit_actions.\n<\/p>\n<p>\nAlthough maybe you&#39;re not *supposed to* be able to filter on action_id, and the error message text phrasing&nbsp;is just a red herring. Because&#8230;\n<\/p>\n<p>\n(This entry is getting a bit long, but I&#39;ll tell you what the VERY interesting point of this exercise is in the next blog entry. Stay tuned.)\n<\/p>\n<p>\n@bobbeauch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;ve always been pretty &quot;standard&quot; in my approach to SQL Server&#39;s auditing feature. That is, Server Audit Specifications are for auditing server-level objects and Database Audit Specifications are for auditing database-level objects. There have always been a few &quot;Audit Action Groups&quot; that pertain to database objects that could be specified in Server Audit Specifications. An [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,31],"tags":[],"class_list":["post-514","post","type-post","status-publish","format-standard","hentry","category-security","category-sql-server-2012"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using filtering and server audit specs to audit DB objects in SQL Server 2012 - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using filtering and server audit specs to audit DB objects in SQL Server 2012 - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"I&#039;ve always been pretty &quot;standard&quot; in my approach to SQL Server&#039;s auditing feature. That is, Server Audit Specifications are for auditing server-level objects and Database Audit Specifications are for auditing database-level objects. There have always been a few &quot;Audit Action Groups&quot; that pertain to database objects that could be specified in Server Audit Specifications. An [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2011-12-01T21:34:00+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/\",\"name\":\"Using filtering and server audit specs to audit DB objects in SQL Server 2012 - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2011-12-01T21:34:00+00:00\",\"dateModified\":\"2011-12-01T21:34:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Security\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/security\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using filtering and server audit specs to audit DB objects in SQL Server 2012\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using filtering and server audit specs to audit DB objects in SQL Server 2012 - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/","og_locale":"en_US","og_type":"article","og_title":"Using filtering and server audit specs to audit DB objects in SQL Server 2012 - Bob Beauchemin","og_description":"I&#39;ve always been pretty &quot;standard&quot; in my approach to SQL Server&#39;s auditing feature. That is, Server Audit Specifications are for auditing server-level objects and Database Audit Specifications are for auditing database-level objects. There have always been a few &quot;Audit Action Groups&quot; that pertain to database objects that could be specified in Server Audit Specifications. An [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/","og_site_name":"Bob Beauchemin","article_published_time":"2011-12-01T21:34:00+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/","name":"Using filtering and server audit specs to audit DB objects in SQL Server 2012 - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2011-12-01T21:34:00+00:00","dateModified":"2011-12-01T21:34:00+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-filtering-and-server-audit-specs-to-audit-db-objects-in-sql-server-2012\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"Security","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/security\/"},{"@type":"ListItem","position":3,"name":"Using filtering and server audit specs to audit DB objects in SQL Server 2012"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=514"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/514\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}