I have encountered today a problem that I have never faced before.
I have developed an application that uses SQL Server database. That application has a Windows Service that accesses the database.
Since the Windows Service uses Network Service as the user, I need to add that user to the database so that it has access to it.
That task is accomplished automatically by an installer I have also developed.
In that installer, I have this script fragment:
USE [MyDB]
GO
IF NOT EXISTS(SELECT principal_id FROM sys.database_principals WHERE name = 'NT AUTHORITY\NETWORK SERVICE')
BEGIN
/****** Object: User [NT AUTHORITY\NETWORK SERVICE] Script Date: 26-10-2018 13:42:57 ******/
CREATE USER [NT AUTHORITY\NETWORK SERVICE] FOR LOGIN [NT AUTHORITY\NETWORK SERVICE] WITH DEFAULT_SCHEMA=[dbo]
ALTER ROLE [db_owner] ADD MEMBER [NT AUTHORITY\NETWORK SERVICE]
END
That script works almost always, but today installation.
Today installation was made in a Windows 7 PC which is in Spanish. The installer sent an error telling that "NT AUTHORITY\NETWORK SERVICE" user does not exist.
Looking at the issue, I found that in that PC, that user is called "NT AUTHORITY\Servicio de Red", that is, "NETWORK SERVICE" in Spanish.
That is strange because I have other PC's with Windows 10 in Spanish, but in that O.S., the user is called "NT AUTHORITY\NETWORK SERVICE" too.
To solve the issue in that PC, I had to install SQL Server Management Studio only to assign "NT AUTHORITY\Servicio de Red" user to the database.
Since I don't know the user name beforehand, is it possible to add to SQL a generic user that will work everywhere?
NT SERVICE\<ServiceName>
). You do not need to create these users in advance, they always have the name of the service (so completely predictable) and Windows will automatically manage the passwords for them. – BerniniNT AUTHORITY\NETWORK SERVICE
does not have "full privileges for all operating system resources" either -- it was introduced specifically because it doesn't. You may be misinformed about what your service truly needs. Any service that runs with permission to do anything is a security problem waiting to happen. – Berniniicacls
to grant write permission on the specific folder you need. Do not just pick an admin account because they happen to already be able to do that, and especially not LocalSystem. Your service does not need to be able to format the hard drive, steal the user's credit card data or serve as a malware backdoor for a zero day hack, right? But that's what you allow when you make it LocalSystem. – Bernini