v0.43.1
This commit is contained in:
1 parent
7514227b3b
commit
dba6668dc9
13 files changed
+156
-25
No files matched your search
@@ -4124,6 +4124,13 @@
|
||||
"certificate_mismatch": {
|
||||
"type": "boolean",
|
||||
"description": "True when the certificate was used although it does not cover the hostnames (the assignment allows a mismatch)."
|
||||
},
|
||||
"sni_certificate_ids": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "When no certificate is selected for the route (agent in Automatic mode or no selected certificate covers the hostnames), the stored certificates SNI serves for its hostnames."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
+40
-2
@@ -260,11 +260,47 @@ async fn backend_status(State(state): State<Arc<App>>) -> Json<Value> {
|
||||
"active_frontends":state.active_listeners, "desired_frontends":snapshot.listeners}),
|
||||
)
|
||||
}
|
||||
fn sni_certificates(
|
||||
selected: Option<&str>,
|
||||
hosts: &[String],
|
||||
certificates: &[crate::tls::Certificate],
|
||||
) -> Vec<String> {
|
||||
if selected.is_some() {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut ids = Vec::new();
|
||||
for host in hosts {
|
||||
if let Some(id) = crate::tls::sni_certificate_id(certificates, host) {
|
||||
if !ids.contains(&id) {
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
ids
|
||||
}
|
||||
fn docker_runtime_views(state: &Arc<App>) -> (Vec<Value>, Vec<Value>, Value) {
|
||||
let snapshot = state.config.load_full();
|
||||
let config = &snapshot.envelope.config;
|
||||
let observed = state.docker.latest();
|
||||
let (publications, issues) = crate::docker::label_publications(config, &observed);
|
||||
let sni_pool: Vec<crate::tls::Certificate> = config
|
||||
.tls
|
||||
.certificates
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|mut certificate| {
|
||||
if certificate.covered_hosts.is_empty() {
|
||||
if let Some(directory) = state.policy.cert_dir.as_deref() {
|
||||
if let Ok(names) =
|
||||
crate::tls::certificate_covered_hosts(directory, &certificate.cert_file)
|
||||
{
|
||||
certificate.covered_hosts = names;
|
||||
}
|
||||
}
|
||||
}
|
||||
certificate
|
||||
})
|
||||
.collect();
|
||||
let mut routes = Vec::new();
|
||||
let mut ids = std::collections::HashSet::new();
|
||||
for agent in &config.docker_agents.agents {
|
||||
@@ -282,7 +318,8 @@ fn docker_runtime_views(state: &Arc<App>) -> (Vec<Value>, Vec<Value>, Value) {
|
||||
&config.tls.certificates,
|
||||
&hosts,
|
||||
);
|
||||
routes.push(json!({"agent_id": &agent.id, "service_key": &assignment.service_key, "pool_id": pool_id, "enabled": assignment.enabled, "hosts": hosts, "certificate_id": certificate_id, "certificate_mismatch": certificate_mismatch}));
|
||||
let sni_certificate_ids = sni_certificates(certificate_id.as_deref(), &hosts, &sni_pool);
|
||||
routes.push(json!({"agent_id": &agent.id, "service_key": &assignment.service_key, "pool_id": pool_id, "enabled": assignment.enabled, "hosts": hosts, "certificate_id": certificate_id, "certificate_mismatch": certificate_mismatch, "sni_certificate_ids": sni_certificate_ids}));
|
||||
}
|
||||
}
|
||||
for publication in &publications {
|
||||
@@ -303,7 +340,8 @@ fn docker_runtime_views(state: &Arc<App>) -> (Vec<Value>, Vec<Value>, Value) {
|
||||
)
|
||||
})
|
||||
.unwrap_or((None, false));
|
||||
routes.push(json!({"agent_id": &publication.agent_id, "service_key": &publication.assignment.service_key, "pool_id": pool_id, "source": "labels", "assignment": &publication.assignment, "hosts": &publication.hosts, "certificate_id": certificate_id, "certificate_mismatch": certificate_mismatch}));
|
||||
let sni_certificate_ids = sni_certificates(certificate_id.as_deref(), &publication.hosts, &sni_pool);
|
||||
routes.push(json!({"agent_id": &publication.agent_id, "service_key": &publication.assignment.service_key, "pool_id": pool_id, "source": "labels", "assignment": &publication.assignment, "hosts": &publication.hosts, "certificate_id": certificate_id, "certificate_mismatch": certificate_mismatch, "sni_certificate_ids": sni_certificate_ids}));
|
||||
}
|
||||
let pools = snapshot
|
||||
.pools
|
||||
|
||||
@@ -70,14 +70,14 @@ function certificateUsage(cert) {
|
||||
vhosts: (config.vhosts || []).filter(item => item.certificate_id === cert.id).map(item => ({ id: item.id, hosts: hostsOf(item), mismatch: item.allow_certificate_mismatch === true, open: () => { setPanel("vhosts"); window.rustProxyVhosts?.edit(item.id); } })),
|
||||
redirects: (config.redirects || []).filter(item => item.certificate_id === cert.id).map(item => ({ id: item.id, hosts: hostsOf(item), open: () => { setPanel("redirects"); window.rustProxyRedirects?.edit(item.id); } })),
|
||||
notfound: (config.not_found_hosts || []).filter(item => item.certificate_id === cert.id).map(item => ({ id: item.id, hosts: hostsOf(item), open: () => { setPanel("notfound"); window.rustProxyNotFound?.edit(item.id); } })),
|
||||
dockerVhosts: certificateDockerRoutes().filter(route => route.certificate_id === cert.id).map(route => ({ id: `${route.agent_id} · ${route.service_key}`, hosts: route.hosts || [], mismatch: route.certificate_mismatch === true, docker: true, open: () => { setPanel("docker-vhosts"); const search = $("docker-search"); if (search) { search.value = (route.hosts || [])[0] || route.service_key; search.dispatchEvent(new Event("input", { bubbles: true })); } } })),
|
||||
dockerVhosts: certificateDockerRoutes().filter(route => route.certificate_id === cert.id || (route.sni_certificate_ids || []).includes(cert.id)).map(route => ({ id: `${route.agent_id} · ${route.service_key}`, hosts: route.hosts || [], mismatch: route.certificate_mismatch === true, sni: route.certificate_id !== cert.id, docker: true, open: () => { setPanel("docker-vhosts"); const search = $("docker-search"); if (search) { search.value = (route.hosts || [])[0] || route.service_key; search.dispatchEvent(new Event("input", { bubbles: true })); } } })),
|
||||
docker: (config.docker_agents?.agents || []).filter(agent => [agent.certificate_id, ...(agent.certificate_ids || [])].includes(cert.id)).map(agent => ({ id: agent.id, hosts: agent.domains || [], open: () => { setPanel("settings"); window.rustProxySettings?.select?.("docker-agents"); } }))
|
||||
};
|
||||
const legacy = [];
|
||||
for (const item of config.vhosts || []) if (item.certificate_id === cert.id) legacy.push(`vhost:${item.id}`);
|
||||
for (const item of config.redirects || []) if (item.certificate_id === cert.id) legacy.push(`redirect:${item.id}`);
|
||||
for (const item of config.not_found_hosts || []) if (item.certificate_id === cert.id) legacy.push(`404:${item.id}`);
|
||||
for (const route of certificateDockerRoutes()) if (route.certificate_id === cert.id) legacy.push(`docker:${route.agent_id}/${route.service_key}`);
|
||||
for (const route of certificateDockerRoutes()) if (route.certificate_id === cert.id || (route.sni_certificate_ids || []).includes(cert.id)) legacy.push(`docker:${route.agent_id}/${route.service_key}`);
|
||||
const admin = config.administration?.certificate_id === cert.id, isDefault = settings.default_certificate === cert.id;
|
||||
if (admin) legacy.push(t("administration"));
|
||||
if (isDefault) legacy.push(t("defaultLabel"));
|
||||
@@ -224,7 +224,8 @@ function renderCertificates() {
|
||||
const cover = certificateCoverageState(coverage, item.hosts);
|
||||
const pillText = cover.state === "full" ? t("certificateCovered") : cover.state === "unknown" ? t("certificateCoverageUnknownShort") : `${t("certificateNotCovered")}: ${cover.missing.join(", ")}${item.mismatch ? ` · ${t("certificateMismatchAccepted")}` : ""}`;
|
||||
const open = el("button", t("certificateOpen"), "quiet certificate-usage-open"); open.type = "button"; open.dataset.uiIconName = "none"; open.addEventListener("click", item.open);
|
||||
row.append(el("span", item.id, "mono"), el("span", item.hosts.join(", ") || "-", "fine"), el("span", pillText, `pill${cover.state === "full" ? " live" : cover.state === "unknown" ? "" : " warn"}`), open);
|
||||
const idCell = el("span", item.id, "mono"); if (item.sni) { const sni = el("span", t("certificateSniAuto"), "pill certificate-usage-sni"); sni.title = t("certificateSniAutoHelp"); idCell.append(" ", sni); }
|
||||
row.append(idCell, el("span", item.hosts.join(", ") || "-", "fine"), el("span", pillText, `pill${cover.state === "full" ? " live" : cover.state === "unknown" ? "" : " warn"}`), open);
|
||||
group.append(row);
|
||||
}
|
||||
usageSection.append(group);
|
||||
|
||||
@@ -73,6 +73,10 @@ textarea {
|
||||
min-height: var(--ui-field-min-height);
|
||||
}
|
||||
|
||||
select {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
a {
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
touch-action: manipulation;
|
||||
|
||||
@@ -109,6 +109,10 @@
|
||||
align-self: end;
|
||||
}
|
||||
|
||||
:is(.vh-grid, .field-grid)>:is(.vh-field, label:not([class]), .auto-id-field)>:is(input:not([type=checkbox], [type=radio]), select) {
|
||||
align-self: start;
|
||||
}
|
||||
|
||||
:is(.vh-grid, .field-grid):has(>.auto-id-field:not(.is-compact))>:is(.vh-field, label:not([class]), .auto-id-field) {
|
||||
grid-template-rows: none;
|
||||
}
|
||||
@@ -1349,6 +1353,27 @@ p,
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.acl-profile-rule label>span.acl-profile-rule-action-badge {
|
||||
display: flex;
|
||||
margin-bottom: 0;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.acl-profile-rule :is(select, input, .acl-profile-rule-action-badge, .acl-profile-rule-remove) {
|
||||
box-sizing: border-box;
|
||||
height: 32px;
|
||||
min-height: 32px;
|
||||
margin-block: 0;
|
||||
}
|
||||
|
||||
.acl-profile-rule .acl-profile-rule-action-badge {
|
||||
padding-block: 0;
|
||||
}
|
||||
|
||||
.acl-profile-rule>label {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.acl-profile-bulk {
|
||||
margin-top: 9px;
|
||||
border-top: 1px solid var(--line);
|
||||
|
||||
@@ -671,7 +671,7 @@ html:not([data-switch-controls="false"]) .docker-publish-field input.docker-publ
|
||||
.docker-agent-grid select {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
min-height: 38px;
|
||||
min-height: var(--ui-field-min-height);
|
||||
margin: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
@@ -1423,7 +1423,7 @@ html[data-dashboard-density=normal] #panel-overview .stat>span,
|
||||
|
||||
.docker-certificate-field>select {
|
||||
width: 100%;
|
||||
min-height: 38px;
|
||||
min-height: var(--ui-field-min-height);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn sni_certificate_id_prefers_bound_names_then_the_narrowest_covering_certificate() {
|
||||
let cert = |id: &str, hosts: &[&str], covered: &[&str]| Certificate {
|
||||
issuer: None,
|
||||
id: id.into(),
|
||||
covered_hosts: covered.iter().map(|v| v.to_string()).collect(),
|
||||
hosts: hosts.iter().map(|v| v.to_string()).collect(),
|
||||
cert_file: format!("{id}.pem"),
|
||||
key_file: format!("{id}.key"),
|
||||
};
|
||||
let certificates = vec![
|
||||
cert("wide", &[], &["*.apps.example.org", "apps.example.org", "*.example.org", "example.org"]),
|
||||
cert("apps", &[], &["*.apps.example.org", "apps.example.org"]),
|
||||
cert("bound", &["shop.apps.example.org"], &[]),
|
||||
];
|
||||
assert_eq!(sni_certificate_id(&certificates, "web.apps.example.org").as_deref(), Some("apps"));
|
||||
assert_eq!(sni_certificate_id(&certificates, "SHOP.apps.example.org.").as_deref(), Some("bound"));
|
||||
assert_eq!(sni_certificate_id(&certificates, "www.example.org").as_deref(), Some("wide"));
|
||||
assert_eq!(sni_certificate_id(&certificates, "a.b.apps.example.org"), None);
|
||||
assert_eq!(sni_certificate_id(&certificates, "example.net"), None);
|
||||
}
|
||||
|
||||
fn private_tempdir() -> tempfile::TempDir {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -278,6 +278,35 @@ fn lookup(map: &HashMap<String, Arc<CertifiedKey>>, host: &str) -> Option<Arc<Ce
|
||||
.or_else(|| single_label_wildcard(host).and_then(|wildcard| map.get(&wildcard)))
|
||||
.cloned()
|
||||
}
|
||||
pub fn sni_certificate_id(certificates: &[Certificate], server_name: &str) -> Option<String> {
|
||||
let host = normalize_host(server_name).ok()?;
|
||||
let candidates = |exact: bool| {
|
||||
let mut best: Option<(usize, &str)> = None;
|
||||
for certificate in certificates {
|
||||
let mut names: Vec<String> = certificate
|
||||
.hosts
|
||||
.iter()
|
||||
.chain(if exact { [].iter() } else { certificate.covered_hosts.iter() })
|
||||
.filter_map(|name| normalize_host_pattern(name).ok())
|
||||
.collect();
|
||||
names.sort();
|
||||
names.dedup();
|
||||
let wildcard = single_label_wildcard(&host);
|
||||
if !names
|
||||
.iter()
|
||||
.any(|name| *name == host || Some(name) == wildcard.as_ref())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let size = if exact { 0 } else { names.len() };
|
||||
if best.is_none_or(|(current, _)| size < current) {
|
||||
best = Some((size, certificate.id.as_str()));
|
||||
}
|
||||
}
|
||||
best.map(|(_, id)| id.to_owned())
|
||||
};
|
||||
candidates(true).or_else(|| candidates(false))
|
||||
}
|
||||
impl Resolver {
|
||||
fn named(&self, server_name: &str) -> Option<Arc<CertifiedKey>> {
|
||||
let host = normalize_host(server_name).ok()?;
|
||||
|
||||
Reference in new issue
Block a user