A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
chore(deploy): pin base images and document proxy ranges (#3885)
Hampus8a6c4f709c1b
diff --git a/deploy/helm/fluxer/templates/NOTES.txt b/deploy/helm/fluxer/templates/NOTES.txtindex 40c72e728..4772418b8 100644--- a/deploy/helm/fluxer/templates/NOTES.txt+++ b/deploy/helm/fluxer/templates/NOTES.txt@@ -24,7 +24,8 @@ Point DNS for {{ $v.domain }} at the external address of the edge-public Service{{- else if eq $v.edge.expose "none" }}Nothing exposes the instance yet. Send your proxy or tunnel to the Service edge-on port 8080, with the Host header {{ $v.domain }}.+on port 8080, with the Host header {{ $v.domain }}. The proxy must replace+X-Forwarded-For with the client address it sees, or add that address at the end.{{- else }}Point DNS for {{ $v.domain }} at your {{ ternary "ingress controller" "gateway" (eq $v.edge.expose "ingress") }}. Its Service needsdiff --git a/deploy/helm/fluxer/values.yaml b/deploy/helm/fluxer/values.yamlindex 0b742379d..cdb5599ef 100644--- a/deploy/helm/fluxer/values.yaml+++ b/deploy/helm/fluxer/values.yaml@@ -710,7 +710,10 @@ edge:storageClassName: ""replicas: 1# Edge settings as NAME: value, overriding the chart's, for example- # FLUXER_EDGE_GLOBAL_OPTIONS or FLUXER_EDGE_ENCODE.+ # FLUXER_EDGE_GLOBAL_OPTIONS, FLUXER_EDGE_ENCODE, or FLUXER_EDGE_TRUSTED_PROXIES+ # set to the address range of your ingress controller, gateway or proxy.+ # Outside loadBalancer mode the edge takes the client IP from X-Forwarded-For+ # sent by any private address unless you narrow it.env: {}extraEnv: []resources:diff --git a/fluxer_docs/Dockerfile b/fluxer_docs/Dockerfileindex b267c990f..c77ec8ecd 100644--- a/fluxer_docs/Dockerfile+++ b/fluxer_docs/Dockerfile@@ -1,7 +1,7 @@# SPDX-License-Identifier: AGPL-3.0-or-laterARG BUILD_VERSION-FROM node:26-trixie-slim AS base+FROM node:26-trixie-slim@sha256:5adad64f9a1fca2d51972caa65983634c8a774eb300d72b20f7f2a0f60368072 AS baseWORKDIR /usr/src/app@@ -26,7 +26,7 @@ RUN pnpm install --frozen-lockfileRUN pnpm --filter fluxer_docs run buildRUN pnpm deploy --legacy --filter=fluxer_docs --prod --config.allow-unused-patches=true /out-FROM node:26-trixie-slim+FROM node:26-trixie-slim@sha256:5adad64f9a1fca2d51972caa65983634c8a774eb300d72b20f7f2a0f60368072ARG BUILD_VERSION=""ARG SOURCE_SHA=""diff --git a/fluxer_docs/src/installer/RexctlRelease.ts b/fluxer_docs/src/installer/RexctlRelease.tsindex 6f222f5dc..ced0966aa 100644--- a/fluxer_docs/src/installer/RexctlRelease.ts+++ b/fluxer_docs/src/installer/RexctlRelease.ts@@ -11,6 +11,8 @@ const CACHE_MS = 5 * 60 * 1000;const RETRY_MS = 30 * 1000;const FETCH_TIMEOUT_MS = 15 * 1000;const PAGES = 3;+const MAX_ENTRIES = 256;+const PINNED_RESERVE = 15;const CALVER = /^\d{4}\.\d{3,4}\.\d{1,6}$/;const SHA256 = /^[0-9a-f]{64}$/;const ENGINE_VERSION = /^\d+\.\d+\.\d+$/;@@ -66,6 +68,9 @@ interface CacheEntry {}const cache = new Map<string, CacheEntry>();+let githubRetryAt = 0;+let rateLimitRemaining = Number.POSITIVE_INFINITY;+let rateLimitResetAt = 0;export class ResolverUnavailableError extends Error {}@@ -91,10 +96,19 @@ async function getJSON<T>(url: string): Promise<T | null> {},signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),});+ const remaining = Number.parseInt(response.headers.get('x-ratelimit-remaining') ?? '', 10);+ const reset = Number.parseInt(response.headers.get('x-ratelimit-reset') ?? '', 10);+ if (Number.isFinite(remaining) && Number.isFinite(reset)) {+ rateLimitRemaining = remaining;+ rateLimitResetAt = reset * 1000;+ }if (response.status === 404) {return null;}if (!response.ok) {+ const now = Date.now();+ const exhausted = (response.status === 403 || response.status === 429) && remaining === 0;+ githubRetryAt = exhausted && rateLimitResetAt > now ? rateLimitResetAt : now + RETRY_MS;throw new ResolverUnavailableError(`GitHub answered ${response.status} for ${url}`);}return (await response.json()) as T;@@ -241,19 +255,33 @@ async function resolveVersion(version: string): Promise<RexctlRelease | null> {return toRexctlRelease(release, version);}+function evictOldest(): void {+ if (cache.size < MAX_ENTRIES) {+ return;+ }+ for (const [key, entry] of cache) {+ if (key !== 'latest' && !entry.pending) {+ cache.delete(key);+ return;+ }+ }+}+export async function resolveRexctlRelease(version: string | null): Promise<RexctlRelease | null> {const key = version ?? 'latest';const now = Date.now();let entry = cache.get(key);if (!entry) {entry = {value: null, fetchedAt: 0, failedAt: 0, pending: null};+ evictOldest();cache.set(key, entry);}const current = entry;if (now - current.fetchedAt < CACHE_MS) {return current.value;}- if (now - current.failedAt < RETRY_MS) {+ const quotaReserved = version !== null && rateLimitRemaining < PINNED_RESERVE && now < rateLimitResetAt;+ if (!current.pending && (now - current.failedAt < RETRY_MS || now < githubRetryAt || quotaReserved)) {if (current.value) {return current.value;}diff --git a/fluxer_docs/src/server/AstroServer.ts b/fluxer_docs/src/server/AstroServer.tsindex e0f3a0f43..0f80c7a99 100644--- a/fluxer_docs/src/server/AstroServer.ts+++ b/fluxer_docs/src/server/AstroServer.ts@@ -432,7 +432,7 @@ async function serveStaticOrRender({}if (shouldRedirectStaticDirectory(staticFile, requestPath)) {response.writeHead(HttpStatus.MOVED_PERMANENTLY, {- [HTTPHeader.LOCATION]: `${requestPath.pathname}/${requestPath.search}`,+ [HTTPHeader.LOCATION]: `${requestPath.pathname.replace(/^\/+/u, '/')}/${requestPath.search}`,[HTTPHeader.CONTENT_LENGTH]: '0',[HTTPHeader.CACHE_CONTROL]: 'no-cache',});diff --git a/tools/dev/src/desktop_modules.rs b/tools/dev/src/desktop_modules.rsindex 1a69a88d8..05c8c2b02 100644--- a/tools/dev/src/desktop_modules.rs+++ b/tools/dev/src/desktop_modules.rs@@ -13,12 +13,11 @@ use std::path::{Path, PathBuf};use std::process::{Command, Stdio};use std::time::{SystemTime, UNIX_EPOCH};-pub const DEVELOPMENT_PACKAGE_ORIGIN: &str = "http://localhost:48780";+pub const DEVELOPMENT_PACKAGE_ORIGIN: &str = "http://127.0.0.1:48780";const PKGS_ROOT_ENV: &str = "FLUXER_DEV_PKGS_ROOT";const PKGS_CONTAINER: &str = "fluxer-dev-pkgs";const PKGS_IMAGE: &str = "nginx:1.28";const PKGS_PUBLISH: &str = "127.0.0.1:48780:80";-const PKGS_PROBE_ORIGIN: &str = "http://127.0.0.1:48780";const PKGS_CONTAINER_ROOT: &str = "/srv/pkgs";const PKGS_CONTAINER_CONFIG: &str = "/etc/nginx/conf.d/default.conf";const PKGS_NGINX_CONFIG: &str = "server {@@ -552,7 +551,7 @@ pub fn ensure_pkgs_server() -> Result<()> {fn verify_served_manifest(target: &ModuleCoordinate, metadata_version: u64) -> Result<()> {let url = format!(- "{PKGS_PROBE_ORIGIN}/desktop/{}/{}/{}/{CHANNEL_MANIFEST_NAME}",+ "{DEVELOPMENT_PACKAGE_ORIGIN}/desktop/{}/{}/{}/{CHANNEL_MANIFEST_NAME}",target.channel, target.platform, target.arch);let mut last = String::new();diff --git a/tools/dev/src/gateway.rs b/tools/dev/src/gateway.rsindex a773dd185..90f650c89 100644--- a/tools/dev/src/gateway.rs+++ b/tools/dev/src/gateway.rs@@ -1,6 +1,6 @@// SPDX-License-Identifier: AGPL-3.0-or-later-use crate::paths::{DEV_GATEWAY_DIR, GATEWAY_CONFIG_DIR, ROOT};+use crate::paths::{DEV_GATEWAY_DIR, GATEWAY_CONFIG_DIR, ROOT, write_private_file};use crate::proc::{AwaitOutcome, RESTART_LIMIT, RESTART_WINDOW, RunOptions, ShutdownSignal, await_or_shutdown,can_bind_tcp_port, cleanup_orphaned_process_groups, configure_process_group,@@ -116,7 +116,7 @@ pub fn write_gateway_config(.replace("${FLUXER_ERLANG_NODE_NAME}", node_name).replace("${FLUXER_ERLANG_COOKIE}", cookie).replace("${FLUXER_ERLANG_DIST_PORT}", dist_port);- fs::write(config_dir.join("vm.args"), vm_text)?;+ write_private_file(&config_dir.join("vm.args"), &vm_text)?;Ok(())}diff --git a/tools/dev/src/paths.rs b/tools/dev/src/paths.rsindex 3c038dbe2..5b9c68471 100644--- a/tools/dev/src/paths.rs+++ b/tools/dev/src/paths.rs@@ -67,6 +67,26 @@ pub fn ensure_writable_dev_paths() -> Result<()> {Ok(())}+pub fn write_private_file(path: &Path, contents: &str) -> Result<()> {+ use std::io::Write;+ let mut options = std::fs::OpenOptions::new();+ options.write(true).create(true).truncate(true);+ #[cfg(unix)]+ std::os::unix::fs::OpenOptionsExt::mode(&mut options, 0o600);+ let mut file = options+ .open(path)+ .with_context(|| format!("failed to write {}", path.display()))?;+ #[cfg(unix)]+ {+ use std::os::unix::fs::PermissionsExt;+ file.set_permissions(std::fs::Permissions::from_mode(0o600))+ .with_context(|| format!("failed to set permissions on {}", path.display()))?;+ }+ file.write_all(contents.as_bytes())+ .with_context(|| format!("failed to write {}", path.display()))?;+ Ok(())+}+pub fn which(name: &str) -> Option<PathBuf> {let path = std::env::var_os("PATH")?;for dir in std::env::split_paths(&path) {diff --git a/tools/dev/src/proxy.rs b/tools/dev/src/proxy.rsindex 8c82e8fbf..a65f73864 100644--- a/tools/dev/src/proxy.rs+++ b/tools/dev/src/proxy.rs@@ -15,7 +15,7 @@ use axum::{use hyper_util::rt::TokioIo;use std::collections::HashMap;use std::env;-use std::net::SocketAddr;+use std::net::{IpAddr, SocketAddr};use std::sync::{Arc, LazyLock, Mutex};use std::time::Duration;use tokio::io::{AsyncReadExt, AsyncWriteExt};@@ -57,6 +57,7 @@ const BLOCKED_RESPONSE_HEADERS: &[&str] = &["upgrade",];const X_FORWARDED_FOR_HEADER: &str = "x-forwarded-for";+const CF_CONNECTING_IP_HEADER: &str = "cf-connecting-ip";pub async fn run_proxy(host: &str, port: u16) -> Result<()> {let bind = format!("{host}:{port}");@@ -105,6 +106,7 @@ async fn proxy_request(return redirect_response(&request_head, &location).into_response();}+ let client_ip = forwarded_client_ip(&request_head, client_addr).to_string();let route = route_for_path(&request_head.path);let (target_host, target_port) = target_for_route(route, &state.gateway_ports);if is_upgrade_request(&request_head) {@@ -114,7 +116,7 @@ async fn proxy_request(route,target_host,target_port,- client_addr,+ &client_ip,).await;}@@ -126,11 +128,21 @@ async fn proxy_request(route,target_host,target_port,- client_addr,+ &client_ip,).await}+fn forwarded_client_ip(request: &RequestHead, client_addr: SocketAddr) -> IpAddr {+ if client_addr.ip().is_loopback()+ && let Some(ip) = header_value(request, CF_CONNECTING_IP_HEADER)+ .and_then(|value| value.trim().parse::<IpAddr>().ok())+ {+ return ip;+ }+ client_addr.ip()+}+async fn proxy_http(state: ProxyState,request: Request<Body>,@@ -138,7 +150,7 @@ async fn proxy_http(route: &'static ProxyRoute,target_host: &'static str,target_port: u16,- client_addr: SocketAddr,+ client_ip: &str,) -> Response<Body> {let target_url = upstream_http_url(&request_head.path, route, target_host, target_port);let (parts, body) = request.into_parts();@@ -147,27 +159,18 @@ async fn proxy_http(if method != Method::GET && method != Method::HEAD {request_builder = request_builder.body(reqwest::Body::wrap_stream(body.into_data_stream()));}- let mut saw_forwarded_for = false;for (name, value) in &parts.headers {let name_str = name.as_str();- if BLOCKED_REQUEST_HEADERS.contains(&name_str) {+ if BLOCKED_REQUEST_HEADERS.contains(&name_str)+ || name_str.eq_ignore_ascii_case(X_FORWARDED_FOR_HEADER)+ {continue;}- if name.as_str().eq_ignore_ascii_case(X_FORWARDED_FOR_HEADER) {- saw_forwarded_for = true;- if let Some(value) = append_forwarded_for(value, client_addr) {- request_builder = request_builder.header(name.clone(), value);- }- } else {- request_builder = request_builder.header(name.clone(), value.clone());- }+ request_builder = request_builder.header(name.clone(), value.clone());}- if !saw_forwarded_for {- request_builder =- request_builder.header(X_FORWARDED_FOR_HEADER, client_addr.ip().to_string());- }+ request_builder = request_builder.header(X_FORWARDED_FOR_HEADER, client_ip);let upstream_response = match request_builder.send().await {Ok(response) => response,@@ -191,7 +194,7 @@ async fn proxy_upgrade(route: &'static ProxyRoute,target_host: &'static str,target_port: u16,- client_addr: SocketAddr,+ client_ip: &str,) -> Response<Body> {let on_upgrade = hyper::upgrade::on(&mut request);let mut target = match TcpStream::connect((target_host, target_port)).await {@@ -205,7 +208,7 @@ async fn proxy_upgrade(route,Some(target_host),Some(target_port),- Some(&client_addr.ip().to_string()),+ Some(client_ip),)).await{@@ -283,11 +286,6 @@ fn request_head_from_request(request: &Request<Body>) -> RequestHead {}}-fn append_forwarded_for(value: &HeaderValue, client_addr: SocketAddr) -> Option<HeaderValue> {- let value = value.to_str().ok()?;- HeaderValue::from_str(&format!("{value}, {}", client_addr.ip())).ok()-}-fn copy_response_headers(source: &HeaderMap, target: &mut HeaderMap) {for (name, value) in source {if BLOCKED_RESPONSE_HEADERS.contains(&name.as_str()) {@@ -621,7 +619,6 @@ pub fn rewrite_head(rewrite_path(&request.path, route),request.version)];- let mut saw_forwarded_for = false;let mut saw_host = false;let mut saw_connection = false;for (name, value) in &request.headers {@@ -634,13 +631,8 @@ pub fn rewrite_head("Connection: {}",if is_upgrade { "Upgrade" } else { "close" }));- } else if name.eq_ignore_ascii_case("x-forwarded-for") {- saw_forwarded_for = true;- if let Some(client_ip) = client_ip {- lines.push(format!("{name}: {value}, {client_ip}"));- } else {- lines.push(format!("{name}: {value}"));- }+ } else if name.eq_ignore_ascii_case(X_FORWARDED_FOR_HEADER) {+ continue;} else {lines.push(format!("{name}: {value}"));}@@ -654,9 +646,7 @@ pub fn rewrite_head(if is_upgrade { "Upgrade" } else { "close" }));}- if let Some(client_ip) = client_ip- && !saw_forwarded_for- {+ if let Some(client_ip) = client_ip {lines.push(format!("X-Forwarded-For: {client_ip}"));}lines.push(String::new());diff --git a/tools/dev/src/tunnel.rs b/tools/dev/src/tunnel.rsindex d7a64ad9c..1f247d672 100644--- a/tools/dev/src/tunnel.rs+++ b/tools/dev/src/tunnel.rs@@ -1,7 +1,7 @@// SPDX-License-Identifier: AGPL-3.0-or-lateruse crate::manifest::{DEV_PROXY_PORT, LOCAL_APP_URL, LOOPBACK_HOST};-use crate::paths::{DEV_STATE_DIR, ROOT, which};+use crate::paths::{DEV_STATE_DIR, ROOT, which, write_private_file};use crate::proc::wait_tcp;use anyhow::{Context, Result, bail};use std::fs;@@ -170,9 +170,7 @@ pub fn write_cloudflare_token_file(token: &str) -> Result<PathBuf> {fs::create_dir_all(DEV_STATE_DIR.as_path()).with_context(|| format!("failed to create {}", DEV_STATE_DIR.display()))?;let path = default_token_file();- fs::write(&path, format!("{}\n", token.trim()))- .with_context(|| format!("failed to write {}", path.display()))?;- set_private_file_mode(&path)?;+ write_private_file(&path, &format!("{}\n", token.trim()))?;println!("Saved Cloudflare tunnel token to {}", path.display());Ok(path)}@@ -226,7 +224,8 @@ pub async fn run_cloudflare_tunnel(println!("Starting Cloudflare Tunnel for {public_url} -> http://127.0.0.1:8088");if let Some(binary) = resolve_cloudflared_binary() {let status = Command::new(binary)- .args(["tunnel", "run", "--token", token.as_str()])+ .args(["tunnel", "run"])+ .env("TUNNEL_TOKEN", &token).status().context("failed to start cloudflared")?;return Ok(status.code().unwrap_or(1));@@ -251,12 +250,13 @@ pub async fn run_cloudflare_tunnel("--rm","--network",&format!("container:{container}"),+ "-e",+ "TUNNEL_TOKEN","cloudflare/cloudflared:latest","tunnel","run",- "--token",- token.as_str(),])+ .env("TUNNEL_TOKEN", &token).status().context("failed to start cloudflare/cloudflared Docker image")?;return Ok(status.code().unwrap_or(1));@@ -351,23 +351,13 @@ fn docker_command() -> Vec<PathBuf> {if docker_socket_is_writable() || which("sudo").is_none() {return vec![PathBuf::from("docker")];}- vec![PathBuf::from("sudo"), PathBuf::from("docker")]+ vec![+ PathBuf::from("sudo"),+ PathBuf::from("--preserve-env=TUNNEL_TOKEN"),+ PathBuf::from("docker"),+ ]}fn docker_socket_is_writable() -> bool {std::os::unix::net::UnixStream::connect("/var/run/docker.sock").is_ok()}--#[cfg(unix)]-fn set_private_file_mode(path: &Path) -> Result<()> {- use std::os::unix::fs::PermissionsExt;- let mut permissions = fs::metadata(path)?.permissions();- permissions.set_mode(0o600);- fs::set_permissions(path, permissions)?;- Ok(())-}--#[cfg(not(unix))]-fn set_private_file_mode(_path: &Path) -> Result<()> {- Ok(())-}