Skip to content
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
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"[powershell]": {
"debug.saveBeforeStart": "nonUntitledEditorsInActiveGroup",
"editor.semanticHighlighting.enabled": false,
"editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?",
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modificationsIfAvailable",
},
"diffEditor.experimental.showMoves": true,
"diffEditor.experimental.useTrueInlineView": true,
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.avoidSemicolonsAsLineTerminators": true,
"powershell.codeFormatting.newLineAfterCloseBrace": false,
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
"powershell.codeFormatting.preset": "OTBS",
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceAfterSeparator": true,
"powershell.codeFormatting.whitespaceBetweenParameters": false,
"powershell.debugging.executeMode": "DotSource",
"powershell.pester.useLegacyCodeLens": false
}
4 changes: 2 additions & 2 deletions Initialize-C4bSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ try {
# Collect current certificate configuration
$Certificate = Get-Certificate -Thumbprint $Thumbprint
Copy-CertToStore -Certificate $Certificate

$null = Test-CertificateDomain -Thumbprint $Thumbprint
} elseif ($PSScriptRoot) {
# We're going to be using a self-signed certificate
Expand Down Expand Up @@ -215,7 +215,7 @@ try {
# Set Choco Server Chocolatey Configuration
Invoke-Choco feature enable --name="'excludeChocolateyPackagesDuringUpgradeAll'"
Invoke-Choco feature enable --name="'usePackageHashValidation'"

# Convert license to a "choco-license" package, and install it locally to test
Write-Host "Creating a 'chocolatey-license' package, and testing install." -ForegroundColor Green
Set-Location $FilesDir
Expand Down
12 changes: 9 additions & 3 deletions Start-C4bCcmSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ process {
$chocoArgs += @("--package-parameters='/CertificateThumbprint=$Thumbprint'")
}
& Invoke-Choco @chocoArgs

if (-not $MyCertificate) { $MyCertificate = Get-Item Cert:\LocalMachine\My\* }

Write-Host "Installing Chocolatey Central Management Website"
Expand All @@ -191,17 +191,23 @@ process {
New-CcmBinding -Thumbprint $Thumbprint
Start-CcmService

# If the user provided certificate has multiple SANs, they may need to select one with params
if (-not (Get-ChocoEnvironmentProperty CertSubject)) {
$CertSubject = (Get-Item Cert:\LocalMachine\TrustedPeople\$Thumbprint).Subject -replace '^CN='
Set-ChocoEnvironmentProperty CertSubject $CertSubject
}

$CcmEndpoint = "https://$(Get-ChocoEnvironmentProperty CertSubject)"
}
choco config set centralManagementServiceUrl "$($CcmEndpoint):24020/ChocolateyManagementService"

#Generate CCM Salt Values
if (-not (Get-ChocoEnvironmentProperty ClientSalt)) {
if (-not ($ClientSaltValue = Get-ChocoEnvironmentProperty ClientSalt)) {
$ClientSaltValue = New-ServicePassword
Set-ChocoEnvironmentProperty ClientSalt $ClientSaltValue
}

if (-not (Get-ChocoEnvironmentProperty ServiceSalt)) {
if (-not ($ServiceSaltValue = Get-ChocoEnvironmentProperty ServiceSalt)) {
$ServiceSaltValue = New-ServicePassword
Set-ChocoEnvironmentProperty ServiceSalt $ServiceSaltValue
}
Expand Down
38 changes: 19 additions & 19 deletions Start-C4bNexusSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ C4B Quick-Start Guide Nexus setup script
- Setup of firewall rule for repository access
#>
[CmdletBinding()]
param(
param(
# The certificate thumbprint that identifies the target SSL certificate in
# the local machine certificate stores.
[Parameter()]
[ArgumentCompleter({
Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
[System.Management.Automation.CompletionResult]::new(
$_.Thumbprint,
$_.Thumbprint,
"ParameterValue",
($_.Subject -replace "^CN=(?<FQDN>.+),?.*$",'${FQDN}')
)
}
})]
[ValidateScript({Test-CertificateDomain -Thumbprint $_})]
Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
[System.Management.Automation.CompletionResult]::new(
$_.Thumbprint,
$_.Thumbprint,
"ParameterValue",
($_.Subject -replace "^CN=(?<FQDN>.+),?.*$", '${FQDN}')
)
}
})]
[ValidateScript({ Test-CertificateDomain -Thumbprint $_ })]
[string]
$Thumbprint = $(
if ((Test-Path C:\choco-setup\clixml\chocolatey-for-business.xml) -and (Import-Clixml C:\choco-setup\clixml\chocolatey-for-business.xml).CertThumbprint) {
Expand All @@ -51,17 +51,17 @@ process {

# Install base nexus-repository package
Write-Host "Installing Sonatype Nexus Repository"
$chocoArgs = @('install', 'nexus-repository', '-y' ,'--no-progress', "--package-parameters='/Fqdn:localhost'")
$chocoArgs = @('install', 'nexus-repository', '-y' , '--no-progress', "--package-parameters='/Fqdn:localhost'")
& Invoke-Choco @chocoArgs

$chocoArgs = @('install', 'nexushell', '-y' ,'--no-progress')
$chocoArgs = @('install', 'nexushell', '-y' , '--no-progress')
& Invoke-Choco @chocoArgs

if ($Thumbprint) {
$NexusPort = 8443

$null = Set-NexusCert -Thumbprint $Thumbprint -Port $NexusPort

if ($CertificateDnsName = Get-ChocoEnvironmentProperty CertSubject) {
# Override the domain, so we don't get prompted for wildcard certificates
Get-NexusLocalServiceUri -HostnameOverride $CertificateDnsName | Write-Verbose
Expand All @@ -71,10 +71,10 @@ process {
# Add Nexus port access via firewall
$FwRuleParams = @{
DisplayName = "Nexus Repository access on TCP $NexusPort"
Direction = 'Inbound'
LocalPort = $NexusPort
Protocol = 'TCP'
Action = 'Allow'
Direction = 'Inbound'
LocalPort = $NexusPort
Protocol = 'TCP'
Action = 'Allow'
}
$null = New-NetFirewallRule @FwRuleParams

Expand Down Expand Up @@ -262,7 +262,7 @@ process {
# Remove Local Chocolatey Setup Source
$chocoArgs = @('source', 'remove', '--name="LocalChocolateySetup"')
& Invoke-Choco @chocoArgs

# Install a non-IE browser for browsing the Nexus web portal.
if (-not (Test-Path 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')) {
Write-Host "Installing Microsoft Edge, to allow viewing the Nexus site"
Expand Down
142 changes: 142 additions & 0 deletions Start-C4bPsuSetup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#requires -Modules C4B-Environment
<#
.SYNOPSIS
C4B Quick-Start Guide PowerShell Universal setup script

.DESCRIPTION
- Performs the following PowerShell Universal setup
- Install of PowerShell Universal package
- Creation of Chocolatey-specific jobs from template files
#>
[CmdletBinding()]
param(
# The certificate thumbprint that identifies the target SSL certificate in
# the local machine certificate stores.
[Parameter()]
[ArgumentCompleter({
Get-ChildItem Cert:\LocalMachine\TrustedPeople | ForEach-Object {
[System.Management.Automation.CompletionResult]::new(
$_.Thumbprint,
$_.Thumbprint,
"ParameterValue",
($_.Subject -replace "^CN=(?<FQDN>.+),?.*$", '${FQDN}')
)
}
})]
[ValidateScript({ Test-CertificateDomain -Thumbprint $_ })]
[string]$Thumbprint = $(
if ((Test-Path C:\choco-setup\clixml\chocolatey-for-business.xml) -and (Import-Clixml C:\choco-setup\clixml\chocolatey-for-business.xml).CertThumbprint) {
(Import-Clixml C:\choco-setup\clixml\chocolatey-for-business.xml).CertThumbprint
} else {
Get-ChildItem Cert:\LocalMachine\TrustedPeople -Recurse | Sort-Object {
$_.Issuer -eq $_.Subject # Prioritise any certificates above self-signed
} | Select-Object -ExpandProperty Thumbprint -First 1
}
),

# Optional: Sets PSU to use a provided SQL database instead of SQLLite.
[string]$ConnectionString
)
try {
$DefaultEap = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
Start-Transcript -Path "$env:SystemDrive\choco-setup\logs\Start-C4bPsuSetup-$(Get-Date -Format 'yyyyMMdd-HHmmss').txt"

Invoke-Choco upgrade powershelluniversal-remove-default-listener.hook --confirm --no-progress
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where is this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is it ran before PowerShell Universal is installed? What listener is it removing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's a hook package, so (unless written to run on install as well as a hook) it needs to be in place before the main package is installed. Though thinking about it, this one is fine to move to after, we're making the adjustment in the setup script... so I can move it to after. Easy!

The listener it's removing is the http :5000 from one of the multiple configuration files, so that we can use it ourselves (and so that we don't have an additional http listener that we don't want to have available).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this stays as a package, it will need to be added to the chocolatey.json file for the packages used by the guide.


# Install PowerShell Universal
Invoke-Choco upgrade powershelluniversal --confirm --no-progress --install-args="STARTSERVICE=0$(if ($ConnectionString) {" CONNECTIONSTRING=$ConnectionString DATABASETYPE=SQL"})"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The PowerShellUniversal CCR package needs to be added to the chocolatey.json file to enable offline installations.

$PSUPort = 5000

# Handle configuration
$ConfigurationFile = Join-Path $env:ProgramData "PowerShellUniversal/appsettings.json"
$CurrentConfiguration = Get-Content $ConfigurationFile | ConvertFrom-Json

if ($Thumbprint) {
$PSUPort = 5000
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we allow the individual running the guide to select the TCP port for their PSU instance? If not in this initial PR, an issue should be raised to support this customization in the future.

$CurrentConfiguration.Kestrel.Endpoints = @{
HTTPS = @{
Url = "https://$(Get-ChocoEnvironmentProperty CertSubject):$PSUPort"
Certificate = @{
Thumbprint = $Thumbprint
Store = "TrustedPeople"
Location = "LocalMachine"
AllowInvalid = "true"
}
}
}
}

if ($ConnectionString) {
$CurrentConfiguration.Data.ConnectionString = $ConnectionString
}

if ((Get-Content $ConfigurationFile -Raw) -ne ($CurrentConfiguration | ConvertTo-Json -Depth 10)) {
$CurrentConfiguration | ConvertTo-Json -Depth 10 | Set-Content $ConfigurationFile
}

# Future consideration: parameter to disable external access?
$FwRuleParams = @{
DisplayName = "PowerShellUniversal Access"
Direction = 'Inbound'
LocalPort = $PSUPort
Protocol = 'TCP'
Action = 'Allow'
}
$null = New-NetFirewallRule @FwRuleParams # Set-EnvFirewallRule @FwRuleParams

# Create admin user
if (-not ($User = Get-ChocoEnvironmentProperty PSUCredential)) {
$User = [pscredential]::new(
"admin",
(New-ServicePassword)
)
Set-ChocoEnvironmentProperty PSUCredential $User

[System.Environment]::SetEnvironmentVariable('PSUDefaultAdminName', $User.UserName, [System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('PSUDefaultAdminPassword', $User.Password.ToPlainText(), [System.EnvironmentVariableTarget]::Machine)
Comment thread
JPRuskin marked this conversation as resolved.
}

# Set Security Defaults
$RepositoryDirectory = Join-Path $env:ProgramData UniversalAutomation\Repository

if (-not (Test-Path $RepositoryDirectory -PathType Container)) {
$null = New-Item -Path $RepositoryDirectory -ItemType Directory
}

if (-not (Test-Path $RepositoryDirectory\.universal\settings.ps1)) {
$null = New-Item -Path $RepositoryDirectory\.universal\settings.ps1 -Value @'
$Parameters = @{
EnhancedAppTokenSecurity = $true
ApiSecurityModel = $true
}
Set-PSUSetting @Parameters
'@ -Force
}

# Deploy jobs and dashboards
Invoke-Choco upgrade chocolatey-licensed-psu-environment --confirm --no-progress
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where is the PR for this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The chocolatey-licensed-psu-environment package must also be added to the chocolatey.json file. Please link to a PR for this package to review or pull down for testing.


# Start service
Start-Service PowerShellUniversal

# Wait until the username and password have been initialized on the first run
if ([System.Environment]::GetEnvironmentVariable('PSUDefaultAdminPassword', [System.EnvironmentVariableTarget]::Machine)) {
Write-Verbose "[$(Get-Date -Format 'hh:mm:ss')] Waiting for PowerShell Universal to start..."
while (-not (Select-String -Path $env:ProgramData\PowerShellUniversal\Logs\System\systemLog$(Get-Date -Format "yyyyMMdd").txt -Pattern "\[INF\]\[UniversalAutomation\.StartupService\] Startup complete.$")) {
Start-Sleep -Seconds 5
}
Write-Verbose "[$(Get-Date -Format 'hh:mm:ss')] PowerShell Universal has successfully started."
}

# Save useful params
Update-Clixml -Properties @{
PowerShellUniversalUri = "https://$(Get-ChocoEnvironmentProperty CertSubject):$PSUPort"
}
} finally {
[System.Environment]::SetEnvironmentVariable('PSUDefaultAdminName', $null, [System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('PSUDefaultAdminPassword', $null, [System.EnvironmentVariableTarget]::Machine)
Comment thread
JPRuskin marked this conversation as resolved.

$ErrorActionPreference = $DefaultEap
Stop-Transcript
}
4 changes: 2 additions & 2 deletions scripts/Create-ChocoLicensePkg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ $licensePackageNuspec = "$licensePackageFolder\$LicensePackageId.nuspec"
# Get license expiration date and node count
[xml]$licenseXml = Get-Content -Path $LicensePath
$licenseExpiration = [datetimeoffset]::Parse("$($licenseXml.SelectSingleNode('/license').expiration) +0")
$null = $licenseXml.license.name -match "(?<=\[).*(?=\])"
$licenseNodeCount = $Matches.Values -replace '\s[A-Za-z]+',''
$null = $licenseXml.license.name -match "(?<=\[)(?<NodeCount>.*)(?=\])"
$licenseNodeCount = $Matches['NodeCount'] -replace '\s[A-Za-z]+'

if ($licenseExpiration -lt [datetimeoffset]::UtcNow) {
Write-Warning "THE LICENSE FILE AT '$LicensePath' is EXPIRED. This is the file used by this script to generate this package, not at '$licensePackageFolder'"
Expand Down
Loading