From 6cdc778421cb29cc6136cebdf552d50048b68889 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 20 Aug 2018 17:42:28 +0200 Subject: [PATCH 1/3] t/configuration-loading-boot-remote: test fetching remote config with liquid (using portal endpoint with path) --- t/configuration-loading-boot-remote.t | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/t/configuration-loading-boot-remote.t b/t/configuration-loading-boot-remote.t index 8033356df..45dcf9768 100644 --- a/t/configuration-loading-boot-remote.t +++ b/t/configuration-loading-boot-remote.t @@ -125,3 +125,64 @@ echo ' --- request GET /t --- exit_code: 200 + +=== TEST 4: retrieve config with liquid values using THREESCALE_PORTAL_ENDPOINT with path +should not fail +--- main_config +env THREESCALE_PORTAL_ENDPOINT=http://127.0.0.1:$TEST_NGINX_SERVER_PORT/config; +env APICAST_CONFIGURATION_LOADER=boot; +env THREESCALE_DEPLOYMENT_ENV=production; +env PATH; +--- http_config + lua_package_path "$TEST_NGINX_LUA_PATH"; +--- config +location = /t { + content_by_lua_block { + local loader = require('apicast.configuration_loader.remote_v2') + ngx.say(assert(loader:call())) + } +} + +location = /config/production.json { +echo ' +{ + "proxy_configs": [ + { + "proxy_config": { + "id": 42, + "version": 1, + "environment": "production", + "content": { + "proxy": { + "hosts": [ + "127.0.0.1" + ], + "policy_chain": [ + { + "name": "headers", + "version": "builtin", + "configuration": { + "request": [ + { + "op": "set", + "header": "New-Header", + "value": "{{ service.id }}", + "value_type": "liquid" + } + ] + } + } + ], + "proxy_rules": [] + } + } + } + } + ] +} + +'; +} +--- request +GET /t +--- exit_code: 200 From 5aeb1984dba78566b86045a438acdc1940c2dfdf Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 20 Aug 2018 17:43:24 +0200 Subject: [PATCH 2/3] configuration_loader/remote_v2: use original proxy configs in index() --- gateway/src/apicast/configuration_loader/remote_v2.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gateway/src/apicast/configuration_loader/remote_v2.lua b/gateway/src/apicast/configuration_loader/remote_v2.lua index 91fbccbe4..80c84431c 100644 --- a/gateway/src/apicast/configuration_loader/remote_v2.lua +++ b/gateway/src/apicast/configuration_loader/remote_v2.lua @@ -118,13 +118,19 @@ function _M:index(host) for i=1, #proxy_configs do local proxy_config = proxy_configs[i].proxy_config + + -- Copy the config because parse_service have side-effects. It adds + -- liquid templates in some policies and those cannot be encoded into a + -- JSON. We should get rid of these side effects. + local original_proxy_config = deepcopy(proxy_config) + local service = configuration.parse_service(proxy_config.content) local issuer, oidc_config = self:oidc_issuer_configuration(service) if issuer then config.oidc[i] = { issuer = issuer, config = oidc_config } end - config.services[i] = proxy_config.content + config.services[i] = original_proxy_config.content end return cjson.encode(config) From 1d1d260f5456811ddd540a48f88ca391483e0548 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 20 Aug 2018 17:49:33 +0200 Subject: [PATCH 3/3] CHANGELOG: add fix for bug when loading policies with liquid from endpoint with path --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e099c793..2178fdb3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - OpenTracing support [PR #669](https://github.com/3scale/apicast/pull/669), [THREESCALE-1159](https://issues.jboss.org/browse/THREESCALE-1159) - Generate new policy scaffold from the CLI [PR #682](https://github.com/3scale/apicast/pull/682) - 3scale batcher policy [PR #685](https://github.com/3scale/apicast/pull/685), [PR #710](https://github.com/3scale/apicast/pull/710), [PR #757](https://github.com/3scale/apicast/pull/757), [PR #786](https://github.com/3scale/apicast/pull/786), [PR #823](https://github.com/3scale/apicast/pull/823), [THREESCALE-1155](https://issues.jboss.org/browse/THREESCALE-1155) -- Liquid templating support in the headers policy configuration [PR #716](https://github.com/3scale/apicast/pull/716), [PR #845](https://github.com/3scale/apicast/pull/845), [THREESCALE-1140](https://issues.jboss.org/browse/THREESCALE-1140) +- Liquid templating support in the headers policy configuration [PR #716](https://github.com/3scale/apicast/pull/716), [PR #845](https://github.com/3scale/apicast/pull/845), [PR #847](https://github.com/3scale/apicast/pull/847), [THREESCALE-1140](https://issues.jboss.org/browse/THREESCALE-1140) - Ability to modify query parameters in the URL rewriting policy [PR #724](https://github.com/3scale/apicast/pull/724), [PR #818](https://github.com/3scale/apicast/pull/818), [THREESCALE-1139](https://issues.jboss.org/browse/THREESCALE-1139) - 3scale referrer policy [PR #728](https://github.com/3scale/apicast/pull/728), [PR #777](https://github.com/3scale/apicast/pull/777), [THREESCALE-329](https://issues.jboss.org/browse/THREESCALE-329) -- Liquid templating support in the rate-limit policy [PR #719](https://github.com/3scale/apicast/pull/719), [PR #845](https://github.com/3scale/apicast/pull/845), [THREESCALE-411](https://issues.jboss.org/browse/THREESCALE-411) +- Liquid templating support in the rate-limit policy [PR #719](https://github.com/3scale/apicast/pull/719), [PR #845](https://github.com/3scale/apicast/pull/845), [PR #847](https://github.com/3scale/apicast/pull/847), [THREESCALE-411](https://issues.jboss.org/browse/THREESCALE-411) - Default credentials policy [PR #741](https://github.com/3scale/apicast/pull/741), [THREESCALE-586](https://issues.jboss.org/browse/THREESCALE-586) - Configurable caching for the token introspection policy [PR #656](https://github.com/3scale/apicast/pull/656) - `APICAST_ACCESS_LOG_FILE` env to make the access log location configurable [PR #743](https://github.com/3scale/apicast/pull/743), [THREESCALE-1148](https://issues.jboss.org/browse/THREESCALE-1148)