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

Add auth support for collector #2570

Closed
wants to merge 3 commits into from
Closed

Add auth support for collector #2570

wants to merge 3 commits into from

Conversation

jpkrohling
Copy link
Contributor

Which problem is this PR solving?

  • The first step towards the multi-tenancy solution: add auth support for both agent and collector.

Short description of the changes

Testing the Agent part from this PR

Start the OpenTelemetry Collector with this configuration:

receivers:
  jaeger:
    protocols:
      grpc:
        tls_settings:
          cert_file: ./local/self-signed.pem
          key_file: ./local/self-signed-key.pem
        auth:
          oidc:
            issuer_url: https://dev-zkkhf874.eu.auth0.com/
            audience: http://auth.example.com

exporters:
  logging:

service:
  pipelines:
    traces:
      receivers:
        - jaeger
      processors: []
      exporters:
        - logging

And the agent from this PR with the following flags:

"--auth.bearer.token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImxiWmJrd2JHUXlrWGdub09mRXNRNCJ9.eyJpc3MiOiJodHRwczovL2Rldi16a2toZjg3NC5ldS5hdXRoMC5jb20vIiwic3ViIjoiMUpEUmZJMm43c0JhNnhvMkQ2VEJSVnpjbGs5M25uVUZAY2xpZW50cyIsImF1ZCI6Imh0dHA6Ly9hdXRoLmV4YW1wbGUuY29tIiwiaWF0IjoxNjAyNzU0NDU0LCJleHAiOjE2MDI4NDA4NTQsImF6cCI6IjFKRFJmSTJuN3NCYTZ4bzJENlRCUlZ6Y2xrOTNublVGIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.R128iWgn68uW_dPOifsYSRI2Yon4_CU-8E8gJeAvoIVQCka3u0S5RZ8C_I8zvLjdcuKePO9PjOp2vh9VcntXAZtc0II3D_K-fAXEsYE6aVM5taJFXnNwb7UAje0yfvMChXTVHfjcJkW8c-i3OrilJ9Ab-8ZSLDaR_a6cuT2c8BGj57tmDV2sWVJwe-dUCOzIPdwocQNK-pC9RsDTyq2uUMpqTRulyKlp51u2PtLd7tBjW1yZokoZcAlsVb4dJm4ZCutYZ4_tkeYSojZKw6JhhSDxcKvTAY4Y7nrMh2pGgjZbll1yzlsL1TyvD0PUWwM24wlDln5O0l4nU1Dzw6F8Wg",
"--reporter.grpc.host-port=localhost:14250",
"--reporter.grpc.tls.enabled=true",
"--reporter.grpc.tls.ca=/home/jpkroehling/Projects/src/github.com/open-telemetry/opentelemetry-collector/local/ca.pem",

Finally, send a trace with, for instance, Jaeger's tracegen:

$ go run ./cmd/tracegen/ -traces 1 

Testing the Collector part of this PR

Start the Jaeger Collector with the following flags:

"--collector.auth.oidc.client-id=http://auth.example.com",
"--collector.auth.oidc.issuer-url=https://dev-zkkhf874.eu.auth0.com/",
"--collector.grpc.tls.cert=/home/jpkroehling/Projects/src/github.com/open-telemetry/opentelemetry-collector/local/self-signed.pem",
"--collector.grpc.tls.key=/home/jpkroehling/Projects/src/github.com/open-telemetry/opentelemetry-collector/local/self-signed-key.pem",
"--collector.grpc.tls.enabled=true",

And an OpenTelemetry Collector with this config:

receivers:
  otlp/noauth:
    protocols:
      grpc:
        endpoint: localhost:56680

exporters:
  jaeger/auth:
    endpoint: localhost:14250
    ca_file: ./local/ca.pem
    per_rpc_auth:
      type: bearer
      bearer_token: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImxiWmJrd2JHUXlrWGdub09mRXNRNCJ9.eyJpc3MiOiJodHRwczovL2Rldi16a2toZjg3NC5ldS5hdXRoMC5jb20vIiwic3ViIjoiMUpEUmZJMm43c0JhNnhvMkQ2VEJSVnpjbGs5M25uVUZAY2xpZW50cyIsImF1ZCI6Imh0dHA6Ly9hdXRoLmV4YW1wbGUuY29tIiwiaWF0IjoxNjAyNzU0NDU0LCJleHAiOjE2MDI4NDA4NTQsImF6cCI6IjFKRFJmSTJuN3NCYTZ4bzJENlRCUlZ6Y2xrOTNublVGIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.R128iWgn68uW_dPOifsYSRI2Yon4_CU-8E8gJeAvoIVQCka3u0S5RZ8C_I8zvLjdcuKePO9PjOp2vh9VcntXAZtc0II3D_K-fAXEsYE6aVM5taJFXnNwb7UAje0yfvMChXTVHfjcJkW8c-i3OrilJ9Ab-8ZSLDaR_a6cuT2c8BGj57tmDV2sWVJwe-dUCOzIPdwocQNK-pC9RsDTyq2uUMpqTRulyKlp51u2PtLd7tBjW1yZokoZcAlsVb4dJm4ZCutYZ4_tkeYSojZKw6JhhSDxcKvTAY4Y7nrMh2pGgjZbll1yzlsL1TyvD0PUWwM24wlDln5O0l4nU1Dzw6F8Wg

service:
  pipelines:
    traces:
      receivers:
        - otlp/noauth
      processors: []
      exporters:
        - jaeger/auth

And finally, send a trace with, for instance, OpenTelemetry's tracegen:

$ go run . -otlp-endpoint localhost:56680 -otlp-insecure -traces 1 

Negative tests

Just change the bearer token to something else in either of the cases.

Signed-off-by: Juraci Paixão Kröhling juraci@kroehling.de

@jpkrohling jpkrohling requested a review from a team as a code owner October 15, 2020 15:40
@jpkrohling
Copy link
Contributor Author

@yurishkuro are the lint problems known? I don't think they are related to this PR.

@yurishkuro
Copy link
Member

you're upgrading grpc dependencies (not recommended as part of functional PRs), so the lint errors are related to this PR.

@jpkrohling
Copy link
Contributor Author

I changed the code to not require adding the OpenTelemetry Collector as a dependency to the main module.

Verified

This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>

Verified

This commit was created on github.com and signed with GitHub’s verified signature.
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
@codecov
Copy link

codecov bot commented Oct 23, 2020

Codecov Report

Merging #2570 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2570      +/-   ##
==========================================
+ Coverage   95.31%   95.33%   +0.01%     
==========================================
  Files         208      208              
  Lines        9281     9294      +13     
==========================================
+ Hits         8846     8860      +14     
+ Misses        356      355       -1     
  Partials       79       79              
Impacted Files Coverage Δ
cmd/agent/app/reporter/grpc/builder.go 95.00% <ø> (ø)
cmd/agent/app/reporter/grpc/flags.go 100.00% <100.00%> (ø)
cmd/collector/app/builder_flags.go 100.00% <100.00%> (ø)
plugin/storage/integration/integration.go 77.90% <0.00%> (+0.55%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f954fe...8542811. Read the comment docs.

flags.String(authOIDCIssuerURL, "", "the OpenID Connect server to validate the incoming auth tokens")
flags.String(authOIDCIssuerCAPath, "", "the path to the issuer's CA")
flags.String(authOIDCClientID, "", "this Jaeger's client ID")
flags.String(authOIDCUsernameClaim, "", "the username claim in the token, in case the 'sub' field shouldn't be used")
Copy link
Contributor

@albertteoh albertteoh Oct 23, 2020

Choose a reason for hiding this comment

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

s/shouldn't be/isn't being/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure -- the sub field is always used, unless this flag is set. What's the right way to convey that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see -- maybe something like "The username claim in the token which, if set, overrides the 'sub' field"? (although, I'm not sure what the 'sub' field refers to :P)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sub is a standard field in JWT (JSON Web Tokens), indicating the "subject" (username).

Copy link
Contributor Author

@jpkrohling jpkrohling Oct 23, 2020

Choose a reason for hiding this comment

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

How about this?

the claim in the token that should be used for the username instead of the default 'sub' field.

@albertteoh
Copy link
Contributor

LGTM, just had a few nit comments. I'll defer approval to maintainers.

Thanks for the nice testing instructions! I tried "Testing the Agent part from this PR" and got this error in Jaeger agent:

{"level":"error","ts":1603448778.8667269,"caller":"grpc/reporter.go:74","msg":"Could not send spans over gRPC","error":"rpc error: code = Unknown desc = authentication didn't succeed"

The "Testing the Collector part of this PR" instructions seemed to work though, saw this in OTEL agent (with logging exporter added):

2020-10-23T21:39:04.636+1100	INFO	loggingexporter/logging_exporter.go:296	TraceExporter	{"#spans": 2}

It's quite likely I stuffed something up in the first test, just thought to inform you anyway.

@jpkrohling
Copy link
Contributor Author

{"level":"error","ts":1603448778.8667269,"caller":"grpc/reporter.go:74","msg":"Could not send spans over gRPC","error":"rpc error: code = Unknown desc = authentication didn't succeed"

Did you use the token from the instructions, or did you setup your own Auth0 application? If you are using the token from the example, it's likely expired by now.

Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
if cfg.GRPC != nil && len(cOpts.AuthOIDCIssuerURL) > 0 {
// TODO: how can we log a warning if the user fails to specify a conditionally required flag?
// if authOIDCIssuerURL is set, authOIDCClientID has to be set as well (and vice-versa).
cfg.GRPC.Auth = &configauth.Authentication{
Copy link
Member

Choose a reason for hiding this comment

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

Unsure if it's possible atm, but I feel like an unsigned token mode would be valuable. If you didn't want to muck with oidc but just wanted to generate some simple tokens for multitenancy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's record this as an issue. I don't think people would actually do that in production environments, but I could be wrong.

@@ -96,6 +110,14 @@ func AddFlags(flags *flag.FlagSet) {
func AddOTELJaegerFlags(flags *flag.FlagSet) {
flags.String(CollectorHTTPHostPort, ports.PortToHostPort(ports.CollectorHTTP), "The host:port (e.g. 127.0.0.1:14268 or :14268) of the collector's HTTP server")
flags.String(CollectorGRPCHostPort, ports.PortToHostPort(ports.CollectorGRPC), "The host:port (e.g. 127.0.0.1:14250 or :14250) of the collector's GRPC server")

// auth-related flags
flags.String(authOIDCIssuerURL, "", "the OpenID Connect server to validate the incoming auth tokens")
Copy link
Member

Choose a reason for hiding this comment

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

won't these flags start showing up on the Jaeger collector but be unsupported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They shouldn't, as they are part of AddOTELJaegerFlags.

Copy link
Member

@joe-elliott joe-elliott Oct 23, 2020

Choose a reason for hiding this comment

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

AddOtelJaegerFlags is called from the normal AddFlags here:

https://github.com/jaegertracing/jaeger/blob/master/cmd/collector/app/builder_flags.go#L91

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are absolutely right:

$ go run ./cmd/collector/ --help | grep oidc
2020/10/23 22:13:16 maxprocs: Leaving GOMAXPROCS=12: CPU quota undefined
      --collector.auth.oidc.client-id string            this Jaeger's client ID
      --collector.auth.oidc.groups-claim string         the claim containing the group membership, where each group is considered a tenant. When absent, multi-tenancy is disabled.
      --collector.auth.oidc.issuer-ca-path string       the path to the issuer's CA
      --collector.auth.oidc.issuer-url string           the OpenID Connect server to validate the incoming auth tokens
      --collector.auth.oidc.username-claim string       the claim in the token that should be used for the username instead of the default 'sub' field

I should probably suppress the flags from the current collector.

@albertteoh
Copy link
Contributor

{"level":"error","ts":1603448778.8667269,"caller":"grpc/reporter.go:74","msg":"Could not send spans over gRPC","error":"rpc error: code = Unknown desc = authentication didn't succeed"

Did you use the token from the instructions, or did you setup your own Auth0 application? If you are using the token from the example, it's likely expired by now.

Yup, I was using the token from the instructions, and probably the cause of the error.

@jpkrohling jpkrohling marked this pull request as draft October 27, 2020 19:53
@jpkrohling
Copy link
Contributor Author

I'm changing this to a draft PR, as we probably want to figure out our OpenTelemetry strategy before merging this here.

@jpkrohling
Copy link
Contributor Author

I'm closing this, as we'll likely not need this if we move the direction we agreed.

@jpkrohling jpkrohling closed this Nov 5, 2020
@jpkrohling jpkrohling deleted the jpkrohling/multitenancy-add-token-auth-support branch July 28, 2021 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants