Grant

24
Grant security plugin for Rails Jeff Kunkle
  • date post

    12-Sep-2014
  • Category

    Technology

  • view

    290
  • download

    6

description

Grant is a Ruby gem and Rails plugin that forces you to make explicit security decisions about the operations performed on your ActiveRecord models. It provides a declarative way to specify rules granting permission to perform CRUD operations on ActiveRecord objects. This presentation covers the basic usage of Grant, highlighting a few of the features that make it different from other solutions available.

Transcript of Grant

Page 1: Grant

Grantsecurity plugin for Rails

Jeff Kunkle

Page 2: Grant

Leveraging Ruby’s Open Classes and

Metaprogramming Capabilities, Combined with Active Record Features to

Develop a Security Plugin for Ruby on Rails

Jeff Kunkle

Page 3: Grant

class EmployeesController < ApplicationControllerbefore_filter :authorize, :if => :update

def list@employees = Employee.all

end

def updateemp = Employee.find params[:id]emp.update_attributes params[:employee]

endend

Page 4: Grant

class EmployeesController < ApplicationControllerbefore_filter :authorize, :if => :update

def list@employees = Employee.all

end

def updateemp = Employee.find params[:id]emp.update_attributes params[:employee]

endend

class EmployeesController < ApplicationController

def list@employees = Employee.all

end

def updateif user.has_role?(:manager)emp = Employee.find params[:id]emp.update_attributes params[:employee]

endend

end

Page 5: Grant

video from http://railscasts.com

Page 6: Grant

video from http://railscasts.com

Page 7: Grant
Page 8: Grant
Page 9: Grant

Is my app secure?

Page 10: Grant
Page 11: Grant

class EmployeesController < ApplicationController

def list@employees = Employee.all

end

def updateif user.has_role?(:manager)emp = Employee.find params[:id]emp.update_attributes params[:employee]

endend

end

Page 12: Grant

class Employee < ActiveRecord::Baseinclude Grant::ModelSecurity

grant(:update) { |user, model| user.has_role?(:manager) }

end

Page 13: Grant

class Employee < ActiveRecord::Baseinclude Grant::ModelSecurity

grant(:update) { |user, model| user.has_role?(:manager) }

end

class EmployeesController < ApplicationController

def list@employees = Employee.all

end

def updateemp = Employee.find params[:id]emp.update_attributes params[:employee]

endend

Page 14: Grant

Quiz

Page 15: Grant

Quizclass Employee < ActiveRecord::Baseinclude Grant::ModelSecuritygrant(:update) { |user, model| user.has_role?(:manager) }

end

Page 16: Grant

class User < ActiveRecord::Basedef has_role?(role)[:employee, :manager].include?(role)

end end

Quizclass Employee < ActiveRecord::Baseinclude Grant::ModelSecuritygrant(:update) { |user, model| user.has_role?(:manager) }

end

Page 17: Grant

class User < ActiveRecord::Basedef has_role?(role)[:employee, :manager].include?(role)

end end

Quiz

class EmployeesController < ApplicationControllerdef updateemp = Employee.find params[:id]emp.update_attributes params[:employee]

endend

class Employee < ActiveRecord::Baseinclude Grant::ModelSecuritygrant(:update) { |user, model| user.has_role?(:manager) }

end

?

Page 18: Grant

Grant::ModelSecurityError: find permission not granted to User:7 for resource Employee:25

from /Users/jkunkle/project/vendor/plugins/grant/lib/grant/model_security_manager.rb:75:in `permission_not_granted' from /Users/jkunkle/project/vendor/plugins/grant/lib/grant/model_security_manager.rb:60:in `apply_security' from /Users/jkunkle/project/vendor/plugins/grant/lib/grant/model_security_manager.rb:44:in `after_find'

Page 19: Grant

class Employee < ActiveRecord::Baseinclude Grant::ModelSecurity

grant(:find)grant(:destroy) { |user, model| user.has_role?(:admin) }grant(:update, :create) do |user, model| user.has_role?(:manager)

end

end

Grant is all or nothing

Page 20: Grant

class Employee < ActiveRecord::Baseinclude Grant::ModelSecurity

has_many :reviews

grant(:find)grant(:destroy) { |user, model| user.has_role?(:admin) }grant(:update, :create) do |user, model| user.has_role?(:manager)

endgrant(:add => :reviews, :remove => :reviews) do |user, model| user.has_role?(:manager)

end

end

... associations too

Page 21: Grant

How does it work?Hook methodsDynamic MethodsActive Record CallbacksAround Aliases

Page 22: Grant

Show and Tell

Page 23: Grant

Show and Tell.. and answer lots of questions

Page 24: Grant

GrantSecurity Anxiety Relief

http://github.com/nearinfinity/grant