Apologies in advance if I don't use some terminology correctly here. I'm not a DBA but I've been temporarily forced into the role.
I've inherited an application that runs on SQL Server 2016 Enterprise - one instance for PROD and another for TEST. These instances are set up in an "always on" configuration, so I have one Availability Group for PROD and one for TEST. Each Availability Group has two servers in it. Each instance has multiple databases in it, but only one DB in each instance is actually used by the application - the others look to have been created for testing purposes. I'm only mentioning that there are other DBs just in case it might be relevant in some way that I'm not aware of.
I have a login for a service account (Windows authentication), and that login is mapped to a user of the same name in a few of the DBs. This service account is a member of the sysadmin role. After an IT Security audit, I've been told to remove SA rights from this account. I don't think this will cause any problems for the application, but of course I want to remove the rights in the TEST instance first so I can confirm that the application doesn't need them for some reason.
In the TEST instance, I've unchecked the sysadmin role for the login and it now only has the "public" box checked, but I find that I can still log in as the service account and access everything that it had access to before. It can still access all the tables in the main database (which I expected because the account has been granted a lot of rights on the dbo schema in the database), but the confusing thing to me is that it can still view the jobs at the server level, which I thought it would lose.
If I run this statement (SELECT * FROM fn_my_permissions(NULL, 'server');
) while logged in as the service account, this is the list of permissions that I get back:
- CONNECT SQL
- SHUTDOWN
- CREATE ENDPOINT
- CREATE ANY DATABASE
- CREATE AVAILABILITY GROUP
- ALTER ANY LOGIN
- ALTER ANY CREDENTIAL
- ALTER ANY ENDPOINT
- ALTER ANY LINKED SERVER
- ALTER ANY CONNECTION
- ALTER ANY DATABASE
- ALTER RESOURCES
- ALTER SETTINGS
- ALTER TRACE
- ALTER ANY AVAILABILITY GROUP
- ADMINISTER BULK OPERATIONS
- AUTHENTICATE SERVER
- EXTERNAL ACCESS ASSEMBLY
- VIEW ANY DATABASE
- VIEW ANY DEFINITION
- VIEW SERVER STATE
- CREATE DDL EVENT NOTIFICATION
- CREATE TRACE EVENT NOTIFICATION
- ALTER ANY EVENT NOTIFICATION
- ALTER SERVER STATE
- UNSAFE ASSEMBLY
- ALTER ANY SERVER AUDIT
- CREATE SERVER ROLE
- ALTER ANY SERVER ROLE
- ALTER ANY EVENT SESSION
- CONNECT ANY DATABASE
- IMPERSONATE ANY LOGIN
- SELECT ALL USER SECURABLES
- CONTROL SERVER
Those seem like SA-level permissions to me, but I don't understand where they're coming from since the sysadmin role is no longer applied to the login. I thought that they might have been granted individually to the login (which seems weird to me, because doesn't that just bypass the purpose of having roles in the first place?) so I tried revoking them. The revoke commands appear to be successful ("Commands completed successfully"), but when I run the same command to check the rights from the service account again, it still has all the same permissions.
I've also found that while logged in as the service account, it can assign the sysadmin role to itself (and remove it from itself).
Other notes: every time I make changes to the account, I'm careful to make sure that I'm making the same changes on both servers that are part of the Availability Group. My understanding is that the logins are separate on each server even though they map to the same database-level user, so any changes to the login have to be done on both servers.
Another thing I've tried is removing the sysadmin role from the account on the secondary node of the PROD instance just to see if I have the same problem with the permissions getting "stuck" on, and the issue doesn't happen there.
I feel like I'm missing something obvious here, but I don't know what it is. Any help would be much appreciated.