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

[extension/basicauth] Implement configauth.ClientAuthenticator #8847

Merged
merged 14 commits into from
Apr 19, 2022

Conversation

neelayu
Copy link
Contributor

@neelayu neelayu commented Mar 25, 2022

Description:
Enhancement: basicauth extension now supports client auth.

Testing: Manual and Unit Tests added.

@neelayu neelayu requested a review from a team March 25, 2022 12:22
@neelayu neelayu requested a review from jpkrohling as a code owner March 25, 2022 12:22
@jpkrohling
Copy link
Member

cc @gouthamve

@@ -27,16 +27,17 @@ receivers:
processors:

exporters:
logging:
logLevel: debug
otlphttp:
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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:

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()
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this for gRPC?

Copy link
Member

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)
Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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.

Copy link
Contributor Author

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.

@neelayu
Copy link
Contributor Author

neelayu commented Apr 14, 2022

@jpkrohling can you give it a one more glance at this. Thanks

@@ -27,16 +27,17 @@ receivers:
processors:

exporters:
logging:
logLevel: debug
otlphttp:
Copy link
Member

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:

func (b *BearerTokenAuth) PerRPCCredentials() (credentials.PerRPCCredentials, error) {
return &PerRPCAuth{
metadata: map[string]string{"authorization": b.bearerToken()},
}, nil
}

extension/basicauthextension/README.md Outdated Show resolved Hide resolved
extension/basicauthextension/extension.go Outdated Show resolved Hide resolved
extension/basicauthextension/extension.go Outdated Show resolved Hide resolved
}

func (ba *basicAuth) PerRPCCredentials() (creds.PerRPCCredentials, error) {
return nil, nil
Copy link
Member

Choose a reason for hiding this comment

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

Yes

extension/basicauthextension/extension_test.go Outdated Show resolved Hide resolved
extension/basicauthextension/extension_test.go Outdated Show resolved Hide resolved
extension/basicauthextension/extension_test.go Outdated Show resolved Hide resolved
extension/basicauthextension/extension.go Show resolved Hide resolved
@neelayu
Copy link
Contributor Author

neelayu commented Apr 15, 2022

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:

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.

Copy link
Member

@jpkrohling jpkrohling left a 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.

extension/basicauthextension/config.go Outdated Show resolved Hide resolved
extension/basicauthextension/extension.go Outdated Show resolved Hide resolved
extension/basicauthextension/extension.go Show resolved Hide resolved
extension/basicauthextension/extension.go Show resolved Hide resolved
extension/basicauthextension/extension.go Show resolved Hide resolved
@jpkrohling jpkrohling changed the title Make basicauth implement configauth.ClientAuthenticator to authenticate outgoing http requests using basicauth [extension/basicauth] Implement configauth.ClientAuthenticator Apr 19, 2022
@jpkrohling jpkrohling merged commit e841b5e into open-telemetry:main Apr 19, 2022
@neelayu neelayu mentioned this pull request Apr 19, 2022
djaglowski added a commit that referenced this pull request Jul 23, 2024
…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]>
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.

5 participants