Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADManagedServiceAccount: add SamAccountName parameter #659

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)
- ADGroup
- Refactored Module.
- Refactored Unit and Integration Tests.
- ADManagedServiceAccount
- Added SamAccountName property.

### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ $script:errorCodeKdsRootKeyNotFound = -2146893811
Returns the current state of an Active Directory managed service account.

.PARAMETER ServiceAccountName
Specifies the Security Account Manager (SAM) account name of the managed service account (ldapDisplayName
'sAMAccountName'). To be compatible with older operating systems, create a SAM account name that is 20 characters
or less. Once created, the user's SamAccountName and CN cannot be changed.
Specifies the name of the object. This parameter sets the Name property of the Active Directory object. The LDAP Display Name (ldapDisplayName) of this property is 'name'. Once created, the account's Name cannot be changed. Once created, the user's SamAccountName and CN cannot be changed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add line breaks around 120 characters


.PARAMETER AccountType
The type of managed service account. Standalone will create a Standalone Managed Service Account (sMSA) and
Expand Down Expand Up @@ -92,6 +90,7 @@ function Get-TargetResource
'DistinguishedName'
'Description'
'DisplayName'
'SamAccountName'
'ObjectClass'
'Enabled'
'PrincipalsAllowedToRetrieveManagedPassword'
Expand Down Expand Up @@ -154,6 +153,7 @@ function Get-TargetResource
Path = Get-ADObjectParentDN -DN $adServiceAccount.DistinguishedName
Description = $adServiceAccount.Description
DisplayName = $adServiceAccount.DisplayName
SamAccountName = $adServiceAccount.SamAccountName
DistinguishedName = $adServiceAccount.DistinguishedName
Enabled = $adServiceAccount.Enabled
KerberosEncryptionType = $adServiceAccount.KerberosEncryptionType -split (', ')
Expand All @@ -171,6 +171,7 @@ function Get-TargetResource
Path = $null
Description = $null
DisplayName = $null
SamAccountName = $null
DistinguishedName = $null
Enabled = $false
KerberosEncryptionType = @()
Expand All @@ -188,9 +189,7 @@ function Get-TargetResource
Tests if an Active Directory managed service account is in the desired state.

.PARAMETER ServiceAccountName
Specifies the Security Account Manager (SAM) account name of the managed service account (ldapDisplayName
'sAMAccountName'). To be compatible with older operating systems, create a SAM account name that is 20
characters or less. Once created, the user's SamAccountName and CN cannot be changed.
Specifies the name of the object. This parameter sets the Name property of the Active Directory object. The LDAP Display Name (ldapDisplayName) of this property is 'name'. Once created, the account's Name cannot be changed. Once created, the user's SamAccountName and CN cannot be changed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add line breaks around 120 characters


.PARAMETER AccountType
The type of managed service account. Standalone will create a Standalone Managed Service Account (sMSA) and
Expand All @@ -206,6 +205,11 @@ function Get-TargetResource
.PARAMETER DisplayName
Specifies the display name of the account (ldapDisplayName 'displayName').

.PARAMETER SamAccountName
Specifies the Security Account Manager (SAM) account name of the managed service account (ldapDisplayName
'sAMAccountName'). To be compatible with older operating systems, create a SAM account name that is 20
characters or less.

.PARAMETER DomainController
Specifies the Active Directory Domain Controller instance to use to perform the task.
This is only required if not executing the task on a domain controller.
Expand Down Expand Up @@ -268,6 +272,11 @@ function Test-TargetResource
[System.String]
$DisplayName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SamAccountName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
Expand Down Expand Up @@ -375,9 +384,7 @@ function Test-TargetResource
Sets the state of an Active Directory managed service account.

.PARAMETER ServiceAccountName
Specifies the Security Account Manager (SAM) account name of the managed service account (ldapDisplayName
'sAMAccountName'). To be compatible with older operating systems, create a SAM account name that is 20
characters or less. Once created, the user's SamAccountName and CN cannot be changed.
Specifies the name of the object. This parameter sets the Name property of the Active Directory object. The LDAP Display Name (ldapDisplayName) of this property is 'name'. Once created, the account's Name cannot be changed. Once created, the user's SamAccountName and CN cannot be changed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add line breaks around 120 characters


.PARAMETER AccountType
The type of managed service account. Standalone will create a Standalone Managed Service Account (sMSA) and
Expand All @@ -393,6 +400,11 @@ function Test-TargetResource
.PARAMETER DisplayName
Specifies the display name of the account (ldapDisplayName 'displayName').

.PARAMETER SamAccountName
Specifies the Security Account Manager (SAM) account name of the managed service account (ldapDisplayName
'sAMAccountName'). To be compatible with older operating systems, create a SAM account name that is 20
characters or less.

.PARAMETER DomainController
Specifies the Active Directory Domain Controller instance to use to perform the task.
This is only required if not executing the task on a domain controller.
Expand Down Expand Up @@ -463,6 +475,11 @@ function Set-TargetResource
[System.String]
$DisplayName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SamAccountName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[ClassVersion("1.0.1.0"), FriendlyName("ADManagedServiceAccount")]
class MSFT_ADManagedServiceAccount : OMI_BaseResource
{
[Key, Description("Specifies the Security Account Manager (SAM) account name of the managed service account (ldapDisplayName 'sAMAccountName'). To be compatible with older operating systems, create a SAM account name that is 20 characters or less. Once created, the user's SamAccountName and CN cannot be changed.")] String ServiceAccountName;
[Key, Description("Specifies the name of the object. This parameter sets the Name property of the Active Directory object. The LDAP Display Name (ldapDisplayName) of this property is 'name'. Once created, the account's Name cannot be changed.")] String ServiceAccountName;
[Required, Description("The type of managed service account. Standalone will create a Standalone Managed Service Account (sMSA) and Group will create a Group Managed Service Account (gMSA)."), ValueMap{"Group","Standalone"}, Values{"Group","Standalone"}] String AccountType;
[Write, Description("Specifies the user account credentials to use to perform this task. This is only required if not executing the task on a domain controller or using the parameter DomainController."), EmbeddedInstance("MSFT_Credential")] String Credential;
[Write, Description("Specifies the description of the account (ldapDisplayName 'description').")] String Description;
[Write, Description("Specifies the display name of the account (ldapDisplayName 'displayName').")] String DisplayName;
[Write, Description("Specifies the Security Account Manager (SAM) account name of the service account. To be compatible with older operating systems, create a SAM account name that is 20 characters or less. If the string value provided is not terminated with a '$' character, the system adds one if needed. The LDAP display name (ldapDisplayName) for this property is 'sAMAccountName'.")] String SamAccountName;
[Write, Description("Specifies the Active Directory Domain Controller instance to use to perform the task. This is only required if not executing the task on a domain controller.")] String DomainController;
[Write, Description("Specifies whether the user account is created or deleted. If not specified, this value defaults to Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Write, Description("Specifies which Kerberos encryption types the account supports when creating service tickets. This value sets the encryption types supported flags of the Active Directory msDS-SupportedEncryptionTypes attribute."),ValueMap{"None","RC4","AES128","AES256"}, Values{"None","RC4","AES128","AES256"}] String KerberosEncryptionType[];
Expand Down
12 changes: 10 additions & 2 deletions tests/Unit/MSFT_ADManagedServiceAccount.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ try
DistinguishedName = "CN=TestSMSA,$mockDefaultMsaPath"
Description = 'Dummy StandAlone service account for unit testing'
DisplayName = 'TestSMSA'
SamAccountName = 'TestSMSA'
Enabled = $true
KerberosEncryptionType = 'RC4', 'AES128', 'AES256'
ManagedPasswordPrincipals = @()
Expand All @@ -87,6 +88,7 @@ try
DistinguishedName = $null
Description = $null
DisplayName = $null
SamAccountName = $null
Enabled = $false
ManagedPasswordPrincipals = @()
MembershipAttribute = $mockAdServiceAccountStandalone.MembershipAttribute
Expand All @@ -97,6 +99,7 @@ try
$mockAdServiceAccountChanged = @{
Description = 'Changed description'
DisplayName = 'Changed displayname'
SamAccountName = 'ChangedSMSA'
KerberosEncryptionType = 'AES128', 'AES256'
ManagedPasswordPrincipals = $mockADUSer.SamAccountName
}
Expand All @@ -107,6 +110,7 @@ try
DistinguishedName = "CN=TestGMSA,$mockDefaultMsaPath"
Description = 'Dummy group service account for unit testing'
DisplayName = 'TestGMSA'
SamAccountName = 'TestGMSA'
Enabled = $true
KerberosEncryptionType = 'RC4', 'AES128', 'AES256'
ManagedPasswordPrincipals = $mockADUSer.SamAccountName, $mockADComputer.SamAccountName
Expand All @@ -120,6 +124,7 @@ try
DistinguishedName = $null
Description = $null
DisplayName = $null
SamAccountName = $null
Enabled = $false
ManagedPasswordPrincipals = @()
MembershipAttribute = $mockAdServiceAccountGroup.MembershipAttribute
Expand All @@ -136,7 +141,7 @@ try
Name = $mockAdServiceAccountStandalone.ServiceAccountName
ObjectClass = 'msDS-ManagedServiceAccount'
ObjectGUID = '91bffe90-4c84-4026-b1fc-d03671ff56ad'
SamAccountName = $mockAdServiceAccountStandalone.ServiceAccountName
SamAccountName = $mockAdServiceAccountStandalone.SamAccountName
SID = 'S-1-5-21-1409167834-891301383-2860967316-1144'
UserPrincipalName = ''
}
Expand All @@ -151,7 +156,7 @@ try
ObjectClass = 'msDS-GroupManagedServiceAccount'
ObjectGUID = '91bffe90-4c84-4026-b1fc-d03671ff56ae'
PrincipalsAllowedToRetrieveManagedPassword = $mockAdServiceAccountGroup.ManagedPasswordPrincipals
SamAccountName = $mockAdServiceAccountGroup.ServiceAccountName
SamAccountName = $mockAdServiceAccountGroup.SamAccountName
SID = 'S-1-5-21-1409167834-891301383-2860967316-1145'
UserPrincipalName = ''
}
Expand All @@ -162,6 +167,7 @@ try
Path = $mockDefaultMsaPath
Description = $mockGetAdServiceAccountResultsStandAlone.Description
DisplayName = $mockGetAdServiceAccountResultsStandAlone.DisplayName
SamAccountName = $mockGetAdServiceAccountResultsStandAlone.SamAccountName
AccountType = 'Standalone'
Ensure = 'Present'
Enabled = $true
Expand All @@ -177,6 +183,7 @@ try
DistinguishedName = $mockGetAdServiceAccountResultsGroup.DistinguishedName
Path = $mockDefaultMsaPath
Description = $mockGetAdServiceAccountResultsGroup.Description
SamAccountName = $mockGetAdServiceAccountResultsStandAlone.SamAccountName
DisplayName = $mockGetAdServiceAccountResultsGroup.DisplayName
AccountType = 'Group'
Ensure = 'Present'
Expand All @@ -194,6 +201,7 @@ try
Path = $null
Description = $null
DisplayName = $null
SamAccountName = $null
AccountType = $null
Ensure = 'Absent'
Enabled = $false
Expand Down