Skip to content

Instantly share code, notes, and snippets.

@maksim-paskal
Created October 2, 2020 14:00
Show Gist options
  • Save maksim-paskal/f2473cacd7b5a850826748d2bd0c5a26 to your computer and use it in GitHub Desktop.
Save maksim-paskal/f2473cacd7b5a850826748d2bd0c5a26 to your computer and use it in GitHub Desktop.
@maksim-paskal
Copy link
Author

maksim-paskal commented Oct 2, 2020

envoy v1.15 (stable) can't use cookie in header_to_metadata extension (this available in latest envoy only) https://www.envoyproxy.io/docs/envoy/v1.15.2/api-v3/extensions/filters/http/header_to_metadata/v3/header_to_metadata.proto#extensions-filters-http-header-to-metadata-v3-config-rule

to use cookie in metadata - you can use Lua extension and add it in http_filters - for example this code will add cookie name CID to metadata envoy.filters.http.lua.cookie to test this code - you add to access log %DYNAMIC_METADATA(envoy.filters.http.lua.cookie)%

access_log:
- name: envoy.access_loggers.file
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
    path: /dev/stdout
    log_format:
      json_format:
        protocol: "%PROTOCOL%"
        duration: "%DURATION%"
        response_code: "%RESPONSE_CODE%"
        response_flags: "%RESPONSE_FLAGS%"
        x_request_id: "%REQ(X-REQUEST-ID)%"
        meta_cookies: "%DYNAMIC_METADATA(envoy.filters.http.lua.cookie)%"

@maksim-paskal
Copy link
Author

to get ratelimit service with cookie name

rate_limits:
- actions:
  - dynamic_metadata:
      descriptor_key: "cookie-cid"
      metadata_key:
        key: envoy.filters.http.lua.cookie
        path:
        - key: CID

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