Skip to content

Commit b618e7c

Browse files
authored
Merge branch 'master' into fix-missing-authentication-realm
2 parents 38380e4 + 5cca8dd commit b618e7c

File tree

6 files changed

+231
-0
lines changed

6 files changed

+231
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- SharePointDsc
1111
- Added automatic release with a new CI pipeline
1212
- Updated PULL_REQUEST_TEMPLATE.md to match DSC standard
13+
- SPFarm
14+
- Added possibility to set application credential key.
1315
- SPTrustedSecurityTokenIssuer
1416
- Fixed RegisteredIssuerNameRealm not applied if specified.
1517

SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function Get-TargetResource
7878
[System.String]
7979
$DeveloperDashboard,
8080

81+
[Parameter()]
82+
[System.Management.Automation.PSCredential]
83+
$ApplicationCredentialKey,
84+
8185
[Parameter()]
8286
[System.Management.Automation.PSCredential]
8387
$InstallAccount
@@ -90,6 +94,7 @@ function Get-TargetResource
9094
throw "SharePointDsc does not support removing a server from a farm, please set the ensure property to 'present'"
9195
}
9296

97+
$supportsSettingApplicationCredentialKey = $false
9398
$installedVersion = Get-SPDscInstalledProductVersion
9499
switch ($installedVersion.FileMajorPart)
95100
{
@@ -119,6 +124,7 @@ function Get-TargetResource
119124
else
120125
{
121126
Write-Verbose -Message "Detected installation of SharePoint 2019"
127+
$supportsSettingApplicationCredentialKey = $true
122128
}
123129
}
124130
default
@@ -128,6 +134,13 @@ function Get-TargetResource
128134
}
129135
}
130136

137+
if ($PSBoundParameters.ContainsKey("ApplicationCredentialKey") -and
138+
-not $supportsSettingApplicationCredentialKey)
139+
{
140+
throw [Exception] ("Specifying ApplicationCredentialKey is only supported " +
141+
"on SharePoint 2019")
142+
}
143+
131144
if (($PSBoundParameters.ContainsKey("ServerRole") -eq $true) -and
132145
$installedVersion.FileMajorPart -ne 16)
133146
{
@@ -236,6 +249,7 @@ function Get-TargetResource
236249
CentralAdministrationPort = (New-Object -TypeName System.Uri $centralAdminSite.Url).Port
237250
CentralAdministrationAuth = $centralAdminAuth
238251
DeveloperDashboard = $developerDashboardStatus
252+
ApplicationCredentialKey = $null
239253
}
240254
$installedVersion = Get-SPDscInstalledProductVersion
241255
if ($installedVersion.FileMajorPart -eq 16)
@@ -280,6 +294,7 @@ function Get-TargetResource
280294
CentralAdministrationUrl = $null
281295
CentralAdministrationPort = $null
282296
CentralAdministrationAuth = $null
297+
ApplicationCredentialKey = $null
283298
Ensure = "Present"
284299
}
285300
}
@@ -304,6 +319,7 @@ function Get-TargetResource
304319
CentralAdministrationUrl = $null
305320
CentralAdministrationPort = $null
306321
CentralAdministrationAuth = $null
322+
ApplicationCredentialKey = $null
307323
Ensure = "Absent"
308324
}
309325
}
@@ -381,6 +397,9 @@ function Set-TargetResource
381397
[System.String]
382398
$DeveloperDashboard,
383399

400+
[Parameter()]
401+
[System.Management.Automation.PSCredential]
402+
$ApplicationCredentialKey,
384403

385404
[Parameter()]
386405
[System.Management.Automation.PSCredential]
@@ -688,6 +707,7 @@ function Set-TargetResource
688707
SkipRegisterAsDistributedCacheHost = $true
689708
}
690709

710+
$supportsSettingApplicationCredentialKey = $false
691711
$installedVersion = Get-SPDscInstalledProductVersion
692712
switch ($installedVersion.FileMajorPart)
693713
{
@@ -708,6 +728,7 @@ function Set-TargetResource
708728
{
709729
Write-Verbose -Message ("Detected Version: SharePoint 2019 - " +
710730
"configuring server as $($params.ServerRole)")
731+
$supportsSettingApplicationCredentialKey = $true
711732
}
712733
$executeArgs.Add("LocalServerRole", $params.ServerRole)
713734
}
@@ -724,6 +745,7 @@ function Set-TargetResource
724745
Write-Verbose -Message ("Detected Version: SharePoint 2019 - no server " +
725746
"role provided, configuring server without a " +
726747
"specific role")
748+
$supportsSettingApplicationCredentialKey = $true
727749
}
728750
$executeArgs.Add("ServerRoleOptional", $true)
729751
}
@@ -736,6 +758,13 @@ function Set-TargetResource
736758
}
737759
}
738760

761+
if ($params.ContainsKey("ApplicationCredentialKey") -and
762+
-not $supportsSettingApplicationCredentialKey)
763+
{
764+
throw [Exception] ("Specifying ApplicationCredentialKey is only supported " +
765+
"on SharePoint 2019")
766+
}
767+
739768
if ($dbStatus.DatabaseExists -eq $true)
740769
{
741770
Write-Verbose -Message ("The SharePoint config database " +
@@ -862,6 +891,12 @@ function Set-TargetResource
862891
Write-Verbose -Message "Starting Install-SPFeature"
863892
Install-SPFeature -AllExistingFeatures -Force | Out-Null
864893

894+
if ($params.ContainsKey("ApplicationCredentialKey"))
895+
{
896+
Write-Verbose -Message "Setting application credential key"
897+
Set-SPApplicationCredentialKey -Password $params.ApplicationCredentialKey.Password
898+
}
899+
865900
# Provision central administration
866901
if ($params.RunCentralAdmin -eq $true)
867902
{
@@ -1060,6 +1095,10 @@ function Test-TargetResource
10601095
[System.String]
10611096
$DeveloperDashboard,
10621097

1098+
[Parameter()]
1099+
[System.Management.Automation.PSCredential]
1100+
$ApplicationCredentialKey,
1101+
10631102
[Parameter()]
10641103
[System.Management.Automation.PSCredential]
10651104
$InstallAccount

SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.schema.mof

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ class MSFT_SPFarm : OMI_BaseResource
1414
[Write, Description("The authentication provider of the CentralAdministration web application"), ValueMap{"NTLM","Kerberos"}, Values{"NTLM","Kerberos"}] String CentralAdministrationAuth;
1515
[Write, Description("SharePoint 2016 & 2019 only - the MinRole role to enroll this server as"), ValueMap{"Application","ApplicationWithSearch","Custom","DistributedCache","Search","SingleServerFarm","WebFrontEnd","WebFrontEndWithDistributedCache"}, Values{"Application","ApplicationWithSearch","Custom","DistributedCache","Search","SingleServerFarm","WebFrontEnd","WebFrontEndWithDistributedCache"}] String ServerRole;
1616
[Write, Description("Specifies the state of the Developer Dashboard ('OnDemand' is SP2013 only)"), ValueMap{"Off","On","OnDemand"}, Values{"Off","On","OnDemand"}] String DeveloperDashboard;
17+
[Write, Description("Specifies the application credential key on the local server. Only supported for SP2019."), EmbeddedInstance("MSFT_Credential")] String ApplicationCredentialKey;
1718
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount;
1819
};

SharePointDsc/DSCResources/MSFT_SPFarm/Readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ begins with HTTPS, and will default to port 443.
4444
DeveloperDashboard can be specified as "On", "Off" and (only when using
4545
SharePoint 2013) to "OnDemand".
4646

47+
ApplicationCredentialKey is used to set the application credential key on the
48+
local server, which is used by certain features to encrypt and decrypt passwords.
49+
The application credential key will only be set during initial farm creation and
50+
when joining the farm. The ApplicationCredentialKey needs to be the same on each
51+
server in the farm. ApplicationCredentialKey is only supported for SharePoint 2019.
52+
4753
NOTE:
4854
When using SharePoint 2016 and later and enabling the Developer Dashboard,
4955
please make sure you also provision the Usage and Health service application
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
<#PSScriptInfo
3+
4+
.VERSION 1.0.0
5+
6+
.GUID 80d306fa-8bd4-4a8d-9f7a-bf40df95e661
7+
8+
.AUTHOR DSC Community
9+
10+
.COMPANYNAME DSC Community
11+
12+
.COPYRIGHT DSC Community contributors. All rights reserved.
13+
14+
.TAGS
15+
16+
.LICENSEURI https://github.com/dsccommunity/SharePointDsc/blob/master/LICENSE
17+
18+
.PROJECTURI https://github.com/dsccommunity/SharePointDsc
19+
20+
.ICONURI https://dsccommunity.org/images/DSC_Logo_300p.png
21+
22+
.EXTERNALMODULEDEPENDENCIES
23+
24+
.REQUIREDSCRIPTS
25+
26+
.EXTERNALSCRIPTDEPENDENCIES
27+
28+
.RELEASENOTES
29+
Updated author, copyright notice, and URLs.
30+
31+
.PRIVATEDATA
32+
33+
#>
34+
35+
<#
36+
37+
.DESCRIPTION
38+
This example shows how a basic SharePoint farm can be created. The database server and names
39+
are specified, and the accounts to run the setup as, the farm account and the passphrase are
40+
all passed in to the configuration to be applied. The application credential key is also
41+
specified. This configuration is only supported with SharePoint 2019. By default the central
42+
admin site in this example is provisioned to port 9999 using NTLM authentication.
43+
44+
#>
45+
46+
Configuration Example
47+
{
48+
param(
49+
[Parameter(Mandatory = $true)]
50+
[PSCredential]
51+
$FarmAccount,
52+
53+
[Parameter(Mandatory = $true)]
54+
[PSCredential]
55+
$SetupAccount,
56+
57+
[Parameter(Mandatory = $true)]
58+
[PSCredential]
59+
$Passphrase,
60+
61+
[Parameter(Mandatory = $true)]
62+
[PSCredential]
63+
$ApplicationCredentialKey
64+
)
65+
Import-DscResource -ModuleName SharePointDsc
66+
67+
node localhost {
68+
SPFarm SharePointFarm
69+
{
70+
IsSingleInstance = "Yes"
71+
DatabaseServer = "SQL.contoso.local\SQLINSTANCE"
72+
FarmConfigDatabaseName = "SP_Config"
73+
AdminContentDatabaseName = "SP_AdminContent"
74+
Passphrase = $Passphrase
75+
FarmAccount = $FarmAccount
76+
ApplicationCredentialKey = $ApplicationCredentialKey
77+
RunCentralAdmin = $true
78+
PsDscRunAsCredential = $SetupAccount
79+
}
80+
}
81+
}
82+
83+
<#
84+
.EXAMPLE
85+
#>
86+

tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,103 @@ namespace Microsoft.SharePoint.Administration {
21662166
}
21672167
}
21682168

2169+
if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16 -and
2170+
$Global:SPDscHelper.CurrentStubBuildNumber.Build.ToString().Length -ne 4)
2171+
{
2172+
Context -Name "ApplicationCredentialKey is specified on SP2019 installation" -Fixture {
2173+
$testParams = @{
2174+
IsSingleInstance = "Yes"
2175+
Ensure = "Present"
2176+
FarmConfigDatabaseName = "SP_Config"
2177+
DatabaseServer = "sql.contoso.com"
2178+
FarmAccount = $mockFarmAccount
2179+
Passphrase = $mockPassphrase
2180+
AdminContentDatabaseName = "SP_AdminContent"
2181+
RunCentralAdmin = $false
2182+
}
2183+
2184+
Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
2185+
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
2186+
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
2187+
return @{
2188+
Locked = $false
2189+
ValidPermissions = $true
2190+
DatabaseExists = $true
2191+
}
2192+
}
2193+
Mock -CommandName "Get-SPDscSQLInstanceStatus" -MockWith {
2194+
return @{
2195+
MaxDOPCorrect = $true
2196+
}
2197+
}
2198+
Mock -CommandName "Get-SPWebApplication" -MockWith {
2199+
return @{
2200+
IsAdministrationWebApplication = $true
2201+
Url = "http://localhost:9999"
2202+
}
2203+
}
2204+
Mock -CommandName "Get-CimInstance" -MockWith {
2205+
return @{
2206+
Domain = "test.lab"
2207+
}
2208+
}
2209+
Mock -CommandName "Get-SPServiceInstance" -MockWith {
2210+
if ($global:SPDscCentralAdminCheckDone -eq $true)
2211+
{
2212+
return @(
2213+
$null | Add-Member -MemberType ScriptMethod `
2214+
-Name GetType `
2215+
-Value {
2216+
return @{
2217+
Name = "SPWebServiceInstance"
2218+
}
2219+
} -PassThru -Force | Add-Member -Name Name `
2220+
-MemberType ScriptProperty `
2221+
-PassThru `
2222+
{
2223+
# get
2224+
""
2225+
}`
2226+
{
2227+
# set
2228+
param ( $arg )
2229+
}
2230+
)
2231+
}
2232+
else
2233+
{
2234+
$global:SPDscCentralAdminCheckDone = $true
2235+
return $null
2236+
}
2237+
}
2238+
2239+
Mock -CommandName "Get-SPWebApplication" -MockWith {
2240+
return @{
2241+
IsAdministrationWebApplication = $true
2242+
ContentDatabases = @(@{
2243+
Name = $testParams.AdminContentDatabaseName
2244+
})
2245+
Url = "http://localhost:9999"
2246+
}
2247+
}
2248+
2249+
Mock -CommandName Set-SPApplicationCredentialKey -MockWith { return $null }
2250+
2251+
It "Should not throw an exception in the get method" {
2252+
{ Get-TargetResource @testParams } | Should Not Throw "Specifying ApplicationCredentialKey is only supported on SharePoint 2019"
2253+
}
2254+
2255+
It "Should set application credential key" {
2256+
Set-TargetResource @testParams
2257+
Assert-MockCalled -CommandName "Set-SPApplicationCredentialKey"
2258+
}
2259+
2260+
It "Should not throw an exception in the test method" {
2261+
{ Test-TargetResource @testParams } | Should not Throw "Specifying ApplicationCredentialKey is only supported on SharePoint 2019"
2262+
}
2263+
}
2264+
}
2265+
21692266
Context -Name "no serverrole is specified but get-targetresource needs to identify and return it" -Fixture {
21702267
$testParams = @{
21712268
IsSingleInstance = "Yes"

0 commit comments

Comments
 (0)