From 4472c4bbf49f6e4099233a6a97b868d20a26bb71 Mon Sep 17 00:00:00 2001 From: Adam Cattermole Date: Tue, 12 Nov 2024 14:07:57 +0000 Subject: [PATCH 1/3] Move selectors to expressions in dev environment Signed-off-by: Adam Cattermole --- utils/deploy/envoy.yaml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/utils/deploy/envoy.yaml b/utils/deploy/envoy.yaml index eafb4d9..3e41f7b 100644 --- a/utils/deploy/envoy.yaml +++ b/utils/deploy/envoy.yaml @@ -180,8 +180,9 @@ data: "scope": "rlp-ns-A/rlp-name-A", "data": [ { - "selector": { - "selector": "unknown.path" + "expression": { + "key": "unknown.path", + "value": "unknown.path" } } ] @@ -237,19 +238,21 @@ data: } }, { - "selector": { - "selector": "source.address" + "expression": { + "key": "source.address", + "value": "source.address" } }, { - "selector": { - "selector": "request.headers.My-Custom-Header-01" + "expression": { + "key": "request.headers['My-Custom-Header-01']", + "value": "request.headers['My-Custom-Header-01']" } }, { - "selector": { - "selector": "metadata.filter_metadata.envoy\\.filters\\.http\\.header_to_metadata.user_id", - "key": "user_id" + "expression": { + "key": "user_id", + "value": "string(getHostProperty(['metadata', 'filter_metadata', 'envoy.filters.http.header_to_metadata', 'user_id']))" } } ] @@ -278,8 +281,9 @@ data: "scope": "rlp-ns-D/rlp-name-D", "data": [ { - "selector": { - "selector": "source.remote_address" + "expression": { + "key": "source.remote_address", + "value": "source.remote_address" } } ] From cc5fa59158f541264f0e8cb84de2fd72bc16bc72 Mon Sep 17 00:00:00 2001 From: Adam Cattermole Date: Tue, 12 Nov 2024 14:54:19 +0000 Subject: [PATCH 2/3] The request.headers should be lowercase Signed-off-by: Adam Cattermole --- README.md | 6 +++--- utils/deploy/envoy.yaml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 57afe0d..4927807 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ actionSets: data: - expression: key: my_header - value: request.headers["My-Custom-Header"] + value: request.headers["my-custom-header"] ``` ## Features @@ -143,7 +143,7 @@ curl -H "Host: test.b.rlp.com" http://127.0.0.1:8000/get -i * `rlp-c`: Descriptor entries from multiple data items should be generated. Hence, rate limiting service should be called. ```sh -curl -H "Host: test.c.rlp.com" -H "x-forwarded-for: 50.0.0.1" -H "My-Custom-Header-01: my-custom-header-value-01" -H "x-dyn-user-id: bob" http://127.0.0.1:8000/get -i +curl -H "Host: test.c.rlp.com" -H "x-forwarded-for: 50.0.0.1" -H "my-custom-header-01: my-custom-header-value-01" -H "x-dyn-user-id: bob" http://127.0.0.1:8000/get -i ``` Check limitador logs for received descriptor entries. @@ -163,7 +163,7 @@ Entry { key: "source.address", value: "50.0.0.1:0" } ``` ``` -Entry { key: "request.headers.My-Custom-Header-01", value: "my-custom-header-value-01" } +Entry { key: "request.headers.my-custom-header-01", value: "my-custom-header-value-01" } ``` ``` diff --git a/utils/deploy/envoy.yaml b/utils/deploy/envoy.yaml index 3e41f7b..39c013c 100644 --- a/utils/deploy/envoy.yaml +++ b/utils/deploy/envoy.yaml @@ -245,8 +245,8 @@ data: }, { "expression": { - "key": "request.headers['My-Custom-Header-01']", - "value": "request.headers['My-Custom-Header-01']" + "key": "request.headers['my-custom-header-01']", + "value": "request.headers['my-custom-header-01']" } }, { From ae16bb39f9fbaae1d4969baadaf07005f9a53c37 Mon Sep 17 00:00:00 2001 From: Adam Cattermole Date: Tue, 12 Nov 2024 15:06:56 +0000 Subject: [PATCH 3/3] Debug log request.headers map Signed-off-by: Adam Cattermole --- src/data/property.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/data/property.rs b/src/data/property.rs index 06ad798..69d7310 100644 --- a/src/data/property.rs +++ b/src/data/property.rs @@ -56,15 +56,12 @@ pub fn host_get_map(path: &Path) -> Result, String> { pub fn host_get_map(path: &Path) -> Result, String> { match *path.tokens() { ["request", "headers"] => { - debug!( - "get_map: {:?}", - proxy_wasm::types::MapType::HttpRequestHeaders - ); let map = proxy_wasm::hostcalls::get_map(proxy_wasm::types::MapType::HttpRequestHeaders) - .unwrap() + .expect("Failed to get_map request.headers") .into_iter() .collect(); + debug!("get_map: {map:#?}"); Ok(map) } _ => Err(format!("Unknown map requested {:?}", path)),