Permissions Auditing: Who, What, and When?
Trust is good, but SERVER AUDIT is better. Auditing helps you find out who granted, revoked, or changed permissions in your database. You do not need third-party tools: SQL Server already includes the necessary functionality. A few statements — CREATE SERVER AUDIT and CREATE DATABASE AUDIT SPECIFICATION — can establish an audit trail.
“Without a log, there is no evidence. Without evidence, there is no security.”
Why audit?
Permissions are power, and power should leave a trace. In environments with many administrators — or developers with sysadmin rights — it can be difficult to establish who changed what. Auditing helps restore accountability.
Audit architecture
Auditing consists of three layers:
- Server Audit defines where events are written: files, the Application Log, or the Security Log.
- Database Audit Specification defines which actions are recorded in a particular database.
- Server Audit Specification tracks server-level events, such as
SERVER_PRINCIPAL_CHANGE_GROUP.
One SERVER AUDIT can serve multiple specifications, allowing you to centralize audit-event collection.
Practical example
First, create an audit at the instance level:
| |
Next, configure permission-change auditing for a specific database:
| |
Statements such as GRANT, DENY, REVOKE, and ALTER ROLE ... ADD MEMBER can be captured when the relevant action groups are configured.
Reading audit logs
You can read the audit files using sys.fn_get_audit_file:
| |
The results show who performed an audited action, when it happened, and which object it involved. For longer retention, you can import events into a dedicated database such as DBA_AuditLogs and visualize them with Grafana or Power BI.
Bonus: auditing logins
You can extend the configuration to monitor login attempts:
| |
This allows you to see not only who changed something, but also who tried to access the system.
Good practices
- Store audit logs on a separate disk or protected network resource.
- Archive audit logs regularly, especially in environments with many users.
- Monitor audit status with
sys.dm_server_audit_statusto detect unexpected disablement. - Combine auditing with Policy-Based Management and SQL Agent Alerts to receive timely notifications.
End-to-end verification (hands-on, 5–10 minutes)
Here is a quick test: create an object and a user, grant and revoke permissions, change role membership, and then inspect the audit trail.
Prerequisites:
SERVER AUDIT Audit_UprawnieniaandDATABASE AUDIT SPECIFICATION Audit_Uprawnienia_DBare enabled as shown above. The audit path isC:\SQLAudit\.
| |
What should you see?
- Entries for
GRANT SELECT,REVOKE SELECT, andALTER ROLE ... ADD/DROP MEMBER. - The
server_principal_namecolumn identifies the login that executed the operation. succeeded = 1indicates a successful operation;0indicates a failure.
Quick alert: Is auditing alive?
To check audit health from a SQL Agent job every five minutes, add a T-SQL step:
| |
Connect this step to a SQL Agent alert (error number 50001) and send a notification by email, SNMP, or Teams.
Trust ends where lack of visibility begins. Auditing is your mirror: it shows who really pulls the levers.
Demo repository: 👉 github.com/marcinpytlik/SQLManiak/tree/master/labs/07-security/PBM_Audit