# KDS root key count should be acceptable

KDS root keys are used to generate keys required for Group Managed Service Accounts (gMSA) and related group-managed credential operations.

Source: https://maester.dev/docs/tests/AD-CFG-22

<!-- This file is generated by website/scripts/generate-test-docs.mjs. Do not edit manually. -->

<div class="test-byline"><div class="test-byline-avatars"><a class="test-byline-avatar test-byline-avatar--author" href="/contributors/soulemike" title="Michael Soule · Original author"><img src="https://github.com/soulemike.png" alt="Michael Soule" width="28" height="28" loading="lazy" decoding="async" /></a></div><div class="test-byline-meta"><span class="test-byline-text">Contributed by <a href="/contributors/soulemike">Michael Soule</a></span><a class="test-byline-link" href="/contributors">All contributors →</a></div></div>

<p class="test-part">Part of <a href="/docs/tests/ad">Active Directory</a> · Active Directory · Directory configuration · <a href="/docs/tests">All checks</a></p>

```powershell title="Run this check"
Invoke-Maester -TestId AD-CFG-22
```

## Overview

KDS root keys are used to generate keys required for Group Managed Service Accounts (gMSA) and related group-managed credential operations.

If KDS root keys are missing, misconfigured, or unexpectedly changed, service account provisioning can fail—potentially causing insecure workarounds or prolonged downtime.

Monitoring the *count* of KDS root keys helps identify:
- Missing keys that prevent proper gMSA key derivation
- Exactly two keys, which can cause gMSA authentication failures in some scenarios

#### Control Type

**Operational**

#### Security Recommendation
- Ensure one or three (or more) KDS root keys exist per forest. Exactly two keys can cause gMSA authentication failures in some sorting scenarios.
- If exactly two keys exist, Microsoft's recommended workaround is to create a third key. Do not remove existing keys.
- Validate the expected number of keys for your environment and alert on deviations.
- Restrict administrative access to actions that can modify KDS root keys.

#### How the Test Works
The test enumerates KDS root keys present in Active Directory and evaluates the count:
- **0 keys**: gMSAs are not in use; the test is skipped.
- **1 key**: The recommended configuration; the test passes.
- **2 keys**: Can cause gMSA authentication failures in some scenarios; the test returns Investigate.
- **3+ keys**: Acceptable per Microsoft guidance (the workaround for the sorting issue is to add a third key); the test passes.

#### References

- [Microsoft: gMSA authentication failures with multiple KDS root keys](https://learn.microsoft.com/troubleshoot/windows-server/active-directory/gmsa-auth-failures-multiple-keys)

## Details

<details>
<summary>Every attribute of this check</summary>

| Field | Value |
| --- | --- |
| Test ID | AD-CFG-22 |
| Severity | Info |
| Suite | Active Directory |
| Product | Active Directory |
| Feature | Directory configuration |
| Area | Infrastructure hardening |
| Resource type | Tenant |
| MITRE ATT&CK | None |
| PowerShell test | [Test-MtAdKdsRootKeysCount](https://github.com/maester365/maester/blob/main/tests/ad/config/Test.AD-CFG-22.ps1) |
| Services | ActiveDirectory |
| Permissions | ActiveDirectory:Ldap:Configuration/*:ReadProperty |

</details>

## Source

- Test: [`tests/ad/config/Test.AD-CFG-22.ps1`](https://github.com/maester365/maester/blob/main/tests/ad/config/Test.AD-CFG-22.ps1)
- Documentation: [`tests/ad/config/Test.AD-CFG-22.md`](https://github.com/maester365/maester/blob/main/tests/ad/config/Test.AD-CFG-22.md)
