Skip to content

contrib/envoyproxy: envoy external processing support#2895

Merged
eliottness merged 16 commits into
mainfrom
flavien/service-extensions
Dec 16, 2024
Merged

contrib/envoyproxy: envoy external processing support#2895
eliottness merged 16 commits into
mainfrom
flavien/service-extensions

Conversation

@e-n-0

@e-n-0 e-n-0 commented Sep 27, 2024

Copy link
Copy Markdown
Member

Motivation

This is the part 1 PR to support Envoy's External Processing.
You can find all related document for this implementation in Confluence ASM - GCP Services Extensions.
You can find the part 2 of this PR here.

What does this PR do?

This PR adds a new gRPC Interceptor (StreamServerInterceptor) to support the interception of ext_proc v3 calls to gRPC server. When the interceptor is applied, all messages of the external processing protocol are instrumented without returning an handle to the original server code. The implementation of a server using this instrumentation can be found in the part 2.

The implementation includes:

  • Analysing synchronously HTTP Requests and Responses data (headers, ip, path, host, status code)
  • Blocking requests (supporting blocking with content-type and redirect)
  • Some refacto of existing code to handle more easily crafted requests without an actual valid http.Request object.

Tests

This PR includes unit testing in the envoy_tests.go, simulating scenarios of malicious or benign requests, validating span tags, security events and blocking results.

System-tests have been implemented on this PR. A new external-processing scenario has been added in the golang stage.

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.

Unsure? Have a question? Request a review!

@DataDog DataDog deleted a comment from datadog-datadog-prod-us1 Bot Sep 27, 2024
@DataDog DataDog deleted a comment from datadog-datadog-prod-us1 Bot Sep 27, 2024
@DataDog DataDog deleted a comment from datadog-datadog-prod-us1 Bot Sep 27, 2024
@DataDog DataDog deleted a comment from datadog-datadog-prod-us1 Bot Sep 27, 2024
@DataDog DataDog deleted a comment from datadog-datadog-prod-us1 Bot Sep 27, 2024
@DataDog DataDog deleted a comment from datadog-datadog-prod-us1 Bot Sep 27, 2024
@e-n-0
e-n-0 force-pushed the flavien/service-extensions branch 7 times, most recently from fcbd354 to a587a09 Compare September 27, 2024 13:33
@pr-commenter

pr-commenter Bot commented Sep 27, 2024

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2024-12-16 13:53:07

Comparing candidate commit bece5b0 in PR branch flavien/service-extensions with baseline commit a8665eb in branch main.

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

@e-n-0
e-n-0 force-pushed the flavien/service-extensions branch 16 times, most recently from 4134743 to a96cc2a Compare September 30, 2024 15:26
@eliottness eliottness changed the title appsec: envoy external processing support contrib/envoyproxy: envoy external processing support Nov 12, 2024
@eliottness
eliottness force-pushed the flavien/service-extensions branch from 0929de5 to e3bb1e5 Compare November 13, 2024 16:14
Comment thread contrib/envoyproxy/envoy/envoy.go Outdated
Comment thread contrib/envoyproxy/envoy/envoy.go Outdated
Comment thread contrib/envoyproxy/envoy/envoy.go Outdated
Comment thread contrib/envoyproxy/envoy/fakehttp.go Outdated
Comment thread contrib/envoyproxy/envoy/fakehttp.go Outdated
Comment thread contrib/envoyproxy/envoy/fakehttp.go Outdated
Comment thread contrib/envoyproxy/envoy/fakehttp.go Outdated
Comment thread contrib/envoyproxy/envoy/envoy.go Outdated
Comment thread contrib/envoyproxy/envoy/envoy_test.go Outdated
Comment thread contrib/envoyproxy/envoy/envoy.go Outdated
@e-n-0
e-n-0 force-pushed the flavien/service-extensions branch from c7063d8 to b0844b8 Compare November 28, 2024 14:59
@e-n-0
e-n-0 requested a review from rarguelloF December 11, 2024 10:09
@e-n-0
e-n-0 force-pushed the flavien/service-extensions branch from b0844b8 to 961d73d Compare December 11, 2024 10:14
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Dec 11, 2024

Copy link
Copy Markdown

Datadog Report

Branch report: flavien/service-extensions
Commit report: 2cbd26c
Test service: dd-trace-go

✅ 0 Failed, 5112 Passed, 70 Skipped, 2m 53.79s Total Time

Comment thread contrib/envoyproxy/go-control-plane/envoy.go Outdated
Comment on lines +16 to +29
// Create a listener for the server.
ln, err := net.Listen("tcp", ":50051")
if err != nil {
log.Fatal(err)
}

// Create the server interceptor using the envoy go control plane package.
si := go_control_plane.StreamServerInterceptor()

// Initialize the grpc server as normal, using the envoy server interceptor.
s := grpc.NewServer(grpc.StreamInterceptor(si))

// ... register your services

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add a more "real-world" like example? similar to https://github.com/envoyproxy/go-control-plane/blob/main/examples/dyplomat/main.go#L43-L53

(currently this example is just a generic grpc server without any envoyproxy stuff)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I applied change in 22d7095
Tell me if that is looking good for you 😄

Comment thread contrib/envoyproxy/go-control-plane/envoy.go Outdated
}
}()

for {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I find this pattern a little bit odd for an interceptor / middleware.

Since it seems this is pretty much specifically intended to override the behaviour of ext_procv3.ExternalProcessorServer.Process, have you considered exporting this functionality as an implementation of this interface instead of a middleware? This way, users could just do:

import envoytrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/envoyproxy/go-control-plane"

// srv would be the user provided implementation of `ext_procv3.ExternalProcessorServer`
appsecBlockSrv := envoytrace.AppsecBlockingProcessorServer(srv) // internally you would call srv.Process() when the request is not blocked
ext_procv3.RegisterExternalProcessorServer(grpcServer, appsecBlockSrv)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed it in 22d7095
Is that what you were thinking of?

Comment thread contrib/envoyproxy/go-control-plane/envoy.go Outdated
Comment thread contrib/envoyproxy/go-control-plane/envoy.go Outdated
@e-n-0
e-n-0 requested a review from rarguelloF December 11, 2024 16:28

@rarguelloF rarguelloF left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! thanks for your patience! 😄 @e-n-0

@darccio darccio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving this PR with some nits (only apply if you want).

Comment thread contrib/envoyproxy/go-control-plane/envoy.go Outdated
Comment thread contrib/envoyproxy/go-control-plane/envoy.go
Comment thread contrib/envoyproxy/go-control-plane/envoy.go Outdated
Comment thread contrib/envoyproxy/go-control-plane/envoy.go Outdated
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 appsec

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants