Skip to content

Commit

Permalink
Force overwrite Certificate property during certificate rotate (#251)
Browse files Browse the repository at this point in the history
# Description
Summary of changes:
- Fixed an issue where certificate property is not updated properly
- Improved logging for cleanup of certificates after rotate

# Change type
- [x] Bug fix (non-breaking change)
- [ ] Code style update (formatting, local variables)
- [ ] New Feature (non-breaking change that adds new functionality
without impacting existing)
- [ ] Breaking change (fix or feature that may cause functionality
impact)
- [ ] Other

# Checklist:
- [x] My code follows the style and contribution guidelines of this
project.
- [x] I have tested and validated my code changes.
  • Loading branch information
arudell authored Apr 4, 2024
1 parent c4cfa58 commit 359d2ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function Start-SdnMuxCertificateRotation {
else {
# in instances where the certificate property does not exist, we will need to add it
# this typically will occur if converting from CA issued certificate to self-signed certificate
$virtualServer.properties | Add-Member -MemberType NoteProperty -Name 'certificate' -Value $encoding
$virtualServer.properties | Add-Member -MemberType NoteProperty -Name 'certificate' -Value $encoding -Force
}
$jsonBody = $virtualServer | ConvertTo-Json -Depth 100

Expand All @@ -186,9 +186,12 @@ function Start-SdnMuxCertificateRotation {
} -ArgumentList $obj.Certificate

if ($certsToExamine) {
"`nMultiple certificates detected for Subject: {0}. Examine the certificates and cleanup if no longer needed." -f $obj.Certificate.Subject | Trace-Output -Level:Warning
foreach ($cert in $certsToExamine) {
"Examine certificate subject {0} and thumbprint {1} on {2} and remove if no longer needed" -f $cert.Subject, $cert.Thumbprint, $obj.managementAddress | Trace-Output -Level:Warning
"`t[{0}] Thumbprint: {1}" -f $cert.PSComputerName, $cert.Thumbprint | Trace-Output -Level:Warning
}

Write-Host "" # insert empty line for better readability
}

# restart the slb mux service on the mux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function New-SdnServerCertificate {
[datetime]$NotAfter = (Get-Date).AddYears(3),

[Parameter(Mandatory = $false)]
[System.String]$Path = "$(Get-WorkingDirectory)\MuxCert_{0}" -f (Get-FormattedDateTimeUTC),
[System.String]$Path = "$(Get-WorkingDirectory)\ServerCert_{0}" -f (Get-FormattedDateTimeUTC),

[Parameter(Mandatory = $false)]
[System.Object]$FabricDetails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function Start-SdnServerCertificateRotation {
else {
# in instances where the certificate property does not exist, we will need to add it
# this typically will occur if converting from CA issued certificate to self-signed certificate
$server.properties | Add-Member -MemberType NoteProperty -Name 'certificate' -Value $encoding
$server.properties | Add-Member -MemberType NoteProperty -Name 'certificate' -Value $encoding -Force
}
$jsonBody = $server | ConvertTo-Json -Depth 100

Expand All @@ -185,9 +185,12 @@ function Start-SdnServerCertificateRotation {
} -ArgumentList $obj.Certificate

if ($certsToExamine) {
"`nMultiple certificates detected for Subject: {0}. Examine the certificates and cleanup if no longer needed." -f $obj.Certificate.Subject | Trace-Output -Level:Warning
foreach ($cert in $certsToExamine) {
"Examine certificate subject {0} and thumbprint {1} on {2} and remove if no longer needed" -f $cert.Subject, $cert.Thumbprint, $obj.managementAddress | Trace-Output -Level:Warning
"`t[{0}] Thumbprint: {1}" -f $cert.PSComputerName, $cert.Thumbprint | Trace-Output -Level:Warning
}

Write-Host "" # insert empty line for better readability
}

# restart nchostagent on server
Expand Down

0 comments on commit 359d2ee

Please sign in to comment.