-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[extension/basicauth] Implement configauth.ClientAuthenticator
#8847
Conversation
cc @gouthamve |
@@ -27,16 +27,17 @@ receivers: | |||
processors: | |||
|
|||
exporters: | |||
logging: | |||
logLevel: debug | |||
otlphttp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about otlp
? It should be used whenever possible instead of otlphttp
, from what I understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently the intention is to support only http client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should then be clearly stated in the readme then. I'm sure I'm missing something obvious, but why can't this be used with gRPC? It would be similar to the bearer token auth, like this:
opentelemetry-collector-contrib/extension/bearertokenauthextension/bearertokenauth.go
Lines 71 to 75 in faf74e4
func (b *BearerTokenAuth) PerRPCCredentials() (credentials.PerRPCCredentials, error) { | |
return &PerRPCAuth{ | |
metadata: map[string]string{"authorization": b.bearerToken()}, | |
}, nil | |
} |
if err != nil { | ||
return fmt.Errorf("read htpasswd content: %w", err) | ||
} | ||
|
||
ba.userPassPair = buff.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right to assume that this is getting the username and password from the htpasswd file? If so, that's not right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was my bad. I assumed something else. I have reverted this block.
} | ||
|
||
func (ba *basicAuth) PerRPCCredentials() (creds.PerRPCCredentials, error) { | ||
return nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you not implementing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for gRPC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
Inline: creds, | ||
}, | ||
}) | ||
assert.NotNil(t, ext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a require
: everything that is required for setting up the stage of the test should use require
. When you are exercising the test subject, use assert
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip. Reworked.
} | ||
|
||
func newExtension(cfg *Config) (configauth.ServerAuthenticator, error) { | ||
func newExtension(cfg *Config) (*basicAuth, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would prefer the factory to determine whether it needs a client authenticator or a server authenticator (see createExtension
in the factory.go).
I also think this extension has two different sets of configuration options:
- username and password for the client authenticator, with only one subject
- htpasswd for the server authenticator, with potentially multiple subjects
So, if both the username and password are set, this takes the shape of a client authenticator, otherwise it's a server authenticator. The extension cannot be both at the same time. As an operator, I would find it confusing to have one extension instance with the two facets at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points. I have incorporated that logic. I have also enforced that this extention will only act as either a client auth or server auth. If a user needs both, there should be two. Kindly review.
Co-authored-by: Stepan Rakitin <[email protected]>
@jpkrohling can you give it a one more glance at this. Thanks |
@@ -27,16 +27,17 @@ receivers: | |||
processors: | |||
|
|||
exporters: | |||
logging: | |||
logLevel: debug | |||
otlphttp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should then be clearly stated in the readme then. I'm sure I'm missing something obvious, but why can't this be used with gRPC? It would be similar to the bearer token auth, like this:
opentelemetry-collector-contrib/extension/bearertokenauthextension/bearertokenauth.go
Lines 71 to 75 in faf74e4
func (b *BearerTokenAuth) PerRPCCredentials() (credentials.PerRPCCredentials, error) { | |
return &PerRPCAuth{ | |
metadata: map[string]string{"authorization": b.bearerToken()}, | |
}, nil | |
} |
} | ||
|
||
func (ba *basicAuth) PerRPCCredentials() (creds.PerRPCCredentials, error) { | ||
return nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
Co-authored-by: Juraci Paixão Kröhling <[email protected]>
You are correct. It is indeed similar to bearer auth. The only reason I did not implement it was because it was written HTTP Basic Auth in the readme before. But sure it works for gRPC as well. I have removed HTTP from the readme now and also implemented it for gRPC. Thank you for reviewing it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, just a couple of minor comments.
configauth.ClientAuthenticator
to authenticate outgoing http requests using basicauthconfigauth.ClientAuthenticator
…asicauth (#33941) **Description:** Updated the `README.md` for the Elasticsearch exporter to use `client_auth` in the `basicauth` extension configuration. Related PR: #8847 **Link to tracking Issue:** X **Testing:** X **Documentation:** X Co-authored-by: Daniel Jaglowski <[email protected]>
Description:
Enhancement:
basicauth
extension now supports client auth.Testing: Manual and Unit Tests added.