Skip to content
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

BREAKING CHANGE: CertReq: Improve certificate match selectivity #271

Merged

Conversation

uw-dc
Copy link
Contributor

@uw-dc uw-dc commented Dec 14, 2022

Pull Request (PR) description

Breaking Change: Support multiple certificates with the same issuer and subject by making friendlyName a mandatory (key) parameter

Prevent existing certificates with non-matching friendlyName and template being considered as existing desired certificates; This resolves problems where an incorrect existing certificate is compared with the desired state and Test-TargetResource consequentially returns $false.

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry to the change log under the Unreleased section of the
    file CHANGELOG.md. Entry should say what was changed and how that
    affects users (if applicable), and reference the issue being resolved
    (if applicable).
  • Resource documentation added/updated in README.md.
  • Resource parameter descriptions added/updated in README.md, schema.mof
    and comment-based help.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Community Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Community Testing Guidelines.
  • New/changed code adheres to DSC Community Style Guidelines.

This change is Reviewable

@uw-dc
Copy link
Contributor Author

uw-dc commented Dec 14, 2022

An issue with 'GENERATE CONCEPTUAL HELP'; Looks environmental?

ERROR: Failed to import classes from file /home/vsts/work/1/s/source/DSCResources/DSC_CertificateExport/DSC_CertificateExport.schema.mof. Error Exception calling "ImportClasses" with "3" argument(s): "Unable to load shared library 'libmi' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibmi: cannot open shared object file: No such file or directory"
At /home/vsts/work/1/s/output/RequiredModules/DscResource.DocGenerator/0.11.1/DscResource.DocGenerator.psm1:1486 char:9
+         throw "Failed to import classes from file $FileName. Error $_ …
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Unable to load shared library 'libmi' or one of its dependencies

`"Unable to load shared library 'libmi' or one of its dependencies`

Hoping that PSWSMan will satisfy dependency
`"Unable to load shared library 'libmi' or one of its dependencies`

This won't be a problem using a Windows image, as per many of the other recently maintained DSC community modules
@codecov
Copy link

codecov bot commented Dec 15, 2022

Codecov Report

Merging #271 (f94fb00) into main (137a69f) will increase coverage by 0%.
The diff coverage is 100%.

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #271   +/-   ##
===================================
  Coverage    84%    84%           
===================================
  Files         7      7           
  Lines       929    933    +4     
===================================
+ Hits        786    790    +4     
  Misses      143    143           
Impacted Files Coverage Δ
source/DSCResources/DSC_CertReq/DSC_CertReq.psm1 100% <100%> (ø)

…te FriendlyName comparison occurs

This is when Test-TargetResource is run with CertificateTemplate == 'DomainControllerAuthentication'

I would expect a DomainController to only have one maintained certificate used for DomainControllerAuthentication, rather than have multiple with distinct friendly names, so it seems fair to maintain this exception and include a specific test for this scenario
When there were other non-SAN certificate extensions, the situation was treated as Current and Desired SANs do not match rather than there being no SANs
@uw-dc
Copy link
Contributor Author

uw-dc commented Dec 15, 2022

@PlagueHO

Is it possible please to get a review on this?
It would be really good for us to resolve the issues this PR covers as issue #121 is affecting our production hosts.

Thank you.

@johlju johlju requested a review from PlagueHO December 15, 2022 15:10
Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

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

Hi @uw-dc - sorry about the delay. Looks great. Just some minor tweaks, nothing major.

Reviewed 2 of 5 files at r1, 1 of 1 files at r2, 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @uw-dc)


azure-pipelines.yml line 27 at r3 (raw file):

        displayName: 'Package Module'
        pool:
          vmImage: 'windows-latest'

We typically use ubuntu-latest for the package step. Not that it matters too much - but if there is a specific need then we should note it here (so I don't revert it later)


CHANGELOG.md line 8 at r3 (raw file):

## [Unreleased]

- CertReq:

Can you move under the ### Changed section`?


CHANGELOG.md line 9 at r3 (raw file):

- CertReq:
  - Made Certificate FriendlyName a mandatory parameter (key) so multiple certificates with same issuer and subject can be configured in the same DSC configuration - Fixes [Issue #269](https://github.com/dsccommunity/CertificateDsc/issues/269)

Can you reduce the line length to less than 100 chars on this line and the next one?


CHANGELOG.md line 9 at r3 (raw file):

- CertReq:
  - Made Certificate FriendlyName a mandatory parameter (key) so multiple certificates with same issuer and subject can be configured in the same DSC configuration - Fixes [Issue #269](https://github.com/dsccommunity/CertificateDsc/issues/269)

Can you include BREAKING CHANGE: at the beginning of these lines? This will tell the pipeline to increase the major version number.


source/DSCResources/DSC_CertReq/DSC_CertReq.psm1 line 202 at r3 (raw file):

    $cert = Get-ChildItem -Path Cert:\LocalMachine\My |
        Where-Object -FilterScript {
            (Compare-CertificateSubject -ReferenceSubject $_.Subject -DifferenceSubject $Subject) -and `

FYI: I like the improvement here - nice!


source/DSCResources/DSC_CertReq/en-US/DSC_CertReq.strings.psd1 line 17 at r3 (raw file):

    NoValidCertificateMessage = No valid certificate found with Subject '{0}', Issuer '{1}', FriendlyName '{2}' and CertificateTemplate '{3}'.
    ExpiredCertificateMessage = The certificate found with Subject '{0}', Issuer '{1}', FriendlyName '{2}' and CertificateTemplate '{3}' has expired: {4}.
    NoExistingSans = The certificate found with Subject '{0}', Issuer '{1}', FriendlyName '{2}' and CertificateTemplate '{3}' has no SANs, yet the following SANs are specified: {4}. Certificate has the Thumbprint '{5}'.

FYI: Consistency - Can you add Message to the end of the property name to differentiate it? Unless it is an error then add "Error" - not a major thing as we clearly haven't been 100% consistent here.


tests/Unit/DSC_CertReq.Tests.ps1 line 1874 at r3 (raw file):

                    -MockWith $mock_getCertificateTemplateName_validCertificateTemplate

                # Mock -CommandName Get-CertificateSubjectAlternativeName `

Can you remove commented out lines here (and throughout)?


tests/Unit/DSC_CertReq.Tests.ps1 line 1878 at r3 (raw file):

                It 'Should return true' {
                    Test-TargetResource @paramsStandard -Verbose | Should -Be $true

Can you change to Should -BeTrue (and Should -BeFalse) and throughout.

@uw-dc uw-dc requested a review from PlagueHO December 16, 2022 09:18
@PlagueHO
Copy link
Member

Sorry @uw-dc - will get onto this tonight.

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r4, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @uw-dc)


CHANGELOG.md line 9 at r3 (raw file):

Previously, PlagueHO (Daniel Scott-Raynsford) wrote…

Can you reduce the line length to less than 100 chars on this line and the next one?

Thank you! You can also wrap if you want. For example:

 - Made Certificate FriendlyName a mandatory parameter (key) so multiple
   certificates with same issuer and subject can be configured in the same
   DSC configuration - Fixes [Issue #269](https://github.com/dsccommunity/CertificateDsc/issues/269)

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @uw-dc)

Copy link
Member

@PlagueHO PlagueHO left a comment

Choose a reason for hiding this comment

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

:lgtm:

Thank you for contributing this! We'll leave it in prerelease for a few weeks and then once we'll push it out as a new major version.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @uw-dc)

@PlagueHO PlagueHO merged commit 8d5f01f into dsccommunity:main Dec 23, 2022
@uw-dc uw-dc deleted the improve-certreq-certificate-match-selectivity branch December 28, 2022 09:08
cmielke pushed a commit to cmielke/CertificateDsc that referenced this pull request Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants