Skip to content

OAuth2: add retry policy to the OAuth2 filter - #35262

Merged
wbpcode merged 22 commits into
envoyproxy:mainfrom
zhaohuabing:oauth2-retry
Aug 30, 2024
Merged

wbpcode merged 22 commits into
envoyproxy:mainfrom
zhaohuabing:oauth2-retry

Conversation

@zhaohuabing

@zhaohuabing zhaohuabing commented Jul 18, 2024 •

Copy link
Copy Markdown
Member

Commit Message: Add retry policy to the OAuth2 filter to avoid failing to call the Authorization server.
Additional Description:

Some EG users reported that Authorization servers may timeout TCP connections in the pool but only send an RST when Envoy reuses a connection to send a request to the Authorization server again. This behavior causes the authentication flow to fail. Implementing retries can mitigate this issue.

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

Related EG issue: envoyproxy/gateway#3178

Caveat: I'm not very experienced in c++, so some of my implementation may not adhere to the best practice of c++ or the conventions of Envoy codebase. I welcome any feedback and will consider it a valuable opportunity to learn the right way to contribute to Envoy. Thank you!

@repokitteh-read-only

Copy link
Copy Markdown

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

🐱

Caused by: #35262 was opened by zhaohuabing.

see: more, trace.

@zhaohuabing
zhaohuabing marked this pull request as draft July 18, 2024 14:06
@zhaohuabing

Copy link
Copy Markdown
Member Author

Hi @envoyproxy/api-shepherds, I have added a retry_policy at the top level of the OAuth2 API for the following reasons:

  • It doesn't require deprecating the existing token_endpoin and adding a new one with retry_policy in it.
  • It's future-proof, allowing us to reuse the same retry_policy for accessing other IdP endpoints, e.g, the logout endpoint.

If we agree on the API change, I'll go ahead to add the implementation.

@wbpcode

wbpcode commented Jul 22, 2024

Copy link
Copy Markdown
Member

This requirement looks good to me and the jwt_authn filter, gcp_authn filter, RemoteDataSource, etc. have provided similar API.

But I think my question would be should we add the retry_policy in the HttpUri directly? Then we needn't change the API again and again in the future.

cc @htuch @mattklein123

@zhaohuabing

zhaohuabing commented Jul 22, 2024 •

Copy link
Copy Markdown
Member Author

But I think my question would be should we add the retry_policy in the HttpUri directly? Then we needn't change the API again and again in the future.

Good point! The only issue is that if we add retry_policy directly to HTTPUri, it implies all the APIs referencing HTTPUri are expected to support retries. While it would great to have this feature, we need to modify all the existing implementations to support it.

@wbpcode

wbpcode commented Jul 22, 2024

Copy link
Copy Markdown
Member

We can comment the current situation clearly and do the retry support for other positions in future PR on required

@htuch

htuch commented Jul 23, 2024

Copy link
Copy Markdown
Member

I don't think retry policy is a property of a URI but of a service. So you could potentially add it to the recently added envoy.config.core.v3.HttpService. But in this case I don't feel that strongly.

@wbpcode

wbpcode commented Jul 23, 2024 •

Copy link
Copy Markdown
Member

I don't think retry policy is a property of a URI but of a service. So you could potentially add it to the recently added envoy.config.core.v3.HttpService. But in this case I don't feel that strongly.

I raised this suggestion because the have add timeout in the HttpUri. I agree HttpService is better position but it is come too late and no much scenarios are using it.

cc @htuch

@htuch

htuch commented Jul 24, 2024

Copy link
Copy Markdown
Member

I agree on the history. Going forward, can we deprecate the existing URI field and replace with Service, adding this there?

@adisuissa

Copy link
Copy Markdown
Contributor

If we could convert everything to use a Service (applies both to HttpService and GrpcService), this would've been great. However, w/o proper API deprecation mechanism this is probably not worth the effort.
At least the code can be refactored to be similar.

@zhaohuabing

Copy link
Copy Markdown
Member Author

@wbpcode @htuch @adisuissa thank you for your thoughtful inputs, I appreciate it. I believe the question of whether the retry policy should be incorporated into HTTPService/GRPCService and the deprecation of HttpUri in existing APIs is a broader topic. Perhaps we could track this in a separate issue if needed?

Regarding this PR, could I proceed with the current standalone retry policy approach?

@wbpcode

wbpcode commented Jul 26, 2024

Copy link
Copy Markdown
Member

Now we have no an actual API deprecation mechanism. Even a API is marked as deprecated, Envoy need to support them forever.

So, it 's hard to replace the HttpUri with HttpService. But as @adisuissa said, at least we can make the code be general.

Any way, this is a bigger topic and it's hard to get a final conclusion in short term.

Specific to this PR, I recommend that let's along the 'tranditional' way first to unblock the following works.

@htuch

htuch commented Jul 26, 2024

Copy link
Copy Markdown
Member

I'm fine with retry policy. where it is in this PR as long as we don't put it in HttpUri.

@wbpcode wbpcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution. And only one comment for now.

Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
@zhaohuabing
zhaohuabing marked this pull request as ready for review July 30, 2024 03:39

@wbpcode wbpcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution. Some comments are added.

/wait

@mattklein123 mattklein123 removed their assignment Jul 31, 2024

@wbpcode wbpcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM overall, thanks. Could you add a unit test or integration test to ensure that the option is actually be set and works?

@wbpcode wbpcode added the waiting label Aug 1, 2024
@RyanTheOptimist

Copy link
Copy Markdown
Contributor

/wait
Needs tests and main merge

@zhaohuabing

zhaohuabing commented Aug 19, 2024 •

Copy link
Copy Markdown
Member Author

Apologies for the delay. I was on vacation last week and will be attending Kubecon next week. I plan to resume work on this PR after Kubecon.

Signed-off-by: Huabing Zhao <[email protected]>
@zhaohuabing
zhaohuabing requested a review from wbpcode August 28, 2024 11:53

@wbpcode wbpcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM overall with only one comment. Thanks.

/wait

Signed-off-by: Huabing Zhao <[email protected]>

@wbpcode wbpcode left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks.

@wbpcode
wbpcode merged commit 7f231c1 into envoyproxy:main Aug 30, 2024
@zhaohuabing
zhaohuabing deleted the oauth2-retry branch August 31, 2024 00:47
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.

enhancement: oauth2 filter supports retries to improve communication stability with OAuth2 severs

6 participants