(PUP-6184) Remove win32/dir usage#8258
Merged
gimmyxd merged 8 commits intopuppetlabs:mainfrom Aug 13, 2020
Merged
Conversation
|
CLA signed by all contributors. |
def97fc to
a772017
Compare
Contributor
Author
|
Jenkins please test this,pxp-agent on windows10ent-64a,windows2012r2-64a,windows2016-64a,windows2019-64a with servertests |
a772017 to
03e9c1f
Compare
Contributor
Author
|
Jenkins please test this on windows10ent-64a,windows2012r2-64a,windows2016-64a,windows2019-64a |
03e9c1f to
6cbd3b6
Compare
Dorin-Pleava
approved these changes
Aug 11, 2020
6cbd3b6 to
cccb89a
Compare
gimmyxd
reviewed
Aug 12, 2020
cccb89a to
61ef18a
Compare
Defined missing functions, constants and structs in `puppet/util/windows/file`, and a private `wstrip` function in our monkey-patched Dir class. We had a similar method but we cannot use it since it's defined on FFI::Pointer, whereas we need it on FFI::Buffer. Use constants instead of strings to specify encodings. Remove requires to win32/dir. Fix ruby 2.7 warning in api_types.rb.
The Win32API library has been deprecated since Ruby 1.9. It was originally added in b5fd953 but sometime ago puppet has switched to using FFI for Win32 API calls.
We cannot require puppet stuff in the install.rb script as Puppet is not installed at that point. Use environment variables for what we need so we don't depend on win32/dir at all. Dir::COMMON_APPDATA maps to ENV['ALLUSERSPROFILE'] Dir::PROGRAM_FILES maps to ENV['PROGRAMFILES']
Before this commit, attempts of installing or running puppet on Windows via AWS Session Manager failed constantly with a `<class:Dir>': uninitialized constant Dir::PERSONAL (Name Error)` error. This behaviour was identified on EC2 Windows Server 2019 instances. The issue is found in the `win32-dir` gem which at some point tries to assign the `Dir::PERSONAL` constant to `Dir::MYDOCUMENTS` without checking if it is initialized/defined first, resulting in the `Name Error` error above. The unlikely scenario where this happens is as follows: The AWS Session Manager communicates with a `SSM Agent` installed on the desired instance. A user called `ssm-user` is created, either manually or automatically by the `SSM Agent` installer (only versions older than 2.3.612.0), to facilitate the connection between the two entities. The root cause comes from this user which does not have a unique user profile and instead is using `C:\Windows\system32\config\systemprofile` so the gem cannot find a `Documents\My Documents` folder since such folders don't actually exist for it. Since Puppet doesn't actually use/needs this path, current fix is defining the `MYDOCUMENTS` constant only if `PERSONAL` is also defined.
61ef18a to
b04b9d2
Compare
gimmyxd
reviewed
Aug 12, 2020
gimmyxd
reviewed
Aug 13, 2020
e8a5d98 to
229bf10
Compare
Contributor
Author
|
Jenkins please test this,pxp-agent on windows10ent-64a,windows2012r2-64a,windows2016-64a,windows2019-64a with servertests |
gimmyxd
approved these changes
Aug 13, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Defined missing functions, constants and structs in
puppet/util/windows/file, and a privatewstripfunction in our Dir monkey-patch. The original gem monkey-patches the String class to define the method, but since we only use it in one place, we add it to Dir.Also fixed some Ruby 2.7 warnings, and removed a stale require to Win32API which we don't use anymore.
Replaced win32-dir usage in install.rb with environment variables, and also removed the win32-security gem from project_data.yaml.
After this PR is merged we should no longer have dependencies on external win32 gems.