Repository navigation
cookie session: support 0 ttl - #32093
Conversation
Signed-off-by: Kuat Yessenov <[email protected]>
Signed-off-by: Kuat Yessenov <[email protected]>
|
Thanks Kuat. That's for istio/istio#49000 - any chance we can get it backported as well ? |
adisuissa
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I see, thanks for clarifying. Please add a comment to the test explaining the intent here.
There was a problem hiding this comment.
No problem, added a comment.
| 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. |
There was a problem hiding this comment.
Please add what is the expected behavior for 0 TTL, and consider moving this under bug_fixes in the same file below.
Signed-off-by: Kuat Yessenov <[email protected]>
| 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>( |
| // 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()); |
There was a problem hiding this comment.
nit: const std::chrono::seconds
| return absl::nullopt; | ||
| if (cookie.expires() != 0) { | ||
| std::chrono::seconds expiry_time(cookie.expires()); | ||
| auto now = std::chrono::duration_cast<std::chrono::seconds>( |
cpakulski
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
|
needs main merge |
|
/wait merge main and address @cpakulski 's comments |
|
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' ?
Permanent cookies with expiration are typically used for SSO or
tracking, and they can get renewed (for 'idle timeout') or deleted (for
'login again after 1 day').
In most common persistent session implementations they last as long as the
endpoint is alive ( or until the endpoint decides to remove the
cookie - which is important in some use cases ).
For Istio we seem to agree on not using permanent cookies ( ttl=0 always ),
so not critical for us since we won't use this mode, but may be important
to clarify in the
docs - it is not clear at all how a backend should be coded to correctly
handle either behavior.
…On Thu, Feb 1, 2024 at 4:16 PM Christoph Pakulski ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Looks good, but I think that additional test should be added.
------------------------------
In test/extensions/http/stateful_session/cookie/cookie_test.cc
<#32093 (comment)>:
> @@ -52,7 +52,6 @@ TEST(CookieBasedSessionStateFactoryTest, SessionStateTest) {
if (use_proto) {
envoy::Cookie cookie;
cookie.set_address("1.2.3.4:80");
- cookie.set_expires(1000);
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.
—
Reply to this email directly, view it on GitHub
<#32093 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2U675IHBTXGBCG72A3YRQV47AVCNFSM6AAAAABCQHK25GVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQNJXHE3TSMJWHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
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 |
|
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? |
|
Max-age is for the browser. I don't think it's sent back to envoy. I mean
what does the TTL in the config means ?
Doc on cookie is:"This will be used to set the expiry time of a new cookie
when it is generated. Set this to 0 to use a session cookie."
That implies non 0 results in non-session cookie, with Max-Age. It doesn't
say anything about what happens when the cookie expires, or how the
second expiration interacts with Max-Age ( is it the same ? ).
I don't think this is bocking for this PR - which is fixing the simple and
clean case of ttl=0. But should probably be addressed in the docs.
Part of the problem is that Cookie seems to be a general-purpose config for
cookies - while persistent sessions are a particular use
of cookies. I'm sure SSO implementations or API for setting cookies in
response will have a very different use case for cookies - and they
may be confused by persistent session specific behaviors...
…On Wed, Feb 7, 2024 at 1:57 PM Graeme ***@***.***> wrote:
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.
… <#m_-1759842294414045908_>
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)
<#32093 (comment)>>,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAUR2UQDIGVEBRVH2IGATLYSOXKTAVCNFSM6AAAAABCQHK25GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZSGQ4DONZQG4
<https://github.com/notifications/unsubscribe-auth/AAAUR2UQDIGVEBRVH2IGATLYSOXKTAVCNFSM6AAAAABCQHK25GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZSGQ4DONZQG4>
. You are receiving this because you commented.Message ID: @.*>
The ttl in the cookie, won't it be the value that Envoy will pay attention
too rather than the max-age?
—
Reply to this email directly, view it on GitHub
<#32093 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2XLECINON5QSNRSTLDYSP2ELAVCNFSM6AAAAABCQHK25GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZTGAYDKMJRGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
@costinm for now, it's an absolute time that the envoy will abort exist cookie and re-select a new instance. |
|
That's reasonable - matches browser behavior.
However it would be good to have some docs and perhaps info for backend
developers. With all other implementations
of persistent sessions in other servers - a backend can assume persistence
will last as long as the backend is alive,
so they can keep session data in memory and do various optimizations.
If Envoy sessions have a hard expiration date - and after x second will
move to a different backend - I assume a backend
will need to track when they saw the first request and somehow handle the
shift ? I don't know how that would work,
very different from everything else I've seen.
At least in Istio we have now set ttl to 0 ( session cookie, no expiration
) so we won't have to deal with this problem, but
for other users of envoy who may set the expiry it would be good to have
some extra doc so they don't assume the
typical persistent session behavior and code their backend for envoy
differently.
…On Wed, Feb 7, 2024 at 9:30 PM code ***@***.***> wrote:
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 <https://github.com/costinm> for now, it's an absolute time that
the envoy will abort exist cookie and re-select a new instance.
—
Reply to this email directly, view it on GitHub
<#32093 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUR2TLW4QIVTZW6EFRZS3YSRPI5AVCNFSM6AAAAABCQHK25GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZTGM4TAMBUGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
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]>
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
|
Updated the docs to explain that 0s TTL implies no expiration. |
|
/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. |
|
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. |
|
@costinm Yes, Envoy only controls expiration by Envoy. |
adisuissa
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@envoyproxy/senior-maintainers assignee is @wbpcode |
Change-Id: I81e461948b75eaee9ef909d8d13bf8fea7c66dc9 Signed-off-by: Kuat Yessenov <[email protected]>
Change-Id: I39f02d9c6207805b6ee8a2a147387db6487d2f70
* 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]>
* 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]>
* 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]>
* 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]>
* 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]>
* 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]>
* 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]>
…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]>
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