Discuss Usage of declarative_authorization at Google Groups
There now is a declarative_authorization discussion group at Google Groups. This group is a good place to discuss patterns of using the plugin. Thanks for setting it up, Mike.
There now is a declarative_authorization discussion group at Google Groups. This group is a good place to discuss patterns of using the plugin. Thanks for setting it up, Mike.
No more issue tracking in comments or direct e-mail! To improve the development process and enable more collaborative development, I created a Lighthouse project for declarative_authorization. Please direct all your suggestions and bug reports to there.
With Rails 2.2 around the corner, I decided to implement a scalable testing infrastructure for the declarative_authorization plugin. One great thing to notice at the RailsConf Europe was Ian’s garlic. Though only given as a side note in Ian’s talk on resources_controller, it provides a nice way of keeping your plugin tested against all those Rails versions.
Very easy to set up. Only add to your Rakefile a few lines that run garlic:
if File.directory?(File.join(File.dirname(__FILE__), 'garlic')) require File.join(File.dirname(__FILE__), 'garlic/lib/garlic_tasks') require File.join(File.dirname(__FILE__), 'garlic') end desc "clone the garlic repo (for running ci tasks)" task :get_garlic do sh "git clone git://github.com/ianwhite/garlic.git garlic" end
And define the tasks that garlic should perform for you. In the declarative_authorization case, garlic should retrieve the plugin from the current path and take a few Rails versions as targets. For the test run, garlic just needs to run “rake”. This is the necessary recipe:
garlic do repo 'rails', :url => 'git://github.com/rails/rails' repo 'declarative_authorization', :path => '.' target 'edge' target '2.1-stable', :branch => 'origin/2-1-stable' target '2.2.0-RC1', :tag => 'v2.2.0' all_targets do prepare do plugin 'declarative_authorization', :clone => true end run do cd "vendor/plugins/declarative_authorization" do sh "rake" end end end end
Thus, all that is needed to check my current declarative_authorization branch against all defined Rails versions is
rake get_garlic # just once
rake garlic:allGreat, all declarative_authorization tests pass on 2.2.0-RC1!
All specified targets passed: edge, 2.1-stable, 2.2.0-RC1One of the interesting comments on our RailsConf Europe presentation on declarative_authorization was offered by Timo Hentschel. He stated that on the Rails CRM project with 90 Controllers and 200 Models that he is working on the declarative_authorization approach was simply not viable. Projects of this size are currently not the target of our plugin, though. Currently, we focus on bringing maintainable authorization into small to medium applications. Nevertheless, it is interesting to look into Timo’s points:
I’m in Berlin for RailsConf Europe currently where I’m talking together with Carsten Bormann about implementing application security in Agile development with Rails and announcing declarative_authorization.
Here is our presentation (will only really display nicely on Firefox 3, though, sorry; full window view):
Having looked through quite a few existing Rails authorization plugins, we decided, we were in need of a different approach. Mainly, it was the missing separation of authorization logic from business logic in the evaluated plugins that caused us to implement a new plugin, declarative_authorization.
In our declarative approach, authorization rules are grouped in a policy file, while only privileges are used inside program code to enforce restrictions. We developed for flexibility and simplicity, requiring only very simple statements in rules and program code. So instead of
class ConferenceController < ApplicationController access_control :DEFAULT => [:admin], [:index, :show] => [...], [:edit, :update] => [:admin, :conference_organizer] end cond = permit?([:admin, :conference_organizer]) ? {} : {:published => true} Conference.find(:all, :conditions => cond) <% restrict_to [:admin, :conference_organizer] do %> <%= link_to 'Edit', edit_conference_path(conference) %> <% end %>
with all the authorization logic interweaved with your code, you only need this
class ConferencesController < ApplicationController filter_access_to :all def index @conferences = Conference.with_permissions_to(:read) end end <%= link_to 'Edit', edit_conference_path(conference) if permitted_to? :edit, conference %>
And, separated in one place the authorization rules:
role :guest do has_permission_on :conferences, :to => :read end role :conference_organizer do has_permission_on :conferences, :to => :manage end
So, the same rules are used in enforcing authorization in Model, View and Controller. Also, they are used for Query Rewriting to automatically constrain the retrieved records according to the authorization rules. Thus, you just modify the rules on authorization requirement changes and you can also use the rules to talk to business owners of Agile projects.
For additional information and more examples, refer to the README and the rdoc documentation. Currently, we are using the plugin for an application with fairly complex authorization and it will be taking into production in the next iteration. So, look into it if you have authorization concerns in your application, it’s released under MIT license.
Updated 2008-12-02
There seems to be a consensus to choose restful_authentication as the Rails way of securing the identity of users, at least with local user databases (in contrast to e.g. OpenID authentication). For authorization, i.e. restricting the access rights of users, the situation is different: there are lots of alternatives. This is probably due to the varying requirements that projects have in the case of authorization. While there are lists and surveys of Rails authorization plugins, I was missing an overview that could help in the decision making process of choosing the right plugin for specific requirements.
Here, I tried to examine each plugin according to a few aspects.
A table of the evaluated authorization plugins, roughly sorted by activity:
| Restrictions for | Model | Controller action |
View | Authorization constraints |
Privileges | Complexity | Last activity |
|---|---|---|---|---|---|---|---|
| Authorization | Yes | Yes | No | Yes | No | medium | recently |
| Restrictions based on pseudo natural language sentences; decisions based on role ACLs on models or model instances | |||||||
| declarative_authorization | Yes | Yes | Yes | Yes | Yes | medium | recently |
| Declarative approach: separation of authorization logic from program code for maintainability and as basis for discussions with domain experts (disclaimer: I am the author of this plugin) | |||||||
| Padlock Authorization | Yes | Yes | No | Yes | No | medium | recently |
| Allows for objects to have roles according to specific users. | |||||||
| ActsAsAuthorizable | Yes | No | No | Yes | No | medium | recently |
| Restrictions based on pseudo natural language sentences; decisions based on role ACLs on models or model instances | |||||||
| ActsAsPermissible | Yes | No | No | No | No | medium | recently |
| Provides the basic necessity of authorization: the model methods for assigning permissions and roles to users and retrieving the merged permissions. | |||||||
| Authorize | No | Yes | Yes | No | No | high | recently |
| Has a subject/trustee concept for specifying relationships regarding authorization. | |||||||
| redpill_access_control | No | Yes | Yes | No | No | medium | recently |
| Uses access restrictions to controller actions for restrictions in views. | |||||||
| base_auth | Yes | Yes | Yes | Yes | No | simple | recently |
| User object-based restrictions on controller actions and views | |||||||
| acts_as_checkpoint | Yes | Yes | No | Yes | No | simple | recently |
| Role-based restrictions on controller actions; simple model restrictions through methods on models, employing associations | |||||||
| rolerequirement | No | Yes | No | No | No | simple | recently |
| Role-based ACLs for restrictions on controller actions | |||||||
| RESTful_ACL | Yes | Yes | Yes | Yes | No | simple | recently |
| Restrictions based on permission methods on models for CRUD operations; no role concept built in; seems to be restricted to CRUD controller actions | |||||||
| Role-ful | Yes | No | No | Yes | Yes | medium | recently |
| Defines roles in the user object that can be queried through instance methods. | |||||||
| Blubber | No | Yes | No | No | No | simple | recently |
| Used by defining [role]_acl methods on the controller. | |||||||
| Easy Access | Yes | No | No | Yes | Yes | simple | recently |
| Helps defining can_be_[action]_by on the model. | |||||||
| acl_system2 | No | Yes | Yes | No | No | simple | 2007 |
| Role-based ACLs for restrictions on controller actions and in views; similar: Simple Access Control | |||||||
| ActiveRbac | No | Yes | No | No | Yes | medium | 2007 |
| Implements only the queries on model instances for access rights | |||||||
| access_control | No | Yes | No | No | No | simple | 2007 |
| Simple controller action restrictions based on Unix-style rwx ACLs | |||||||
| UserEngine | No | Yes | No | No | Yes | medium | 2006 |
| Controller/action-based privileges assigned to roles for filtering access to controller actions | |||||||
| ActiveAcl | Yes | No | No | Yes | Yes | high | 2006 |
| Complex database design to allow arbitrary user - role - privilege - object relations | |||||||
Let me know if I missed important aspects of those plugins or other plugins that you like.
Modeling authorization for workflows in Small and Medium Enterprises (SME) differs from the approach taken in large corporations. The latter employ heavy workflow management systems that are deployed by help of immense consulting resources. By contrast, typical SME need to implement fairly straight-forward workflows while preserving a good deal of flexibility that they are used to from the established informal workflows such as passing around spreadsheets.
From our experience in working with an SME to implement their workflows in a web application, modeling the authorization is a crucial factor. While information security is welcomed by the management, measures need to interfere as little as possible with the daily work. Also, domain experts tend to describe ideal workflows, which is sometimes called Process Confabulation. Frequent exceptions may be unknown to developers until late in the development cycle, despite user tests.
Therefore, we propose a new approach to access control, allowing users to decide when to extend their previously defined privileges in a controled manner. Thus, the effect of inacurate definition of process and authorization models is mitigated. This concept of “self-service” is described in detail in the German paper that I wrote together with Carsten Bormann, “Berechtigungsmodellierung im Geschäftsprozessmanagement von KMU” and presented at the DACH Security conference in Berlin.
…so der Arbeitstitel für meine Diplomarbeit. Es geht um das Verteilen von Informationen über vorhandene Internetzugänge für mobile Nutzer. Da tut sich ja gerade eine Menge, und WLAN-Hotspots werden demnächst um weitere Zugangstechniken ergänzt. Wir stellen uns die Zugangsdienste auf einer Karte dargestellt vor, eben als Service Map.
Nachdem ich gut ein halbes Jahr mal mehr mal weniger Intensiv (nebenbei lief noch unser studentisches Projekt) am Thema gebastelt habe, gab es Freitag die (in der AG) obligatorische Vorstellung im Kolloqium der AG Rechnernetze. Natürlich hatte ich viel zu viel auf meinen Folien, als dass es in Ruhe in die 20 Minuten gepasst hätte. Zum Thema Business Case gab es trotzdem sehr interessantes Feedback, hier fehlten einfach noch ein paar wichtige potentielle Mitspieler am Markt.