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

Update AppSec Settings to use the env, and type options #2987

Merged
merged 3 commits into from
Jul 24, 2023

Conversation

GustavoCaso
Copy link
Member

@GustavoCaso GustavoCaso commented Jul 21, 2023

What does this PR do?

Build on top of #2983

Update the AppSec settings to use env, and type options to improve appsec settings integrity

Motivation

Additional Notes

How to test the change?

@GustavoCaso GustavoCaso requested a review from a team July 21, 2023 07:51
@github-actions github-actions bot added the appsec Application Security monitoring product label Jul 21, 2023
@GustavoCaso GustavoCaso force-pushed the update-appsec-settings-to-use-env-and-type branch from c3fffa7 to 4bbad6a Compare July 21, 2023 07:52
@codecov-commenter
Copy link

Codecov Report

Merging #2987 (db832a3) into master (33b4be5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2987   +/-   ##
=======================================
  Coverage   98.08%   98.08%           
=======================================
  Files        1301     1301           
  Lines       72468    72461    -7     
  Branches     3349     3347    -2     
=======================================
- Hits        71082    71076    -6     
+ Misses       1386     1385    -1     
Impacted Files Coverage Δ
lib/datadog/appsec/configuration/settings.rb 98.64% <100.00%> (+0.03%) ⬆️
spec/datadog/appsec/configuration/settings_spec.rb 99.64% <100.00%> (-0.02%) ⬇️

... and 1 file with indirect coverage changes

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

Comment on lines -554 to +536
let(:track_user_events_mode) { :extended }
let(:track_user_events_mode) { 'extended' }
Copy link
Member

@marcotc marcotc Jul 21, 2023

Choose a reason for hiding this comment

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

There's a small change related to these lines where, somewhere in our code, we are converting :extended to a String, but now we just pass the String directly.
Is this material to the application running appsec, or simply a testing artifact?

Copy link
Member Author

Choose a reason for hiding this comment

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

On the first iteration, we accepted either string or symbol as a possible value for appsec.track_user_events.mode. Internally we stored it as a string, and what ever check we did against those values expected a string.

when EXTENDED_MODE
@email = @resource.email
@username = @resource.username
when SAFE_MODE

With this change, we signal that we only support string values.

As a note, this feature hasn't ben release yet, so there are no users using it, so there is no breaking change or anything that could potentially affect users of appsec

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

👍 LGTM

Comment on lines +89 to +91
o.type :string
o.env 'DD_APPSEC_OBFUSCATION_PARAMETER_VALUE_REGEXP'
o.default DEFAULT_OBFUSCATOR_VALUE_REGEX
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR, but it kills me that we use REGEXP and REGEX lol

Copy link
Member

@lloeki lloeki Jul 24, 2023

Choose a reason for hiding this comment

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

I definitely relate to that feeling! These env vars typically come from external specifications.

Comment on lines 117 to 119
'The appsec.track_user_events.mode value provided is not supported.' \
"Supported values are: safe | extended.\n" \
'Using default value safe'
Copy link
Member

Choose a reason for hiding this comment

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

Minor: This was already like this, but since we're here, I suggest removing the newline from the log message, as a lot of logging tools can get tripped with newlines (e.g. show them out of order and whatnot), and thus having it all in a single line avoids any possible confusion.

Suggested change
'The appsec.track_user_events.mode value provided is not supported.' \
"Supported values are: safe | extended.\n" \
'Using default value safe'
'The appsec.track_user_events.mode value provided is not supported.' \
"Supported values are: safe | extended. " \
'Using default value safe'

Comment on lines 52 to 56
context 'is not defined' do
let(:appsec_enabled) { nil }

it { is_expected.to be described_class::DEFAULT_APPSEC_ENABLED }
it { is_expected.to eq false }
end
Copy link
Member

Choose a reason for hiding this comment

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

👏 I really love having the defaults inlined in the tests. That's because it protects us from changing some default accidentally, or at least without considering its impact on the tests -- if the behavior of the implementation (default) changes, the tests should have to change too!

Copy link
Member

@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!

@GustavoCaso GustavoCaso merged commit d6fd258 into master Jul 24, 2023
@GustavoCaso GustavoCaso deleted the update-appsec-settings-to-use-env-and-type branch July 24, 2023 11:16
@github-actions github-actions bot added this to the 1.13.0 milestone Jul 24, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants