feat: route Jeannie API through edge
This commit is contained in:
parent
2a5912f174
commit
2b3aa42c0c
|
|
@ -21,31 +21,35 @@ locals {
|
|||
oidc_backend_host = (
|
||||
var.oidc_backend_host != "" ? var.oidc_backend_host : var.gitea_backend_host
|
||||
)
|
||||
jellyfin_backend_host = var.jellyfin_backend_host != "" ? var.jellyfin_backend_host : var.gitea_backend_host
|
||||
server_names = distinct(concat([var.server_name, local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name], var.additional_server_names))
|
||||
matrix_server_names = var.matrix_enabled ? [var.matrix_server_name, var.element_server_name] : []
|
||||
main_server_names = [for name in local.server_names : name if !contains([local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name], name) && !contains(local.matrix_server_names, name)]
|
||||
jellyfin_backend_host = var.jellyfin_backend_host != "" ? var.jellyfin_backend_host : var.gitea_backend_host
|
||||
jeannie_api_server_name = "api.${var.server_name}"
|
||||
server_names = distinct(concat([var.server_name, local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name, local.jeannie_api_server_name], var.additional_server_names))
|
||||
matrix_server_names = var.matrix_enabled ? [var.matrix_server_name, var.element_server_name] : []
|
||||
main_server_names = [for name in local.server_names : name if !contains([local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name, local.jeannie_api_server_name], name) && !contains(local.matrix_server_names, name)]
|
||||
default_conf = templatefile("${path.module}/templates/default.conf.tftpl", {
|
||||
server_name = var.server_name
|
||||
server_names = join(" ", local.server_names)
|
||||
main_server_names = join(" ", local.main_server_names)
|
||||
backend_host = var.backend_host
|
||||
backend_port = tostring(var.backend_port)
|
||||
demos_backend_port = var.demos_backend_port
|
||||
gitea_backend_host = var.gitea_backend_host
|
||||
gitea_backend_port = var.gitea_backend_port
|
||||
heimdall_server_name = local.heimdall_server_name
|
||||
heimdall_backend_host = local.heimdall_backend_host
|
||||
heimdall_backend_port = tostring(var.heimdall_backend_port)
|
||||
homepage_server_name = local.homepage_server_name
|
||||
homepage_backend_host = local.homepage_backend_host
|
||||
homepage_backend_port = tostring(var.homepage_backend_port)
|
||||
oidc_server_name = local.oidc_server_name
|
||||
oidc_backend_host = local.oidc_backend_host
|
||||
oidc_backend_port = tostring(var.oidc_backend_port)
|
||||
jellyfin_server_name = local.jellyfin_server_name
|
||||
jellyfin_backend_host = local.jellyfin_backend_host
|
||||
jellyfin_backend_port = tostring(var.jellyfin_backend_port)
|
||||
server_name = var.server_name
|
||||
server_names = join(" ", local.server_names)
|
||||
main_server_names = join(" ", local.main_server_names)
|
||||
backend_host = var.backend_host
|
||||
backend_port = tostring(var.backend_port)
|
||||
demos_backend_port = var.demos_backend_port
|
||||
gitea_backend_host = var.gitea_backend_host
|
||||
gitea_backend_port = var.gitea_backend_port
|
||||
heimdall_server_name = local.heimdall_server_name
|
||||
heimdall_backend_host = local.heimdall_backend_host
|
||||
heimdall_backend_port = tostring(var.heimdall_backend_port)
|
||||
homepage_server_name = local.homepage_server_name
|
||||
homepage_backend_host = local.homepage_backend_host
|
||||
homepage_backend_port = tostring(var.homepage_backend_port)
|
||||
oidc_server_name = local.oidc_server_name
|
||||
oidc_backend_host = local.oidc_backend_host
|
||||
oidc_backend_port = tostring(var.oidc_backend_port)
|
||||
jellyfin_server_name = local.jellyfin_server_name
|
||||
jellyfin_backend_host = local.jellyfin_backend_host
|
||||
jellyfin_backend_port = tostring(var.jellyfin_backend_port)
|
||||
jeannie_api_server_name = local.jeannie_api_server_name
|
||||
jeannie_api_backend_host = var.jeannie_api_backend_host
|
||||
jeannie_api_backend_port = tostring(var.jeannie_api_backend_port)
|
||||
})
|
||||
default_vcl = templatefile("${path.module}/templates/default.vcl.tftpl", {
|
||||
backend_host = var.backend_host
|
||||
|
|
@ -99,6 +103,8 @@ resource "null_resource" "edge_services" {
|
|||
oidc_port = tostring(var.oidc_backend_port)
|
||||
jellyfin_host = local.jellyfin_backend_host
|
||||
jellyfin_port = tostring(var.jellyfin_backend_port)
|
||||
jeannie_api_host = var.jeannie_api_backend_host
|
||||
jeannie_api_port = tostring(var.jeannie_api_backend_port)
|
||||
enable_letsencrypt = tostring(var.enable_letsencrypt)
|
||||
letsencrypt_email = var.letsencrypt_email
|
||||
letsencrypt_staging = tostring(var.letsencrypt_staging)
|
||||
|
|
@ -180,6 +186,8 @@ oidc_host="${self.triggers.oidc_host}"
|
|||
oidc_port="${self.triggers.oidc_port}"
|
||||
jellyfin_host="${self.triggers.jellyfin_host}"
|
||||
jellyfin_port="${self.triggers.jellyfin_port}"
|
||||
jeannie_api_host="${self.triggers.jeannie_api_host}"
|
||||
jeannie_api_port="${self.triggers.jeannie_api_port}"
|
||||
enable_letsencrypt="${self.triggers.enable_letsencrypt}"
|
||||
letsencrypt_email="${self.triggers.letsencrypt_email}"
|
||||
letsencrypt_staging="${self.triggers.letsencrypt_staging}"
|
||||
|
|
@ -226,6 +234,11 @@ if ! curl -sS --connect-timeout 10 "http://$jellyfin_host:$jellyfin_port/" >/dev
|
|||
echo "Check the Debian Jellyfin container and published port before testing the public hostname." >&2
|
||||
fi
|
||||
|
||||
if ! curl -sS --connect-timeout 10 -o /dev/null -w '%%{http_code}' "http://$jeannie_api_host:$jeannie_api_port/v1/health" | grep -Eq '^(200|401)$'; then
|
||||
echo "Warning: cannot reach Jeannie API backend http://$jeannie_api_host:$jeannie_api_port/v1/health from the edge host." >&2
|
||||
echo "Check the Debian Jeannie API service before testing the public hostname." >&2
|
||||
fi
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
if [ "$install_docker" = "true" ]; then
|
||||
curl -fsSL https://get.docker.com | sudo sh
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ access_log /var/log/nginx/crowdsec-access.log;
|
|||
error_log /var/log/nginx/crowdsec-error.log warn;
|
||||
|
||||
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
|
||||
limit_req_zone $binary_remote_addr zone=jeannie_api:10m rate=10r/s;
|
||||
|
||||
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=static_assets:10m max_size=100m inactive=24h;
|
||||
proxy_cache_path /var/cache/nginx_dynamic levels=1:2 keys_zone=dynamic_content:5m max_size=50m inactive=1h;
|
||||
|
|
@ -44,6 +45,11 @@ upstream jellyfin_backend {
|
|||
keepalive 8;
|
||||
}
|
||||
|
||||
upstream jeannie_api_backend {
|
||||
server ${jeannie_api_backend_host}:${jeannie_api_backend_port};
|
||||
keepalive 8;
|
||||
}
|
||||
|
||||
set_real_ip_from 173.245.48.0/20;
|
||||
set_real_ip_from 103.21.244.0/22;
|
||||
set_real_ip_from 103.22.200.0/22;
|
||||
|
|
@ -78,7 +84,7 @@ server {
|
|||
|
||||
server {
|
||||
listen 80;
|
||||
server_name ${heimdall_server_name} ${homepage_server_name} ${oidc_server_name} ${jellyfin_server_name};
|
||||
server_name ${heimdall_server_name} ${homepage_server_name} ${oidc_server_name} ${jellyfin_server_name} ${jeannie_api_server_name};
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
|
|
@ -91,6 +97,59 @@ server {
|
|||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
http2 on;
|
||||
server_name ${jeannie_api_server_name};
|
||||
|
||||
ssl_certificate /etc/nginx/certs/current.crt;
|
||||
ssl_certificate_key /etc/nginx/certs/current.key;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||
ssl_session_cache shared:homelab_ssl:10m;
|
||||
ssl_session_timeout 1d;
|
||||
|
||||
keepalive_timeout 65s;
|
||||
keepalive_requests 1000;
|
||||
|
||||
if ($blocked_uris) { return 403; }
|
||||
|
||||
add_header X-Frame-Options SAMEORIGIN;
|
||||
add_header X-XSS-Protection "1; mode=block";
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin";
|
||||
add_header Permissions-Policy "geolocation=(), microphone=()";
|
||||
|
||||
location = /edge-health {
|
||||
access_log off;
|
||||
return 204;
|
||||
}
|
||||
|
||||
location / {
|
||||
limit_req zone=jeannie_api burst=20 nodelay;
|
||||
client_max_body_size 64k;
|
||||
|
||||
proxy_pass http://jeannie_api_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
proxy_connect_timeout 3s;
|
||||
proxy_read_timeout 35s;
|
||||
proxy_send_timeout 35s;
|
||||
proxy_next_upstream off;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
proxy_set_header X-Forwarded-Port 443;
|
||||
proxy_set_header CF-Connecting-IP $http_cf_connecting_ip;
|
||||
add_header Cache-Control "no-store";
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
http2 on;
|
||||
|
|
|
|||
|
|
@ -133,6 +133,21 @@ variable "jellyfin_backend_port" {
|
|||
default = 8096
|
||||
}
|
||||
|
||||
variable "jeannie_api_backend_host" {
|
||||
type = string
|
||||
default = ""
|
||||
|
||||
validation {
|
||||
condition = var.jeannie_api_backend_host != ""
|
||||
error_message = "jeannie_api_backend_host must be provided from homelab.yml through jeannie or an explicit tfvars/env value."
|
||||
}
|
||||
}
|
||||
|
||||
variable "jeannie_api_backend_port" {
|
||||
type = number
|
||||
default = 8787
|
||||
}
|
||||
|
||||
# Matrix (isolated vhost + its own cert; does NOT touch shared current.crt)
|
||||
variable "matrix_enabled" {
|
||||
type = bool
|
||||
|
|
|
|||
|
|
@ -25,21 +25,24 @@ stored in memory and command output is returned through
|
|||
GET /v1/executions/{id}. It is not a public edge service and does not accept
|
||||
arbitrary shell commands.
|
||||
|
||||
## Kubernetes API gateway
|
||||
## Edge API gateway
|
||||
|
||||
The `jeannie-api` Argo application publishes the Debian API through Traefik
|
||||
at `api.lab2025.duckdns.org`. The backend remains the Debian host at
|
||||
`192.168.100.73:8787`; Kubernetes does not run a second Jeannie server.
|
||||
The canonical public route publishes the Debian API directly through the OCI
|
||||
edge proxy at `api.lab2025.duckdns.org`. The backend remains the Debian host
|
||||
at `192.168.100.73:8787`; Kubernetes does not run a second Jeannie server and
|
||||
is not required for API availability.
|
||||
|
||||
The gateway applies the existing bearer-token authentication, a rate limit of
|
||||
10 requests per second with a burst of 20, and backend timeouts of 3 seconds
|
||||
for dialing, 30 seconds for response headers, and 60 seconds for idle
|
||||
connections. Read-only routes may be retried once; `POST /v1/execute` is not
|
||||
retried so a command cannot be submitted twice by the gateway.
|
||||
The edge gateway applies a per-client rate limit of 10 requests per second
|
||||
with a burst of 20, forwards the bearer token to Debian, and uses 35-second
|
||||
proxy read/write timeouts. The Jeannie API remains responsible for bearer
|
||||
authentication and command allowlisting. Read-only retries are not enabled at
|
||||
the edge; `POST /v1/execute` is never retried so a command cannot be submitted
|
||||
twice by a proxy.
|
||||
|
||||
Traefik exposes JSON access logs and Prometheus request metrics. Prometheus
|
||||
scrapes the Traefik metrics endpoint as the `traefik` job, with entrypoint and
|
||||
service labels enabled.
|
||||
The Kubernetes `jeannie-api` route may remain available for internal testing,
|
||||
but it is not the availability-critical path. Traefik continues to expose
|
||||
Kubernetes request metrics, while the edge proxy records the canonical API
|
||||
traffic in its access logs.
|
||||
|
||||
The Temporal UI is bound to `127.0.0.1:8233` by default because Debian uses
|
||||
port 8088 for the provisioning service. Override it during deployment with
|
||||
|
|
@ -51,5 +54,6 @@ LAN address or a local DNS override. Direct backend testing remains:
|
|||
curl -H 'Authorization: Bearer replace-with-a-secret' \
|
||||
http://192.168.100.73:8787/v1/health
|
||||
|
||||
Through the API gateway, use the API hostname and the Traefik load-balancer
|
||||
address from the cluster network.
|
||||
Through the canonical gateway, use the API hostname and the OCI edge address.
|
||||
For a controlled test without changing DNS, use `curl --resolve` with the
|
||||
edge public IP.
|
||||
|
|
|
|||
|
|
@ -148,6 +148,10 @@ services:
|
|||
host: debian
|
||||
http_port: 8096
|
||||
public_url: https://jellyfin.lab2025.duckdns.org/
|
||||
jeannie_api:
|
||||
host: debian
|
||||
http_port: 8787
|
||||
public_url: https://api.lab2025.duckdns.org/
|
||||
gitops_mirror:
|
||||
host: debian
|
||||
path: /home/jv/git-server/my-homelab-configs.git
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ mapping = {
|
|||
"services.dex.public_url": "LAB_DEX_PUBLIC_URL",
|
||||
"services.jellyfin.http_port": "LAB_JELLYFIN_HTTP_PORT",
|
||||
"services.jellyfin.public_url": "LAB_JELLYFIN_PUBLIC_URL",
|
||||
"services.jeannie_api.http_port": "LAB_JEANNIE_API_BACKEND_PORT",
|
||||
"services.local_registry.endpoint": "LAB_REGISTRY_ENDPOINT",
|
||||
"services.ollama.url": "LAB_OLLAMA_URL",
|
||||
"services.ollama.bind_address": "LAB_OLLAMA_BIND_ADDRESS",
|
||||
|
|
@ -280,6 +281,8 @@ export_homelab_inventory_tf_vars() {
|
|||
export_if_unset TF_VAR_gitea_auth_source_name "${LAB_GITEA_DEX_SOURCE_NAME:-dex}"
|
||||
export_if_unset TF_VAR_jellyfin_backend_host "${LAB_JELLYFIN_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}"
|
||||
export_if_unset TF_VAR_jellyfin_backend_port "${LAB_JELLYFIN_HTTP_PORT:-}"
|
||||
export_if_unset TF_VAR_jeannie_api_backend_host "${LAB_JEANNIE_API_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-${LAB_DEBIAN_LAN_IP:-}}}"
|
||||
export_if_unset TF_VAR_jeannie_api_backend_port "${LAB_JEANNIE_API_BACKEND_PORT:-8787}"
|
||||
export_if_unset TF_VAR_gitops_repo_url "${LAB_GITOPS_REPO_URL:-}"
|
||||
export_if_unset TF_VAR_calico_operator_node_name "${LAB_CALICO_OPERATOR_NODE_NAME:-${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-}}"
|
||||
export_if_unset TF_VAR_worker_tailscale_enabled "${LAB_PIMOX_WORKER_TAILSCALE_ENABLED:-}"
|
||||
|
|
|
|||
|
|
@ -45,11 +45,14 @@ if [ "$FORMAT" = "--dot" ] || [ "$FORMAT" = "dot" ]; then
|
|||
digraph homelab {
|
||||
rankdir=LR;
|
||||
"Internet" -> "OCI edge ${oci}";
|
||||
"OCI edge ${oci}" -> "Jeannie API ${debian}:8787";
|
||||
"OCI edge ${oci}" -> "Traefik ${traefik}";
|
||||
"OCI edge ${oci}" -> "Debian Tailscale ${debian_ts}";
|
||||
"Debian ${debian}" -> "Gitea :${gitea_http}/git";
|
||||
"Debian ${debian}" -> "Local registry ${registry}";
|
||||
"Debian ${debian}" -> "Kubernetes control plane";
|
||||
"Jeannie API ${debian}:8787" -> "Temporal/Postgres on Debian";
|
||||
"Temporal/Postgres on Debian" -> "Kubernetes control plane and homelab services";
|
||||
"Debian ${debian}" -> "Pimox ${pimox}";
|
||||
"Pimox ${pimox}" -> "Worker VMs";
|
||||
"Worker VMs" -> "Kubernetes apps";
|
||||
|
|
@ -74,7 +77,9 @@ Public entry
|
|||
Internet
|
||||
-> ${domain}
|
||||
-> OCI edge ${oci} / tailscale ${oci_ts}
|
||||
-> Traefik LoadBalancer ${traefik}
|
||||
-> api.${domain} -> Jeannie API on Debian ${debian}:8787
|
||||
-> Temporal/Postgres on Debian -> Kubernetes and homelab services
|
||||
-> other hostnames -> Traefik LoadBalancer ${traefik}
|
||||
-> Kubernetes ingress routes
|
||||
-> website, demos, Heimdall, observability, Argo CD, arr routes
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue