-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
appsec: setup ossec package and OpenOperation (#2781)
Signed-off-by: Eliott Bouhana <[email protected]>
- Loading branch information
1 parent
002b6ff
commit da02d30
Showing
11 changed files
with
259 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Orchestrion | ||
on: | ||
workflow_dispatch: # manually | ||
pull_request: | ||
merge_group: | ||
push: | ||
branches: | ||
- release-v* | ||
|
||
permissions: read-all | ||
|
||
concurrency: | ||
# Automatically cancel previous runs if a new one is triggered to conserve resources. | ||
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
name: 'Run Tests' | ||
uses: DataDog/orchestrion/.github/workflows/workflow_call.yml@main # we don't want to pin our own action | ||
with: | ||
dd-trace-go-ref: ${{ github.sha }} | ||
runs-on: ubuntu-latest-16-cores |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2024 Datadog, Inc. | ||
|
||
package ossec | ||
|
||
import ( | ||
"io/fs" | ||
|
||
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/dyngo" | ||
) | ||
|
||
type ( | ||
// OpenOperation type embodies any kind of function calls that will result in a call to an open(2) syscall | ||
OpenOperation struct { | ||
dyngo.Operation | ||
blockErr error | ||
} | ||
|
||
// OpenOperationArgs is the arguments for an open operation | ||
OpenOperationArgs struct { | ||
// Path is the path to the file to be opened | ||
Path string | ||
// Flags are the flags passed to the open(2) syscall | ||
Flags int | ||
// Perms are the permissions passed to the open(2) syscall if the creation of a file is required | ||
Perms fs.FileMode | ||
} | ||
|
||
// OpenOperationRes is the result of an open operation | ||
OpenOperationRes[File any] struct { | ||
// File is the file descriptor returned by the open(2) syscall | ||
File *File | ||
// Err is the error returned by the function | ||
Err *error | ||
} | ||
) | ||
|
||
func (OpenOperationArgs) IsArgOf(*OpenOperation) {} | ||
func (OpenOperationRes[File]) IsResultOf(*OpenOperation) {} |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2024 Datadog, Inc. | ||
|
||
package ossec | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/DataDog/appsec-internal-go/limiter" | ||
waf "github.com/DataDog/go-libddwaf/v3" | ||
|
||
"gopkg.in/DataDog/dd-trace-go.v1/appsec/events" | ||
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/dyngo" | ||
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/ossec" | ||
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/listener" | ||
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/listener/sharedsec" | ||
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/trace" | ||
) | ||
|
||
const ( | ||
ServerIOFSFileAddr = "server.io.fs.file" | ||
) | ||
|
||
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}} | ||
}) | ||
|
||
dyngo.On(op, func(op *ossec.OpenOperation, args ossec.OpenOperationArgs) { | ||
dyngo.OnData(op, func(e *events.BlockingSecurityEvent) { | ||
dyngo.OnFinish(op, func(_ *ossec.OpenOperation, res ossec.OpenOperationRes[*os.File]) { | ||
if res.Err != nil { | ||
*res.Err = e | ||
} | ||
}) | ||
}) | ||
runWAF(op, args) | ||
}) | ||
} | ||
|
||
func OSAddressesPresent(addresses listener.AddressSet) bool { | ||
_, fileAddr := addresses[ServerIOFSFileAddr] | ||
return fileAddr | ||
} |
This file contains 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
Oops, something went wrong.