Skip to content

Commit

Permalink
Merge branch 'main' into aws-streamname-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
webdestroya authored Sep 10, 2024
2 parents dcd3e6a + 0ffa615 commit 43e342a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 4 deletions.
10 changes: 9 additions & 1 deletion internal/appsec/remoteconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/config"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"gopkg.in/DataDog/dd-trace-go.v1/internal/orchestrion"
"gopkg.in/DataDog/dd-trace-go.v1/internal/remoteconfig"

internal "github.com/DataDog/appsec-internal-go/appsec"
Expand Down Expand Up @@ -409,7 +410,14 @@ func (a *appsec) enableRASP() {
if err := remoteconfig.RegisterCapability(remoteconfig.ASMRASPSSRF); err != nil {
log.Debug("appsec: Remote config: couldn't register RASP SSRF: %v", err)
}
// TODO: register other RASP capabilities when supported
if err := remoteconfig.RegisterCapability(remoteconfig.ASMRASPSQLI); err != nil {
log.Debug("appsec: Remote config: couldn't register RASP SQLI: %v", err)
}
if orchestrion.Enabled() {
if err := remoteconfig.RegisterCapability(remoteconfig.ASMRASPLFI); err != nil {
log.Debug("appsec: Remote config: couldn't register RASP LFI: %v", err)
}
}
}

func (a *appsec) disableRCBlocking() {
Expand Down
18 changes: 15 additions & 3 deletions internal/remoteconfig/remoteconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,26 @@ const (
APMTracingHTTPHeaderTags
// APMTracingCustomTags enables APM client to set custom tags on all spans
APMTracingCustomTags
// ASMProcessorOverrides adds support for processor overrides through the ASM RC Product
ASMProcessorOverrides
// ASMCustomDataScanners adds support for custom data scanners through the ASM RC Product
ASMCustomDataScanners
// ASMExclusionData adds support configurable exclusion filter data from the ASM_DATA Product
ASMExclusionData
// APMTracingEnabled enables APM tracing
APMTracingEnabled
// APMTracingDataStreamsEnabled enables Data Streams Monitoring
APMTracingDataStreamsEnabled
// ASMRASPSQLI enables ASM support for runtime protection against SQL Injection attacks
ASMRASPSQLI
// ASMRASPLFI enables ASM support for runtime protection against Local File Inclusion attacks
ASMRASPLFI
// ASMRASPSSRF enables ASM support for runtime protection against SSRF attacks
ASMRASPSSRF = 23
ASMRASPSSRF
)

// Additional capability bit index values that are non-consecutive from above.
const (
// APMTracingEnabled enables APM tracing
APMTracingEnabled Capability = 19
// APMTracingSampleRules represents the sampling rate using matching rules from APM client libraries
APMTracingSampleRules = 29
)
Expand Down
31 changes: 31 additions & 0 deletions profiler/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
"gopkg.in/DataDog/dd-trace-go.v1/internal/httpmem"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"gopkg.in/DataDog/dd-trace-go.v1/internal/orchestrion"
"gopkg.in/DataDog/dd-trace-go.v1/internal/traceprof"
"gopkg.in/DataDog/dd-trace-go.v1/internal/version"

Expand Down Expand Up @@ -748,3 +749,33 @@ func TestUDSDefault(t *testing.T) {

<-profiles
}

func TestOrchestrionProfileInfo(t *testing.T) {
testCases := []struct {
env string
want string
}{
{want: "manual"},
{env: "1", want: "manual"},
{env: "true", want: "manual"},
{env: "auto", want: "auto"},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("env=\"%s\"", tc.env), func(t *testing.T) {
t.Setenv("DD_PROFILING_ENABLED", tc.env)
p := doOneShortProfileUpload(t)
info := p.event.Info.Profiler
t.Logf("%+v", info)
if got := info.Activation; got != tc.want {
t.Errorf("wanted profiler activation \"%s\", got %s", tc.want, got)
}
want := "none"
if orchestrion.Enabled() {
want = "orchestrion"
}
if got := info.SSI.Mechanism; got != want {
t.Errorf("wanted profiler injected = %v, got %v", want, got)
}
})
}
}
32 changes: 32 additions & 0 deletions profiler/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import (
"mime/multipart"
"net/http"
"net/textproto"
"os"
"strings"
"time"

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

// maxRetries specifies the maximum number of retries to have when an error occurs.
Expand Down Expand Up @@ -144,6 +146,20 @@ type uploadEvent struct {
Version string `json:"version"`
EndpointCounts map[string]uint64 `json:"endpoint_counts,omitempty"`
CustomAttributes []string `json:"custom_attributes,omitempty"`
Info struct {
Profiler profilerInfo `json:"profiler"`
} `json:"info"`
}

// profilerInfo holds profiler-specific information which should be attached to
// the event for backend consumption
type profilerInfo struct {
SSI struct {
Mechanism string `json:"mechanism,omitempty"`
} `json:"ssi"`
// Activation distinguishes how the profiler was enabled, either "auto"
// (env var set via admission controller) or "manual"
Activation string `json:"activation"`
}

// encode encodes the profile as a multipart mime request.
Expand All @@ -167,6 +183,22 @@ func encode(bat batch, tags []string) (contentType string, body io.Reader, err e
CustomAttributes: bat.customAttributes,
}

// DD_PROFILING_ENABLED is only used to enable profiling when added with
// Orchestrion. The "auto" value comes from the Datadog Kubernetes
// admission controller. Otherwise, the client library doesn't care
// about the value and assumes it was something "truthy", or this code
// wouldn't run. We just track it to be consistent with other languages
if os.Getenv("DD_PROFILING_ENABLED") == "auto" {
event.Info.Profiler.Activation = "auto"
} else {
event.Info.Profiler.Activation = "manual"
}
if orchestrion.Enabled() {
event.Info.Profiler.SSI.Mechanism = "orchestrion"
} else {
event.Info.Profiler.SSI.Mechanism = "none"
}

for _, p := range bat.profiles {
event.Attachments = append(event.Attachments, p.name)
f, err := mw.CreateFormFile(p.name, p.name)
Expand Down

0 comments on commit 43e342a

Please sign in to comment.