Skip to content

Commit 2fbb9de

Browse files
committed
(doc) Adds Jenkins SSL Upgrade Instructions for Quickstart Guide
1 parent f0bfbf4 commit 2fbb9de

File tree

2 files changed

+107
-3
lines changed

2 files changed

+107
-3
lines changed

src/content/docs/en-us/c4b-environments/quick-start-environment/certificate-renewal.mdx

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Callout from '@choco/components/Callout.astro';
88
import Iframe from '@choco/components/Iframe.astro';
99
import Xref from '@components/Xref.astro';
1010

11-
This document is meant to serve as a guide for where to look when needing to renew your SSL certificate(s) for the Nexus and Chocolatey Central Management components of the quick start environment.
11+
This document is meant to serve as a guide for where to look when needing to renew your SSL certificate(s) for the Jenkins, Nexus, and Chocolatey Central Management components of the quick start environment.
1212

1313
## Set-NexusCert.ps1
1414

@@ -213,3 +213,102 @@ process {
213213
```powershell
214214
.\Set-CCMCert.ps1 -CertificateThumbprint 'Your_Certificate_Thumbprint_Value'
215215
```
216+
217+
## Set-JenkinsCert.ps1
218+
219+
A version of this script may already be saved on your repository server at `C:\choco-setup\scripts\Set-JenkinsCert.ps1`.
220+
221+
```powershell
222+
<#
223+
.Synopsis
224+
Updates a keystore and ensure Jenkins is configured to use an appropriate port and certificate for HTTPS access
225+
226+
.Example
227+
Set-JenkinsCert -Thumbprint $Thumbprint
228+
229+
.Notes
230+
Requires a Jenkins service restart after the changes have been made.
231+
#>
232+
[CmdletBinding()]
233+
param(
234+
# The thumbprint of the certificate to use
235+
[Parameter(Mandatory)]
236+
[String]$Thumbprint,
237+
238+
# The port to have HTTPS available on
239+
[Parameter()]
240+
[uint16]$Port = 7443
241+
)
242+
243+
$KeyStore = "C:\ProgramData\Jenkins\.jenkins\keystore.jks"
244+
$KeyTool = Convert-Path "C:\Program Files\Eclipse Adoptium\jre-*.*\bin\keytool.exe" # Using Temurin*jre package keytool
245+
$Passkey = [System.Net.NetworkCredential]::new(
246+
"JksPassword",
247+
"$(New-Guid)"
248+
).Password
249+
250+
if (Test-Path $KeyStore) {
251+
Remove-Item $KeyStore -Force
252+
}
253+
254+
# Generate the Keystore file
255+
try {
256+
$CertificatePath = Join-Path $env:Temp "$($Thumbprint).pfx"
257+
$CertificatePassword = [System.Net.NetworkCredential]::new(
258+
"TemporaryCertificatePassword",
259+
"$(New-Guid)"
260+
)
261+
262+
# Temporarily export the certificate as a PFX
263+
$null = Get-ChildItem Cert:\LocalMachine\TrustedPeople\ | Where-Object {$_.Thumbprint -eq $Thumbprint} | Export-PfxCertificate -FilePath $CertificatePath -Password $CertificatePassword.SecurePassword
264+
265+
# Using a job to hide improper non-output streams
266+
$Job = Start-Job {
267+
$CurrentAlias = ($($using:CertificatePassword.Password | & $using:KeyTool -list -v -storetype PKCS12 -keystore $using:CertificatePath) -match "^Alias.*").Split(':')[1].Trim()
268+
269+
$null = & $using:KeyTool -importkeystore -srckeystore $using:CertificatePath -srcstoretype PKCS12 -srcstorepass $using:CertificatePassword.Password -destkeystore $using:KeyStore -deststoretype JKS -alias $currentAlias -destalias jetty -deststorepass $using:Passkey
270+
$null = & $using:KeyTool -keypasswd -keystore $using:KeyStore -alias jetty -storepass $using:Passkey -keypass $using:CertificatePassword.Password -new $using:Passkey
271+
} | Wait-Job
272+
if ($Job.State -eq 'Failed') {
273+
$Job | Receive-Job
274+
} else {
275+
$Job | Remove-Job
276+
}
277+
} finally {
278+
# Clean up the exported certificate
279+
Remove-Item $CertificatePath
280+
}
281+
282+
# Update the Jenkins Configuration
283+
$XmlPath = "C:\Program Files\Jenkins\jenkins.xml"
284+
[xml]$Xml = Get-Content $XmlPath
285+
@{
286+
httpPort = -1
287+
httpsPort = $Port
288+
httpsKeyStore = $KeyStore
289+
httpsKeyStorePassword = $Passkey
290+
}.GetEnumerator().ForEach{
291+
if ($Xml.SelectSingleNode("/service/arguments")."#text" -notmatch [Regex]::Escape("--$($_.Key)=$($_.Value)")) {
292+
$Xml.SelectSingleNode("/service/arguments")."#text" = $Xml.SelectSingleNode("/service/arguments")."#text" -replace "\s*--$($_.Key)=.+?\b", ""
293+
$Xml.SelectSingleNode("/service/arguments")."#text" += " --$($_.Key)=$($_.Value)"
294+
}
295+
}
296+
$Xml.Save($XmlPath)
297+
298+
if ((Get-Service Jenkins).Status -eq 'Running') {
299+
Restart-Service Jenkins
300+
}
301+
```
302+
303+
### What does this script do?
304+
305+
- The script will prompt for a certificate thumbprint. Please enter the thumbprint of a certificate available in the LocalMachine\TrustedPeople store.
306+
- Adds the certificate to the Jenkins Java Keystore.
307+
- Modifies the `jenkins.xml` configuration file to point to the new port, keystore, and passkey.
308+
- Restarts the Jenkins service.
309+
310+
### Script Example
311+
312+
```powershell
313+
.\Set-JenkinsCert.ps1 -Thumbprint 'Your_Certificate_Thumbprint_Value'
314+
```

src/content/docs/en-us/c4b-environments/quick-start-environment/upgrade-jenkins.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ If your server is internet restricted, please internalize the needed packages on
1616

1717
<Callout type="warning">
1818
The current Jenkins package requires Java version 17 or 21 which hasn't been added as a package dependency to jenkins (due to the numerous flavours of Java out there). As part of the Quick Start Guide setup we install the temurin21jre package. However any Java version 17 or 21 package will work.
19-
19+
2020
More information is available in the [Java support policy documentation](https://www.jenkins.io/doc/book/platform-information/support-policy-java/).
2121
</Callout>
2222

@@ -25,14 +25,15 @@ If your server is internet restricted, please internalize the needed packages on
2525
1. Internalize the Jenkins package and push it to your internal repo.
2626
2. Internalize a java package compatible with Jenkins and push it to your internal repo. We recommend the [temurin21jre package](https://community.chocolatey.org/packages/Temurin21jre).
2727
3. Upgrade the temurin21jre and Jenkins packages (Example commands provided below).
28+
4. Run the `Set-JenkinsCert.ps1` script to set Jenkins to run over HTTPS again.
2829

2930
export const callout2 = {
3031
title: 'Internalizing Note',
3132
type: 'info'
3233
};
3334

3435
<Callout content={callout2}>
35-
You can add the temurin21jre and Jenkins packages to your Jenkins pipelines, setup by the Quick Start Guide, to help keep new versions of these packages in your internal repo.
36+
You can add the `temurin21jre` and `jenkins` packages to your Jenkins pipelines, setup by the Quick Start Guide, to help keep new versions of these packages in your internal repo.
3637
</Callout>
3738

3839
### Example Upgrade Commands:
@@ -44,3 +45,7 @@ choco upgrade temurin21jre --package-parameters="/ADDLOCAL=FeatureJavaHome" -y -
4445
```powershell
4546
choco upgrade jenkins -y --source="'Your Internal Repo'"
4647
```
48+
49+
```powershell
50+
C:\choco-setup\files\scripts\Set-JenkinsCert.ps1 -Thumbprint 'Your_Certificate_Thumbprint_Value'
51+
```

0 commit comments

Comments
 (0)