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

chore(session) do not read body by default and only on certain HTTP methods #10333

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

bungle
Copy link
Member

@bungle bungle commented Feb 21, 2023

Summary

On comment: #7418 (comment) @PidgeyBE mentioned that session plugin reads bodies by on every HTTP request that is not an GET request.

Because it is quite common to use bodies to send large files, reading body makes features like route.request_buffering=off, not working. Thus, the default value for logout_post_arg in session plugin was removed. The bodies are only read when this is configured. This might change behaviour on scripts that create session plugin and which also think that logout by body argument works as before. On the other hand it is a way more common to read session than it is to log out session, thus it should be better value for future of us.

KAG-634

@bungle bungle force-pushed the chore/session-no-read-body branch 2 times, most recently from 635d7c5 to 5d706a3 Compare February 22, 2023 16:56
@hbagdi
Copy link
Member

hbagdi commented Feb 22, 2023

Aapo, is there a way to fix the performance problem without a breaking change?
Perhaps giving users a knob to disable reading bodies (and then calling that out in documentation)?

I'm all for fixing performance issues but I don't agree that this warrants a breaking change in Kong. Sessions library changes in 3.2 have enough breaking changes, we should not pile on that and instead try to limit them as much as possible.
What do you think?

@PidgeyBE
Copy link
Contributor

Aapo, is there a way to fix the performance problem without a breaking change? Perhaps giving users a knob to disable reading bodies (and then calling that out in documentation)?

I'm all for fixing performance issues but I don't agree that this warrants a breaking change in Kong. Sessions library changes in 3.2 have enough breaking changes, we should not pile on that and instead try to limit them as much as possible. What do you think?

If you are looking for a non-breaking compromise, you could always try to check the Content-Length header and only get the body if it is below a certain threshold... In this way the performance issue is fixed for (large) file uploads and it won't break logout flows (which should be small requests in size).

@bungle
Copy link
Member Author

bungle commented Feb 23, 2023

I'm all for fixing performance issues but I don't agree that this warrants a breaking change in Kong.

As explained it is not only a performance fix, it also makes route.request_buffering=false to not work, so it can be viewed as a bug too. It does not break any existing configurations as they already have the default value stored in db. Just some scripts that rely on default value. Not a huge breakage.

@bungle
Copy link
Member Author

bungle commented Feb 23, 2023

If you are looking for a non-breaking compromise, you could always try to check the Content-Length header and only get the body if it is below a certain threshold... In this way the performance issue is fixed for (large) file uploads and it won't break logout flows (which should be small requests in size).

Just wondering whether it is too magical.

@bungle
Copy link
Member Author

bungle commented Feb 23, 2023

Aapo, is there a way to fix the performance problem without a breaking change? Perhaps giving users a knob to disable reading bodies (and then calling that out in documentation)?

The knob is there, aka set logout_post_arg actively to null. But that has turned out to be complicated with yamls/kic and stuff. If we add a knob it should be that bodies are not read by default to detect logout. In general the plugin should not do logout at all by default. You should configure separate plugin at /logout and enable it there. But that would be even more breaking.

@hbagdi
Copy link
Member

hbagdi commented Feb 23, 2023

It does not break any existing configurations as they already have the default value stored in db. Just some scripts that rely on default value. Not a huge breakage.

That's simplifying the breaking change problem a bit.
Whenever these defaults change, alternate control planes like Koko which work with DPs of multiple versions at the same time have a hard time adopting this change since there can be only one default (Kong schemas are not versioned whatsoever).

If the default value before this patch is captured in decK, KIC, etc, then the effectiveness of this "bug-fix" is questionable as well since fixing the bug actually requires more work than upgrading the gateway.

Are you more open to an alternate where we introduce a net new schema field that toggles the behavior of reading bodies or not?
This is still a breaking change in terms of the behavior of Kong but it is not a breaking change to the schema of Kong. We are sensitive to both kinds of breaking changes but the schema ones are more problematic currently. This further reduces the likelihood that a user will still run into this bug (the bug being reading bodies even with buffering disabled) after an upgrade.

@bungle
Copy link
Member Author

bungle commented Feb 27, 2023

Are you more open to an alternate where we introduce a net new schema field that toggles the behavior of reading bodies or not?

As said, there is already an option, just actively set logout_post_arg to null. The change in this PR was trying to make it default as having better defaults means better usability and that adding session plugin with default settings to Kong will not screw up the performance and other features. I am open adding feature read_bodies or something with a default value of false, but I don't think it makes sense to add one with default value of true.

@hbagdi hbagdi added the version-compatibility Incompatibility with older data plane versions label Mar 1, 2023
@bungle bungle force-pushed the chore/session-no-read-body branch from 5d706a3 to d3ef73a Compare March 2, 2023 15:35
@pull-request-size pull-request-size bot added size/M and removed size/S labels Mar 2, 2023
@bungle bungle force-pushed the chore/session-no-read-body branch from d3ef73a to c355d3d Compare March 2, 2023 15:35
@hanshuebner hanshuebner force-pushed the chore/session-no-read-body branch from c355d3d to b011951 Compare March 14, 2023 10:44
@bungle bungle force-pushed the chore/session-no-read-body branch 5 times, most recently from 3553f68 to 305dfdd Compare March 22, 2023 12:07
CHANGELOG.md Outdated
that changes behavior of `logout_post_arg` in a way that it is not anymore considered if the
`read_bodies` is not explicitly set to `true`. This is to avoid session plugin from reading
request bodies by default on e.g. `POST` request for logout detection.
[#10333](https://github.com/Kong/kong/pull/10333)
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this up into the "Breaking changes" section?

@hbagdi
Copy link
Member

hbagdi commented Jun 7, 2023

I'm adding the 3.4 milestones to this patch. It seems awfully close and is a worthwhile performance change. Recommend changing the commit type to 'perf'.

@hbagdi hbagdi requested a review from hanshuebner June 7, 2023 20:58
@hbagdi hbagdi added this to the 3.4.0 milestone Jun 7, 2023
Copy link
Contributor

@hanshuebner hanshuebner left a comment

Choose a reason for hiding this comment

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

I have tried to understand the pull request description and the CHANGELOG entry, but I found both very difficult to follow. It seems that there is consensus that the implementation makes sense, but maybe the verbiage can be improved. Happy to jump onto a Zoom to help with this.

kong/plugins/session/schema.lua Outdated Show resolved Hide resolved
@kikito kikito removed this from the 3.4.0 milestone Jul 18, 2023
@kikito
Copy link
Member

kikito commented Jul 18, 2023

I'm removing this from the milestone, we are too close to the GA date and have no people available to review/approve this in the meantime.

@kikito kikito added this to the 3.5.0 milestone Sep 12, 2023
@kikito kikito requested a review from hanshuebner September 12, 2023 08:31
@hanshuebner
Copy link
Contributor

@hbagdi We discussed whether we should really treat this as a breaking change in the PR queue review meeting earlier and these is some consensus that it is unlikely that someone relies on the current undocumented behavior. Thus, merging this PR should be fine, even if we document it as breaking change in the change log. What do you think?

@kikito kikito requested a review from hbagdi September 19, 2023 08:39
@team-eng-enablement team-eng-enablement added author/community PRs from the open-source community (not Kong Inc) and removed author/community PRs from the open-source community (not Kong Inc) labels Sep 26, 2023
@jschmid1
Copy link
Contributor

@bungle this seems to not made any progress. Do you still think this should be targeted to 3.5?

@kikito kikito requested a review from jschmid1 October 17, 2023 08:15
@bungle bungle force-pushed the chore/session-no-read-body branch from 3908a02 to 1b217f9 Compare October 17, 2023 08:19
@bungle bungle force-pushed the chore/session-no-read-body branch from 1b217f9 to 1360960 Compare October 17, 2023 08:21
@bungle bungle force-pushed the chore/session-no-read-body branch 3 times, most recently from 8b0f20c to 05c8264 Compare October 17, 2023 08:42
Copy link
Contributor

@jschmid1 jschmid1 left a comment

Choose a reason for hiding this comment

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

To summarize this patch:

Currently we're reading the body for every request as logout_post_arg is set to a non-null default. This forces us to look into every request body by default to detect if a logout is requested.
Reading bodies can become expensive, especially when requests with large payloads are sent. To resolve this issue there are a couple of options.

  1. Explicitly disable the logout functionality.

This affects a rather large group of people and doesn't really solve the issue at hand. When enabling this flag, you'd still have to set logout_post_arg to null to avoid body reads alltogether.

  1. Disable body reads by default

This will also affect some people but the surface is smaller in comparison to (1). To get this functionality back, a user can re-enable this flag.

  1. Change the default of logout_post_arg

This is technically speaking the most straightforward fix. Changing defaults will affect other products though and should be avoided if possible (@hbagdi agrees here)

This leaves us with (2) as it has the lowest impact and achieves what this patch tries to solve.

What I'm not happy with is the name of the config flag as it doesn't reflect the scope this parameter is used in. My proposal is

read_body_for_logout (move from bodies to body, define the scope - for logout)

…ethods

On comment: #7418 (comment)
@PidgeyBE mentioned that session plugin reads bodies by on every HTTP request
that is not an GET request.

Because it is quite common to use bodies to send large files, reading body
makes features like route.request_buffering=off, not working. Thus, a new
configuration option `read_body_for_logout` was added with a default value of `false`.
The bodies are only read when this is configured as `true`. This is a
**breaking** change that the plugin does not anymore read body to detect
logout if the `read_body_for_logout` is not explicitly set to `true`, On the other
hand it is a way more common to read session than it is to log out
session, thus it should be better default for future of us.

Signed-off-by: Aapo Talvensaari <[email protected]>
@jschmid1 jschmid1 force-pushed the chore/session-no-read-body branch from 05c8264 to 71ff1cb Compare October 17, 2023 11:23
@jschmid1 jschmid1 self-requested a review October 17, 2023 12:12
@jschmid1 jschmid1 merged commit 383873f into master Oct 17, 2023
@jschmid1 jschmid1 deleted the chore/session-no-read-body branch October 17, 2023 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants