-
Notifications
You must be signed in to change notification settings - Fork 338
Upgrade libddwaf native bindings #5792
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
Open
CarlesDD
wants to merge
22
commits into
master
Choose a base branch
from
ccapell/new-waf-builder
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ccc741a
WIP
CarlesDD f9b4242
Clean up + apply_error
CarlesDD cf6b37c
WAF update diagnostics propagation through RC and telemetry
CarlesDD bf584c8
Change metrics for waf update and config errors
CarlesDD 85e40fd
Remove deprecated span tags
CarlesDD fb8f7dd
Fix report waf update
CarlesDD 66712f6
Tests
CarlesDD 0417683
Tests for Rule Manager
CarlesDD ec54f44
More tests
CarlesDD 5174d97
Improve assert
CarlesDD 00b9cdd
Tests
CarlesDD efbf2a6
Clean up
CarlesDD 50da11a
Clean up
CarlesDD 1d79770
Native appsec package bump
CarlesDD 2ad92a6
Revert "Remove deprecated span tags"
CarlesDD 1987802
Revert tag deprecation
CarlesDD ac9b1d6
Clean up
CarlesDD c5841ab
Lint
CarlesDD 479c2e9
Fix assertion
CarlesDD 66e1b28
Improve RC product check
CarlesDD 1a2ebc9
Avoid checking obj keys in rule manager extract errors
CarlesDD 079af0e
Abstract log message publish in reporter
CarlesDD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
'use strict' | ||
|
||
const dc = require('dc-polyfill') | ||
const zlib = require('zlib') | ||
|
||
const Limiter = require('../rate_limiter') | ||
const { storage } = require('../../../datadog-core') | ||
const web = require('../plugins/util/web') | ||
const { ipHeaderList } = require('../plugins/util/ip_extractor') | ||
const { | ||
incrementWafInitMetric, | ||
incrementWafUpdatesMetric, | ||
incrementWafConfigErrorsMetric, | ||
incrementWafRequestsMetric, | ||
updateWafRequestsMetricTags, | ||
updateRaspRequestsMetricTags, | ||
updateRaspRuleSkippedMetricTags, | ||
updateRateLimitedMetric, | ||
getRequestMetrics | ||
} = require('./telemetry') | ||
const zlib = require('zlib') | ||
const { keepTrace } = require('../priority_sampler') | ||
const { ASM } = require('../standalone/product') | ||
|
||
|
@@ -25,6 +28,20 @@ const COLLECTED_REQUEST_BODY_MAX_STRING_LENGTH = 4096 | |
const COLLECTED_REQUEST_BODY_MAX_DEPTH = 20 | ||
const COLLECTED_REQUEST_BODY_MAX_ELEMENTS_PER_NODE = 256 | ||
|
||
const telemetryLogCh = dc.channel('datadog:telemetry:log') | ||
|
||
const WAF_DIAGNOSTICS_CONFIG_KEYS_TO_REPORT = [ | ||
'rules', | ||
'custom_rules', | ||
'exclusions', | ||
'actions', | ||
'processors', | ||
'scanners', | ||
'rules_override', | ||
'rules_data', | ||
'exclusion_data' | ||
] | ||
|
||
// default limiter, configurable with setRateLimit() | ||
let limiter = new Limiter(100) | ||
|
||
|
@@ -225,6 +242,54 @@ function reportWafInit (wafVersion, rulesVersion, diagnosticsRules = {}, success | |
incrementWafInitMetric(wafVersion, rulesVersion, success) | ||
} | ||
|
||
function logWafDiagnosticMessage (product, rcConfigId, configKey, message, level) { | ||
telemetryLogCh.publish({ | ||
message, | ||
level, | ||
tags: { | ||
log_type: `rc::${product.toLowerCase()}::diagnostic`, | ||
appsec_config_key: configKey, | ||
rc_config_id: rcConfigId | ||
} | ||
}) | ||
} | ||
|
||
function reportSuccessfulWafUpdate (product, rcConfigId, diagnostics) { | ||
for (const configKey of WAF_DIAGNOSTICS_CONFIG_KEYS_TO_REPORT) { | ||
const configDiagnostics = diagnostics[configKey] | ||
if (!configDiagnostics) continue | ||
|
||
if (configDiagnostics.error) { | ||
logWafDiagnosticMessage(product, rcConfigId, configKey, configDiagnostics.error, 'ERROR') | ||
continue | ||
} | ||
|
||
if (configDiagnostics.errors) { | ||
for (const [errorMessage, errorIds] of Object.entries(configDiagnostics.errors)) { | ||
logWafDiagnosticMessage( | ||
product, | ||
rcConfigId, | ||
configKey, | ||
`"${errorMessage}": ${JSON.stringify(errorIds)}`, | ||
'ERROR' | ||
) | ||
} | ||
} | ||
|
||
if (configDiagnostics.warnings) { | ||
for (const [warningMessage, warningIds] of Object.entries(configDiagnostics.warnings)) { | ||
logWafDiagnosticMessage( | ||
product, | ||
rcConfigId, | ||
configKey, | ||
`"${warningMessage}": ${JSON.stringify(warningIds)}`, | ||
'WARN' | ||
) | ||
} | ||
} | ||
Comment on lines
+267
to
+289
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion (I think this is already good as is, so it's up to you): this could be unified with a loop over |
||
} | ||
} | ||
|
||
function reportMetrics (metrics, raspRule) { | ||
const store = storage('legacy').getStore() | ||
const rootSpan = store?.req && web.root(store.req) | ||
|
@@ -485,9 +550,11 @@ module.exports = { | |
filterExtendedHeaders, | ||
formatHeaderName, | ||
reportWafInit, | ||
reportSuccessfulWafUpdate, | ||
reportMetrics, | ||
reportAttack, | ||
reportWafUpdate: incrementWafUpdatesMetric, | ||
reportWafConfigError: incrementWafConfigErrorsMetric, | ||
reportRaspRuleSkipped: updateRaspRuleSkippedMetricTags, | ||
reportDerivatives, | ||
finishRequest, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These logs are sent via telemetry, but aren't shown in the output if the logs are enabled, is the expected behaviour?
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.
The RFC only establishes the propagation of diagnostics by telemetry and RC. Specifically it states that: