-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added CertificateSubject feature to xDSCWebService DSC Resource #379
Added CertificateSubject feature to xDSCWebService DSC Resource #379
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #379 +/- ##
====================================
+ Coverage 67% 73% +6%
====================================
Files 27 27
Lines 3939 3992 +53
Branches 4 4
====================================
+ Hits 2670 2954 +284
+ Misses 1265 1034 -231
Partials 4 4 |
Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 849 at r2 (raw file):
I think it would be better for the configuration to fail if no cert is found than to set the machine not in the desired state with a warning. Comments from Reviewable |
Reviewed 1 of 2 files at r1, 2 of 2 files at r2. Comments from Reviewable |
I was just looking at submitting the same type of changes. It actually used to work this way (back in 2014). Thank you for submitting!!! I submitted feedback. |
Review status: 1 of 3 files reviewed at latest revision, 1 unresolved discussion. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 849 at r2 (raw file): Previously, mgreenegit (Michael Greene) wrote…
I was in two minds about that behavior. I have made the suggested change. Comments from Reviewable |
attn @kwirkykat |
@@ -190,7 +232,11 @@ function Set-TargetResource | |||
$language = 'en' | |||
} | |||
|
|||
$os = [System.Environment]::OSVersion.Version | |||
#$os = [System.Environment]::OSVersion.Version | |||
$os = Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you changing how we retrieve the OS version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change to mock the OS version for testing.
Is there another way to do this without changing the code?
@@ -319,10 +365,7 @@ function Set-TargetResource | |||
} | |||
else | |||
{ | |||
if($AcceptSelfSignedCertificates -and ($AcceptSelfSignedCertificates -eq $false)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this check removed?
This seems like a breaking change.
Previously we would not run this command if $AcceptSelfSignedCertificates was null or true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The If block will never be true so the code would never run.
I think I made a mistake here as I intended to comment out the line so it would be brought up to discuss the purpose.
I will change the If block to trigger only when $AcceptSelfSignedCertificates is $false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had second thoughts on making this change.
Wouldn't fixing the If statement result in a breaking change?
Would it be better to put it back how it was and add a comment for it to be checked if it's still needed?
|
||
$webAdminSrvMgr = [Microsoft.Web.Administration.ServerManager]::OpenRemote("127.0.0.1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to open the remote port is gone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was replaced with New-Object -TypeName Microsoft.Web.Administration.ServerManager so it can be mocked.
@BerheAbrha or @Indhukrishna Can you take a look at this PR? |
User need to explicitly opt-out to allow unencrypted traffic for security reasons. I am not sure if making this optional is a good idea security wise. @TravisEz13 could you please advise on this. |
$_.Oid.FriendlyName -eq 'Certificate Template Name' | ||
}.Format($false) -eq $TemplateName | ||
} | Sort-Object -Property 'NotAfter' -Descending | Select-Object -First 1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If more than one cert is found which satisfy the criteria. I think It should error out instead of choosing one based on the expiry date. The reason being, the same cert have to be trusted by all clients connecting to this server and we can't tell which cert is trusted by all clients connecting to this PullServer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is a requirement that the user explicitly say that they intended for the endpoint to AllowUnencryptedTraffic
Review status: 1 of 3 files reviewed at latest revision, 3 unresolved discussions. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 840 at r3 (raw file): Previously, TravisEz13 (Travis Plunk) wrote…
I have updated the function to only allow one certificate to be returned. Comments from Reviewable |
@@ -2,8 +2,10 @@ | |||
class MSFT_xDSCWebService : OMI_BaseResource | |||
{ | |||
[Key] string EndpointName; | |||
[required, Description("Can take the value AllowUnencryptedTraffic for setting up a non SSL based endpoint")] | |||
[write , Description("Can take the value AllowUnencryptedTraffic for setting up a non SSL based endpoint")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need some mechanism to require the user to explicitly opt-out of being secure
@kwirkykat Can you drive this review? |
@rcarpenter79 are you able to continue the work on this PR? Happy to help you get this reviewed. Could you please rebase this PR against dev so that we get the latest changes? |
I have re-based my branch and fixed some tests that were failing. One test is now failing but in an unrelated module. What is the recommended action? |
@rcarpenter79 Not sure the rebase worked as expected because there a lot of changes this PR want to do that is already part of dev, like that changes in the README.md. Let's start first with the rebase again, and then see if the problem with the tests still persists. |
I think I have fixed the rebase now as it's only showing the files I modified and added. |
Thanks! Rebase looking good. 🙂 Could you look at the review comments, please go into Reviewable and write 'Done' when they are resolved. When these review comments are resolved I will review again. Review status: 0 of 3 files reviewed at latest revision, 4 unresolved discussions. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 236 at r3 (raw file): Previously, rcarpenter79 wrote…
Could you instead move the original string into a helper function that wraps the original way of getting the OS version? That wrapper function could be changed to use another method in the future, if needed. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 49 at r5 (raw file):
Maybe: Throughout. Or even better add this as a localized string so it can be reused. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 138 at r5 (raw file):
This will only work if the thumbprint is set? What should happen if only subject is set? DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 575 at r5 (raw file):
Shouldn't this also check if DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 866 at r5 (raw file):
Using version here, would that break this resource in the future if only a newer version is available? DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 913 at r5 (raw file):
Could we add a comment that describes what the OID number used here means? DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.schema.mof, line 5 at r4 (raw file): Previously, TravisEz13 (Travis Plunk) wrote…
Can we use a new Boolean parameter to opt-out - default is secure, and throws if no certificate is specified. To opt-out this new parameter must be set to Comments from Reviewable |
I think I should have addressed everything. Review status: 0 of 4 files reviewed at latest revision, 9 unresolved discussions. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 849 at r2 (raw file): Previously, rcarpenter79 wrote…
Done. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 236 at r3 (raw file): Previously, johlju (Johan Ljunggren) wrote…
Done. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 840 at r3 (raw file): Previously, rcarpenter79 wrote…
Done. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 49 at r5 (raw file): Previously, johlju (Johan Ljunggren) wrote…
Done. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 138 at r5 (raw file): Previously, johlju (Johan Ljunggren) wrote…
I'm returning the current configuration in the Get-TargetResource method. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 575 at r5 (raw file): Previously, johlju (Johan Ljunggren) wrote…
CertificateSubject and CertificateThumbprint are in different parameter sets. If both are specified it should error. I don't think I added tests for that so I'll add that them while I'm at it. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 866 at r5 (raw file): Previously, johlju (Johan Ljunggren) wrote…
You're right. Hard coding a version isn't sensible. I will lookup the version instead in a function so I can Mock it for testing when the assembly isn't present. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 913 at r5 (raw file): Previously, johlju (Johan Ljunggren) wrote…
I've added the comment and refactored the code to allow for certificates that use 'Certificate Template Information' as well as Certificate Template Name. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.schema.mof, line 5 at r4 (raw file): Previously, johlju (Johan Ljunggren) wrote…
I put a check in place to make sure something was specified for CertificateThumbprint. Comments from Reviewable |
There is definitely something odd about the xWindowsProcess Integration Tests. |
You can close and reopen the PR to kick off the tests again. But this time you can make a change, there are a file that is missing new line at the end; https://ci.appveyor.com/project/PowerShell/xpsdesiredstateconfiguration/build/6.0.1074.0?fullLog=true#L55 |
Reviewed 1 of 3 files at r5, 2 of 3 files at r6, 1 of 1 files at r7. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 236 at r3 (raw file): Previously, rcarpenter79 wrote…
It's currently a (reported) bug with Reviewable that writing 'Done.' with fulls top make me not able to acknowledge the review comments. :/ Please write 'Done' here instead 🙂 DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 138 at r5 (raw file): Previously, rcarpenter79 wrote…
It feels like I want it to return $null if no certificate was set. Feels strange to return 'AllowUnencryptedTraffic' as the thumbprint. Here it is another good example that this should have been a boolean instead to opt-out from being secure. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 6 at r7 (raw file):
I think this should be DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 132 at r7 (raw file):
$output (lowe-case 'o'). Throughout. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 155 at r7 (raw file):
$certificate (lower-case 'c'). DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 880 at r7 (raw file):
$gacAssemblyVersion (lower-case 'g'). Throughout. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 932 at r7 (raw file):
$filteredCertificates lower-case. We should use camelCase for variables except parameters that uses PascalCase. Throughout. To many to comment on each 🙂 Though, you only need to do your code changes, but wouldn't mind the other changed as well. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.schema.mof, line 5 at r4 (raw file): Previously, rcarpenter79 wrote…
Leave it as is for now and I will raise the question and see if we should change this now. DSCResources/MSFT_xDSCWebService/en-US/MSFT_xDSCWebService.psd1, line 5 at r7 (raw file):
Nitpick (non-blocking): Maybe use quotes around template name since it can be spaces in the names? This and below if so. Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 26 at r7 (raw file):
camelCase here as well. Throughout the tests. Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 168 at r7 (raw file):
Does Pester catches this if it throws an error if this is run in the Context-block and not in the It-block? Should we add this call to each It-block instead? Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 239 at r7 (raw file):
We usually write 'Should...' (upper 'S'). Throughout. Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 264 at r7 (raw file):
Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 1038 at r7 (raw file):
Is this debug/todo comments? This and the one below? Comments from Reviewable |
@TravisEz13 @kwirkykat @mgreenegit Could you acknowledge any review comments you have pending or comment if there are still issues. Thanks! @TravisEz13 What do you think about we add an |
Awesome work fixing some much style issue. Thank you! 😃 Reviewed 3 of 3 files at r8. a discussion (no related file): DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 246 at r8 (raw file):
Suggest we set all DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 309 at r8 (raw file):
Should this be DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 787 at r8 (raw file):
Just want to verify. By setting these parameters to mandatory, since there are no integration tests, doe the unit test verify that these are always called with both properties? Same for all other helper functions that have the mandatory property changed for the parameters. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.schema.mof, line 5 at r4 (raw file): Previously, johlju (Johan Ljunggren) wrote…
Would you mind creating an issue for this enhancement? Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 1038 at r7 (raw file): Previously, rcarpenter79 wrote…
Please submit an issue for this. After that, if you want to resolve the problem then please do. 🙂 Do you think it is a breaking change? Comments from Reviewable |
Review status: all files reviewed at latest revision, 9 unresolved discussions. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 246 at r8 (raw file): Previously, johlju (Johan Ljunggren) wrote…
There's no specific reason to use Bool. I always use the type accelerator, where available, over the .Net class. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 309 at r8 (raw file): Previously, johlju (Johan Ljunggren) wrote…
Done DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 787 at r8 (raw file): Previously, johlju (Johan Ljunggren) wrote…
I checked each occurrence of each function to confirm every parameter is specified when the function is called. Comments from Reviewable |
@rcarpenter79 I think you forgot to push the changes? Can't see any commits between my comment and your comments. Or am I missing something here? 🤔 |
I ran out of time. I have pushed the latest changes now. Review status: 1 of 5 files reviewed at latest revision, 9 unresolved discussions. a discussion (no related file): Previously, johlju (Johan Ljunggren) wrote…
Done DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 246 at r8 (raw file): Previously, rcarpenter79 wrote…
Done DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.schema.mof, line 5 at r4 (raw file): Previously, johlju (Johan Ljunggren) wrote…
Raised as #419. Tests/Unit/MSFT_xDSCWebService.Tests.ps1, line 1038 at r7 (raw file): Previously, johlju (Johan Ljunggren) wrote…
Raised as #418. Comments from Reviewable |
Done Review status: 1 of 5 files reviewed at latest revision, 9 unresolved discussions. Comments from Reviewable |
Reviewed 4 of 4 files at r9. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 309 at r8 (raw file): Previously, rcarpenter79 wrote…
Want to double-check. Not sure if done means this is correct as-is or if this was supposed to be changed? 🙂 DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 787 at r8 (raw file): Previously, rcarpenter79 wrote…
LGTM. I prefer having these as mandatory if it works. Comments from Reviewable |
Review status: 4 of 5 files reviewed at latest revision, 5 unresolved discussions. DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1, line 309 at r8 (raw file): Previously, johlju (Johan Ljunggren) wrote…
I misunderstood. I thought you were referencing the style guidelines. Comments from Reviewable |
Awaiting confirmation from other reviewers for a while before merging. Reviewed 1 of 1 files at r10. Comments from Reviewable |
@rcarpenter79 Think I found the problem with the tests, I hope. Gonna merge #421 once the tests passes. |
@rcarpenter79 Can you please rebase now after PR #421 was merged. Hope the tests will all pass now! 🙂 |
After rebase for the merging of a fix for randomly failing tests. Reviewed 1 of 1 files at r11. Comments from Reviewable |
…fied by subject and template name. Removed the Mandatory parameter from CertificateThumbprint and a check to validate that if CertificateSubject is not specified then CertificateThumbprint must be specified and not null. Made some changes to some lines to allow for code to be mocked during testing. Added unit testing for the module.
Reverted OS change from using Cim-Instance back to use the OSVersion method but moved this to a function. Changed the way the Microsoft.Web.Administration was loaded so that it wouldn't only load a specific version but can still mock the ServerManager object. Made a change to Find-CertificateThumbprintWithSubjectAndTemplateName so it will also work with certificates that use the Oid Certificate Template Information and removed references to the Oid from the code in favour of using the friendly name.
Fixed the issue (#418) in Test-WebConfigModulesSetting so it would return $false if a module exists and shouldn't. Renamed [Bool] back to [Boolean] to keep with the rest of the resource kit. Updated README.md unreleased section.
Changed CertificateThumbprint from mandatory to use a default value AllowUnencryptedTraffic.
CertificateSubject can take a regex expression.
If multiple certificates are found then return the one with the latest not after date.
If no certificate subject is found set thumbprint to 'AllowUnencryptedTraffic'.
Fixes #57
Fixes #205
Fixes #418
This change is