User tests: Successful: Unsuccessful:
Joomla Tracker: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=30550 (submitted for both Joomla 2.5 and 4)
There is currently no easy way to specify the default action permission rules
for a component that has component-specific custom permission rules. If
component developers want default ACL rules for their custom ACL rules, they
must create code that modifies the root asset. This is extra work for
component developers and a potential source of errors and problems.
The proposed fix addresses this problem by extending the syntax of component
'access.xml' file that lists the component-specific ACL rules. The goal is to
allow the component developer to specify the groups that should be allowed to
perform the ACL action as part of the XML definition for each ACL rule. This
would require updates to Joomla (the platform) to interpret the additions to
the 'access.xml' and add the appropriate permissions to the system.
The proposed function provides new functions to install or remove the default
permissions specified in the 'access.xml' file. Normally this would be done
in by the installer by having the component installer call the new function
during installation. In the following description, assume the new function is
called by the installer.
These additions will be backwards compatible since the additional XML
attributes will be ignored by versions of Joomla that have not implemented
this fix.
Since there are many different ways that a particular component can implement
ACL rules, a few guiding principles are necessary:
The following syntax change is proposed. In the following examples, the
component for the 'access.xml' file is 'com_example':
Notice the new 'default' attribute at the end. The groups will be searched to
find the least authoritative group that has the 'core.delete' permission for
com_content (for instance, delete example items they created). This will mean
that all derived groups also have this permission.
Note that this could be a comma-separated list of group names.
The component developer could also specify a hint on which group to check
first:
In this case, the installer would first check to see if the 'Author' group has
the required permission. If it does, it would be used. If not, no warning
message would be given and the search for a group with that permission would
continue.
Note that the test component could be something other than 'com_content':
Which would find a group that has permission to do 'core.delete' for the
'com_xyz123' component. This could be used to synchronize default permissions
between two related components.
A test component 'com_permtest' is available on github:
https://github.com/jmcameron/component_permissions_test
This includes a zipped up version of the component that is ready to install.
comp_permtest.zip
This test component should work on both Joomla 2.5.x and 3.x. Obviously the
functions will not do anything if the fixes to Joomla described here are not
implemented.
To try these fixes:
Note that these fixes include unit tests for the new capabilities (on the
Joomal 3.x version). See the bottom of the this document.
The functionality above is implemented by adding functions to JAccess and
JRules:
JRules::removeActions($action_regexp)
JAccess::getGroupId($groupname)
JAccess::removeDescendentGroups($groupIds)
JAccess::leastAuthoritativeGroup($groupIds, $asset)
JAccess::installComponentDefaultRules($component, $file = null)
JAccess::purgeComponentDefaultRules($component)
Jonathan Cameron
April 28, 2013
Hi Elin,
I was aware of the issue of unknown/deleted groups on installed system. So the code will ignore groups that it cannot find on the target system. But you bring up a good point about groups that are shifted around.
I'm willing to update/extend how this works. So you are suggesting something like finding a group that has permission to perform the action on articles (com_content). I'll have to think about how to represent that in the default information in the access.xml files. Perhaps just:
default="com_content:core.create"
Then it would have to find a group that has that permission so it can update the root asset appropriately.
-Jonahtan
To me that would be very very useful and more powerful.
Elin
On Thu, Apr 18, 2013 at 12:06 AM, Jonathan Cameron <notifications@github.com
wrote:
Hi Elin,
I was aware of the issue of unknown/deleted groups on installed system. So
the code will ignore groups that it cannot find on the target system. But
you bring up a good point about groups that are shifted around.
I'm willing to update/extend how this works. So you are suggesting
something like finding a group that has permission to perform the action on
articles (com_content). I'll have to think about how to represent that in
the default information in the access.xml files. Perhaps just:default="com_content:core.create"
Then it would have to find a group that has that permission so it can
update the root asset appropriately.-Jonahtan
—
Reply to this email directly or view it on GitHub#976 (comment)
.
Ok, I'll work on it. What should it doe if it cannot find a group with the required permission?
-Jonathan
Here is what I'm going to work on (unless I hear complaints):
defaults="com_content:core_create[Author]"
So this enables the permission for the rule involved if it can find a group that perform 'core_create' for the 'com_content' component. The optional 'Author' in brackets at the end is a hint of what group try first. It will check to see if that group has the required permission. If so, it will use it. If not, it will search through the groups to find all groups that have the desired permission and then select the one that is the least privileged (closest to the root group).
-Jonathan
P.S. @sanderpotjer You may want to let me finish this update before you test this.
I am working on refactoring this and will do a new pull request or re-open this one when I'm ready.
-Jonathan
Completed refactoring this to accept the changed syntax for the defaults discussed above. Updated documentation for the issue and fix above. To see the old documentation see the files attached to the joomlacode tracker page http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=30550 (See DefaultPermissions-OLD.pdf). The new documentation above is also in the updated DefaultPermissions-VERSION2.pdf on the tracker page. The tracker page also includes new patch files and test component zip file.
Re-opening pull request.
Title |
|
Description | <h1>Default Component ACL Rules</h1> <p>Joomla Tracker: <a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=30550">http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=30550</a> (submitted for both Joomla 2.5 and 4)</p> <h2>Background / Motivation</h2> <p>There is currently no easy way to specify the default action permission rules<br> for a component that has component-specific custom permission rules. If<br> component developers want default ACL rules for their custom ACL rules, they<br> must create code that modifies the root asset. This is extra work for<br> component developers and a potential source of errors and problems.</p> <h2>Proposed Fix</h2> <p>The proposed fix addresses this problem by extending the syntax of component<br> 'access.xml' file that lists the component-specific ACL rules. The goal is to<br> allow the component developer to specify the groups that should be allowed to<br> perform the ACL action as part of the XML definition for each ACL rule. This<br> would require updates to Joomla (the platform) to interpret the additions to<br> the 'access.xml' and add the appropriate permissions to the system. </p> <p>The proposed function provides new functions to install or remove the default<br> permissions specified in the 'access.xml' file. Normally this would be done<br> in by the installer by having the component installer call the new function<br> during installation. In the following description, assume the new function is<br> called by the installer.</p> <p>These additions will be backwards compatible since the additional XML<br> attributes will be ignored by versions of Joomla that have not implemented<br> this fix.</p> <p>Since there are many different ways that a particular component can implement<br> ACL rules, a few guiding principles are necessary:</p> <ol> <li><p>If the default for a custom ACL rule is not specified, the default root<br> ACL rules will not be modified. This is the current behavior.</p></li> <li><p>If the group with the specified permssions in the default rules does not<br> exist in the Joomla installation, no root permission will be set and an<br> information message will be generated. Some Joomla installations have<br> been known to delete all common groups (such as Public, Registered) and<br> create new groups. So there is no guarantee that normally expected groups<br> will exist.</p></li> <li><p>The component developer will specify a component (usually com_content)<br> and an action to check and the installer will find a group with that<br> permission. The component developer may give a suggestion for which<br> group to check first. If the group is found and has the required<br> permissions, then it will be used. Otherwise the installer will search<br> for a suitable group with the required permissions. All groups will be<br> checked and the one with the least authority will be used (eg, if both<br> Author and Publisher have the required permission, Author will be chosen<br> since Publisher has more authority).</p></li> <li><p>This new feature would only be applied to any custom component-specific<br> rule in a components 'access.xml'. This approach cannot be used to<br> modify the core rules in the root rule.</p></li> </ol><h2>Example 'access.xml' syntax additions</h2> <p>The following syntax change is proposed. In the following examples, the<br> component for the 'access.xml' file is 'com_example':</p> <div class="highlight highlight-xml"><pre><span class="nt"><action</span> <span class="na">name=</span><span class="s">"example.delete.own"</span> <span class="na">title=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN"</span> <span class="na">description=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN_DESC"</span> <span class="na">default=</span><span class="s">"com_content:core.delete"</span> <span class="nt">/></span> </pre></div> <p>Notice the new 'default' attribute at the end. The groups will be searched to<br> find the least authoritative group that has the 'core.delete' permission for<br> com_content (for instance, delete example items they created). This will mean<br> that all derived groups also have this permission.</p> <p>Note that this could be a comma-separated list of group names.</p> <p>The component developer could also specify a hint on which group to check<br> first:</p> <div class="highlight highlight-xml"><pre><span class="nt"><action</span> <span class="na">name=</span><span class="s">"example.delete.own"</span> <span class="na">title=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN"</span> <span class="na">description=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN_DESC"</span> <span class="na">default=</span><span class="s">"com_content:core.delete[Author]"</span> <span class="nt">/></span> </pre></div> <p>In this case, the installer would first check to see if the 'Author' group has<br> the required permission. If it does, it would be used. If not, no warning<br> message would be given and the search for a group with that permission would<br> continue.</p> <p>Note that the test component could be something other than 'com_content':</p> <div class="highlight highlight-xml"><pre><span class="nt"><action</span> <span class="na">name=</span><span class="s">"example.delete.own"</span> <span class="na">title=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN"</span> <span class="na">description=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN_DESC"</span> <span class="na">default=</span><span class="s">"com_xyz123:core.delete"</span> <span class="nt">/></span> </pre></div> <p>Which would find a group that has permission to do 'core.delete' for the<br> 'com_xyz123' component. This could be used to synchronize default permissions<br> between two related components.</p> <h2>Testing the new functionality</h2> <p>A test component 'com_permtest' is available on github:</p> <p><a href="https://github.com/jmcameron/component_permissions_test">https://github.com/jmcameron/component_permissions_test</a></p> <p>This includes a zipped up version of the component that is ready to install.</p> <p>comp_permtest.zip</p> <p>This test component should work on both Joomla 2.5.x and 3.x. Obviously the<br> functions will not do anything if the fixes to Joomla described here are not<br> implemented.</p> <p>To try these fixes:</p> <ul> <li><p>Install the fixes on your Joomla 2.5 or 3.x site (by doing 'git pull' or<br> using a patch file)</p></li> <li><p>Install the component in the regular way and then go to the<br> 'component-permissions-test' component under the 'Components' menu in the<br> back end.</p></li> <li><p>Read the instructions there on how to test it.</p></li> </ul><p>Note that these fixes include unit tests for the new capabilities (on the<br> Joomal 3.x version). See the bottom of the this document.</p> <h2>Implementation Notes</h2> <p>The functionality above is implemented by adding functions to JAccess and<br> JRules:</p> <p><strong>JRules::removeActions($action_regexp)</strong></p> <ul> <li>Remove all actions from the rule whose action name matches the regular expression. This a general function and could be used to remove core actions from the root rule, if the calling code requested it (not recommended).</li> </ul><p><strong>JAccess::getGroupId($groupname)</strong></p> <ul> <li><p>Returns a group ID for the given group name.</p></li> <li><p>This could be moved elsewhere, but there did not seem to be a suitable<br> place. We may want to add a JUserGroup class (in<br> libraries/joomla/user/group.php) and move this function into that class.</p></li> </ul><p><strong>JAccess::removeDescendentGroups($groupIds)</strong></p> <ul> <li>Removes all groups in the provided set of groups that have ancestors in the set of groups. This is part of the code that helps select the least authoritative group since it eliminates children of groups that are already in the set since the child group is likely to have more permissions than its parent group.</li> </ul><p><strong>JAccess::leastAuthoritativeGroup($groupIds, $asset)</strong></p> <ul> <li>Selects the least authoritative group out of a set of groups.<br> Read the code for a clearer idea of how this works.</li> </ul><p><strong>JAccess::installComponentDefaultRules($component, $file = null)</strong></p> <ul> <li><p>Parse the rules for custom rules in component's 'access.xml' file and<br> install new permissions in the root asset, as needed.</p></li> <li><p>Does not allow modifying core rules.</p></li> <li><p>If a group with the required permission is not found or the group name<br> specified in the hint part is unknown by the Joomla installation, the<br> default specified will be ignored. Currently a log message is being added.<br> This should probably be a JApplication::enqueueMessage() call but I could<br> not get that to work in the unit tests.</p></li> <li><p>This function can be called any time, but it would make sense to call this<br> during component installation in the postflight section.</p></li> <li><p>The optional $file can be used to specify an alternate location for the<br> 'acess.xml' file (for testing).</p></li> </ul><p><strong>JAccess::purgeComponentDefaultRules($component)</strong></p> <ul> <li><p>Removes all custom rules for $component defined in the root asset.</p></li> <li><p>Core rules will not be modified.</p></li> <li><p>This function can be called at any time, but it would make sense to call<br> this during the uninstallation of a component (during preflight or the<br> uninstall function).</p></li> </ul><h2>Unit tests</h2> <ul> <li><p>Unit tests for Joomla 3 that cover the features above have been added to<br> the <em>tests/unit/suites/libraries/access</em> folder.</p></li> <li><p>The custom unit test configuration file<br><strong>tests/system/servers/configdef.php</strong> was added to the toplevel .gitignore<br> since it could contain private data and should be ignored (like .gitignore<br> already ignores the top-level phpunit config file <strong>phpunit.xml</strong>).</p></li> </ul><p>Jonathan Cameron<br><br> April 28, 2013</p> | ⇒ | <h1>Default Component ACL Rules</h1> <p>Joomla Tracker: <a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=30550">http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=30550</a> (submitted for both Joomla 2.5 and 4)</p> <h2>Background / Motivation</h2> <p>There is currently no easy way to specify the default action permission rules<br> for a component that has component-specific custom permission rules. If<br> component developers want default ACL rules for their custom ACL rules, they<br> must create code that modifies the root asset. This is extra work for<br> component developers and a potential source of errors and problems.</p> <h2>Proposed Fix</h2> <p>The proposed fix addresses this problem by extending the syntax of component<br> 'access.xml' file that lists the component-specific ACL rules. The goal is to<br> allow the component developer to specify the groups that should be allowed to<br> perform the ACL action as part of the XML definition for each ACL rule. This<br> would require updates to Joomla (the platform) to interpret the additions to<br> the 'access.xml' and add the appropriate permissions to the system. </p> <p>The proposed function provides new functions to install or remove the default<br> permissions specified in the 'access.xml' file. Normally this would be done<br> in by the installer by having the component installer call the new function<br> during installation. In the following description, assume the new function is<br> called by the installer.</p> <p>These additions will be backwards compatible since the additional XML<br> attributes will be ignored by versions of Joomla that have not implemented<br> this fix.</p> <p>Since there are many different ways that a particular component can implement<br> ACL rules, a few guiding principles are necessary:</p> <ol class="task-list"> <li><p>If the default for a custom ACL rule is not specified, the default root<br> ACL rules will not be modified. This is the current behavior.</p></li> <li><p>If the group with the specified permssions in the default rules does not<br> exist in the Joomla installation, no root permission will be set and an<br> information message will be generated. Some Joomla installations have<br> been known to delete all common groups (such as Public, Registered) and<br> create new groups. So there is no guarantee that normally expected groups<br> will exist.</p></li> <li><p>The component developer will specify a component (usually com_content)<br> and an action to check and the installer will find a group with that<br> permission. The component developer may give a suggestion for which<br> group to check first. If the group is found and has the required<br> permissions, then it will be used. Otherwise the installer will search<br> for a suitable group with the required permissions. All groups will be<br> checked and the one with the least authority will be used (eg, if both<br> Author and Publisher have the required permission, Author will be chosen<br> since Publisher has more authority).</p></li> <li><p>This new feature would only be applied to any custom component-specific<br> rule in a components 'access.xml'. This approach cannot be used to<br> modify the core rules in the root rule.</p></li> </ol><h2>Example 'access.xml' syntax additions</h2> <p>The following syntax change is proposed. In the following examples, the<br> component for the 'access.xml' file is 'com_example':</p> <div class="highlight highlight-xml"><pre><span class="nt"><action</span> <span class="na">name=</span><span class="s">"example.delete.own"</span> <span class="na">title=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN"</span> <span class="na">description=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN_DESC"</span> <span class="na">default=</span><span class="s">"com_content:core.delete"</span> <span class="nt">/></span> </pre></div> <p>Notice the new 'default' attribute at the end. The groups will be searched to<br> find the least authoritative group that has the 'core.delete' permission for<br> com_content (for instance, delete example items they created). This will mean<br> that all derived groups also have this permission.</p> <p>Note that this could be a comma-separated list of group names.</p> <p>The component developer could also specify a hint on which group to check<br> first:</p> <div class="highlight highlight-xml"><pre><span class="nt"><action</span> <span class="na">name=</span><span class="s">"example.delete.own"</span> <span class="na">title=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN"</span> <span class="na">description=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN_DESC"</span> <span class="na">default=</span><span class="s">"com_content:core.delete[Author]"</span> <span class="nt">/></span> </pre></div> <p>In this case, the installer would first check to see if the 'Author' group has<br> the required permission. If it does, it would be used. If not, no warning<br> message would be given and the search for a group with that permission would<br> continue.</p> <p>Note that the test component could be something other than 'com_content':</p> <div class="highlight highlight-xml"><pre><span class="nt"><action</span> <span class="na">name=</span><span class="s">"example.delete.own"</span> <span class="na">title=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN"</span> <span class="na">description=</span><span class="s">"COM_EXAMPLE_PERMISSION_DELETEOWN_DESC"</span> <span class="na">default=</span><span class="s">"com_xyz123:core.delete"</span> <span class="nt">/></span> </pre></div> <p>Which would find a group that has permission to do 'core.delete' for the<br> 'com_xyz123' component. This could be used to synchronize default permissions<br> between two related components.</p> <h2>Testing the new functionality</h2> <p>A test component 'com_permtest' is available on github:</p> <p><a href="https://github.com/jmcameron/component_permissions_test">https://github.com/jmcameron/component_permissions_test</a></p> <p>This includes a zipped up version of the component that is ready to install.</p> <p>comp_permtest.zip</p> <p>This test component should work on both Joomla 2.5.x and 3.x. Obviously the<br> functions will not do anything if the fixes to Joomla described here are not<br> implemented.</p> <p>To try these fixes:</p> <ul class="task-list"> <li><p>Install the fixes on your Joomla 2.5 or 3.x site (by doing 'git pull' or<br> using a patch file)</p></li> <li><p>Install the component in the regular way and then go to the<br> 'component-permissions-test' component under the 'Components' menu in the<br> back end.</p></li> <li><p>Read the instructions there on how to test it.</p></li> </ul><p>Note that these fixes include unit tests for the new capabilities (on the<br> Joomal 3.x version). See the bottom of the this document.</p> <h2>Implementation Notes</h2> <p>The functionality above is implemented by adding functions to JAccess and<br> JRules:</p> <p><strong>JRules::removeActions($action_regexp)</strong></p> <ul class="task-list"> <li>Remove all actions from the rule whose action name matches the regular expression. This a general function and could be used to remove core actions from the root rule, if the calling code requested it (not recommended).</li> </ul><p><strong>JAccess::getGroupId($groupname)</strong></p> <ul class="task-list"> <li><p>Returns a group ID for the given group name.</p></li> <li><p>This could be moved elsewhere, but there did not seem to be a suitable<br> place. We may want to add a JUserGroup class (in<br> libraries/joomla/user/group.php) and move this function into that class.</p></li> </ul><p><strong>JAccess::removeDescendentGroups($groupIds)</strong></p> <ul class="task-list"> <li>Removes all groups in the provided set of groups that have ancestors in the set of groups. This is part of the code that helps select the least authoritative group since it eliminates children of groups that are already in the set since the child group is likely to have more permissions than its parent group.</li> </ul><p><strong>JAccess::leastAuthoritativeGroup($groupIds, $asset)</strong></p> <ul class="task-list"> <li>Selects the least authoritative group out of a set of groups.<br> Read the code for a clearer idea of how this works.</li> </ul><p><strong>JAccess::installComponentDefaultRules($component, $file = null)</strong></p> <ul class="task-list"> <li><p>Parse the rules for custom rules in component's 'access.xml' file and<br> install new permissions in the root asset, as needed.</p></li> <li><p>Does not allow modifying core rules.</p></li> <li><p>If a group with the required permission is not found or the group name<br> specified in the hint part is unknown by the Joomla installation, the<br> default specified will be ignored. Currently a log message is being added.<br> This should probably be a JApplication::enqueueMessage() call but I could<br> not get that to work in the unit tests.</p></li> <li><p>This function can be called any time, but it would make sense to call this<br> during component installation in the postflight section.</p></li> <li><p>The optional $file can be used to specify an alternate location for the<br> 'acess.xml' file (for testing).</p></li> </ul><p><strong>JAccess::purgeComponentDefaultRules($component)</strong></p> <ul class="task-list"> <li><p>Removes all custom rules for $component defined in the root asset.</p></li> <li><p>Core rules will not be modified.</p></li> <li><p>This function can be called at any time, but it would make sense to call<br> this during the uninstallation of a component (during preflight or the<br> uninstall function).</p></li> </ul><h2>Unit tests</h2> <ul class="task-list"> <li><p>Unit tests for Joomla 3 that cover the features above have been added to<br> the <em>tests/unit/suites/libraries/access</em> folder.</p></li> <li><p>The custom unit test configuration file<br><strong>tests/system/servers/configdef.php</strong> was added to the toplevel .gitignore<br> since it could contain private data and should be ignored (like .gitignore<br> already ignores the top-level phpunit config file <strong>phpunit.xml</strong>).</p></li> </ul><p>Jonathan Cameron<br><br> April 28, 2013</p> |
Labels |
Added:
?
|
Status | New | ⇒ | Pending |
Labels |
Removed:
?
|
Category | ⇒ | ACL |
Are we still accepting new features for 2.5
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/976.
Status | Pending | ⇒ | Needs Review |
I put up this proposal about a year and half ago. I still think it is a good idea, but it got no traction. I think you're right that it is too late for Joomla 2.5. So I'm fine with closing this pull request.
-Jonathan
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/976.
Hi Jonathan,
Unfortunately, we're not able to accept features for 2.5 anymore. However, we still have #975 for Joomla 3. Let's close this one and focus our efforts on #975 (though it will receive a new number once it's submitted toward the staging branch instead).
Thanks for you patience, Jonathan! I'll do my best to get someone to look at the J3 feature proposal during tomorrow's PBF.
Status | Needs Review | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-10-17 03:02:30 |
How would a developer know what groups exist on a given site? A user may have deleted or renamed all of them or simply redefined what they mean.
Would it make more sense to do this by referring to the specific action/items i.e say make anyone who has create permission for articles also have create permission for this component by default?