You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Description
Summary of changes:
This pull request includes several updates to improve the handling of
certificates in the `SdnDiagnostics` module. The most important changes
include renaming the `New-SdnCertificate` function, introducing a
utility function to confirm if a certificate is self-signed, and
ensuring administrative checks are performed consistently.
Improvements to certificate handling:
*
[`src/SdnDiagnostics.psd1`](diffhunk://#diff-17aaaa968cc894449c79b449c228b28d8a8990bde4000e59bcf24d8189671ee1L126-R126):
Renamed `New-SdnCertificate` to `New-SdnSelfSignedCertificate` to
clarify its purpose.
*
[`src/modules/SdnDiag.Common.psm1`](diffhunk://#diff-9ab71f66f6e21719dc9527f01ea738656003bbbe631f4f1bd85ab1ab8a746f24L368-R368):
Added `Confirm-IsCertSelfSigned` function to check if a certificate is
self-signed and replaced direct comparisons with calls to this function.
[[1]](diffhunk://#diff-9ab71f66f6e21719dc9527f01ea738656003bbbe631f4f1bd85ab1ab8a746f24L368-R368)
[[2]](diffhunk://#diff-9ab71f66f6e21719dc9527f01ea738656003bbbe631f4f1bd85ab1ab8a746f24L1693-R1726)
[[3]](diffhunk://#diff-9ab71f66f6e21719dc9527f01ea738656003bbbe631f4f1bd85ab1ab8a746f24L1811-R1843)
[[4]](diffhunk://#diff-9ab71f66f6e21719dc9527f01ea738656003bbbe631f4f1bd85ab1ab8a746f24R1879-R1882)
[[5]](diffhunk://#diff-15898640fc68e07afa836ad8d93af4f22a4442978d9c233f39d48d44d85cfb60L188-R188)
*
[`src/modules/SdnDiag.Common.psm1`](diffhunk://#diff-9ab71f66f6e21719dc9527f01ea738656003bbbe631f4f1bd85ab1ab8a746f24R1326-R1331):
Added parameters `Subject`, `Thumbprint`, and `NetworkControllerOid` to
`Get-SdnCertificate` to enhance certificate search capabilities.
[[1]](diffhunk://#diff-9ab71f66f6e21719dc9527f01ea738656003bbbe631f4f1bd85ab1ab8a746f24R1326-R1331)
[[2]](diffhunk://#diff-9ab71f66f6e21719dc9527f01ea738656003bbbe631f4f1bd85ab1ab8a746f24L1350-L1369)
Consistent administrative checks:
* `src/SdnDiagnostics.psm1`, `src/modules/SdnDiag.LoadBalancerMux.psm1`,
`src/modules/SdnDiag.NetworkController.psm1`,
`src/modules/SdnDiag.Server.psm1`: Replaced inline administrator checks
with calls to `Confirm-IsAdmin` for consistency.
[[1]](diffhunk://#diff-490865628c61b2e97c50f45b37d7086647c70b2444cbfb9c60cc8c682801356eL278-R278)
[[2]](diffhunk://#diff-8b1f41eba916fc0a86f95c4ab4e5c8c23ce217faa05f9aef2f3564bb60577c2cL391-R391)
[[3]](diffhunk://#diff-26f7a08ead3e5bf8f7eb9bc916e1240653352463c34fb7321d570202143203f8L2541-R2541)
[[4]](diffhunk://#diff-11217f20b55d3b4ea34c8c217794c81d65acc4852dff9bf4295e5cc4d6dfaeedL2643-R2643)
These changes streamline the certificate management process and ensure
consistent administrative privilege checks across the module.
# Change type
- [ ] Bug fix (non-breaking change)
- [ ] Code style update (formatting, local variables)
- [x] 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.
throwNew-Object System.Exception("This function requires elevated permissions. Run PowerShell as an Administrator and import the module again.")
281
-
}
278
+
Confirm-IsAdmin
282
279
283
280
if ($Global:SdnDiagnostics.EnvironmentInfo.ClusterConfigType-ine'ServiceFabric') {
284
281
throwNew-Object System.NotSupportedException("This function is only supported on Service Fabric clusters.")
@@ -290,16 +287,6 @@ function Start-SdnCertificateRotation {
290
287
throwNew-Object System.NotSupportedException("The current machine is not a NetworkController, run this on NetworkController.")
291
288
}
292
289
293
-
# add disclaimer that this feature is currently under preview
294
-
if (!$Force) {
295
-
"This feature is currently under preview. Please report any issues to https://github.com/microsoft/SdnDiagnostics/issues so we can accurately track any issues and help unblock your cert rotation."|Trace-Output-Level:Warning
296
-
$confirm=Confirm-UserInput-Message "Do you want to proceed with certificate rotation? [Y/N]:"
297
-
if (-NOT$confirm) {
298
-
"User has opted to abort the operation. Terminating operation"|Trace-Output-Level:Warning
"Unable to locate certificate using {0}"-f$PSCmdlet.ParameterSetName|Trace-Output-Level:Warning
1370
1403
return$null
1371
1404
}
1372
1405
@@ -1690,8 +1723,7 @@ function Import-SdnCertificate {
1690
1723
}
1691
1724
1692
1725
# determine if the certificates being used are self signed
1693
-
if ($certObject.CertInfo.Subject-ieq$certObject.CertInfo.Issuer) {
1694
-
"Detected the certificate subject and issuer are the same. Setting SelfSigned to true"|Trace-Output-Level:Verbose
1726
+
if (Confirm-IsCertSelfSigned-Certificate $certObject.CertInfo) {
1695
1727
$certObject.SelfSigned=$true
1696
1728
1697
1729
# check to see if we installed to root store with above operation
@@ -1808,7 +1840,7 @@ function Invoke-SdnGetNetView {
1808
1840
}
1809
1841
}
1810
1842
1811
-
functionNew-SdnCertificate {
1843
+
functionNew-SdnSelfSignedCertificate {
1812
1844
<#
1813
1845
.SYNOPSIS
1814
1846
Creates a new self-signed certificate for use with SDN fabric.
@@ -1819,7 +1851,7 @@ function New-SdnCertificate {
1819
1851
.PARAMETERNotAfter
1820
1852
Specifies the date and time, as a DateTime object, that the certificate expires. To obtain a DateTime object, use the Get-Date cmdlet. The default value for this parameter is one year after the certificate was created.
throwNew-Object System.Exception("This function requires elevated permissions. Run PowerShell as an Administrator and import the module again.")
514
-
}
515
-
516
-
# add disclaimer that this feature is currently under preview
517
-
if (!$Force) {
518
-
"This feature is currently under preview. Please report any issues to https://github.com/microsoft/SdnDiagnostics/issues so we can accurately track any issues and help unblock your cert rotation."|Trace-Output-Level:Warning
519
-
$confirm=Confirm-UserInput-Message "Do you want to proceed with certificate rotation? [Y/N]:"
520
-
if (-NOT$confirm) {
521
-
"User has opted to abort the operation. Terminating operation"|Trace-Output-Level:Warning
throwNew-Object System.Exception("This function requires elevated permissions. Run PowerShell as an Administrator and import the module again.")
2986
-
}
2987
-
2988
-
# add disclaimer that this feature is currently under preview
2989
-
if (!$Force) {
2990
-
"This feature is currently under preview. Please report any issues to https://github.com/microsoft/SdnDiagnostics/issues so we can accurately track any issues and help unblock your cert rotation."|Trace-Output-Level:Warning
2991
-
$confirm=Confirm-UserInput-Message "Do you want to proceed with certificate rotation? [Y/N]:"
2992
-
if (-NOT$confirm) {
2993
-
"User has opted to abort the operation. Terminating operation"|Trace-Output-Level:Warning
0 commit comments