> For the complete documentation index, see [llms.txt](https://docs.lithnet.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lithnet.io/ams/help-and-support/support-articles/kb000008.md).

# KB000008: AMS is unable to JIT into privileged groups such as Domain Admins

## Summary

When attempting to JIT into a privileged group such as Domain Admins, the request may fail and show the user the following error message.

`An unexpected error occurred while trying to complete your request`

The `access-manager-webapp.log` file will show a message similar to the following

```
System.UnauthorizedAccessException: Access is denied.
at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.SetInfo()
at System.DirectoryServices.DirectoryEntry.CommitChanges()
at Lithnet.AccessManager.ActiveDirectory.ActiveDirectoryGroup.AddMember(IActiveDirectorySecurityPrincipal principal, TimeSpan ttl)
```

There may be one or more successful attempts before these errors occur.

## Cause

Certain groups in Active Directory are considered ['protected' groups](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/plan/security-best-practices/appendix-c--protected-accounts-and-groups-in-active-directory) by Active Directory.

Protected groups have a special permission set on them enforced by AD itself. Every 60 minutes AD will turn off inheritance and reset the ACL of these protected users and groups, if they have been modified.

The process that does this also follows nested membership. So if you add a group to domain admins, that group also becomes protected, and has its ACL overwritten to the AdminSDHolder template.

The ACL template that is applied comes from the AdminSDHolder template in AD.

## Resolution

In order to allow Access Manager to modify the member of protected groups, you must modify the ACL of the AdminSDHolder object, to include the AMS service account. This does have the side effect that the AMS service account will have the access you provided, to *all* protected accounts and groups.

If you grant `write member` permissions to the AMS service account on the AdminSDHolder template, then AMS will have modify member rights on [all groups that are protected](https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/plan/security-best-practices/appendix-c--protected-accounts-and-groups-in-active-directory#protected-groups).

There is no way to limit the permission to a specific group.

To do this safely, we recommend having a dedicated AMS instance for 'tier zero', where the underlying server, and the AMS instance is only accessible by Domain admins. This instance is then used for JITting into roles like schema admins, enterprise admins, etc.

## Deployment script

The following script can be used to grant 'write member' permissions to all protected groups in a domain, by modifying the AdminSDHolder template permissions in the directory.

```powershell
# Grant-ModifyProtectedGroupMembershipPermissions
# 
# This script grants permissions for the AMS service account to update protected groups
# Running this script requires membership in the Domain Admins group for the target domain
#
# Version 1.0

#-------------------------------------------------------------------------
# Set the following values as appropriate for your environment. If the service account is in another forest and cannot be resolved, provide its SID, by looking it up first in the source domain using Get-ADUser or Get-ADServiceAccount
#-------------------------------------------------------------------------

$amsServiceAccount = "dev\svc-lithnetams$"

#-------------------------------------------------------------------------
# Do not modify below here
#-------------------------------------------------------------------------

if (-not $amsServiceAccount.StartsWith("S-1-5"))
{
    $ntaccount = new-object System.Security.Principal.NTAccount $amsServiceAccount
    $sid = $ntAccount.Translate([System.Security.Principal.SecurityIdentifier]);
}
else
{
    $sid = $amsServiceAccount
}

Import-Module ActiveDirectory

$ErrorActionPreference = "Stop"
$InformationPreference = "Continue"

if ([string]::IsNullOrEmpty($domain))
{
	$server = (Get-ADRootDSE).dnsHostName
}
else
{
	$server = (Get-ADDomainController -DomainName $domain -Discover -ForceDiscover -Writable).HostName[0]
}

$rootDSE = Get-ADRootDSE -Server $server

if ([string]::IsNullOrEmpty($DN))
{
	$DN = $rootDSE.defaultNamingContext
}

$DN = "CN=AdminSDHolder,CN=System," + $DN 

$schemaNC = $rootDSE.schemaNamingContext
$groupObjectGuid = New-Object Guid @(,(Get-ADObject -Server $server -SearchBase $schemaNC -LdapFilter "(&(ldapDisplayName=group)(objectclass=classSchema))" -Properties "SchemaIDGuid").SchemaIDGuid)
$memberAttributeGuid = New-Object Guid @(,(Get-ADObject -Server $server -SearchBase $schemaNC -LdapFilter "(&(ldapDisplayName=member)(objectclass=attributeSchema))" -Properties "SchemaIDGuid").SchemaIDGuid)

$ntaccount = new-object System.Security.Principal.NTAccount $amsServiceAccount
$sid = $ntAccount.Translate([System.Security.Principal.SecurityIdentifier]);

$ace1user = new-object System.DirectoryServices.ActiveDirectoryAccessRule $sid, "WriteProperty", "Allow", $memberAttributeGuid, "None", $groupObjectGuid
 
$path = "AD:\$DN"

$acl = get-acl -Path $path
$acl.AddAccessRule($ace1user)

set-acl -AclObject $acl -Path $path
```

### Further reading

* <https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/plan/security-best-practices/appendix-c--protected-accounts-and-groups-in-active-directory>
* <https://specopssoft.com/support/en/password-reset/understanding-privileged-accounts-and-adminsdholder.htm>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lithnet.io/ams/help-and-support/support-articles/kb000008.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
