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

make sure to assign a valid processor to the appsec component #2637

Merged
merged 2 commits into from
Feb 23, 2023

Conversation

GustavoCaso
Copy link
Member

What does this PR do?

After merging #2632, we got alerted that our system tests were failing.
The scenario that is failing is when the appsec processor fails to parse the WAF rules.
The test fails when the app wants tries to shout down and we try to finalize the appsec component. The problem is that the processor was never ready, so finalizing a non-ready processor caused an error.

This PR fix that case by making sure to check if the processor is ready to assign to the appsec component.

Additional Notes

Should we make the AppSec::Component.new method private and only allow to use build_appsec_component?

How to test the change?

@GustavoCaso GustavoCaso requested review from a team and lloeki February 22, 2023 16:25
@github-actions github-actions bot added appsec Application Security monitoring product integrations Involves tracing integrations labels Feb 22, 2023
Copy link
Contributor

@lloeki lloeki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a few suggestions.

We should improve thread safety further when we get to remote configuration.

Comment on lines 35 to 38
if processor
processor.finalize
@processor = nil
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve thread safety, Processor might be finalized already but not yet nil.

Also, prefer a guard clause:

Suggested change
if processor
processor.finalize
@processor = nil
end
return if processor.nil? || !processor.ready?
processor.finalize
@processor = nil

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer a guard clause too. It looks like steep likes:

def shutdown!
  if processor && processor.ready?
    processor.finalize
    @processor = nil
  end
end

With this form, steep is able to resolve the type checking issue we discussed earlier in which steep does not find the finalize method

lib/datadog/appsec/component.rb:28:18: [error] Type `::Datadog::AppSec::Processor` does not have method `finalize`
│ Diagnostic ID: Ruby::NoMethod
│
└         processor.finalize if processor
                    ~~~~~~~~

Detected 1 problem from 1 file

lib/datadog/appsec/contrib/rack/request_middleware.rb Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Merging #2637 (09ee622) into master (2b163dd) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2637      +/-   ##
==========================================
- Coverage   98.08%   98.08%   -0.01%     
==========================================
  Files        1155     1155              
  Lines       63330    63358      +28     
  Branches     2826     2828       +2     
==========================================
+ Hits        62117    62142      +25     
- Misses       1213     1216       +3     
Impacted Files Coverage Δ
lib/datadog/appsec/component.rb 100.00% <100.00%> (ø)
.../datadog/appsec/contrib/rack/request_middleware.rb 95.83% <100.00%> (ø)
spec/datadog/appsec/component_spec.rb 100.00% <100.00%> (ø)
...atadog/tracing/contrib/grpc/support/grpc_helper.rb 98.24% <0.00%> (-1.76%) ⬇️
lib/datadog/core/diagnostics/environment_logger.rb 97.69% <0.00%> (-1.57%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@GustavoCaso GustavoCaso merged commit 9d4eae6 into master Feb 23, 2023
@GustavoCaso GustavoCaso deleted the appsec-make-sure-processor-is-ready branch February 23, 2023 09:25
@github-actions github-actions bot added this to the 1.10.0 milestone Feb 23, 2023
@TonyCTHsu TonyCTHsu mentioned this pull request Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appsec Application Security monitoring product integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants