-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- When read-only mode is enabled via rails config, controller endpoints that are explicitly enrolled into a `write_protected` list return a HTTP 405 Method Not Allowed when invoked, also throwing Conjur error code: `CONJ00153E` - Implemented using module prepending
- Loading branch information
1 parent
0c6c4b2
commit 380bb0a
Showing
7 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ReadOnlyPrepender | ||
# Given a list of method symbols, preempt calls to them using a proxy that | ||
# raises an error if read_only is enabled. | ||
def write_protected(*method_names) | ||
method_names.each do |m| | ||
proxy = Module.new do | ||
define_method(m) do |*args| | ||
raise ::Errors::Conjur::ReadOnly::ActionNotPermitted unless !Rails.configuration.read_only | ||
super *args | ||
end | ||
end | ||
self.prepend proxy | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
Rails.application.configure do | ||
# Determines whether or not writable API endpoints are enabled. | ||
# | ||
# The `read_only` arguement is a boolean. By default, `read_only` is "Off". | ||
# This means that any of the writable API endpoints will function as intended. | ||
# | ||
# A writable API endpoint is one whose controller method is decorated with the | ||
# `@read_safe` decorator. When `read_only` is "On", such endpoints will return | ||
# an HTTP 405 Method Not Allowed response code. | ||
# | ||
config.read_only = false | ||
end | ||
|