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

Can't set perms for APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES #9

Open
tehsuk opened this issue Mar 7, 2018 · 3 comments

Comments

@tehsuk
Copy link

tehsuk commented Mar 7, 2018

Sample config:

Configuration TestAppPackagePerms
{
    Import-DscResource -ModuleName "cNtfsAccessControl"
    Import-DscResource -ModuleName "PSDesiredStateConfiguration"
	File CreateTestFolder
	{
		Type = "Directory"
		DestinationPath = "C:\Program Files\Test"
		Ensure = "Present"
	}

	cNtfsPermissionsInheritance DisableInheritOnProgramFilesTest
	{
		Path = "C:\Program Files\Test"
		Enabled = $false
		PreserveInherited = $false
		DependsOn = "[File]CreateTestFolder"
	}

	cNtfsPermissionEntry SetPermsOnCTestForApplicationPackageAuthority
	{
		Ensure = "Present"
		Path = "C:\Program Files\Test"
		# For Principal, same results using the following:
		# "ALL APPLICATION PACKAGES"
		# "S-1-15-2-1"
		Principal = "APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES" 
		AccessControlInformation = @(
			cNtfsAccessControlInformation
			{
				AccessControlType = "Allow"
				FileSystemRights = "ReadAndExecute"
				Inheritance = "ThisFolderSubfoldersAndFiles"
			}
        )
        DependsOn = "[cNtfsPermissionsInheritance]DisableInheritOnProgramFilesTest"
	}
}

TestAppPackagePerms -Verbose
Start-DscConfiguration -Path .\TestAppPackagePerms -Wait -Verbose -Force

Result:

VERBOSE: [SERVER]: LCM:  [ Start  Resource ]  [[cNtfsPermissionEntry]SetPermsOnCTestForApplicationPackageAuthority]
VERBOSE: [SERVER]: LCM:  [ Start  Test     ]  [[cNtfsPermissionEntry]SetPermsOnCTestForApplicationPackageAuthority]
VERBOSE: [SERVER]:                            [[cNtfsPermissionEntry]SetPermsOnCTestForApplicationPackageAuthority] Ensure                   : 'Present'
VERBOSE: [SERVER]:                            [[cNtfsPermissionEntry]SetPermsOnCTestForApplicationPackageAuthority] Path                     : 'C:\Program Files\Test'
VERBOSE: [SERVER]:                            [[cNtfsPermissionEntry]SetPermsOnCTestForApplicationPackageAuthority] Principal                : 'APPLICATION PACKAGE AU
THORITY\ALL APPLICATION PACKAGES'
VERBOSE: [SERVER]:                            [[cNtfsPermissionEntry]SetPermsOnCTestForApplicationPackageAuthority] AccessControlInformation : 'cNtfsAccessControlInfo
rmation'
VERBOSE: [SERVER]:                            [[cNtfsPermissionEntry]SetPermsOnCTestForApplicationPackageAuthority] Verbose                  : 'True'
VERBOSE: [SERVER]:                            [[cNtfsPermissionEntry]SetPermsOnCTestForApplicationPackageAuthority] Resolving identity reference 'APPLICATION PACKAGE 
AUTHORITY\ALL APPLICATION PACKAGES'.
VERBOSE: [SERVER]: LCM:  [ End    Test     ]  [[cNtfsPermissionEntry]SetPermsOnCTestForApplicationPackageAuthority]  in 0.0780 seconds.
PowerShell DSC resource cNtfsPermissionEntry  failed to execute Test-TargetResource functionality with error message: The running command stopped because the preference 
variable "ErrorActionPreference" or common parameter is set to Stop: Could not resolve identity reference 'APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES': 
'Exception calling "Translate" with "1" argument(s): "Some or all identity references could not be translated."'. 
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost
 
VERBOSE: [SERVER]: LCM:  [ End    Set      ]
The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost
 
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.8 seconds
`
@SNikalaichyk
Copy link
Contributor

SNikalaichyk commented Mar 7, 2018

Hi, there's a similar issue. And it looks like it's a Win32 API bug. Need to dive deeper.

PowerShell/Win32-OpenSSH#750

The real problem is here:
'APPLICATION PACKAGE AUTHORITY\ALL RESTRICTED APPLICATION PACKAGES'- can't translate fully qualified name. it is a win32 API bug. To workaround, we need to use the shortValue of the IdentityReference
'ALL APPLICATION PACKAGES' exists only on Win2k12 and Win2k16 and 'ALL RESTRICTED APPLICATION PACKAGES' exists only in Win2k16

@tehsuk
Copy link
Author

tehsuk commented Apr 26, 2018

Here is a script resource I'm using to set perms for All Application Packages with paths & rights hardcoded:

Script SetPermissionsOnProgramFilesx86CompanyProgramForApplicationPackageAuthority
        {
            GetScript = {
                Get-ACL -Path "C:\Program Files (x86)\Company\Program"
            }
            TestScript = {
                $PermEntries = (Get-Acl -Path "C:\Program Files (x86)\Company\Program").Access | Where-Object `
                {$_.IdentityReference -eq "APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES"}
                if ($PermEntries) {
                    Foreach ($PermEntry in $PermEntries) {
                        if ($PermEntry.FileSystemRights -eq "ReadAndExecute, Synchronize") {
                            return $true
                        }
                    }
                } else {
                    return $false
                }
            }
            SetScript = {
                $AppPackageSid = New-Object System.Security.Principal.SecurityIdentifier("S-1-15-2-1")
                $FolderACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($AppPackageSid, 'ReadAndExecute', ('ContainerInherit','ObjectInherit'), 'None','Allow')
                $FolderACL = Get-ACL -Path "C:\Program Files (x86)\Company\Program"
                $FolderACL.AddAccessRule($FolderACE)
                Set-ACL -Path "C:\Program Files (x86)\Company\Program" -ACLObject $FolderACL
            }
            DependsOn = "[cNtfsPermissionsInheritance]DisableInheritOnProgramFilesx86EveriNGMSServices"
        }

@SNikalaichyk
Copy link
Contributor

@tehsuk,
Thanks for sharing the snippet. I will look into this problem.

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

No branches or pull requests

2 participants