Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC for managing write-only permission at the Sequel level #2896

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class UnprocessableEntity < RuntimeError
rescue_from Errors::Authorization::AccessToResourceIsForbiddenForRole, with: :forbidden
rescue_from Errors::Conjur::RequestedResourceNotFound, with: :resource_not_found
rescue_from Errors::Authorization::InsufficientResourcePrivileges, with: :forbidden
rescue_from Errors::Conjur::ReadOnly::ActionNotPermitted, with: :method_not_allowed

around_action :run_with_transaction

Expand Down
7 changes: 7 additions & 0 deletions app/domain/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ module Conjur
msg: "Resource '{0-resource}' requested by role '{1-role}' not found",
code: "CONJ00123E"
)

module ReadOnly
ActionNotPermitted = ::Util::TrackableErrorClass.new(
msg: "This action is not permitted when the server is in read-only mode",
code: "CONJ00153E"
)
end
end

module Authorization
Expand Down
20 changes: 20 additions & 0 deletions app/models/read_only.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Removes persistence if Conjur is operating as a read-only instance
class Sequel::Model
def before_save
check_if_writes_permitted
super
end

def before_destroy
check_if_writes_permitted
super
end

def check_if_writes_permitted
return unless Rails.configuration.read_only

raise ::Errors::Conjur::ReadOnly::ActionNotPermitted
end
end
1 change: 1 addition & 0 deletions config/environments/appliance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
config.middleware.use(Rack::RememberUuid)
config.audit_socket = '/run/conjur/audit.socket'
config.audit_database ||= 'postgres://:5433/audit'
config.read_only = false
end
6 changes: 6 additions & 0 deletions config/initializers/read_only_mode.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

# Put Conjur into "read-only" mode
Rails.application.configure do
config.read_only = true
end
6 changes: 3 additions & 3 deletions dev/start
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fi
# Minimal set of services. We add to this list based on cmd line flags.
services=(pg conjur client)

# Authenticators to enable.
# Authenticators to enable.
default_authenticators="authn,authn-k8s/test"
enabled_authenticators="$default_authenticators"

Expand Down Expand Up @@ -80,7 +80,7 @@ main() {

# Updates CONJUR_AUTHENTICATORS and restarts required services.
start_auth_services
create_alice
# create_alice
kill_conjur # so dev's can restart it manually
enter_container
}
Expand All @@ -97,7 +97,7 @@ Usage: start [options]
--authn-gcp Starts with authn-gcp as authenticator
--authn-iam Starts with authn-iam/prod as authenticator
--authn-jwt Starts with authn-jwt as authenticator
--authn-ldap Starts OpenLDAP server and loads a demo policy to enable
--authn-ldap Starts OpenLDAP server and loads a demo policy to enable
authentication via:
'curl -X POST -d "alice" http://localhost:3000/authn-ldap/test/cucumber/alice/authenticate'
-h, --help Shows this help message.
Expand Down