SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Grant
security plugin for Rails




                            Jeff Kunkle
Leveraging Ruby’s Open
        Classes and
     Metaprogramming
Capabilities, Combined with
 Active Record Features to
Develop a Security Plugin for
       Ruby on Rails
                         Jeff Kunkle
class EmployeesController < ApplicationController
  before_filter :authorize, :if => :update

 def list
   @employees = Employee.all
 end

  def update
    emp = Employee.find params[:id]
    emp.update_attributes params[:employee]
  end
end
class EmployeesController < ApplicationController

                          def list
                            @employees = Employee.all
                          end

                           def update
                             if user.has_role?(:manager)
                                emp = Employee.find params[:id]
                                emp.update_attributes params[:employee]
                             end
class EmployeesController <end
                            ApplicationController
  before_filter :authorize, :if => :update
                        end
 def list
   @employees = Employee.all
 end

  def update
    emp = Employee.find params[:id]
    emp.update_attributes params[:employee]
  end
end
video from http://railscasts.com
video from http://railscasts.com
Is my app secure?
class EmployeesController < ApplicationController

 def list
   @employees = Employee.all
 end

  def update
    if user.has_role?(:manager)
      emp = Employee.find params[:id]
      emp.update_attributes params[:employee]
    end
  end
end
class Employee < ActiveRecord::Base
  include Grant::ModelSecurity

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

end
class Employee < ActiveRecord::Base
  include Grant::ModelSecurity

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

end



class EmployeesController < ApplicationController

 def list
   @employees = Employee.all
 end

  def update
    emp = Employee.find params[:id]
    emp.update_attributes params[:employee]
  end
end
Quiz
Quiz
class Employee < ActiveRecord::Base
  include Grant::ModelSecurity
  grant(:update) { |user, model| user.has_role?(:manager) }
end
Quiz
class Employee < ActiveRecord::Base
  include Grant::ModelSecurity
  grant(:update) { |user, model| user.has_role?(:manager) }
end

class User < ActiveRecord::Base
  def has_role?(role)
    [:employee, :manager].include?(role)
  end
end
Quiz
class Employee < ActiveRecord::Base
  include Grant::ModelSecurity
  grant(:update) { |user, model| user.has_role?(:manager) }
end

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

class EmployeesController < ApplicationController




                                                              ?
  def update
    emp = Employee.find params[:id]
    emp.update_attributes params[:employee]
  end
end
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'
Grant is all or nothing
class Employee < ActiveRecord::Base
  include Grant::ModelSecurity

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

end
... associations too
class Employee < ActiveRecord::Base
  include 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)
 end
 grant(:add => :reviews, :remove => :reviews) do |user, model|
   user.has_role?(:manager)
 end

end
How does it work?
  Hook methods
  Dynamic Methods
  Active Record Callbacks
  Around Aliases
Show and Tell
Show and Tell
  .. and answer lots of questions
Grant
             Security
             Anxiety
              Relief



http://github.com/nearinfinity/grant

Contenu connexe

Tendances

Workflow demo
Workflow demoWorkflow demo
Workflow demo
Kamal Raj
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
ecomputernotes
 

Tendances (19)

هیبرید کارا، از رویا تا واقعیت!
هیبرید کارا، از رویا تا واقعیت!هیبرید کارا، از رویا تا واقعیت!
هیبرید کارا، از رویا تا واقعیت!
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
Rails introduction
Rails introductionRails introduction
Rails introduction
 
2007 Zend Con Mvc
2007 Zend Con Mvc2007 Zend Con Mvc
2007 Zend Con Mvc
 
Dive into React Performance
Dive into React PerformanceDive into React Performance
Dive into React Performance
 
Test Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsTest Drive Development in Ruby On Rails
Test Drive Development in Ruby On Rails
 
Confident Refactoring - Ember SF Meetup
Confident Refactoring - Ember SF MeetupConfident Refactoring - Ember SF Meetup
Confident Refactoring - Ember SF Meetup
 
Some tips to improve developer experience with Symfony
Some tips to improve developer experience with SymfonySome tips to improve developer experience with Symfony
Some tips to improve developer experience with Symfony
 
Function Returns
Function ReturnsFunction Returns
Function Returns
 
Functions
FunctionsFunctions
Functions
 
Workflow demo
Workflow demoWorkflow demo
Workflow demo
 
Painless Javascript Unit Testing
Painless Javascript Unit TestingPainless Javascript Unit Testing
Painless Javascript Unit Testing
 
EMC Documentum - xCP 2.x Updating Java Services
EMC Documentum - xCP 2.x Updating Java ServicesEMC Documentum - xCP 2.x Updating Java Services
EMC Documentum - xCP 2.x Updating Java Services
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best Practices
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
 
Using velocity Templates(An overview)
Using velocity Templates(An overview)Using velocity Templates(An overview)
Using velocity Templates(An overview)
 
Defensive Apex Programming
Defensive Apex ProgrammingDefensive Apex Programming
Defensive Apex Programming
 
What's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overviewWhat's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overview
 

Similaire à Grant

Simple restfull app_s
Simple restfull app_sSimple restfull app_s
Simple restfull app_s
netwix
 
Rails best practices_slides
Rails best practices_slidesRails best practices_slides
Rails best practices_slides
Cao Van An
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
fiyuer
 
Resource and view
Resource and viewResource and view
Resource and view
Papp Laszlo
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 Ajax
Wen-Tien Chang
 

Similaire à Grant (20)

Simple restfull app_s
Simple restfull app_sSimple restfull app_s
Simple restfull app_s
 
Comparison of different access controls
Comparison of different access controlsComparison of different access controls
Comparison of different access controls
 
Simplify Your Rails Controllers With a Vengeance
Simplify Your Rails Controllers With a VengeanceSimplify Your Rails Controllers With a Vengeance
Simplify Your Rails Controllers With a Vengeance
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
 
Rails best practices_slides
Rails best practices_slidesRails best practices_slides
Rails best practices_slides
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
 
Curso Symfony - Clase 3
Curso Symfony - Clase 3Curso Symfony - Clase 3
Curso Symfony - Clase 3
 
Rails Plugin Development 101 (...and some...)
Rails Plugin Development 101 (...and some...)Rails Plugin Development 101 (...and some...)
Rails Plugin Development 101 (...and some...)
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weibo
 
Resource and view
Resource and viewResource and view
Resource and view
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010Código Saudável => Programador Feliz - Rs on Rails 2010
Código Saudável => Programador Feliz - Rs on Rails 2010
 
How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
Software Testing & PHPSpec
Software Testing & PHPSpecSoftware Testing & PHPSpec
Software Testing & PHPSpec
 
Laravel tips-2019-04
Laravel tips-2019-04Laravel tips-2019-04
Laravel tips-2019-04
 
Practical Celery
Practical CeleryPractical Celery
Practical Celery
 
Cramp websockets
Cramp websocketsCramp websockets
Cramp websockets
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
 
LvivPy - Flask in details
LvivPy - Flask in detailsLvivPy - Flask in details
LvivPy - Flask in details
 
Ruby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 AjaxRuby on Rails : RESTful 和 Ajax
Ruby on Rails : RESTful 和 Ajax
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Grant

  • 1. Grant security plugin for Rails Jeff Kunkle
  • 2. Leveraging Ruby’s Open Classes and Metaprogramming Capabilities, Combined with Active Record Features to Develop a Security Plugin for Ruby on Rails Jeff Kunkle
  • 3. class EmployeesController < ApplicationController before_filter :authorize, :if => :update def list @employees = Employee.all end def update emp = Employee.find params[:id] emp.update_attributes params[:employee] end end
  • 4. class EmployeesController < ApplicationController def list @employees = Employee.all end def update if user.has_role?(:manager) emp = Employee.find params[:id] emp.update_attributes params[:employee] end class EmployeesController <end ApplicationController before_filter :authorize, :if => :update end def list @employees = Employee.all end def update emp = Employee.find params[:id] emp.update_attributes params[:employee] end end
  • 7.
  • 8.
  • 9. Is my app secure?
  • 10.
  • 11. class EmployeesController < ApplicationController def list @employees = Employee.all end def update if user.has_role?(:manager) emp = Employee.find params[:id] emp.update_attributes params[:employee] end end end
  • 12. class Employee < ActiveRecord::Base include Grant::ModelSecurity grant(:update) { |user, model| user.has_role?(:manager) } end
  • 13. class Employee < ActiveRecord::Base include Grant::ModelSecurity grant(:update) { |user, model| user.has_role?(:manager) } end class EmployeesController < ApplicationController def list @employees = Employee.all end def update emp = Employee.find params[:id] emp.update_attributes params[:employee] end end
  • 14. Quiz
  • 15. Quiz class Employee < ActiveRecord::Base include Grant::ModelSecurity grant(:update) { |user, model| user.has_role?(:manager) } end
  • 16. Quiz class Employee < ActiveRecord::Base include Grant::ModelSecurity grant(:update) { |user, model| user.has_role?(:manager) } end class User < ActiveRecord::Base def has_role?(role) [:employee, :manager].include?(role) end end
  • 17. Quiz class Employee < ActiveRecord::Base include Grant::ModelSecurity grant(:update) { |user, model| user.has_role?(:manager) } end class User < ActiveRecord::Base def has_role?(role) [:employee, :manager].include?(role) end end class EmployeesController < ApplicationController ? def update emp = Employee.find params[:id] emp.update_attributes params[:employee] end end
  • 18. 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'
  • 19. Grant is all or nothing class Employee < ActiveRecord::Base include Grant::ModelSecurity grant(:find) grant(:destroy) { |user, model| user.has_role?(:admin) } grant(:update, :create) do |user, model| user.has_role?(:manager) end end
  • 20. ... associations too class Employee < ActiveRecord::Base include 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) end grant(:add => :reviews, :remove => :reviews) do |user, model| user.has_role?(:manager) end end
  • 21. How does it work? Hook methods Dynamic Methods Active Record Callbacks Around Aliases
  • 23. Show and Tell .. and answer lots of questions
  • 24. Grant Security Anxiety Relief http://github.com/nearinfinity/grant