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

Credential Injector Filter: OAuth2 client credential extension #33702

Merged
merged 55 commits into from
May 9, 2024

Conversation

vikaschoudhary16
Copy link
Contributor

Commit Message:
This PR is follow up to #30850 and is adding oauth2(client credential grant) extension. At a high level, oauth2 extension has TokenProvider which runs on main thread to fetch token from oauth server and sets tls slot with the received token. All worker threads then access this token from tls to inject requestHeaders during decodeHeaders.

Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
@vikaschoudhary16 vikaschoudhary16 marked this pull request as draft April 19, 2024 12:10
@@ -3,464 +3,421 @@ EXTENSIONS = {
#
# Access loggers
#

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, I will fix unnecessary formatting.

Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @adisuissa
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #33702 was synchronize by vikaschoudhary16.

see: more, trace.

@vikaschoudhary16 vikaschoudhary16 marked this pull request as ready for review April 24, 2024 10:55
@vikaschoudhary16 vikaschoudhary16 marked this pull request as draft April 24, 2024 11:32
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
@vikaschoudhary16 vikaschoudhary16 marked this pull request as ready for review April 27, 2024 03:09
@vikaschoudhary16
Copy link
Contributor Author

I will work on coverage and adding docs, meanwhile early feedback is much appreciated. @kyessenov @wbpcode

Comment on lines 103 to 106
timer_ = dispatcher_->createTimer([this]() -> void { asyncGetAccessToken(); });
ENVOY_LOG(debug, "onGetAccessTokenSuccess: Token fetched successfully, expires in {} seconds.",
expires_in.count());
timer_->enableTimer(expires_in / 2);
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 the things about timer could be simper. You completely needn't create the timer again and again. You can only create one and enable/disable it according your requirement here.

Copy link
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

This look great overall. Only a comment about the retry timer. Thanks for working on this.

@wbpcode
Copy link
Member

wbpcode commented Apr 29, 2024

/wait

Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Copy link
Member

@phlax phlax left a comment

Choose a reason for hiding this comment

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

thanks for iterating @vikaschoudhary16

a bunch of docs nits, but otherwise lgtm

Copy link
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Thanks for you quick response and update. Some comments are added. Please note the possible lifetime problem of the in-flight-request.

return absl::NotFoundError("Failed to get oauth2 token from token provider");
}

headers.setCopy(Envoy::Http::CustomHeaders::get().Authorization, token);
Copy link
Member

Choose a reason for hiding this comment

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

nit: setReferenceKey()

Comment on lines 55 to 58
thread_local_cluster->httpAsyncClient().send(
std::move(msg), *this,
Envoy::Http::AsyncClient::RequestOptions().setTimeout(
std::chrono::milliseconds(PROTOBUF_GET_MS_REQUIRED(uri_, timeout))));
Copy link
Member

@wbpcode wbpcode May 2, 2024

Choose a reason for hiding this comment

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

What will happen if the client was destructed because the xDS updating and then the a response is received from remote server?
I think you may need to store the in-flight-request here and use the result to cancel any pending request when the client is destructed.

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 pointing out. Addressed it.

Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
@phlax
Copy link
Member

phlax commented May 3, 2024

/docs

Copy link

Docs for this Pull Request will be rendered here:

https://storage.googleapis.com/envoy-pr/33702/docs/index.html

The docs are (re-)rendered each time the CI envoy-presubmit (precheck docs) job completes.

🐱

Caused by: a #33702 (comment) was created by @phlax.

see: more, trace.

phlax
phlax previously approved these changes May 3, 2024
Copy link
Member

@phlax phlax left a comment

Choose a reason for hiding this comment

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

docs lgtm, thanks again @vikaschoudhary16 for working on this

handing over to @wbpcode and @adisuissa for signoff

Copy link
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Thanks for your hard work. The code is fine to me. Most comments are for tests.

Comment on lines 3 to 15

#include "test/mocks/event/mocks.h"
#include "test/mocks/server/factory_context.h"
#include "test/mocks/thread_local/mocks.h"
#include "test/mocks/upstream/cluster_manager.h"

#include "gtest/gtest.h"

namespace Envoy {
namespace Extensions {
namespace Http {
namespace InjectedCredentials {
namespace OAuth2 {
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 all these oauth2 tests should be placed in the test/extensions/http/credential_injector/oauth2?

And seems the unit tests are pretty simple (although the integration tests are great)

Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

/lgtm api

@repokitteh-read-only repokitteh-read-only bot removed the api label May 6, 2024
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
@vikaschoudhary16 vikaschoudhary16 requested a review from wbpcode May 7, 2024 08:16
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
Signed-off-by: Vikas Choudhary <choudharyvikas16@gmail.com>
@wbpcode wbpcode enabled auto-merge (squash) May 9, 2024 01:38
@wbpcode wbpcode merged commit 1d180ac into envoyproxy:main May 9, 2024
52 of 53 checks passed
@vikaschoudhary16
Copy link
Contributor Author

Thanks a lot @wbpcode @adisuissa @phlax for guidance and feedback. really appreciate!!

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.

4 participants