All Projects → markets → Sudo_rails

markets / Sudo_rails

Licence: mit
🔒 Sudo mode for your Rails controllers

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Sudo rails

Rails server timings
Server Timing headers for Rails apps
Stars: ✭ 112 (+69.7%)
Mutual labels:  rails-engine, rails
Workflow core
[Deprecated, use flor_core instead] A Rails engine which providing essential infrastructure of workflow. It's based on Workflow Nets.
Stars: ✭ 171 (+159.09%)
Mutual labels:  rails-engine, rails
Spotlight
Spotlight enables librarians, curators, and others who are responsible for digital collections to create attractive, feature-rich websites that highlight these collections.
Stars: ✭ 137 (+107.58%)
Mutual labels:  rails-engine, rails
Tabler Rubygem
Rubygem for https://tabler.github.io
Stars: ✭ 77 (+16.67%)
Mutual labels:  rails-engine, rails
Material icons
A simple Rails wrapper for Google Material Icons
Stars: ✭ 266 (+303.03%)
Mutual labels:  rails-engine, rails
Comfy Blog
Blog Engine for ComfortableMexicanSofa (Rails 5.2+)
Stars: ✭ 98 (+48.48%)
Mutual labels:  rails-engine, rails
Flipflop
Flipflop lets you declare and manage feature flags in your Rails application.
Stars: ✭ 165 (+150%)
Mutual labels:  rails-engine, rails
Thredded
The best Rails forums engine ever.
Stars: ✭ 1,263 (+1813.64%)
Mutual labels:  rails-engine, rails
Role core
🔐A Rails engine providing essential industry of Role-based access control.
Stars: ✭ 262 (+296.97%)
Mutual labels:  rails-engine, rails
Comfortable Mexican Sofa
ComfortableMexicanSofa is a powerful Ruby on Rails 5.2+ CMS (Content Management System) Engine
Stars: ✭ 2,707 (+4001.52%)
Mutual labels:  rails-engine, rails
Redis web manager
Manage your Redis instance (see keys, memory used, connected client, etc...)
Stars: ✭ 139 (+110.61%)
Mutual labels:  rails-engine, rails
Rails email preview
Preview and edit app mailer templates in Rails.
Stars: ✭ 524 (+693.94%)
Mutual labels:  rails-engine, rails
Form core
A Rails engine providing ability to generate dynamic form.
Stars: ✭ 175 (+165.15%)
Mutual labels:  rails-engine, rails
Maily
📫 Rails Engine to preview emails in the browser
Stars: ✭ 502 (+660.61%)
Mutual labels:  rails-engine, rails
Fae
CMS for Rails. For Reals.
Stars: ✭ 701 (+962.12%)
Mutual labels:  rails-engine, rails
Sudo pair
Plugin for sudo that requires another human to approve and monitor privileged sudo sessions
Stars: ✭ 1,077 (+1531.82%)
Mutual labels:  sudo
Mixed gauge
A simple and robust database sharding with ActiveRecord.
Stars: ✭ 58 (-12.12%)
Mutual labels:  rails
Sudo killer
A tool to identify and exploit sudo rules' misconfigurations and vulnerabilities within sudo for linux privilege escalation.
Stars: ✭ 1,073 (+1525.76%)
Mutual labels:  sudo
Danbooru
A taggable image board written in Rails 6.
Stars: ✭ 1,077 (+1531.82%)
Mutual labels:  rails
Ama
"Ask Me Anything" with Rails 5.2 Application
Stars: ✭ 61 (-7.58%)
Mutual labels:  rails

Sudo Rails

Gem Build Status Maintainability

Sudo mode for your Rails controllers

🔒 Protect any Rails action with a customizable password confirmation strategy.

class SecretController < ApplicationController
  sudo
end

Inspired by Unix sudo command and GitHub Sudo mode.

Installation

Add this line to your Gemfile and then execute bundle install:

gem 'sudo_rails'

Usage

From now on, you have the sudo method available in your controllers, you can protect the whole controller or only some actions:

class SettingsController < ApplicationController
  sudo only: :sensible_settings
end

Under the hood, the sudo method delegates to a before_action callback, so you're able to pass the following options: :only, :except, :if and :unless.

The gem also provides a couple of controller helpers, useful to manually manage the sudo session status:

  • reset_sudo_session!: resets the current sudo session, if any.
  • extend_sudo_session!: marks the current session as a valid sudo session.

Configuration

You can use the setup method to configure and customize different things:

# config/initializers/sudo_rails.rb
SudoRails.setup do |config|
  # On/off engine
  config.enabled = true

  # Sudo mode sessions duration, default is 30 minutes
  config.sudo_session_duration = 10.minutes

  # Confirmation page styling
  config.custom_logo = '/images/logo_medium.png'
  config.primary_color = '#1a7191'
  config.background_color = '#1a1a1a'
  config.layout = 'admin'

  # Confirmation strategy implementation
  config.confirm_strategy = -> (context, password) {
    user = context.current_user
    user.valid_password?(password)
  }

  # Reset password link
  config.reset_pass_link = '/users/password/new'
end

Sudo sessions

Using the sudo_session_duration option you are able to configure the sudo session duration (30 minutes by default).

If you set it to nil, your sudo session won't expire automatically and you will have to do it manually by using the reset_sudo_session! helper.

Styling

Using the custom_logo, primary_color and background_color options, you can customize the confirmation page. In case you want full control of the styles, you can use your own layout (and consequently your own styles too) using the layout option.

See some 📷 examples here.

NOTE If you are using your own layout, don't forget to render the flash messages in that layout. You can do something like this.

Confirmation strategy

You should define how to validate the password using the confirm_strategy option. It must be a lambda, which will receive 2 arguments: the controller instance (context) and the password from the user.

By default, the gem ships with Devise and Clearance integration. Check it here.

Implementation examples:

# Devise implementation
config.confirm_strategy = -> (context, password) {
  user = context.current_user
  user.valid_password?(password)
}

# has_secure_password implementation
config.confirm_strategy = -> (context, password) {
  user = context.current_user
  user.authenticate(password)
}

# Other custom implementations
config.confirm_strategy = -> (context, password) {
  user = context.current_user
  user.admin? && password == ENV['SUPER_SECRET_PASSWORD']
}

config.confirm_strategy = -> (context, password) {
  Auth.call(context.current_user.email, password)
}

I18n

sudo_rails uses I18n by default. Take a look at our locale file to check all available messages.

Development

Any kind of feedback, bug report, idea or enhancement are really appreciated.

To contribute, just fork the repo, hack on it and send a pull request. Don't forget to add tests for behaviour changes and run the test suite:

> bundle exec rspec

License

Copyright (c) Marc Anguera. SudoRails is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].