Skip to content

Commit

Permalink
internal/appsec: setup rasp metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Sep 18, 2024
1 parent b9e57e2 commit 2fe0fa5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/appsec/listener/httpsec/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// RegisterRoundTripperListener registers a listener on outgoing HTTP client requests to run the WAF.
func RegisterRoundTripperListener(op dyngo.Operation, events *trace.SecurityEventsHolder, wafCtx *waf.Context, limiter limiter.Limiter) {
dyngo.On(op, sharedsec.MakeWAFRunListener(events, wafCtx, limiter, func(args types.RoundTripOperationArgs) waf.RunAddressData {
return waf.RunAddressData{Ephemeral: map[string]any{ServerIoNetURLAddr: args.URL}}
return waf.RunAddressData{Ephemeral: map[string]any{ServerIoNetURLAddr: args.URL}, Scope: waf.RASPScope}
}))
}

Expand Down
2 changes: 1 addition & 1 deletion internal/appsec/listener/ossec/lfi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (

func RegisterOpenListener(op dyngo.Operation, eventsHolder *trace.SecurityEventsHolder, wafCtx *waf.Context, limiter limiter.Limiter) {
runWAF := sharedsec.MakeWAFRunListener(eventsHolder, wafCtx, limiter, func(args ossec.OpenOperationArgs) waf.RunAddressData {
return waf.RunAddressData{Ephemeral: map[string]any{ServerIOFSFileAddr: args.Path}}
return waf.RunAddressData{Ephemeral: map[string]any{ServerIOFSFileAddr: args.Path}, Scope: waf.RASPScope}
})

dyngo.On(op, func(op *ossec.OpenOperation, args ossec.OpenOperationArgs) {
Expand Down
3 changes: 2 additions & 1 deletion internal/appsec/listener/sharedsec/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
eventRulesLoadedTag = "_dd.appsec.event_rules.loaded"
eventRulesFailedTag = "_dd.appsec.event_rules.error_count"
wafVersionTag = "_dd.appsec.waf.version"
wafSpanTagPrefix = "_dd.appsec."
)

func RunWAF(wafCtx *waf.Context, values waf.RunAddressData) waf.Result {
Expand Down Expand Up @@ -91,7 +92,7 @@ func AddWAFMonitoringTags(th trace.TagSetter, rulesVersion string, stats map[str

// Report the stats sent by the WAF
for k, v := range stats {
th.SetTag(k, v)
th.SetTag(wafSpanTagPrefix+k, v)
}
}

Expand Down
13 changes: 8 additions & 5 deletions internal/appsec/listener/sharedsec/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

waf "github.com/DataDog/go-libddwaf/v3"
"github.com/stretchr/testify/require"

"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/trace"
)

Expand All @@ -34,11 +35,13 @@ func TestTagsTypes(t *testing.T) {
AddRulesMonitoringTags(&th, &wafDiags)

stats := map[string]any{
wafDurationTag: 10,
wafDurationExtTag: 20,
wafTimeoutTag: 0,
"_dd.appsec.waf.truncations.depth": []int{1, 2, 3},
"_dd.appsec.waf.run": 12000,
"waf.duration": 10,
"rasp.duration": 10,
"waf.duration_ext": 20,
"rasp.duration_ext": 20,
"waf.timeouts": 0,
"waf.truncations.depth": []int{1, 2, 3},
"waf.run": 12000,
}

AddWAFMonitoringTags(&th, "1.2.3", stats)
Expand Down
2 changes: 1 addition & 1 deletion internal/appsec/listener/sqlsec/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

func RegisterSQLListener(op dyngo.Operation, events *trace.SecurityEventsHolder, wafCtx *waf.Context, limiter limiter.Limiter) {
dyngo.On(op, sharedsec.MakeWAFRunListener(events, wafCtx, limiter, func(args types.SQLOperationArgs) waf.RunAddressData {
return waf.RunAddressData{Ephemeral: map[string]any{ServerDBStatementAddr: args.Query, ServerDBTypeAddr: args.Driver}}
return waf.RunAddressData{Ephemeral: map[string]any{ServerDBStatementAddr: args.Query, ServerDBTypeAddr: args.Driver}, Scope: waf.RASPScope}
}))
}

Expand Down

0 comments on commit 2fe0fa5

Please sign in to comment.