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

#229 Add OpenTelemetry Collector Server Auth Extensions to Receivers #2203

Merged
merged 35 commits into from
Jan 10, 2025

Conversation

aidanleuck
Copy link
Contributor

@aidanleuck aidanleuck commented Dec 2, 2024

PR Description

Adds server authentication support to otelcol.receivers.* that support the OpenTelemetry collector auth extension model. Some receivers are not wrappers of the collector so they are excluded from this PR.

Receivers that now support server auth:

  • Datadog
  • Jaeger
  • Otlp
  • Opencensus
  • Zipkin
  • Jaeger_Remote_Sampling
  • InfluxDB

Which issue(s) this PR fixes

Fixes #229

Notes to the Reviewer

TestAuthServer in auth_basic_test.go is consistently failing due to a race condition in startup. Any ideas or potential solutions to this problem would be appreciated. The auth_basic plugin appears to function as expected when running from the binary.

User interface for client auth has not changed.

PR Checklist

  • [ x ] CHANGELOG.md updated
  • [ x ] Documentation added
  • [ x ] Tests updated

@aidanleuck aidanleuck requested review from clayton-cornell and a team as code owners December 2, 2024 17:01
@CLAassistant
Copy link

CLAassistant commented Dec 2, 2024

CLA assistant check
All committers have signed the CLA.

@clayton-cornell clayton-cornell added the type/docs Docs Squad label across all Grafana Labs repos label Dec 9, 2024
@clayton-cornell
Copy link
Contributor

clayton-cornell commented Dec 9, 2024

@grafana/grafana-alloy-maintainers I am going to hold back on reviewing the doc input until after a technical code review has been completed. There are some questions I have about the way things are phrased in the docs that may be resolved with the code review.

@aidanleuck
Copy link
Contributor Author

aidanleuck commented Dec 10, 2024

@grafana/grafana-alloy-maintainers I am going to hold back on reviewing the doc input until after a technical code review has been completed. There are some questions I have about the way things are phrased in the docs that may be resolved with the code review.

Thanks for taking a look! Happy to clarify once the code review is complete.

@aidanleuck
Copy link
Contributor Author

Looks like some errors with the auth tests.

Yeah, I dug into why this test was failing for a couple of hours and my assessment was that it was an issue with the test infrastructure incorrectly reporting that the component is running. See auth_test.go and I have a detailed comment explaining what is happening. Do you have any suggestions or comments on how to wait for the underlying extension to be running on the host?

@mattdurham
Copy link
Collaborator

Will try to take a look at this but for full transparency most of the team is gonna be unavailable for a week or so due to the holidays.

@aidanleuck
Copy link
Contributor Author

Will try to take a look at this but for full transparency most of the team is gonna be unavailable for a week or so due to the holidays.

Not a problem, I'm not in any rush to get this PR merged. I did see a PR go through recently that added a /healthy endpoint to a component. I will try using that and let you know. Thanks for the help so far.

@aidanleuck
Copy link
Contributor Author

The latest commits should fix the issue with the race condition in auth_basic.go. I have also addressed the outstanding comments on the PR.

@@ -10,6 +10,8 @@ title: otelcol.auth.oauth2

`otelcol.auth.oauth2` exposes a `handler` that can be used by other `otelcol` components to authenticate requests using OAuth 2.0.

This extension only supports client authentication.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an extension to a component? Or do we mean component here?

@aidanleuck aidanleuck requested a review from a team as a code owner January 3, 2025 02:52
@aidanleuck
Copy link
Contributor Author

@clayton-cornell I have made the requested changes to the docs. Based on your previous feedback I also slightly modified each receiver's docs. Let me know if you would like any more changes.

@aidanleuck aidanleuck force-pushed the feature/add_auth_to_otlp_receiver branch from 3913159 to 4665aaf Compare January 3, 2025 03:02
Copy link
Contributor

@clayton-cornell clayton-cornell left a comment

Choose a reason for hiding this comment

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

Some really minor tweaks to the docs and they look OK to me.

Comment on lines 304 to 307
{{< admonition type="note" >}}
Not all OpenTelemetry Collector authentication plugins support receiver authentication.
Refer to the [documentation](https://grafana.com/docs/alloy/<ALLOY_VERSION>/reference/components/otelcol/) for each `otelcol.auth.*` component to determine its compatibility.
{{< /admonition >}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{{< admonition type="note" >}}
Not all OpenTelemetry Collector authentication plugins support receiver authentication.
Refer to the [documentation](https://grafana.com/docs/alloy/<ALLOY_VERSION>/reference/components/otelcol/) for each `otelcol.auth.*` component to determine its compatibility.
{{< /admonition >}}
{{< admonition type="note" >}}
Not all OpenTelemetry Collector authentication plugins support receiver authentication.
Refer to the [documentation](https://grafana.com/docs/alloy/<ALLOY_VERSION>/reference/components/otelcol/) for each `otelcol.auth.*` component to determine its compatibility.
{{< /admonition >}}

Removing extra space

@@ -11,7 +11,7 @@ title: otelcol.auth.basic
`otelcol.auth.basic` exposes a `handler` that can be used by other `otelcol`
components to authenticate requests using basic authentication.

This extension supports both server and client authentication.
This `component` supports both server and client authentication.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This `component` supports both server and client authentication.
This component supports both server and client authentication.

Ooops, my fault. I used the inline code syntax to emphasize in the previous comment.

@@ -11,7 +11,7 @@ title: otelcol.auth.bearer
`otelcol.auth.bearer` exposes a `handler` that can be used by other `otelcol`
components to authenticate requests using bearer token authentication.

This extension supports both server and client authentication.
This `component` supports both server and client authentication.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This `component` supports both server and client authentication.
This component supports both server and client authentication.

@@ -11,7 +11,7 @@ title: otelcol.auth.headers
`otelcol.auth.headers` exposes a `handler` that can be used by other `otelcol`
components to authenticate requests using custom headers.

This extension only supports client authentication.
This `component` only supports client authentication.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This `component` only supports client authentication.
This component only supports client authentication.

@@ -10,7 +10,7 @@ title: otelcol.auth.oauth2

`otelcol.auth.oauth2` exposes a `handler` that can be used by other `otelcol` components to authenticate requests using OAuth 2.0.

This extension only supports client authentication.
This `component` only supports client authentication.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This `component` only supports client authentication.
This component only supports client authentication.

@@ -12,7 +12,7 @@ title: otelcol.auth.sigv4
components to authenticate requests to AWS services using the AWS Signature Version 4 (SigV4) protocol.
For more information about SigV4 see the AWS documentation about [Signing AWS API requests][].

This extension only supports client authentication.
This `component` only supports client authentication.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This `component` only supports client authentication.
This component only supports client authentication.

@aidanleuck
Copy link
Contributor Author

aidanleuck commented Jan 4, 2025

Documentation changes have been implemented. However, the recent merge with the main branch seems to have caused a test failure. This pull request PR appears to be the culprit. The same test is also failing on the main branch. I wanted to flag this issue here to ensure the failure doesn't hinder the progress of this PR.

@clayton-cornell
Copy link
Contributor

@aidanleuck It's probably OK to ignore the failing test here. The Deploy pr preview will fail on forks. The macos test fail is not a mandatory pass to merge.

@grafana/grafana-alloy-maintainers over to someone on the dev team for code review

// authentication extensions to all of our components.
// Auth is a binding to an otelcol.auth.* component extension which handles
// authentication.
Auth *auth.Handler `alloy:"auth,attr,optional"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should name this to a authentication in both the var name and alloy name. This is so it doesnt overlap with authentication. Same with the documentation.

Copy link
Contributor Author

@aidanleuck aidanleuck Jan 9, 2025

Choose a reason for hiding this comment

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

What do you think about renaming the var name to Authentication but keeping the alloy name as auth? That way when using client auth or server auth the field is consistent.

client auth looks like this. We can't easily change this without breaking the user interface.

otelcol.exporter.otlp "otlp"{
  auth = <component>.handler
}

server auth would look like this if we changed auth to authentication.

otelcol.receiver.otlp "receiver"{
    authentication = <component>.handler
}

As a user I like the consistency between it being auth for both exporters and receivers. Let me know what you think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can live with that. Can you add a comment in the code saying why its that way?

}

// Configure the authentication if args.Auth is set.
var auth *otelconfigauth.Authentication
var authz *otelconfigauth.Authentication
Copy link
Collaborator

Choose a reason for hiding this comment

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

Var name feels like authorization.

Copy link
Collaborator

@mattdurham mattdurham left a comment

Choose a reason for hiding this comment

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

Code looks good, minor nits on var naming and alloy configuration naming.

if err != nil {
return err
} else if ext != nil {
Copy link
Contributor Author

@aidanleuck aidanleuck Jan 9, 2025

Choose a reason for hiding this comment

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

This merge conflict was already handled in this PR in the function createExtension() on line 388 of this file.

@mattdurham
Copy link
Collaborator

This is looking great. One last comment to add and I will merge. Likely will pull this into the RC candidate before release.

@aidanleuck
Copy link
Contributor Author

aidanleuck commented Jan 9, 2025

Comments addressed! I also changed the var name for client blocks from Auth to Authentication for consistency.

Copy link
Collaborator

@mattdurham mattdurham left a comment

Choose a reason for hiding this comment

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

lgtm thank you for the PR!

@mattdurham mattdurham enabled auto-merge (squash) January 10, 2025 14:15
@mattdurham mattdurham merged commit e8f5bcd into grafana:main Jan 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/docs Docs Squad label across all Grafana Labs repos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support auth for otelcol.receiver components
5 participants