Skip to content

OAuth2 filter: Optimize HMAC encoding - #28867

Merged
yanavlasov merged 41 commits into
envoyproxy:mainfrom
Ronnie-personal:oauth2Optimzation28728
Sep 5, 2023
Merged

yanavlasov merged 41 commits into
envoyproxy:mainfrom
Ronnie-personal:oauth2Optimzation28728

Conversation

@Ronnie-personal

@Ronnie-personal Ronnie-personal commented Aug 6, 2023 •

Copy link
Copy Markdown
Contributor

Commit Message: remove base64 encoding from OAuth2 HMAC cookie, apply hex encoding only.
Additional Description:
Risk Level: Low
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
Fixes #28728
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

Signed-off-by: Ronnie Personal <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

Hi @Ronnie-personal, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #28867 was opened by Ronnie-personal.

see: more, trace.

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #28867 was opened by Ronnie-personal.

see: more, trace.

Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
@Ronnie-personal

Copy link
Copy Markdown
Contributor Author

Hi @htuch
Would you mind helping me with a question? Is it possible to debug test/extensions/filters/http/oauth2/filter_test.cc locally?

I have configured the Visual Studio Code Dev Container based on the guide at https://github.com/envoyproxy/envoy/blob/main/tools/vscode/README.md.
But I don't see run test/debug test button in the IDE.

Thanks.

Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
@htuch

htuch commented Aug 8, 2023

Copy link
Copy Markdown
Member

I'm not super familiar with the VS Code flow, I tend to use vim :) That said, you can definitely run tests via Bazel locally. Maybe you are missing a Bazel plugin for VS Code?

Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
@Ronnie-personal

Copy link
Copy Markdown
Contributor Author

@htuch
Can you please help me to understand the status of the pipeline? There 22 jobs displayed as 'Waiting for status to be reported'. I have tried to trigger the CI for couple of times, but those jobs are still not kicked off.

Thanks.

@htuch

htuch commented Aug 10, 2023 •

Copy link
Copy Markdown
Member

Since you are a new contributor, CI requires a maintainer to kick off the CI. I pushed the button :)

@Ronnie-personal
Ronnie-personal marked this pull request as ready for review August 11, 2023 02:59
@yanavlasov

Copy link
Copy Markdown
Contributor

This change is user visible, i.e. it modifies Envoy's behavior in a way that can potentially break some users. In this case we use runtime features to allow switching back to the old behavior in case some Envoy operator was impacted by this change.

Please add a new runtime feature to switch back to the old behavior. See PR #27974 for example on how to do it.

/wait

@Ronnie-personal

Copy link
Copy Markdown
Contributor Author

This change is user visible, i.e. it modifies Envoy's behavior in a way that can potentially break some users. In this case we use runtime features to allow switching back to the old behavior in case some Envoy operator was impacted by this change.

Please add a new runtime feature to switch back to the old behavior. See PR #27974 for example on how to do it.

/wait

Thanks for the review! I will look into the runtime features.

@Ronnie-personal
Ronnie-personal marked this pull request as draft August 17, 2023 02:28
@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #28867 was synchronize by Ronnie-personal.

see: more, trace.

Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
@Ronnie-personal

Ronnie-personal commented Aug 23, 2023 •

Copy link
Copy Markdown
Contributor Author

two other thoughts here:

1. I'm wondering if there oughtta be a migrate path - ability to allocate tokens in the new format while still respecting tokens of the old format. That way operators can safely roll out the new envoy version with no surprises and after a reasonable amount of time has passed we can safely axe the b64+hex

2. I'm curious if there's a reason for choosing only hex rather than only base64? Base64 seems to yield shorter values per the github issue.

Thanks for the review.

  1. I will look into respecting the token of the old format. Should we consider implementing a flag to disable this behavior?
  2. No, there is not specific reason for choosing hex, the requirement does not call out the exact option. I just choose one of the two options. I definitely can refactor the code to use base64.

absl::Base64Escape(Hex::encode(crypto_util.getSha256Hmac(secret, hmac_payload)), &encoded_hmac);
return encoded_hmac;
if (Runtime::runtimeFeatureEnabled("envoy.reloadable_features.hmac_hex_encoding_only")) {
return Hex::encode(crypto_util.getSha256Hmac(secret, hmac_payload));

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.

Hex will take two characters for each byte while Base64 takes 4 characters for every 3 bytes, so it should be more efficient to just use base64. Wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, we can go with Base64.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you have any guidance on 'respecting the token of the old format'?
I can update the OAuth2 filter validator to accept both 'base64' and 'hex+base64'. However, how do we disable this behavior when the user no longer needs this backward compatibility?

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.

I agree accepting the old token is a good idea. What we may be able to do is to accept the base64+hex token and set-cookie with the new token. This way when this backward compatibility is not required and becomes the default behaviour we can remove the runtime guard safely. There may be better ideas, but this seems simple enough.

Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
@Ronnie-personal
Ronnie-personal marked this pull request as draft August 27, 2023 23:55
Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
@yanavlasov

Copy link
Copy Markdown
Contributor

@Ronnie-personal

Copy link
Copy Markdown
Contributor Author

Ronnie-personal and others added 4 commits August 28, 2023 23:45
Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
Co-authored-by: tony-2023 <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
Signed-off-by: Ronnie Personal <[email protected]>
@Ronnie-personal

Copy link
Copy Markdown
Contributor Author

The pipeline failed with '##[error]We stopped hearing from agent i-060b64c3735e1bae4. Verify the agent machine is running and has a healthy network connection. Anything that terminates an....'

Shall I rerun the pipeline?

@Ronnie-personal

Copy link
Copy Markdown
Contributor Author

/retest

@yanavlasov

Copy link
Copy Markdown
Contributor

@Ronnie-personal I've restarted CI, but there merge conflict that needs resolving.

@yanavlasov

Copy link
Copy Markdown
Contributor

/wait

@Ronnie-personal

Copy link
Copy Markdown
Contributor Author

/wait

@Ronnie-personal I've restarted CI, but there merge conflict that needs resolving.

Thanks! I will resolve the conflict.

Signed-off-by: Ronnie Personal <[email protected]>
@Ronnie-personal

Ronnie-personal commented Aug 31, 2023 •

Copy link
Copy Markdown
Contributor Author

After merging from the main branch, the pipeline failed with another error. This PR does not touch 'substitution_formatter_test.cc'.
I will investigate further.

Here is the error:
test/common/formatter/substitution_formatter_test.cc:934:38: error: use of undeclared identifier 'request_headers'
upstream_format.format(request_headers, response_headers, response_trailers,

@Ronnie-personal
Ronnie-personal marked this pull request as ready for review September 1, 2023 01:12
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.

OAuth2: Optimization: Use only base64 or only hex encoding for the HMAC cookie

6 participants