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

appsec: add Start() and Stop() to API #2507

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eliottness
Copy link
Contributor

@eliottness eliottness commented Jan 16, 2024

What does this PR do?

This PR adds Start and Stop and options to it on the appsec public API for a programmatic access to enabling ASM Threats.

Motivation

We would like to have a way to enable and configure ASM directly in consul internally in Datadog. A Version 1 of this works already but requires to redeploy everything which can be slow and cannot be done by us. A way to dynamically activate ASM but more granularly than Remote Activation is required to make this happen.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@eliottness eliottness changed the title appsec: add appsec.Start() and appsec.Stop() to appsec API appsec: add Start() and Stop() to API Jan 16, 2024
@eliottness eliottness self-assigned this Jan 16, 2024
@eliottness eliottness force-pushed the eliott.bouhana/public-appsec-start branch from 6ad9c86 to 1dd09f2 Compare January 25, 2024 16:17
@github-actions github-actions bot added the apm:ecosystem contrib/* related feature requests or bugs label Jan 25, 2024
Signed-off-by: Eliott Bouhana <eliott.bouhana@datadoghq.com>
Signed-off-by: Eliott Bouhana <eliott.bouhana@datadoghq.com>
@eliottness eliottness force-pushed the eliott.bouhana/public-appsec-start branch from 06cc2fd to 33d8249 Compare January 25, 2024 16:33
@pr-commenter
Copy link

pr-commenter bot commented Jan 25, 2024

Benchmarks

Benchmark execution time: 2024-01-25 16:50:37

Comparing candidate commit 33d8249 in PR branch eliott.bouhana/public-appsec-start with baseline commit c03c56b in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 39 metrics, 2 unstable metrics.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should align with the new "Go style" used in v2 for options - I think we decided to go with a simple public config struct

Comment on lines +64 to +69
// WithCodeActivation enable or disable Appsec. Can also be set using `DD_APPSEC_ENABLED`.
func WithCodeActivation(enable bool) StartOption {
return func(c *internalConfig.Config) {
c.CodeActivation = &enable
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose to hide this detail and hard-code c.CodeAction = true in public_appsec.Start() when called.

Suggested change
// WithCodeActivation enable or disable Appsec. Can also be set using `DD_APPSEC_ENABLED`.
func WithCodeActivation(enable bool) StartOption {
return func(c *internalConfig.Config) {
c.CodeActivation = &enable
}
}

A user should just write appsec.Start(cfg) to be able to start ASM with this option explicitly set.

Comment on lines +57 to +62
// WithRCActive enable or disable Remote Configuration for Appsec Datadog feature.
func WithRCActive(enable bool) StartOption {
return func(c *internalConfig.Config) {
c.RCEnabled = enable
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any usefulness for this. ASM without RC doesn't make sense, as RC brings all the protection features, and protection features are our main ASM value.

Comment on lines +168 to +171
if !tracer.IsUpAndRunning() {
tracerNotStarted.Do(func() { log.Error("appsec: tracer not started. appsec won't start. Please use tracer.Start() first") })
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT of doing it the other way around: asking public_appsec.Start users to do it before tracer.Start so that we can just accept the first config being started with. Today's implementation restarts when private_appsec.Start is called multiple times.

appsec.Start(cfg1)
tracer.Start(cfg2)

or even simpler for this first iteration:

tracer.Start(tracer.WithAppSecConfig(cfg))

// and enforces to have AppSec disabled.
enabled, set, err := config.IsEnabled()
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't read the full logic, but here is what's important: DD_APPSEC_ENABLED=false must always disable AppSec, no matter what else is trying to enable it. So code activation + DD_APPSEC_ENABLED=false => appsec disabled.

Copy link

This PR is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale Stuck for more than 1 month label Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs stale Stuck for more than 1 month
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants