index
int64
0
4.08k
text
stringlengths
34
4.9k
url
stringclasses
38 values
496
Discussion Depending on your environment, your DNS implementation may require that you cre‐ ate secondary zones to allow for load balancing for busy DNS servers or remote sites connected by slow links. In this situation, you want to allow zone transfers to occur between your AD integrated DNS servers and your secondary servers, but you want to restrict which hosts can initiate zone transfers with your AD integrated name servers. Allowing anyone to initiate a zone transfer with your domain controllers could provide an attacker with information for mapping out your network; it is therefore critical that you limit which hosts can pull zone transfers from your servers. If you are using only Active Directory−integrated zones, the Name Servers tab will be automatically populated with a list of all name servers that are authoritative for the selected zone, and this is the recommended choice when you have a large network with many name servers deployed. If any of your name servers are using standard zone files, however, you will need to populate this tab manually for any secondary name servers you deploy. Specifying a list of IP addresses for hosts that can initiate zone transfers may be more secure since it is more specific, but this approach has the trade-off of creating the ad‐ ditional management overhead of keeping track of the IP addresses of all name servers on your network, so you should follow this approach only if your network is small and you have relatively few name servers deployed. Another disadvantage of this approach is that if you forget to add some IP addresses of name servers to your list, zone infor‐ mation stored on those servers could become stale, causing name resolution to fail for some of your clients. This could result in some of your users experiencing difficulties in accessing network resources. DNS is secured, by default, because in the case of file-based zones, it is configured to allow zone transfers only with servers listed on the Name Servers tab of a zone. In the case of Active Directory integrated zones, DNS is configured to disallow zone transfers entirely—they generally aren’t needed in an Active Directory environment because the data replicates through Active Directory replication. See Also “Understanding zones and zone transfer” 13.7. Configuring Forwarding Problem You want to configure forwarding to allow for name resolution outside of your corporate network. 13.7. Configuring Forwarding | 471
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
497
Solution Using a graphical user interface 1. Open the DNS Management snap-in (dnsmgmt.msc). 2. Connect to the DNS server you want to modify. In the left pane, right-click on DNS and select Connect to DNS Server. Select “The following computer” and enter the target server name. Click OK. 3. Right-click on the server and select Properties. 4. Click the Forwarders tab. 5. Click the Edit button. 6. Enter the IP address, or DNS name, of the destination DNS server. 7. Click OK twice. Using a command-line interface The following command sets the default forwarders. Replace <IPsOfForwarders> with a space-separated list of IP addresses for the name servers to forward requests to: > dnscmd <ServerName> /resetforwarders <IPsOfForwarders> For example: > dnscmd dns01 /resetforwarders 10.22.3.4 10.22.3.5 The following command configures the default forwarder timeout: > dnscmd <ServerName> /config /forwardingtimeout <NumSeconds> The following command configures the forwarder timeout for a specific domain: > dnscmd <ServerName> /config <DomainName> /forwardertimeout <NumSeconds> Using PowerShell Set-DnsServerForwarder -IPAddress "<IPAddress>" -Timeout "<Value>" Discussion Name servers have long supported the notion of forwarders. Rather than sending all unresolved queries to the root Internet name servers, you can use forwarders to send queries to a specific server or set of servers, perhaps hosted by your ISP or by a partner corporation. This allows you to better control the name resolution process on your network. 472 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
498
Using PowerShell By using the –PassThru switch, you can see the object that you are working with and the values of the properties. See Also MS KB 304491 (Conditional Forwarding in Windows Server 2003); MS KB 811118 (Support WebCast: Microsoft Windows Server 2003 DNS: Stub Zones and Conditional Forwarding) 13.8. Configuring Conditional Forwarding Problem You want to configure forwarding for specific domain names. Solution Using a graphical user interface 1. Open the DNS Management snap-in (dnsmgmt.msc). 2. Connect to the DNS server that you want to modify. In the left pane, right-click on DNS and select Connect to DNS Server. Select “The following computer” and enter the target server name. Click OK. 3. Expand the DNS server and then right-click on Conditional Forwarders. Click New Conditional Forwarder. 4. Enter the DNS name of the domain you wish to forward. 5. Enter the IP address or DNS name of the destination DNS server. 6. Choose whether to store the forwarder in Active Directory or to modify the query timeout period, and then click OK. Using a command-line interface dnscmd <ServerName> /zoneadd <DomainName> /forwarder <IPsOfForwarders> Using PowerShell Add-DnsServerConditionalForwarderZone "<DomainName>" -MasterServers↵ "<IPAddress>" -ReplicationScope <Forest|Domain|Legacy|Custom>↵ -ForwarderTimeout "<Value>" 13.8. Configuring Conditional Forwarding | 473
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
499
Discussion With conditional forwarding, you can forward unresolved queries for specific domains to different name servers. The most common use of conditional forwarding is when you have two or more noncontiguous namespaces. Consider, for example, a merger between the adatum.com and othercorp.com corporations. Normally, for the name servers of adatum.com to resolve queries for othercorp.com, the queries would have to first be forwarded to the root Internet name servers. With conditional forwarding, you can configure the adatum.com DNS servers so that all requests for othercorp.comshould be sent directly to the othercorp.com name servers and all other unresolved queries should be sent to the Internet, and vice versa. The trade-off for this feature is the addi‐ tional CPU processing that’s necessary to examine each query and forward it to the appropriate server, rather than just funneling all unresolved queries to a single external server. 13.9. Delegating Control of an Active Directory Integrated Zone Problem You want to delegate control of managing the resource records in a zone. Solution Using a graphical user interface 1. Open the DNS Management snap-in (dnsmgmt.msc). 2. If an entry for the DNS server you want to connect to does not exist, right-click on DNS in the left pane and select Connect to DNS Server. Select “This computer” or “The following computer”, and then enter the server you want to connect to (if applicable) and click OK. 3. Expand the server in the left pane and expand either Forward Lookup Zones or Reverse Lookup Zones, depending on the type of zone. 4. Right-click on the name of the zone and select Properties. 5. Click on the Security tab. 6. Click the Add button. 7. Use the Object Picker to locate the user or group to which you want to delegate control. 474 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
500
8. Under Permissions, check the Full Control box. 9. Click OK. Using a command-line interface The following command grants full control over managing the resource records in an AD integrated zone: > dsacls dc=<ZoneName>,cn=MicrosoftDNS,<DomainOrAppPartitionDN>↵ /G<UserOrGroup>:GA Using PowerShell The following script delegates full control of an AD integrated DNS zone to a particular user or group: $Path = [ADSI]"LDAP://dc=<ZoneName>,cn=MicrosoftDNS,cn=System,↵ <DomainOrAppPartitionDN>" $Group = New-Object System.Security.Principal.NTAccount("<UserorGroup>") $IdentityReference = $Group.Translate↵ ([System.Security.Principal.SecurityIdentifier]) $Perms = New-Object System.DirectoryServices.ActiveDirectoryAccessRule↵ ($IdentityReference,"GenericAll","Allow") $Path.psbase.ObjectSecurity.AddAccessRule($Perms) $Path.psbase.commitchanges() Discussion By default, members of the DNSAdmins group have control over DNS server and zone configuration. You can delegate control of individual AD integrated zones by modifying permissions on the zone object in AD. The solutions show examples for how to grant full control to an additional user or group over a particular zone. See Also MS KB 256643 (Unable to Prevent DNS Zone Administrator from Creating New Zones) 13.10. Creating and Deleting Resource Records Problem You want to create and delete resource records in a zone. 13.10. Creating and Deleting Resource Records | 475
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
501
Solution Using a graphical user interface 1. Open the DNS Management snap-in (dnsmgmt.msc). 2. If an entry for the DNS server you want to connect to does not exist, right-click on DNS in the left pane and select Connect to DNS Server. Select “This computer” or “The following computer,” and then enter the server you want to connect to (if applicable) and click OK. 3. If you want to add or delete a record in a forward zone, expand the Forward Lookup Zone folder. If you want to add or delete a record for a reverse zone, expand the Reverse Lookup Zone folder. To create a resource record, do the following: 1. In the left pane, right-click the zone and select the option that corresponds to the record type you want to create—for example, New Host (A). 2. Fill in all required fields. 3. Click OK. To delete a resource record, do the following: 1. In the left pane, click on the zone the record is in. 2. In the right pane, right-click on the record you want to delete and select Delete. 3. Click Yes to confirm. Using a command-line interface To add a resource record, use the following command: > dnscmd <DNSServerName> /recordadd <ZoneName> <NodeName> <RecordType> <RRData> The following command adds an A record in the adatum.com zone: > dnscmd dc1 /recordadd adatum.com Server01 A 192.168.52.2 To delete a resource record, use the following command: > dnscmd <DNSServerName> /recorddelete <ZoneName> <NodeName> <RecordType>↵ <RRData> The following command deletes an A record in the adatum.com zone: > dnscmd dc1 /recorddelete adatum.com wins01 A 192.168.52.2 476 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
502
Using PowerShell There are several PowerShell cmdlets available to create resource records for DNS zones: Add-DnsServerResourceRecord This cmdlet adds an available resource record for a given zone. Add-DnsServerResourceRecordA This cmdlet adds an A type record for IPv4 hosts in a given zone. Add-DnsServerResourceRecordAAAA This cmdlet adds an AAAA type record for IPv6 hosts in a given zone. Add-DnsServerResourceRecordCName This cmdlet adds a CNAME type record for a given zone. Add-DnsServerResourceRecordDnsKey This cmdlet adds a DNS Key record for DNSSEC zones. Add-DnsServerResourceRecordDS This cmdlet creates a Delegation of Signing record for a signed zone file. Add-DnsServerResourceRecordMX This cmdlet creates an MX record for mail records in a given zone. Add-DnsServerResourceRecordPtr This cmdlet creates a PTR record for reverse DNS lookup. The following will add an A record named Host01 that corresponds to the IP address 10.0.0.3, in the adatum.com zone: Add-DnsServerResourceRecordA -Name "Host01" -IPv4Address "10.0.0.3"↵ -ZoneName "adatum.com" The following will delete an A record named Host01, without prompting for confir‐ mation, from the adatum.com zone: Remove-DnsServerResourceRecord -ZoneName "adatum.com" -Name "Host01"↵ -RRType "A" -Force Discussion Using a graphical user interface The DNS Management snap-in is good for creating a small number of records, but if you need to add or delete more than a couple of dozen, then we’d recommend writing a PowerShell script to automate the process. 13.10. Creating and Deleting Resource Records | 477
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
503
Using a command-line interface Adding A, CNAME, and PTR resource records is pretty straightforward in terms of the data you must enter, but other record types, such as SRV, require quite a bit more data. The help pages for /recordadd and /recorddelete display the required information for each record type. For example, to add an SRV record using dnscmd, you need to specify the priority, weight, port, and hostname of the record, as in the following example: > dnscmd /recordadd adatum.com dc1.adatum.com SRV _kerberos 50 100 88 See Also MSDN: MicrosoftDNS_ResourceRecord 13.11. Querying Resource Records Problem You want to query resource records. Solution Using a graphical user interface 1. Open the DNS Management snap-in (dnsmgmt.msc). 2. If an entry for the DNS server you want to connect to does not exist, right-click on DNS in the left pane and select Connect to DNS Server. Select “This computer” or “The following computer.” and then enter the server you want to connect to (if applicable) and click OK. 3. Expand the lookup zone folder and then select the zone you wish to filter. 4. Right-click the zone name and select View→Filter. 5. Enter the filter parameters and then click OK. 6. Right-click the zone name again and click Refresh. Using a command-line interface In the following command, replace <RecordType> with the type of resource record you want to find (e.g., A, CNAME, SRV) and <RecordName> with the name or IP address of the record to match: > nslookup -type=<RecordType> <RecordName> 478 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
504
Using PowerShell Get-DnsServerResourceRecord -ZoneName "<ZoneName>" -RRType "A" Discussion Using a command-line interface You can leave off the -type switch, and the command will find any A, PTR, and CNAME records that match <RecordName>. You can also run nslookup from interactive mode, which can be entered by typing nslookup at a command prompt with no additional parameters, or you can switch back and forth between query types by using the set q=ANY command to reset nslookup. Interactive mode allows you to issue a series of queries with more efficiency because you don’t have to type nslookup or wait for the initial connection to the DNS server. See Also MSDN: MicrosoftDNS_ResourceRecord; RFC 1035 (Domain Names—Implementa‐ tion and Specification); RFC 1700 (DNS Parameters) 13.12. Modifying the DNS Server Configuration Problem You want to modify the DNS server settings. Solution Using a graphical user interface 1. Open the DNS Management snap-in (dnsmgmt.msc). 2. If an entry for the DNS server you want to connect to does not exist, right-click on DNS in the left pane and select Connect to DNS Server. Select “This computer” or “The following computer”, and then enter the server you want to connect to (if applicable) and click OK. 3. Right-click on the server and select Properties. 4. Edit the server settings from the tabs that are displayed. 5. Click OK to commit the changes after you complete your modifications. 13.12. Modifying the DNS Server Configuration | 479
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
505
Using a command-line interface With the following command, replace <Setting> with the name of the setting to modify and <Value> with the value to set: > dnscmd <DNSServerName> /config /<Setting> <Value> The following command enables the EnableDnsSec setting on dns01: > dnscmd dns01 /config /EnableDnsSec 1 The following command disables the NoTcp setting on the local host: > dnscmd /config /NoTcp 0 The following command sets the DsPollingInterval setting to 60 on dns02: > dnscmd dns02 /config /DsPollingInterval 60 For the complete list of settings, run dnscmd /config from the command line. Using PowerShell There are several Windows PowerShell cmdlets that you can use to set DNS properties. To view a list of all available cmdlets that set DNS properties, use the following command: Get-Command *Set-Dns* Discussion The Microsoft DNS server supports a variety of settings to configure everything from scavenging and forwarders to logging. With the DNS Management snap-in, the settings are spread over several tabs in the Properties page. You can get a list of these settings by simply running dnscmd /config from a command line. See Also MSDN: MicrosoftDNS_Server 13.13. Scavenging Old Resource Records Problem You want to scavenge old resource records. DNS scavenging is the process whereby resource records are automatically removed if they are not updated after a period of time. Typically, this applies only to resource records that were added via dynamic DNS (DDNS), but you can also scavenge manually created static records. DNS scavenging is a recommended practice so that your DNS zones are automatically kept clean of stale resource records. 480 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
506
Solution The following solutions will show how to enable automatic scavenging on all AD inte‐ grated zones. Using a graphical user interface 1. Open the DNS Management snap-in (dnsmgmt.msc). 2. If an entry for the DNS server you want to connect to does not exist, right-click on DNS in the left pane and select Connect to DNS Server. Select “This computer” or “The following computer”, and then enter the server you want to connect to (if applicable) and click OK. 3. Click on the server, right-click on it, and select “Set Aging/Scavenging for all zones”. 4. Check the box beside “Scavenge stale resource records”. 5. Configure the No-Refresh and Refresh intervals as necessary, and click OK. 6. Check the box beside “Apply these settings to the existing Active Directory￾integrated zones” and click OK. 7. Right-click on the server again and select Properties. 8. Select the Advanced tab. 9. Check the box beside “Enable automatic scavenging of stale resource records”. 10. Configure the scavenging period as necessary. 11. Click OK. Using a command-line interface > dnscmd <DNSServerName> /config /ScavengingInterval <ScavengingMinutes> > dnscmd <DNSServerName> /config /DefaultAgingState 1 > dnscmd <DNSServerName> /config /DefaultNoRefreshInterval <NoRefreshMinutes> > dnscmd <DNSServerName> /config /DefaultRefreshInterval <RefreshMinutes> > dnscmd <DNSServerName> /config ..AllZones /aging 1 Using PowerShell Set-DnsServerScavenging -ScavengingState $True -RefreshInterval "<Value>"↵ -ScavengingInterval "<Value>" Start-DnsServerScavenging -Force Discussion There are four settings that you need to be aware of before enabling scavenging. You must use caution when enabling scavenging, because an incorrect configuration could lead to resource records getting deleted by mistake. 13.13. Scavenging Old Resource Records | 481
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
507
The first setting you have to configure is the scavenging interval. This is the interval in which the DNS server will kick off the scavenging process. It is disabled by default so that scavenging does not take place unless you enable this setting. The default value is seven days. The second setting is the default aging configuration setting for new zones. If you want all new zones to be configured for scavenging, set this to 1. The next two settings control how records get scavenged. The no-refresh interval de‐ termines how much time must pass before a dynamically updated record can be updated again. This setting is necessary to reduce how often a DNS server has to update its timestamp of the resource record. The default value is seven days. This means that after a resource record has been dynamically updated, the server will not accept another dynamic update for the same record for another seven days. However, if the IP address or some other data for the record changes, the server will still accept the new informa‐ tion. Static records have a timestamp of 0 and will not get scavenged in an automated scavenging process. The refresh interval setting is the amount of time that must pass after the no-refresh interval during which a client can update its record before it is considered old or stale. The default value for this setting is also 168 hours (seven days). If you use the default values, the combination of the no-refresh interval and refresh interval would mean that a dynamically updated record would not be considered stale for up to 14 days after its most recent update. Combine this with the default scavenging interval, and it could be up to 21 days before a record is deleted if the record became stale immediately after the last scavenge process completed: 7 days (no refresh) + 7 days (refresh) + up to 7 days (scavenge process) = up to 21 days. The solutions in this recipe show you how to configure these settings for all zones that are hosted on a server; however, you can configure these settings for individual zones as well. In the GUI solution, you would do this by accessing the Properties sheet of an individual zone rather than the server node; in dnscmd, simply specify the zone name after /aging, /scavenginginterval, /defaultagingstate, /defaultnorefreshin terval, or /defaultrefreshinterval. 13.14. Clearing the DNS Cache Problem You want to clear the DNS cache. The DNS cache contains resource records that are cached by the server or workstation for a period of time in memory so that repeated requests for the same record can be returned immediately. There are two types of DNS cache. One pertains to the cache on the Windows DNS client resolver (this can refer to both server and workstation operating systems when they are requesting DNS 482 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
508
information from a server), and the other refers to the cache used by the Microsoft DNS server software. Solution To flush the client resolver cache, use the following command: > ipconfig /flushdns To flush the client resolver cache by using PowerShell, use the following cmdlet: Clear-DnsClientCache To flush the DNS server cache, use any of the following solutions. Using a graphical user interface 1. Open the DNS Management snap-in (dnsmgmt.msc). 2. Right-click on DNS in the left pane and select Connect to DNS Server. 3. Enter the server you want to connect to and click Enter. 4. Right-click on the server and select Clear Cache. Using a command-line interface The following command will clear the cache on <DNSServerName>. You can leave out the <DNSServerName> parameter to simply run the command against the local server: > dnscmd <DNSServerName> /clearcache Using PowerShell Clear-DnsServerCache -Force Discussion The client resolver cache is populated whenever a DNS lookup is performed on a work‐ station or server (e.g., by visiting a website in Internet Explorer, a DNS lookup is per‐ formed and cached). It’s important to remember that this cache will store positive DNS responses as well as negative ones. For example, if lost network connectivity causes DNS queries for an external resource like a mail server to fail, those queries will continue to fail until the cache refreshes: the queries have been negatively cached. The second type of cache is in place on Microsoft DNS servers and on some third-party DNS servers. It is a cache of all DNS requests that the server has made while processing queries from various clients. You can view this cache by browsing the Cached Lookups folder for a server in the DNS Management snap-in. This folder is not shown by default, so you’ll need to select Advanced from the View menu. 13.14. Clearing the DNS Cache | 483
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
509
With both the client and server cache, records are removed from the cache after the record’s TTL value expires. The TTL is used to age records so that clients and servers will request an updated copy of the record at a later point in order to receive any changes that may have occurred. 13.15. Verifying That a Domain Controller Can Register Its Resource Records Problem You want to verify that DNS is configured correctly so that a domain controller can register its resource records, which are needed for clients to be able to locate various AD services. Solution Using a command-line interface With the following dcdiag command, replace <DomainName> with the FQDN of the domain that the domain controller is in. This command has to be run from the domain controller you want to test, not from an administrative workstation: > dcdiag /test:RegisterInDNS /DnsDomain:<DomainName> Starting test: RegisterInDNS DNS configuration is sufficient to allow this domain controller to↵ dynamically register the domain controller Locator records in DNS. The DNS configuration is sufficient to allow this computer to dynamically↵ register the A record corresponding to its DNS name. Using PowerShell Test-DnsServer "<IPAddress>" Discussion With the default setup, domain controllers attempt to dynamically register the resource records necessary for them to be located by Active Directory clients and other domain controllers. Domain controllers must have their resource records populated in DNS in order to function, but it can be very tedious and error-prone to register all of the records manually. This is why allowing the domain controllers to use DDNS to automatically register and update their records can be much easier from a support standpoint. 484 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
510
The dcdiag command provides a RegisterInDNS switch that allows you to test whether the DC can register its records. In the solution, we showed the output if the domain controller passes the test. Here is the output if an error occurs: Starting test: RegisterInDNS This domain controller cannot register domain controller Locator DNS↵ records. This is because it cannot locate a DNS server authoritative for the↵ zone adatum.com. This is due to one of the following: 1. One or more DNS servers involved in the name resolution of the adatum.com↵ name are not responding or contain incorrect delegation of the DNS zones; or 2. The DNS server that this computer is configured with contains incorrect↵ root hints. The list of such DNS servers might include the DNS servers with which this↵ computer is configured for name resolution and the DNS servers responsible↵ for the following zones: adatum.com Verify the correctness of the specified domain name and contact your↵ network/DNS administrator to fix the problem. You can also manually add the records specified in the↵ %systemroot%\system32\config\netlogon.dns file. As you can see, the output of dcdiag offers some options for resolving the problem. The information provided will also vary depending on the error encountered. See Also Recipe 13.17 for registering a domain controller’s resource records 13.16. Enabling DNS Server Debug Logging Problem You want to enable DNS debug logging to troubleshoot issues related to DNS queries or updates. Solution Using a graphical user interface 1. From the Administrative Tools, Open the DNS Management snap-in (dnsmgmt.msc). 13.16. Enabling DNS Server Debug Logging | 485
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
511
2. Connect to the DNS Server you want to modify. In the left pane, right-click on DNS and select Connect to DNS Server. Select “The following computer” and enter the target server name. Click OK. 3. Right-click on the server and select Properties. 4. Click on the Debug Logging tab. 5. Select what you want to log and the location of the logfile. 6. Click OK. Using a command-line interface Use the following four commands to enable debug logging. For the log level, you have to add together the event codes you want logged and specify the result in hex. The available event codes can be found in Table 13-3. > dnscmd <ServerName> /Config /LogLevel <EventFlagSumInHex> Use the following command to specify the location of the logfile: > dnscmd <ServerName> /Config /LogFilePath <DirectoryAndFilePath> Use the following command to log only entries that pertain to certain IP addresses: > dnscmd <ServerName> /Config /LogIPFilterList <IPAddress1>[,<IPAddress2>...] Use the following command to specify the maximum logfile size: > dnscmd <ServerName> /Config /LogFileMaxSize <NumberOfBytesInHex> Use the following command to disable debug logging: > dnscmd <ServerName> /Config /LogLevel 0 Using PowerShell Set-DnsServerDiagnostics -SaveLogsToPersistentStorage $True↵ -LogFilePath "<LogFilePath>" Discussion With the DNS Server debug log, you can record all DNS operations received and initi‐ ated by the server, including queries, updates, zone transfers, etc. If you need to trou‐ bleshoot a particular host, you can use the LogIPFilterList setting in dnscmd or the WMI DNS Provider to restrict the log to operations performed only for or by that host. The most important debug log setting is the log level. With the DNS snap-in, you can select from a list of available options. The DNS snap-in provides an intuitive interface for selecting the required options. Table 13-3 contains all of the event codes with their hexadecimal and decimal values for the command-line options. 486 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
512
Table 13-3. DNS debug logging event codes Hexadecimal value Decimal value Descriptions 0x0 0 No logging. This is the default. 0x1 1 Query transactions. 0x10 16 Notifications transactions. 0x20 32 Update transactions. 0xFE 254 Nonquery transactions. 0x100 256 Question packets. 0x200 512 Answer packets. 0x1000 4096 Send packets. 0x2000 8192 Receive packets. 0x4000 16384 UDP packets. 0x8000 32768 TCP packets. 0xFFFF 65535 All packets. 0x10000 65536 AD write transactions. 0x20000 131072 AD update transactions. 0x1000000 16777216 Full packets. 0x80000000 2147483648 Write-through transactions. DNS debug logging can come in handy if you want to look at the dynamic update requests a particular DNS server is processing. For example, if a client or DHCP server is attempting to dynamically register records, you can enable the Update Transactions log category on the DNS server you think should be processing the updates. If you don’t see any update transactions, this can indicate that another server is processing the dy‐ namic update requests. Transactions are not immediately written to the debug logfile as they occur. They are buffered and written to the file after a certain number of requests are processed. See Also MSDN: MicrosoftDNS_Server 13.16. Enabling DNS Server Debug Logging | 487
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
513
13.17. Registering a Domain Controller’s Resource Records Problem You want to manually force registration of a domain controller’s resource records. This may be necessary if you’ve made some configuration changes on your DNS servers to allow your domain controllers to start dynamically registering resource records. Solution Using a command-line interface > nltest /dsregdns /server:<DomainControllerName> Discussion With the nltest command, a /dsregdns switch allows you to force registration of the domain-controller-specific resource records. You can also force reregistration of its re‐ source records by restarting the NetLogon service on the domain controller. The Net‐ Logon service automatically attempts to reregister a domain controller’s resource re‐ cords every hour, so if you can wait that long, you do not need to use nltest. See Also Recipe 13.15 for verifying whether a domain controller is registering its resource records 13.18. Deregistering a Domain Controller’s Resource Records Problem You want to manually deregister a domain controller’s resource records. Solution Using a command-line interface With the following nltest command, replace <DomainControllerName> with the FQDN of the domain controller you want to deregister and <DomainDNSName> with the FQDN of the domain of which the domain controller is a member: > nltest /dsderegdns: <DomainControllerName> /dom:<DomainDNSName> 488 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
514
Discussion When a domain controller is demoted from a domain, it dynamically deregisters its resource records. This is a nice feature of the demotion process because it means you do not have to manually remove all of the resource records or wait for scavenging to remove them. If, however, you have a domain controller that crashes and you do not plan to bring it back online, you’ll need to remove the records manually or wait for the scavenging process to take place. You can use the DNS Management MMC snap-in and even the dnscmd.exe utility to manually remove them one by one, or you can use nltest, as shown in the solution. The /dsderegdns switch also has /DomGUID and /DsaGUID options if you want to delete the records that are based on the domain GUID and DSA GUID, respectively. You need to know the actual GUIDs of the domain and domain controller to use those switches, so if you don’t have them handy, it would be easier to delete them using the DNS Man‐ agement MMC snap-in. 13.19. Preventing a Domain Controller from Dynamically Registering All Resource Records Problem You want to prevent a domain controller from dynamically registering its resource re‐ cords using DDNS. If you manually register a domain controller’s resource records, you’ll want to prevent those domain controllers from attempting to dynamically register them. If you do not disable them from sending dynamic update requests, you may see annoying error messages on your DNS servers that certain DDNS updates are failing. Solution Using a command-line interface > reg add HKLM\System\CurrentControlSet\Services\Netlogon\Parameters /v↵ UseDynamicDNS /t REG_DWORD /d 0 The operation completed successfully. > net stop netlogon The Net Logon service is stopping. The Net Logon service was stopped successfully. > del %SystemRoot%\system32\config\netlogon.dnb > net start netlogon The Net Logon service is starting....... The Net Logon service was started successfully. 13.19. Preventing a Domain Controller from Dynamically Registering All Resource Records | 489
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
515
Using PowerShell $strRegPath = "HKLM:\System\CurrentControlSet\Services\Netlogon\Parameters" new-ItemProperty -path $strRegPath -name "UseDynamicDNS" -type DWORD set-ItemProperty -path $strRegPath -name "UseDynamicDNS" -value "0" Stop-Service netlogon $strPath = join-path (get-content env:SystemRoot) system32\config\netlogon.dnb Remove-Item $strPath Start-Service netlogon Discussion By default, domain controllers attempt to dynamically register their Active Directory −related resource records every hour via the NetLogon service. You can prevent a do‐ main controller from doing this by setting the UseDynamicDNS value to 0 under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Netlogon\Parameters. After you set that value, you should stop the NetLogon service, remove the %SystemRoot %\system32\config\netlogon.dnb file and then restart NetLogon. It is necessary to re‐ move the netlogon.dnb file because it maintains a cache of the resource records that are dynamically updated. This file will get re-created when the NetLogon service restarts. See Also Recipe 13.20 for preventing certain resource records from being dynamically registered; MS KB 198767 (How to Prevent Domain Controllers from Dynamically Registering DNS Names) 13.20. Preventing a Domain Controller from Dynamically Registering Certain Resource Records Problem You want to prevent a domain controller from dynamically registering certain resource records. It is sometimes advantageous to prevent certain resource records from being dynamically registered. For example, if you want to reduce the load on the PDC Emu‐ lator for a domain, you can prevent some of its SRV records from being published, which would reduce the amount of client traffic the server receives. Solution Using a graphical user interface 1. Open the Group Policy Management snap-in (gpmc.msc). 490 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
516
2. Create a GPO linked to the Domain Controllers OU, or else edit an existing GPO. 3. Select Computer Configuration→Policies→Administrative Templates→Sys‐ tem→Net Logon→DC Locator DNS Records. 4. Enable the “Specify DC Locator DNS records not registered by the DCs” setting, and list one or more of the following record types that should not be registered: • Dc • DcAtSite • DcByGuid • Gc • Gc • GcAtSite • GcIpAddress • GenericGc • Kdc • Ldap • LdapIpAddress • Rfc1510Kdc • Rfc1510Kpwd • Rfc1510UdpKdc • Rfc1510UdpKpwd Using a command-line interface This command will disable the Ldap, Gc, and GcIpAddress resource records from being dynamically registered: > reg add HKLM\System\CurrentControlSet\Services\Netlogon\Parameters↵ /v DnsAvoidRegisterRecords /t REG_MULTI_SZ /d Ldap\0Gc\0GcIpAddress > net stop netlogon > del %SystemRoot%\system32\config\netlogon.dnb > net start netlogon Using PowerShell $strRegPath = "HKLM:\System\CurrentControlSet\Services\Netlogon\Parameters" $arrValues = "Ldap", "Gc", "GcIpAddress" 13.20. Preventing a Domain Controller from Dynamically Registering Certain Resource Records | 491
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
517
New-ItemProperty -Path $strRegPath -Name "DnsAvoidRegisterRecords" -Type↵ MultiString Set-ItemProperty -Path $strRegPath -Name "DnsAvoidRegisterRecords" -Value↵ $arrValues Stop-Service netlogon $strPath = Join-Path (Get-Content env:SystemRoot) system32\config\netlogon.dnb Remove-Item $strPath Start-Service netlogon Discussion The procedure to disable registration of certain resource records is very similar to that described in Recipe 13.19 for preventing all resource records from being dynamically registered; however, in this case you need to create a value called DnsAvoidRegisterRe cords under the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Net logon\Parameters key. The type for DnsAvoidRegisterRecords should be REG_MUL TI_SZ, and the data should be a whitespace-separated list of mnemonics. Mnemonics are used to represent various resource records that domain controllers register. The complete list of mnemonics is included in Table 13-4. You can also control these values using Group Policy, in Computer Con figuration\Policies\Administrative Templates\System\Netlogon. Table 13-4. Registry mnemonics for resource records Registry mnemonic Resource record type Resource record name LdapIpAddress A <DnsDomainName> Ldap SRV _ldap._tcp.<DnsDomainName> LdapAtSite SRV _ldap._tcp.<SiteName>._sites.<DnsDomainName> Pdc SRV _ldap._tcp.pdc._msdcs.<DnsDomainName> Gc SRV _ldap._tcp.gc._msdcs.<DnsForestName> GcAtSite SRV _ldap._tcp.<SiteName>._sites.gc._msdcs.<DnsForest Name> DcByGuid SRV _ldap._tcp.<DomainGuid>.domains._msdcs.<DnsForest Name> GcIpAddress A _gc._msdcs.<DnsForestName> DsaCname CNAME <DsaGuid>._msdcs.<DnsForestName> Kdc SRV _kerberos._tcp.dc._msdcs.<DnsDomainName> KdcAtSite SRV _kerberos._tcp.dc._msdcs.<SiteName>._sites. <DnsDo mainName> 492 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
518
Registry mnemonic Resource record type Resource record name Dc SRV _ldap._tcp.dc._msdcs.<DnsDomainName> DcAtSite SRV _ldap._tcp.<SiteName>._sites.dc._msdcs.<DnsDomain Name> Rfc1510Kdc SRV _kerberos._tcp.<DnsDomainName> Rfc1510KdcAtSite SRV _kerberos._tcp.<SiteName>._sites.<DnsDomainName> GenericGc SRV _gc._tcp.<DnsForestName> GenericGcAtSite SRV _gc._tcp.<SiteName>._sites.<DnsForestName> Rfc1510UdpKdc SRV _kerberos._udp.<DnsDomainName> Rfc1510Kpwd SRV _kpasswd._tcp.<DnsDomainName> Rfc1510UdpKpwd SRV _kpasswd._udp.<DnsDomainName> If you configure DCs not to register these domain-wide SRV records, such as in a branch office environment, your branch office clients will still fail over to DCs in your hub site if their local DC becomes unavailable. Clients will continue to use the hub site DCs until they are rebooted, even if the local DC comes back online. MS KB 939252 provides a hotfix for Windows XP and Windows Server 2003 that will improve client failover be‐ havior in this scenario. In Windows operating systems since Windows XP, there is im‐ provement and built-in control available. See TechNet for more details. See Also Recipe 13.19 for preventing all resource records from being dynamically registered 13.21. Allowing Computers to Use a Domain Suffix That Is Different from Their AD Domain Problem You want to allow computers to use a domain suffix that is different from their AD domain. Solution Using a graphical user interface 1. Open ADSI Edit. 2. Connect to the domain you want to edit. 3. Right-click on the domainDNS object and select Properties. 13.21. Allowing Computers to Use a Domain Suffix That Is Different from Their AD Domain | 493
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
519
4. Edit the msDS-AllowedDNSSuffixes attribute and the DNS suffix you want to add. 5. Click OK. Using a command-line interface Create an LDIF file called add_dns_suffix.ldf with the following contents: dn: <DomainDN> changetype: modify add: msDS-AllowedDNSSuffixes msDS-AllowedDNSSuffixes: <DNSSuffix> - Then run the following command: > ldifde -v -i -f add_dns_suffix.ldf.ldf You can also make this change using AdMod, as follows: > admod -b <DomainDN> msDS-AllowedDNSSuffixes:+:<DNSSuffix> Using PowerShell You can modify the list of allowed DNS suffixes for a domain using PowerShell, as follows: Set-ADObject "<DomainDN>" -Add @{"msDS-AllowedDNSSuffixes"="<Suffix>"} Discussion Windows Server and client domain members dynamically maintain the dNSHostName and servicePrincipalName attributes of their corresponding computer object in Active Directory with their current hostname. By default, those attributes can only contain hostnames that have a DNS suffix equal to the Active Directory domain the computer is a member of. If the computer’s DNS suffix is not equal to the Active Directory domain, as may be the case during a domain migration or a corporate merger or consolidation, 5788 and 5789 events will be generated in the System event log on the domain controllers the clients attempt to update. These events report that the dnsHostName and servicePrincipal Name attributes could not be updated due to an incorrect domain suffix. You can avoid this by adding the computer’s DNS suffix to the msDS-AllowedDNSSuffixes attribute on the domain object (e.g., dc=adatum,dc=com). See Also MS KB 258503 (DNS Registration Errors 5788 and 5789 When DNS Domain and Active Directory Domain Name Differ) 494 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
520
13.22. Authorizing a DHCP Server Problem You want to permit (i.e., authorize) a DHCP server to process DHCP requests from clients. This is necessary only if the DHCP server is a member of an Active Directory domain. Solution Using a graphical user interface 1. Open the DHCP snap-in (dhcpmgmt.msc). 2. If necessary, in the left pane, right-click on DHCP and select Add Server. Type in the name of the DHCP server you want to target and click OK. 3. Click on the server entry in the left pane. 4. Right-click on the server and select Authorize. If the DHCP server is not a member of an Active Directory domain, you will not see the Authorize option. Using a command-line interface The following command authorizes a DHCP server in Active Directory: > netsh dhcp add server <DHCPServerName> <DHCPServerIP> This example shows how to authorize the DHCP server named dhcp01.adatum.com with IP 192.168.191.15: > netsh dhcp add server dhcp01.adatum.com 192.168.191.15 Using PowerShell The following PowerShell command will authorize a DHCP server in Active Directory: Add-DhcpServerInDC -DnsName "<ServerName>" Discussion Windows-based DHCP servers that belong to an Active Directory domain must be authorized before they can give leases to clients. This feature helps reduce the danger of a rogue Windows DHCP server that an end user sets up, perhaps even unintentionally. 13.22. Authorizing a DHCP Server | 495
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
521
However, this still doesn’t prevent someone from plugging in a non-Windows DHCP server (e.g., a Linksys router with the DHCP server enabled) and causing clients to receive bad leases. A rogue DHCP server can provide incorrect lease information or deny lease requests altogether, ultimately causing a denial of service for clients on your network. A DHCP server that is a member server of an Active Directory domain performs a query in Active Directory to determine whether it is authorized. If it is, it will respond to DHCP requests; if not, it will not respond to requests. A standalone Windows DHCP server that is not a member of an Active Directory do‐ main sends out a DHCPINFORM message when it first initializes. If an authorized DHCP server responds to the message, the standalone server will not respond to any further DHCP requests. If it does not receive a response from a DHCP server, it will respond to client requests and distribute leases. DHCP servers are represented in Active Directory as objects of the dhcpClass class, in the cn=NetServices,cn=Services,cn=Configuration,<ForestRootDN> container. The relative distinguished name of these objects is the IP address of the DHCP server. There is also an object in the same container named cn=dhcpRoot, which is created after the first DHCP server is authorized. It has an attribute named dhcpServers that contains all authorized servers. By default, only members of the Enterprise Admins group can authorize DHCP servers. However, you can delegate the rights to authorize a DHCP server. Do the following to delegate the necessary permissions to a group called DHCP Admins: 1. Open ADSI Edit from the Support Tools while logged on as a member of the Enterprise Admins group. 2. In the left pane, expand the Configuration Container→cn=Configura tion→cn=Services→cn=NetServices. 3. Right-click on cn=NetServices and select Properties. 4. Select the Security tab. 5. Click the Advanced button. 6. Click the Add button. 7. Use the object picker to select the DHCP Admins group. 8. Check the boxes under “Create dHCPClass objects” and “Delete dHCPClass objects.” 9. Click OK until all dialog boxes are closed. 10. Back in ADSI Edit, right-click on cn=dhcpRoot (if you’ve previously authorized DHCP servers) and select Properties. 11. Select the Security tab. 496 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
522
12. Click the Advanced button. 13. Click the Add button. 14. Use the object picker to select the DHCP Administrators group. 15. Check the boxes under Allow for Write All Properties. 16. Click OK until all dialog boxes are closed. If the DHCP Administrators group does not exist, run the following command on a DHCP server or on a computer with the DHCP man‐ agement tool installed: netsh dhcp add securitygroups Using a graphical user interface You can quickly determine whether a DHCP server has been authorized by looking at its server node in the left pane of the DHCP snap-in. If the icon has a little red flag, it isn’t authorized; if the flag is green, it is authorized. Using a command-line interface To see the list of authorized servers using the command line, run the following command: > netsh dhcp show server Using PowerShell Get-DhcpServerInDC See Also “Controlling DHCP Active Directory Authorization” 13.23. Restricting DHCP Administrators Problem You want to restrict who can administer your DHCP servers in your domain. 13.23. Restricting DHCP Administrators | 497
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
523
Solution Using a graphical user interface 1. Open the Active Directory Users and Computers MMC snap-in (dsa.msc). 2. In the console tree, click Active Directory Users and Computers→<Domain Name>→Users. 3. In the Details pane, click DHCP Administrators. If the DHCP Administrators group does not exist, run the following command: netsh dhcp add securitygroups 4. Click Action→Properties→Members. 5. Remove all users and groups you do not want to have administering your DHCP server by clicking their names and then clicking Remove. 6. To add new DHCP administrators, click Add, provide the user or group name, and then click OK. 7. Click OK. Using a command-line interface Add a member to a group with DSMod by passing the -addmbr option: > dsmod group "<GroupDN>" -addmbr "<MemberDN>" To add a group member with AdMod, use the following syntax: > admod -b "<GroupDN>" member:+:"<MemberDN>" Remove a member from a group with DSMod by passing the -rmmbr option: > dsmod group "<GroupDN>" -rmmbr "<MemberDN>" To remove a group member with AdMod, use the following syntax: > admod -b "<GroupDN>" member:-:"<MemberDN>" Replace the complete membership list with DSMod by passing the -chmbr option: > dsmod group "<GroupDN>" -chmbr "<Member1DN Member2DN ...>" To replace the membership of a group with AdMod, use the following command: > admod -b "<GroupDN>" member:+-:"<Member1DN>;<Member2DN>;<Member3DN>" 498 | Chapter 13: DNS and DHCP
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
524
Using PowerShell You can add a user or group to the membership of the DHCP Administrators group using the Add-ADGroupMember command as follows: Add-ADGroupMember "DHCP Administrators" "<User/Group>" Discussion In Active Directory, most roles can be assigned independently of one another rather than just by making a user a Domain Admin or an Enterprise Admin. This is great for security administrators who want to ensure that users have only enough rights to per‐ form their assigned tasks. For example, a user Fred might need to modify an enterprise￾wide object. You could just add Fred to the Enterprise Admin groups to solve the prob‐ lem. However, Fred now has access to virtually any object in the entire forest and could cause irreparable harm to your network, not to mention compromising all security in place. Instead, you can grant Fred access to just that object. This can be done in different ways. One method is to use the Delegation of Control Wizard. Another way is to use the several built-in groups in Windows that are created and populated when specific services are installed. One such group is DHCP Adminis‐ trators, which is created when the first DHCP server is brought up in a domain. You can control administrative access to the DHCP function of these servers through this group membership. Nondomain joined computers also have a DHCP Administrators group. This is a local group on each computer and must be managed separately on each server. See Also “DHCP Groups” 13.23. Restricting DHCP Administrators | 499
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
525
null
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
526
CHAPTER 14 Security and Authentication 14.0. Introduction The default Windows 2000 installation of Active Directory was not as secure as it could have been out of the box. It allowed anonymous queries to be executed, which could take up valuable processing resources, and it did not place any requirements on en‐ crypting or signing traffic between clients and domain controllers. As a result, user‐ names, passwords, and search results could be sent over the network in clear text. For‐ tunately, beginning with Windows Server 2003, things tightened up significantly. LDAP traffic is signed by default, and anonymous queries are disabled by default. Additionally, Transport Layer Security (TLS), the more flexible cousin of Secure Sockets Layer (SSL), is supported, allowing for end-to-end encryption of traffic between domain controllers and clients. Active Directory’s ACL model provides ultimate flexibility for securing objects through‐ out a forest; you can restrict access down to the attribute level if you need to. With this flexibility comes increased complexity. An object’s ACL is initially generated from the default ACL for the object’s class, inherited permissions, and permissions directly ap‐ plied on the object. An ACL is a collection of ACEs, which defines the permission and properties that a security principal can use on the object to which the ACL is applied. Defining these entries and populating the ACL is the foundation of Active Directory security and del‐ egation. In this chapter, we will explore some of the common tasks of managing permissions in Active Directory. If you are looking for a detailed guide to Active Directory permissions, we suggest reading Active Directory, Fifth Edition, by Brian Desmond et al. (O’Reilly). In order for ACLs to be of use, a user must first authenticate to Active Directory. Kerberos is the primary network authentication system used by Active Directory. Kerberos is a 501
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
527
standards-based system originally developed at MIT that has been widely implemented at universities. We will also be covering some Kerberos-related tasks in this chapter that you will likely encounter in an Active Directory environment. For a complete review of Kerberos, we recommend Kerberos: The Definitive Guide by Jason Garman (O’Reilly). 14.1. Enabling SSL/TLS Problem You want to enable SSL/TLS access to your domain controllers so that clients can encrypt LDAP traffic to the servers. Solution Using a graphical user interface (solution specific to Windows Server 2012) 1. Open Server Manager. 2. Click Manage, then click Add Roles and Features, and then click Next. 3. Click Next, which will select a role-based or featured-based installation. 4. Click Next to select the local server as the destination server. 5. Check the box beside Active Directory Certificate Services and then click Next. 6. The Add Roles and Features Wizard will appear. Maintain the option to include the management tools, and then click the Add Features button to add the required features to the role installation. Click Next. 7. On the features screen, click Next. 8. On the AD CS screen, click Next. 9. On the Role services screen, click Next. 10. Review the installation options and then click Install to begin the installation. 11. Upon completion of the installation, click Close. 12. Go back to Server Manager and click the notifications. In the Post-deployment Configuration notification for AD CS, click the “Configure Active Directory Cer‐ tificate Services on the destination server” link. 13. On the Credentials screen, enter administrative credentials if needed and then click Next. 14. On the Role Services screen, click Certification Authority and then click Next. 15. Select the setup type that you want and click Next. 16. Select the CA type that you want the server to be and click Next. 502 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
528
17. The “Specify the type of the private key” screen appears. Click Next to create a new private key. 18. The Cryptography for CA screen will appear. Click Next. 19. On the CA Name screen, click Next. 20. On the Validity Period screen, click Next. 21. Enter the location for the certificate database and logs, and then click Next. 22. Click Configure and then click Close when the installation completes. Discussion The GUI solution example installs AD CS on an existing domain controller. (While this works, it is a good practice to separate AD DS and AD CS to separate servers when possible.) Because the example installs AD CS on a domain controller, the domain con‐ troller automatically acquires a certificate after the installation is complete. If you install AD CS on member server(s), you will need to acquire a certificate for each domain controller. One way to do this is to create an auto-enrollment GPO for all domain con‐ trollers. After Active Directory domain controllers obtain certificates, they automati‐ cally listen on ports 636 and 3269. Port 636 is for LDAP over SSL/TLS and port 3269 is used for global catalog queries performed over SSL/TLS. See Recipe 14.2 for more in‐ formation on how to query a domain controller using SSL/TLS. See Also “How to Enable Secure Socket Layer [SSL] Communication over LDAP for Windows 2000 Domain Controllers”; “How to enable LDAP over SSL with a third-party certifi‐ cation authority” 14.2. Securing LDAP Traffic with SSL, TLS, or Signing Problem You want to secure LDAP traffic using SSL, TLS, or signing. Solution Using a graphical user interface Most of the GUI-based tools running on both client computers and server computers will automatically sign and encrypt traffic between the server and client. This includes the following tools: 14.2. Securing LDAP Traffic with SSL, TLS, or Signing | 503
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
529
• Active Directory Domains and Trusts • Active Directory Sites and Services • Active Directory Schema • Active Directory Users and Computers • Active Directory Administrative Center • ADSI Edit • Group Policy Management snap-in • Object Picker With ADSI Edit, you can also specify the port number to use when browsing a partition. View the settings for a connection by right-clicking on the partition and selecting Set‐ tings. Click the Advanced button and enter 636 for LDAP over SSL or 3269 for the global catalog over SSL. Using a command-line interface The DS command-line tools support LDAP signing and encryption. This includes DSAdd, DSMod, DSrm, DSMove, DSGet, and DSQuery. The joeware utilities also sup‐ port connecting using SSL security. Discussion It is a good idea to test whether traffic is being encrypted. If you run Network Monitor (netmon.exe) while using tools that perform simple LDAP binds, you’ll see LDAP re‐ quests, usernames, and passwords going over the network in plain text. Obviously this is not the most secure configuration. If you use some of the tools listed in the preceding section, you will notice that you aren’t able to see the requests, usernames, or passwords. Don’t take encryption for granted. See Also Recipe 14.1 for enabling SSL/TLS; Recipe 14.3; MSDN: ADS_AUTHENTICA‐ TION_ENUM 14.3. Disabling LDAP Signing Problem You want to disable LDAP signing. 504 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
530
Solution Using a graphical user interface To temporarily disable LDAP encryption or signing for troubleshooting purposes, use the following steps on a client computer: 1. Create a new GPO. Edit the GPO and select Computer Configuration→Poli‐ cies→Windows Settings→Security Settings→Local Policies, and then highlight Se‐ curity Options. 2. In the right pane, double-click the policy titled “Network security: LDAP client signing requirements”. 3. Click the checkbox to define the policy setting and then select None as the setting. 4. Click OK. 5. Link the GPO to the container that contains the desired computer object(s). Discussion If the target domain controllers require signing, then disabling the client signing will result in the client administrative tools not being able to communicate with the domain controllers. To disable LDAP signing on domain controllers, follow the preceding steps but modify the policy titled “Domain controller: LDAP server signing requirements” in the Default Domain Controllers policy. See Also Recipe 14.2 to enable LDAP signing and encryption 14.4. Enabling Anonymous LDAP Access Problem You want to enable anonymous LDAP access for clients. Anonymous queries are dis‐ abled by default except for querying the RootDSE. Solution Using a graphical user interface 1. Open ADSI Edit. 14.4. Enabling Anonymous LDAP Access | 505
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
531
2. In the Configuration partition, browse to cn=Services→cn=Windows NT→cn=Di rectory Service. 3. In the left pane, right-click on the Directory Service object and select Properties. 4. Double-click on the dSHeuristics attribute. 5. If the attribute is empty, set it with the value 0000002. 6. If the attribute has an existing value, make sure the seventh digit is set to 2. 7. Click OK twice. Using PowerShell $root = [ADSI]"LDAP://RootDSE" $obj = [ADSI]("LDAP://cn=Directory Service,cn=Windows NT,cn=Services," +↵ $root.configurationNamingContext) $dsHeuristics = $obj.dsHeuristics.value if ($dsHeuristics -eq $null) { "dsHeuristics was null (not previously set)" $dsHeuristics = "0000000" # seven zeroes } $len = $dsHeuristics.Length if ($len -lt 7) { $dsHeuristics = $dsHeuristics + ("0000000").SubString(0, (7 - $len)) $len = 7 } # we've ensured that $dsHeuristics is AT LEAST seven chars long now # it may be 13 chars or more. we really don't care about that! $char = $dsHeuristics.SubString(6, 1) if ($char -eq "2") { "Anonymous query mode already set to 2" } else { $upd = $dsHeuristics.SubString(0, 6) + "2" if ($dsHeuristics.Length -gt 7) { $dsHeuristics.SubString(7, $len) } $obj.dsHeuristics = $upd $obj.SetInfo() "Anonymous query mode set to 2" 506 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
532
"New value of dsHeuristics equal to $upd" } Discussion To enable anonymous access, you have to modify the dSHeuristics attribute of the cn=Directory Service,cn=Windows NT,cn=Services,ConfigurationDN object. The dSHeuristics attribute is an interesting attribute used to control certain behavior in Active Directory. For example, you can enable List Object Access mode (see Recipe 14.17) by setting the dSHeuristics flag. The dSHeuristics attribute consists of a series of digits that, when set, enable certain functionality. To enable anonymous access, the seventh digit must be set to 2. By default, dSHeuristics does not have a value. If you set it to enable anonymous access, the value would be 0000002. After enabling anonymous access, the assumption is that you’ll want to grant access for anonymous users to retrieve certain data from Active Directory. To do that, grant the ANONYMOUS LOGON user access to the parts of the directory you want anonymous users to search. You must grant the access from the root of the directory down to the object of interest. See MS KB 320528 for an example of how to enable the anonymous user to query the email addresses of user objects. See Also Recipe 14.17; “How to configure Active Directory to allow anonymous queries”; MSDN: DS-Heuristics attribute 14.5. Using the Delegation of Control Wizard Problem You want to delegate control over objects in Active Directory to a user or group. Solution Using a graphical user interface 1. Open the Active Directory Users and Computers snap-in (dsa.msc) or Active Di‐ rectory Sites and Services snap-in (dssite.msc), depending on the type of object you want to delegate. 2. In the left pane, browse to the object on which you want to delegate control. 14.5. Using the Delegation of Control Wizard | 507
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
533
3. Right-click on the object and select Delegate Control. Only certain objects support the Delegation of Control Wizard, so this option will not show up for every type of object. 4. Click Next. 5. Click the Add button and use the object picker to select the users or groups to which you want to delegate control. 6. Click Next. 7. If the task you want to delegate is an option under “Delegate the following common tasks,” place a checkmark next to it and click Next. If the task is not present, select “Create a custom task to delegate” and click Next. If you selected the latter option, you will need to perform four additional steps: a. Select the object type you want to delegate. b. Click Next. c. Select the permissions you want to delegate. d. Click Next. 8. Click Finish. Using a command-line interface To grant permissions from the command line, use the following syntax: > dsacls <ObjectDN> /g <Permissions> For example, the following syntax will delegate the permission to read and write infor‐ mation to the description property: > dsacls <ObjectDN> /g RPWP;description; Discussion The Delegation of Control Wizard is Microsoft’s attempt to ease the pain of trying to set permissions for common tasks. Because Active Directory permissions are so gran‐ ular, they can also be cumbersome to configure. The Delegation of Control Wizard helps in this regard, but it is still limited in functionality. The default tasks that can be delegated are fairly minimal, although you can add more tasks as described in Recipe 14.6. Another limitation is that you can only add new permissions; you cannot undo or remove per‐ missions that you previously set with the wizard. To do that, you have to use the ACL Editor directly as described in Recipe 14.8. 508 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
534
See Also Recipe 14.6 for customizing the Delegation of Control Wizard; Recipe 14.7 for more on using dsrevoke 14.6. Customizing the Delegation of Control Wizard Problem You want to add or remove new delegation options in the Delegation of Control Wizard. Solution Open the Delegation of Control Wizard INF file (%SystemRoot%\System32\Dele gwiz.inf in Windows Server 2008 and later) on the computer for which you want to modify the wizard. Under the [DelegationTemplates] section, you’ll see a line similar to the following: Templates = template1, template2, template3, template4, template5, template6, template7, template8, template9,template10, template11, template12, template13 You need to append a new template name. In this case, we’ll follow the same naming convention and create a template named template14. The line should now look like this: Templates = template1, template2, template3, template4, template5, template6, template7, template8, template9,template10, template11, template12, template13, template14 Scroll to the end of the file and append a new template section. You can use the other template sections as examples. Here is the generic format: [<TemplateName>] AppliesToClasses = <CommaSeparatedListOfObjectClassesInvokedFrom> Description = "<DescriptionShownInWizard>" ObjectTypes = <CommaSeparatedListOfObjectClassesThatAreSet> [<TemplateName>.SCOPE]<Permission entries for Scope> [<TemplateName>.<ObjectClass1>]<Permission entries for ObjectClass1> [<TemplateName>.<ObjectClass2>]<Permission entries for ObjectClass2> ... <TemplateName> is the same as what we used in the [DelegationTemplates] section— that is, template14. 14.6. Customizing the Delegation of Control Wizard | 509
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
535
In the AppliesToClasses line, replace <CommaSeparatedListOfObjectClassesInvo kedFrom> with a comma-separated list of LDAP display names of the classes that can be delegated. This delegation action will show up on the classes listed here only when you select Delegate Control from a snap-in. To make our new template entry apply to domain objects, OUs, and containers, we would use this line: AppliesToClasses = domainDNS,organizationalUnit,container In the Description line, replace <DescriptionShownInWizard> with the text you want shown in the wizard that describes the permissions being delegated. Here is a sample description for delegating full control over inetOrgPerson objects: Description = "Create, delete, and manage user and inetOrgPerson accounts" In the ObjectTypes line, replace <CommaSeparatedListOfObjectClassesThatAre Set> with a comma-separated list of object classes to be delegated. In this example, permissions will be modified for user and inetOrgPerson objects: ObjectTypes = user,inetOrgPerson Next, define the actual permissions to set when this action is selected. You can define two different types of permissions. You can use a [<TemplateName>.SCOPE] section to define permissions that are set on the object that is used to start the wizard. This will be one of the object classes defined in the AppliesToClass line. This is commonly used in the context of containers and organizational units to specify, create, modify, or delete child objects of a particular type. For example, to allow the granting of create (CC) or delete (DC) permissions for user and inetOrgPerson objects, you would use the fol‐ lowing: [template14.SCOPE] user=CC,DC inetOrgPerson=CC,DC As you can see, each permission (e.g., create child) is abbreviated to a two-letter code (e.g., CC). Table 14-1 lists the valid codes. Table 14-1. Permissions and abbreviated codes Abbreviated code Permission RP Read Property WP Write Property CC Create Child DC Delete Child GA Full Control It is perfectly valid to leave out a SCOPE section if it is not needed. The rest of the lines are used to specify permissions that should be set on the object classes defined by the ObjectTypes line. 510 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
536
To allow the granting of full control over all existing user and inetOrgPerson objects, we’ll use these entries: [template14.user] @=GA [template14.inetOrgPerson] @=GA This is very similar to the previous example, except that here SCOPE is replaced with the names of the object classes the permissions apply to. The @ symbol is used to indicate that the permission applies to all attributes on the object. You can get more granular by replacing @ with the name of the attribute the permission applies to. For example, this would allow the granting of read and write permissions on the department attribute for inetOrgPerson objects: [template14.inetOrgPerson] department=RP,WP You can also enable control access rights using the CONTROLRIGHT designator instead of @ or an attribute name; you just need to specify the LDAP display name of the control access right you want to enable. The following section enables the Reset Password right on inetOrgPerson objects and enables read and write access to the pwdLastSet attribute: [template14.inetOrgPerson] CONTROLRIGHT="Reset Password" pwdLastSet=RP,WP Discussion You can completely customize the tasks that can be delegated with the Delegation of Control Wizard, but you still have the problem of getting the Delegwiz.inf file, on all the clients that need to use the new settings. You can manually copy it to the computers that need it, or you can use Group Policy to automate the distribution of it. Microsoft offers a prebuilt delegation file that allows you to delegate more than 70 administrative tasks. The file can be used to replace the existing Delegwiz.inf file or it can be used as a starting point if you only wanted to use a subset of the file. See the file at TechNet for more information. See Also Recipe 14.5 for more on using the Delegation of Control Wizard 14.6. Customizing the Delegation of Control Wizard | 511
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
537
14.7. Revoking Delegated Permissions Problem You want to remove permissions that you’ve delegated to a domain or an OU. Solution Using a graphical user interface 1. Open the Active Directory Users and Computers MMC snap-in (dsa.msc). Right￾click on the object that you wish to modify and select Properties. 2. From the Security tab, highlight the permissions entry that you wish to revoke and click Remove, and then click OK. Using a command-line interface The following command will remove any permissions that have been delegated directly to the ADATUM\jsmith user over the Finance Organizational Unit: > dsrevoke /remove "/root:ou=Finance,dc=adatum,dc=com" ADATUM\jsmith Discussion While the Delegation of Control Wizard makes it trivial to grant permissions to objects within Active Directory, one thing that it lacks is an Undo button. To help address this, Microsoft has made the dsrevoke command-line utility a free download from its web‐ site. Note that the tool is dated as it was created originally for Windows 2000. It has been a bit spotty on Windows Server 2008 and Windows Server 2008 R2, but we’ve used it successfully with Windows Server 2012. The dsrevoke utility will remove any permis‐ sions that have been delegated to a security principal on a domain or an OU, with the following limitations: • You can use dsrevoke only on a domain or an OU; if you’ve delegated permissions over individual objects, you’ll need to remove them manually. • dsrevoke removes only object permissions; if you’ve assigned any user rights through Group Policy, they’ll need to be removed separately. • You can’t use dsrevoke to remove any permissions that have been delegated to the Schema or Configuration NCs. 512 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
538
See Also “Best Practices for Delegating Active Directory Administration” 14.8. Viewing the ACL for an Object Problem You want to view the ACL for an object. Solution Using a graphical user interface 1. Open the ACL Editor. You can do this by viewing the properties of an object (right￾click on the object and select Properties) with a tool such as ADUC or ADSI Edit. Select the Security tab. To see the Security tab with ADUC, you must select View→Advanced Features from the menu. 2. Click the Advanced button to view a list of the individual ACEs. Using a command-line interface > dsacls <ObjectDN> Using PowerShell (Get-Acl "ad:\<ObjectDN>").Access | FL Discussion Viewing an object’s ACL is a common task and should already be familiar to most administrators. The ACL Editor is useful for checking the permissions that have been set on objects, especially after running the Delegation of Control Wizard. In addition to viewing permissions, the options available in the GUI include viewing auditing set‐ tings and the owner of the object. Knowing the owner of an object is important because ownership confers certain inherent rights. Because the ACL Editor is the same for NTFS permissions and properties as it is for Active Directory objects, you should feel comfortable with the look and feel of the interface; it is exactly the same as file and folder permissions. We also highly recommend getting familiar with the Advanced view of the ACL Editor, as this is truly the view in which you can determine what is going on with permissions. The Basic view presents a list of security principals that have permissions configured, but it will not always show every configured ACE entry. The Advanced view will show the complete picture, 14.8. Viewing the ACL for an Object | 513
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
539
including the scope of permissions for ACEs down to the object and even the attribute level. See Also Recipe 14.12 for changing an ACL; Recipe 15.13 for auditing of object access 14.9. Customizing the ACL Editor Problem You want to set permissions on attributes that do not show up in the default Active Directory Users and Computers ACL Editor. Solution The ACL Editor in ADUC and in the Active Directory Administrative Center shows only a subset of the object’s attributes on which permissions can be set. Most attributes can be seen in the ACL Editor by clicking the Advanced button, adding or editing a permission entry, and selecting the Properties tab. An attribute can have a read permission, a write permission, or both, either of which can be set to Allow or Deny. If the attribute you want to secure is not in the list, you will need to modify the dssec.dat file on the computer that you’re running the ACL Editor from. On Windows Server 2012, the dssec.dat file is located in the %SYSTEMROOT% \System32 folder. There are sections for each object class represented in square brackets—for example, [user]. Underneath that heading is a list of attributes that you can configure to display or not display in the ACL Editor. These are the first few lines for the [user] section: [user] aCSPolicyName=7 adminCount=7 allowedAttributes=7 The value to the right of the attribute determines whether it is shown in the ACL Editor. The valid values include the following: 0 Both the Read property and the Write property are displayed for the attribute. 1 The Write property is displayed for the attribute. 514 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
540
2 The Read property is displayed for the attribute. 7 No entries are displayed for the attribute. If the attribute is not defined, then the default value (specified by @, if present) is used. Discussion Much like the Delegation of Control Wizard, you can customize the attributes that are shown in the ACL Editor, but you still need to distribute the dssec.datfile to all computers that need to see the change. After making the changes to dssec.dat, close ADUC and/or the Active Directory Ad‐ ministrative Center and then reopen them. See Also MS KB 296490 (How to Modify the Filtered Properties of an Object); MS KB 294952 (How to Delegate the Unlock Account Right) 14.10. Viewing the Effective Permissions on an Object Problem You want to view the effective permissions that a user or group has for a particular object. Solution Using a graphical user interface (solution specific to Windows Server 2012) 1. Open the ACL Editor. You can do this by viewing the properties of an object (right￾click on the object and select Properties) with a tool such as ADUC or ADSI Edit. Select the Security tab. To see the Security tab with ADUC, you must select View→Advanced Features from the menu. 2. Click the Advanced button. 3. Select the Effective Access tab. 4. Click the “Select a user” button to bring up the Object Editor. 5. Find the user or group for which you want to see the effective permissions. 6. Click the “View effective access” button. 14.10. Viewing the Effective Permissions on an Object | 515
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
541
The results will be shown in the bottom of the window. The Effective Access tab is the new name for the Effective Permissions tab since Windows Server 2008. Using a command-line interface > acldiag <ObjectDN> /geteffective:<UserOrGroupDN> Discussion Viewing the permissions on an object does not tell the whole story as to what the actual translated permissions are for a user or group on that object. The effective permissions of an object take into account all group membership and any inherited permissions that might have been applied farther up the tree. While this is a useful tool to analyze per‐ missions, it is unfortunately only a best guess; there are still some situations in which certain permissions will not be reflected. The AclDiag tool is from the Windows Server 2003 Service Pack 2 32-bit Support Tools. It is a free download, and it installs and works successfully up to Windows Server 2012. See Also AclDiag overview 14.11. Configuring Permission Inheritance Problem You want to configure permission inheritance on an Active Directory container to con‐ figure whether a child object should automatically receive any permissions that you’ve granted to its parent object. Solution 1. Open the ACL Editor. You can do this by viewing the properties of an object (right￾click on the object and select Properties) with a tool such as Active Directory Users and Computers (ADUC) or ADSI Edit. Select the Security tab. If the Security tab is not visible within ADUC, you must select View→Advanced Features from the menu. 2. Click the Advanced button to view a list of the individual ACEs. 516 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
542
3. To turn off inheritance, click the “Disable inheritance” button. 4. You will be given the option to “Convert inherited permissions into explicit per‐ missions on this object”, to “Remove all inherited permissions from this object”, or to cancel. Click the desired option. 5. To reenable permission inheritance from objects farther up the directory structure, click the “Enable inheritance” button in the Advanced Permissions window. Using a command-line interface To disable permission inheritance (i.e., to configure an object such that only explicitly assigned permissions apply), use the following syntax: > dsacls <ObjectDN> /P:Y To enable permission inheritance, do the following: > dsacls <ObjectDN> /P:N Using PowerShell The following syntax will prevent an object from receiving inherited permissions that have been applied at a higher level in the tree: $acl = Get-Acl -Path "AD:<ObjectDN>" $acl.SetAccessRuleProtection($true,$true);Set-Acl -AclObject $acl "AD:<ObjectDN>" The following syntax will configure an AD object so that it will receive inherited per‐ missions that have been applied at a higher level in the directory tree: $acl = Get-Acl -Path "AD:<ObjectDN>" $acl.SetAccessRuleProtection($false,$false);Set-Acl -AclObject $acl↵ "AD:<ObjectDN>" Discussion Similar to NTFS permissions on the filesystem, Active Directory permissions on con‐ tainer objects can be set to inherit or trickle down to objects farther down the directory structure. This process can greatly simplify assigning permissions, as you can assign a common set of permissions high up in the directory structure and have those permis‐ sions filter down to all of the OUs and objects below. In some cases, though, you might want to turn off permission inheritance to configure an entirely different set of per‐ missions for a child object or container. One thing to keep in mind when enabling or disabling inheritance is that there are a number of AD security principals protected by the AdminSDHolder process that will receive a specific set of permissions regardless of the inheritance settings you configure. These groups include Enterprise Admins, Schema Admins, Domain Admins, Adminis‐ trators, Account Operators, Server Operators, Print Operators, Backup Operators, and 14.11. Configuring Permission Inheritance | 517
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
543
Cert Publishers. In addition, some Active Directory−aware applications depend on in‐ heritance being in place in order to function efficiently. See Also “AdminSDHolder—or where did my permissions go?”; “Description and Update of the Active Directory AdminSDHolder Object” 14.12. Changing the ACL of an Object Problem You want to change the ACL on an object to grant or restrict access to it for a user or group. Solution Using a graphical user interface 1. Open the ACL Editor. You can do this by viewing the properties of an object (right￾click on the object and select Properties) with a tool such as ADUC, Active Directory Administrative Center, or ADSI Edit. Select the Security tab. To see the Security tab with ADUC, you must select Views→Advanced Features from the menu. 2. Click the Advanced button to view a list of the individual ACEs. 3. Click Add to specify a new user or group, and then place checkmarks next to the permissions that you want to assign and click OK. 4. To remove an ACE, highlight the entry and click Remove. If the Permissions entry is inherited from farther up the directory tree, the option to remove the permission will not be available unless you disable inheritance. With inheritance enabled, you will only have the option to remove any permissions that have not been inherited. Using a command-line interface To grant permissions from the command line, use the following syntax: > dsacls <ObjectDN> /g <Permissions> To deny permissions, replace /g with /d. Using PowerShell To add an entry for Full Control to the ACL of an object, use the following syntax: 518 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
544
$Path = [ADSI]"LDAP://<ObjectDN>" $Group = New-Object System.Security.Principal.NTAccount("<GroupName>") $IdentityReference = $Group.Translate↵ ([System.Security.Principal.SecurityIdentifier]) $Perms = New-Object System.DirectoryServices.ActiveDirectoryAccessRule↵ ($IdentityReference,"GenericAll","Allow") $Path.psbase.ObjectSecurity.AddAccessRule($Perms) $Path.psbase.commitchanges() Discussion Changing the ACL of an object is a common task for administrators in any but the most basic AD implementations because, as shown in Recipe 14.5 and Recipe 14.6, the Del‐ egation of Control Wizard is limited and cumbersome to extend and deploy. The GUI and command-line methods are useful for one-off changes to permissions, but for making global changes to a number of objects, you should consider using a script to automate the process. See Also Recipe 7.10; Recipe 8.2; Recipe 13.9; Recipe 14.5; Recipe 14.6; Recipe 17.9 14.13. Changing the Default ACL for an Object Class in the Schema Problem You want to change the default ACL for an object class in the schema. Solution Using a graphical user interface 1. Open the Active Directory Schema snap-in. 2. In the left pane, browse to the class you want to modify. 3. Right-click on it and select Properties. 4. Select the Default Security tab. 5. Use the ACL Editor to change the ACL. 6. Click OK. 14.13. Changing the Default ACL for an Object Class in the Schema | 519
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
545
Discussion Each instantiated object in Active Directory has an associated structural class that de‐ fines a default security descriptor (the defaultSecurityDescriptor attribute). When an object is created and a security descriptor isn’t specified, the default security de‐ scriptor is applied to it. This, along with inheritable permissions from the parent con‐ tainer, determines how an object’s security descriptor is initially defined. If you find that you are modifying the default security descriptor on a particular type of object every time it is created, you may want to modify its default security descriptor. Another option would be to use a script that would modify the individual object’s ACL at the same time that the object was created. See Also Recipe 10.1 for more on registering the Active Directory Schema snap-in; Recipe 14.14 for comparing the ACL of an object to the default defined in the schema; Recipe 14.15 for resetting the ACL of an object to the default defined in the schema 14.14. Comparing the ACL of an Object to the Default Defined in the Schema Problem You want to determine whether an object has the permissions defined in the schema for its object class as part of its ACL. Solution Using a command-line interface > acldiag <ObjectDN> /schema Discussion For more on the default security descriptor (SD), see Recipe 14.13. AclDiag will deter‐ mine whether the object possesses the security descriptor that’s defined in the schema —if you’ve modified the security descriptor, AclDiag will compare the object’s SD against the currently defined SD, not the Active Directory default. See Also Recipe 14.15 for resetting an object’s ACL to the default defined in the schema 520 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
546
14.15. Resetting an Object’s ACL to the Default Defined in the Schema Problem You want to reset an object’s ACL to the one defined in the schema for the object’s object class. Solution Using a graphical user interface 1. Open the ACL Editor. You can do this by viewing the properties of an object (right￾click on the object and select Properties) with a tool such as ADUC, Active Directory Administrative Center, or ADSI Edit. Select the Security tab. To see the Security tab with ADUC, you must select View→Advanced Features from the menu. 2. Click the Advanced button. 3. Click the “Restore defaults” button. 4. Click OK twice. Using a command-line interface > dsacls <ObjectDN> /S The /S parameter is case-sensitive. Discussion For more on the default security descriptor, see Recipe 14.13. 14.16. Enabling Strong Domain Authentication Problem You want to ensure that users can only authenticate to Active Directory using strong authentication protocols. 14.15. Resetting an Object’s ACL to the Default Defined in the Schema | 521
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
547
Solution Using a graphical user interface 1. Open the Group Policy Management snap-in (gpmc.msc). 2. In the left pane, expand the Forest container, expand the Domains container, browse to the domain you want to administer, and expand the Group Policy Objects container. 3. Right-click on the GPO that controls the configuration of your domain controllers and select Edit. (By default, this is the Default Domain Controller Policy, but it may be a different GPO in your environment.) This will bring up the Group Policy Object Editor. 4. Browse to Computer Configuration→Policies→Windows Settings→Security Set‐ tings→Local Policies→Security Options. 5. Double-click on “Network security: LAN Manager Authentication Level”. Place a checkmark next to “Define this policy setting”. 6. Select “Send NTLMv2 response only. Refuse LM & NTLM.” Click OK. 7. Wait for Group Policy to refresh, or run the gpupdate /force command from the command prompt. Discussion Microsoft operating systems have supported different flavors of LM and NT LAN Man‐ ager (NTLM) authentication since the earliest days of Windows. LM authentication is an extremely old and weak authentication protocol that should no longer be used in production environments unless absolutely necessary. By default, Windows 2000 Active Directory supported client authentication attempts using LM, NTLM, or NTLMv2; Windows Server 2003 and later support only NTLM and NTLMv2 out of the box. The strongest NTLM authentication scheme you can select is to refuse LM and NTLM authentication from any client, and to respond only to clients using NTLMv2. Depend‐ ing on your client configuration, though, enabling this option may require changes on the client side as well. You can apply the same setting to a GPO linked to your Active Directory domain to ensure that all of your clients will use NTLMv2 instead of older, weaker protocols. Windows Server 2008, Windows Server 2008 R2, and Windows Server 2012 Active Directory have a default value of “Send NTLMv2 response only” for this GPO setting. This is more secure than previous versions of the operating system but still allows do‐ main controllers to accept weaker authentication methods. 522 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
548
See Also “Introducing the Restriction of NTLM Authentication”; “Purging Old NT Security Pro‐ tocols” 14.17. Enabling List Object Access Mode Problem You want to prevent any authenticated user from being able to browse the contents of Active Directory by default. Enabling List Object Access mode means that users will need explicit permissions to see directory listings of containers. Solution Using a graphical user interface 1. Open ADSI Edit. 2. In the Configuration partition, browse to cn=Services→cn=Windows NT→cn=Di rectory Service. 3. In the left pane, right-click on the Directory Service object and select Properties. 4. Double-click on the dSHeuristics attribute. 5. If the attribute is empty, set it with the value 001. If the attribute has an existing value, make sure the third digit (from the left) is set to 1. 6. Click OK twice. Using VBScript On Error Resume Next ' necessary if dsHeuristics is not ' already set ' This code enables or disables list object mode for a forest. ' ------ SCRIPT CONFIGURATION ----- boolEnableListObject = 1 ' e.g. 1 to enable, 0 to disable ' ------ END CONFIGURATION -------- set objRootDSE = GetObject("LDAP://RootDSE") set objDS = GetObject( _ "LDAP://cn=Directory Service,cn=Windows NT,cn=Services," ↵ & objRootDSE.Get("configurationNamingContext") ) strDSH = objDS.Get("dSHeuristics") if len(strDSH) = 1 then strDSH = strDSH & "0" end if 14.17. Enabling List Object Access Mode | 523
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
549
strNewDSH = Left(strDSH,2) & boolEnableListObject if len(strDSH) > 3 then strNewDSH = strNewDSH & Right(strDSH, len(strDSH) - 3) end if WScript.Echo "Old value: " & strDSH WScript.Echo "New value: " & strNewDSH if strDSH <> strNewDSH then objDS.Put "dSHeuristics", strNewDSH objDS.SetInfo WScript.Echo "Successfully set list object mode to " & ↵ boolEnableListObject else WScript.Echo "List object mode already set to " & boolEnableListObject end if Discussion List Object Access mode is useful if you want your users to view only a subset of objects when doing a directory listing of a particular container, or you do not want them to be able to list the objects in a container at all. This mode was originally intended for mul‐ titenant environments and should undergo thorough testing in an environment before deploying to production. By default, the Authenticated Users group is granted the List Contents access control right over objects in a domain. If you remove or deny this right on a container by modifying the ACL, users will not be able to get a listing of the objects in that container using tools such as ADUC or ADSI Edit. To limit the objects that users can see when they pull up an object listing, you first need to enable List Object Access mode as described in the solution. You should then remove the List Contents access control right on the target container. Lastly, you’ll need to grant the List Object right to the objects that the users or groups should be able to list. Enabling List Object Access mode can significantly increase the administration over‐ head for configuring ACLs in Active Directory. It can also impact performance on a domain controller since it will take considerably more time to verify ACLs before re‐ turning information to a client. Using VBScript This script requires the On Error Resume Next command in order to function. Without this line in place, the script will throw an error if the dsHeuristics attribute is not set. See Also Ask the Directory Services Team blog 524 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
550
14.18. Modifying the ACL on Administrator Accounts Problem You want to modify the ACL for user accounts that are members of one of the admin‐ istrative groups. Solution Using one of the methods described in Recipe 14.12, modify the ACL on the cn=Ad minSDHolder,cn=Systems,<DomainDN> object in the domain that the administrator ac‐ counts reside in. The ACL on this object gets applied every hour to all user accounts that are members of the administrative groups. Discussion If you’ve ever tried to directly modify the ACL on a user account that was a member of one of the administrative groups in Active Directory, or you modified the ACL on the OU containing an administrative account, and then wondered why the account’s ACL was overwritten later, you’ve come to the right place. The Admin SD Holder feature of Active Directory is one that many administrators stumble upon after much grinding of teeth. However, after you realize the purpose for it, you’ll understand it is a necessary feature. Once an hour, a process on the PDC Emulator that we’ll refer to as the Admin SD Holder process compares the ACL on the AdminSDHolder object to the ACL on the accounts that are in administrative groups in the domain as well as the groups themselves. If it detects a difference, it will overwrite the account or Group ACL and disable inheritance. If you later remove a user from an administrative group, you will need to reapply any inherited permissions and enable inheritance if neces‐ sary. The Admin SD Holder process will not take care of this for you. The Admin SD Holder process is intended to subvert any malicious activity by a user that has been delegated rights over an OU or container that contains an account that is in one of the administrative groups. An OU administrator could, for example, modify permissions inheritance on an OU to attempt to lock out the Domain Admins group; this permission change would be reverted the next time the AdminSDHolder thread runs. These groups are included as part of Admin SD Holder processing: • Administrators • Account Operators 14.18. Modifying the ACL on Administrator Accounts | 525
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
551
• Cert Publishers • Backup Operators • Domain Admins • Enterprise Admins • Print Operators • Schema Admins • Server Operators The administrator and krbtgt user accounts are also specifically checked during the Admin SD Holder process. See Also “Description and Update of the Active Directory AdminSDHolder Object”; “Five com‐ mon questions about AdminSdHolder and SDProp” 14.19. Viewing and Purging Your Kerberos Tickets Problem You want to view and purge your Kerberos tickets. Solution The kerbtray utility can be found in the Windows Server 2003 Resource Kit. The ker‐ btray utility works through Windows Server 2012. Klist is built into the Active Directory Domain Services role. Using a graphical user interface 1. Run kerbtray.exe from the command line or from Start→Run. 2. A new icon (green) should show up in the system tray. Double-click on that icon. This will allow you to view your current tickets. 3. To purge your tickets, right-click on the kerbtray icon in the system tray and select Purge Tickets. 4. Close the kerbtray window and reopen it by right-clicking on the kerbtray icon and selecting List Tickets. 526 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
552
Using a command-line interface Run the following command to list your current tickets: > klist tickets Run the following command to purge your tickets: > klist purge Discussion Active Directory uses Kerberos as its preferred network authentication system. When you authenticate to a Kerberos Key Distribution Center (KDC), which in Active Direc‐ tory terms is a domain controller, you are issued one or more tickets. These tickets identify you as a certain principal in Active Directory and can be used to authenticate you to other Kerberized services. This type of ticket is known as a ticket-granting tick‐ et, or TGT. Once you’ve obtained a TGT, the client can use the TGT to gain access to a Kerberized service by querying the Ticket Granting Service on the KDC; if the KDC verifies that the user is authorized to access the service in question, it will issue a service ticket that allows the client to use the particular service. Kerberos is a fairly complicated system, and we can’t do it justice in a single paragraph. If you want more information on tickets and how the Kerberos authentication system works, see Kerberos: The Definitive Guide by Jason Garman (O’Reilly). See Also RFC 1510 (The Kerberos Network Authentication Service V5); “Kerberos Authentica‐ tion Overview” 14.20. Forcing Kerberos to Use TCP Problem Clients are experiencing authentication problems, and you’ve determined it is due to UDP fragmentation of Kerberos traffic. You want to force Kerberos traffic to use TCP instead. Perform the solution on all computers that are experiencing the issue (client computers, server, domain controllers). Solution Using a graphical user interface 1. Run regedit.exe from the command line or from Start→Run. 14.20. Forcing Kerberos to Use TCP | 527
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
553
2. In the left pane, expand HKEY_LOCAL_MACHINE→System→Current￾ControlSet→Control→Lsa→Kerberos→Parameters. 3. Right-click on Parameters and select New→DWORD value. Enter MaxPacket Size for the value name. 4. In the right pane, double-click on MaxPacketSize and enter 1. 5. Click OK. Using a command-line interface > reg add "HKLM\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters" /v↵ "MaxPacketSize" /t REG_DWORD /d 1 Using VBScript ' This code forces Kerberos to use TCP. ' ------ SCRIPT CONFIGURATION ----- strComputer = "<ComputerName>" ' e.g. rallen-w2k3 ' ------ END CONFIGURATION -------- const HKLM = &H80000002 strRegKey = "SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters" set objReg = GetObject("winmgmts:\\" & strComputer & ↵ "\root\default:StdRegProv") objReg.SetDwordValue HKLM, strRegKey, "MaxPacketSize", 1 WScript.Echo "Kerberos forced to use TCP for " & strComputer Using PowerShell $strRegPath = "HKLM:\System\CurrentControlSet\Lsa\Kerberos\Parameters" New-ItemProperty -path $strRegPath -name "MaxPacketSize" -type DWORD Set-ItemProperty -path $strRegPath -name "MaxPacketSize" -value "1" Discussion If you have users that are experiencing extremely slow logon times (especially over VPN) or they are seeing the infamous “There are currently no logon servers available to service the logon request” message, then they may be experiencing UDP fragmentation of Ker‐ beros traffic. This occurs because UDP is a connectionless protocol, so UDP packets that arrive out of order will be dropped by the destination router. A source of information is the System event log on the clients. Various Kerberos-related events are logged there if problems with authentication occur. See Also “How to force Kerberos to use TCP instead of UDP in Windows” 528 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
554
14.21. Modifying Kerberos Settings Problem You want to modify the default Kerberos settings, such as maximum ticket lifetime. Solution Using a graphical user interface 1. Open the Default Domain Group Policy Object, or another domain-linked GPO, in the Group Policy Management Console. 2. Navigate to Computer Configuration→Policies→Windows Settings→Security Set‐ tings→Account Policies→Kerberos Policy. 3. In the right pane, double-click on the setting you want to modify. 4. Enter the new value and click OK. Discussion There are several Kerberos-related settings you can customize, most of which revolve around either increasing or decreasing the maximum lifetime for Kerberos user and service tickets. In most environments, the default settings are sufficient, but the ones you can modify are listed in Table 14-2. Change the default Kerberos policy settings with caution, as doing so can cause operational problems and compromise security if done in‐ correctly. Table 14-2. Kerberos policy settings Setting Default value Enforce user logon restrictions Enabled Maximum lifetime for service ticket 600 minutes Maximum lifetime for user ticket 10 hours Maximum lifetime for user ticket renewal 7 days Maximum tolerance for computer clock synchronization 5 minutes See Also “Kerberos Policy” 14.21. Modifying Kerberos Settings | 529
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
555
14.22. Viewing Access Tokens Problem You want to view the access tokens that are created for a user account that has authen‐ ticated to Active Directory. Solution Using a command-line interface > tokensz /compute_tokensize /package:negotiate /target_server:host/<DCName>↵ /user:<Username> /domain:<DomainName> /password:<Password> /dumpgroups Discussion When an Active Directory security principal receives a TGT from the Kerberos Key Distribution Center, the TGT contains a Privilege Attribute Certificate (PAC). This PAC contains several pieces of authentication data, such as the groups that a user belongs to (including all nested group memberships). In the majority of AD environments, this PAC is created without issue, but some larger environments can run into instances of token bloat. This occurs when a user belongs to a large number of groups (estimates start at around 70 to 120), and the size of the PAC becomes too large for the TGT to handle. This issue can manifest itself through authentication issues or through Group Policy Objects not applying properly. You can download and use the tokensz.exe utility to compute the token size for a user relative to the maximum allowable size, as well as to list the groups that a user belongs to. You can resolve this issue by streamlining the number of groups that the user or users belong to, which has the added benefit of simplifying the process of assigning permis‐ sions and applying Group Policy Objects. If this isn’t possible, you can apply the hotfix referenced in MS KB 327825 or modify the HKLM\System\CurrentControlSet\Control \Lsa\Kerberos\Parameters\MaxTokenSize DWORD value on your domain comput‐ ers. This issue is most relevant on legacy domain controllers, since modern versions of Windows have made a number of improvements to alleviate the need to modify this value. Additional details about the recent improvements are in the following “See Also” section. If you determine that you need to modify the MaxTokenSize value, use the following formula as an approximate guideline: 1200 + 40d + 80s In this equation, 1200 denotes a suggested amount of overhead that’s used by the PAC; you can use the tokensz utility to determine the size for the domain in question. d refers to the number of domain local security groups that a representative user is a member 530 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
556
of, plus any universal security groups in other domains that the user belongs to, plus any groups represented in the user’s sIDHistory attribute. s refers to the number of global security groups a representative user belongs to, plus any universal security groups within the user’s own domain. See Also “MaxTokenSize and Windows 8 and Windows Server 2012”; “Whoami” (note that a new /CLAIMS parameter exists but is not documented on the Whoami site at the time of this writing) 14.23. Creating a Claim Type Problem You want to create a new claim type for Dynamic Access Control. Solution Using a graphical user interface 1. Launch the Active Directory Administrative Center. 2. Select Dynamic Access Control and then click Claim Types. 3. From the Tasks menu, click New→Claim Type. 4. Select an Active Directory attribute to use as a source and modify the name and description, if desired. 5. Select whether to use the claim type for Users, Computers, or both class types. 6. Click OK to create the claim type. Using PowerShell The following PowerShell command will create a new claim type: New-ADClaimType -DisplayName "<DisplayName>" -SourceAttribute "<ADAttribute>"↵ -AppliesToClasses "<ClassType>" Discussion Claim types are associated with an Active Directory attribute and are then associated with the object class. Claim types can be associated with the following Active Directory classes: 14.23. Creating a Claim Type | 531
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
557
• User • Computer • InetOrgPerson • msDS-ManagedServiceAccount • msDS-GroupManagedServiceAccount See Also “Dynamic Access Control: Scenario Overview”; New-ADClaimType cmdlet reference; Active Directory, Fifth Edition, by Brian Desmond et al. (O’Reilly) 14.24. Creating a Resource Property Problem You want to create a resource property for Dynamic Access Control. Solution Using a graphical user interface 1. Launch the Active Directory Administrative Center. 2. Select Dynamic Access Control and then click Resource Properties. 3. From the Tasks menu click New→Resource Property. 4. Enter a display name for the resource property. 5. Select a value type from the drop-down list to use for the resource property. 6. If required by the value type, click Add in suggested values. 7. Add a value and display name, and then click OK twice. Using PowerShell New-ADResourceProperty -DisplayName "<DisplayName>"↵ -ResourcePropertyValueType "<ValueType>" Discussion Resource properties are used to authorize access to data. They can be used to describe and classify files through a manual or automatic classification process. Here is a list of built-in resource property value types: 532 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
558
• MS-DS-SingleValuedChoice • MS-DS-YesNo • MS-DS-Number • MS-DS-DateTime • MS-DS-OrderedList • MS-DS-Text • MS-DS-MultiValuedText • MS-DS-MultiValuedChoice See Also “Deploy a Central Access Policy (Demonstration Steps)”; New-ADResourceProperty cmdlet reference; and Active Directory, Fifth Edition, by Brian Desmond et al. (O’Reilly) 14.25. Configuring a Central Access Rule Problem You want to configure a central access rule for Dynamic Access Control. Solution Using a graphical user interface 1. Launch the Active Directory Administrative Center. 2. Select Dynamic Access Control and then click Central Access Rules. 3. From the Tasks menu, click New→Central Access Rule. 4. Enter a name for the rule. 5. If necessary, edit the target resources to customize the scope. 6. If necessary, modify the permissions that will apply to the central access rule. 7. Click OK to create the central access rule. Using PowerShell New-ADCentralAccessRule -Name "<RuleName>" -ResourceCondition "<Conditions>"↵ -CurrentAcl "<ACL>" 14.25. Configuring a Central Access Rule | 533
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
559
Discussion A central access rule assigns permissions to resources under the conditions set on the target resource. Central access rules are used in central access policies, which are then applied on a resource, such as a shared folder. See Also “Deploy a Central Access Policy (Demonstration Steps)”; New-ADCentralAccessRule cmdlet reference; Active Directory, Fifth Edition, by Brian Desmond et al. (O’Reilly) 14.26. Creating a Central Access Policy Problem You want to create a central access policy. Solution Using a graphical user interface 1. Launch the Active Directory Administrative Center. 2. Select Dynamic Access Control and then click Central Access Policies. 3. From the Tasks menu, click New→Central Access Policy. 4. Enter a name for the central access policy. 5. Click Add and select the central access rules to add to the policy by selecting the rule and clicking the double-arrow icon. 6. Click OK twice to create the policy. Using PowerShell New-ADCentralAccessPolicy -Name "<PolicyName>" Add-ADCentralAccessPolicyMember "<PolicyName>" -Members "<CentralAccessRule>" Discussion A central access policy is a collection of central access rules. The policy can be applied to the resource that will be protected. In the PowerShell solution, first we create the access policy and then we add in the central access rules as necessary. 534 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
560
See Also “Deploy a Central Access Policy (Demonstration Steps)”; Active Directory, Fifth Edi‐ tion, by Brian Desmond et al. (O’Reilly) 14.27. Applying a Central Access Policy Problem You want to apply a central access policy by using Group Policy. Solution 1. Launch the Group Policy Management console. 2. Create and link a GPO, or select an existing GPO to apply the central access policy. 3. Right-click the GPO and click Edit. 4. Navigate to Computer Configuration→Policies→Windows Settings→Security Set‐ tings→File System. 5. Right-click Central Access Policy and select Manage Central Access Policies. 6. Select the central access policy you wish to apply and then click Add. Click OK to close the configuration dialog box. Discussion Central access policies complement existing discretionary access control lists (DACLs) by providing another layer of permissions for resource access. You can use Group Policy to effectively and efficiently deploy a central access policy to the specific servers that need the central access policy settings. See Also Recipe 14.27; “Deploy a Central Access Policy (Demonstration Steps)”; Active Directo‐ ry, Fifth Edition, by Brian Desmond et al. (O’Reilly) 14.28. Enabling Domain Controller Support for Claims and Compound Authentication Problem You want to allow domain controllers to provide claims or device authorization. 14.27. Applying a Central Access Policy | 535
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
561
Solution 1. Launch the Group Policy Management console (gpmc.msc). 2. Select the Default Domain Controllers Policy or another GPO that applies to all domain controllers. Right-click the GPO and click Edit. 3. Navigate to Computer Configuration→Policies→Administrative Templates→Sys‐ tem→KDC. 4. Right-click KDS Support for claims, compound authentication, and Kerberos ar‐ moring and select Edit. 5. Click Enabled to enable the configuration and then select Supported from the “op‐ tions” drop-down list. 6. Click OK to close the properties dialog box. KDC support for claims, compound authentication, and Kerberos ar‐ moring has a couple of options (“Always provide claims” and “Fail un‐ armored authentication requests”) that require that the domain be set to the Windows Server 2012 domain functional level. Discussion For domain controllers to provide claims or device authorization, they must be con‐ figured to support Dynamic Access Control. Changing this setting through the Default Domain Controllers Policy allows you to modify this setting for all domain controllers efficiently and effectively. See Also Recipe 14.26; Recipe 14.27; “Deploy a Central Access Policy (Demonstration Steps)”; Active Directory, Fifth Edition, by Brian Desmond et al. (O’Reilly) 14.29. Enabling Claims for Devices in a Domain Problem You want to enable claims for devices within a domain. Solution 1. Launch the Group Policy Management console (gpmc.msc). 536 | Chapter 14: Security and Authentication
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
562
2. Select the Default Domain Policy or another GPO that applies to all domain devices. Right-click the GPO and click Edit. 3. Navigate to Computer Configuration→Policies→Administrative Templates→Sys‐ tem→Kerberos. 4. Right-click Kerberos Support for claims, compound authentication, and Kerberos armoring and select Edit. 5. Click Enabled to enable the configuration and then select Supported from the “op‐ tions” drop-down list. 6. Click OK to close the properties dialog box, and then close the Group Policy Man‐ agement console. 7. Launch the Active Directory Administrative Center. 8. Select Dynamic Access Control and then double-click Claim Types. 9. Right-click the claim that you want to modify and then select Properties. 10. Place a checkmark next to Computer and then click OK. Kerberos support for claims, compound authentication, and Kerberos armoring requires that there be at least one domain controller running Windows Server 2012 to support devices running Windows 8. Discussion For devices to provide claims, they must be configured to support Dynamic Access Control. The two-step process described in this recipe allows you to configure claims for devices within a domain. See Also Recipe 14.28; “Deploy a Central Access Policy (Demonstration Steps)”; Active Directo‐ ry, Fifth Edition, by Brian Desmond et al. (O’Reilly) 14.29. Enabling Claims for Devices in a Domain | 537
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
563
null
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
564
CHAPTER 15 Logging, Monitoring, and Quotas 15.0. Introduction This chapter deals with tracking the activity and usage of various Active Directory components. When you need to troubleshoot a problem, often the first place you look is the logfiles. With Active Directory, there are several different logfiles, and each has different ways to increase or decrease the verbosity of the information that is logged. Viewing log messages can be a useful troubleshooting step, but you should also look at performance metrics to determine whether system hardware or a particular service is being overutilized. In this chapter, we’ll review a couple of ways you can view perfor‐ mance metrics, as well as monitor Active Directory performance. For more extensive monitoring, we suggest looking at Microsoft System Center Operations Manager (OpsMgr), or similar products from other vendors such as NetIQ and Quest. In addition to the typical items that you would monitor on a Windows server (e.g., disk space usage, physical and virtual memory errors, processor utilization), you should also monitor AD-specific performance metrics. This extends to monitoring replication activity and Event Log information. We’ll also cover a somewhat-related topic called quotas, which allow you to monitor and limit the number of objects that a security principal (user, group, or computer) can create within a partition. This feature closes a hole that allowed users who had access to create as many objects in Active Directory as they wanted. These users could cause a denial-of-service attack by creating objects until the disk drive on the domain con‐ trollers filled to capacity. This kind of attack is not likely to happen in most environ‐ ments, but you should still consider the possibility and protect against it. The Anatomy of a Quota Object Container Quota objects are stored in the NTDS Quotas container of the naming contexts and application partitions except for the schema naming context. (Quotas cannot be 539
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
565
associated with the schema NC.) By default, this container is hidden from view within tools such as Active Directory Users and Computers, but you can see it by selecting View→Advanced Features from the menu. The quota object container has an object Class of msDS-QuotaContainer and contains several attributes that define default quota behavior. Table 15-1 lists some of the important attributes of msDS-QuotaContainer objects. Table 15-1. Attributes of msDS-QuotaContainer objects Attribute Description cn RDN of quota container objects. By default, this is equal to NTDSQuotas. msDS-DefaultQuota The default quota applied to all security principals that do not have another quota specification applied. See Recipe 15.18 for more details. msDS-QuotaEffective A constructed attribute that contains the effective quota of the security principal that is viewing the attribute. See Recipe 15.19 for more details. msDS-QuotaUsed A constructed attribute that contains the quota usage of the security principal that is viewing the attribute. See Recipe 15.19 for more details. msDS-TombstoneQuotaFactor Percentage that tombstone objects count against a quota. The default is 100, which means a tombstone object has equal weighting to a normal object. See Recipe 15.17 for more details. msDS-TopQuotaUsage Multivalued attribute that contains information about the security principals with the top quota usage. See Recipe 15.19 for more details. The Anatomy of a Quota Object Quota objects have an objectClass of msDS-QuotaControl, which defines three at‐ tributes that relate to quotas. Table 15-2 contains these attributes and provides a de‐ scription for each. Table 15-2. Attributes of msDS-QuotaControl objects Attribute Description cn RDN of the quota object. msDS-QuotaAmount Number of objects that can be created by the security principals that the quota applies to. See Recipe 15.15 for more information. msDS-QuotaTrustee SID of the security principal that the quota applies to. This can be a user, group, or computer SID. See Recipe 15.15 for more information. 15.1. Enabling Diagnostics Logging Problem You want to enable diagnostics event logging because the current level of logging is not providing enough information to help pinpoint the problem you are troubleshooting. 540 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
566
Solution Using a graphical user interface 1. Run regedit.exe from the command line or from Start→Run. 2. In the left pane, expand the following Registry key: HKEY_LOCAL_MACHINE \System\CurrentControlSet\Services\NTDS\Diagnostics. 3. In the right pane, double-click on the diagnostics logging entry you want to increase, and enter a number (0–5) based on how much you want logged. 4. Click OK. Using a command-line interface > reg add HKLM\SYSTEM\CurrentControlSet\Services\NTDS\Diagnostics /v↵ "<LoggingSetting>" /t REG_DWORD /d <0-5> Using PowerShell Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\NTDS\↵ Diagnostics" -Name "<LoggingSetting>" -Value "<FlagValue>" Discussion A useful way to troubleshoot specific problems you are encountering with Active Di‐ rectory is to increase the diagnostics logging level. Diagnostics logging can be enabled for individual components of AD. For example, if you determine the KCC is not com‐ pleting every 15 minutes, you can enable diagnostics logging for the “1 Knowledge Consistency Checker” setting. These settings are stored under HKLM\SYSTEM\CurrentControlSet\Services\NTDS \Diagnostics. By default, all settings are set to 0, which disables diagnostics logging, but you can increase it by setting it to a number from 1 through 5. As a general rule, a value of 1 is used for minimum logging, 3 for medium logging, and 5 for maximum logging. It is a good practice to ease your way up to 5 because some diagnostics logging settings can generate a bunch of events in the event log, which may make it difficult to read, along with increasing resource utilization on the domain controller. Here is the complete list of diagnostics logging settings: 1 Knowledge Consistency Checker 2 Security Events 3 ExDS Interface Events 4 MAPI Interface Events 5 Replication Events 6 Garbage Collection 7 Internal Configuration 15.1. Enabling Diagnostics Logging | 541
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
567
8 Directory Access 9 Internal Processing 10 Performance Counters 11 Initialization/Termination 12 Service Control 13 Name Resolution 14 Backup 15 Field Engineering 16 LDAP Interface Events 17 Setup 18 Global Catalog 19 Inter-site Messaging 20 Group Caching 21 Linked-Value Replication 22 DS RPC Client 23 DS RPC Server 24 DS Schema 25 Transformation Engine 26 Claims-Based Access Control See Also “Active Directory Diagnostic Logging” 15.2. Enabling NetLogon Logging Problem You want to enable NetLogon logging to help with troubleshooting client account logon, lockout, or domain controller location issues. Solution Using a command-line interface To enable NetLogon logging, use the following command: > nltest /dbflag:0x2080ffff To disable NetLogon logging, use the following command: > nltest /dbflag:0x0 Discussion The netlogon.log file located in %SystemRoot%\Debug can be invaluable for trouble‐ shooting client logon and related issues. When enabled at the highest setting (0x2080ffff), it logs useful information such as the site the client is in, the domain con‐ troller the client authenticated against, additional information related to the DC Locator 542 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
568
process, account password expiration information, account lockout information, and even Kerberos failures. The NetLogon logging level is stored in the following Registry value: HKLM\System\CurrentControlSet\Services\Netlogon\Parameters\DBFlag If you set that Registry value manually instead of using nltest, you’ll need to create the string value, adjust the value, and then restart the NetLogon service for it to take effect. One of the issues with the netlogon.log file is that it can quickly grow to several mega‐ bytes, which makes it difficult to peruse. The command-line tool nlparse can filter the contents of the netlogon.log file so that you’ll see only certain types of log entries. The nlparse tool is part of the Account Lockout and Management Tools. See Also MS KB 109626 (Enabling Debug Logging for the Netlogon Service); MS KB 247811 (How Domain Controllers Are Located in Windows); MS KB 273499 (Description of Security Event 681); “Troubleshooting Netlogon Error Codes” 15.3. Enabling GPO Client Logging Problem You want to troubleshoot GPO processing issues on a client or server by enabling ad‐ ditional logging in the Application event log. Solution Using a graphical user interface 1. Run regedit.exe from the command line or from Start→Run. 2. In the left pane, expand the appropriate key from the table in this recipe’s “Discus‐ sion” section. 3. Create and populate the appropriate key value. 4. Click OK. Using a command-line interface > reg add "<Key Value>" /v "<ValueName>" /t REG_DWORD /d <Value> 15.3. Enabling GPO Client Logging | 543
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
569
Using PowerShell Set-ItemProperty -Path "<RegistryKeyPath>" -Name "<ValueName>" -Value "<Value>" Discussion If you experience problems with client GPO processing, such as a GPO not getting applied even though you think it should, there are a number of different Registry keys that can help you troubleshoot the problem. One way to get detailed information about which GPOs are applied on a client computer is by enabling additional GPO event logging. Table 15-3 lists a number of Registry settings that can be configured to enable Group Policy logging, as well as the files that are created when the settings are enabled. Table 15-3. Registry settings to enable Group Policy logging Logging for the CSE Location Enable verbose logging by adding this key or value ... ...to this Registry key Security CSE %windir%\security \logs\winlogon.log ExtensionDebugLevel = REG_DWORD 0x2 HKEY_LOCAL_MACHINE\Software \Microsoft\Windows NT \CurrentVersion\Winlogon \GpExtensions \{827d319e-6eac-11d2- a4ea-00c04f79f83a}\ Folder Redirection CSE windir%\debug \usermode \fdeploy.log FdeployDebugLevel = Reg_DWORD 0x0f HKEY_LOCAL_MACHINE\Software \Microsoft\Windows NT \CurrentVersion\Diagnostics Software Installation CSE %windir%\debug \usermode \appmgmt.log Appmgmtdebuglevel=dword:0000009b HKEY_LOCAL_MACHINE\Software \Microsoft\Windows NT \CurrentVersion\Diagnostics Windows Installer (deployment-related actions) %windir%\temp \MSI*.log Logging = voicewarmup Debug = DWORD: 00000003 HKEY_LOCAL_MACHINE\Software \Policies\Microsoft\Windows\Installer Windows Installer (user-initiated actions) %temp%\MSI*.log Logging = voicewarmup Debug = DWORD: 00000003 HKEY_LOCAL_MACHINE\Software \Policies\Microsoft\Windows\Installer See Also “Fixing Group Policy problems by using log files”; “Troubleshooting Group Policy Us‐ ing Event Logs”; “Userenvlog for Windows Vista/2008/Win7” 544 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
570
15.4. Enabling Kerberos Logging Problem You want to enable Kerberos logging on a domain controller to troubleshoot authenti‐ cation problems. Solution Using a graphical user interface 1. Run regedit.exe from the command line or from Start→Run. 2. In the left pane, expand HKEY_LOCAL_MACHINE\System\CurrentControlSet \Control\Lsa\Kerberos\Parameters. 3. If the LogLevel value doesn’t already exist, right-click on Parameters and select New→DWORD value. Enter LogLevel for the value name and click OK. 4. In the right pane, double-click on LogLevel and enter 1. 5. Click OK. Using a command-line interface > reg add HKLM\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters↵ /v "LogLevel" /t REG_DWORD /d 1 Using PowerShell Set-ItemProperty -Path↵ "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters" -Name↵ "LogLevel" -Value "1" Discussion If you are experiencing authentication problems or would like to determine whether you are experiencing any Kerberos-related issues, enabling Kerberos logging will ensure that Kerberos errors will be logged in the System event log. The Kerberos events can point out if the problem is related to clock skew, an expired ticket, an expired password, etc. For a good overview of some of the Kerberos error messages, see MS KB 230476. Here is a sample event: Event type: Error Event source: Security-Kerberos Event ID: 3 A Kerberos error message was received: 15.4. Enabling Kerberos Logging | 545
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
571
on logon session user5@adatum ClientTime ServerTime 19:34:26.0000 12/17/2012 Z ErrorCode 0x17 ErrorMessage 0x19 KDC_ERR_PREAUTH_REQUIRED ExtendedError ClientRealm ClientName ServerRealm ADATUM.COM ServerName krbtgt/ADATUM.COM TargetName krbtgt/ADATUM.COM@ADATUM.COM ErrorText File e Line d3a Error Data is in record data. See Also “How to enable Kerberos event logging” 15.5. Viewing DNS Server Performance Statistics Problem You want to view DNS server performance statistics. Solution Using a graphical user interface 1. Open the Performance Monitor. 2. Click on Performance Monitor in the left pane. 3. In the right pane, click the + button. This will bring up the page to add counters. 4. Under “Select counters from computer”, enter the DNS server you want to target. 5. Select the DNS performance object. 6. Select the counters you want to add and click the Add button. 7. Click Close. Using a command-line interface > dnscmd <DNSServerName> /statistics 546 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
572
Using PowerShell Get-EventLog "DNS Server" Discussion The Microsoft DNS Server keeps track of dozens of performance metrics. These metrics include the number of queries, updates, transfers, directory reads, and directory writes processed by the server. If you can pump these metrics into an enterprise management system, you can track DNS usage and growth over time. These statistics can also be useful to troubleshoot load-related issues. If you suspect a DNS server is being overwhelmed with DNS update requests, you can look at the Dy‐ namic Update Received/sec counter and see whether it is processing an unusually high number of updates. Using a command-line interface You can obtain a subset of the statistics by providing a statid after the /statistics option. Each statistics category has an associated number (i.e., statid). For a complete list of categories and their statids, run the following command: > dnscmd /statistics /? Here is an example of viewing the Query (statid = 2) and Query2 (statid = 4) statistics: > dnscmd /statistics 6 DNS Server . statistics: Queries and Responses: ---------------------- Total: Queries Received = 14902 Responses Sent = 12900 UDP: Queries Recvd = 14718 Responses Sent = 12716 Queries Sent = 23762 Responses Recvd = 0 TCP: Client Connects = 184 Queries Recvd = 184 Responses Sent = 184 Queries Sent = 0 Responses Recvd = 0 Queries: -------- Total = 14902 Notify = 0 15.5. Viewing DNS Server Performance Statistics | 547
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
573
Update = 2207 TKeyNego = 184 Standard = 12511 A = 1286 NS = 29 SOA = 2263 MX = 0 PTR = 1 SRV = 8909 ALL = 0 IXFR = 0 AXFR = 0 OTHER = 23 Command completed successfully. See Also MSDN: MicrosoftDNS_Statistic 15.6. Monitoring the Windows Time Service Problem You want to verify the correct functioning of the Windows Time Service. Solution Using a command-line interface The following syntax verifies that the Windows Time Service is functioning on dc1.ada‐ tum.com and dc2.adatum.com: > w32tm /monitor /computers:dc1.adatum.com,dc2.adatum.com Discussion Because Active Directory relies on Kerberos for authentication, it’s critical that all of your domain controllers, member servers, and client computers maintain a consistent time across the network; if any computer’s clock is off by more than five minutes, then by default, it will not be able to authenticate to Active Directory. You can use the w32tm utility to verify time synchronization on one or more computers using the /monitor switch, as well as using the /resync switch to prompt a computer to immediately re‐ synchronize its clock with its authoritative time source. 548 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
574
See Also “Configuring a Time Source for the Forest”; “How to configure an authoritative time server in Windows Server” 15.7. Enabling Inefficient and Expensive LDAP Query Logging Problem You want to log inefficient and expensive LDAP queries to the Directory Services event log. Solution To log a summary report about the total number of searches, total expensive searches, and total inefficient searches to the Directory Services event log, set the 15 Field Engi‐ neering diagnostics logging setting to 4. This summary is generated every 12 hours during the garbage collection cycle. To log an event to the Directory Services event log every time an expensive or inefficient search occurs, set the 15 Field Engineering diagnostics logging setting to 5. See Recipe 15.1 for more on enabling diagnostics logging. Discussion A search is considered expensive if it has to visit a large number of objects in Active Directory. The default threshold for an expensive query is 10,000. That means any search that visits 10,000 or more objects would be considered expensive. A search is considered inefficient if it returns fewer than 10 percent of the total objects it visits. If a query visited 10,000 objects and only returned 999 of them (less than 10 percent), it would be con‐ sidered inefficient. The default bottom limit for an inefficient query is 1,000. If the query returned 1,000 instead, it would not be considered inefficient. To summarize, with 1,000 as the default bottom threshold, no search that visits fewer than 1,000 entries (even if it visited 999 and returned 0) would be considered inefficient. Here is a sample summary report event that is logged when 15 Field Engineering is set to 5: Log Name: Directory Service Source: Microsoft-Windows-ActiveDirectory_DomainService Date: 12/21/2012 11:38:32 PM Event ID: 1643 Task Category: Field Engineering Level: Information 15.7. Enabling Inefficient and Expensive LDAP Query Logging | 549
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
575
Keywords: Classic User: ANONYMOUS LOGON Computer: adatum-dc.adatum.com Description: Internal event: Active Directory Domain Services performed the following number↵ of search operations within this time interval. Time interval (hours): 0 Number of search operations: 38529 During this time interval, the following number of search operations were↵ characterized as either expensive or inefficient. Expensive search operations: 7 Inefficient search operations: 22 If you set 15 Field Engineering to 5, the summary event is logged during the garbage collection cycle, and event 1644 is generated every time an expensive or inefficient search occurs. Setting this value can provide useful information if you are running applications that regularly generate expensive or inefficient queries. Notice that this event provides details on all aspects of the search, including the authenticating user, search base DN, search filter, attributes, controls, number of entries visited, and number of entries returned. The following entry is from a Windows Server 2012 domain con‐ troller: Log Name: Directory Service Source: Microsoft-Windows-ActiveDirectory_DomainService Date: 12/22/2012 1:19:05 AM Event ID: 1644 Task Category: Field Engineering Level: Information Keywords: Classic User: SYSTEM Computer: dc1.adatum.com Description: Internal event: A client issued a search operation with the following options. Client: SAM Starting node: dc=adatum,dc=com Filter: ( & (userAccountControl&2) (objectClass=user) (objectCategory=cn=Person,cn=Schema,cn=Configuration,dc=adatum,dc=com) ) Search scope: subtree Attribute selection: 550 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
576
[shortnames]objectSid,sAMAccountName,userAccountControl Server controls: Visited entries: 51443 Returned entries: 3513 With the default settings, the query shown in the preceding event is considered both expensive and inefficient. It is expensive because it visited more than 10,000 entries. It is inefficient because it returned fewer than 10 percent of those entries. You can customize what a domain controller considers expensive and inefficient by creating a couple of Registry values under the HKLM\SYSTEM\CurrentControlSet \Services\NTDS\Parameters key. You can create a value named Expensive Search Re sults Threshold of type DWORD and specify the number of entries a search would need to visit to be considered expensive. Similarly, you can create a value named Inefficient Search Results Threshold of type DWORD and specify the minimum number of entries visited where a match returning fewer than 10 percent would be considered inefficient. If you want to see all the LDAP queries that are being sent to a domain controller, a quick way to do that would be to set the 15 Field Engi‐ neering setting to 5 and Expensive Search Results Threshold to 0. This would cause the domain controller to consider every search as expen‐ sive and log all the LDAP searches. While this can be very useful, you should use it with care as it could quickly fill your event log. Be sure to allow sufficient disk space for your event logs to avoid any issues with low disk space on your domain controllers. See Also Recipe 15.1 for enabling diagnostics logging 15.8. Using the STATS Control to View LDAP Query Statistics Problem You want to use the STATS LDAP control to test the efficiency of a query. 15.8. Using the STATS Control to View LDAP Query Statistics | 551
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
577
Solution Using a graphical user interface 1. Launch LDP.exe. 2. From the menu, select Connection→Connect. 3. For Server, enter the name of a domain controller. 4. For Port, enter 389. 5. Click OK. 6. From the menu, select Connection→Bind. 7. Enter the credentials of a user to perform the search or accept the default and bind as the currently logged on user. 8. Click OK. 9. From the menu, select Options→Controls. 10. From the Load Predefined drop-down, select Search Stats. 11. Click OK. 12. From the menu, select Browse→Search. 13. Enter your search criteria and then click the Options button. 14. Under Search Call Type, be sure that Extended is selected. 15. Click OK and then click Run. The status will be shown at the top of the search results. Using a command-line interface The AdFind command-line utility has four switches that will display efficiency statistics for any query: -stats Enables the STATS control to return statistics about the query, along with the actual results of the query -statsonly Returns only the statistics about the query, and suppresses the actual query results -stats+ Similar to -stats, but also displays additional advanced analysis about the query -stats+only Just like -stats+, but will suppress the actual results of the query and display only the query statistics 552 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
578
Discussion The STATS control is a useful way to obtain statistics about the performance of an LDAP query. With the STATS control, you can find out information such as the amount of time it took the server to process the query, how many entries were visited versus re‐ turned, what the search filter expanded to, and whether any indexes were used. Here is an example of what the STATS control returns for a search for all group objects in the cn=Users container: Statistics ================================================== Elapsed time: 0 (ms) Returned 18 of 23 visited - (78.26%) Used Filter: (objectCategory=cn=Group,cn=Schema,cn=Configuration,cn=adatum,cn=com Used Indices: Ancestors_index:23:N Pages referenced: 332 Pages read from disk: 0 Pages pre-read from Disk: 0 Analysis -------------------------------------------------- Indices used: Index name: Ancestors_index Record count: 23 (estimate) Index type: Normal attribute index Ancestor index used, possibly inefficient, verify filter A couple of things are worth noting here. You can also see that the filter used, (object category=group), was expanded to: (objectCategory=cn=Group,cn=Schema,cn=Configuration,dc=adatum,dc=com) The syntax of the objectCategory attribute is a distinguished name, but Active Direc‐ tory provides a shortcut so that you need to use only the LDAP display name of the class instead. Internally, Active Directory converts the display name to the distinguished name, as shown here. Finally, we can see that our search used an index, INTERSECT_IN DEX:17:I. Let’s look at another example, except this time we’ll perform an ANR search for Jim Smith: ***Searching ... ldap_search_ext_s(ld, "ou=Sales,dc=adatum,dc=com", 2, "(anr=Jim Smith)", attrList, 0, svrCtrls, ClntCtrls, 20, 1000 ,&msg) 15.8. Using the STATS Control to View LDAP Query Statistics | 553
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
579
Result <0>: Matched DNs: Stats: Call Time: 20 (ms) Entries Returned: 1 Entries Visited: 2 Used Filter: ( | (displayName=Jim Smith*) (givenName=Jim Smith*) (legacyExchangeDN=Jim Smith) (msDS-AdditionalSamAccountName=Jim Smith*) (physicalDeliveryOfficeName=Jim Smith*) (proxyAddresses=Jim Smith*) (name=Jim Smith*) (sAMAccountName=Jim Smith*) (sn=Jim Smith*) ( & (givenName=Jim*) (sn=Smith*) ) ( & (givenName=Smith*) (sn=Jim*) ) ) Used Indexes: idx_givenName:10:N;idx_givenName:10:N;idx_sn:9:N;idx_ sAMAccountName:8:N;idx_name:7:N;idx_proxyAddresses:6:N;idx_ physicalDeliveryOfficeName:5:N;idx_msDS-AdditionalSamAccountName:4:N;idx_ legacyExchangeDN:3:N;idx_givenName:2:N;idx_displayName:1:N; You can see from the second line that we used a very simple filter, (anr=Jim Smith). If you look down a little farther at Used Filter: you can see a better example of search￾filter expansion. Like the objectCategory example earlier, ANR is a shorthand way to do something complex. A simple one-term search filter expands into a multiterm filter that searches across numerous attributes. (For more on the behavior of ANR, see Recipe 10.12.) The point of showing this is to illustrate that the STATS control is very powerful and can be an invaluable tool when trying to troubleshoot or optimize LDAP queries. See Also Recipe 4.4 for using LDAP controls; Recipe 4.8 for searching for objects; Recipe 10.12 for more on ANR; Recipe 15.7 for more on expensive and inefficient searches 15.9. Monitoring the Performance of Active Directory Problem You want to use the Performance Monitor to examine the performance of Active Directory. Solution Using a graphical user interface 1. Open the Performance Monitor (perfmon.exe). 2. Click on Performance Monitor in the left pane. 3. Click the + button. This will bring up the page to add counters. 554 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
580
4. Under “Select counters from computer”, enter the name of the domain controller you want to target. 5. Select the NTDS performance object. 6. Select the counters that you want to monitor. 7. After you’re done with your selections, click Close. Using PowerShell To retrieve a continuous counter for a performance object, use the following PowerShell command: Get-Counter -Counter "<PerformanceObject>" -Continuous For example, to view the performance counter for the DS Directory Searches/sec object, run the following command: Get-Counter -Counter "\NTDS\DS Directory Searches/sec" -Continuous Discussion There are several Performance Monitor counters that can be very valuable for moni‐ toring and troubleshooting Active Directory. The NTDS performance object has coun‐ ters for address-book lookups; inbound and outbound replication; LDAP reads, writes, and searches; and the Security Account Manager (SAM). Here is a list of some of the most useful NTDS counters. We’ve also included their Performance Monitor explanation, which you can view by clicking on the Explain but‐ ton in the Add Counters dialog box. DRA Inbound Bytes Total/sec Shows the total number of bytes received through replication. It is the sum of the number of uncompressed bytes (never compressed) and the number of compressed bytes (after compression). DRA Inbound Objects/sec Shows the number of objects received from neighbors through inbound replication. A neighbor is a domain controller from which the local domain controller replicates locally. DRA Inbound Values Total/sec Shows the total number of object property values received from inbound replication partners. Each inbound object has one or more properties, and each property has zero or more values. A zero value indicates property removal. 15.9. Monitoring the Performance of Active Directory | 555
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
581
DRA Outbound Bytes Total/sec Shows the total number of bytes replicated out. It is the sum of the number of uncompressed bytes (never compressed) and the number of compressed bytes (after compression). DRA Outbound Objects/sec Shows the number of objects replicated out. DRA Outbound Values Total/sec Shows the number of object property values sent to outbound replication partners. DRA Pending Replication Synchronizations Shows the number of directory synchronizations that are queued for this server but not yet processed. DS Client Binds/sec Shows the number of ntdsapi.dll binds per second serviced by this DC. DS Directory Reads/sec Shows the number of directory reads per second. DS Directory Searches/sec Shows the number of directory searches per second. DS Directory Writes/sec Shows the number of directory writes per second. LDAP Bind Time Shows the time, in milliseconds, taken for the last successful LDAP bind. LDAP Client Sessions Shows the number of currently connected LDAP client sessions. LDAP Searches/sec Shows the rate at which LDAP clients perform search operations. LDAP Successful Binds/sec Shows the number of LDAP binds per second. LDAP Writes/sec Shows the rate at which LDAP clients perform write operations. 556 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
582
15.10. Using Perfmon Trace Logs to Monitor Active Directory Problem You want to enable Trace Logs to view system-level calls related to Active Directory. Solution Using a graphical user interface 1. Open the Performance Monitor (perfmon.exe). 2. In the left pane, expand Data Collector Sets. 3. Right-click Event Trace Sessions and click New→Data Collector Sets. 4. In the Name: field, enter AD Trace Log. Click Next. 5. Click Add. In the Event Trace Providers screen, click Active Directory Domain Services: Core. Click OK. 6. Click Next, note the directory to be used for the log, and then click Next again. 7. Click the “Start this data collector set now” radio button and click Finish. 8. Open a command prompt and run the following command: tracerpt <LogFileName> Discussion Trace Logs capture detailed system- and application-level events. Applications support Trace Log capability by developing a Trace Log Provider. Active Directory supports several providers that log low-level system calls related to Kerberos, LDAP, and DNS, to name a few. This can be an extremely valuable tool for debugging or just exploring the inner workings of Active Directory. Trace Logs can be resource-intensive, so you should enable them with care. The tracerpt/tracedmp commands generate a summary.txt file that summarizes all of the events by total. A second file called dumpfile.xml is created by default, but the dump format can be changed by specifying the -of switch, with a CSV, EVTX, or XML value. Here is an example of what the summary.txt file looks like on a domain controller that had all of the Active Directory−related Trace Log Providers enabled: Files Processed: AD Trace Log.etl 15.10. Using Perfmon Trace Logs to Monitor Active Directory | 557
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
583
Total Buffers Processed 18 Total Events Processed 720 Total Events Lost 0 Start Time Saturday, December 22, 2012 End Time Saturday, December 22, 2012 Elapsed Time 51 sec +--------------------------------------------------------------------------------+ |Event Count Event Name Task Opcode Version Guid +--------------------------------------------------------------------------------+ | 1 EventTrace 0 DbgIdRSDS 2 {68fdd900-4a3e-11d1↵ -84f4-0000f80464e3}| | 1 EventTrace 0 BuildInfo 2 {68fdd900-4a3e-11d1↵ -84f4-0000f80464e3}| | 1 EventTrace 0 Header 2 {68fdd900-4a3e-11d1↵ -84f4-0000f80464e3}| | 2 DsDrsReplGtChg 0 End 4 {14f8aa24-7f4b-11d2↵ -b389-0000f87a46c8}| | 2 DsDrsReplGtChg 0 Start 4 {14f8aa24-7f4b-11d2↵ -b389-0000f87a46c8}| | 125 LdapRequest 0 End 4 {b9d4702a-6a98-11d2↵ -b710-00c04fb998a2}| +--------------------------------------------------------------------------------+ Here you can see that over a 51-second period, there was one Event Trace request (EventTrace), two directory replication change requests (DsDrsReplGtChg), and 125 total LDAP requests (LdapRequest). The dumpfile.csv file contains entries for every event that was generated during the time period. Here is an example of an entry for one of the DsDrsReplGtChg requests (note that the lines will wrap due to their length, so we’ve added a blank line in between for separation): DsDrsReplGtChg, Start, 0, 4, 0, 0, 1, 0, 0x0000000000000000, 0x00000240, 0x00001388, 0, , , {00000000-0000-0000-0000-000000000000}, , 130006457569095598, 15, 0, "DS", 4, 8, 3506765888, 0, "e5a1b109-4add-4503-a909-66e55820265c (DC2.adatum.com)", "dc=adatum,dc=com", "250469", "250469", "2147483760", "536", "5363998", "0", 0x00000000000000000000A7E12200CD00 DsDirGtNcChg, Start, 0, 4, 0, 0, 1, 0, 0x0000000000000000, 0x00000240, 0x00001388, 0, , , {00000000-0000-0000-0000-000000000000}, , 130006457569097056, 15, 0, "DS", 4, 6, 805568576, 0, "e5a1b109-4add-4503-a909-66e55820265c (DC2.adatum.com)", "dc=adatum,dc=com", "250469", "80000070", "0", "0", 0x47D92200CD000000A820303D Based on those two lines, you can see Active Directory Domain Services replication commutation occur from this server to another server named dc2.adatum.com. 558 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
584
15.11. Creating an Administrative Alert Problem You want to define a threshold for a performance counter that should cause an alert to be generated. Solution Using a graphical user interface 1. Open the Performance Monitor (perfmon.exe). 2. Expand Data Collector Sets. Right-click User-Defined and click New→Data Col‐ lector Set. 3. In the Name text box, enter AD Performance Alert. Select the “Create manually” radio button and click Next. 4. Click the Performance Counter Alert radio button and click Next. 5. Click Add. Select the counter that you wish to be alerted about. Click Add and click OK. 6. In the “Alert when:” drop-down box, click Above or Below. In the Limit text box, enter the threshold value that you wish to monitor. Click Next. 7. Click the “Start this data collector now” radio button. Click Finish. Discussion There are a number of options for monitoring the ongoing performance of the Windows operating system, whether the machine in question is a domain controller, member server, or client computer. For larger environments, you can look into add-on tools such as the Microsoft System Center Operations Manager (OpsMgr) or third-party utilities from NetPro, NetIQ, and others. For a built-in solution, however, the Performance Monitor MMC snap-in can monitor performance metrics and send various adminis‐ trative alerts. See Also “Windows Performance Monitor” 15.11. Creating an Administrative Alert | 559
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
585
15.12. Emailing an Administrator on a Performance Alert Problem You want to create an alert that will notify an administrator via email if a performance alert is generated. Solution Using PowerShell You can create a Windows scheduled task that runs the following PowerShell command. Then, the task can be called from a performance counter alert in Performance Monitor. Send-MailMessage -SmtpServer "<ServerName>" -From "<FromAddress>"↵ -To "<ToAddress>" -Subject "<MessageSubject>" -Body "<MessageBody>" Discussion A common request among Windows system administrators is to have the ability to email an on-call administrator when a critical performance alert is generated—for ex‐ ample, when a domain controller is experiencing a critical hardware failure. It is a rel‐ atively simple matter to send email through PowerShell using the sample command shown in the solution. You can either hardcode the appropriate alert messages into the email message and maintain multiple scripts for the various alerts that you create, or include counter information in each message by using a generic email message (see Recipe 15.9). Using the Performance Monitor MMC, you can submit one or more of the following as command-line arguments to a script that’s been fired in response to an alert: • Date/time • The value that was measured by the alert • The name of the alert • The name of the counter being measured • The value of the limit that was exceeded • A manually defined text string You can also use a number of third-party tools to implement this solution, such as the open-source Blat SourceForge project, which allows you to send SMTP or NNTP messages from a command line. 560 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
586
See Also Send-MailMessage cmdlet overview 15.13. Enabling Auditing of Directory Access Problem You want to enable auditing of directory access and modifications. Audit events are logged to the Security event log. Solution Using a graphical user interface 1. Open the Group Policy Management snap-in (gpmc.msc) and edit the Default Do‐ main Controllers Policy. 2. In the left pane, expand Computer Configuration→Policies→Windows Set‐ tings→Security Settings→Local Policies and click on Audit Policy. 3. In the right pane, double-click “Audit directory service access.” 4. Make sure the box is checked beside “Define these policy settings.” 5. Check the box beside Success and/or Failure. 6. Click OK. Alternatively, you can also use the Advanced Audit Policy Configuration settings, which allow for a bit more granularity: 1. Open the Group Policy Management snap-in (gpmc.msc) and edit the Default Do‐ main Controllers Policy. 2. In the left pane, expand Computer Configuration→Policies→Windows Set‐ tings→Security Settings→Advanced Audit Configuration Policy and click on Audit Policies. 3. In the right pane, double-click “DS access.” 4. In the right pane, enable “Success and/or Failure auditing” for the Audit Directory Service Access and the Audit Directory Service Changes subcategories. Discussion You can log events to the Security event log for every successful and/or failed attempt to access or modify the directory, which is referred to as auditing. Auditing is enabled 15.13. Enabling Auditing of Directory Access | 561
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
587
via the Security Settings section of a GPO that’s linked to the Domain Controllers OU, using either the “Audit directory service access” setting or the “Advanced Audit Policy Configuration” settings. Once either is enabled, you need to use the ACL Editor to define auditing in the SACL of the objects and containers you want to monitor. By default, the domain object has an inherited audit entry for the Everyone security principal for all object access and modifications. That means once you enable auditing in the Domain Controller Security Policy and this configuration change replicates out, domain controllers will log events for any directory access or modification to any part of the directory. As you can imagine, auditing every access to Active Directory can generate a lot of events, so you’ll either want to disable auditing of the Everyone group and use the Advanced Audit Policy Configuration settings instead, or else keep a close eye on your domain controllers to ensure that they are not adversely affected while auditing is enabled. Here is a sample event that was logged after the Administrator account created a user object called foobar in the Sales OU: Event Type: Audit Success Event Source: Microsoft Windows security Task Category: User Account Management Event ID: 4720 Date: 12/26/2012 Time: 7:24:10 PM User: N/A Computer: DC1 A user account was created. Subject: Security ID: ADATUM\administrator Account Name: administrator Account Domain: ADATUM Logon ID: 0x36BFF New Account: Security ID: ADATUM\foobar Account Name: foobar Account Domain: ADATUM Attributes: SAM Account Name: foobar Display Name: foobar User Principal Name: foobar@adatum.com Home Directory: - Home Drive: - Script Path: - Profile Path: - User Workstations: - Password Last Set: <never> Account Expires: <never> 562 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
588
Primary Group ID: 513 Allowed To Delegate To: - Old UAC Value: 0x0 New UAC Value: 0x15 User Account Control: Account Disabled 'Password Not Required' - Enabled 'Normal Account' - Enabled User Parameters: - SID History: - Logon Hours: <value not set> Additional Information: Privileges - It can also be useful to enable Audit Account Management in the GPO that’s linked to the Domain Controllers OU. This provides additional information about account-management operations—for example, finding what account deleted a certain object. Once you have enabled auditing of Directory Service Changes and configured auditing on the relevant objects or containers, the Directory Services Event Viewer will record detailed entries whenever an AD object is created, modified, moved, or deleted, as follows: • Event 4738 will be logged when an object is modified. In the case of a modify event, you will see the old value (e.g., the old description attribute) and the new value (e.g., the new description attribute). • Event 4720 will be logged when an object is created. • Event 4725 will be logged when an object is disabled. • Event 4740 will be logged when an object is locked out. • Event 4726 will be logged when an object is deleted. See Also “Advanced Security Audit Policy Settings”; “Planning and Deploying Advanced Security Audit Policies” 15.13. Enabling Auditing of Directory Access | 563
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
589
15.14. Enabling Auditing of Registry Keys Problem You want to enable auditing of any changes to one or more Registry keys. Solution Using a graphical user interface To enable auditing of a Registry key on an individual domain controller, do the following: 1. Create a Group Policy Object (or edit an existing GPO) that enables settings under the following path: Computer Configuration→Policies→Windows Settings→Se‐ curity Settings→Local Policies→Audit Policy: • Audit object access: Success • Audit object access: Failure 2. Link the GPO to the OU containing the DC that you wish to audit. 3. On the DC that you want to audit, open regedit.exe. 4. Navigate to the Registry key that you want to enable auditing on. 5. Right-click on the key and select Permissions. Click Advanced and select the Au‐ diting tab. 6. Click Add to select a user or group to audit, then click OK. For Apply Onto, select “This key only,” “This key and subkeys,” or “Subkeys only.” 7. Under Access, select the actions that should be audited, and click OK. If you need to enable auditing of the same Registry keys on multiple computers, a much more efficient solution would be to use a GPO as follows: 1. Create a Group Policy Object (or modify an existing GPO) that enables the fol‐ lowing settings under Computer Configuration→Policies→Windows Set‐ tings→Security Settings→Local Policies→Audit Policy: • Audit object access: Success • Audit object access: Failure 2. Navigate to Computer Configuration→Policies→Windows Settings→Security Set‐ tings→Registry. 564 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
590
3. Right-click on Registry and select “Add key.” On the “Select Registry key” screen, navigate to the key that you want to audit and click OK. 4. Right-click on the key and select Permissions. Click Advanced and select the Au‐ diting tab. 5. Click Add to select a user or group to audit, then click OK. For Apply Onto, select “This key only,” “This key and subkeys,” or “Subkeys only.” 6. Under Access, select the actions that should be audited, and click OK. 7. Link the GPO to the container containing the computers that you wish to audit. The Advanced Audit Policy Configuration settings offer another way to audit the Registry. This method allows you to use a global object access audit policy, which provides for auditing without having to spec‐ ify security access control lists (SACLs). For additional information, check out the “See Also” section of this recipe. Discussion Before you can enable auditing on specific Registry keys, you must create an audit policy that enables auditing of object access events, both Success and Failure events. You can enable auditing by modifying an existing GPO or by creating a new GPO created ex‐ pressly for this purpose. Maintaining a number of single-purpose GPOs can make for easier Group Policy troubleshooting but can lead to performance implications if clients need to process too many GPOs at logon and during the background refresh of Group Policy. As is usually the case, the definition of “too many” will vary from one environ‐ ment to the next; it’s important to monitor the performance of your clients to determine which approach is appropriate for your environment. Once you’ve enabled auditing of a specific key or keys, information about the activity that you’ve chosen to audit will appear in the Security event log of the computer where the event took place. See Also “Advanced Security Audit Policy Step-by-Step Guide” 15.15. Creating a Quota Problem You want to limit the number of objects a security principal can create in a partition by creating a quota. 15.15. Creating a Quota | 565
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
591
Solution Using a command-line interface > dsadd quota -part <PartitionDN> -qlimit <QuotaLimit> -acct <PrincipalName>↵ [-rdn <QuotaName>] The following command creates a quota specification that allows the ADATUM\rall‐ en user to create only five objects in the dc=adatum,dc=com partition: > dsadd quota -part dc=adatum,dc=com -qlimit 5 -acct ADATUM\rallen Discussion Quotas allow an administrator to limit the number of objects that a user (or group of users) can create. A quota applies not just to a user object, but also to the creation of any object type in Active Directory. Three things need to be set when creating a quota specification: Partition Currently, quotas can apply only to an entire partition. You cannot create a quota that pertains only to a subtree in a partition. You can create quotas for any partition, including application partitions, except for the schema naming context. The rea‐ soning behind this restriction is that the schema is a highly protected area of the directory, and you shouldn’t need to restrict how many objects get created there. Target security principal A quota can be defined for any type of security principal. The msDS￾QuotaTrustee attribute on the quota object stores the target principal in the form of an SID. Limit This determines how many objects the target security principal can create. The quota limit is a combination of the new objects that a user creates plus any tomb‐ stone objects that are created by that user. If a user creates an object and then deletes another object, that would still count as two objects toward any quotas that apply to the user. This is because when an object is deleted, it isn’t removed; it is simply marked as tombstoned. Once the tombstone object is removed from Active Directory, the user’s quota will be decremented accordingly. By default, a tombstone object counts as one object, but that is configurable. See Recipe 15.17 for more on changing the tombstone quota factor. Since quotas can be assigned to both users and groups, it is conceivable that multiple quotas may apply to a user. In this case, the quota with the highest limit will be in force for the user. You can also create a default quota for a partition that applies to all security principals. See Recipe 15.18 for more information on configuring the default quota. 566 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
592
Quotas do not apply to members of the Enterprise Admins and Domain Admins groups. Even if you’ve configured a default quota for all users, members of those administrative groups will not have any restrictions. See Also Recipe 8.13 for more on the computer object quota; this chapter’s Recipe 15.0 section for more on the attributes of quota objects; Recipe 15.16 for finding the quotas assigned to a security principal; Recipe 15.17 for changing the tombstone quota factor; Recipe 15.18 for setting a default quota 15.16. Finding the Quotas Assigned to a Security Principal Problem You want to find the quotas that have been configured for a security principal (i.e., user, group, or computer). Solution Using a command-line interface > dsquery quota <PartitionDN> -acct <PrincipalName> The following command searches for quotas that have been assigned to the ADATUM \rallen user in the dc=adatum,dc=com partition: > dsquery quota dc=adatum,dc=com -acct ADATUM\rallen Using PowerShell The following command searches for all quotas in a domain: Get-ADObject -Filter {objectClass -eq "msDS-QuotaControl"} | FL Name Discussion The DSQuery solution will find only quotas that have been directly assigned to a security principal; it will not list quotas that have been assigned to any group objects that the principal may be a member of. The msDS-QuotaTrustee attribute on quota objects de‐ fines an SID that the quota applies to. The dsquery quota command will look up the SID for the specified account and match that against quota objects that reference that SID. Unfortunately, this doesn’t quite show the whole picture. A user could have a quota assigned directly, which the DSQuery command would show, but the user could also be part of one or more groups that have quotas assigned. These won’t show up using 15.16. Finding the Quotas Assigned to a Security Principal | 567
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
593
DSQuery. The PowerShell solution lists all quotas, including groups, for the Active Directory domain. However, it does not show a relation between the user object and any groups returned. A more robust solution would entail retrieving the tokenGroups attribute of the user, which contains a list of SIDs for all expanded group memberships, and then querying each of those groups to determine whether any of them have quotas assigned. This is actually the type of algorithm that is used to determine a user’s effective quota, as shown in Recipe 15.19. See Also Recipe 15.15 for creating a quota; Recipe 15.19 15.17. Changing How Tombstone Objects Count Against Quota Usage Problem You want to change the relative weight of tombstone objects in quota calculations. Solution Using a graphical user interface 1. Open ADSI Edit. 2. Connect to the partition on which you want to modify this setting. (This setting must be changed for each partition that you want to configure.) 3. In the left pane, expand the root of the partition. 4. Right-click on cn=NTDS Quotas and select Properties. 5. Set the msDS-TombstoneQuotaFactor attribute to a value between 0 and 100. 6. Click OK. Using a command-line interface Create an LDIF file called change_ tombstone_quota.ldf with the following contents: dn: cn=NTDS Quotas,<PartitionDN> changetype: modify replace: msDs-TombstoneQuotaFactor msDs-TombstoneQuotaFactor: <1-100> - 568 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
594
Then run the following command: > ldifde -v -i -f change_tombstone_quota.ldf You can also make the change using DSMod or AdMod. DSMod takes the following syntax: > dsmod partition <PartitionDN> -qtmbstnwt <1-100> You can make the change with AdMod, as follows: > admod -b <PartitionDN> msDs-TombstoneQuotaFactor::<0-100> Using PowerShell You can modify the tombstone quota factor by using PowerShell, as follows: Set-ADObject "<PartitionDN>" -Replace↵ @{"msDS-TombstoneQuotaFactor"="<QuotaValue>"} Discussion The tombstone quota factor is a percentage that determines how much each tombstone object counts against a security principal’s quota usage. By default, tombstone objects count as one object. This means if a user’s quota is set to 10 and the user deletes 10 objects, that user will not be able to create or delete any other objects until those tomb‐ stone objects have been purged from Active Directory. The msDs-TombstoneQuotaFactor attribute on the NTDS Quota container for each par‐ tition defines the tombstone quota factor. As mentioned previously, the default is that tombstone objects count 100 percent of a normal object; thus, the attribute msDs￾TombstoneQuotaFactor contains 100 by default. If you modify this attribute to contain a value of 50 and a user has a quota limit of 10, then that user could delete a maximum of 20 objects (i.e., create 20 tombstone objects) because 20 × 50 percent = 10. As another example, you may not care about how many objects your users delete; in this case, you’d want to set the tombstone quota factor to 0 so that tombstoned objects would not count against a user’s NTDS quota at all. See Also MSDN: ms-DS-Tombstone-Quota-Factor attribute [AD Schema]; MSDN: ms-DS￾Quota-Container class [AD Schema]; “Active Directory Quotas” 15.17. Changing How Tombstone Objects Count Against Quota Usage | 569
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf
595
15.18. Setting the Default Quota for All Security Principals in a Partition Problem You want to set a default quota for all security principals. Solution Using a graphical user interface 1. Open ADSI Edit. 2. Connect to the partition you want to modify. (This setting must be changed for each partition that you want to configure.) 3. In the left pane, expand the root of the partition. 4. Right-click on cn=NTDS Quotas and select Properties. 5. Set the msDS-DefaultQuota attribute to the number of objects that security prin‐ cipals should be allowed to create if they are not assigned another quota. 6. Click OK. Using a command-line interface Create an LDIF file called set_default_quota.ldf with the following contents: dn: cn=NTDS Quotas,<PartitionDN> changetype: modify replace: msDs-DefaultQuota msDs-DefaultQuota: <NumberOfObjects> - Then run the following command: > ldifde -v -i -f set_default_quota.ldf You can also make the change using DSMod or AdMod. DSMod takes the following syntax: > dsmod partition <NTDS Quotas DN> -qdefault <DefaultQuota> You can make the change with AdMod, as follows: > admod -b <NTDS Quotas DN> msDs-DefaultQuota::<DefaultQuota> Using PowerShell You can modify the tombstone quota factor using PowerShell, as follows: 570 | Chapter 15: Logging, Monitoring, and Quotas
http://ter40.free.fr/ebooktmp/new/Active%20Directory%20Cookbook,%204th%20Edition.pdf