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

dynamodb instrmentation added #125

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions lib/newrelic_security/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module NewRelic::Security
COLON_IAST_COLON = ':IAST:'
NOSQL_DB_COMMAND = 'NOSQL_DB_COMMAND'
SQL_DB_COMMAND = 'SQL_DB_COMMAND'
DYNAMO_DB_COMMAND = 'DYNAMO_DB_COMMAND'
FILE_OPERATION = 'FILE_OPERATION'
FILE_INTEGRITY = 'FILE_INTEGRITY'
SYSTEM_COMMAND = 'SYSTEM_COMMAND'
Expand All @@ -30,6 +31,7 @@ module NewRelic::Security
SQLITE = 'SQLITE'
MYSQL = 'MYSQL'
POSTGRES = 'POSTGRES'
DQL = 'DQL'
ISO_8859_1 = 'ISO-8859-1'
UTF_8 = 'UTF-8'
RAILS = 'rails'
Expand Down
52 changes: 52 additions & 0 deletions lib/newrelic_security/instrumentation-security/dynamodb/chain.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module NewRelic::Security
module Instrumentation
module Aws
module DynamoDB
module Client
module Chain

def self.instrument!
::Aws::DynamoDB::Client.class_eval do
include NewRelic::Security::Instrumentation::Aws::DynamoDB::Client

alias_method :put_item_without_security, :put_item

def put_item(*args)
retval = nil
event = put_item_on_enter(*args) { retval = put_item_without_security(*args) }
put_item_on_exit(event) { return retval }
end

alias_method :get_item_without_security, :get_item

def get_item(*args)
retval = nil
event = get_item_on_enter(*args) { retval = get_item_without_security(*args) }
get_item_on_exit(event) { return retval }
end

alias_method :update_item_without_security, :update_item

def update_item(*args)
retval = nil
event = update_item_on_enter(*args) { retval = update_item_without_security(*args) }
update_item_on_exit(event) { return retval }
end

alias_method :delete_item_without_security, :delete_item

def delete_item(*args)
retval = nil
event = delete_item_on_enter(*args) { retval = delete_item_without_security(*args) }
delete_item_on_exit(event) { return retval }
end

end
end
end
end
end

end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
require_relative 'prepend'
require_relative 'chain'

module NewRelic::Security
module Instrumentation
module Aws::DynamoDB::Client
def put_item_on_enter(*args)
event = nil
NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
hash = {}
hash[:payloadType] = :write
hash[:payload] = args[0]
event = NewRelic::Security::Agent::Control::Collector.collect(DYNAMO_DB_COMMAND, [hash], DQL)
rescue => exception
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
yield
return event
end

def put_item_on_exit(event)
NewRelic::Security::Agent.logger.debug "OnExit : #{self.class}.#{__method__}"
NewRelic::Security::Agent::Utils.create_exit_event(event)
rescue => exception
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
yield
end

def get_item_on_enter(*args)
event = nil
NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
hash = {}
hash[:payloadType] = :read
hash[:payload] = args[0]
event = NewRelic::Security::Agent::Control::Collector.collect(DYNAMO_DB_COMMAND, [hash], DQL)
rescue => exception
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
yield
return event
end

def get_item_on_exit(event)
NewRelic::Security::Agent.logger.debug "OnExit : #{self.class}.#{__method__}"
NewRelic::Security::Agent::Utils.create_exit_event(event)
rescue => exception
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
yield
end

def update_item_on_enter(*args)
event = nil
NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
hash = {}
hash[:payloadType] = :update
hash[:payload] = args[0]
event = NewRelic::Security::Agent::Control::Collector.collect(DYNAMO_DB_COMMAND, [hash], DQL)
rescue => exception
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
yield
return event
end

def update_item_on_exit(event)
NewRelic::Security::Agent.logger.debug "OnExit : #{self.class}.#{__method__}"
NewRelic::Security::Agent::Utils.create_exit_event(event)
rescue => exception
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
yield
end

def delete_item_on_enter(*args)
event = nil
NewRelic::Security::Agent.logger.debug "OnEnter : #{self.class}.#{__method__}"
hash = {}
hash[:payloadType] = :delete
hash[:payload] = args[0]
event = NewRelic::Security::Agent::Control::Collector.collect(DYNAMO_DB_COMMAND, [hash], DQL)
rescue => exception
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
yield
return event
end

def delete_item_on_exit(event)
NewRelic::Security::Agent.logger.debug "OnExit : #{self.class}.#{__method__}"
NewRelic::Security::Agent::Utils.create_exit_event(event)
rescue => exception
NewRelic::Security::Agent.logger.error "Exception in hook in #{self.class}.#{__method__}, #{exception.inspect}, #{exception.backtrace}"
ensure
yield
end

end

end
end

NewRelic::Security::Instrumentation::InstrumentationLoader.install_instrumentation(:dynamodb, ::Aws::DynamoDB::Client, ::NewRelic::Security::Instrumentation::Aws::DynamoDB::Client)
39 changes: 39 additions & 0 deletions lib/newrelic_security/instrumentation-security/dynamodb/prepend.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module NewRelic::Security
module Instrumentation
module Aws
module DynamoDB
module Client
module Prepend
include NewRelic::Security::Instrumentation::Aws::DynamoDB::Client

def put_item(*args)
retval = nil
event = put_item_on_enter(*args) { retval = super }
put_item_on_exit(event) { return retval }
end

def get_item(*args)
retval = nil
event = get_item_on_enter(*args) { retval = super }
get_item_on_exit(event) { return retval }
end

def update_item(*args)
retval = nil
event = update_item_on_enter(*args) { retval = super }
update_item_on_exit(event) { return retval }
end

def delete_item(*args)
retval = nil
event = delete_item_on_enter(*args) { retval = super }
delete_item_on_exit(event) { return retval }
end

end
end
end

end
end
end
Loading