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

contrib/go-chi/chi: add appsec monitoring #1130

Merged
merged 5 commits into from
Jan 20, 2022
Merged

Conversation

Julio-Guerra
Copy link
Contributor

@Julio-Guerra Julio-Guerra commented Jan 18, 2022

  • Integrate AppSec into the existing contrib/go-chi/chi.v5 and contrib/go-chi/chi integrations.
  • Create a new integration for Chi v4 - copy/paste of the chi.v5 package.

Note that I tried using the http.TraceAndServe() function but it currently lacks the following features that I felt would be better in a separate PR:

  1. Configurable status code error tag
  2. Computing the resource name after the call to the HTTP handler (because it's not available before).

@Julio-Guerra Julio-Guerra added this to the 1.36.0 milestone Jan 18, 2022
@Julio-Guerra Julio-Guerra requested a review from a team as a code owner January 18, 2022 21:37
@Julio-Guerra Julio-Guerra requested a review from a team January 18, 2022 21:37
@Julio-Guerra Julio-Guerra marked this pull request as draft January 18, 2022 21:37
Base automatically changed from francois.mazeau/appsec-http-path-params to v1 January 19, 2022 14:19
@Julio-Guerra Julio-Guerra force-pushed the julio.guerra/appsec-chi branch from bc74f85 to 4e03b0f Compare January 19, 2022 14:22
@Julio-Guerra Julio-Guerra marked this pull request as ready for review January 19, 2022 15:05
contrib/go-chi/chi.v4/appsec.go Outdated Show resolved Hide resolved
contrib/go-chi/chi.v5/appsec.go Outdated Show resolved Hide resolved
Comment on lines +309 to +314
appsec.Start()
defer appsec.Stop()

if !appsec.Enabled() {
t.Skip("appsec disabled")
}
Copy link
Contributor

@gbbr gbbr Jan 20, 2022

Choose a reason for hiding this comment

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

For now, this API is only used internally, but consider that this form may be confusing if and when it becomes public API. I mean, this is what happens:

  1. AppSec gets started on line 309
  2. Line 312 checks if it's enabled and skips the test, even though it was never stopped.

I understand the fact that there is an explanation for this, and that Start might not actually start AppSec, but nevertheless it's confusing because a function like appsec.Start which returns no error is assumed to succeed. Perhaps returning an error from appsec.Start (let's say appsec.NotStarted or something more specific which includes the reason) would be more clear.

Nothing needed in this PR, just some random feedback.

Copy link
Contributor Author

@Julio-Guerra Julio-Guerra Jan 20, 2022

Choose a reason for hiding this comment

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

Yes, I'm aware of this weirdness, due to how AppSec gets enabled for now: you can start/stop it, but it actually starts only if DD_APPSEC_ENABLED is true, hence the separate IsEnabled() call.

Copy link
Contributor

@Hellzy Hellzy left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@Julio-Guerra Julio-Guerra merged commit a9f9352 into v1 Jan 20, 2022
@Julio-Guerra Julio-Guerra deleted the julio.guerra/appsec-chi branch January 20, 2022 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants