v0.39.0
This commit is contained in:
1 parent
5e43752041
commit
15425fb803
34 files changed
+1423
-89
No files matched your search
@@ -25,6 +25,8 @@ pub(super) static READER_DOCUMENTS: &[(&str, &str, &str)] = &[
|
||||
reader_doc!("docs/PHP_FPM.md", "guides"),
|
||||
reader_doc!("docs/CACHE.md", "guides"),
|
||||
reader_doc!("docs/VCL.md", "guides"),
|
||||
reader_doc!("docs/VCL_SUPPORT_MATRIX.md", "guides"),
|
||||
reader_doc!("docs/VCL_TRAFFIC_COOKBOOK.md", "guides"),
|
||||
reader_doc!("docs/RESPONSE_DELIVERY.md", "guides"),
|
||||
reader_doc!("docs/TRANSPORT.md", "guides"),
|
||||
reader_doc!("docs/STREAMS.md", "guides"),
|
||||
|
||||
+58
-30
@@ -238,6 +238,50 @@ async fn events(
|
||||
.into_response())
|
||||
}
|
||||
|
||||
/// List the effective (compiled) reverse-proxy vhosts, including Docker
|
||||
/// assignments. The persisted config deliberately excludes generated routes.
|
||||
/// Catalog fingerprints also change when Docker inventory changes without
|
||||
/// increasing the persisted configuration revision.
|
||||
fn monitored_vhost_catalog(state: &Arc<App>) -> (Vec<crate::vhost::Vhost>, Vec<Value>, String) {
|
||||
let snapshot = state.config.load_full();
|
||||
let desired = &snapshot.envelope.config;
|
||||
let observed = state.docker.latest();
|
||||
let (publications, _) = crate::docker::label_publications(desired, &observed);
|
||||
let mut docker_labels = std::collections::HashMap::new();
|
||||
for agent in &desired.docker_agents.agents {
|
||||
let inventory = observed.get(&agent.id).and_then(|item| item.inventory.as_ref());
|
||||
let assignments = agent.assignments.iter().filter(|assignment| assignment.enabled)
|
||||
.chain(publications.iter().filter(|entry| entry.agent_id == agent.id)
|
||||
.map(|entry| &entry.assignment));
|
||||
for assignment in assignments {
|
||||
let service = inventory.and_then(|inventory| inventory.services.iter()
|
||||
.find(|service| service.key == assignment.service_key));
|
||||
let name = service.map(|service| service.container_name.as_str())
|
||||
.filter(|name| !name.is_empty())
|
||||
.unwrap_or(assignment.hostname.as_str());
|
||||
docker_labels.insert(crate::docker::generated_id(&agent.id, &assignment.service_key),
|
||||
(name.to_owned(), agent.name.clone()));
|
||||
}
|
||||
}
|
||||
let vhosts: Vec<_> = cache_rule_vhosts(state).into_iter()
|
||||
.filter(|vhost| snapshot.vhost_metrics.contains_key(&vhost.id))
|
||||
.collect();
|
||||
let options: Vec<Value> = vhosts.iter().map(|vhost| {
|
||||
let host = vhost.frontend.hosts.first().map(String::as_str).unwrap_or(&vhost.id);
|
||||
let docker = docker_labels.get(&vhost.id);
|
||||
let label = match docker {
|
||||
Some((name, agent)) => format!("{name} - {host} (Docker: {agent})"),
|
||||
None => format!("{} / {}", vhost.id, vhost.frontend.hosts.join(", ")),
|
||||
};
|
||||
json!({"id": vhost.id, "hosts": vhost.frontend.hosts,
|
||||
"docker": docker.is_some(), "label": label})
|
||||
}).collect();
|
||||
let bytes = serde_json::to_vec(&options).unwrap_or_default();
|
||||
let digest = <sha2::Sha256 as sha2::Digest>::digest(&bytes);
|
||||
let catalog_version: String = digest[..12].iter().map(|byte| format!("{byte:02x}")).collect();
|
||||
(vhosts, options, catalog_version)
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
struct TrafficQuery {
|
||||
@@ -259,23 +303,16 @@ async fn traffic_status(
|
||||
}
|
||||
};
|
||||
let snapshot = state.config.load_full();
|
||||
let (vhosts, options, catalog_version) = monitored_vhost_catalog(&state);
|
||||
if query.vhost.as_ref().is_some_and(|id| {
|
||||
id != "*"
|
||||
&& !snapshot
|
||||
.envelope
|
||||
.config
|
||||
.vhosts
|
||||
.iter()
|
||||
.any(|vhost| &vhost.id == id)
|
||||
id != "*" && !vhosts.iter().any(|vhost| &vhost.id == id)
|
||||
}) {
|
||||
return Err(ApiError(
|
||||
StatusCode::NOT_FOUND,
|
||||
"unknown vhost traffic scope".into(),
|
||||
));
|
||||
return Err(ApiError(StatusCode::NOT_FOUND, "unknown vhost traffic scope".into()));
|
||||
}
|
||||
let scope = query.vhost.as_deref().unwrap_or("*");
|
||||
let mut payload = json!({
|
||||
"revision": snapshot.envelope.revision,
|
||||
"catalog_version": catalog_version,
|
||||
"scope": scope,
|
||||
"since": "process_start",
|
||||
"settings": {
|
||||
@@ -288,13 +325,7 @@ async fn traffic_status(
|
||||
if live {
|
||||
return Ok(Json(payload));
|
||||
}
|
||||
payload["vhosts"] = json!(snapshot
|
||||
.envelope
|
||||
.config
|
||||
.vhosts
|
||||
.iter()
|
||||
.map(|vhost| json!({"id": vhost.id, "hosts": vhost.frontend.hosts}))
|
||||
.collect::<Vec<_>>());
|
||||
payload["vhosts"] = json!(options);
|
||||
Ok(Json(payload))
|
||||
}
|
||||
|
||||
@@ -321,15 +352,9 @@ async fn cache_status(
|
||||
}
|
||||
};
|
||||
let snapshot = state.config.load_full();
|
||||
if query
|
||||
.vhost
|
||||
.as_ref()
|
||||
.is_some_and(|id| !snapshot.envelope.config.vhosts.iter().any(|v| &v.id == id))
|
||||
{
|
||||
return Err(ApiError(
|
||||
StatusCode::NOT_FOUND,
|
||||
"unknown vhost cache scope".into(),
|
||||
));
|
||||
let (vhosts, options, catalog_version) = monitored_vhost_catalog(&state);
|
||||
if query.vhost.as_ref().is_some_and(|id| !vhosts.iter().any(|vhost| &vhost.id == id)) {
|
||||
return Err(ApiError(StatusCode::NOT_FOUND, "unknown vhost cache scope".into()));
|
||||
}
|
||||
let dashboard = state.cache.dashboard(
|
||||
query.vhost.as_deref(),
|
||||
@@ -338,6 +363,7 @@ async fn cache_status(
|
||||
);
|
||||
let mut payload = json!({
|
||||
"revision": snapshot.envelope.revision,
|
||||
"catalog_version": catalog_version,
|
||||
"metrics": state.cache.view(),
|
||||
"dashboard": dashboard,
|
||||
"bans": state.cache.bans()
|
||||
@@ -346,9 +372,11 @@ async fn cache_status(
|
||||
return Ok(Json(payload));
|
||||
}
|
||||
payload["settings"] = json!(snapshot.envelope.config.cache);
|
||||
payload["vhosts"] = json!(snapshot.envelope.config.vhosts.iter().map(|vhost| {
|
||||
json!({"id":vhost.id, "hosts":vhost.frontend.hosts, "metrics":state.cache.scope_view(&vhost.id),
|
||||
"settings":vhost.cache.resolve(&snapshot.envelope.config.cache).ok()})
|
||||
payload["vhosts"] = json!(vhosts.iter().zip(options.iter()).map(|(vhost, option)| {
|
||||
let mut item = option.clone();
|
||||
item["metrics"] = json!(state.cache.scope_view(&vhost.id));
|
||||
item["settings"] = json!(vhost.cache.resolve(&snapshot.envelope.config.cache).ok());
|
||||
item
|
||||
}).collect::<Vec<_>>());
|
||||
Ok(Json(payload))
|
||||
}
|
||||
+52
-11
@@ -1961,9 +1961,7 @@
|
||||
"vhosts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"additionalProperties": true
|
||||
"$ref": "#/components/schemas/VhostScopeCatalogItem"
|
||||
}
|
||||
},
|
||||
"dashboard": {
|
||||
@@ -1976,6 +1974,10 @@
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/CacheBan"
|
||||
}
|
||||
},
|
||||
"catalog_version": {
|
||||
"type": "string",
|
||||
"description": "Fingerprint of effective Vhost scope catalog, including Docker publications. Check on view=live even when revision is unchanged."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
@@ -6961,9 +6963,12 @@
|
||||
"vhosts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
"$ref": "#/components/schemas/VhostScopeCatalogItem"
|
||||
}
|
||||
},
|
||||
"catalog_version": {
|
||||
"type": "string",
|
||||
"description": "Fingerprint of effective Vhost scope catalog, including Docker publications. Check on view=live even when revision is unchanged."
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -8959,6 +8964,42 @@
|
||||
"maxLength": 262144
|
||||
}
|
||||
}
|
||||
},
|
||||
"VhostScopeCatalogItem": {
|
||||
"type": "object",
|
||||
"description": "Effective reverse-proxy Vhost, including generated Docker publications. The stable ID remains the API scope; the label is presentation-only.",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"description": "Stable Vhost scope ID, also used in cache purge/invalidation and Traffic analytics."
|
||||
},
|
||||
"hosts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"docker": {
|
||||
"type": "boolean",
|
||||
"description": "True for a generated Docker Vhost."
|
||||
},
|
||||
"label": {
|
||||
"type": "string",
|
||||
"description": "Human-readable Vhost description; Docker entries include container/domain/agent where available."
|
||||
},
|
||||
"metrics": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Only in full Cache responses."
|
||||
},
|
||||
"settings": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"nullable": true,
|
||||
"description": "Resolved effective cache settings; only in full Cache responses."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -11025,7 +11066,7 @@
|
||||
"operationId": "get_api_cache",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Full response by default. view=live omits static settings/vhost configuration while retaining revision, live metrics, dashboard objects/domains and BAN rules.",
|
||||
"description": "Full response by default, including ordinary and generated Docker Vhost scopes (with human labels, resolved cache settings and metrics). view=live omits static settings/vhost definitions but retains revision, catalog_version, metrics, dashboard and BAN rules.",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
@@ -11080,7 +11121,7 @@
|
||||
"name": "vhost",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Configured vhost ID. Omit to select all scopes.",
|
||||
"description": "Ordinary or generated Docker Vhost ID. Omit to select all scopes.",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
@@ -11111,7 +11152,7 @@
|
||||
"name": "view",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Set to live for polling. Omits static settings and vhost configuration; refetch the full view when revision changes.",
|
||||
"description": "Set to live for polling. Omits static settings/vhost catalog; refetch full view when revision or catalog_version changes.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
@@ -14212,7 +14253,7 @@
|
||||
"name": "vhost",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Configured vhost ID or * for all vhosts.",
|
||||
"description": "Ordinary or generated Docker Vhost ID, or * for all Vhosts.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"default": "*"
|
||||
@@ -14222,7 +14263,7 @@
|
||||
"name": "view",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Set to live for polling. Omits the static vhost list; refetch the full view when revision changes.",
|
||||
"description": "Set to live for polling. Omits static Vhost list; refetch full view when revision or catalog_version changes.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
@@ -14233,7 +14274,7 @@
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Full response by default. view=live omits the static vhost list while retaining revision, current settings, GeoIP state and analytics.",
|
||||
"description": "Full response includes ordinary and generated Docker Vhost scope IDs with readable labels. view=live omits the static Vhost list while retaining revision, catalog_version, settings, GeoIP state and analytics.",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
|
||||
+2
-16
@@ -62,14 +62,7 @@ async fn cache_purge(
|
||||
Query(scope): Query<PurgeScope>,
|
||||
) -> Result<Json<Value>, ApiError> {
|
||||
if let Some(id) = &scope.vhost {
|
||||
if !state
|
||||
.config
|
||||
.load()
|
||||
.envelope
|
||||
.config
|
||||
.vhosts
|
||||
.iter()
|
||||
.any(|host| &host.id == id)
|
||||
if !cache_rule_vhosts(&state).iter().any(|host| &host.id == id)
|
||||
{
|
||||
return Err(ApiError(
|
||||
StatusCode::NOT_FOUND,
|
||||
@@ -119,14 +112,7 @@ async fn cache_invalidate(
|
||||
) -> Result<Json<Value>, ApiError> {
|
||||
let Json(request) = input.map_err(public::invalid_json)?;
|
||||
if let Some(id) = &request.vhost {
|
||||
if !state
|
||||
.config
|
||||
.load()
|
||||
.envelope
|
||||
.config
|
||||
.vhosts
|
||||
.iter()
|
||||
.any(|host| &host.id == id)
|
||||
if !cache_rule_vhosts(&state).iter().any(|host| &host.id == id)
|
||||
{
|
||||
return Err(ApiError(
|
||||
StatusCode::NOT_FOUND,
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
}
|
||||
function configure() {
|
||||
const selected = scope(); const items = [el("option", t("logAllVhosts"))]; items[0].value = "*";
|
||||
for (const host of envelope?.config.vhosts || []) { const item = el("option", `${host.id} / ${host.frontend.hosts.join(", ")}`); item.value = host.id; items.push(item); }
|
||||
for (const host of staticData?.vhosts || []) { const item = el("option", host.label || `${host.id} / ${(host.hosts || []).join(", ")}`); item.value = host.id; item.title = host.id; items.push(item); }
|
||||
$("cache-scope").replaceChildren(...items); $("cache-scope").value = items.some(e => e.value === selected) ? selected : "*";
|
||||
}
|
||||
function render(data) {
|
||||
@@ -255,11 +255,24 @@
|
||||
try {
|
||||
const base = `/api/cache?${query}`;
|
||||
if (staticData) query.set("view", "live");
|
||||
let data = await api(`/api/cache?${query}`, { signal });
|
||||
if (staticData && data.revision !== staticRevision) data = await api(base, { signal });
|
||||
let data;
|
||||
try {
|
||||
data = await api(`/api/cache?${query}`, { signal });
|
||||
} catch (error) {
|
||||
// A label-only Docker publication can disappear from the
|
||||
// effective catalog. Recover from its now-invalid scope.
|
||||
if (error?.status !== 404 || scope() === "*") throw error;
|
||||
$("cache-scope").value = "*";
|
||||
offset = 0; resetLiveChart("*");
|
||||
staticData = null; staticRevision = null;
|
||||
query.delete("vhost"); query.delete("view"); query.set("offset", "0");
|
||||
data = await api(`/api/cache?${query}`, { signal });
|
||||
}
|
||||
if (staticData && (data.revision !== staticRevision || data.catalog_version !== staticData.catalog_version)) data = await api(base, { signal });
|
||||
if (data.settings && Array.isArray(data.vhosts)) {
|
||||
staticData = { settings: data.settings, vhosts: data.vhosts };
|
||||
staticData = { settings: data.settings, vhosts: data.vhosts, catalog_version: data.catalog_version };
|
||||
staticRevision = data.revision;
|
||||
configure(); // Effective Docker vhosts can change without a saved config revision.
|
||||
} else if (staticData) {
|
||||
data = { ...staticData, ...data };
|
||||
}
|
||||
|
||||
@@ -165,6 +165,18 @@ window.rustProxyCacheRules = (() => {
|
||||
{ name: t("cacheRuleTplStaticCookies"), stage: "request", match: "all", conditions: [{ field: "extension", operator: "equals", values: ["css", "js", "mjs", "png", "jpg", "jpeg", "gif", "webp", "avif", "svg", "ico", "woff", "woff2"] }], actions: [{ type: "strip_cookies", keep: [] }] },
|
||||
{ name: t("cacheRuleTplStaticTtl"), stage: "response", match: "all", conditions: [{ field: "extension", operator: "equals", values: ["css", "js", "mjs", "png", "jpg", "jpeg", "gif", "webp", "avif", "svg", "ico", "woff", "woff2"] }, { field: "status", operator: "equals", values: ["200"] }], actions: [{ type: "ttl", seconds: 2592000 }, { type: "strip_set_cookie" }] },
|
||||
],
|
||||
// Opt-in CDN cookie policy. Never strip a mixed Cookie header: it may
|
||||
// contain session/authentication state required by the origin.
|
||||
cdn: () => {
|
||||
const technical = "(?:__cf_bm|cf_clearance|_cfuvid|__cfruid|__cfseq|_abck|ak_bmsc|bm_sz|bm_sv)";
|
||||
return [
|
||||
{ name: t("cacheRuleTplCdnMethods"), stage: "request", match: "all", conditions: [{ field: "method", operator: "equals", values: ["GET", "HEAD"], negate: true }], actions: [{ type: "pass" }], stop: true },
|
||||
{ name: t("cacheRuleTplCdnPrivate"), stage: "request", match: "all", conditions: [{ field: "path", operator: "regex", values: ["^/(admin|api|auth|login|logout|panel|konto|dashboard)(/|$)"] }], actions: [{ type: "pass" }], stop: true },
|
||||
{ name: t("cacheRuleTplCdnAuth"), stage: "request", match: "all", conditions: [{ field: "header", name: "Authorization", operator: "exists" }], actions: [{ type: "pass" }], stop: true },
|
||||
{ name: t("cacheRuleTplCdnStrip"), stage: "request", match: "all", conditions: [{ field: "header", name: "Cookie", operator: "regex", values: [`^${technical}=[^;]*(?:;[ \\t]*${technical}=[^;]*)*$`] }], actions: [{ type: "strip_cookies", keep: [] }] },
|
||||
{ name: t("cacheRuleTplCdnRemaining"), stage: "request", match: "all", conditions: [{ field: "header", name: "Cookie", operator: "exists" }], actions: [{ type: "pass" }], stop: true },
|
||||
];
|
||||
},
|
||||
tracking: () => [{ name: t("cacheRuleTplTracking"), stage: "request", match: "all", conditions: [], actions: [{ type: "strip_query", params: ["utm_*", "fbclid", "gclid", "msclkid", "mc_cid", "mc_eid", "_ga"] }] }],
|
||||
api: () => [{ name: t("cacheRuleTplApi"), stage: "request", match: "all", conditions: [{ field: "path", operator: "prefix", values: ["/api/"] }], actions: [{ type: "pass" }] }],
|
||||
language: () => [{ name: t("cacheRuleTplLanguage"), stage: "request", match: "all", conditions: [], actions: [{ type: "hash_cookie", name: "lang" }] }],
|
||||
|
||||
@@ -4224,6 +4224,36 @@ sub vcl_backend_response {
|
||||
<p class="fine" data-i18n="cacheGuideRequestWarning">Authorization, Cookie (except dedicated unset), Cache-Control and forwarding/transport headers are protected in request rules. Complex URL rewrites are warned about, not guessed. Always review import warnings.</p>
|
||||
<p class="fine" data-i18n="cacheGuideUncacheableDifference">RustProxy's beresp.uncacheable = false applies only to a previous cache-rule restriction; this is not Varnish's exact behavior. The backend's private/no-store and Set-Cookie protections remain unless deliberately rewritten by a separate trusted rule.</p>
|
||||
</section>
|
||||
<section class="cache-guide-card">
|
||||
<h3 data-i18n="cacheGuideCdnTitle">Cloudflare and Akamai technical Cookie template</h3>
|
||||
<p data-i18n="cacheGuideCdnText">Only strip the Cookie header when every cookie is a known technical CDN cookie. Any session or unknown cookie, Authorization, private path or non-GET/HEAD method bypasses cache.</p>
|
||||
<pre><code>// Optional template: only shared/public content independent of these cookies.
|
||||
// Cloudflare: __cf_bm, cf_clearance, _cfuvid, __cfruid, __cfseq
|
||||
// Akamai: _abck, ak_bmsc, bm_sz, bm_sv
|
||||
// Security cookies can be needed for bot challenges; review before enabling.
|
||||
sub vcl_recv {
|
||||
if (req.method != "GET" && req.method != "HEAD") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.url ~ "^/(admin|api|auth|login|logout|panel|konto|dashboard)(/|[?]|$)") {
|
||||
return(pass);
|
||||
}
|
||||
if (req.http.Authorization) {
|
||||
return(pass);
|
||||
}
|
||||
// Match the complete Cookie header, not one cookie within it.
|
||||
if (req.http.Cookie ~ "^(?:__cf_bm|cf_clearance|_cfuvid|__cfruid|__cfseq|_abck|ak_bmsc|bm_sz|bm_sv)=[^;]*(?:;[ \t]*(?:__cf_bm|cf_clearance|_cfuvid|__cfruid|__cfseq|_abck|ak_bmsc|bm_sz|bm_sv)=[^;]*)*$") {
|
||||
unset req.http.Cookie;
|
||||
}
|
||||
if (req.http.Cookie) {
|
||||
return(pass);
|
||||
}
|
||||
return(hash);
|
||||
}</code></pre>
|
||||
<button class="outline cache-guide-import-example" type="button"
|
||||
data-i18n="cacheGuideInsert">Insert into VCL importer</button>
|
||||
<p class="fine" data-i18n="cacheGuideCdnWarning">Optional policy: some CDN challenge cookies are required at the origin. Verify public pages and the challenge flow before using this template. It does not override Cache-Control and Vary admission safeguards.</p>
|
||||
</section>
|
||||
<section class="cache-guide-card">
|
||||
<h3 data-i18n="cacheGuideStagesTitle">VCL stages and rule precedence</h3>
|
||||
<p data-i18n="cacheGuideStagesText">vcl_recv handles pass/hash and request rewrites; vcl_hash supports selected hash_data(req.http.X); vcl_backend_response handles TTL, grace and backend headers; vcl_deliver edits final headers, even on HIT or BYPASS.</p>
|
||||
@@ -4245,6 +4275,7 @@ curl -sS -D - -o /dev/null \
|
||||
</div>
|
||||
<div class="cache-guide-footer">
|
||||
<p class="fine" data-i18n="cacheGuideScope">These VCL rules affect reverse-proxy vhosts; they do not execute on the embedded administration panel or all Web Server sources. Test on a non-production vhost first.</p>
|
||||
<a class="docs-link" href="/docs#doc=docs%2FVCL_SUPPORT_MATRIX.md" target="_blank" rel="noopener noreferrer" data-i18n="cacheGuideDocsMatrix">VCL support: implemented vs unsupported</a>
|
||||
<a class="docs-link" href="/docs#doc=docs%2FVCL.md" target="_blank" rel="noopener noreferrer" data-i18n="cacheGuideDocsVcl">Complete supported VCL syntax and limits</a>
|
||||
<a class="docs-link" href="/docs#doc=docs%2FCACHE.md" target="_blank" rel="noopener noreferrer" data-i18n="cacheGuideDocsCache">HTTP cache policy and diagnostics</a>
|
||||
</div>
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
const selected = scope(), options = [el("option", t("logAllVhosts"))];
|
||||
options[0].value = "*";
|
||||
for (const vhost of data.vhosts || []) {
|
||||
const option = el("option", `${vhost.id} / ${(vhost.hosts || []).join(", ")}`);
|
||||
option.value = vhost.id; options.push(option);
|
||||
const option = el("option", vhost.label || `${vhost.id} / ${(vhost.hosts || []).join(", ")}`);
|
||||
option.value = vhost.id; option.title = vhost.id; options.push(option);
|
||||
}
|
||||
$("traffic-scope").replaceChildren(...options);
|
||||
$("traffic-scope").value = options.some(option => option.value === selected) ? selected : "*";
|
||||
@@ -117,12 +117,22 @@
|
||||
loading = true;
|
||||
try {
|
||||
const base = `/api/traffic?vhost=${encodeURIComponent(scope())}`;
|
||||
let data = await api(staticData ? `${base}&view=live` : base, { signal });
|
||||
if (staticData && data.revision !== staticRevision) {
|
||||
let data;
|
||||
try {
|
||||
data = await api(staticData ? `${base}&view=live` : base, { signal });
|
||||
} catch (error) {
|
||||
// Labels are inventory-derived. If the selected publication
|
||||
// vanished, fall back to All rather than polling a stale ID.
|
||||
if (error?.status !== 404 || scope() === "*") throw error;
|
||||
$("traffic-scope").value = "*";
|
||||
staticData = null; staticRevision = null;
|
||||
data = await api("/api/traffic?vhost=*", { signal });
|
||||
}
|
||||
if (staticData && (data.revision !== staticRevision || data.catalog_version !== staticData.catalog_version)) {
|
||||
data = await api(base, { signal });
|
||||
}
|
||||
if (Array.isArray(data.vhosts)) {
|
||||
staticData = { vhosts: data.vhosts };
|
||||
staticData = { vhosts: data.vhosts, catalog_version: data.catalog_version };
|
||||
staticRevision = data.revision;
|
||||
} else if (staticData) {
|
||||
data = { ...staticData, ...data };
|
||||
|
||||
Vendored
+16
@@ -848,6 +848,22 @@ impl CompiledCondition {
|
||||
.header
|
||||
.as_ref()
|
||||
.map(|header| {
|
||||
if header.as_str() == http::header::COOKIE.as_str() {
|
||||
// Cookie can appear in several field lines. An anchored
|
||||
// allowlist must match all of them, not just one. Bad
|
||||
// UTF-8 or an empty field must still count as present
|
||||
// so subsequent `if (req.http.Cookie) return(pass)`
|
||||
// remains fail-closed.
|
||||
let mut parts = Vec::new();
|
||||
for value in request.headers.get_all(header).iter() {
|
||||
match value.to_str() {
|
||||
Ok(text) => parts.push(text),
|
||||
Err(_) => return vec![Cow::Borrowed("")],
|
||||
}
|
||||
}
|
||||
return if parts.is_empty() { Vec::new() }
|
||||
else { vec![Cow::Owned(parts.join("; "))] };
|
||||
}
|
||||
request
|
||||
.headers
|
||||
.get_all(header)
|
||||
|
||||
Vendored
+68
@@ -993,4 +993,72 @@ sub vcl_deliver {
|
||||
assert!(import_vcl("sub vcl_recv { set req.http.X-A = \"missing; }").is_err());
|
||||
assert!(import_vcl("sub vcl_recv { /* missing */ set req.http.X-A = \"x\"; /*").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vcl_cdn_template_strips_only_complete_technical_cookie_headers() {
|
||||
let vcl = include_str!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/examples/vcl/cdn-technical-cookies.vcl"
|
||||
));
|
||||
let imported = import_vcl(vcl).unwrap();
|
||||
assert!(imported.warnings.is_empty(), "{:?}", imported.warnings);
|
||||
assert!(!imported.rules.is_empty());
|
||||
validate_rules(&imported.rules, true).unwrap();
|
||||
let compiled = CompiledRules::compile("shop", &[], &imported.rules, false).unwrap();
|
||||
|
||||
for cookie in [
|
||||
"__cf_bm=token",
|
||||
"cf_clearance=token; _cfuvid=id",
|
||||
"_abck=abc; ak_bmsc=def; bm_sz=xyz",
|
||||
"__cfseq=token; __cfruid=other; bm_sv=third",
|
||||
] {
|
||||
let input = request("/", None, &[("cookie", cookie)]);
|
||||
let result = compiled.evaluate_request(&input, false);
|
||||
assert!(result.pass.is_none(), "unexpected pass on {cookie}");
|
||||
assert!(result.lookup.is_some(), "missing lookup on {cookie}");
|
||||
let mut forwarded = input.headers.clone();
|
||||
result.rewrite_cookies(&mut forwarded);
|
||||
assert!(!forwarded.contains_key(http::header::COOKIE), "{cookie}");
|
||||
}
|
||||
for cookie in [
|
||||
"session=secret",
|
||||
"__cf_bm=token; session=secret",
|
||||
"session=secret; cf_clearance=token",
|
||||
"__cf_bm=token; XSRF-TOKEN=csrf",
|
||||
"cf_clearance=token; unknown_cookie=x",
|
||||
] {
|
||||
let input = request("/", None, &[("cookie", cookie)]);
|
||||
let result = compiled.evaluate_request(&input, false);
|
||||
assert!(result.pass.is_some(), "missing pass on {cookie}");
|
||||
let mut forwarded = input.headers.clone();
|
||||
result.rewrite_cookies(&mut forwarded);
|
||||
assert_eq!(forwarded.get(http::header::COOKIE).unwrap(), cookie);
|
||||
}
|
||||
// Cookie may be split across multiple HTTP header field lines.
|
||||
// Matching any single field line would discard a real session cookie.
|
||||
let split = request("/", None, &[
|
||||
("cookie", "__cf_bm=token"),
|
||||
("cookie", "session=secret"),
|
||||
]);
|
||||
let result = compiled.evaluate_request(&split, false);
|
||||
assert!(result.pass.is_some());
|
||||
assert!(result.strip_cookies.is_none());
|
||||
|
||||
let mut invalid_cookie = request("/", None, &[]);
|
||||
invalid_cookie.headers.insert(http::header::COOKIE,
|
||||
HeaderValue::from_bytes(b"__cf_bm=\xff").unwrap());
|
||||
let result = compiled.evaluate_request(&invalid_cookie, false);
|
||||
assert!(result.pass.is_some());
|
||||
assert!(result.strip_cookies.is_none());
|
||||
|
||||
for path in ["/admin", "/admin/settings", "/login", "/api/profile", "/konto"] {
|
||||
let input = request(path, None, &[("cookie", "__cf_bm=token")]);
|
||||
assert!(compiled.evaluate_request(&input, false).pass.is_some(), "{path}");
|
||||
}
|
||||
let input = request("/", None, &[("Authorization", "Bearer test")]);
|
||||
assert!(compiled.evaluate_request(&input, false).pass.is_some());
|
||||
let mut post = request("/", None, &[]);
|
||||
post.method = Method::POST;
|
||||
assert!(compiled.evaluate_request(&post, false).pass.is_some());
|
||||
}
|
||||
}
|
||||
@@ -367,6 +367,59 @@ mod tests {
|
||||
assert!(route.backend.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn docker_cache_settings_and_id_survive_container_disappearance_and_return() {
|
||||
let mut desired = crate::config::demo_config("127.0.0.1:9000".parse().unwrap());
|
||||
desired.vhosts.clear();
|
||||
desired.docker_agents.agents.push(Agent {
|
||||
id: "node1".into(),
|
||||
name: "Node 1".into(),
|
||||
base_domain: "docker1.lab.local".into(),
|
||||
listener_ids: vec!["http".into()],
|
||||
assignments: vec![Assignment {
|
||||
service_key: "container:app:8080/tcp".into(),
|
||||
hostname: "app".into(),
|
||||
cache_enabled: true,
|
||||
cache_default_ttl_seconds: Some(180),
|
||||
cache_rules: vec![serde_json::from_value(serde_json::json!({
|
||||
"id": "no-admin-cache",
|
||||
"conditions": [{"field": "path", "operator": "prefix", "values": ["/admin"]}],
|
||||
"actions": [{"type": "pass"}]
|
||||
})).unwrap()],
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
});
|
||||
let persisted = serde_json::to_value(&desired.docker_agents.agents[0].assignments[0])
|
||||
.unwrap();
|
||||
let restored: Assignment = serde_json::from_value(persisted).unwrap();
|
||||
assert_eq!(restored.cache_default_ttl_seconds, Some(180));
|
||||
assert_eq!(restored.cache_rules.len(), 1);
|
||||
|
||||
let found = observation(service(), vec![HostAddress {
|
||||
ip: "10.2.3.4".into(),
|
||||
source: "interface".into(),
|
||||
interface: "eth0".into(),
|
||||
scope: "private".into(),
|
||||
}]);
|
||||
let before = effective_config(desired.clone(), &found).unwrap();
|
||||
assert!(!before.vhosts[0].transient_unavailable);
|
||||
|
||||
let mut missing = found.clone();
|
||||
missing.get_mut("node1").unwrap().inventory.as_mut().unwrap().services.clear();
|
||||
let offline = effective_config(desired.clone(), &missing).unwrap();
|
||||
assert_eq!(offline.vhosts.len(), 1);
|
||||
assert!(offline.vhosts[0].transient_unavailable);
|
||||
assert_eq!(offline.vhosts[0].id, before.vhosts[0].id);
|
||||
assert_eq!(offline.vhosts[0].cache.default_ttl_seconds, Some(180));
|
||||
assert_eq!(offline.vhosts[0].cache.rules.len(), 1);
|
||||
|
||||
let returned = effective_config(desired, &found).unwrap();
|
||||
assert!(!returned.vhosts[0].transient_unavailable);
|
||||
assert_eq!(returned.vhosts[0].id, before.vhosts[0].id);
|
||||
assert_eq!(returned.vhosts[0].cache.rules.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_agent_observation_with_last_inventory_keeps_backend_materialized() {
|
||||
let mut desired = crate::config::demo_config("127.0.0.1:9000".parse().unwrap());
|
||||
@@ -932,6 +985,25 @@ mod tests {
|
||||
.any(|item| item.assignment.service_key == "container:web:80/tcp"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn label_only_publications_reappear_without_becoming_persisted_assignments() {
|
||||
let (desired, found) = label_config(vec![labelled(
|
||||
"web", 80, &[("rustproxy.enable", "true"), ("rustproxy.host", "web")],
|
||||
)]);
|
||||
assert!(desired.docker_agents.agents[0].assignments.is_empty());
|
||||
let before = effective_config(desired.clone(), &found).unwrap();
|
||||
assert_eq!(before.vhosts.len(), 1);
|
||||
|
||||
let mut missing = found.clone();
|
||||
missing.get_mut("node1").unwrap().inventory.as_mut().unwrap().services.clear();
|
||||
assert!(effective_config(desired.clone(), &missing).unwrap().vhosts.is_empty());
|
||||
|
||||
let again = effective_config(desired.clone(), &found).unwrap();
|
||||
assert_eq!(again.vhosts.len(), 1);
|
||||
assert_eq!(again.vhosts[0].id, before.vhosts[0].id);
|
||||
assert!(desired.docker_agents.agents[0].assignments.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alerts_cover_offline_resources_missing_and_unhealthy_services() {
|
||||
let unhealthy = Service {
|
||||
|
||||
Reference in new issue
Block a user