-
Notifications
You must be signed in to change notification settings - Fork 225
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
SqlDatabaseObjectPermission: INSERT permission never shows as InDesiredState when other permissions are on the table #2006
Comments
Thanks for submitting this issue and the detailed run down. Your suggested fix looks good. Do you have time to send in a PR with the fix? |
@johlju I created a pull request. I was able to test in my environment, and that seemed to work, but if you have access to a more robust testing environment, by all means, I'd love some additional eyes on it. I also added an Insert permission object in the unit test. Let me know if that was not appropriate/needed, and I can remove it. The other tasks in the Task List didn't seem appropriate here, but let me know if you disagree and I can make further updates. |
Looks good, I made a review and would be great to change the mock according to my comment. |
@johlju Fixed the mock and got the unit tests to pass |
) - SqlDatabaseObjectPermission - Added `foreach` loop in `Get-TargetResource` to fix issues with `INSERT` permissions when it's not the only permission on the table (issue #2006).
Problem description
When you are only granting INSERT permissions on a table, if INSERT is the only permission on the table, everything works as expected. However, when there are permissions on the table other than INSERT (such as SELECT/GRANT/UPDATE), the testing of the resource will always show
InDesiredState = False
Here is a screenshot showing with just INSERT it works as expected:
Here is a screenshot showing that even though both the DELETE and INSERT permissions have been set, it's stating that the permissions are not in a desired state:
I believe it has something to do with this line in the code.
if ($true -in $currentObjectPermissions.PermissionType.$currentPermissionProperty)
If I test that code outside of this module, we see that the
if ($true -in $currentObjectPermissions.PermissionType.$currentPermissionProperty)
block doesn't actually work with INSERTPulling the
if
block test out by itself, we get:And looking at just
CurrentObjectPermissions.PermissionType.Insert
we get the following:Verbose logs
DSC configuration
Suggested solution
My proposed solution is this:
If we wrap the
if ($true -in $currentObjectPermissions.PermissionType.$currentPermissionProperty)
block in it's own foreach loop, then it seems to work.This is because when you have multiple permissions, the
$currentObjectPermissions
is an array and has theInsert
as anIList
method.But if you look at an individual item in the array, then the
Insert
is actually a property as expectedSQL Server edition and version
SQL Server PowerShell modules
Operating system
PowerShell version
SqlServerDsc version
The text was updated successfully, but these errors were encountered: