Skip to content

cookie session: support 0 ttl - #32093

Merged
wbpcode merged 8 commits into
envoyproxy:mainfrom
kyessenov:support_ttl_0
Feb 16, 2024
Merged

wbpcode merged 8 commits into
envoyproxy:mainfrom
kyessenov:support_ttl_0

Conversation

@kyessenov

Copy link
Copy Markdown
Contributor

Commit Message: Follow-up to #26761 to restore support for 0 TTL. That PR always populated the cookie expiry field rendering it useless when TTL was set to 0. This is counter to the documented behavior in https://www.envoyproxy.io/docs/envoy/latest/api-v3/type/http/v3/cookie.proto#envoy-v3-api-msg-type-http-v3-cookie to support TTL 0 for a session cookie.
Additional Description:
Risk Level: med, reverts a breaking change
Testing: yes
Docs Changes: none
Release Notes: yes

Signed-off-by: Kuat Yessenov <[email protected]>
@kyessenov
kyessenov requested a review from wbpcode as a code owner January 29, 2024 22:39
Signed-off-by: Kuat Yessenov <[email protected]>
@costinm

costinm commented Jan 29, 2024

Copy link
Copy Markdown
Contributor

Thanks Kuat. That's for istio/istio#49000 - any chance we can get it backported as well ?

@kyessenov kyessenov added the backport/review Request to backport to stable releases label Jan 29, 2024

@adisuissa adisuissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing the bug!
Left a minor comment on the test, trying to clarify the behavior.

if (use_proto) {
envoy::Cookie cookie;
cookie.set_address("1.2.3.4:80");
cookie.set_expires(1000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this removed from the test?

If the cookie expires field is the same as the current time (i.e., now == expiry_time in the code above), what should be the returned value? The test here seems to send a set-cookie with TTL of 0 (which AFAICT is infinite), no? I'm wondering if this is the right behavior.

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.

Right, this is testing with TTL 0. cookie here is the expected value. The correct expected value should have expiry infinite (or 0 due to the encoding). The previous commit had it at 1000 which means it immediately expired once issued.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that this test was designed to test the situation when a request without a cookie arrives to stateful filter and the filter needs to generate a cookie in response. This resembles initial request when an initial cookie is generated. The generated cookie's expiry time should be time_now + configured ttl. In this test configured ttl was previously zero and monotonic time is 1000, so the test checked if generated cookie's expiry time is 1000. I think we should keep this test but add EXPECT_CALL to return config's ttl which is not zero to verify that proper expiry time is generated. Additionally another test should be added to verify that when ttl is zero, the proper cookie is generated in similar, initial situation.

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.

TTL 0 has a different meaning for expiry - it must mean the generated cookie has no expiry at all. Checking for time_now+configured ttl when TTL is not 0 is done in the next test case below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, thanks for clarifying. Please add a comment to the test explaining the intent here.

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.

No problem, added a comment.

Comment thread changelogs/current.yaml Outdated
Multiply the gradient value stat by 1000 to make it more granular (values will range between 500 and 2000).
- area: stateful_session
change: |
Support 0 TTL for proto-encoded cookies.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add what is the expected behavior for 0 TTL, and consider moving this under bug_fixes in the same file below.

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.

Done.

Signed-off-by: Kuat Yessenov <[email protected]>
wbpcode
wbpcode previously approved these changes Jan 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 with nit comments. Thanks.

cookie.set_address(std::string(host_address));
cookie.set_expires(expiry_time.count());
if (factory_.ttl_ != std::chrono::seconds::zero()) {
auto expiry_time = std::chrono::duration_cast<std::chrono::seconds>(

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.

nit: const auto ...

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.

Done.

// upstream cluster to select a new host and new cookie will be generated.
return absl::nullopt;
if (cookie.expires() != 0) {
std::chrono::seconds expiry_time(cookie.expires());

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.

nit: const std::chrono::seconds

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.

Done.

return absl::nullopt;
if (cookie.expires() != 0) {
std::chrono::seconds expiry_time(cookie.expires());
auto now = std::chrono::duration_cast<std::chrono::seconds>(

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.

nit: const auto now = ...

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.

Done.

@cpakulski cpakulski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, but I think that additional test should be added.

if (use_proto) {
envoy::Cookie cookie;
cookie.set_address("1.2.3.4:80");
cookie.set_expires(1000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that this test was designed to test the situation when a request without a cookie arrives to stateful filter and the filter needs to generate a cookie in response. This resembles initial request when an initial cookie is generated. The generated cookie's expiry time should be time_now + configured ttl. In this test configured ttl was previously zero and monotonic time is 1000, so the test checked if generated cookie's expiry time is 1000. I think we should keep this test but add EXPECT_CALL to return config's ttl which is not zero to verify that proper expiry time is generated. Additionally another test should be added to verify that when ttl is zero, the proper cookie is generated in similar, initial situation.

@alyssawilk

Copy link
Copy Markdown
Contributor

needs main merge

@wbpcode

wbpcode commented Feb 7, 2024

Copy link
Copy Markdown
Member

/wait merge main and address @cpakulski 's comments

@costinm

costinm commented Feb 7, 2024 via email

Copy link
Copy Markdown
Contributor

@cybrhwk

cybrhwk commented Feb 7, 2024

Copy link
Copy Markdown

Would it not be more flexible to allow the configuration of the ttl, so the person configuring Envoy/Istio can decide if they want the stateful session cookie to have an expiry or be a session based cookie? I have never used a session cookie to provide the sticky session mechanism, so I'm not sure how/if that would work for ensuring the traffic goes to the right destination for the duration of the user session

@costinm

costinm commented Feb 7, 2024 via email

Copy link
Copy Markdown
Contributor

@cybrhwk

cybrhwk commented Feb 7, 2024 •

Copy link
Copy Markdown

Which TTL ? There is the Max-Age - that tells the browser to persist the cookie and reuse it for a long time. There is the new TTL in the cookie itself. And the behavior is not specified just by TTL - does the user want 'refresh the cookie periodically' - or hard stop even if the endpoint is still around ? For non-browsers - it's about the same thing, since very few follow the specs and actually 'persist' the cookie (most cookie jars are in memory only), so it's almost the same as header-based. Browsers just get rid of the cookie when the tab is closed ( and have to show the annoying GDPR warnings for persistent cookies - which the backend implementation will have to code if the envoy setting happens to enable Max-Age and the client is a browser (or at least check with their privacy/compliance experts). For sticky sessions - I have not seen any use case for stopping the persistence after 1 hour even if the backend is still alive. Not clear how it'll even be handled correctly by a backend.
…
On Wed, Feb 7, 2024 at 9:00 AM Graeme @.> wrote: Would it not be more flexible to allow the configuration of the ttl, so the person configuring Envoy/Istio can decide if they want the stateful session cookie to have an expiry or be a session based cookie? I have never used a session cookie to provide the sticky session mechanism, so I'm not sure how/if that would work for ensuring the traffic goes to the right destination for the duration of the user session — Reply to this email directly, view it on GitHub <#32093 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAUR2UQDIGVEBRVH2IGATLYSOXKTAVCNFSM6AAAAABCQHK25GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZSGQ4DONZQG4 . You are receiving this because you commented.Message ID: @.>

The ttl in the cookie stored in Envoy. As the Envoy cookie is proposed to be a session cookie, what's the definition of a session in this context?

@costinm

costinm commented Feb 7, 2024 via email

Copy link
Copy Markdown
Contributor

@wbpcode

wbpcode commented Feb 8, 2024

Copy link
Copy Markdown
Member

Good call - but is this 'expires' an absolute time when the session must
abruptly end ( and request goes to a different endpoint, even if the
original endpoint is still alive ) ?
Or is it a 'if not used (idle), start a new session and go to a different
endpoint' ?

@costinm for now, it's an absolute time that the envoy will abort exist cookie and re-select a new instance.

@wbpcode wbpcode added the waiting label Feb 8, 2024
@costinm

costinm commented Feb 8, 2024 via email

Copy link
Copy Markdown
Contributor

Change-Id: I4ec7a73838f59d2bff8c4e7bfacf6f081c15b053
Signed-off-by: Kuat Yessenov <[email protected]>
Change-Id: I24b84f52cbe3617e5e298d89b4cafd3c76a62ec8
Signed-off-by: Kuat Yessenov <[email protected]>
Change-Id: Ib88c98412a6fe696365a01e3f69a9198bf1b90e7
Signed-off-by: Kuat Yessenov <[email protected]>
@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 @wbpcode
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #32093 was synchronize by kyessenov.

see: more, trace.

@kyessenov

kyessenov commented Feb 9, 2024 •

Copy link
Copy Markdown
Contributor Author

Updated the docs to explain that 0s TTL implies no expiration.

@kyessenov

Copy link
Copy Markdown
Contributor Author

/assign @adisuissa

Adi, can you take a look instead of @wbpcode since they are out for the holiday? I think @wbpcode LGTM'ed with nit comments, that I addressed.

@costinm

costinm commented Feb 9, 2024

Copy link
Copy Markdown
Contributor

Well - 0 TTL doesn't imply no expiration. A browser will expire it when the tab is closed. And envoy will terminate it when the endpoint is gone. Everything expires at some point.

@kyessenov

Copy link
Copy Markdown
Contributor Author

@costinm Yes, Envoy only controls expiration by Envoy.

@adisuissa adisuissa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall LGTM.
Left a minor comment (test descriptions), and a general comment (is runtime-flag needed) for the senior-maintainer to consider.

/assign-from @envoyproxy/senior-maintainers

if (use_proto) {
envoy::Cookie cookie;
cookie.set_address("1.2.3.4:80");
cookie.set_expires(1000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, thanks for clarifying. Please add a comment to the test explaining the intent here.

if (cookie.ParseFromString(decoded_value)) {
address = cookie.address();
if (address.empty() || (cookie.expires() == 0)) {
if (address.empty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if this needs a runtime-flag.
I tend to no (IIUC this was the prior behavior and it is fixing an issue added in a prior PR, and it matches the description of the feature before and after that PR), but will keep it as a question for the next reviewer.

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.

For context, this is breaking one of our customers because the change happened during an upgrade. I'm planning to backport this. I'd argue we don't need a flag for a backported change.

@repokitteh-read-only

Copy link
Copy Markdown

@envoyproxy/senior-maintainers assignee is @wbpcode

🐱

Caused by: a #32093 (review) was submitted by @adisuissa.

see: more, trace.

Change-Id: I81e461948b75eaee9ef909d8d13bf8fea7c66dc9
Signed-off-by: Kuat Yessenov <[email protected]>
Change-Id: I39f02d9c6207805b6ee8a2a147387db6487d2f70

@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 6354dcf into envoyproxy:main Feb 16, 2024
yxun pushed a commit to yxun/envoy that referenced this pull request Jul 29, 2024
* cookie session: support 0 ttl

Signed-off-by: Kuat Yessenov <[email protected]>

* add note

Signed-off-by: Kuat Yessenov <[email protected]>

* update changelog

Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I24b84f52cbe3617e5e298d89b4cafd3c76a62ec8
Signed-off-by: Kuat Yessenov <[email protected]>

* clarify doc

Change-Id: Ib88c98412a6fe696365a01e3f69a9198bf1b90e7
Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I81e461948b75eaee9ef909d8d13bf8fea7c66dc9
Signed-off-by: Kuat Yessenov <[email protected]>

---------

Signed-off-by: Kuat Yessenov <[email protected]>
yxun pushed a commit to yxun/envoy that referenced this pull request Jul 29, 2024
* cookie session: support 0 ttl

Signed-off-by: Kuat Yessenov <[email protected]>

* add note

Signed-off-by: Kuat Yessenov <[email protected]>

* update changelog

Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I24b84f52cbe3617e5e298d89b4cafd3c76a62ec8
Signed-off-by: Kuat Yessenov <[email protected]>

* clarify doc

Change-Id: Ib88c98412a6fe696365a01e3f69a9198bf1b90e7
Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I81e461948b75eaee9ef909d8d13bf8fea7c66dc9
Signed-off-by: Kuat Yessenov <[email protected]>

---------

Signed-off-by: Yuanlin Xu <[email protected]>
Co-authored-by: Kuat Yessenov <[email protected]>
yxun pushed a commit to yxun/envoy that referenced this pull request Jul 30, 2024
* cookie session: support 0 ttl

Signed-off-by: Kuat Yessenov <[email protected]>

* add note

Signed-off-by: Kuat Yessenov <[email protected]>

* update changelog

Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I24b84f52cbe3617e5e298d89b4cafd3c76a62ec8
Signed-off-by: Kuat Yessenov <[email protected]>

* clarify doc

Change-Id: Ib88c98412a6fe696365a01e3f69a9198bf1b90e7
Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I81e461948b75eaee9ef909d8d13bf8fea7c66dc9
Signed-off-by: Kuat Yessenov <[email protected]>

---------

Signed-off-by: Yuanlin Xu <[email protected]>
Co-authored-by: Kuat Yessenov <[email protected]>
phlax pushed a commit that referenced this pull request Jul 31, 2024
* cookie session: support 0 ttl

Signed-off-by: Kuat Yessenov <[email protected]>

* add note

Signed-off-by: Kuat Yessenov <[email protected]>

* update changelog

Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I24b84f52cbe3617e5e298d89b4cafd3c76a62ec8
Signed-off-by: Kuat Yessenov <[email protected]>

* clarify doc

Change-Id: Ib88c98412a6fe696365a01e3f69a9198bf1b90e7
Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I81e461948b75eaee9ef909d8d13bf8fea7c66dc9
Signed-off-by: Kuat Yessenov <[email protected]>

---------

Signed-off-by: Yuanlin Xu <[email protected]>
Co-authored-by: Kuat Yessenov <[email protected]>
phlax pushed a commit that referenced this pull request Jul 31, 2024
* cookie session: support 0 ttl

Signed-off-by: Kuat Yessenov <[email protected]>

* add note

Signed-off-by: Kuat Yessenov <[email protected]>

* update changelog

Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I24b84f52cbe3617e5e298d89b4cafd3c76a62ec8
Signed-off-by: Kuat Yessenov <[email protected]>

* clarify doc

Change-Id: Ib88c98412a6fe696365a01e3f69a9198bf1b90e7
Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I81e461948b75eaee9ef909d8d13bf8fea7c66dc9
Signed-off-by: Kuat Yessenov <[email protected]>

---------

Signed-off-by: Yuanlin Xu <[email protected]>
Co-authored-by: Kuat Yessenov <[email protected]>
yxun pushed a commit to yxun/envoy that referenced this pull request Aug 9, 2024
* cookie session: support 0 ttl

Signed-off-by: Kuat Yessenov <[email protected]>

* add note

Signed-off-by: Kuat Yessenov <[email protected]>

* update changelog

Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I24b84f52cbe3617e5e298d89b4cafd3c76a62ec8
Signed-off-by: Kuat Yessenov <[email protected]>

* clarify doc

Change-Id: Ib88c98412a6fe696365a01e3f69a9198bf1b90e7
Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I81e461948b75eaee9ef909d8d13bf8fea7c66dc9
Signed-off-by: Kuat Yessenov <[email protected]>

---------

Signed-off-by: Yuanlin Xu <[email protected]>
Co-authored-by: Kuat Yessenov <[email protected]>
yxun pushed a commit to yxun/envoy that referenced this pull request Aug 30, 2024
* cookie session: support 0 ttl

Signed-off-by: Kuat Yessenov <[email protected]>

* add note

Signed-off-by: Kuat Yessenov <[email protected]>

* update changelog

Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I24b84f52cbe3617e5e298d89b4cafd3c76a62ec8
Signed-off-by: Kuat Yessenov <[email protected]>

* clarify doc

Change-Id: Ib88c98412a6fe696365a01e3f69a9198bf1b90e7
Signed-off-by: Kuat Yessenov <[email protected]>

* review

Change-Id: I81e461948b75eaee9ef909d8d13bf8fea7c66dc9
Signed-off-by: Kuat Yessenov <[email protected]>

---------

Signed-off-by: Yuanlin Xu <[email protected]>
Co-authored-by: Kuat Yessenov <[email protected]>
@phlax phlax removed the backport/review Request to backport to stable releases label Jul 9, 2025
jue-yin added a commit to jue-yin/envoy that referenced this pull request Aug 24, 2025
…eful session envelope, aiming to cover MCP 250326 spec SSE

cherry-pick from envoyproxy#30573 envoyproxy@62f4a14#diff-c904f9b0d49cdd938ffaa952192372529415afa8602d7dc6acb904e61111d8a5 add strict mode to stateful session, return 503 when destination is not available

cherry-pick from envoyproxy#32093 envoyproxy@6354dcf support 0 ttl in cookie stateful sessiion to disable cookie expiration

Signed-off-by: 爵银 <[email protected]>
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