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

Dsc resources parameters should be case insensitive #254

Closed
Clebam opened this issue Sep 26, 2023 · 8 comments
Closed

Dsc resources parameters should be case insensitive #254

Clebam opened this issue Sep 26, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@Clebam
Copy link
Contributor

Clebam commented Sep 26, 2023

Describe the Bug

Here is an error message I have from DSC

Error: Failed to apply catalog: Parameter dsc_ensure failed on Dsc_xwebapppool[test_site.fr]: dsc_xwebapppool.dsc_ensure expects an undef value or a match for Enum['Absent', 'Present'], got 'present'

We can see the resource fails to apply because the enum expects a capitalized Present

Expected Behavior

The casing should not matter.

Whether 'present' or 'Present' is provided should be accepted.
At least when dealing with enforced values (like Enum)

  1. 'present' is provided
  2. dsc_base_provider compares to Enum entries case_insensitively ('present' -imatch 'Present')
  3. Then converts to the expected casing ('present' becomes 'Present')
  4. Then delivers 'Present' is provided to the resource

Steps to Reproduce

Steps to reproduce the behavior:
Set ensure: present (all downcased)

Environment

Additional Context

@Clebam Clebam added the bug Something isn't working label Sep 26, 2023
@gavindidrichsen
Copy link
Contributor

Hi @Clebam. Thanks for submitting this issue.

To help me replicate this on my Windows test server, can you please include some sample code? If relevant, could you send some code snippets:

  • puppet code that produced the behaviour above
  • an equivalent DSC script. Does the DSC work ok and the puppet, which wraps the underlying DSC, fail?

What Windows version are you running the above on?

Many thanks,

@Clebam
Copy link
Contributor Author

Clebam commented Sep 26, 2023

Hi @gavindidrichsen,

This would fail

  dsc_xwebapppool { 'my_pool':
    dsc_ensure                => 'present',
    dsc_state                 => 'started',
    dsc_enable32bitapponwin64 => false,
    dsc_managedpipelinemode   => 'integrated',
    dsc_managedruntimeversion => 'v4.0',
  }

This would run (notice both 'Present' and 'Started' and 'Integrated' were upcased)

  dsc_xwebapppool { 'my_pool':
    dsc_ensure                => 'Present',
    dsc_state                 => 'Started',
    dsc_enable32bitapponwin64 => false,
    dsc_managedpipelinemode   => 'Integrated',
    dsc_managedruntimeversion => 'v4.0',
  }

Running on windows 2019 (but would be similar on other version)

The whole issue is linked to the fact that upon conversion from .ps1 file to puppet resource, the casing of Enum is preserved.

@Clebam
Copy link
Contributor Author

Clebam commented Sep 26, 2023

I can find this comment that concerns this issue : https://github.com/puppetlabs/ruby-pwsh/blob/main/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb#L86

Edit : Found this PR : #131

It seems to purposefully exclude enum from matching insensitively.

Is there a good reason for this ?

Thanks

@Clebam
Copy link
Contributor Author

Clebam commented Sep 27, 2023

I learned about validation_mode => 'resource', parameter.
Setting this to resource prevents the issue from happening.

Though, it updates each params when one of them is changed. (that is the expected behavior of validation_mode)

I wonder if the issue still needs to stay opened of if the definitive answer to this type of problems is the validation_mode

@Clebam
Copy link
Contributor Author

Clebam commented Sep 29, 2023

Well it appears validation_mode slows down a lot the resource.

I experience the casing issue on every resource (for instance for dsc_ensure => 'present', every resource will have this kind of constant changes

For 30ish windowsfeatures.
time with validation_mode (and dsc_ensure => 'present') : 45s
time without validation_mode (and dsc_ensure => 'Present') : 0.5s
Notice: /Stage[main]/Sw_iis::Features::Default/Dsc_windowsfeature[Web-Windows-Auth]/dsc_ensure: dsc_ensure changed 'Present' to 'present' (corrective)
Notice: dsc_windowsfeature[{:name=>"Web-Windows-Auth", :dsc_name=>"Web-Windows-Auth"}]: Updating: Finished in 1.18 seconds

@Clebam
Copy link
Contributor Author

Clebam commented Oct 3, 2023

Hi, there is one thing I would like to figure out.
Does every one using pwshlib face the "casing" issue (like 'Present' != 'present) ?
Everything let me think it should work (ie the casing should not matter):

  • The documentation of each module indicates both downcased and PascalCased value as valid in enum.
  • The canonicalize() function seems to handle specifically this issue (it's even what it is meant for according to the puppet doc)

Therefore I really think it may be something from my environment. But I would like some confirmation that it does work as intented for everyone. I tried to dig for a few days in my env without finding anything that would explain the issue I'm facing. But if I have the confirmation it definitely should work, I'll keep digging. (For now, I don't know if it's a bug, a feature or my env 😓)

@jordanbreen28
Copy link
Contributor

@Clebam thanks for raising this. Closing as per discussion https://puppetcommunity.slack.com/archives/CFD8Z9A4T/p1696342031154069.

Root cause was use of the deprecated and unmaintained dsc_xWebAdministration module, which has problems in the underlying dsc module code. Use of the favoured dsc_webadministrationdsc module resolved this issue. Action items are on us to update the badging of these modules on the forge ASAP to reflect their status.

Thanks again!

@jordanbreen28 jordanbreen28 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
@jesusvila
Copy link

jesusvila commented Jan 9, 2024

Also we have problems updating iis site certificates. (Creating sites works perfectly) In previous versions (Server 2016 and Puppet 6), it works perfectly, but now in Server 2022 and Puppet 8, it is not working. We are using dsc-webadministrationdsc (v4.1.0-0-5). The following code is the one causing the error upon execution:

dsc_website{ $title:
	dsc_ensure => 'Present',
	dsc_name => "${prefixSiteName}${title}",
	dsc_state => 'Started',
	dsc_physicalpath => "${webRootFolder}\\${title}",
	dsc_logpath => $logPath,
	dsc_applicationpool => $title,
	dsc_bindinginfo => [{
		protocol => 'http',
		port => 80,
		bindinginformation => "*:80",
		hostname => $title,
	},{
		protocol => 'https',
		port => 443,
		bindinginformation => "*:443",
		hostname => $title,
		certificatestorename => 'My',   # <------------- here 
		certificatethumbprint => $certificateHash,
		sslflags => '1'
	}]
}
Could not evaluate: Provider returned data that does not match the Type Schema for `dsc_website[xxx.site.com]`
(index 0 entry 'certificatestorename' expects an undef value or a match for Enum['My', 'WebHosting', 'my', 'webhosting'], got 'MY')

if we edit this file /etc/puppetlabs/code/environments/production/modules/webadministrationdsc/lib/puppet/type/dsc_website.rb and modify this line:

dsc_bindinginfo: {
      type: "Optional[Array[Struct[{
              sslflags => Optional[Enum['0', '1', '2', '3']],
              certificatestorename => Optional[Enum['MY', 'My', 'my', 'WebHosting', 'webhosting']],

and in the enum we add 'MY' it works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants