Skip to content

Commit 78c5c55

Browse files
committed
Separate VCL template for varnish-end-user/varnish-admin
1 parent a4894cd commit 78c5c55

File tree

5 files changed

+79
-18
lines changed

5 files changed

+79
-18
lines changed

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ services:
104104
entrypoint: /bin/sh -c "cp /etc/varnish/default.vcl.template /etc/varnish/default.vcl && sed -i 's|$${BACKEND_HOST}|'"$$BACKEND_HOST"'|g' /etc/varnish/default.vcl && sed -i 's|$${BACKEND_PORT}|'"$$BACKEND_PORT"'|g' /etc/varnish/default.vcl && sed -i 's|$${CLIENT_HOST}|'"$$CLIENT_HOST"'|g' /etc/varnish/default.vcl && /usr/local/bin/docker-varnish-entrypoint \"$$0\" \"$$@\""
105105
command: [ "-t", "86400" ] # time to live
106106
volumes:
107-
- ./platform/varnish.vcl.template:/etc/varnish/default.vcl.template:ro
107+
- ./platform/varnish-frontend.vcl.template:/etc/varnish/default.vcl.template:ro
108108
varnish-admin:
109109
image: varnish:7.3.0
110110
user: root # otherwise the varnish user does not have permissions to the mounted folder which is owner by root
@@ -119,7 +119,7 @@ services:
119119
entrypoint: /bin/sh -c "cp /etc/varnish/default.vcl.template /etc/varnish/default.vcl && sed -i 's|$${BACKEND_HOST}|'"$$BACKEND_HOST"'|g' /etc/varnish/default.vcl && sed -i 's|$${BACKEND_PORT}|'"$$BACKEND_PORT"'|g' /etc/varnish/default.vcl && sed -i 's|$${CLIENT_HOST}|'"$$CLIENT_HOST"'|g' /etc/varnish/default.vcl && /usr/local/bin/docker-varnish-entrypoint \"$$0\" \"$$@\""
120120
command: [ "-t", "86400" ] # time to live
121121
volumes:
122-
- ./platform/varnish.vcl.template:/etc/varnish/default.vcl.template:ro
122+
- ./platform/varnish-backend.vcl.template:/etc/varnish/default.vcl.template:ro
123123
varnish-end-user:
124124
image: varnish:7.3.0
125125
user: root # otherwise varnish user does not have permissions to the mounted folder which is owner by root
@@ -134,7 +134,7 @@ services:
134134
entrypoint: /bin/sh -c "cp /etc/varnish/default.vcl.template /etc/varnish/default.vcl && sed -i 's|$${BACKEND_HOST}|'"$$BACKEND_HOST"'|g' /etc/varnish/default.vcl && sed -i 's|$${BACKEND_PORT}|'"$$BACKEND_PORT"'|g' /etc/varnish/default.vcl && sed -i 's|$${CLIENT_HOST}|'"$$CLIENT_HOST"'|g' /etc/varnish/default.vcl && /usr/local/bin/docker-varnish-entrypoint \"$$0\" \"$$@\""
135135
command: [ "-t", "86400" ] # time to live
136136
volumes:
137-
- ./platform/varnish.vcl.template:/etc/varnish/default.vcl.template:ro
137+
- ./platform/varnish-backend.vcl.template:/etc/varnish/default.vcl.template:ro
138138
email-server:
139139
image: namshi/smtp
140140
environment:
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
vcl 4.0;
2+
3+
import std;
4+
5+
backend default {
6+
.host = "${BACKEND_HOST}";
7+
.port = "${BACKEND_PORT}";
8+
.first_byte_timeout = 60s;
9+
}
10+
11+
acl local {
12+
"localhost";
13+
"${CLIENT_HOST}";
14+
}
15+
16+
sub vcl_recv {
17+
if (req.method == "PURGE") {
18+
if (!client.ip ~ local) {
19+
return (synth(403, "Unknown IP address '" + client.ip + "'. Access denied."));
20+
}
21+
return (purge);
22+
}
23+
24+
if (req.method == "BAN") { # supports only 2 URIs!
25+
if (!client.ip ~ local) {
26+
return (synth(403, "Unknown IP address '" + client.ip + "'. Access denied."));
27+
}
28+
29+
set req.http.X-Escaped-Request-URI-1 = regsub(req.http.X-Escaped-Request-URI, ",.*$", ""); # remove header value after comma
30+
set req.http.X-Escaped-Request-URI-2 = regsub(req.http.X-Escaped-Request-URI, "^.*,", ""); # remove header value before comma
31+
ban("req.url ~ " + req.http.X-Escaped-Request-URI-1);
32+
ban("req.url ~ " + req.http.X-Escaped-Request-URI-2);
33+
return (synth(200, "Banned"));
34+
}
35+
36+
if (req.method != "GET" &&
37+
req.method != "HEAD" &&
38+
req.method != "PUT" &&
39+
req.method != "POST" &&
40+
req.method != "TRACE" &&
41+
req.method != "OPTIONS" &&
42+
req.method != "DELETE" &&
43+
req.method != "PATCH") {
44+
/* Non-RFC2616 or CONNECT which is weird. */
45+
return (pipe);
46+
}
47+
48+
if (req.method != "GET" && req.method != "HEAD") {
49+
/* We only deal with GET and HEAD by default */
50+
return (pass);
51+
}
52+
53+
return (hash);
54+
}
55+
56+
sub vcl_backend_response {
57+
/* purge URLs after updates */
58+
if ((beresp.status == 200 || beresp.status == 201 || beresp.status == 204) && bereq.method ~ "POST|PUT|DELETE|PATCH") {
59+
set beresp.http.X-LinkedDataHub = "Banned";
60+
ban("req.url == " + bereq.url + " && req.http.host == " + bereq.http.host);
61+
}
62+
63+
return (deliver);
64+
}
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ acl local {
1313
"${CLIENT_HOST}";
1414
}
1515

16+
acl remote {
17+
}
18+
1619
sub vcl_recv {
1720
if (req.method == "PURGE") {
18-
if (!client.ip ~ local) {
21+
if (!client.ip ~ local && !client.ip ~ remote) {
1922
return (synth(403, "Unknown IP address '" + client.ip + "'. Access denied."));
2023
}
2124
return (purge);
2225
}
2326

2427
if (req.method == "BAN") { # supports only 2 URIs!
25-
if (!client.ip ~ local) {
28+
if (!client.ip ~ local && !client.ip ~ remote) {
2629
return (synth(403, "Unknown IP address '" + client.ip + "'. Access denied."));
2730
}
2831

@@ -49,7 +52,10 @@ sub vcl_recv {
4952
/* We only deal with GET and HEAD by default */
5053
return (pass);
5154
}
52-
55+
if (req.http.Client-Cert) {
56+
/* Authenticated requests are not cacheable */
57+
return (pass);
58+
}
5359
if (req.http.Cookie) {
5460
# explicitly allow only cookies required by LDH server-side
5561
set req.http.Cookie = ";" + req.http.Cookie;
@@ -58,21 +64,11 @@ sub vcl_recv {
5864
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
5965
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
6066

61-
if (req.http.Cookie ~ "LinkedDataHub\.id_token=") {
62-
# extract the LinkedDataHub.id_token value
63-
set req.http.X-LinkedDataHub-Id-Token = regsub(req.http.Cookie, ".*LinkedDataHub\.id_token=([^; ]+).*", "\1");
64-
}
65-
6667
if (req.http.cookie ~ "^\s*$") {
6768
unset req.http.cookie;
6869
}
6970
}
7071

71-
if ((req.http.Client-Cert || req.http.X-LinkedDataHub-Id-Token) && (req.http.Accept ~ "text/html" || req.http.Accept ~ "application/xhtml+xml")) {
72-
/* Authenticated (X)HTML requests are not cacheable (since they're user-specific) */
73-
return (pass);
74-
}
75-
7672
return (hash);
7773
}
7874

@@ -84,4 +80,4 @@ sub vcl_backend_response {
8480
}
8581

8682
return (deliver);
87-
}
83+
}

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/layout.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ LIMIT 100
800800
<xsl:param name="typeof" select="key('resources', ac:absolute-path(ldh:base-uri(.)))/rdf:type/@rdf:resource/xs:anyURI(.)" as="xs:anyURI*"/>
801801
<xsl:param name="classes" select="for $class-uri in $default-classes return key('resources', $class-uri, document(ac:document-uri($class-uri)))" as="element()*"/>
802802
<xsl:param name="doc-types" select="key('resources', ac:absolute-path(ldh:base-uri(.)))/rdf:type/@rdf:resource[ . = ('&def;Root', '&dh;Container', '&dh;Item')]" as="xs:anyURI*"/>
803-
<!-- take care not to load unnecessary documents over HTTP when the response is an error response -->
803+
<!-- take care not to load unnecessary documents over HTTP when $doc-types is empty -->
804804
<xsl:param name="block-values" select="if (exists($doc-types)) then (if (doc-available(resolve-uri('ns?query=ASK%20%7B%7D', $ldt:base))) then (ldh:query-result(map{}, resolve-uri('ns', $ldt:base), $template-query || ' VALUES $Type { ' || string-join(for $type in $doc-types return '&lt;' || $type || '&gt;', ' ') || ' }')//srx:binding[@name = 'content']/srx:uri/xs:anyURI(.)) else ()) else ()" as="xs:anyURI*"/>
805805
<xsl:param name="has-content" select="key('resources', key('resources', ac:absolute-path(ldh:base-uri(.)))/rdf:*[starts-with(local-name(), '_')]/@rdf:resource) or exists($block-values)" as="xs:boolean"/>
806806

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/resource.xsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ extension-element-prefixes="ixsl"
614614
<xsl:param name="typeof" select="rdf:type/@rdf:resource/xs:anyURI(.)" as="xs:anyURI*"/>
615615
<xsl:param name="mode" as="xs:anyURI?"/>
616616
<xsl:param name="style" as="xs:string?"/>
617+
<!-- take care not to load unnecessary documents over HTTP when $typeof is empty -->
617618
<xsl:variable name="block-values" select="if (exists($typeof)) then (if (doc-available(resolve-uri('ns?query=ASK%20%7B%7D', $ldt:base))) then (ldh:query-result(map{}, resolve-uri('ns', $ldt:base), $template-query || ' VALUES $Type { ' || string-join(for $type in $typeof return '&lt;' || $type || '&gt;', ' ') || ' }')//srx:binding[@name = 'block']/srx:uri/xs:anyURI(.)) else ()) else ()" as="xs:anyURI*" use-when="system-property('xsl:product-name') = 'SAXON'"/>
618619

619620
<xsl:choose>

0 commit comments

Comments
 (0)