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

feat: credential injector impl #30850

Merged
merged 93 commits into from
Apr 10, 2024

Conversation

zhaohuabing
Copy link
Member

@zhaohuabing zhaohuabing commented Nov 13, 2023

Implementation for the credential injector HTTP filter.
This PR includes the implementation of the Credential Injector filter and the Generic extension type. The oauth2 extension type will be in a follow-up pR.

Related: #27769

Sponsor: @kyessenov kindly offered to be the sponsor of this new filter.

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

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: #30850 was opened by zhaohuabing.

see: more, trace.

@zhaohuabing zhaohuabing changed the title credential injector impl feat: credential injector impl Nov 13, 2023
@zhaohuabing zhaohuabing marked this pull request as draft November 13, 2023 17:08
@zhaohuabing zhaohuabing force-pushed the credential_injector_filter_impl branch 7 times, most recently from 1350725 to 78d5e62 Compare November 15, 2023 05:12
@zhaohuabing

This comment was marked as outdated.

@zhaohuabing zhaohuabing marked this pull request as ready for review November 16, 2023 05:02
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.

Small API comment.
RE doc errors, I assume it is due to linking to "not-implemented-hide" protos.

@zhaohuabing zhaohuabing force-pushed the credential_injector_filter_impl branch 2 times, most recently from b829c04 to b93e805 Compare November 20, 2023 21:45
@adisuissa
Copy link
Contributor

Assigning Kuat as code-owner.
/assign @kyessenov

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.

Thanks!
Left a small suggestion on the API, but otherwise the API LGTM.

@zhaohuabing zhaohuabing force-pushed the credential_injector_filter_impl branch 5 times, most recently from 887b67b to 21934d7 Compare November 28, 2023 05:57
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
@zhaohuabing
Copy link
Member Author

/retest

@zhaohuabing
Copy link
Member Author

zhaohuabing commented Apr 2, 2024

After discussing with @wbpcode, we think the initialization process can be handled in individual credential extensions. This means the filter only needs to call the inject method.

  • The oauth2 credential extension/or other possible similar extensions manage the initialization of credentials on their own, just like how generic extension handles SDS secrets.
    • It retrieves the credentials from the OAuth2 server through the client credential flow.
    • The received credentials are stored in TLS (Thread Local Storage) for accessibility by worker threads.
  • During the decodeHeaders stage, the credential injector filter simply calls the inject method of the extensions to inject the credentials.

@kyessenov I believe you suggested a similar approach before?

If we're all in agreement with this approach, I'll proceed with updating the current implementation as outlined above.

@kyessenov
Copy link
Contributor

Sounds reasonable. The details are easier to work out once you have an implementation for oauth2. All we really need is to be able to pause a request, and let the extension handle the job itself (e.g. no explicit thread management in this filter).

@zhaohuabing
Copy link
Member Author

All we really need is to be able to pause a request, and let the extension handle the job itself (e.g. no explicit thread management in this filter).

I'm thinking just failing the request and letting the client decide the next step(fail, retry, etc.) if the extension fails to initialize the credentials, like what we have done with the generic extension(SDS).

By this way, we can decouple the filter and the extension's credential initialization/retry logic.

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
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 update. It's much simpler (and better) now. Fix the tests and CI, then it is ready for final review.

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
@zhaohuabing
Copy link
Member Author

/retest

@phlax
Copy link
Member

phlax commented Apr 8, 2024

no point retesting atm - test certs are currently broken (#33389)

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 update. It's near to there. Only some minor comments are added to the implementation details.

Comment on lines +13 to +20
class MockSecretReader : public Http::InjectedCredentials::Common::SecretReader {
public:
MockSecretReader(const std::string& secret) : secret_(secret){};
const std::string& credential() const override { return secret_; }

private:
const std::string secret_;
};
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think it would be better to mock the CredentialInjector rather than to mock the SecretReader. Because the filter actually only use the CredentialInjector and the SecretReader is only part of implementation of GenericCredentialInjector.

@wbpcode
Copy link
Member

wbpcode commented Apr 9, 2024

/wait

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

wrap tests in anonymous namespace

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

address comments

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
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.

LGTM. Thanks so much for your great works and paying of so long time.

@wbpcode wbpcode merged commit 5f68428 into envoyproxy:main Apr 10, 2024
54 checks passed
@zhaohuabing
Copy link
Member Author

Thank you @kyessenov @lizan @adisuissa @wbpcode for helping on reviews and all the great feedback. I really appreciate it.

alyssawilk pushed a commit to alyssawilk/envoy that referenced this pull request Apr 29, 2024
* credential injector impl

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

---------

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Co-authored-by: phlax <phlax@users.noreply.github.com>
Co-authored-by: Adi (Suissa) Peleg <adip@google.com>
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.

8 participants