windows 中的服務隔離在windows vista 以及server 2008之後就有了,可以讓管理者控制本地資源的使用(如檔案、系統資料庫等等)。之前windows版本中,系統内置了一些高權限的服務賬号,大家所熟悉的有Local System,Network,LocalService
為了最小化權限使用,通常我們需要建立賬号來賦予最小權限,然後配置服務以這個賬号運作,但是如果服務較多,那麼有許許多多的賬号要維護,而且如果你有嚴格的密碼政策的話,比如定期要更改服務賬号的密碼,那真是頭疼。
window 中的Service SID(另外一個稱呼是Virutal Account) 可以針對每個服務啟用,它可以讓管理者針對Service SID來隔離服務使用的資源。同時不必維護服務賬号的密碼。Service SID 賬号通路網絡資源是使用的憑據是計算機賬号,DomainName\ComputerName$.
建立Service ID 可以使用
sc sidtype <service_name> unrestricted
sc sidtype <service_name> restricted
當然也可以使用sc qsidtype <serviec_name>來查詢Service SID ,我這裡針對微軟的SCOM Agent health service 服務進行查詢。
<a href="http://s3.51cto.com/wyfs02/M00/86/69/wKiom1e-WbuDrAxSAAAOBt0BH6M376.png"></a>
sidtype 有三種
None (0x0) – the service will not have a per-service SID. 服務預設設定為none
Unrestricted (0x1) – the service has a per-service SID 服務有一個service SID
Restricted (0x3) – the service has a per-service SID and a write-restricted token.服務有一個Service SID,同時加上了寫保護 标簽。
當服務配置使用Service SID時(無論restricted 或unrestricted) ,Service SID是一串SHA1 Hash.如果想看這個SID的具體值,可以使用
sc showsid <servicename>
<a href="http://s3.51cto.com/wyfs02/M01/86/69/wKiom1e-WbyT1eErAAAiLpaYGgw097.png"></a>
然後我們看看wsearch 的執行賬号配置為本地系統賬号
<a href="http://s3.51cto.com/wyfs02/M00/86/69/wKioL1e-Wb2xPzv8AAAklne2rPg071.png"></a>
那這個Service SID起了什麼作用呢,拿SQL Server為例,SQL Server 2008 r2 之前的版本會預設讓local system 賬号放在資料庫sysadmin 中,但是sql server 2012 之後就不放了,那麼之前如果你有個服務運作在local system 賬号,比如我們的SCOM監控服務通路SQL應該是沒有權限問題的,但是在sql server 2012 上,你可能需要額外設定,因為這個時候會沒有權限。這個時候我假設你給SCOM監控用戶端服務啟用了Service SID ,那麼會在healthservice的服務程序上就會增加 nt service\healthservice 的令牌,這個時候如果你單獨在SQL中建立nt service\healthservice 的登入,并賦予相應權限,那麼這個healthservice 雖然是運作在local system 賬号,但是他卻能通路sql了。然後你可能還有另外的其他服務B也是以local system 賬号運作,但是這個sql 的權限卻隻給了healthservice 服務,這個服務B卻不能通路SQL。(之前在沒有Service SID 的時候,你可能一股腦把權限開給了local system ,然後所有使用local system 登陸的服務都有了通路SQL 的權限)。
那麼這個Service SID的實戰作用在哪裡呢?這就是這篇文章的終極目的。如果你用SCOM 監控SQL,那麼更高版本的SQL Server的執行賬号管理的問題,你可能已經很頭痛了。使用service SID 可以輕松解決這個問題,然後還有個人專門另外建立了管理包,可以監視有SQL Server的機器上的healthservice 的Service SID有沒有開啟,然後可以用恢複任務來開啟(這個恢複任務預設是禁用的)。然後還可以監控healthservice 的SID賬号有沒有資料庫的權限。參考這個連結:
<a href="https://gallery.technet.microsoft.com/SQL-Server-RunAs-Addendum-0c183c32#content">https://gallery.technet.microsoft.com/SQL-Server-RunAs-Addendum-0c183c32#content</a>
windows内置系統賬号權限及作用參考:
Name: <code>NT AUTHORITY\LocalService</code>
the account has no password (any password information you provide is ignored)
HKCU represents the LocalService user account
has minimal privileges on the local computer
presents anonymous credentials on the network
SID: S-1-5-19
has its own profile under the HKEY_USERS registry key (<code>HKEY_USERS\S-1-5-19</code>)
A limited service account that is very similar to Network Service and meant to run standard least-privileged services. However, unlike Network Service it has no ability to access the network as the machine accesses the network as an Anonymous user.
<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684272%28v=vs.85%29.aspx">NetworkService account</a>
<code>NT AUTHORITY\NetworkService</code>
HKCU represents the NetworkService user account
presents the computer's credentials (e.g. <code>MANGO$</code>) to remote servers
SID: S-1-5-20
has its own profile under the HKEY_USERS registry key (<code>HKEY_USERS\S-1-5-20</code>)
If trying to schedule a task using it, enter <code>NETWORK SERVICE</code> into the Select User or Groupdialog
Limited service account that is meant to run standard least-privileged services. This account is far more limited than Local System (or even Administrator) but still has the right to access the network as the machine (see caveat above).
Name: <code>.\LocalSystem</code> (can also use <code>LocalSystem</code> or <code>ComputerName\LocalSystem</code>)
SID: S-1-5-18
does not have any profile of its own (<code>HKCU</code> represents the default user)
has extensive privileges on the local computer
<a href="http://windowsitpro.com/security/q-how-can-security-windows-service-benefit-service-isolation-feature-how-can-i-set-service-">http://windowsitpro.com/security/q-how-can-security-windows-service-benefit-service-isolation-feature-how-can-i-set-service-</a>
<a href="https://blogs.technet.microsoft.com/voy/2007/03/22/per-service-sid/">https://blogs.technet.microsoft.com/voy/2007/03/22/per-service-sid/</a>
<a href="https://support.microsoft.com/en-us/kb/2620201">https://support.microsoft.com/en-us/kb/2620201</a>
<a href="http://thoughtsonopsmgr.blogspot.com/2014/09/sql-mp-challenge-run-as-accounts.html">http://thoughtsonopsmgr.blogspot.com/2014/09/sql-mp-challenge-run-as-accounts.html</a>
版權聲明:原創作品,如需轉載,請注明出處。否則将追究法律責任
本文轉自 yoke88 51CTO部落格,原文連結:http://blog.51cto.com/yoke88/1842327