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

Fix h2c support #694

Merged
merged 5 commits into from
Oct 26, 2023
Merged

Conversation

anivanovic
Copy link
Contributor

About

This solves #786 issue in krakend-ce repo.

Move support for h2c from gin router init to http server
init.

Description

If we initialize h2c using gin router it will use h2c handler
to wrap handler with all routes registered on gin router.
The problem is that it is possible to construct router factory
with RunServer function which will wrap h2c handler with additional
handler. Any logic in this handler will not be able to understand
http2 cleartext requests.

We have this example in krakend-ce repository where CORS support
is added through RunServer function. Then we have CORS handler ->
h2c handler -> Gin router.

Simplest fix is to move h2c support to server initialization
and add h2c handler as the outermost layer.

@anivanovic anivanovic force-pushed the antonije/fix_h2c_support branch from e1427a2 to 534a193 Compare October 20, 2023 11:08
@dhontecillas
Copy link
Contributor

dhontecillas commented Oct 24, 2023

Hi @anivanovic , thanks for your contribution!

The PR looks good, and fixes the issue: however there is a minor detail, and is that when we move the use_h2c wrapper up the stack it no longer depends on gin framework, so the flag should not be inside the extra_config under the "github_com/luraproject/lura/router/gin" namespace. On the other side, to not break backwards compatibility (or change behaviour) for the lura framework, we need to maintain that config option there.

So, one option I am thinking of is:

  • we add the use_h2c at the service level, and we maintain also the old use_h2c under the gin namespace with a deprecation warning.
  • in the CE code, we check for the existence of the old flag, and if it exists we copy the value to the new use_h2c at the service level before all the setup process (and thus, it will fix the behaviour for existing configuration)

But before doing anything, let me check with some mates about this approach.

Thanks.

Copy link
Contributor

@dhontecillas dhontecillas left a comment

Choose a reason for hiding this comment

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

@anivanovic , I've double checked with a mate, and we think that in order to be able to merge this PR we would need those minor changes.

Once this is merged, we apply the required changes at the krakend-ce level to finish the fix, and we can work on doing a new release to have the fixe available for everyone.

Again, thank you very much for your contribution.

transport/http/server/server.go Outdated Show resolved Hide resolved
router/gin/engine.go Outdated Show resolved Hide resolved
@anivanovic anivanovic force-pushed the antonije/fix_h2c_support branch from 812fdac to a8402ec Compare October 24, 2023 15:18
@anivanovic
Copy link
Contributor Author

@anivanovic , I've double checked with a mate, and we think that in order to be able to merge this PR we would need those minor changes.

Once this is merged, we apply the required changes at the krakend-ce level to finish the fix, and we can work on doing a new release to have the fixe available for everyone.

Again, thank you very much for your contribution.

Sounds good to me. Thanks on taking time reviewing the PR.

Copy link
Contributor

@dhontecillas dhontecillas left a comment

Choose a reason for hiding this comment

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

Looks good, thanks ! :)

Copy link
Contributor

@dhontecillas dhontecillas left a comment

Choose a reason for hiding this comment

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

the test requires an update to the provided service config , and will be ready to go.

@dhontecillas
Copy link
Contributor

@anivanovic , sorry for bothering, but in order to merge the PR, we also need the commits to be signed: perhaps you will need to amend the commits and add the -s -S flags to sign the commits.

@anivanovic
Copy link
Contributor Author

I signed off all commits with -s.

@taik0
Copy link
Contributor

taik0 commented Oct 25, 2023

I signed off all commits with -s.

Hi @anivanovic ,
The -s is for the sign-off, -S is to sign the commits using your SSH/PGP Key.
See this article: https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key

@anivanovic anivanovic force-pushed the antonije/fix_h2c_support branch from d17ac3a to 7936f04 Compare October 25, 2023 12:31
@anivanovic
Copy link
Contributor Author

I signed off all commits with -s.

Hi @anivanovic , The -s is for the sign-off, -S is to sign the commits using your SSH/PGP Key. See this article: https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key

@taik0 first time doing it so I need some time to set it up. I signed just the last commit. Is this enough?

@taik0
Copy link
Contributor

taik0 commented Oct 25, 2023

You should sign all commits :(

Look for git resign commits, and you will find ways of creating a new branch and sign those commits.

@anivanovic anivanovic force-pushed the antonije/fix_h2c_support branch 3 times, most recently from e00d380 to 9e3366a Compare October 26, 2023 12:46
init.

If we initialize h2c using gin router it will use h2c handler
to wrap handler with all routes registered on gin router.
The problem is that it is possible to construct router factory
with RunServer function which will wrap h2c handler with additional
handler. Any logic in this handler will not be able to understand
http2 cleartext requests.

We have this example in krakend-ce repository where CORS support
is added through RunServer function. Then we have CORS handler ->
h2c handler -> Gin router.

Simplest fix is to move h2c support to server initialization
and add h2c handler as the outermost layer.

Signed-off-by: Antonije Ivanovic <[email protected]>
Signed-off-by: Antonije Ivanovic <[email protected]>
Signed-off-by: Antonije Ivanovic <[email protected]>
Signed-off-by: Antonije Ivanovic <[email protected]>
Signed-off-by: Antonije Ivanovic <[email protected]>
@anivanovic anivanovic force-pushed the antonije/fix_h2c_support branch from 9e3366a to c9838bd Compare October 26, 2023 12:47
@anivanovic
Copy link
Contributor Author

@dhontecillas, I just need your reapproval. Everything is signed-off and signed.

Copy link
Contributor

@dhontecillas dhontecillas left a comment

Choose a reason for hiding this comment

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

Great!

We will update also the documentation for contributions, so people are aware of the required signing process.

Thank you very much for your contribution.

@dhontecillas dhontecillas merged commit 4d07104 into luraproject:master Oct 26, 2023
2 checks passed
@anivanovic anivanovic deleted the antonije/fix_h2c_support branch October 26, 2023 14:53
anivanovic added a commit to anivanovic/lura that referenced this pull request Nov 9, 2023
In my [luraproject#694](luraproject#694) I fixed
issued with h2c support and CORS. There was small bug which slipped
through code review. New config field does not use correct struct tag.

Changed `json` to `mapstructure`.
anivanovic added a commit to anivanovic/lura that referenced this pull request Nov 9, 2023
In my [luraproject#694](luraproject#694) I fixed
issued with h2c support and CORS. There was small bug which slipped
through code review. New config field does not use correct struct tag.

Changed `json` to `mapstructure`.

Signed-off-by: Antonije Ivanovic <[email protected]>
Copy link

This pull request was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants