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

Changed $ca parameter #43

Closed
wants to merge 17 commits into from
Closed

Changed $ca parameter #43

wants to merge 17 commits into from

Conversation

svenvanrijen
Copy link
Contributor

@svenvanrijen svenvanrijen commented Jan 31, 2017

Changed $ca parameter from $ca = "'$CAServerFQDN$CARootName' " to $ca
= "$CAServerFQDN$CARootName". Old parameter gave errors since
'$CAServerFQDN (example: 'CA01.domain.com) could not be found when
running the script.


This change is Reviewable

Changed $ca parameter from $ca = "'$CAServerFQDN\$CARootName' "  to $ca
= "$CAServerFQDN\$CARootName". Old parameter gave errors since
'$CAServerFQDN (example: 'CA01.domain.com) could not be found when
running the script.
@msftclas
Copy link

Hi @svenvanrijen, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

This seems like a small (but important) contribution, so no Contribution License Agreement is required at this point. Real humans will now evaluate your PR.

TTYL, MSBOT;

@PlagueHO PlagueHO added the needs review The pull request needs a code review. label Feb 2, 2017
@PlagueHO PlagueHO self-assigned this Feb 2, 2017
@@ -128,7 +128,7 @@ function Get-TargetResource
)

# The certificate authority, accessible on the local area network
$ca = "'$CAServerFQDN\$CARootName'"
$ca = "$CAServerFQDN\$CARootName"

Choose a reason for hiding this comment

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

Change looks good. Please document your change on the README.md file https://github.com/PowerShell/xCertificate/blob/dev/ReadMe.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just all changed lines as discussed under PR 43 and issue 42. Also documented the changes in README.md file as requested.

@BerheAbrha BerheAbrha added the waiting for author response The pull request is waiting for the author to respond to comments in the pull request. label Feb 2, 2017
@PlagueHO
Copy link
Member

PlagueHO commented Feb 2, 2017

Hi @svenvanrijen - this change will actually cause problems if the $CARootName contains spaces (which is an acceptable CA Root Name name format).

Could I request that rather than just remove the quotes, could you put a check in to ensure that the $CARootName contains no spaces? If there are no spaces then removing the quotes is OK, if not, they need to be left in.

It might also be worth moving the $ca = "$CAServerFQDN\$CARootName" into a separate function in the CertificateCommon module. But that isn't a requirement.

Does that make sense?

And good job BTW! 😁

@svenvanrijen
Copy link
Contributor Author

Hi @PlagueHO . Thank you for your feedback. Gonna work on that later this week and will keep u posted.

Regards,
Sven

@PlagueHO
Copy link
Member

PlagueHO commented Feb 8, 2017

Thanks @svenvanrijen - thanks for doing this for the community!

@svenvanrijen
Copy link
Contributor Author

svenvanrijen commented Feb 9, 2017

Hi @PlagueHO,

I've been checking on your comments, but it seems like I don't fully get it.
First of all, I don't want to remove ALL the quotes, only the single quotes. I understand that, when using no quotation at all, things go wrong when a string contains spaces.

I'll try to show you what I mean with 3 examples:

the variables are:
$CAServerFQDN = 'ca.test.com'
$CARootName = 'this-is a test'

Example 1: the original config
$ca = "'$CAServerFQDN\$CARootName'"

Output:
'ca.test.com\this-is a test'

Example 2: my suggested change
$ca = "$CAServerFQDN\$CARootName"

Output:
ca.test.com\this-is a test

Example 3: no quotes at all
$ca = $CAServerFQDN\$CARootName

Output (=Error message):
At line:1 char:20 $ca = $CAServerFQDN\$CARootName Unexpected token '\$CARootName' in expression or statement.

So, my point is: removing just the single quotes from the original config is valid as it does not negatively influence the output of the code when spaces are used.

Can you agree on this?

Kind regards,
Sven

@PlagueHO
Copy link
Member

Hi @svenvanrijen - what I meant was to do something like this:

if ($CARootName.Contains(' '))
{
    $ca = "'$CAServerFQDN\$CARootName'"
}
else
{
    $ca = "$CAServerFQDN\$CARootName"
}

Where I work we have CA's with the following naming styles:
CACONTOSO-DV
Contoso.com Issuing CA - DEV 2

The top style CA should be fine without single quotes. The bottom style I think will have problems without single quotes around it. I meant to do some more investigation on my systems to confirm this but I ran out of time today.

What I want to ensure is that any fix works for all naming conventions.

@svenvanrijen
Copy link
Contributor Author

Hi @PlagueHO,

I do understand that, I have the same intentions. I also understood the if/then statement intention, but I think/thought that might not be necessary. But please test this on your systems, and if indeed necessary, I'll be happy to add the if/then statement to the code.

Kind regards,
Sven

@PlagueHO
Copy link
Member

Hi @svenvanrijen - I'll do a couple of quick tests at the office next week and see if the single quotes are required on all CA's. Thanks for your help and patience!

@PlagueHO
Copy link
Member

Hi @svenvanrijen - Ok, I have made some progress looking into this.

You can go ahead and keep the change to remove the single quotes completely from line:

$ca = "'$CAServerFQDN\$CARootName'"

There is no need for the check if spaces exist. However, you will need to change this line: https://github.com/PowerShell/xCertificate/blob/dev/DSCResources/MSFT_xCertReq/MSFT_xCertReq.psm1#L407

To:

$arguments = "-Command ""& $ENV:SystemRoot\system32\certreq.exe" + `
    " @('-submit','-q','-config','$ca','$reqPath','$cerPath')" + `
    " | Set-Content -Path '$certReqOutPath'"""

This should allow the resource to work when Credentials are provided and when they are not. The Credential parameter is required when the CA server does not allow "Everyone" to issue certificates (e.g. you need to request the cert using a specific account).

Does this make sense?

@svenvanrijen
Copy link
Contributor Author

Hi @PlagueHO,

No problem, going to work on that.
Are there any other files I need to update, besides the .psm1 and https://github.com/PowerShell/xCertificate/blob/dev/ReadMe.md as @BerheAbrha requested earlier?

Regards,
Sven

@PlagueHO
Copy link
Member

Hi @svenvanrijen - just add the details of the change to the ## Unreleased section in the Readme.md.

I've managed to identify the problem when using the $credential parameter. To fix it can you please include the following change to this line:
https://github.com/PowerShell/xCertificate/blob/dev/DSCResources/MSFT_xCertReq/MSFT_xCertReq.psm1#L424

Change it from:

$null = Wait-Win32ProcessEnd `
    -Path $command `
    -Arguments $arguments `
    -Credential $Credential

To:

$null = Wait-Win32ProcessStop `
    -Path $command `
    -Arguments $arguments `
    -Credential $Credential

E.g. we're changing the function from Wait-Win32ProcessEnd to Wait-Win32ProcessStop.

One final change (just so the manual integration tests work):
https://github.com/PowerShell/xCertificate/blob/dev/Tests/Integration/MSFT_xCertReq.config.ps1#L22
Change from:

Exportable = $($Exportable.ToString().ToUpper())

Change to:

Exportable = $Exportable

Appreciate your help on this!

Changed all lines as discussed under PR 43 and issue 42
@svenvanrijen
Copy link
Contributor Author

Just all changed lines as discussed under PR 43 and issue 42.

@svenvanrijen
Copy link
Contributor Author

Seems there are still some problems with the CI tests. Looking into that later.

@PlagueHO
Copy link
Member

@svenvanrijen - the test failures aren't caused by something you've done. We've changed the common DSCResource test frameworks to behave differently which requires some changes to this repo. I've included these changes in my PR #48

Once my PR is merged, your PR will pass and can be merged.

@svenvanrijen
Copy link
Contributor Author

@PlagueHO - Good to know! Thank you for your reply!

@PlagueHO PlagueHO added in progress The issue is being actively worked on by someone. and removed waiting for author response The pull request is waiting for the author to respond to comments in the pull request. labels Feb 24, 2017
@PlagueHO
Copy link
Member

PlagueHO commented Mar 2, 2017

Hi @svenvanrijen - my PR has gone through now, so your one should begin passing tests. So if you can fix the merge conflicts by rebasing then I should be able to review and merge it. Thanks again for contributing this!

This reverts commit 3494dfa.
# Conflicts:
#	DSCResources/MSFT_xCertReq/MSFT_xCertReq.psm1
#	ReadMe.md
@svenvanrijen
Copy link
Contributor Author

Hi @PlagueHO,

just merged the repo again, but still one check fails. Not sure it's in the module or the test itself. Can you have another look at it or can I help out on this?

Regards,
Sven

@PlagueHO
Copy link
Member

PlagueHO commented Mar 2, 2017

Hi @svenvanrijen - I think the problem is that my changes from my PR haven't made it into your branch (your PR is undoing a few of my changes). If you have a look at the "Files Changed" you can see a bunch of changes that you didn't actually make 😁 It does look like you've merged my changes though... but perhaps try again?

@svenvanrijen
Copy link
Contributor Author

I'll try again, thnx. I'm quite a newbie on this. I'm sorry....

@svenvanrijen
Copy link
Contributor Author

@PlagueHO I'm affraid I'm not sure how to fix this :(
Any hints or tips?

My thoughts are close this PR, re-fork the original repo and re-apply my changes...

@svenvanrijen
Copy link
Contributor Author

@PlagueHO
A couple of steps further down the road I guess. Still an error while testing unfortunately:

   Context autorenew is false, credentials passed
      [+] should not throw 352ms
      [-] should call expected mocks 96ms
        You did not declare a mock of the Wait-Win32ProcessStop Command in module MSFT_xCertReq.
        at line: 636 in C:\Program Files\WindowsPowerShell\Modules\Pester\4.0.2\Functions\Mock.ps1

I'm affraid I cannot fix this, can I?

Regards,
Sven

@PlagueHO
Copy link
Member

PlagueHO commented Mar 7, 2017

Hi @svenvanrijen - I think there is still a number of changes that are being reverted by your PR. If you have a look at the "Files Changed" Tab above you should be able to identify the changes you've made as opposed to the files that are reverted and then bring those changes back.

As for the test failure, I can give you advise on fixing that once the above changes are reverted.

@svenvanrijen
Copy link
Contributor Author

Still problems resolving various merge issues. Closing this PR and opening a new one.

@vors vors removed the needs review The pull request needs a code review. label Mar 12, 2017
@PlagueHO PlagueHO removed the in progress The issue is being actively worked on by someone. label Jun 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants