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

win_acl doesn't work with registry keys #54357

Closed
mhunsber opened this issue Mar 25, 2019 · 6 comments · Fixed by #54427
Closed

win_acl doesn't work with registry keys #54357

mhunsber opened this issue Mar 25, 2019 · 6 comments · Fixed by #54427
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. windows Windows community

Comments

@mhunsber
Copy link
Contributor

SUMMARY

Since the module uses the LiteralPath argument for getting and setting the ACL, it does not work for registry keys. This is due to a weird behavior in PowerShell's Get-Acl and Set-Acl cmdlets where you have to be in the drive of the registry key for LiteralPath to work.

In earlier versions of powershell, e.g. PSv2, LiteralPath doesn't exist for Get-Acl and Set-Acl

ISSUE TYPE
  • Bug Report
COMPONENT NAME

win_acl

ANSIBLE VERSION
ansible 2.8.0.dev0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/admin/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/admin/ansible/lib/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
CONFIGURATION

OS / ENVIRONMENT

Windows Server 2012 R2
Windows 10

STEPS TO REPRODUCE

try to use win_acl on a registry key

---

- hosts: windows
  tasks:
    - name: 'Administrators have full control on HKCU:\Environment'
      win_acl:
        path: 'HKCU:\Environment'
        user: Administrators
        type: allow
        rights: FullControl
        inherit: ContainerInherit,ObjectInherit
        propagation: None
        state: present
EXPECTED RESULTS

expected to get "ok" or "changed"

ACTUAL RESULTS
Using module file /home/admin/ansible/lib/ansible/modules/windows/win_acl.ps1
Pipelining is enabled.
<192.168.101.103> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5985 TO 192.168.101.103
EXEC (via pipeline wrapper)
fatal: [testhost]: FAILED! => {
    "changed": false,
    "msg": "an error occurred when attempting to present FullControl permission(s) on HKCU:\\Environment for Administrators - Cannot find path 'HKEY_CURRENT_USER\\Environment' because it does not exist."
}

PLAY RECAP *******************************************************************************************************************************************************
testhost            : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

@mhunsber
Copy link
Contributor Author

mhunsber commented Mar 25, 2019

If I change win_acl.ps1 lines 130-136 to the following, it behaves as expected, but I don't know if this is a better approach than just using -Path because it feels like a hack.

    If ($path -match "^HK(CC|CR|CU|LM|U):\\") {
        $objACE = New-Object System.Security.AccessControl.RegistryAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
        Set-Location -LiteralPath $Matches[0]
        $objACL = Get-ACL -LiteralPath $path
    }
    Else {
        $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
        $objACL = Get-ACL -LiteralPath $path
    }

I also opened a bug report in PowerShell here, since I wasn't able to find any references to the problem elsewhere, but I tried it on several different machines and got the same results

@ansibot
Copy link
Contributor

ansibot commented Mar 25, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. windows Windows community labels Mar 25, 2019
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Mar 26, 2019
@jborean93
Copy link
Contributor

@mhunsber thanks for finding this bug, should have a fix relatively shortly.

@jborean93
Copy link
Contributor

@mhunsber here is a PR to fix your issue #54427. If you have time to review it, that would be great.

@mhunsber
Copy link
Contributor Author

@jborean93 looks good, I tested with the changes in my instance and it worked.
I did not know about Push-Location and Pop-Location, so that was nice to learn today.

@jborean93
Copy link
Contributor

Thanks for the confirmation, it honestly shouldn't be needed but it's nice to cleanup after yourself and Push/Pop makes that quite simple.

@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. windows Windows community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants