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

(MODULES-5152) Fix ACE mutation on output #105

Conversation

Iristyle
Copy link
Contributor

@Iristyle Iristyle commented Jun 29, 2017

  • Existing code mutates an Ace instance in the methods used to emit
    string versions of Ace objects - permissions_should_to_s and
    permissions_to_s. In particular, the ALL APPLICATION PACKAGES
    group is special as it must be specified without the leading
    APPLICATION PACKAGE AUTHORITY to properly resolve to a SID
    with the Windows API.

    Previously, for the sake of outputting the name of the group
    to users in the output of change messages / puppet resource,
    a SID name would be resolved to a complete name like
    APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES and
    the original Ace instance would be mutated causing future
    misbehavior as a result.

  • Previously permissions_to_s produced an Array of
    Puppet::Type::Acl::Ace objects, but now produces an Array of
    Ruby Hash objects, which can still be turned into log messages
    just fine. Puppet 5 in particular changed how values are
    logged to display to support arbitrarily nested structures.

  • Update documentation for how to use these accounts correctly.

  • Add integration tests for APPLICATION PACKAGES - though these
    unfortunately do not prove that the accounts can be used in a
    real manifest.

@Iristyle Iristyle changed the title (MODULES-2152) Fix ACE ctor / unwanted mutation (MODULES-5152) Fix ACE ctor / unwanted mutation Jun 29, 2017
@Iristyle Iristyle force-pushed the ticket/MODULES-5152-error-with-ALL-APPLICATION-PACKAGES branch from 2bc8493 to 88fab9a Compare June 29, 2017 00:27
@glennsarti
Copy link
Contributor

Looks like an id='' keyvalue pair has snuck into the tests...nvm you just push a commit 👍

@Iristyle Iristyle force-pushed the ticket/MODULES-5152-error-with-ALL-APPLICATION-PACKAGES branch from 88fab9a to 709cd72 Compare June 29, 2017 00:28
@Iristyle
Copy link
Contributor Author

Bummer.. output isn't quite right here as it now drops the original ACEs:

Notice: /Stage[main]/Main/Acl[c:\test]/permissions: permissions changed [] to [
 { identity => 'APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES', id => 'S-1-15-2-1', rights => ["full"] }]
Notice: /Stage[main]/Main/Acl[c:\test]/inherit_parent_permissions: inherit_parent_permissions changed true to 'false'

But at least it doesn't crash.

perm_hash = perm.to_hash
perm_hash['identity'] = get_account_name(perm.identity)
# TODO: is it just as easy to perm.dup instead?
Puppet::Type::Acl::Ace.new(perm_hash, nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look into just returning an array of strings / hashes here instead... or calling .to_s directly on the Ace object and supplanting the identity.

Note that the behavior on Puppet 4 / Puppet 5 will be different.

@Iristyle Iristyle force-pushed the ticket/MODULES-5152-error-with-ALL-APPLICATION-PACKAGES branch from 709cd72 to 480984e Compare June 29, 2017 00:39
@@ -322,7 +323,7 @@ def inspect
if key_value.is_a? Array
"#{key} => #{key_value}"
else
"#{key} => '#{key_value}'"
"#{key} => '#{key_value}'" unless (key == 'id' && key_value.nil?)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gross... designed to not emit an empty SID (to match prior behavior).

Might have to scrap adding id to the returned hash.

@Iristyle Iristyle force-pushed the ticket/MODULES-5152-error-with-ALL-APPLICATION-PACKAGES branch 2 times, most recently from dd4a78b to 18b147f Compare June 29, 2017 04:19
"'#{value}'"
end
end
# def self.format_value_for_display(value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commented this just to see if it's actually called anywhere... its unused in specs on OSX, but maybe it is called on Windows somehow?

@Iristyle Iristyle force-pushed the ticket/MODULES-5152-error-with-ALL-APPLICATION-PACKAGES branch 7 times, most recently from aa5d1fd to c7b2ea2 Compare June 30, 2017 23:20
@Iristyle
Copy link
Contributor Author

Iristyle commented Jul 6, 2017

Testing with manifest:

file { 'c:/test': ensure => 'directory' } ~>
acl { 'c:/test':
  purge => 'true',
  permissions => [{ identity => 'ALL APPLICATION PACKAGES', rights => ['full']},],
  inherit_parent_permissions => 'false',
}

@Iristyle Iristyle force-pushed the ticket/MODULES-5152-error-with-ALL-APPLICATION-PACKAGES branch 8 times, most recently from d5976c7 to d2390e1 Compare July 25, 2017 18:58
@Iristyle Iristyle changed the title (MODULES-5152) Fix ACE ctor / unwanted mutation (MODULES-5152) Fix ACE mutation on output Jul 25, 2017
@Iristyle
Copy link
Contributor Author

Iristyle commented Jul 25, 2017

@eputnam 6333f0b has the combined fixes for Puppet 5 / Ruby 2.4 / test changes / ubergem pinning.

@Iristyle Iristyle force-pushed the ticket/MODULES-5152-error-with-ALL-APPLICATION-PACKAGES branch from be02ad1 to 94ff5e7 Compare July 25, 2017 20:55
 - Although some of the changes in this PR should be independent, it
   was necessary to combine them to get a passing commit, given the
   timeline of some related releases.

 - rspec-puppet introduced some monkey patching in 2.6.0 which breaks
   Windows on Windows testing - introduced in
   rodjek/rspec-puppet#498

 - AppVeyor won't demonstrate the problem given Puppet 4.2.3 has been
   removed from the matrix, but this PR also pins
   puppet-module-win-dev-r21 back to `0.0.7` for a few reasons.
   0.0.8+ doesn't work properly in Jenkins due to the addition of
   rspec-puppet-facts which requires json and triggers compilation
   of a native extension in spec environments without compilers.
   The 0.0.9 / 0.0.10 releases include a dependency on metadata-json-list
   2.0.0+ which requires Puppet 4.7+

 - Finally, the behavior of Puppet format_value_for_display changed in
   Puppet 5, which produces different output for change notifications
   and `puppet resource` in Puppet 5.  This module will likely need to
   be refactored later to simplify the use of Ruby types (to remove
   Ace deriving from Hash), but for now, changing just the test to
   accurately portray Puppet behavior is sufficient.
@Iristyle Iristyle force-pushed the ticket/MODULES-5152-error-with-ALL-APPLICATION-PACKAGES branch from ab96e40 to 6333f0b Compare July 25, 2017 21:31
Iristyle added 3 commits July 25, 2017 14:31
 - Use manifests to prove that the ACL mdoule can properly handle
   the identities in APPLICATION PACKAGE AUTHORITY - namely
   S-1-15-2-1 / ALL APPLICATION PACKAGES and S-1-15-2-2 /
   ALL RESTRICTED APPLICATION PACKAGES.

   Note that accounts in APPLICATION PACKAGE AUTHORITY are handled
   strangely in the Windows API, and are not resolvable when fully
   qualified with the LookupAccountName like other accounts are.

   Therefore there are no tests showing that the fully qualified
   name actually works, and the README for this module will be
   updated accordingly.
 - Existing code mutates an Ace instance in the methods used to emit
   string versions of Ace objects - permissions_should_to_s and
   permissions_to_s. In particular, the `ALL APPLICATION PACKAGES`
   group is special as it must be specified without the leading
   `APPLICATION PACKAGE AUTHORITY` to properly resolve to a SID
   with the Windows API.

   Previously, for the sake of outputting the name of the group
   to users in the output of change messages / `puppet resource`,
   a SID name would be resolved to a complete name like
   `APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES` *and*
   the original Ace instance would be mutated causing future
   misbehavior as a result.

 - Previously permissions_to_s produced an Array of
   Puppet::Type::Acl::Ace objects, but now produces an Array of
   Ruby Hash objects, which can still be turned into log messages
   just fine. Puppet 5 in particular changed how values are
   logged to display to support arbitrarily nested structures.

 - Update documentation for how to use these accounts correctly.

 - Add integration tests for APPLICATION PACKAGES - though these
   unfortunately do not prove that the accounts can be used in a
   real manifest.
Copy link
Contributor

@eputnam eputnam left a comment

Choose a reason for hiding this comment

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

looks good from a non-windows perspective

Copy link
Contributor

@glennsarti glennsarti left a comment

Choose a reason for hiding this comment

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

Apart from a typo, ready for merge!

@@ -443,6 +443,11 @@ To ensure that a specific set of permissions are absent from the ACL, set `purge

* When using SIDs for identities, autorequire tries to match to users with fully qualified names (e.g., User[BUILTIN\Administrators]) in addition to SIDs (User[S-1-5-32-544]). However, it can't match against 'User[Administrators]', because that could cause issues if domain accounts and local accounts share the same name e.g., 'Domain\Bob' and 'LOCAL\Bob'.

* When referring to accounts in the `APPLICATION PACKAGE AUTHORITY`, use either their SID values or their unqualified names. The Windows API has well documented bugs preventing the fully qualifed account names from being used.
Copy link
Contributor

Choose a reason for hiding this comment

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

Think it's missing a word "accounts in the APPLICATION PACKAGE AUTHORITY" should be "accounts in the APPLICATION PACKAGE AUTHORITY domain" ?

Copy link
Contributor Author

@Iristyle Iristyle Jul 26, 2017

Choose a reason for hiding this comment

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

In Windows terms, I believe they're actually referred to as authorities, even though they look like domains.

Other authorities (including SECURITY_APP_PACKAGE_AUTHORITY ({0,0,0,0,0,15} AKA S-1-15)):
https://msdn.microsoft.com/en-us/library/dd302645.aspx

The new defs in WinNT.h (added for Windows 8) - https://recxltd.blogspot.com/2012/03/windows-8-app-container-security-notes.html

//
// Application Package Authority.
// 

#define SECURITY_APP_PACKAGE_AUTHORITY              {0,0,0,0,0,15}
#define SECURITY_APP_PACKAGE_BASE_RID               (0x00000002L)
#define SECURITY_BUILTIN_APP_PACKAGE_RID_COUNT      (2L)
#define SECURITY_APP_PACKAGE_RID_COUNT              (8L)
#define SECURITY_CAPABILITY_BASE_RID                (0x00000003L)
#define SECURITY_BUILTIN_CAPABILITY_RID_COUNT       (2L)
#define SECURITY_CAPABILITY_RID_COUNT               (5L)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh ok so APPLICATION PACKAGE AUTHORITY is an authority and it would look odd to have " ... in the APPLICATION PACKAGE AUTHORITY authority. PR is good for merge.

@glennsarti glennsarti merged commit 6eac937 into puppetlabs:master Jul 27, 2017
@Iristyle Iristyle deleted the ticket/MODULES-5152-error-with-ALL-APPLICATION-PACKAGES branch July 27, 2017 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants