Repository navigation
fix: don't wipe policy_grants and drop_trigger_grants on a rejected value - #279
utkarash2991 wants to merge 2 commits into
Conversation
…alue The check hooks freed the live arrays and parsed the new value into them before validating it. A bad value left the backend without grants until the next good reload, leaked the partial entries in TopMemoryContext and kept a stale table count on the half parsed slot, so a later valid value for that role was rejected too. Parse into a scratch array in the check hook and load the live arrays from a new assign hook, same shape as extensions_parameter_overrides.
imor
left a comment
There was a problem hiding this comment.
Left just one minor comment to improve tests, otherwise LGTM.
| alter system set supautils.policy_grants to '{"stale_role": ["public.table_1"]}'; | ||
| alter system reset supautils.policy_grants; | ||
| \echo | ||
|
|
There was a problem hiding this comment.
Can the tests be improved by using a show supautils.<guc> command in the output which would make it clear whether the change took effect or not instead of indirectly exercising the effect of those changes?
| clear_policy_grants_array(pgs, MAX_POLICY_GRANTS); | ||
| total_pgs = 0; | ||
|
|
There was a problem hiding this comment.
What happens if there is an error i.e for example run out of memory halfway through loading the new grants? We’ve already cleared the old grants, and the new list is left in partial state. Could we keep the old grants in place until the new list is ready? Same comment applies to drop_trigger_grants as well.
There was a problem hiding this comment.
Agreed. Assign hooks are not meant to fail, but there is no reason to leave a half-loaded array if one does. Going to take care in next revision
| grant usage on schema allow_policies to grants_role; | ||
| alter system set supautils.policy_grants to '{"grants_role": ["allow_policies.my_table"], "oops": 1}'; | ||
| ERROR: supautils.policy_grants: unexpected scalar, expected an array | ||
| alter system set supautils.policy_grants to '{"grants_role": ["allow_policies.other_table"]}'; |
There was a problem hiding this comment.
should we add create policy statement for other_table to confirm the desired behaviour after policy creation for my_table is denied.
There was a problem hiding this comment.
added a test case in next revision
…w and reload tests The assign hooks now parse into a scratch array and only then replace the live one, so a failure halfway leaves the old grants in place. Tests show the GUC after a rejected value, and a new case reloads the config to check the accepted value is the one enforced.
Fixes #213.
The check hooks for
policy_grantsanddrop_trigger_grantsfreed the live arrays and parsed the new value into them before validating it. If the value was bad, Postgres kept the old string but supautils had already lost the parsed grants. In that backendshowstill printed the old JSON, yetprivileged_rolecould no longer create policies or drop triggers until the next good reload. The partially parsed entries also leaked inTopMemoryContext, and a slot left half parsed kept its table count, so a later valid value for the same role failed with "too many policy grant tables specified".Fix: the check hook parses into a scratch array and throws it away. A new assign hook, same shape as
extensions_parameter_overrides, clears every slot and loads the live arrays.