Skip to content
New issue

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

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

Already on GitHub? # to your account

EZP-29817: Varnish - Purge requests with tokens #72

Merged
merged 8 commits into from
Jan 15, 2019

Conversation

damianz5
Copy link
Contributor

@damianz5 damianz5 commented Nov 28, 2018

Meta repo changes:

default_parameters.yml

    varnish_invalidate_token: '%env(HTTPCACHE_VARNISH_INVALIDATE_TOKEN)%'

    env(HTTPCACHE_VARNISH_INVALIDATE_TOKEN): ~

ezplatform.yml

ezpublish:
...
	system:
	...
		site_group: (same for admin_group)
            		http_cache:
			        purge_servers: ['%purge_server%']
+             			varnish_invalidate_token: '%varnish_invalidate_token%'

.env

# Enable varnish purging invalidate token by setting valid token
#HTTPCACHE_VARNISH_INVALIDATE_TOKEN=""

https://jira.ez.no/browse/EZP-29817

@damianz5 damianz5 changed the title EZP-29817: Varnish - Purge requests with tokens [WIP]EZP-29817: Varnish - Purge requests with tokens Nov 28, 2018
@andrerom
Copy link
Contributor

andrerom commented Nov 28, 2018

Cool, didn't know it was planned 👍

As for VCL, not same approach, but started looking into it today and have this if you need some pointers on one possible approach: https://gist.github.com/andrerom/c1f123fe65b577ca915c57fa6ceaf835

@damianz5 damianz5 force-pushed the varnish_purge_header branch from d444c51 to 5dfe3d0 Compare November 28, 2018 14:13
@damianz5 damianz5 changed the title [WIP]EZP-29817: Varnish - Purge requests with tokens EZP-29817: Varnish - Purge requests with tokens Nov 28, 2018
vidarl
vidarl previously approved these changes Nov 29, 2018
Copy link
Member

@vidarl vidarl left a comment

Choose a reason for hiding this comment

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

LGTM, but I would like to have vcl and docs updated too...

@andrerom andrerom dismissed vidarl’s stale review November 29, 2018 12:54

It's a poc, not for review yet afaik?

@andrerom
Copy link
Contributor

Once we have updated VCL here, we can get @Plopix, or one of us to update https://github.com/ezsystems/ezplatform/pull/315/files as well to finish this code wise (doc will also be needed).

@damianz5
Copy link
Contributor Author

damianz5 commented Nov 30, 2018

@andrerom It was PoC at the beginning, but I will remove this label - review is required, I will continue working on this regarding the reviews

@andrerom
Copy link
Contributor

andrerom commented Nov 30, 2018

Ok, I'd like to see changes to VCL (VCL in this repo, we can copy over changes to meta repo once this is approved and merged) so we can see the full picture as part of the review, feel free to use from example gist link above.

@damianz5 damianz5 force-pushed the varnish_purge_header branch from 5dfe3d0 to 552b985 Compare November 30, 2018 15:40
@damianz5
Copy link
Contributor Author

Note: [platform.sh] check if ACL_INVALIDATE_TOKEN (or any env in general) will be injected to varnish node, and not only to app node.

@andrerom
Copy link
Contributor

andrerom commented Dec 1, 2018

@damianz5 FYI tried to check with platform.sh folks if they prefered env or global var.
But no answer besides @kmadejski mentioning global var being slow.

Alternative is afaik to hardcode token in the VCL sub routine itself, which I was thinking we'd like to avoid.

Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

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

Besides nitpick, and assuming it works +1

@Plopix
Copy link
Contributor

Plopix commented Dec 5, 2018

Regargind this: https://github.com/ezsystems/ezplatform/pull/315/files

I think they will or they have changed something else regarding the relationship.
I say that based on a conversation I had with @Crell but I am unsure of the status if they kept it or not.

Also with this token I don't think we need a relationship as the whole point is to remove it. (to avoid the circular reference)

I think we need Platform.sh in the loop to confirm everything.

Then I will be happy to update the PR!

But that's cool, I can't wait to have varnish ready

@andrerom
Copy link
Contributor

andrerom commented Dec 5, 2018

You are bringing up a good point here @Plopix, we/Symfony rely on IP to denote which Proxy we trust. This implies still need for circular relationship unless there are suggestions on how we can avoid it.

One way is to add support for host names in app.php for trusted proxies (look them up). But if we can avoid that, it’d be great.

@Plopix
Copy link
Contributor

Plopix commented Dec 6, 2018

hey @andrerom , again I am just guessing here, we need someone from Platform.sh.

To me, TrustedProxies are not relevant here https://symfony.com/doc/current/deployment/proxies.html

The normal chain on Platform.sh is Web -> Varnish -> App, the actual issue is that we need to purge Varnish and thus need a relation that does Web -> Varnish <-> App for App to purge Varnish kind of internally.

relationships:
    ...
    varnish: "varnish:http"

that my current understanding of the circular reference issue.

That why they will introduce a Token to allow to have only Web -> Varnish -> App and then App would purge through Web, the the Purge Request will not go directly from App -> Varnish but will go out and enter by Web (that is why we need a token)

Trusted Proxy is something else and it is probably not an issue.

@damianz5 damianz5 force-pushed the varnish_purge_header branch from a778e5e to 47b926d Compare December 12, 2018 08:16
@damianz5 damianz5 force-pushed the varnish_purge_header branch from 47b926d to ab15147 Compare December 13, 2018 08:59
@damianz5 damianz5 force-pushed the varnish_purge_header branch from ab15147 to 7e02d25 Compare December 20, 2018 14:25
Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

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

+1 We can cleanup VCL once we drop Varnish 4.1 support in the future.

@damianz5 damianz5 force-pushed the varnish_purge_header branch from 17e23c6 to ef310dd Compare December 20, 2018 15:38
@andrerom andrerom requested a review from kmadejski December 28, 2018 19:10
docs/varnish/vcl/varnish4.vcl Outdated Show resolved Hide resolved
@damianz5
Copy link
Contributor Author

damianz5 commented Jan 9, 2019

@andrerom @vidarl final review please

Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

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

Header could be a constant, but besides that I'm +1

sub ez_purge_acl {
// if (req.http.x-purge-token) {
// # Won't work on Varnish <= 5.1, if needed in 4.1 you can hardcode a secret token here instead of std.getenv() usage
// if (req.http.x-purge-token != std.getenv("HTTPCACHE_VARNISH_INVALIDATE_TOKEN")) {
Copy link
Member

Choose a reason for hiding this comment

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

I have not tested, but this looks like a security hole

If server is configured to use whitelist (invalidators), and evil user sends x-purge-token header with empty value, this if might match if env variable HTTPCACHE_VARNISH_INVALIDATE_TOKEN is not set?

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 think if x-purge-token will be empty - the if condition if (req.http.x-purge-token) { will return false and second condition (req.http.x-purge-token != std.ge...) will not be called

Copy link
Contributor

@andrerom andrerom Jan 11, 2019

Choose a reason for hiding this comment

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

This is why it's not enabled by default. As enabling it means you should always inject env to avoid the

What @damianz5 says, the if won't enter unless header has value, so you can't match empty value. This is why there are two conditions here instead of one.

But, as p.sh does not support injecting it by env, which is where we need this. We can change example here to just have hardcoded token to avoid anyone stumbling into such an issue by mistake.

Avoids us having to document any differences between 4.1 and higher as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or, what was the outcome so far of discussions with p.sh?

Copy link
Member

Choose a reason for hiding this comment

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

No reply from ph.sh yet. I have created a ticket in their jira, requesting us to be able to define env variables in the varnish container

Copy link
Member

Choose a reason for hiding this comment

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

I have now tested sending token header with empty value, and indeed it seems to work as we intended.

So, since that is the case, why comment out the lines in the first place...?

Copy link
Contributor

@andrerom andrerom Jan 14, 2019

Choose a reason for hiding this comment

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

It was discussed on Slack, it's because std.getenv is not defined on Varnish 4.1 (LTS).
We can drop support for 4.x in a future major, but not in a minor where we currently need this.

Copy link
Member

Choose a reason for hiding this comment

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

acknowledged

@andrerom
Copy link
Contributor

Merging for followup on aligning VCL files. And progressing the work in meta repo once platform.sh adds more convenient ways to inject secrets to Varnish, ref: ezsystems/ezplatform#346

@andrerom andrerom merged commit ccaee46 into ezsystems:0.8 Jan 15, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Development

Successfully merging this pull request may close these issues.

6 participants