# Authentik forward-auth snippet (domain-level mode).
# Usage: add "import authentik" inside any site block to gate it.
(authentik) {
	route {
		reverse_proxy /outpost.goauthentik.io/* http://192.168.8.180:9000
		forward_auth http://192.168.8.180:9000 {
			uri /outpost.goauthentik.io/auth/caddy
			copy_headers X-Authentik-Username X-Authentik-Groups X-Authentik-Email X-Authentik-Name X-Authentik-Uid X-Authentik-Jwt X-Authentik-Meta-Jwks X-Authentik-Meta-Outpost X-Authentik-Meta-Provider X-Authentik-Meta-App X-Authentik-Meta-Version
			trusted_proxies private_ranges
			header_up X-Forwarded-Host {host}
			header_up X-Forwarded-Proto {scheme}
			header_up X-Forwarded-Uri {uri}
		}
	}
}

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

media.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.206:8096
}

git.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	handle_path /_plantuml/* {
		rewrite * /plantuml{uri}
		reverse_proxy 192.168.8.205:8079
	}
	handle {
		reverse_proxy 192.168.8.121:3000
	}
}

paperless.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	@api path /api/*
	handle @api {
		reverse_proxy 192.168.8.130:8000
	}
	handle {
		import authentik
		reverse_proxy 192.168.8.130:8000
	}
}

books.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.205:6060
}

home.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.101:8123
}

cloud.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.224:80
}

matrix.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.239:8008
}

proxmox.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy https://192.168.8.77:8006 {
		transport http {
			tls_insecure_skip_verify
		}
	}
}

docker.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy https://192.168.8.205:9443 {
		transport http {
			tls_insecure_skip_verify
		}
	}
}

jellyseerr.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.132:5056
}

qbit.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	@api path /api/*
	handle @api {
		reverse_proxy 192.168.8.132:8080
	}
	handle {
		import authentik
		reverse_proxy 192.168.8.132:8080
	}
}

sab.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.132:8081
}

blog.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.205:8080
}

photos.hubris.network {
	# mule-image — PhotoPrism + Go sidecar + SvelteKit (post-Mulimage 2.0)
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	encode zstd gzip
	# PhotoPrism API + OIDC callback first (matched before static catch-all)
	@pp path /api/v1/* /api/v1 /static/* /share/*
	reverse_proxy @pp 192.168.8.136:2342
	# PhotoPrism's OIDC initiation lives at /library/login (and the
	# JS posts to /library/login/* during the Authentik handshake).
	# Proxy those through to PhotoPrism BEFORE the /library/* catch-all
	# redir, otherwise the user clicks "Sign in with Authentik" and
	# caddy bounces them straight back to the SvelteKit root.
	@pp_login path /library/login /library/login/*
	reverse_proxy @pp_login 192.168.8.136:2342
	# Everything else under /library/* (notably /library/browse, which
	# PhotoPrism redirects to after a successful login) bounces back
	# to the SvelteKit SPA — mule-image is the only user-facing frontend.
	redir /library /  302
	redir /library/* / 302
	# mule-sidecar (Go) — keeps the /api/sidecar/ prefix
	@sc path /api/sidecar/*
	reverse_proxy @sc 192.168.8.136:8000
	# Catch-all → nginx-on-120 serving the SvelteKit static bundle (no Vite in prod)
	reverse_proxy 192.168.8.136:3000
}

auth.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.180:9000
}

artifacto.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	# Public paths: share URLs, static assets, health — no SSO
	@public path /p/* /static/* /healthz
	handle @public {
		reverse_proxy 192.168.8.205:3100
	}
	# Admin + login surface: Authentik forward-auth + shared-secret header
	# so the app can auto-login an Authentik-authenticated user.
	handle {
		import authentik
		reverse_proxy 192.168.8.205:3100 {
			header_up X-Artifacto-Gateway {env.ARTIFACTO_GATEWAY_SECRET}
		}
	}
}

plato.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.190:8080
}

zimaos.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.195
}

# Homelab MCP server (read-only context + management tools).
# Mesh+LAN-gated by the service itself + nftables; no SSO so agent clients work.
mcp.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.205:9810
}

# Per-client age-key issuance (mesh-only via source-IP gating in the service).
# No SSO — agents call this during bootstrap; identity is mesh peer + hostname.
secrets.hubris.network {
	tls {
		dns ionos {env.IONOS_AUTH_API_TOKEN}
	}
	reverse_proxy 192.168.8.205:9820
}
