mirror of
https://github.com/sadoyan/aralez.git
synced 2026-06-10 17:24:21 +08:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27aca0a3a5 | ||
|
|
3c99ed0c44 | ||
|
|
4a6e1d817b | ||
|
|
f6a2df44d0 | ||
|
|
e8d976f5f1 | ||
|
|
a1341e90f7 | ||
|
|
ddcacc509c | ||
|
|
2b385cc630 | ||
|
|
1b5223986d | ||
|
|
ac2bd8113d | ||
|
|
4d9a2ecfe3 | ||
|
|
aa70d818b2 | ||
|
|
15d356f087 | ||
|
|
b17962e6d5 | ||
|
|
ea779182f2 | ||
|
|
9339a142a6 | ||
|
|
cfc9bd319d | ||
|
|
a5ced59e5c | ||
|
|
c3df7bc131 | ||
|
|
0248d73836 | ||
|
|
96a5aef7d0 | ||
|
|
5c3b72b7a3 | ||
|
|
3cf0fc493f | ||
|
|
207ee481fb | ||
|
|
1c2f7327aa | ||
|
|
310a554a25 | ||
|
|
69a5167346 | ||
|
|
4734ccab2f | ||
|
|
61d65f6e4e | ||
|
|
20ac39067d | ||
|
|
7afa76de8f | ||
|
|
e29161965f | ||
|
|
9216710dda |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,6 +7,7 @@
|
|||||||
*.sh
|
*.sh
|
||||||
/docs/
|
/docs/
|
||||||
/docs
|
/docs
|
||||||
|
/etc
|
||||||
/target/
|
/target/
|
||||||
*.iml
|
*.iml
|
||||||
.idea/
|
.idea/
|
||||||
|
|||||||
123
Cargo.lock
generated
123
Cargo.lock
generated
@@ -135,7 +135,6 @@ dependencies = [
|
|||||||
"axum",
|
"axum",
|
||||||
"base16ct 1.0.0",
|
"base16ct 1.0.0",
|
||||||
"base64",
|
"base64",
|
||||||
"ctrlc",
|
|
||||||
"dashmap",
|
"dashmap",
|
||||||
"futures",
|
"futures",
|
||||||
"instant-acme",
|
"instant-acme",
|
||||||
@@ -156,10 +155,12 @@ dependencies = [
|
|||||||
"rcgen",
|
"rcgen",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rustls-pemfile",
|
"rustls-pemfile",
|
||||||
|
"sd-notify",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yml",
|
"serde_yml",
|
||||||
"sha2 0.11.0",
|
"sha2 0.11.0",
|
||||||
|
"signal-hook",
|
||||||
"subtle",
|
"subtle",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tonic",
|
"tonic",
|
||||||
@@ -359,6 +360,15 @@ version = "1.8.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
|
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bit-vec"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b71798fca2c1fe1086445a7258a4bc81e6e49dcd24c8d0dd9a1e57395b603f51"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@@ -398,15 +408,6 @@ dependencies = [
|
|||||||
"hybrid-array",
|
"hybrid-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block2"
|
|
||||||
version = "0.6.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5"
|
|
||||||
dependencies = [
|
|
||||||
"objc2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "brotli"
|
name = "brotli"
|
||||||
version = "3.5.0"
|
version = "3.5.0"
|
||||||
@@ -719,17 +720,6 @@ dependencies = [
|
|||||||
"hybrid-array",
|
"hybrid-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ctrlc"
|
|
||||||
version = "3.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e0b1fab2ae45819af2d0731d60f2afe17227ebb1a1538a236da84c93e9a60162"
|
|
||||||
dependencies = [
|
|
||||||
"dispatch2",
|
|
||||||
"nix 0.31.2",
|
|
||||||
"windows-sys 0.61.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "curve25519-dalek"
|
name = "curve25519-dalek"
|
||||||
version = "4.1.3"
|
version = "4.1.3"
|
||||||
@@ -956,18 +946,6 @@ dependencies = [
|
|||||||
"crypto-common 0.2.1",
|
"crypto-common 0.2.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dispatch2"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.11.1",
|
|
||||||
"block2",
|
|
||||||
"libc",
|
|
||||||
"objc2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "displaydoc"
|
name = "displaydoc"
|
||||||
version = "0.2.5"
|
version = "0.2.5"
|
||||||
@@ -1940,9 +1918,9 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libmimalloc-sys"
|
name = "libmimalloc-sys"
|
||||||
version = "0.1.47"
|
version = "0.1.49"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2d1eacfa31c33ec25e873c136ba5669f00f9866d0688bea7be4d3f7e43067df6"
|
checksum = "6a45a52f43e1c16f667ccfe4dd8c85b7f7c204fd5e3bf46c5b0db9a5c3c0b8e9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
@@ -1995,9 +1973,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.29"
|
version = "0.4.30"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
@@ -2075,9 +2053,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mimalloc"
|
name = "mimalloc"
|
||||||
version = "0.1.50"
|
version = "0.1.52"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b3627c4272df786b9260cabaa46aec1d59c93ede723d4c3ef646c503816b0640"
|
checksum = "2d4139bb28d14ad1facf21d5eb8825051b326e172d216b39f6d31df53cc97862"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libmimalloc-sys",
|
"libmimalloc-sys",
|
||||||
]
|
]
|
||||||
@@ -2202,18 +2180,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nix"
|
|
||||||
version = "0.31.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5d6d0705320c1e6ba1d912b5e37cf18071b6c2e9b7fa8215a1e8a7651966f5d3"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.11.1",
|
|
||||||
"cfg-if",
|
|
||||||
"cfg_aliases",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nom"
|
name = "nom"
|
||||||
version = "7.1.3"
|
version = "7.1.3"
|
||||||
@@ -2315,15 +2281,6 @@ dependencies = [
|
|||||||
"libm",
|
"libm",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "objc2"
|
|
||||||
version = "0.6.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f"
|
|
||||||
dependencies = [
|
|
||||||
"objc2-encode",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "objc2-core-foundation"
|
name = "objc2-core-foundation"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@@ -2343,12 +2300,6 @@ dependencies = [
|
|||||||
"objc2-core-foundation",
|
"objc2-core-foundation",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "objc2-encode"
|
|
||||||
version = "4.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "object"
|
name = "object"
|
||||||
version = "0.37.3"
|
version = "0.37.3"
|
||||||
@@ -3147,9 +3098,9 @@ checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rcgen"
|
name = "rcgen"
|
||||||
version = "0.14.7"
|
version = "0.14.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "10b99e0098aa4082912d4c649628623db6aba77335e4f4569ff5083a6448b32e"
|
checksum = "57f6d249aad744e274e682777a50283a225a32705394ee6d5fcc01efa25e4055"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-lc-rs",
|
"aws-lc-rs",
|
||||||
"pem",
|
"pem",
|
||||||
@@ -3200,9 +3151,9 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.13.3"
|
version = "0.13.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "62e0021ea2c22aed41653bc7e1419abb2c97e038ff2c33d0e1309e49a97deec0"
|
checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -3465,6 +3416,15 @@ version = "1.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sd-notify"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3e4ef7359e694bfaf1dd27a30f9d760b54c00dfae9f19bd0c05a39bc9128fe76"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sec1"
|
name = "sec1"
|
||||||
version = "0.7.3"
|
version = "0.7.3"
|
||||||
@@ -3550,9 +3510,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.149"
|
version = "1.0.150"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -3651,6 +3611,16 @@ version = "1.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook"
|
||||||
|
version = "0.4.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2a0c28ca5908dbdbcd52e6fdaa00358ab88637f8ab33e1f188dd510eb44b53d"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"signal-hook-registry",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook-registry"
|
name = "signal-hook-registry"
|
||||||
version = "1.4.8"
|
version = "1.4.8"
|
||||||
@@ -4111,9 +4081,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-http"
|
name = "tower-http"
|
||||||
version = "0.6.10"
|
version = "0.6.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "68d6fdd9f81c2819c9a8b0e0cd91660e7746a8e6ea2ba7c6b2b057985f6bcb51"
|
checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.11.1",
|
"bitflags 2.11.1",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -4891,10 +4861,11 @@ checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yasna"
|
name = "yasna"
|
||||||
version = "0.5.2"
|
version = "0.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd"
|
checksum = "b5f6765e852b9b4dc8e2a76843e4d64d1cea8e79bcde0b6901aea8e7c7f08282"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bit-vec",
|
||||||
"time",
|
"time",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
15
Cargo.toml
15
Cargo.toml
@@ -20,11 +20,11 @@ pingora-proxy = "0.8.0"
|
|||||||
pingora-http = "0.8.0"
|
pingora-http = "0.8.0"
|
||||||
pingora-limits = "0.8.0"
|
pingora-limits = "0.8.0"
|
||||||
async-trait = "0.1.89"
|
async-trait = "0.1.89"
|
||||||
log = "0.4.29"
|
log = "0.4.30"
|
||||||
futures = "0.3.32"
|
futures = "0.3.32"
|
||||||
notify = "9.0.0-rc.4"
|
notify = "9.0.0-rc.4"
|
||||||
axum = { version = "0.8.9" }
|
axum = { version = "0.8.9" }
|
||||||
reqwest = { version = "0.13.3", features = ["json", "stream", "blocking"] }
|
reqwest = { version = "0.13.4", features = ["json", "stream", "blocking"] }
|
||||||
serde_yml = "0.0.12"
|
serde_yml = "0.0.12"
|
||||||
rand = "0.10.1"
|
rand = "0.10.1"
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
@@ -34,17 +34,18 @@ sha2 = { version = "0.11.0-rc.5", default-features = false }
|
|||||||
base16ct = { version = "1.0.0", features = ["alloc"] }
|
base16ct = { version = "1.0.0", features = ["alloc"] }
|
||||||
urlencoding = "2.1.3"
|
urlencoding = "2.1.3"
|
||||||
arc-swap = "1.9.1"
|
arc-swap = "1.9.1"
|
||||||
mimalloc = { version = "0.1.50", default-features = false }
|
|
||||||
prometheus = "0.14.0"
|
prometheus = "0.14.0"
|
||||||
x509-parser = "0.18.1"
|
x509-parser = "0.18.1"
|
||||||
rustls-pemfile = "2.2.0"
|
rustls-pemfile = "2.2.0"
|
||||||
tower-http = { version = "0.6.10", features = ["fs"] }
|
tower-http = { version = "0.6.11", features = ["fs"] }
|
||||||
privdrop = "0.5.6"
|
privdrop = "0.5.6"
|
||||||
ctrlc = "3.5.2"
|
serde_json = "1.0.150"
|
||||||
serde_json = "1.0.149"
|
|
||||||
subtle = "2.6.1"
|
subtle = "2.6.1"
|
||||||
moka = { version = "0.12.15", features = ["sync"] }
|
moka = { version = "0.12.15", features = ["sync"] }
|
||||||
ahash = "0.8.12"
|
ahash = "0.8.12"
|
||||||
instant-acme = "0.8.5"
|
instant-acme = "0.8.5"
|
||||||
rcgen = "0.14.7"
|
rcgen = "0.14.8"
|
||||||
log4rs = "1.4.0"
|
log4rs = "1.4.0"
|
||||||
|
mimalloc = { version = "0.1.52", default-features = false }
|
||||||
|
signal-hook = "0.4.4"
|
||||||
|
sd-notify = "0.5.0"
|
||||||
|
|||||||
13
Dockerfile
13
Dockerfile
@@ -1,13 +0,0 @@
|
|||||||
FROM debian:trixie-slim
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y ca-certificates curl net-tools iputils-ping
|
|
||||||
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
COPY aralez /usr/local/bin/aralez
|
|
||||||
|
|
||||||
RUN chmod +x /usr/local/bin/aralez
|
|
||||||
RUN mkdir -p /etc/aralez/certs/upstreams
|
|
||||||
|
|
||||||
WORKDIR /etc/aralez
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/aralez", "-c", "/etc/aralez/main.yaml"]
|
|
||||||
79
README.md
79
README.md
@@ -50,31 +50,27 @@ Built on Rust, on top of **Cloudflare’s Pingora engine**, **Aralez** delivers
|
|||||||
|
|
||||||
### `main.yaml`
|
### `main.yaml`
|
||||||
|
|
||||||
| Key | Example Value | Description |
|
| Key | Example Value | Description |
|
||||||
|----------------------------------|--------------------------|----------------------------------------------------------------------------------------------------|
|
|----------------------------------|----------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
| **threads** | 12 | Number of running daemon threads. Optional, defaults to 1 |
|
| **threads** | 12 | Number of running daemon threads. Optional, defaults to 1 |
|
||||||
| **runuser** | aralez | Optional, Username for running aralez after dropping root privileges, requires to launch as root |
|
| **runuser** | aralez | Optional. Username for running aralez after dropping root privileges (requires launch as root) |
|
||||||
| **rungroup** | aralez | Optional,Group for running aralez after dropping root privileges, requires to launch as root |
|
| **rungroup** | aralez | Optional. Group for running aralez after dropping root privileges (requires launch as root) |
|
||||||
| **daemon** | false | Run in background (boolean) |
|
| **daemon** | false | Run in background (boolean) |
|
||||||
| **upstream_keepalive_pool_size** | 500 | Pool size for upstream keepalive connections |
|
| **upstream_keepalive_pool_size** | 500 | Pool size for upstream keepalive connections |
|
||||||
| **pid_file** | /tmp/aralez.pid | Path to PID file |
|
| **pid_file** | /tmp/aralez.pid | Path to PID file |
|
||||||
| **error_log** | /tmp/aralez_err.log | Path to error log file |
|
| **config_address** | 0.0.0.0:3000 | HTTP API address for pushing upstreams.yaml from remote location |
|
||||||
| **upgrade_sock** | /tmp/aralez.sock | Path to live upgrade socket file |
|
| **proxy_tls_grade** | high, medium, unsafe | Grade of TLS ciphers. `high` matches Qualys SSL Labs A+ (defaults to `medium`) |
|
||||||
| **config_address** | 0.0.0.0:3000 | HTTP API address for pushing upstreams.yaml from remote location |
|
| **proxy_address_http** | 0.0.0.0:6193 | Aralez HTTP bind address |
|
||||||
| **proxy_tls_grade** | (high, medium, unsafe) | Grade of TLS ciphers, for easy configuration. High matches Qualys SSL Labs A+ (defaults to medium) |
|
| **proxy_address_tls** | 0.0.0.0:6194 | Aralez HTTPS bind address (Optional) |
|
||||||
| **config_tls_key_file** | etc/key.pem | Private Key file path. Mandatory if proxy_address_tls is set, else optional |
|
| **proxy_configs** | /etc/aralez/ | Direcotry containing configuration files, must be writeable by user `aralez` |
|
||||||
| **proxy_address_http** | 0.0.0.0:6193 | Aralez HTTP bind address |
|
| **upstreams_conf** | /etc/aralez/upstreams.yaml | Location of the upstreams file |
|
||||||
| **proxy_address_tls** | 0.0.0.0:6194 | Aralez HTTPS bind address (Optional) |
|
| **log_level** | info | Log level: `info`, `warn`, `error`, `debug`, `trace`, `off` |
|
||||||
| **proxy_configs** | etc/ | The top directory of config files |
|
| **log_file** | /full/path/to/aralez.log | Optional, the location of log file. If thi entry does not exist logs will be emitted to stdout. |
|
||||||
| **upstreams_conf** | etc/upstreams.yaml | The location of upstreams file |
|
| **hc_method** | HEAD | Healthcheck method: HEAD, GET, POST (UPPERCASE) |
|
||||||
| **log_level** | info | Log level , possible values : info, warn, error, debug, trace, off |
|
| **hc_interval** | 2 | Interval for health checks in seconds |
|
||||||
| **log_file** | /full/path/to/aralez.log | Optional, the location of log file. If thi entry does not exist logs will be emitted to stdout. |
|
| **file_server_folder** | /some/local/folder | Optional. Local folder to serve |
|
||||||
| **hc_method** | HEAD | Healthcheck method (HEAD, GET, POST are supported) UPPERCASE |
|
| **file_server_address** | 127.0.0.1:3002 | Optional. Local address for file server |
|
||||||
| **hc_interval** | 2 | Interval for health checks in seconds |
|
| **config_api_enabled** | true | Enable/disable remote config push capability |
|
||||||
| **master_key** | Random long string | Master key for working with API server and JWT Secret generation |
|
|
||||||
| **file_server_folder** | /some/local/folder | Optional, local folder to serve |
|
|
||||||
| **file_server_address** | 127.0.0.1:3002 | Optional, Local address for file server. Can set as upstream for public access |
|
|
||||||
| **config_api_enabled** | true | Boolean to enable/disable remote config push capability |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -113,6 +109,24 @@ For getting the best performance on newer hardware use `aralez-x86_64-*.gz`.
|
|||||||
docker run -d -v /path/to/config:/etc/aralez:rw -p 80:80 -p 443:443 sadoyan/aralez
|
docker run -d -v /path/to/config:/etc/aralez:rw -p 80:80 -p 443:443 sadoyan/aralez
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Dockerfile :**
|
||||||
|
|
||||||
|
```dockerfile
|
||||||
|
FROM debian:trixie-slim
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y ca-certificates curl net-tools iputils-ping
|
||||||
|
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY aralez /usr/local/bin/aralez
|
||||||
|
|
||||||
|
RUN chmod +x /usr/local/bin/aralez
|
||||||
|
RUN mkdir -p /etc/aralez/certs/upstreams
|
||||||
|
|
||||||
|
WORKDIR /etc/aralez
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/aralez", "-c", "/etc/aralez/main.yaml"]
|
||||||
|
```
|
||||||
|
|
||||||
## Running the Proxy
|
## Running the Proxy
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -121,7 +135,7 @@ docker run -d -v /path/to/config:/etc/aralez:rw -p 80:80 -p 443:443 sadoyan/aral
|
|||||||
|
|
||||||
## Systemd integration
|
## Systemd integration
|
||||||
|
|
||||||
Assuming Arales in installed in `/opt/aralez` folder
|
Assuming Aralez in installed in `/opt/aralez` folder
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cat > /etc/systemd/system/aralez.service <<EOF
|
cat > /etc/systemd/system/aralez.service <<EOF
|
||||||
@@ -209,7 +223,7 @@ DEFAULT:
|
|||||||
|
|
||||||
**This means:**
|
**This means:**
|
||||||
|
|
||||||
- Sticky sessions are enabled globally. This setting applies to all upstreams. If enabled the value withh be set for `Max-Age=` cookie.
|
- Sticky sessions are enabled globally. This setting applies to all upstreams. If enabled the value will be set for `Max-Age=` cookie.
|
||||||
- HTTP to HTTPS redirect disabled globally, but can be overridden by `to_https` setting per upstream.
|
- HTTP to HTTPS redirect disabled globally, but can be overridden by `to_https` setting per upstream.
|
||||||
- All upstreams will receive custom headers : `X-Forwarded-Proto:https` and `X-Forwarded-Port:443`
|
- All upstreams will receive custom headers : `X-Forwarded-Proto:https` and `X-Forwarded-Port:443`
|
||||||
- Additionally, myhost.mydomain.com with path `/` will receive custom headers : `X-Another-Header:Hohohohoho` and `X-Something-Else:Foobar`
|
- Additionally, myhost.mydomain.com with path `/` will receive custom headers : `X-Another-Header:Hohohohoho` and `X-Something-Else:Foobar`
|
||||||
@@ -251,11 +265,20 @@ DEFAULT:
|
|||||||
To enable TLS for the proxy server.
|
To enable TLS for the proxy server.
|
||||||
|
|
||||||
- Set `proxy_address_tls` in `main.yaml`
|
- Set `proxy_address_tls` in `main.yaml`
|
||||||
- Provide at least on `tls_certificate/tls_key_file` pair.
|
- Provide at least one `tls_certificate/tls_key_file` pair.
|
||||||
- First pair is required to create the TLS listener.
|
- First pair is required to create the TLS listener.
|
||||||
- This pair can be anything, even self-signed with dummy domain.
|
- This pair can be anything, even self-signed with dummy domain.
|
||||||
- After getting normal certificate it can be deleted
|
- After getting normal certificate it can be deleted
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mkdir -p /etc/aralez/certificates
|
||||||
|
chown -R aralez:aralez /etc/aralez
|
||||||
|
cd /etc/aralez/certificates
|
||||||
|
openssl req -x509 -newkey rsa:4096 \
|
||||||
|
-keyout dummy.key -out dummy.crt -sha256 -days 3650 -nodes \
|
||||||
|
-subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Remote Config API
|
## Remote Config API
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Main configuration file, applied on startup
|
# Main configuration file, applied on startup
|
||||||
threads: 12 # Number of daemon threads default setting
|
threads: 12 # Number of daemon threads default setting
|
||||||
runuser: aralez # Username for running aralez after dropping root privileges, requires program to start as root
|
#runuser: pastor # Username for running aralez after dropping root privileges, requires program to start as root
|
||||||
rungroup: aralez # Group for running aralez after dropping root privileges, requires program to start as root
|
#rungroup: pastor # Group for running aralez after dropping root privileges, requires program to start as root
|
||||||
daemon: false # Run in background
|
daemon: false # Run in background
|
||||||
upstream_keepalive_pool_size: 500 # Pool size for upstream keepalive connections
|
upstream_keepalive_pool_size: 500 # Pool size for upstream keepalive connections
|
||||||
pid_file: /tmp/aralez.pid # Path to PID file
|
pid_file: /tmp/aralez.pid # Path to PID file
|
||||||
@@ -11,12 +11,13 @@ config_api_enabled: true # Boolean to enable/disable remote config push capabili
|
|||||||
config_address: 0.0.0.0:3000 # HTTP API address for pushing upstreams.yaml from remote location
|
config_address: 0.0.0.0:3000 # HTTP API address for pushing upstreams.yaml from remote location
|
||||||
proxy_address_http: 0.0.0.0:6193 # Proxy HTTP bind address
|
proxy_address_http: 0.0.0.0:6193 # Proxy HTTP bind address
|
||||||
proxy_address_tls: 0.0.0.0:6194 # Optional, Proxy TLS bind address
|
proxy_address_tls: 0.0.0.0:6194 # Optional, Proxy TLS bind address
|
||||||
proxy_configs: /opt/aralez/etc # Mandatory if proxy_address_tls set, should contain a certificate and key files strictly in a format {NAME}.crt, {NAME}.key.
|
proxy_configs: /opt/Rust/Projects/asyncweb/etc # Mandatory if proxy_address_tls set, should contain a certificate and key files strictly in a format {NAME}.crt, {NAME}.key.
|
||||||
proxy_tls_grade: a+ # Grade of TLS suite for proxy (a+, a, b, c, unsafe), matching grades of Qualys SSL Labs
|
proxy_tls_grade: high # Grade of TLS suite for proxy (high, medium, unsafe), matching grades of Qualys SSL Labs
|
||||||
upstreams_conf: /opt/aralez/etc/upstreams.yaml # the location of upstreams file
|
upstreams_conf: /opt/Rust/Projects/asyncweb/etc/upstreams.yaml # the location of upstreams file
|
||||||
file_server_folder: /opt/storage # Optional, local folder to serve
|
#file_server_folder: /opt/storage # Optional, local folder to serve
|
||||||
file_server_address: 127.0.0.1:3002 # Optional, Local address for file server. Can set as upstream for public access.
|
#file_server_address: 127.0.0.1:3002 # Optional, Local address for file server. Can set as upstream for public access.
|
||||||
log_level: info # info, warn, error, debug, trace, off
|
log_level: info # info, warn, error, debug, trace, off
|
||||||
|
log_file: /tmp/aralez.log # Optional, the location of log file. If this entry does not exist logs will be emitted to stdout.
|
||||||
hc_method: HEAD # Healthcheck method (HEAD, GET, POST are supported) UPPERCASE
|
hc_method: HEAD # Healthcheck method (HEAD, GET, POST are supported) UPPERCASE
|
||||||
hc_interval: 2 #Interval for health checks in seconds
|
hc_interval: 2 #Interval for health checks in seconds
|
||||||
master_key: 910517d9-f9a1-48de-8826-dbadacbd84af-cb6f830e-ab16-47ec-9d8f-0090de732774 # Mater key for working with API server and JWT Secret
|
#master_key: 910517d9-f9a1-48de-8826-dbadacbd84af-cb6f830e-ab16-47ec-9d8f-0090de732774 # Mater key for working with API server and JWT Secret
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
# The file under watch and hot reload, changes are applied immediately, no need to restart or reload.
|
# The file under watch and hot reload, changes are applied immediately, no need to restart or reload.
|
||||||
provider: "file" # "file" "consul" "kubernetes"
|
provider: "file" # "file" "consul" "kubernetes"
|
||||||
sticky_sessions: false
|
sticky_sessions: 8600
|
||||||
to_https: false
|
to_https: false
|
||||||
rate_limit: 100
|
rate_limit: 300
|
||||||
|
x4xx_limit: 200
|
||||||
server_headers:
|
server_headers:
|
||||||
- "X-Forwarded-Proto:https"
|
- "X-Forwarded-Proto:https"
|
||||||
- "X-Forwarded-Port:443"
|
- "X-Forwarded-Port:443"
|
||||||
@@ -62,6 +63,7 @@ upstreams:
|
|||||||
paths:
|
paths:
|
||||||
"/":
|
"/":
|
||||||
rate_limit: 200
|
rate_limit: 200
|
||||||
|
x4xx_limit: 100
|
||||||
to_https: false
|
to_https: false
|
||||||
client_headers:
|
client_headers:
|
||||||
- "X-Proxy-From:Aralez"
|
- "X-Proxy-From:Aralez"
|
||||||
@@ -72,7 +74,7 @@ upstreams:
|
|||||||
- "127.0.0.4:8000"
|
- "127.0.0.4:8000"
|
||||||
- "127.0.0.5:8000"
|
- "127.0.0.5:8000"
|
||||||
"/ping":
|
"/ping":
|
||||||
authorization: # Will be ignored if global authentication is enabled.
|
authorization: # Will be ignored if global authentication is enabled.
|
||||||
type: "basic"
|
type: "basic"
|
||||||
creds: "admin:admin"
|
creds: "admin:admin"
|
||||||
to_https: false
|
to_https: false
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ mod utils;
|
|||||||
mod web;
|
mod web;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
|
// static ALLOC: Jemalloc = Jemalloc;
|
||||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||||
// pub static A: CountingAllocator = CountingAllocator;
|
// pub static A: CountingAllocator = CountingAllocator;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ pub mod healthcheck;
|
|||||||
pub mod httpclient;
|
pub mod httpclient;
|
||||||
pub mod jwt;
|
pub mod jwt;
|
||||||
pub mod kuberconsul;
|
pub mod kuberconsul;
|
||||||
|
pub mod lazylock;
|
||||||
pub mod metrics;
|
pub mod metrics;
|
||||||
pub mod parceyaml;
|
pub mod parceyaml;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
|||||||
@@ -37,9 +37,8 @@ pub async fn start(fp: String, mut toreturn: Sender<Configuration>) {
|
|||||||
match event {
|
match event {
|
||||||
Ok(e) => match e.kind {
|
Ok(e) => match e.kind {
|
||||||
EventKind::Modify(ModifyKind::Data(_)) | EventKind::Create(..) | EventKind::Remove(..) => {
|
EventKind::Modify(ModifyKind::Data(_)) | EventKind::Create(..) | EventKind::Remove(..) => {
|
||||||
if e.paths[0].to_str().unwrap().ends_with("yaml") && start.elapsed() > Duration::from_secs(2) {
|
if start.elapsed() > Duration::from_secs(2) {
|
||||||
start = Instant::now();
|
start = Instant::now();
|
||||||
// info!("Config File changed :=> {:?}", e);
|
|
||||||
let snd = load_configuration(file_path, "filepath").await.0;
|
let snd = load_configuration(file_path, "filepath").await.0;
|
||||||
if let Some(snd) = snd {
|
if let Some(snd) = snd {
|
||||||
toreturn.send(snd).await.unwrap();
|
toreturn.send(snd).await.unwrap();
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::utils::lazylock::REVERSE_STORE;
|
||||||
use crate::utils::structs::{InnerMap, UpstreamsDashMap, UpstreamsIdMap};
|
use crate::utils::structs::{InnerMap, UpstreamsDashMap, UpstreamsIdMap};
|
||||||
use crate::utils::tools::*;
|
use crate::utils::tools::*;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -20,6 +21,7 @@ pub async fn hc2(upslist: Arc<UpstreamsDashMap>, fullist: Arc<UpstreamsDashMap>,
|
|||||||
if !compare_dashmaps(&totest, &upslist) {
|
if !compare_dashmaps(&totest, &upslist) {
|
||||||
clone_dashmap_into(&totest, &upslist);
|
clone_dashmap_into(&totest, &upslist);
|
||||||
clone_idmap_into(&totest, &idlist);
|
clone_idmap_into(&totest, &idlist);
|
||||||
|
REVERSE_STORE.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,15 +55,14 @@ async fn build_upstreams(fullist: &UpstreamsDashMap, method: &str, client: &Clie
|
|||||||
let mut innervec = Vec::new();
|
let mut innervec = Vec::new();
|
||||||
|
|
||||||
for upstream in path_entry.value().0.iter() {
|
for upstream in path_entry.value().0.iter() {
|
||||||
let tls = detect_tls(upstream.address.as_ref(), &upstream.port, client).await;
|
let tls = if upstream.healthcheck.unwrap_or(true) {
|
||||||
let is_h2 = matches!(tls.1, Some(Version::HTTP_2));
|
detect_tls(upstream.address.as_ref(), &upstream.port, client).await
|
||||||
|
|
||||||
let link = if tls.0 {
|
|
||||||
format!("https://{}:{}{}", upstream.address, upstream.port, path)
|
|
||||||
} else {
|
} else {
|
||||||
format!("http://{}:{}{}", upstream.address, upstream.port, path)
|
(false, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let is_h2 = matches!(tls.1, Some(Version::HTTP_2));
|
||||||
|
|
||||||
let mut scheme = InnerMap {
|
let mut scheme = InnerMap {
|
||||||
address: upstream.address.clone(),
|
address: upstream.address.clone(),
|
||||||
port: upstream.port,
|
port: upstream.port,
|
||||||
@@ -76,6 +77,12 @@ async fn build_upstreams(fullist: &UpstreamsDashMap, method: &str, client: &Clie
|
|||||||
};
|
};
|
||||||
|
|
||||||
if scheme.healthcheck.unwrap_or(true) {
|
if scheme.healthcheck.unwrap_or(true) {
|
||||||
|
let link = if tls.0 {
|
||||||
|
format!("https://{}:{}{}", upstream.address, upstream.port, path)
|
||||||
|
} else {
|
||||||
|
format!("http://{}:{}{}", upstream.address, upstream.port, path)
|
||||||
|
};
|
||||||
|
|
||||||
let resp = http_request(&link, method, "", client).await;
|
let resp = http_request(&link, method, "", client).await;
|
||||||
if resp.0 {
|
if resp.0 {
|
||||||
if resp.1 {
|
if resp.1 {
|
||||||
@@ -134,10 +141,7 @@ async fn detect_tls(ip: &str, port: &u16, client: &Client) -> (bool, Option<Vers
|
|||||||
}
|
}
|
||||||
let http_url = format!("http://{}:{}", ip, port);
|
let http_url = format!("http://{}:{}", ip, port);
|
||||||
match client.get(&http_url).send().await {
|
match client.get(&http_url).send().await {
|
||||||
Ok(response) => {
|
Ok(response) => (false, Some(response.version())),
|
||||||
// println!("{} => {:?} (HTTP)", http_url, response.version());
|
|
||||||
(false, Some(response.version()))
|
|
||||||
}
|
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
if ping_grpc(&http_url).await {
|
if ping_grpc(&http_url).await {
|
||||||
(false, Some(Version::HTTP_2))
|
(false, Some(Version::HTTP_2))
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ async fn clone_compare(upstreams: &UpstreamsDashMap, prev_upstreams: &UpstreamsD
|
|||||||
};
|
};
|
||||||
clone_dashmap_into(upstreams, prev_upstreams);
|
clone_dashmap_into(upstreams, prev_upstreams);
|
||||||
clone_dashmap_into(upstreams, &tosend.upstreams);
|
clone_dashmap_into(upstreams, &tosend.upstreams);
|
||||||
print_upstreams(&tosend.upstreams);
|
print_upstreams(&tosend.upstreams, &tosend.extraparams);
|
||||||
return Some(tosend);
|
return Some(tosend);
|
||||||
};
|
};
|
||||||
None
|
None
|
||||||
|
|||||||
11
src/utils/lazylock.rs
Normal file
11
src/utils/lazylock.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
use dashmap::DashMap;
|
||||||
|
use moka::sync::Cache;
|
||||||
|
use pingora_limits::rate::Rate;
|
||||||
|
use std::net::IpAddr;
|
||||||
|
use std::sync::{Arc, LazyLock};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
pub static REVERSE_STORE: LazyLock<DashMap<String, String>> = LazyLock::new(DashMap::new);
|
||||||
|
pub static RATE_LIMITER: LazyLock<Rate> = LazyLock::new(|| Rate::new(Duration::from_secs(1)));
|
||||||
|
pub static REQUESTS_4XX: LazyLock<Cache<IpAddr, u32>> = LazyLock::new(|| Cache::builder().time_to_live(Duration::from_secs(1)).build());
|
||||||
|
pub static LOCALHOST: LazyLock<Arc<str>> = LazyLock::new(|| Arc::from("localhost"));
|
||||||
@@ -14,18 +14,28 @@ pub struct MetricTypes {
|
|||||||
pub version: Version,
|
pub version: Version,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub static OPEN_FILES: LazyLock<IntGauge> = LazyLock::new(|| register_int_gauge!("aralez_open_files", "Number of open file descriptors").unwrap());
|
||||||
|
pub static MEMORY_USAGE: LazyLock<IntGauge> = LazyLock::new(|| register_int_gauge!("aralez_memory_bytes", "Total memory allocated in bytes").unwrap());
|
||||||
pub static ACTIVE_SESSIONS: LazyLock<IntGauge> = LazyLock::new(|| register_int_gauge!("aralez_active_sessions", "Current number of active sessions").unwrap());
|
pub static ACTIVE_SESSIONS: LazyLock<IntGauge> = LazyLock::new(|| register_int_gauge!("aralez_active_sessions", "Current number of active sessions").unwrap());
|
||||||
|
|
||||||
pub static REQUEST_COUNT: LazyLock<IntCounter> = LazyLock::new(|| register_int_counter!("aralez_requests_total", "Total number of requests handled by Aralez").unwrap());
|
pub static REQUEST_COUNT: LazyLock<IntCounter> = LazyLock::new(|| register_int_counter!("aralez_requests_total", "Total number of requests handled by Aralez").unwrap());
|
||||||
|
|
||||||
pub static RESPONSE_CODES: LazyLock<IntCounterVec> =
|
pub static RESPONSE_CODES: LazyLock<IntCounterVec> =
|
||||||
LazyLock::new(|| register_int_counter_vec!("aralez_responses_total", "Responses grouped by status code", &["status"]).unwrap());
|
LazyLock::new(|| register_int_counter_vec!("aralez_responses_total", "Responses grouped by status code", &["status"]).unwrap());
|
||||||
|
|
||||||
|
// pub static RESPONSE_LATENCY: LazyLock<Histogram> = LazyLock::new(|| {
|
||||||
|
// register_histogram!(
|
||||||
|
// "aralez_response_latency_seconds",
|
||||||
|
// "Response latency in seconds",
|
||||||
|
// vec![0.01, 0.05, 0.1, 0.25, 0.5, 1.0, 2.0, 5.0]
|
||||||
|
// )
|
||||||
|
// .unwrap()
|
||||||
|
// });
|
||||||
|
|
||||||
pub static RESPONSE_LATENCY: LazyLock<Histogram> = LazyLock::new(|| {
|
pub static RESPONSE_LATENCY: LazyLock<Histogram> = LazyLock::new(|| {
|
||||||
register_histogram!(
|
register_histogram!(
|
||||||
"aralez_response_latency_seconds",
|
"aralez_response_latency_seconds",
|
||||||
"Response latency in seconds",
|
"Response latency in seconds",
|
||||||
vec![0.01, 0.05, 0.1, 0.25, 0.5, 1.0, 2.0, 5.0]
|
vec![0.001, 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 1.0, 2.0, 5.0]
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
});
|
});
|
||||||
@@ -54,3 +64,20 @@ pub fn calc_metrics(metric_types: &MetricTypes) {
|
|||||||
REQUESTS_BY_UPSTREAM.with_label_values(&[metric_types.upstream.as_ref()]).inc();
|
REQUESTS_BY_UPSTREAM.with_label_values(&[metric_types.upstream.as_ref()]).inc();
|
||||||
RESPONSE_LATENCY.observe(metric_types.latency.as_secs_f64());
|
RESPONSE_LATENCY.observe(metric_types.latency.as_secs_f64());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_memory_usage() -> usize {
|
||||||
|
std::fs::read_to_string("/proc/self/status")
|
||||||
|
.ok()
|
||||||
|
.and_then(|s| {
|
||||||
|
s.lines()
|
||||||
|
.find(|l| l.starts_with("VmRSS:"))
|
||||||
|
.and_then(|l| l.split_whitespace().nth(1))
|
||||||
|
.and_then(|v| v.parse::<usize>().ok())
|
||||||
|
})
|
||||||
|
.unwrap_or(0)
|
||||||
|
* 1024
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_open_files() -> usize {
|
||||||
|
std::fs::read_dir("/proc/self/fd").map(|dir| dir.count()).unwrap_or(0)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::utils::healthcheck;
|
use crate::utils::healthcheck;
|
||||||
|
use crate::utils::lazylock::REVERSE_STORE;
|
||||||
use crate::utils::state::{is_first_run, mark_not_first_run};
|
use crate::utils::state::{is_first_run, mark_not_first_run};
|
||||||
use crate::utils::structs::*;
|
use crate::utils::structs::*;
|
||||||
use crate::utils::tools::{clone_dashmap, clone_dashmap_into, print_upstreams};
|
use crate::utils::tools::{clone_dashmap, clone_dashmap_into, print_upstreams};
|
||||||
@@ -21,57 +22,82 @@ pub static DOMAINS: LazyLock<DashMap<String, bool>> = LazyLock::new(DashMap::new
|
|||||||
pub async fn load_configuration(d: &str, kind: &str) -> (Option<Configuration>, String) {
|
pub async fn load_configuration(d: &str, kind: &str) -> (Option<Configuration>, String) {
|
||||||
let mut conf_files = Vec::new();
|
let mut conf_files = Vec::new();
|
||||||
let yaml_data = match kind {
|
let yaml_data = match kind {
|
||||||
"filepath" => match fs::read_to_string(d) {
|
"filepath" => {
|
||||||
Ok(data) => {
|
let mut data = String::new();
|
||||||
let mut confdir = Path::new(d).parent().unwrap().to_path_buf();
|
let mut last_error = None;
|
||||||
let mut autocfg = Path::new(d).parent().unwrap().to_path_buf();
|
for _ in 0..5 {
|
||||||
|
match fs::read_to_string(d) {
|
||||||
autocfg.push("autoconfigs");
|
Ok(content) => {
|
||||||
if fs::metadata(autocfg.clone()).is_err() {
|
if !content.trim().is_empty() {
|
||||||
fs::create_dir_all(autocfg.clone()).ok();
|
data = content;
|
||||||
}
|
break;
|
||||||
autocfg.push("domains.json");
|
|
||||||
if autocfg.exists() {
|
|
||||||
let json: Option<Vec<String>> = fs::read_to_string(autocfg).ok().and_then(|s| serde_json::from_str(&s).ok());
|
|
||||||
if let Some(domains) = json {
|
|
||||||
for domain in domains {
|
|
||||||
DOMAINS.insert(domain, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Err(e) => {
|
||||||
|
error!("Config read failed, retrying...");
|
||||||
confdir.push("conf.d");
|
last_error = Some(e);
|
||||||
|
|
||||||
if let Ok(entries) = fs::read_dir(&confdir) {
|
|
||||||
let mut paths: Vec<_> = entries
|
|
||||||
.flatten()
|
|
||||||
.map(|e| e.path())
|
|
||||||
.filter(|p| p.extension().and_then(|e| e.to_str()) == Some("yaml"))
|
|
||||||
.collect();
|
|
||||||
paths.sort();
|
|
||||||
|
|
||||||
for path in paths {
|
|
||||||
let content = fs::read_to_string(&path);
|
|
||||||
match content {
|
|
||||||
Ok(content) => {
|
|
||||||
conf_files.push(content);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("Reading: {}: {:?}", path.display(), e)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
||||||
info!("Reading upstreams from {}", d);
|
|
||||||
data
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
if data.is_empty() {
|
||||||
error!("Reading: {}: {:?}", d, e);
|
let err_msg = match last_error {
|
||||||
|
Some(e) => {
|
||||||
|
error!("Reading: {}: {:?}", d, e);
|
||||||
|
e.to_string()
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
error!("Reading: {}: File is empty after retries", d);
|
||||||
|
"File is empty".to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
warn!("Running with empty upstreams list, update it via API");
|
warn!("Running with empty upstreams list, update it via API");
|
||||||
return (None, e.to_string());
|
return (None, err_msg);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
let mut confdir = Path::new(d).parent().unwrap().to_path_buf();
|
||||||
|
let mut autocfg = Path::new(d).parent().unwrap().to_path_buf();
|
||||||
|
|
||||||
|
autocfg.push("autoconfigs");
|
||||||
|
if fs::metadata(autocfg.clone()).is_err() {
|
||||||
|
fs::create_dir_all(autocfg.clone()).ok();
|
||||||
|
}
|
||||||
|
autocfg.push("domains.json");
|
||||||
|
if autocfg.exists() {
|
||||||
|
let json: Option<Vec<String>> = fs::read_to_string(autocfg).ok().and_then(|s| serde_json::from_str(&s).ok());
|
||||||
|
if let Some(domains) = json {
|
||||||
|
for domain in domains {
|
||||||
|
DOMAINS.insert(domain, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
confdir.push("conf.d");
|
||||||
|
|
||||||
|
if let Ok(entries) = fs::read_dir(&confdir) {
|
||||||
|
let mut paths: Vec<_> = entries
|
||||||
|
.flatten()
|
||||||
|
.map(|e| e.path())
|
||||||
|
.filter(|p| p.extension().and_then(|e| e.to_str()) == Some("yaml"))
|
||||||
|
.collect();
|
||||||
|
paths.sort();
|
||||||
|
|
||||||
|
for path in paths {
|
||||||
|
let content = fs::read_to_string(&path);
|
||||||
|
match content {
|
||||||
|
Ok(content) => {
|
||||||
|
conf_files.push(content);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("Reading: {}: {:?}", path.display(), e)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
info!("Reading upstreams from {}", d);
|
||||||
|
data
|
||||||
|
}
|
||||||
"content" => {
|
"content" => {
|
||||||
info!("Reading upstreams from API post body");
|
info!("Reading upstreams from API post body");
|
||||||
d.to_string()
|
d.to_string()
|
||||||
@@ -85,7 +111,6 @@ pub async fn load_configuration(d: &str, kind: &str) -> (Option<Configuration>,
|
|||||||
let mut parsed: Config = match serde_yml::from_str(&yaml_data) {
|
let mut parsed: Config = match serde_yml::from_str(&yaml_data) {
|
||||||
Ok(cfg) => cfg,
|
Ok(cfg) => cfg,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("================================================");
|
|
||||||
error!("Failed to parse upstreams file: {}", e);
|
error!("Failed to parse upstreams file: {}", e);
|
||||||
return (None, e.to_string());
|
return (None, e.to_string());
|
||||||
}
|
}
|
||||||
@@ -233,7 +258,8 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) {
|
|||||||
clone_dashmap_into(&r, &config.upstreams);
|
clone_dashmap_into(&r, &config.upstreams);
|
||||||
}
|
}
|
||||||
info!("Upstream Config:");
|
info!("Upstream Config:");
|
||||||
print_upstreams(&config.upstreams);
|
REVERSE_STORE.clear();
|
||||||
|
print_upstreams(&config.upstreams, &config.extraparams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn parce_main_config(path: &str) -> AppConfig {
|
pub fn parce_main_config(path: &str) -> AppConfig {
|
||||||
@@ -320,7 +346,8 @@ fn log_builder(conf: &AppConfig, location: &Option<String>) {
|
|||||||
LevelFilter::Info
|
LevelFilter::Info
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let pattern = "{d(%Y-%m-%d %H:%M:%S)} {l} {t} - {m}{n}";
|
// let pattern = "{d(%Y-%m-%d %H:%M:%S)} {l} {t} - {m}{n}";
|
||||||
|
let pattern = "{d(%Y-%m-%d %H:%M:%S)} {l} {t} - {m}\n";
|
||||||
if let Some(location) = location {
|
if let Some(location) = location {
|
||||||
let file = FileAppender::builder().encoder(Box::new(PatternEncoder::new(pattern))).build(location).unwrap();
|
let file = FileAppender::builder().encoder(Box::new(PatternEncoder::new(pattern))).build(location).unwrap();
|
||||||
let config = Log4rsConfig::builder()
|
let config = Log4rsConfig::builder()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::tls::load;
|
use crate::tls::load;
|
||||||
use crate::tls::load::CertificateConfig;
|
use crate::tls::load::CertificateConfig;
|
||||||
use crate::utils::structs::{InnerMap, InnerMapForJson, UpstreamSnapshotForJson, UpstreamsDashMap, UpstreamsIdMap};
|
use crate::utils::structs::{Extraparams, InnerMap, InnerMapForJson, UpstreamSnapshotForJson, UpstreamsDashMap, UpstreamsIdMap};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use notify::{event::ModifyKind, Config, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
|
use notify::{event::ModifyKind, Config, EventKind, RecommendedWatcher, RecursiveMode, Watcher};
|
||||||
@@ -20,7 +20,7 @@ use std::sync::Arc;
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use std::{fs, process, thread, time};
|
use std::{fs, process, thread, time};
|
||||||
|
|
||||||
pub fn print_upstreams(upstreams: &UpstreamsDashMap) {
|
pub fn print_upstreams(upstreams: &UpstreamsDashMap, extraparams: &Extraparams) {
|
||||||
let mut out = String::new();
|
let mut out = String::new();
|
||||||
for host_entry in upstreams.iter() {
|
for host_entry in upstreams.iter() {
|
||||||
writeln!(out, "Hostname: {}", host_entry.key()).unwrap();
|
writeln!(out, "Hostname: {}", host_entry.key()).unwrap();
|
||||||
@@ -35,8 +35,8 @@ pub fn print_upstreams(upstreams: &UpstreamsDashMap) {
|
|||||||
f.is_ssl,
|
f.is_ssl,
|
||||||
f.is_http2,
|
f.is_http2,
|
||||||
f.to_https,
|
f.to_https,
|
||||||
f.rate_limit.unwrap_or(0),
|
f.rate_limit.unwrap_or(extraparams.rate_limit.unwrap_or(0)),
|
||||||
f.x4xx_limit.unwrap_or(0)
|
f.x4xx_limit.unwrap_or(extraparams.x4xx_limit.unwrap_or(0))
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
@@ -159,8 +159,8 @@ pub fn clone_idmap_into(original: &UpstreamsDashMap, cloned: &UpstreamsIdMap) {
|
|||||||
x.port,
|
x.port,
|
||||||
x.is_http2,
|
x.is_http2,
|
||||||
x.to_https,
|
x.to_https,
|
||||||
x.rate_limit.unwrap_or_default(),
|
|
||||||
x.x4xx_limit.unwrap_or_default(),
|
x.x4xx_limit.unwrap_or_default(),
|
||||||
|
x.rate_limit.unwrap_or_default(),
|
||||||
x.healthcheck.unwrap_or_default(),
|
x.healthcheck.unwrap_or_default(),
|
||||||
x.authorization
|
x.authorization
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod acme;
|
||||||
pub mod bgservice;
|
pub mod bgservice;
|
||||||
pub mod gethosts;
|
pub mod gethosts;
|
||||||
pub mod proxyhttp;
|
pub mod proxyhttp;
|
||||||
|
|||||||
64
src/web/acme.rs
Normal file
64
src/web/acme.rs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
use crate::tls::acme::order::CHALLENGES;
|
||||||
|
use crate::tls::acme::{account, order};
|
||||||
|
use axum::body::Body;
|
||||||
|
use axum::extract::State;
|
||||||
|
use axum::http::{Response, StatusCode};
|
||||||
|
use axum::response::IntoResponse;
|
||||||
|
|
||||||
|
#[allow(clippy::needless_return)]
|
||||||
|
pub async fn acme_create(State(state): State<crate::web::webserver::AppState>) -> impl IntoResponse {
|
||||||
|
match account::load_or_create(state.cert_creds.as_str()).await {
|
||||||
|
Ok(txt) => {
|
||||||
|
return Response::builder()
|
||||||
|
.status(StatusCode::OK)
|
||||||
|
.header("Content-Type", "text/plain")
|
||||||
|
.body(Body::from(txt))
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Response::builder()
|
||||||
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
|
.body(Body::from(format!("Failed to create account: {}", e)))
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[allow(clippy::needless_return)]
|
||||||
|
pub async fn acme_order(State(state): State<crate::web::webserver::AppState>, axum::extract::Path(domain): axum::extract::Path<String>) -> impl IntoResponse {
|
||||||
|
let domain_clean = domain.trim_matches('/');
|
||||||
|
match order::order(domain_clean, state.cert_creds.as_str(), state.certs_dir).await {
|
||||||
|
Ok(txt) => {
|
||||||
|
return Response::builder()
|
||||||
|
.status(StatusCode::OK)
|
||||||
|
.header("Content-Type", "text/plain")
|
||||||
|
.body(Body::from(txt))
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Response::builder()
|
||||||
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
|
.body(Body::from(format!("Failed to order a certificate: {}", e)))
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub async fn http01_challenge(axum::extract::Path(token): axum::extract::Path<String>) -> impl IntoResponse {
|
||||||
|
if let Ok(challenges) = CHALLENGES.read() {
|
||||||
|
// for k in challenges.iter() {
|
||||||
|
// println!(" ==> {} : {}", k.0, k.1);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if let Some(key_authorization) = challenges.get(&token) {
|
||||||
|
return Response::builder()
|
||||||
|
.status(StatusCode::OK)
|
||||||
|
.header("Content-Type", "text/plain")
|
||||||
|
.body(Body::from(key_authorization.clone()))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Response::builder()
|
||||||
|
.status(StatusCode::NOT_FOUND)
|
||||||
|
.header("Content-Type", "text/plain")
|
||||||
|
.body(Body::from("Not found"))
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
@@ -60,19 +60,13 @@ impl BackgroundService for LB {
|
|||||||
masterkey: self.config.master_key.clone(),
|
masterkey: self.config.master_key.clone(),
|
||||||
config_api_enabled: self.config.config_api_enabled,
|
config_api_enabled: self.config.config_api_enabled,
|
||||||
upstreams_file: self.config.upstreams_conf.clone(),
|
upstreams_file: self.config.upstreams_conf.clone(),
|
||||||
// certs_dir: self.config.proxy_certificates.clone().unwrap_or_else(|| "/tmp".to_string()),
|
|
||||||
config_dir: confdir.clone(),
|
config_dir: confdir.clone(),
|
||||||
certs_dir: certdir.clone(),
|
certs_dir: certdir.clone(),
|
||||||
// tls_address: self.config.config_tls_address.clone(),
|
|
||||||
// tls_certificate: self.config.config_tls_certificate.clone(),
|
|
||||||
// tls_key_file: self.config.config_tls_key_file.clone(),
|
|
||||||
file_server_address: self.config.file_server_address.clone(),
|
file_server_address: self.config.file_server_address.clone(),
|
||||||
file_server_folder: self.config.file_server_folder.clone(),
|
file_server_folder: self.config.file_server_folder.clone(),
|
||||||
current_upstreams: self.ump_upst.clone(),
|
current_upstreams: self.ump_upst.clone(),
|
||||||
full_upstreams: self.ump_full.clone(),
|
full_upstreams: self.ump_full.clone(),
|
||||||
};
|
};
|
||||||
// let crtdir = api_load.certs_dir.clone();
|
|
||||||
// let tx_api = tx.clone();
|
|
||||||
drop(tokio::spawn(async move { api_load.start(tx_api).await }));
|
drop(tokio::spawn(async move { api_load.start(tx_api).await }));
|
||||||
|
|
||||||
let uu = self.ump_upst.clone();
|
let uu = self.ump_upst.clone();
|
||||||
@@ -93,6 +87,7 @@ impl BackgroundService for LB {
|
|||||||
if let Some(ss) = val {
|
if let Some(ss) = val {
|
||||||
clone_dashmap_into(&ss.upstreams, &self.ump_full);
|
clone_dashmap_into(&ss.upstreams, &self.ump_full);
|
||||||
clone_dashmap_into(&ss.upstreams, &self.ump_upst);
|
clone_dashmap_into(&ss.upstreams, &self.ump_upst);
|
||||||
|
clone_idmap_into(&ss.upstreams, &self.ump_byid);
|
||||||
let current = self.extraparams.load_full();
|
let current = self.extraparams.load_full();
|
||||||
let mut new = (*current).clone();
|
let mut new = (*current).clone();
|
||||||
new.to_https = ss.extraparams.to_https;
|
new.to_https = ss.extraparams.to_https;
|
||||||
|
|||||||
@@ -1,33 +1,29 @@
|
|||||||
use crate::utils::auth::authenticate;
|
use crate::utils::auth::authenticate;
|
||||||
|
use crate::utils::lazylock::{LOCALHOST, RATE_LIMITER, REQUESTS_4XX, REVERSE_STORE};
|
||||||
use crate::utils::metrics::*;
|
use crate::utils::metrics::*;
|
||||||
use crate::utils::structs::{AppConfig, Extraparams, Headers, InnerMap, UpstreamsDashMap, UpstreamsIdMap};
|
use crate::utils::structs::{AppConfig, Extraparams, Headers, InnerMap, UpstreamsDashMap, UpstreamsIdMap};
|
||||||
use crate::web::gethosts::{GetHost, GetHostsReturHeaders};
|
use crate::web::gethosts::{GetHost, GetHostsReturHeaders};
|
||||||
use arc_swap::ArcSwap;
|
use arc_swap::ArcSwap;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use axum::body::Bytes;
|
use axum::body::Bytes;
|
||||||
use dashmap::DashMap;
|
|
||||||
use log::{debug, error, warn};
|
use log::{debug, error, warn};
|
||||||
use moka::sync::Cache;
|
|
||||||
use pingora::http::{RequestHeader, ResponseHeader, StatusCode};
|
use pingora::http::{RequestHeader, ResponseHeader, StatusCode};
|
||||||
use pingora::prelude::*;
|
use pingora::prelude::*;
|
||||||
use pingora::ErrorSource::Upstream;
|
use pingora::ErrorSource::Upstream;
|
||||||
use pingora_core::listeners::ALPN;
|
use pingora_core::listeners::ALPN;
|
||||||
use pingora_core::prelude::HttpPeer;
|
use pingora_core::prelude::HttpPeer;
|
||||||
use pingora_limits::rate::Rate;
|
|
||||||
use pingora_proxy::{ProxyHttp, Session};
|
use pingora_proxy::{ProxyHttp, Session};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::net::IpAddr;
|
use std::sync::Arc;
|
||||||
use std::sync::{Arc, LazyLock};
|
|
||||||
use std::time::Duration;
|
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
|
|
||||||
static REVERSE_STORE: LazyLock<DashMap<String, String>> = LazyLock::new(DashMap::new);
|
|
||||||
thread_local! {static IP_BUFFER: RefCell<String> = RefCell::new(String::with_capacity(50));}
|
thread_local! {static IP_BUFFER: RefCell<String> = RefCell::new(String::with_capacity(50));}
|
||||||
pub static RATE_LIMITER: LazyLock<Rate> = LazyLock::new(|| Rate::new(Duration::from_secs(1)));
|
// static REVERSE_STORE: LazyLock<DashMap<String, String>> = LazyLock::new(DashMap::new);
|
||||||
pub static REQUESTS_4XX: LazyLock<Cache<IpAddr, u32>> = LazyLock::new(|| Cache::builder().time_to_live(Duration::from_secs(1)).build());
|
// pub static RATE_LIMITER: LazyLock<Rate> = LazyLock::new(|| Rate::new(Duration::from_secs(1)));
|
||||||
pub static LOCALHOST: LazyLock<Arc<str>> = LazyLock::new(|| Arc::from("localhost"));
|
// pub static REQUESTS_4XX: LazyLock<Cache<IpAddr, u32>> = LazyLock::new(|| Cache::builder().time_to_live(Duration::from_secs(1)).build());
|
||||||
|
// pub static LOCALHOST: LazyLock<Arc<str>> = LazyLock::new(|| Arc::from("localhost"));
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct LB {
|
pub struct LB {
|
||||||
@@ -104,7 +100,7 @@ impl ProxyHttp for LB {
|
|||||||
session.set_keepalive(None);
|
session.set_keepalive(None);
|
||||||
session.write_response_header(Box::new(header), true).await?;
|
session.write_response_header(Box::new(header), true).await?;
|
||||||
if let (Some(oi), Some(oa)) = (&_ctx.hostname, rate_key) {
|
if let (Some(oi), Some(oa)) = (&_ctx.hostname, rate_key) {
|
||||||
warn!("Limit 4XX: {}-rps exceed on {} from {}", rate, oi, oa);
|
warn!("Limit 4XX: {}-rps exceed on {} from {} path {}", rate, oi, oa, session.req_header().uri.path());
|
||||||
}
|
}
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
@@ -185,12 +181,13 @@ impl ProxyHttp for LB {
|
|||||||
let mut s = String::with_capacity(64);
|
let mut s = String::with_capacity(64);
|
||||||
write!(
|
write!(
|
||||||
&mut s,
|
&mut s,
|
||||||
"{}:{}:{}:{}:{}:{}:{}:{:?}",
|
"{}:{}:{}:{}:{}:{}:{}:{}:{:?}",
|
||||||
hostname,
|
hostname,
|
||||||
innermap.address,
|
innermap.address,
|
||||||
innermap.port,
|
innermap.port,
|
||||||
innermap.is_http2,
|
innermap.is_http2,
|
||||||
innermap.to_https,
|
innermap.to_https,
|
||||||
|
innermap.x4xx_limit.unwrap_or_default(),
|
||||||
innermap.rate_limit.unwrap_or_default(),
|
innermap.rate_limit.unwrap_or_default(),
|
||||||
innermap.healthcheck.unwrap_or_default(),
|
innermap.healthcheck.unwrap_or_default(),
|
||||||
innermap.authorization
|
innermap.authorization
|
||||||
@@ -229,11 +226,11 @@ impl ProxyHttp for LB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn upstream_request_filter(&self, session: &mut Session, upstream_request: &mut RequestHeader, ctx: &mut Self::CTX) -> Result<()> {
|
async fn upstream_request_filter(&self, session: &mut Session, upstream_request: &mut RequestHeader, ctx: &mut Self::CTX) -> Result<()> {
|
||||||
if let Some(client_ip) = session.client_addr() {
|
if let Some(ip) = session.client_addr().and_then(|a| a.as_inet()).map(|i| i.ip()) {
|
||||||
IP_BUFFER.with(|buffer| {
|
IP_BUFFER.with(|buffer| {
|
||||||
let mut buf = buffer.borrow_mut();
|
let mut buf = buffer.borrow_mut();
|
||||||
buf.clear();
|
buf.clear();
|
||||||
write!(buf, "{}", client_ip).unwrap_or(());
|
write!(buf, "{}", ip).unwrap_or(());
|
||||||
upstream_request.append_header("X-Forwarded-For", buf.as_str()).unwrap_or(false);
|
upstream_request.append_header("X-Forwarded-For", buf.as_str()).unwrap_or(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -278,7 +275,6 @@ impl ProxyHttp for LB {
|
|||||||
buf.push_str(&val.to_string());
|
buf.push_str(&val.to_string());
|
||||||
buf.push_str("; HttpOnly; SameSite=Lax");
|
buf.push_str("; HttpOnly; SameSite=Lax");
|
||||||
// buf.push_str("; Path=/; Max-Age=86400; HttpOnly; SameSite=Lax");
|
// buf.push_str("; Path=/; Max-Age=86400; HttpOnly; SameSite=Lax");
|
||||||
// println!("{}", buf);
|
|
||||||
let _ = _upstream_response.insert_header("set-cookie", buf.as_str());
|
let _ = _upstream_response.insert_header("set-cookie", buf.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,23 @@ use crate::utils::structs::Extraparams;
|
|||||||
use crate::utils::tools::*;
|
use crate::utils::tools::*;
|
||||||
use crate::web::proxyhttp::LB;
|
use crate::web::proxyhttp::LB;
|
||||||
use arc_swap::ArcSwap;
|
use arc_swap::ArcSwap;
|
||||||
use ctrlc;
|
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use log::info;
|
use log::info;
|
||||||
use pingora::tls::ssl::{SslAlert, SslRef};
|
use pingora::tls::ssl::{SslAlert, SslRef};
|
||||||
use pingora_core::listeners::tls::TlsSettings;
|
use pingora_core::listeners::tls::TlsSettings;
|
||||||
use pingora_core::prelude::{background_service, Opt};
|
use pingora_core::prelude::{background_service, Opt};
|
||||||
use pingora_core::server::Server;
|
use pingora_core::server::Server;
|
||||||
|
use privdrop::reexports::libc::SIGQUIT;
|
||||||
|
use sd_notify::NotifyState;
|
||||||
|
use signal_hook::{
|
||||||
|
consts::{SIGINT, SIGTERM},
|
||||||
|
iterator::Signals,
|
||||||
|
};
|
||||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{fs, thread};
|
use std::time::Duration;
|
||||||
|
use std::{fs, process, thread};
|
||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
// default_provider().install_default().expect("Failed to install rustls crypto provider");
|
// default_provider().install_default().expect("Failed to install rustls crypto provider");
|
||||||
let parameters = Opt::parse_args();
|
let parameters = Opt::parse_args();
|
||||||
@@ -104,15 +111,25 @@ pub fn run() {
|
|||||||
proxy.add_tcp(bind_address_http.as_str());
|
proxy.add_tcp(bind_address_http.as_str());
|
||||||
server.add_service(proxy);
|
server.add_service(proxy);
|
||||||
server.add_service(bg_srvc);
|
server.add_service(bg_srvc);
|
||||||
|
|
||||||
thread::spawn(move || server.run_forever());
|
thread::spawn(move || server.run_forever());
|
||||||
|
|
||||||
if let (Some(user), Some(group)) = (cfg.rungroup.clone(), cfg.runuser.clone()) {
|
if let (Some(user), Some(group)) = (cfg.rungroup.clone(), cfg.runuser.clone()) {
|
||||||
drop_priv(user, group, cfg.proxy_address_http.clone(), cfg.proxy_address_tls.clone());
|
drop_priv(user, group, cfg.proxy_address_http.clone(), cfg.proxy_address_tls.clone());
|
||||||
}
|
}
|
||||||
|
let _ = sd_notify::notify(&[NotifyState::Ready]);
|
||||||
|
let _ = fs::write("/tmp/aralez.pid", process::id().to_string());
|
||||||
|
|
||||||
let (tx, rx) = channel();
|
let mut signals = Signals::new(&[SIGINT, SIGTERM, SIGQUIT]).unwrap();
|
||||||
ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel.")).expect("Error setting Ctrl-C handler");
|
for sig in signals.forever() {
|
||||||
rx.recv().expect("Could not receive from channel.");
|
match sig {
|
||||||
info!("Signal received ! Exiting...");
|
SIGINT => info!("SIGINT received! Exiting..."),
|
||||||
|
SIGTERM => info!("SIGTERM received! Exiting..."),
|
||||||
|
SIGQUIT => {
|
||||||
|
thread::sleep(Duration::from_secs(300));
|
||||||
|
info!("SIGQUIT received! Exiting...")
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
// use std::net::SocketAddr;
|
|
||||||
use crate::tls::acme::order::CHALLENGES;
|
|
||||||
// use axum_server::tls_openssl::OpenSSLConfig;
|
|
||||||
use crate::tls::acme::{account, order};
|
|
||||||
use crate::utils::discovery::APIUpstreamProvider;
|
use crate::utils::discovery::APIUpstreamProvider;
|
||||||
use crate::utils::jwt::Claims;
|
use crate::utils::jwt::Claims;
|
||||||
|
use crate::utils::metrics::{get_memory_usage, get_open_files, MEMORY_USAGE, OPEN_FILES};
|
||||||
use crate::utils::structs::{Config, Configuration, UpstreamsDashMap};
|
use crate::utils::structs::{Config, Configuration, UpstreamsDashMap};
|
||||||
use crate::utils::tools::{upstreams_liveness_json, upstreams_to_json};
|
use crate::utils::tools::{upstreams_liveness_json, upstreams_to_json};
|
||||||
|
use crate::web::acme::{acme_create, acme_order, http01_challenge};
|
||||||
use axum::body::Body;
|
use axum::body::Body;
|
||||||
use axum::extract::{Query, State};
|
use axum::extract::{Query, State};
|
||||||
use axum::http::{Response, StatusCode};
|
use axum::http::{Response, StatusCode};
|
||||||
@@ -18,10 +16,12 @@ use jsonwebtoken::{encode, EncodingKey, Header};
|
|||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use prometheus::{gather, Encoder, TextEncoder};
|
use prometheus::{gather, Encoder, TextEncoder};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use signal_hook::{consts::SIGQUIT, iterator::Signals};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
use tokio::sync::mpsc;
|
||||||
use tower_http::services::ServeDir;
|
use tower_http::services::ServeDir;
|
||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
@@ -30,10 +30,10 @@ struct OutToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct AppState {
|
pub(crate) struct AppState {
|
||||||
master_key: Option<String>,
|
master_key: Option<String>,
|
||||||
cert_creds: String,
|
pub(crate) cert_creds: String,
|
||||||
certs_dir: String,
|
pub(crate) certs_dir: String,
|
||||||
upstreams_file: String,
|
upstreams_file: String,
|
||||||
config_sender: Sender<Configuration>,
|
config_sender: Sender<Configuration>,
|
||||||
config_api_enabled: bool,
|
config_api_enabled: bool,
|
||||||
@@ -56,11 +56,6 @@ pub async fn run_server(config: &APIUpstreamProvider, mut to_return: Sender<Conf
|
|||||||
};
|
};
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
// .route("/{*wildcard}", get(senderror))
|
// .route("/{*wildcard}", get(senderror))
|
||||||
// .route("/{*wildcard}", post(senderror))
|
|
||||||
// .route("/{*wildcard}", put(senderror))
|
|
||||||
// .route("/{*wildcard}", head(senderror))
|
|
||||||
// .route("/{*wildcard}", delete(senderror))
|
|
||||||
// .nest_service("/static", static_files)
|
|
||||||
.route("/jwt", post(jwt_gen))
|
.route("/jwt", post(jwt_gen))
|
||||||
.route("/acme_create", any(acme_create))
|
.route("/acme_create", any(acme_create))
|
||||||
.route("/acme_order/{*domain}", any(acme_order))
|
.route("/acme_order/{*domain}", any(acme_order))
|
||||||
@@ -70,28 +65,35 @@ pub async fn run_server(config: &APIUpstreamProvider, mut to_return: Sender<Conf
|
|||||||
.route("/status", get(status))
|
.route("/status", get(status))
|
||||||
.with_state(app_state);
|
.with_state(app_state);
|
||||||
|
|
||||||
// if let Some(value) = &config.tls_address {
|
let mut static_handle: Option<tokio::task::JoinHandle<()>> = None;
|
||||||
// let cf = OpenSSLConfig::from_pem_file(config.tls_certificate.clone().unwrap(), config.tls_key_file.clone().unwrap()).unwrap();
|
|
||||||
// let addr: SocketAddr = value.parse().expect("Unable to parse socket address");
|
|
||||||
// let tls_app = app.clone();
|
|
||||||
// tokio::spawn(async move {
|
|
||||||
// if let Err(e) = axum_server::bind_openssl(addr, cf).serve(tls_app.into_make_service()).await {
|
|
||||||
// eprintln!("TLS server failed: {}", e);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// info!("Starting the TLS API server on: {}", value);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if let (Some(address), Some(folder)) = (&config.file_server_address, &config.file_server_folder) {
|
if let (Some(address), Some(folder)) = (&config.file_server_address, &config.file_server_folder) {
|
||||||
|
port_is_available("File Server", &address).await;
|
||||||
let static_files = ServeDir::new(folder);
|
let static_files = ServeDir::new(folder);
|
||||||
let static_serve: Router = Router::new().fallback_service(static_files);
|
let static_serve: Router = Router::new().fallback_service(static_files);
|
||||||
let static_listen = TcpListener::bind(address).await.unwrap();
|
let static_listen = TcpListener::bind(address).await.unwrap();
|
||||||
drop(tokio::spawn(async move { axum::serve(static_listen, static_serve).await.unwrap() }));
|
// drop(tokio::spawn(async move { axum::serve(static_listen, static_serve).await.unwrap() }));
|
||||||
|
static_handle = Some(tokio::spawn(async move { axum::serve(static_listen, static_serve).await.unwrap() }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
port_is_available("Config API", &config.address).await;
|
||||||
let listener = TcpListener::bind(config.address.clone()).await.unwrap();
|
let listener = TcpListener::bind(config.address.clone()).await.unwrap();
|
||||||
info!("Starting the API server on: {}", config.address);
|
info!("Starting the API server on: {}", config.address);
|
||||||
axum::serve(listener, app).await.unwrap();
|
let api_server = tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });
|
||||||
|
|
||||||
|
let (tx, mut rx) = mpsc::channel(1);
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
let mut signals = Signals::new(&[SIGQUIT]).unwrap();
|
||||||
|
for sig in signals.forever() {
|
||||||
|
tx.blocking_send(sig).unwrap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rx.recv().await;
|
||||||
|
api_server.abort();
|
||||||
|
if let Some(handle) = static_handle {
|
||||||
|
handle.abort();
|
||||||
|
}
|
||||||
|
info!("Exiting...");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn conf(State(st): State<AppState>, Query(params): Query<HashMap<String, String>>, content: String) -> impl IntoResponse {
|
async fn conf(State(st): State<AppState>, Query(params): Query<HashMap<String, String>>, content: String) -> impl IntoResponse {
|
||||||
@@ -171,6 +173,9 @@ async fn jwt_gen(State(state): State<AppState>, Json(payload): Json<Claims>) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn metrics() -> impl IntoResponse {
|
async fn metrics() -> impl IntoResponse {
|
||||||
|
MEMORY_USAGE.set(get_memory_usage() as i64);
|
||||||
|
OPEN_FILES.set(get_open_files() as i64);
|
||||||
|
|
||||||
let metric_families = gather();
|
let metric_families = gather();
|
||||||
let encoder = TextEncoder::new();
|
let encoder = TextEncoder::new();
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
@@ -222,72 +227,27 @@ async fn status(State(st): State<AppState>, Query(params): Query<HashMap<String,
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::needless_return)]
|
pub async fn port_is_available(name: &str, address: &str) {
|
||||||
async fn acme_create(State(state): State<AppState>) -> impl IntoResponse {
|
let addr_port = address.split(":").collect::<Vec<&str>>();
|
||||||
match account::load_or_create(state.cert_creds.as_str()).await {
|
let t = Duration::from_secs(2);
|
||||||
Ok(txt) => {
|
|
||||||
return Response::builder()
|
|
||||||
.status(StatusCode::OK)
|
|
||||||
.header("Content-Type", "text/plain")
|
|
||||||
.body(Body::from(txt))
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
return Response::builder()
|
|
||||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
|
||||||
.body(Body::from(format!("Failed to create account: {}", e)))
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#[allow(clippy::needless_return)]
|
|
||||||
async fn acme_order(State(state): State<AppState>, axum::extract::Path(domain): axum::extract::Path<String>) -> impl IntoResponse {
|
|
||||||
let domain_clean = domain.trim_matches('/');
|
|
||||||
match order::order(domain_clean, state.cert_creds.as_str(), state.certs_dir).await {
|
|
||||||
Ok(txt) => {
|
|
||||||
return Response::builder()
|
|
||||||
.status(StatusCode::OK)
|
|
||||||
.header("Content-Type", "text/plain")
|
|
||||||
.body(Body::from(txt))
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
return Response::builder()
|
|
||||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
|
||||||
.body(Body::from(format!("Failed to order a certificate: {}", e)))
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn http01_challenge(axum::extract::Path(token): axum::extract::Path<String>) -> impl IntoResponse {
|
let mut a = addr_port[0];
|
||||||
if let Ok(challenges) = CHALLENGES.read() {
|
if address == "0.0.0.0" {
|
||||||
// for k in challenges.iter() {
|
a = "127.0.0.1";
|
||||||
// println!(" ==> {} : {}", k.0, k.1);
|
}
|
||||||
// }
|
let p = addr_port[1].parse::<u16>().unwrap();
|
||||||
|
|
||||||
if let Some(key_authorization) = challenges.get(&token) {
|
loop {
|
||||||
return Response::builder()
|
match TcpListener::bind((a, p)).await {
|
||||||
.status(StatusCode::OK)
|
Ok(_) => {
|
||||||
.header("Content-Type", "text/plain")
|
break;
|
||||||
.body(Body::from(key_authorization.clone()))
|
}
|
||||||
.unwrap();
|
Err(_) => {
|
||||||
|
warn!("{} port is not available: {} will try again in {:?}", name, p, t);
|
||||||
|
tokio::time::sleep(t).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Response::builder()
|
|
||||||
.status(StatusCode::NOT_FOUND)
|
|
||||||
.header("Content-Type", "text/plain")
|
|
||||||
.body(Body::from("Not found"))
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn key_authorization(headers: &HeaderMap, params: &HashMap<String, String>, masterkey: &str) -> bool {
|
|
||||||
// if let Some(s) = headers.get("x-api-key").and_then(|v| v.to_str().ok()).or(params.get("key").map(|s| s.as_str())) {
|
|
||||||
// if s.as_bytes().ct_eq(masterkey.as_bytes()).into() {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// false
|
|
||||||
// }
|
|
||||||
|
|
||||||
// -- ⚝ by Dave -- in NeoVim ⚝ --
|
// -- ⚝ by Dave -- in NeoVim ⚝ --
|
||||||
|
|||||||
Reference in New Issue
Block a user