-
Notifications
You must be signed in to change notification settings - Fork 375
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
[APPSEC-8112] Appsec block request when user ID matches rules data #2642
Conversation
f643f15
to
c978ae2
Compare
@@ -56,6 +56,11 @@ def self.set_user(trace, id:, email: nil, name: nil, session_id: nil, role: nil, | |||
others.each do |k, v| | |||
trace.set_tag("usr.#{k}", v) unless v.nil? | |||
end | |||
|
|||
if ::Datadog::AppSec.enabled? | |||
user = OpenStruct.new(id: id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenStruct
is very slow, let's replace it quickly! (on a separate PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely. I'm not a fun of OpenStruct
but for getting out of the way is very handy
5442da0
to
b6f7afe
Compare
b6f7afe
to
3b09f87
Compare
Codecov Report
@@ Coverage Diff @@
## master #2642 +/- ##
==========================================
+ Coverage 98.05% 98.08% +0.03%
==========================================
Files 1159 1160 +1
Lines 63607 63695 +88
Branches 2846 2849 +3
==========================================
+ Hits 62369 62477 +108
+ Misses 1238 1218 -20
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
module Datadog | ||
module AppSec | ||
module Ext | ||
INTERRUPT = :datadog_appsec_interrupt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you genericised the name from REQUEST_INTERRUPT
to INTERRUPT
so that it's context agnostic (request or otherwise)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. Would you like to change it? I thought about BLOCK
which is also context agnostic
@@ -48,7 +49,7 @@ def watch_user_id(gateway = Instrumentation.gateway) | |||
_result, block = Monitor::Reactive::SetUser.publish(op, user) | |||
end | |||
|
|||
next [nil, [[:block, event]]] if block | |||
throw(Datadog::AppSec::Ext::INTERRUPT, [nil, [:block, event]]) if block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in other discussions, we will have to see if this is still correct when multiple watchers are present on the same watch point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm eager to have a use case for multiple watchers and see how the reactive engine works
@@ -56,6 +56,11 @@ def self.set_user(trace, id:, email: nil, name: nil, session_id: nil, role: nil, | |||
others.each do |k, v| | |||
trace.set_tag("usr.#{k}", v) unless v.nil? | |||
end | |||
|
|||
if ::Datadog::AppSec.enabled? | |||
user = OpenStruct.new(id: id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenStruct
is very slow, let's replace it quickly! (on a separate PR)
What does this PR do?
This PR works on top of the previous work done to introduce the
AppSec::Component
and theAppsec::Monitor
The new code added does the following:
Kit::Identity.set_user
if appsec is enabled, we would propagate the user information to the appsec reactive enginethrow
I had to add
Datadog::AppSec.settings.send(:reset!)
after all the integration contrib tests to avoid having leaky tests.Motivation
Additional Notes
How to test the change?
CI should be 🟢