forked from dsccommunity/xPSDesiredStateConfiguration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample_xDscWebService_Preferred.ps1
153 lines (134 loc) · 5.91 KB
/
Sample_xDscWebService_Preferred.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<#PSScriptInfo
.VERSION 1.0.0
.GUID 4321b681-da05-4486-a7db-1ce4842d40c5
.AUTHOR Microsoft Corporation
.COMPANYNAME Microsoft Corporation
.COPYRIGHT
.TAGS DSCConfiguration
.LICENSEURI https://github.com/dsccommunity/xPSDesiredStateConfiguration/blob/main/LICENSE
.PROJECTURI https://github.com/dsccommunity/xPSDesiredStateConfiguration
.ICONURI
.EXTERNALMODULEDEPENDENCIES NetworkingDsc, xPSDesiredStateConfiguration, xWebAdministration
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
#>
<#
.SYNOPSIS
Configures a DSC Pull Server with an separately configured IIS Application Pool
.DESCRIPTION
The Sample_xDscWebServiceRegistration configuration sets up a DSC pull
server that is capable for client nodes to register with it and
retrieve configuration documents with configuration names instead of
configuration id.
Prerequisite: 1 - Install a certificate in 'CERT:\LocalMachine\MY\' store
For testing environments, you could use a self-signed
certificate. (New-SelfSignedCertificate cmdlet could
generate one for you). For production environments, you
will need a certificate signed by valid CA. Registration
only works over https protocols. So to use registration
feature, a secure pull server setup with certificate is
necessary.
2 - To configure a Firewall Rule (Exception) to allow external
connections the [NetworkingDsc](https://github.com/PowerShell/NetworkingDsc)
DSC module is required.
3 - The [xWebAdministration](https://github.com/PowerShell/xWebAdministration)
DSC module is required to configure the IIS Application Pool
.PARAMETER NodeName
The name of the node being configured as a DSC Pull Server.
.PARAMETER CertificateThumbPrint
Certificate thumbprint for creating an HTTPS endpoint. Use
"AllowUnencryptedTraffic" for setting up a non SSL based endpoint.
.PARAMETER RegistrationKey
This key will be used by client nodes as a shared key to authenticate
during registration. This should be a string with enough entropy
(randomness) to protect the registration of clients to the pull server.
The example creates a new GUID for the registration key.
.PARAMETER Port
The TCP port on which the Pull Server will listen for connections
.PARAMETER ApplicationPoolName
The IIS Application Pool to use with the new Pull Server
.EXAMPLE
$thumbprint = (New-SelfSignedCertificate -DnsName $env:COMPUTERNAME -CertStoreLocation Cert:\LocalMachine\My).Thumbprint
$registrationKey = [System.Guid]::NewGuid()
Sample_xDscWebService_Preferred -RegistrationKey $registrationkey -CertificateThumbPrint $thumbprint
#>
Configuration Sample_xDscWebService_Preferred
{
param
(
[Parameter()]
[System.String[]]
$NodeName = 'localhost',
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$CertificateThumbPrint,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$RegistrationKey,
[Parameter()]
[ValidateRange(1, 65535)]
[System.UInt16]
$Port = 8080,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$ApplicationPoolName
)
Import-DscResource -ModuleName 'NetworkingDsc' -ModuleVersion 7.4.0.0
Import-DSCResource -ModuleName 'xPSDesiredStateConfiguration'
Import-DscResource -ModuleName 'xWebAdministration' -ModuleVersion 3.0.0.0
Node $NodeName
{
WindowsFeature DSCServiceFeature
{
Ensure = 'Present'
Name = 'DSC-Service'
}
xWebAppPool PSDSCPullServerPool
{
Ensure = 'Present'
Name = $ApplicationPoolName
IdentityType = 'NetworkService'
}
xDscWebService PSDSCPullServer
{
Ensure = 'Present'
EndpointName = 'PSDSCPullServer'
ApplicationPoolName = $ApplicationPoolName
Port = $Port
PhysicalPath = "$env:SystemDrive\inetpub\PSDSCPullServer"
CertificateThumbPrint = $CertificateThumbPrint
ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
State = 'Started'
RegistrationKeyPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService"
AcceptSelfSignedCertificates = $true
Enable32BitAppOnWin64 = $false
UseSecurityBestPractices = $true
ConfigureFirewall = $false
DependsOn = '[WindowsFeature]DSCServiceFeature', '[xWebAppPool]PSDSCPullServerPool'
}
File RegistrationKeyFile
{
Ensure = 'Present'
Type = 'File'
DestinationPath = "$env:ProgramFiles\WindowsPowerShell\DscService\RegistrationKeys.txt"
Contents = $RegistrationKey
}
Firewall PSDSCPullServerRule
{
Ensure = 'Present'
Name = "DSC_PullServer_$Port"
DisplayName = "DSC PullServer $Port"
Group = 'DSC PullServer'
Enabled = $true
Action = 'Allow'
Direction = 'InBound'
LocalPort = $Port
Protocol = 'TCP'
DependsOn = '[xDscWebService]PSDSCPullServer'
}
}
}