Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when downloading configs that contain Liquid #845

Merged
merged 3 commits into from
Aug 20, 2018

Conversation

davidor
Copy link
Contributor

@davidor davidor commented Aug 14, 2018

We were parsing the service just to get the OIDC issuer endpoint. That's unnecessary because we can get easily get it from the decoded JSON.

Also, parsing the service was causing a bug. An error was raised with services containing a policy with fields to be interpreted by Liquid (have '{{' and '}}'). (Closes #828 )

@davidor davidor requested a review from a team as a code owner August 14, 2018 15:21
@@ -317,8 +317,10 @@ function _M:config(service, environment, version)
if res.status == 200 then
local proxy_config = cjson.decode(res.body).proxy_config

local config_service = configuration.parse_service(proxy_config.content)
local issuer, oidc_config = self:oidc_issuer_configuration(config_service)
local oidc_issuer_endpoint = proxy_config.content.proxy and
Copy link
Contributor Author

@davidor davidor Aug 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: when calling parse_service, the configuration module builds the policy chain, and when doing so, in the case of the headers policy, the configuration received in new() is modified because it adds a template_string field with an instance of TemplateString.

That's why this failed only when the service was parsed. Parsing the service is not a problem by itself, but later, when the proxy configs are encoded, it fails because of the template string.

An unexpected side-effect.

We should probably review the policy initializers and avoid this kind of side-effects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need an integration test to reproduce this failure.

And I wonder why it crashes when we add an instance of TemplateString.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add an integration test.

Regarding the TemplateString exception, here's a minimal case to reproduce it:

local cjson = require 'cjson'
local Liquid = require 'liquid'
local LiquidTemplate = Liquid.Template

local template = LiquidTemplate:parse('{{ service.id }}')

cjson.encode(template) -- Error: Cannot serialise table: table key must be a number or string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work too 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I thought that there was no point in parsing the service, because the information can be easily get from the JSON. But maybe parsing the service is better in case we're performing some validations there.

@davidor davidor force-pushed the fix-bug-remote-config-with-liquid branch from fa47fd0 to 3eb5515 Compare August 14, 2018 17:33
@pestanko
Copy link

@davidor is there any estimate when this will be merged? (I suppose next week?)

@@ -5,6 +5,8 @@
-- Similarly, this policy also allows to add, modify, and delete the headers
-- included in the response.

local tablex = require('pl.tablex')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't want to depend on penlight in policies. OpenResty provides table.clone that does shallow clone.

Also, if we are doing this, then it should be pushed from the top, not done in each policy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I suggest we solve the problem in the loader first and leave the immutable config for a future PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 👍

@davidor davidor force-pushed the fix-bug-remote-config-with-liquid branch from 635590f to 8077a7e Compare August 20, 2018 13:05
@davidor davidor requested a review from mikz August 20, 2018 13:14
Copy link
Contributor

@mikz mikz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@davidor davidor merged commit 535f474 into master Aug 20, 2018
@davidor davidor deleted the fix-bug-remote-config-with-liquid branch August 20, 2018 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants