UAC e limitazioni per utenti membri del gruppo locale Administrators

L’introduzione della User Account Control (UAC) in Windows Vista e successivi comporta alcuni comportamenti in apparenza anomali in Esplora Risorse.

Si consideri in seguente scenario:

  • Un volume la cui security NTFS è così impostata:
    • SYSTEM con accesso FULL
    • Gruppo locale Administrators con accesso FULL
  • Un utente membro de gruppo locale Administrators

Quando l’utente tenta di accedere al volume tramite esplora risorse riceverà il messaggio Accesso Negato, mentre se lo stesso utente tenta di accedere alla cartella mediante il prompt dei comandi o Powershell avviati in modalità amministrativa riuscirà ad accedere alla cartella.

Avviando Esplora Risorse in modalità amministrativa è invece è possibile accedere al volume, per avviare Esplora Risorse in modalità amministrativa e senza supporto alla UAC è possibile eseguire il seguente comando da un prompt del comandi avviato in modalità amministrativa:

taskkill /F /IM explorer.exe & start explorer /nouaccheck

Il parametro /nouaccheck evita che l’operazione pianificata CreateExplorerShellUnelevatedTask abbatta Esplora Risorse se avviato con privilegi amministrativi, a riguardo si veda What is the CreateExplorerShellUnelevatedTask scheduled task?:

“Explorer needs to run non-elevated because it needs to be available to other applications which aren’t necessarily elevated. To ensure that it can do that, Explorer detects that it is running elevated and de-elevates itself by using a scheduled task called Create­Explorer­Shell­Unelevated­Task which does what it says on the tin: It launches Explorer un-elevated. The elevated version of Explorer exits after asking the scheduled task to run.

So the elevated Explorer exits, and is replaced by an un-elevated Explorer.

The Create­Explorer­Shell­Unelevated­Task is created on demand when Explorer is first launched elevated. If your system doesn’t have this task, then pat yourself on the back. It means that your system hasn’t ever needed it.”

In sintesi quando sia apre una sessione su un sistema con UAC attiva tramite le credenziali di un account membro del gruppo locale Administrators opera nel sistema senza privilegi amministrativi a meno che non dia l’approvazione ad usare i privilegi amministrativi quando questi necessitino per eseguire specifiche attività come descritto in How User Account Control works:

“By default, standard users and administrators access resources and run apps in the security context of standard users. When a user logs on to a computer, the system creates an access token for that user. The access token contains information about the level of access that the user is granted, including specific security identifiers (SIDs) and Windows privileges.

When an administrator logs on, two separate access tokens are created for the user: a standard user access token and an administrator access token. The standard user access token contains the same user-specific information as the administrator access token, but the administrative Windows privileges and SIDs are removed. The standard user access token is used to start apps that do not perform administrative tasks (standard user apps). The standard user access token is then used to display the desktop (explorer.exe). Explorer.exe is the parent process from which all other user-initiated processes inherit their access token. As a result, all apps run as a standard user unless a user provides consent or credentials to approve an app to use a full administrative access token.

A user that is a member of the Administrators group can log on, browse the Web, and read e-mail while using a standard user access token. When the administrator needs to perform a task that requires the administrator access token, Windows automatically prompts the user for approval. This prompt is called an elevation prompt, and its behavior can be configured by using the Local Security Policy snap-in (Secpol.msc) or Group Policy.”

Lo stesso concetto è ribadito anche nel seguente User Account Control Step-by-Step Guide:

“In Windows Vista, UAC and its Admin Approval Mode are enabled by default. When UAC is enabled, local administrator accounts run as standard user accounts. This means that when a member of the local Administrators group logs on, they run with their administrative privileges disabled. This is the case until they attempt to run an application or task that has an administrative token. When members of the local Administrators group attempt to start such an application or task, they are prompted to consent to running the application as elevated. Scenario 1 details the procedure to run an application or task as elevated one time.”

Questo significa che quando l’utente membro del gruppo locale Administrators prova ad accedere al volume verrà preso in considerazione il token in cui non sono presenti privilegi amministrativi che l’appartenenza al gruppo locale Administrators conferisce e di conseguenza non è possibile accedere al volume.

Per aggirare questo comportamento vi sono varie possibilità:

Metodo 1: Non utilizzare sul volume il gruppo locale Administrators per gestire la security NTFS, ma un gruppo locale o di dominio custom a cui l’utente dovrà appartenere, questa indicazione è suggerita nel seguente When you select Continue for folder access in Windows Explorer, your user account is added to the ACL for the folder anche se il contesto della problematica è differente la causa è la medesima:

“If you have an application-specific folder that’s locked down to prevent ordinary users from accessing it, you can also add permissions for a custom group and then add authorized users to that group. For example, consider a scenario in which an application-specific folder grants access only to the Administrators group and to the System account. In this situation, create a domain or a local AppManagers group, and then add authorized users to it. Then, use a utility such as icacls.exe, the security tab of the folder’s Properties dialog box, or the PowerShell Set-Acl cmdlet to grant the AppManagers group Full Control of the folder, in addition to the existing permissions.

Users who are members of AppManagers can use Windows Explorer to browse the folder without UAC having to change the folder’s permissions. This alternative applies only to application-specific folders. You should never make any permission changes to folders that are part of the Windows operating system, such as C:\Windows\ServiceProfiles.”

Metodo 2: Utilizzare un’applicazione che sia possibile eseguire in modalità amministrativa per accedere alla cartella come il prompt dei comandi o Powershell al posto di Esplora Risorse, questa indicazione è suggerita nel seguente When you select Continue for folder access in Windows Explorer, your user account is added to the ACL for the folder anche se il contesto della problematica è differente la causa è la medesima:

“To avoid changing permissions in a folder that’s accessible only to administrators, consider using another program that can run elevated instead of using Windows Explorer. Examples include Command Prompt, PowerShell, and the Computer Management MMC snap-in for share management.”

Metodo 3: Disabilitare la UAC, soluzione in sconsigliata in generale, ma consigliata i specifici scenari su Windows Server come indicato nel seguente How to disable User Account Control (UAC) on Windows Server:

“Under certain constrained circumstances, disabling UAC on Windows Server can be an acceptable and recommended practice. These circumstances occur only when both the following conditions are true:

  • Only administrators are allowed to sign in to the Windows server interactively at the console, or by using Remote Desktop Services.
  • Administrators sign in to the Windows-based server only to do legitimate system administrative functions on the server.

If either of these conditions isn’t true, UAC should remain enabled. For example, the server enables the Remote Desktop Services role so that nonadministrative users can sign in to the server to run applications. UAC should remain enabled in this situation. Similarly, UAC should remain enabled in the following situations:

Administrators run risky applications on the server. For example, web browsers, email clients, or instant messaging clients.
Administrators do other operations that should be done from a client operating system, such as Windows 7.”

Per la disabilitazione della UAC si veda anche quanto riportato in How User Account Control works:

“In order to fully disable UAC you must disable the policy User Account Control: Run all administrators in Admin Approval Mode.”

Metodo 4: Impostare sul volume un accesso in lettura per un gruppo diverso dal gruppo locale Administrators, questo consentirà ad Esplora Risorse si consentire l’accesso al volume e di richiedere poi l’approvazione per eseguire a operazioni quali creazione/eliminazione di cartelle, incolla/eliminazione/ridenominazione di file. Si noti però che Esplora Risorse non offrirà le voci di menù relative alla creazione dei file se su tale gruppo non verrà anche concesso il privilegio di scrittura. Un gruppo che  può avere senso utilizzare nel caso sia acceda tramite l’utente solo tramite Desktop Remoto è Remote Interactive Logon che come descritto nel seguente Special identity groups ha le seguenti caratteristiche:

“This identity represents all users who are currently logged on to a computer by using a Remote Desktop Protocol connection. This group is a subset of the Interactive group. Access tokens that contain the Remote Interactive Logon SID also contain the Interactive SID.”