Skip to content

cookies are still routing the traffic after the ttl's expiry #26347

Closed

Description

@pramodrj07

Title: Session cookies are still routing the traffic after the ttl's expiry

Description:

The HTTP requests with cookies are still being routed to the same backend after the expiry of the cookies set in the "TTL" field (https://www.envoyproxy.io/docs/envoy/latest/api-v3/type/http/v3/cookie.proto). I presume we use "Max-Age" in the "Set-Cookie:" field to view the expiry of the cookie.

Repro steps:

Listener configuration similar to the one below but using the go-control plane.
an HTTP request (using curl) to the envoy is routing the request to the same backend after the cookie's expiry

Admin and Stats Output:

"route": {
"weighted_clusters": {
"clusters": [
{
"name": "some_cluster",
"weight": 100
}
],
"total_weight": 100
},
"host_rewrite_literal": "",
"timeout": "30s",
"hash_policy": [
{
"cookie": {
"name": "session-cookie",
"ttl": "25s"
}
}
],
"idle_timeout": "60s"
}


Config: Below is an example, but I am using a control-plane similar to the one in the go-control plane.

static_resources:
listeners:

  • name: listener_0
    address:
    socket_address:
    address: 0.0.0.0
    port_value: 5000
    filter_chains:
    • filters:

    • name: envoy.http_connection_manager
      typed_config:
      "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
      stat_prefix: ingress_http
      drain_timeout: 2s
      route_config:
      name: local_route
      virtual_hosts:
      - name: local_service
      domains:
      - "*"
      routes:
      - match:
      prefix: "/"
      route:
      cluster: example_proxy_cluster
      http_filters:

      • name: envoy.filters.http.stateful_session
        typed_config:
        "@type": type.googleapis.com/envoy.extensions.filters.http.stateful_session.v3.StatefulSession
        session_state:
        name: envoy.http.stateful_session.cookie
        typed_config:
        "@type": type.googleapis.com/envoy.extensions.http.stateful_session.cookie.v3.CookieBasedSessionState
        cookie:
        name: session-cookie
        ttl: 25s

      transport_socket:
      name: envoy.transport_sockets.starttls
      typed_config:
      "@type": type.googleapis.com/envoy.extensions.transport_sockets.starttls.v3.StartTlsConfig
      tls_socket_config:
      common_tls_context: {}

clusters:

  • name: some_cluster
    transport_socket:
    name: envoy.transport_sockets.starttls
    typed_config:
    "@type": type.googleapis.com/envoy.extensions.transport_sockets.starttls.v3.UpstreamStartTlsConfig
    tls_socket_config:
    common_tls_context: {}

Logs:

Envoy-logs - Did not see any cookie-related information apart from the cookies mentioned in the requests
Access-Logs - Cookies are present under the route-action.

Activity

  1. added
    triage
    on Mar 24, 2023
  2. changed the title [-]Session cookies are still routing the traffic after the ttl's expiry[/-] [+]cookies are still routing the traffic after the ttl's expiry[/+] on Mar 24, 2023
  3. lizan commented on Mar 27, 2023

    @lizan
    Member
  4. removed
    triage
    on Mar 27, 2023
  5. cpakulski commented on Mar 27, 2023

    @cpakulski
    Contributor

    I can look into this issues.

  6. pramodrj07 commented on Mar 31, 2023

    @pramodrj07
    Author

    hi @cpakulski - Did you get a chance to confirm if this is a bug? Would like to validate if it's just me finding this.

  7. cpakulski commented on Apr 3, 2023

    @cpakulski
    Contributor

    I will verify it this week.

  8. cpakulski commented on Apr 4, 2023

    @cpakulski
    Contributor

    @pramodrj07 You are right. After Envoy issues cookie to a client, Envoy does not check ttl. As long as the client keeps sending the same cookie, Envoy will route to the originally assigned endpoint, regardless of ttl value. Working on the fix.

  9. wbpcode commented on Apr 5, 2023

    @wbpcode
    Member

    I think the responsibility of cookies management is belong to the client or browser. The TTL is used to tell the client when will the cookies are expired and the client shouldn't send request with expired cookies.

    How can envoy check the TTL of cookies in the downstream request? @cpakulski

  10. pramodrj07 commented on Apr 5, 2023

    @pramodrj07
    Author

    I think the responsibility of cookies management is belong to the client or browser. The TTL is used to tell the client when will the cookies are expired and the client shouldn't send request with expired cookies.

    How can envoy check the TTL of cookies in the downstream request? @cpakulski

    @wbpcode - Agree the cookie management does belong to the client. However, how does the lifecycle of cookies (specifically hash value assigned per cookie) look from Envoy's perspective? Disregarding the client's side for a moment, does envoy hold on to the cookie value without ever recycling(deleting) it or consider it as expired (considering envoy doesn't care about ttl)?

  11. cpakulski commented on Apr 5, 2023

    @cpakulski
    Contributor

    From Envoy's perspective cookies are stateless. It means that when a cookie is created and sent downstream to a client, Envoy does not store any context associated with that cookie. Currently the cookie is base-64 encoded IP address of upstream host. When Envoy receives a cookie, it does base-64 decoding, reads the address and asks upstream cluster to select that host. Envoy does not check if it issued that cookie in the past.

    @wbpcode To solve the problem with TTL, I would like to add expiration time when base-64 encoding happens. When StatefulSession filter receives a cookie, it would check the expiration date and if it is expired, it will behave the same way as in requests without the cookie - it would ask upstream LB to select a new host. That host would be used to generate a new cookie.

  12. wbpcode commented on Apr 6, 2023

    @wbpcode
    Member

    I would like to add expiration time when base-64 encoding happens.

    SGTM to add additional field to the base-64 encoded cookie values. Then we can do more control. But please take the backward compatibility into account when doing the design. Thanks. 😸

  13. wbpcode commented on Apr 6, 2023

    @wbpcode
    Member

    /assign @cpakulski

  14. pramodrj07 commented on Apr 10, 2023

    @pramodrj07
    Author

    From Envoy's perspective cookies are stateless. It means that when a cookie is created and sent downstream to a client, Envoy does not store any context associated with that cookie. Currently the cookie is base-64 encoded IP address of upstream host. When Envoy receives a cookie, it does base-64 decoding, reads the address and asks upstream cluster to select that host. Envoy does not check if it issued that cookie in the past.

    @wbpcode To solve the problem with TTL, I would like to add expiration time when base-64 encoding happens. When StatefulSession filter receives a cookie, it would check the expiration date and if it is expired, it will behave the same way as in requests without the cookie - it would ask upstream LB to select a new host. That host would be used to generate a new cookie.

    I see. Thanks for the clarification.

  15. ramaraochavali commented on Apr 11, 2023

    @ramaraochavali
    Contributor

    But please take the backward compatibility into account when doing the design.

    This is very important. Please consider supporting both during the design.

  16. cpakulski commented on Apr 11, 2023

    @cpakulski
    Contributor

    @ramaraochavali Would you mind explaining why backward compatibility is important for your use case? I thought that Envoy may issue a cookie in any format and HTTP clients just needs to attach that cookie to further requests without caring about the format, length, etc of the cookie.

  17. ramaraochavali commented on Apr 11, 2023

    @ramaraochavali
    Contributor

    @ramaraochavali Would you mind explaining why backward compatibility is important for your use case? I thought that Envoy may issue a cookie in any format and HTTP clients just needs to attach that cookie to further requests without caring about the format, length, etc of the cookie.

    What you said is generally correct. Our use case is mainly for http stateful session header where we are trying to get the first request also to an ip that we want instead of a random ip and then session getting maintained from there. So in a some rare cases, we use the same logic as envoy to encode the first ip.

    Not sure if some one uses it like this for cookie also.

  18. cpakulski commented on Apr 11, 2023

    @cpakulski
    Contributor

    Understood. Thanks for explaining. For your use case statefullness based on a header should be used (as you are using it now). Documentation clearly states that the content of the header should be base64 encoded IP:port of the preferred upstream host.
    However, for cookies, docs do not say anything about encoded content of the cookie. I will provide the backward compatibility but will also generate logs to indicate that this behaviour will change and "old" format of the cookie will be rejected in the future.

  19. ramaraochavali commented on Apr 12, 2023

    @ramaraochavali
    Contributor

    However, for cookies, docs do not say anything about encoded content of the cookie. I will provide the backward compatibility but will also generate logs to indicate that this behaviour will change and "old" format of the cookie will be rejected in the future.

    Sure. Makes sense. Thank you

  20. pramodrj07 commented on May 10, 2023

    @pramodrj07
    Author

    Thank you @cpakulski @wbpcode for your help. Really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions